示例#1
0
        public override void Attach(Response response, dynamic arguments)
        {
            SessionLog.WriteLine("Attach command received");
            _process.DebugPort      = getInt(arguments, "debugPort", 2801);
            _process.ProcessExited += (s, e) =>
            {
                SessionLog.WriteLine("_process exited");
                SendEvent(new TerminatedEvent());
            };

            try
            {
                IDebuggerService service;
                var tcpConnector = new TcpDebugConnector(_process.DebugPort, this);
                tcpConnector.Connect();
                SessionLog.WriteLine($"Connected to host on port {_process.DebugPort}");
                service = tcpConnector;

                _process.SetConnection(service);
                _process.InitAttached();
            }
            catch (Exception e)
            {
                SessionLog.WriteLine(e.ToString());
                SendErrorResponse(response, 4550, "Can't connect: " + e.ToString());
                return;
            }

            SendResponse(response);
        }
示例#2
0
        public override void Launch(Response response, dynamic args)
        {
            SessionLog.WriteLine("Launch command accepted");

            try
            {
                _process.Init(args);
            }
            catch (InvalidDebugeeOptionsException e)
            {
                SendErrorResponse(response, e.ErrorCode, e.Message);
                return;
            }

            _process.OutputReceived += (s, e) =>
            {
                SessionLog.WriteLine("output received: " + e.Content);
                SendOutput(e.Category, e.Content);
            };

            _process.ProcessExited += (s, e) =>
            {
                SessionLog.WriteLine("_process exited");
                SendEvent(new TerminatedEvent());
            };

            try
            {
                _process.Start();
                SessionLog.WriteLine("Debuggee started");
            }
            catch (Exception e)
            {
                SessionLog.WriteLine(e.ToString());
                SendErrorResponse(response, 3012, "Can't launch debugee ({reason}).", new { reason = e.Message });
                return;
            }

            try
            {
                IDebuggerService service;
                if (_process.DebugProtocol == "wcf")
                {
                    var wcfConnector = new WcfDebuggerConnection(_process.DebugPort, this);
                    wcfConnector.Connect();
                    service = wcfConnector;
                }
                else
                {
                    var tcpConnector = new TcpDebugConnector(_process.DebugPort, this);
                    tcpConnector.Connect();
                    service = tcpConnector;
                }

                _process.SetConnection(service);
            }
            catch (Exception e)
            {
                _process.Kill();
                _process = null;
                SessionLog.WriteLine(e.ToString());
                SendErrorResponse(response, 4550, "Can't connect: " + e.ToString());
                return;
            }

            SendResponse(response);
        }