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);
 }
Exemple #3
0
        public override void Initialize(Response response, dynamic args)
        {
            SessionLog.WriteLine("Initialize:" + args);
            SendResponse(response, new Capabilities()
            {
                supportsConditionalBreakpoints   = false,
                supportsFunctionBreakpoints      = false,
                supportsConfigurationDoneRequest = true,
                exceptionBreakpointFilters       = new dynamic[0],
                supportsEvaluateForHovers        = true
            });

            SendEvent(new InitializedEvent());
        }
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 " + i));
            }

            SendResponse(response, new ThreadsResponseBody(threads));
            SessionLog.WriteLine("Threads processed");
        }
Exemple #5
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 #6
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 #7
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,
                    new Source(processFrames[i].Source),
                    processFrames[i].LineNumber, 0);
            }

            SendResponse(response, new StackTraceResponseBody(frames));
        }
Exemple #8
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());
        }
Exemple #9
0
        public override void Launch(Response response, dynamic args)
        {
            var startupScript = (string)args["program"];

            if (startupScript == null)
            {
                SendErrorResponse(response, 1001, "Property 'program' is missing or empty.");
                return;
            }

            if (!File.Exists(startupScript))
            {
                SendErrorResponse(response, 1002, "Script '{path}' does not exist.", new { path = Path.Combine(Directory.GetCurrentDirectory(), startupScript) });
                return;
            }

            // validate argument 'args'
            string[] arguments = null;
            if (args.args != null)
            {
                arguments = args.args.ToObject <string[]>();
                if (arguments != null && arguments.Length == 0)
                {
                    arguments = null;
                }
            }

            // validate argument 'cwd'
            var workingDirectory = (string)args.cwd;

            if (workingDirectory != null)
            {
                workingDirectory = workingDirectory.Trim();
                if (workingDirectory.Length == 0)
                {
                    SendErrorResponse(response, 3003, "Property 'cwd' is empty.");
                    return;
                }
                workingDirectory = ConvertClientPathToDebugger(workingDirectory);
                if (!Directory.Exists(workingDirectory))
                {
                    SendErrorResponse(response, 3004, "Working directory '{path}' does not exist.", new { path = workingDirectory });
                    return;
                }
            }
            else
            {
                workingDirectory = Path.GetDirectoryName(startupScript);
            }

            // validate argument 'runtimeExecutable'
            var runtimeExecutable = (string)args.runtimeExecutable;

            if (runtimeExecutable != null)
            {
                runtimeExecutable = runtimeExecutable.Trim();
                if (runtimeExecutable.Length == 0)
                {
                    SendErrorResponse(response, 3005, "Property 'runtimeExecutable' is empty.");
                    return;
                }

                runtimeExecutable = ConvertClientPathToDebugger(runtimeExecutable);
                if (!File.Exists(runtimeExecutable))
                {
                    SendErrorResponse(response, 3006, "Runtime executable '{path}' does not exist.", new
                    {
                        path = runtimeExecutable
                    });
                    return;
                }
            }
            else
            {
                runtimeExecutable = "oscript.exe";
            }

            _process = new DebugeeProcess();

            _process.RuntimeExecutable = runtimeExecutable;
            _process.RuntimeArguments  = Utilities.ConcatArguments(args.runtimeArgs);
            _process.StartupScript     = startupScript;
            _process.ScriptArguments   = Utilities.ConcatArguments(args.args);
            _process.WorkingDirectory  = workingDirectory;

            _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();
            }
            catch (Exception e)
            {
                SendErrorResponse(response, 3012, "Can't launch debugee ({reason}).", new { reason = e.Message });
                return;
            }

            int port = getInt(args, "debugPort", 2801);

            try
            {
                _process.Connect(port, this);
            }
            catch (Exception e)
            {
                _process.Kill();
                _process = null;
                SendErrorResponse(response, 4550, "Can't connect: " + e.ToString());
                return;
            }

            SendResponse(response);
        }
Exemple #10
0
 private void RequestDummy(string message, Response response, dynamic arguments)
 {
     SessionLog.WriteLine(message);
     SendResponse(response, arguments);
 }
Exemple #11
0
 public void ProcessExited(int exitCode)
 {
     SessionLog.WriteLine("Exited event recieved");
     SendEvent(new ExitedEvent(exitCode));
 }