Exemple #1
0
        public override void SetBreakpoints(Response response, dynamic arguments)
        {
            SessionLog.WriteLine($"Set breakpoints command accepted {arguments}");

            if ((bool)arguments.sourceModified)
            {
                if (_startupPerformed)
                {
                    SendErrorResponse(response, 1102, "Нельзя установить точку останова на модифицированный файл.");
                    return;
                }
                SendResponse(response, new SetBreakpointsResponseBody());
                return;
            }

            var path = (string)arguments.source.path;

            path = ConvertClientPathToDebugger(path);
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                // vscode иногда передает путь, где диск - маленькая буква
                path = NormalizeDriveLetter(path);
            }

            var breaks = new List <OneScript.DebugProtocol.Breakpoint>();

            foreach (var srcBreakpoint in arguments.breakpoints)
            {
                var bpt = new OneScript.DebugProtocol.Breakpoint();
                bpt.Line   = (int)srcBreakpoint.line;
                bpt.Source = path;
                breaks.Add(bpt);
            }

            if (breaks.Count == 0) // в целях сохранения интерфейса WCF придется сделать костыль на перех. период
            {
                var bpt = new OneScript.DebugProtocol.Breakpoint();
                bpt.Line   = 0;
                bpt.Source = path;
                breaks.Add(bpt);
            }

            var confirmedBreaks       = _process.SetBreakpoints(breaks);
            var confirmedBreaksVSCode = new List <VSCodeDebug.Breakpoint>(confirmedBreaks.Length);

            for (int i = 0; i < confirmedBreaks.Length; i++)
            {
                confirmedBreaksVSCode.Add(new VSCodeDebug.Breakpoint(true, confirmedBreaks[i].Line));
            }

            SendResponse(response, new SetBreakpointsResponseBody(confirmedBreaksVSCode));
        }
Exemple #2
0
 public override void ConfigurationDone(Response response, dynamic args)
 {
     if (_process == null)
     {
         SessionLog.WriteLine("Config Done. Process is not started");
         SendResponse(response);
         return;
     }
     SessionLog.WriteLine("Config Done. Process is started");
     _process.BeginExecution(-1);
     _startupPerformed = true;
     SendResponse(response);
 }
        private T GetResponse <T>()
        {
            var rpcResult = _processor.GetResult();

            SessionLog.WriteLine("Response received " + rpcResult.Id + " t = " + rpcResult.ReturnValue);
            if (rpcResult.ReturnValue is RpcExceptionDto excDto)
            {
                SessionLog.WriteLine($"Exception received: {excDto.Description}");
                throw new RpcOperationException(excDto);
            }

            return((T)rpcResult.ReturnValue);
        }
Exemple #4
0
        public override void Threads(Response response, dynamic arguments)
        {
            var threads = new List <VSCodeDebug.Thread>();

            SessionLog.WriteLine("Threads request accepted");
            var processThreads = _process.GetThreads();

            for (int i = 0; i < processThreads.Length; i++)
            {
                threads.Add(new VSCodeDebug.Thread(processThreads[i], $"Thread {processThreads[i]}"));
            }

            SendResponse(response, new ThreadsResponseBody(threads));
            SessionLog.WriteLine("Threads processed");
        }
        public void Connect()
        {
            var debuggerUri = Binder.GetDebuggerUri(_port);

            SessionLog.WriteLine("Creating commands tcp channel");

            var client = new TcpClient();

            TryConnect(client, debuggerUri);
            _commandsChannel = new BinaryChannel(client);

            SessionLog.WriteLine("connected");

            RunEventsListener(_commandsChannel);
        }
 private void ServerOnDataReceived(object sender, CommunicationEventArgs e)
 {
     SessionLog.WriteLine("Data received " + e.Data);
     if (e.Exception == null)
     {
         DispatchMessage((TcpProtocolDtoBase)e.Data, e.Channel);
     }
     else
     {
         SessionLog.WriteLine("RPC Exception " + e.Exception + " critical: " + e.Exception.StopChannel);
         if (e.Exception.StopChannel)
         {
             Stop();
         }
     }
 }
Exemple #7
0
        public override void Scopes(Response response, dynamic arguments)
        {
            int frameId = getInt(arguments, "frameId");
            var frame   = _framesHandles.Get(frameId, null);

            if (frame == null)
            {
                SendErrorResponse(response, 10001, "No active stackframe");
                return;
            }

            var frameVariablesHandle = _variableHandles.Create(frame);
            var localScope           = new Scope("Локальные переменные", frameVariablesHandle);

            SendResponse(response, new ScopesResponseBody(new Scope[] { localScope }));
            SessionLog.WriteLine("Scopes done");
        }
Exemple #8
0
        public override void Initialize(Response response, dynamic args)
        {
            SessionLog.WriteLine("Initialize:" + args);
            AdapterID = (string)args.adapterID;

            _process = DebugeeFactory.CreateProcess(AdapterID, PathStrategy);

            SendResponse(response, new Capabilities()
            {
                supportsConditionalBreakpoints   = false,
                supportsFunctionBreakpoints      = false,
                supportsConfigurationDoneRequest = true,
                exceptionBreakpointFilters       = new dynamic[0],
                supportsEvaluateForHovers        = true
            });

            SendEvent(new InitializedEvent());
        }
Exemple #9
0
        private static void StartSession(bool showTrace, Stream input, Stream output)
        {
            var session = new OscriptDebugSession();

            session.TRACE          = showTrace;
            session.TRACE_RESPONSE = showTrace;
            SessionLog.Open(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/debug.log");
            try
            {
                session.Start(input, output);
            }
            catch (Exception e)
            {
                SessionLog.WriteLine(e.ToString());
            }
            finally
            {
                SessionLog.Close();
            }
        }
Exemple #10
0
        public override void StackTrace(Response response, dynamic arguments)
        {
            SessionLog.WriteLine("Stacktrace request accepted");
            SessionLog.WriteLine(arguments.ToString());
            var firstFrameIdx = (int?)arguments.startFrame ?? 0;
            var limit         = (int?)arguments.levels ?? 0;
            var threadId      = (int)arguments.threadId;
            var processFrames = _process.GetStackTrace(threadId, firstFrameIdx, limit);
            var frames        = new VSCodeDebug.StackFrame[processFrames.Length];

            for (int i = 0; i < processFrames.Length; i++)
            {
                frames[i] = new VSCodeDebug.StackFrame(
                    _framesHandles.Create(processFrames[i]),
                    processFrames[i].MethodName,
                    processFrames[i].GetSource(),
                    processFrames[i].LineNumber, 0);
            }

            SendResponse(response, new StackTraceResponseBody(frames));
        }
Exemple #11
0
        static void Main(string[] args)
        {
            bool showTrace = false;

            foreach (var argument in args)
            {
                switch (argument)
                {
                case "-trace":
                    showTrace = true;
                    break;
                }
            }

            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += (s, e) =>
            {
                SessionLog.WriteLine(e.ExceptionObject.ToString());
            };

            StartSession(showTrace, Console.OpenStandardInput(), Console.OpenStandardOutput());
        }
        private static void TryConnect(TcpClient client, Uri debuggerUri)
        {
            const int limit = 3;

            // TODO: параметризовать ожидания и попытки
            for (int i = 0; i < limit; ++i)
            {
                try
                {
                    client.Connect(debuggerUri.Host, debuggerUri.Port);
                    break;
                }
                catch (SocketException)
                {
                    if (i == limit - 1)
                    {
                        throw;
                    }

                    SessionLog.WriteLine("Error. Retry connect");
                    Thread.Sleep(1500);
                }
            }
        }
Exemple #13
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);
        }
Exemple #14
0
 private void RequestDummy(string message, Response response, dynamic arguments)
 {
     SessionLog.WriteLine(message);
     SendResponse(response, arguments);
 }
Exemple #15
0
 public void ProcessExited(int exitCode)
 {
     SessionLog.WriteLine("Exited event recieved");
     SendEvent(new ExitedEvent(exitCode));
 }