Beispiel #1
0
 private void listenForMessages(DebuggerClient client)
 {
     try
     {
         while (true)
         {
             string message = client.Reader.ReadLine();
             if (message == "PONG")
             {
                 client.Ping = 0;
             }
             else
             {
                 OnDebuggerMessageRecieved(new DebuggerMessageRecievedEventArgs {
                     DebuggerClient = client, Message = message
                 });
             }
             Thread.Sleep(20);
         }
     }
     catch (IOException)
     {
         OnDebuggerClientDisconnected(new DebuggerClientDisconnectedEventArgs {
             DebuggerClient = client
         });
     }
 }
Beispiel #2
0
        void ReceiveEvents(int timeout = -1)
        {
            string[] response = DebuggerClient.Receive(timeout);

            if (response == null)
            {
                throw new DebuggerNotResponses();
            }

            foreach (string line in response)
            {
                Logger.LogLine("< " + line);
            }

            MIOutput output = MIParser.ParseOutput(response);

            if (output.ResultRecord != null)
            {
                // this output must hasn't result record
                throw new MIParserException();
            }

            foreach (var record in output.OutOfBandRecords)
            {
                EventQueue.Enqueue(record);
            }
        }
        public static IDebuggerClient NewInstance(string debuggerURI)
        {
            var rootURI  = new Uri(debuggerURI);
            var executor = DebuggerClientExecutor.Create(rootURI);

            return(DebuggerClient.NewInstance(executor));
        }
 public DebuggerClientTests()
 {
     _options = new AgentOptions
     {
         ProjectId = _projectId,
         Module    = _module,
         Version   = _version,
     };
     _debuggee = new Debuggee
     {
         Project = _projectId,
         Id      = _debugId
     };
     _breakpoint = new Debugger.V2.Breakpoint
     {
         Id = _breakpointId
     };
     _breakpoint2 = new Debugger.V2.Breakpoint
     {
         Id = _breakpointId2
     };
     _response = new RegisterDebuggeeResponse
     {
         Debuggee = _debuggee
     };
     _mockControllerClient = new Mock <Controller2Client>();
     _client = new DebuggerClient(_options, _mockControllerClient.Object);
 }
Beispiel #5
0
        public MainWindow()
        {
            InitializeComponent();

            _viewModel = new MainWindowViewModel();
            _settings  = new SettingsContainer("Settings.json");
            _debugger  = new DebuggerClient(_viewModel);

            DataContext = _viewModel;
            _viewModel.Registers.RegistersUpdated += Registers_RegistersUpdated;
            _viewModel.Pins.PropertyChanged       += Pins_PropertyChanged;
        }
Beispiel #6
0
        public void Run(string testCaseName, string testCourceList)
        {
            // Explicit encoding setup, since system console encoding could be not utf8 (Windows OS).
            // Note, netcoredbg aimed to interact with utf8 encoding usage only for all protocols.
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.InputEncoding  = System.Text.Encoding.UTF8;

            string testSuiteRoot = Path.GetFullPath(
                Path.Combine(Directory.GetCurrentDirectory(), "../../../..")
                );

            var Env = new NetcoreDbgTestCore.Environment();

            Env.TestName = testCaseName;

            string[] testFileArray = testCourceList.Split(";");
            foreach (var FileName in testFileArray)
            {
                Env.SourceFilesPath += Path.Combine(testSuiteRoot, testCaseName, FileName + ";");
            }
            Env.SourceFilesPath = Env.SourceFilesPath.Remove(Env.SourceFilesPath.Length - 1);

            Env.TargetAssemblyPath = Path.Combine(testSuiteRoot,
                                                  testCaseName + "/bin/Debug/netcoreapp3.1/",
                                                  testCaseName + ".dll");
            string fullDebuggerPath = Path.GetFullPath(Path.Combine(testSuiteRoot, DebuggerPath));

            if (testCaseName.StartsWith("MI"))
            {
                LocalDebugger = new LocalDebuggerProcess(fullDebuggerPath, @" --interpreter=mi");
                LocalDebugger.Start();
                DebuggerClient = new MILocalDebuggerClient(LocalDebugger.Input,
                                                           LocalDebugger.Output);
            }
            else if (testCaseName.StartsWith("VSCode"))
            {
                LocalDebugger = new LocalDebuggerProcess(fullDebuggerPath, @" --interpreter=vscode");
                LocalDebugger.Start();
                DebuggerClient = new VSCodeLocalDebuggerClient(LocalDebugger.Input,
                                                               LocalDebugger.Output);
            }
            else
            {
                throw new System.Exception();
            }

            Xunit.Assert.True(DebuggerClient.DoHandshake(5000));

            var Script = new ControlScript(Env.SourceFilesPath, DebuggerClient.Protocol);

            new ControlPart().Run(Script, DebuggerClient, Env);
        }
Beispiel #7
0
 private void listenForConnections()
 {
     while (true)
     {
         DebuggerClient client = new DebuggerClient(listener.AcceptTcpClient());
         Clients.Add(client);
         client.ListenerThread = new Thread(() => listenForMessages(client));
         client.ListenerThread.Start();
         client.PingThread = new Thread(() => sendPing(client));
         client.PingThread.Start();
         OnDebuggerClientConnected(new DebuggerClientConnectedEventArgs {
             DebuggerClient = client
         });
     }
 }
Beispiel #8
0
        public MIResultRecord Request(string command, int timeout = -1)
        {
            MIResultRecord resultRecord = null;

            Logger.LogLine("> " + command);

            if (!DebuggerClient.Send(command))
            {
                throw new DebuggerNotResponses();
            }

            while (true)
            {
                string[] response = DebuggerClient.Receive(timeout);

                if (response == null)
                {
                    throw new DebuggerNotResponses();
                }

                foreach (string line in response)
                {
                    Logger.LogLine("< " + line);
                }

                // we could get async record, in this case we could have two "(gdb)" prompts one by one
                // NOTE in this case we have only one line response, that contain prompt only
                if (MIParser.IsEnd(response[0]))
                {
                    continue;
                }

                MIOutput output = MIParser.ParseOutput(response);

                foreach (var record in output.OutOfBandRecords)
                {
                    EventQueue.Enqueue(record);
                }

                if (output.ResultRecord != null)
                {
                    resultRecord = output.ResultRecord;
                    break;
                }
            }

            return(resultRecord);
        }
Beispiel #9
0
        public Form1()
        {
            InitializeComponent();
            standardColor = serverAddress.ForeColor;
            errorColor    = Color.Red;

            //Set up debugger
            debugger              = new DebuggerClient(IPAddress.Parse(serverAddress.Text));
            debugger.OnAudioData += Debugger_OnAudioData;

            //Set up audio provider
            audioProvider = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(48000, 2));
            audioOutput   = new WaveOut();
            audioOutput.Init(audioProvider);
            audioOutput.Play();
        }
Beispiel #10
0
        public void Run(string testCaseName, string testCourceList)
        {
            string testSuiteRoot = Path.GetFullPath(
                Path.Combine(Directory.GetCurrentDirectory(), "../../../..")
                );

            var Env = new NetcoreDbgTestCore.Environment();

            Env.TestName = testCaseName;

            string[] testFileArray = testCourceList.Split(";");
            foreach (var FileName in testFileArray)
            {
                Env.SourceFilesPath += Path.Combine(testSuiteRoot, testCaseName, FileName + ";");
            }
            Env.SourceFilesPath = Env.SourceFilesPath.Remove(Env.SourceFilesPath.Length - 1);

            Env.TargetAssemblyPath = Path.Combine(testSuiteRoot,
                                                  testCaseName + "/bin/Debug/netcoreapp3.1/",
                                                  testCaseName + ".dll");
            string fullDebuggerPath = Path.GetFullPath(Path.Combine(testSuiteRoot, DebuggerPath));

            if (testCaseName.StartsWith("MI"))
            {
                LocalDebugger = new LocalDebuggerProcess(fullDebuggerPath, @" --interpreter=mi");
                LocalDebugger.Start();
                DebuggerClient = new MILocalDebuggerClient(LocalDebugger.Input,
                                                           LocalDebugger.Output);
            }
            else if (testCaseName.StartsWith("VSCode"))
            {
                LocalDebugger = new LocalDebuggerProcess(fullDebuggerPath, @" --interpreter=vscode");
                LocalDebugger.Start();
                DebuggerClient = new VSCodeLocalDebuggerClient(LocalDebugger.Input,
                                                               LocalDebugger.Output);
            }
            else
            {
                throw new System.Exception();
            }

            Xunit.Assert.True(DebuggerClient.DoHandshake(200));

            var Script = new DebuggeeScript(Env.SourceFilesPath, DebuggerClient.Protocol);

            Debuggee.Run(Script, DebuggerClient, Env);
        }
        public async Task SendMessageViaDebuggerClient()
        {
            // Arrange
            var connectionMock   = new Mock <IDebuggerConnection>();
            var messageEventArgs = new MessageEventArgs(Resources.NodeDisconnectResponse);

            connectionMock.Setup(p => p.SendMessage(It.IsAny <string>()))
            .Raises(f => f.OutputMessage += null, messageEventArgs);
            var client            = new DebuggerClient(connectionMock.Object);
            var disconnectCommand = new DisconnectCommand(10);

            // Act
            await client.SendRequestAsync(disconnectCommand);

            // Assert
            Assert.IsTrue(disconnectCommand.Running);
        }
Beispiel #12
0
 public void Dispose()
 {
     if (DebuggerClient != null)
     {
         DebuggerClient.Close();
     }
     if (LocalDebugger != null)
     {
         // we may exit debugger by "gdb-exit" call in command script
         try
         {
             LocalDebugger.Close();
         }
         // "No such process" exception at System.Diagnostics.Process.Kill()
         catch (System.ComponentModel.Win32Exception) {}
     }
 }
        public void CreateDebuggerClientWithNullConnection()
        {
            // Arrange
            Exception      exception = null;
            DebuggerClient client    = null;

            // Act
            try {
                client = new DebuggerClient(null);
            } catch (Exception e) {
                exception = e;
            }

            // Assert
            Assert.IsNull(client);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(ArgumentNullException));
        }
Beispiel #14
0
        public VSCodeResult Request(Request command, int timeout = -1)
        {
            command.seq = RequestSeq++;
            string stringJSON = JsonConvert.SerializeObject(command,
                                                            Formatting.None,
                                                            new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            Logger.LogLine("-> (C) " + stringJSON);

            if (!DebuggerClient.Send(stringJSON))
            {
                throw new DebuggerNotResponses();
            }

            while (true)
            {
                string[] response = DebuggerClient.Receive(timeout);
                if (response == null)
                {
                    throw new DebuggerNotResponses();
                }
                string line = response[0];

                if (isResponseContainProperty(line, "type", "response"))
                {
                    Logger.LogLine("<- (R) " + line);
                    if ((Int64)GetResponsePropertyValue(line, "request_seq") == command.seq)
                    {
                        return(new VSCodeResult((bool)GetResponsePropertyValue(line, "success"), line));
                    }
                    else
                    {
                        throw new WrongResponseSequence();
                    }
                }
                else
                {
                    Logger.LogLine("<- (E) " + line);
                    EventQueue.Enqueue(line);
                }
            }
        }
Beispiel #15
0
        public static void Gui(string args)
        {
            //System.Diagnostics.Debug.Assert(false);

            if (nppDebugger == null)
            {
                nppDebugger = new DebuggerClient(Shell);
            }

            var ap = new ArgParser(args);

            if (ap.Exists(0))
            {
                if (ap.AsString(0) == "close")
                {
                    if (nppDebugger != null)
                    {
                        nppDebugger.Close();
                        Application.Exit(); // this line will cause the message pump on other thread to quit.
                        return;
                    }
                    else
                    {
                        throw new MDbgShellException("NPP not started.");
                    }
                }
                else
                {
                    throw new MDbgShellException("invalid argument");
                }
            }

            if (Shell.IO == nppDebugger)
            {
                WriteOutput("NPP already started. Cannot start second instance.");
                return;
            }

            WriteOutput("starting npp");

            Shell.IO = nppDebugger;
        }
        public void RaiseBreakpointEventViaDebuggerClient()
        {
            // Arrange
            var    connectionMock    = new Mock <IDebuggerConnection>();
            var    messageEventArgs  = new MessageEventArgs(Resources.NodeBreakpointResponse);
            var    client            = new DebuggerClient(connectionMock.Object);
            object sender            = null;
            BreakpointEventArgs args = null;

            // Act
            client.BreakpointEvent += (s, a) => {
                sender = s;
                args   = a;
            };
            connectionMock.Raise(f => f.OutputMessage += null, messageEventArgs);

            // Assert
            Assert.AreEqual(client, sender);
            Assert.IsNotNull(args);
            Assert.IsNotNull(args.BreakpointEvent);
        }
Beispiel #17
0
 private void sendPing(DebuggerClient client)
 {
     try
     {
         while (client.Ping <= 10000)
         {
             client.Write("PING");
             client.Ping += 1000;
             Thread.Sleep(1000);
         }
     }
     catch (IOException)
     {
         OnDebuggerClientDisconnected(new DebuggerClientDisconnectedEventArgs {
             DebuggerClient = client
         });
     }
     OnDebuggerClientDisconnected(new DebuggerClientDisconnectedEventArgs {
         DebuggerClient = client
     });
 }
Beispiel #18
0
        void ReceiveEvents(int timeout = -1)
        {
            while (true)
            {
                string[] response = DebuggerClient.Receive(timeout);
                if (response == null)
                {
                    throw new DebuggerNotResponses();
                }
                string line = response[0];

                Logger.LogLine("<- (E) " + line);
                EventQueue.Enqueue(line);

                foreach (var Event in StopEvents)
                {
                    if (isResponseContainProperty(line, "event", Event))
                    {
                        return;
                    }
                }
            }
        }
Beispiel #19
0
 public VSCodeDebugger(DebuggerClient debuggerClient)
 {
     DebuggerClient = debuggerClient;
 }
        private static IDebuggerClient Create(MockHttpMessageHandler messageHandler)
        {
            var executor = messageHandler.CreateExecutor();

            return(DebuggerClient.NewInstance(executor));
        }
Beispiel #21
0
 public void AttachDebugger(DebuggerClient debugger)
 {
     this._debugger = debugger;
 }
Beispiel #22
0
        static int Main(string[] args)
        {
            var                  cli           = new CLInterface(args);
            DebuggerClient       debugger      = null;
            ControlScript        script        = null;
            LocalDebuggerProcess localDebugger = null;

            if (cli.NeedHelp)
            {
                cli.PrintHelp();
                return(1);
            }

            if (cli.ClientInfo == null)
            {
                Console.Error.WriteLine("Please define client type");
                return(1);
            }

            try {
                switch (cli.Protocol)
                {
                case ProtocolType.MI:
                    switch (cli.ClientInfo.Type)
                    {
                    case ClientType.Local:
                        var localClientInfo = (LocalClientInfo)cli.ClientInfo;
                        localDebugger = new LocalDebuggerProcess(
                            localClientInfo.DebuggerPath, @" --interpreter=mi");
                        localDebugger.Start();

                        debugger = new MILocalDebuggerClient(localDebugger.Input,
                                                             localDebugger.Output);
                        break;

                    case ClientType.Tcp:
                        var tcpClientInfo = (TcpClientInfo)cli.ClientInfo;
                        debugger = new MITcpDebuggerClient(tcpClientInfo.Addr,
                                                           tcpClientInfo.Port);
                        break;

                    default:
                        Console.Error.WriteLine("Only tcp and local debuggers are supported now");
                        return(1);
                    }

                    break;

                case ProtocolType.VSCode:
                    switch (cli.ClientInfo.Type)
                    {
                    case ClientType.Local:
                        var localClientInfo = (LocalClientInfo)cli.ClientInfo;
                        localDebugger = new LocalDebuggerProcess(
                            localClientInfo.DebuggerPath, @" --interpreter=vscode");
                        localDebugger.Start();

                        debugger = new VSCodeLocalDebuggerClient(localDebugger.Input,
                                                                 localDebugger.Output);
                        break;

                    case ClientType.Tcp:
                        var tcpClientInfo = (TcpClientInfo)cli.ClientInfo;
                        debugger = new VSCodeTcpDebuggerClient(tcpClientInfo.Addr,
                                                               tcpClientInfo.Port);
                        break;

                    default:
                        Console.Error.WriteLine("Only tcp and local debuggers are supported now");
                        return(1);
                    }

                    break;

                default:
                    Console.Error.WriteLine("Only GDB/MI and VSCode protocols is supported now");
                    return(1);
                }
            }
            catch {
                Console.Error.WriteLine("Can't create debugger client");
                if (localDebugger != null)
                {
                    localDebugger.Close();
                }
                return(1);
            }

            if (!debugger.DoHandshake(5000))
            {
                Console.Error.WriteLine("Handshake is failed");
                debugger.Close();
                if (localDebugger != null)
                {
                    localDebugger.Close();
                }
                return(1);
            }

            try {
                script = new ControlScript(cli.Environment.SourceFilesPath, debugger.Protocol);
            }
            catch (ScriptNotBuiltException e) {
                Console.Error.WriteLine("Script is not built:");
                Console.Error.WriteLine(e.ToString());
                debugger.Close();
                if (localDebugger != null)
                {
                    localDebugger.Close();
                }
                return(1);
            }

            try {
                new ControlPart().Run(script, debugger, cli.Environment);
                Console.WriteLine("Success: Test case \"{0}\" is passed!!!",
                                  cli.Environment.TestName);
            }
            catch (System.Exception e) {
                Console.Error.WriteLine("Script running is failed. Got exception:\n" + e.ToString());
                debugger.Close();
                if (localDebugger != null)
                {
                    localDebugger.Close();
                }
                return(1);
            }

            debugger.Close();
            if (localDebugger != null)
            {
                localDebugger.Close();
            }
            return(0);
        }
 public DisplayRenderer(DebuggerClient debugger)
 {
     InitializeComponent();
     this.debugger = debugger;
 }
Beispiel #24
0
 public void DettachDebugger()
 {
     this._debugger = null;
 }
Beispiel #25
0
 public MIDebugger(DebuggerClient debuggerClient)
 {
     DebuggerClient = debuggerClient;
 }