Exemple #1
0
        protected override async Task <bool> AcceptCommand(MessageId id, string method, JObject args, CancellationToken token)
        {
            switch (method)
            {
            case "Debugger.getScriptSource": {
                var script = args? ["scriptId"]?.Value <string> ();
                return(await OnGetScriptSource(id, script, token));
            }

            case "Runtime.compileScript": {
                var exp = args? ["expression"]?.Value <string> ();
                if (exp.StartsWith("//dotnet:", StringComparison.Ordinal))
                {
                    OnCompileDotnetScript(id, token);
                    return(true);
                }
                break;
            }

            case "Debugger.getPossibleBreakpoints": {
                var start = SourceLocation.Parse(args? ["start"] as JObject);
                //FIXME support variant where restrictToFunction=true and end is omitted
                var end = SourceLocation.Parse(args? ["end"] as JObject);
                if (start != null && end != null)
                {
                    return(GetPossibleBreakpoints(id, start, end, token));
                }
                break;
            }

            case "Debugger.setBreakpointByUrl": {
                Log("info", $"BP req {args}");
                var bp_req = BreakpointRequest.Parse(args, GetContext(id).Store);
                if (bp_req != null)
                {
                    await SetBreakPoint(id, bp_req, token);

                    return(true);
                }
                break;
            }

            case "Debugger.removeBreakpoint": {
                return(await RemoveBreakpoint(id, args, token));
            }

            case "Debugger.resume": {
                await OnResume(id, token);

                break;
            }

            case "Debugger.stepInto": {
                return(await Step(id, StepKind.Into, token));
            }

            case "Debugger.stepOut": {
                return(await Step(id, StepKind.Out, token));
            }

            case "Debugger.stepOver": {
                return(await Step(id, StepKind.Over, token));
            }

            case "Runtime.getProperties": {
                var objId = args? ["objectId"]?.Value <string> ();
                if (objId.StartsWith("dotnet:", StringComparison.Ordinal))
                {
                    var parts = objId.Split(new char [] { ':' });
                    if (parts.Length < 3)
                    {
                        return(true);
                    }
                    switch (parts[1])
                    {
                    case "scope": {
                        await GetScopeProperties(id, int.Parse(parts[2]), token);

                        break;
                    }

                    case "object": {
                        await GetDetails(id, MonoCommands.GetObjectProperties(int.Parse(parts[2])), token);

                        break;
                    }

                    case "array": {
                        await GetDetails(id, MonoCommands.GetArrayValues(int.Parse(parts [2])), token);

                        break;
                    }
                    }
                    return(true);
                }
                break;
            }
            }

            return(false);
        }
Exemple #2
0
        protected override async Task <bool> AcceptCommand(MessageId id, string method, JObject args, CancellationToken token)
        {
            switch (method)
            {
            case "Debugger.enable": {
                    var resp = await SendCommand(id, method, args, token);

                    GetContext(id).DebuggerId = resp.Value ["debuggerId"]?.ToString();

                    if (await IsRuntimeAlreadyReadyAlready(id, token))
                    {
                        await RuntimeReady(id, token);
                    }

                    SendResponse(id, resp, token);
                    return(true);
            }

            case "Debugger.getScriptSource": {
                    var script = args? ["scriptId"]?.Value <string> ();
                    return(await OnGetScriptSource(id, script, token));
            }

            case "Runtime.compileScript": {
                var exp = args? ["expression"]?.Value <string> ();
                if (exp.StartsWith("//dotnet:", StringComparison.Ordinal))
                {
                    OnCompileDotnetScript(id, token);
                    return(true);
                }
                break;
            }

            case "Debugger.getPossibleBreakpoints": {
                var resp = await SendCommand(id, method, args, token);

                if (resp.IsOk && resp.Value["locations"].HasValues)
                {
                    SendResponse(id, resp, token);
                    return(true);
                }

                var start = SourceLocation.Parse(args? ["start"] as JObject);
                //FIXME support variant where restrictToFunction=true and end is omitted
                var end = SourceLocation.Parse(args? ["end"] as JObject);
                if (start != null && end != null && await GetPossibleBreakpoints(id, start, end, token))
                {
                    return(true);
                }

                SendResponse(id, resp, token);
                return(true);
            }

            case "Debugger.setBreakpoint": {
                break;
            }

            case "Debugger.setBreakpointByUrl": {
                var context = GetContext(id);
                var resp    = await SendCommand(id, method, args, token);

                if (!resp.IsOk)
                {
                    SendResponse(id, resp, token);
                    return(true);
                }

                var bpid    = resp.Value["breakpointId"]?.ToString();
                var request = BreakpointRequest.Parse(bpid, args);
                context.BreakpointRequests[bpid] = request;
                if (await IsRuntimeAlreadyReadyAlready(id, token))
                {
                    var store = await RuntimeReady(id, token);

                    Log("verbose", $"BP req {args}");
                    await SetBreakpoint(id, store, request, token);
                }

                SendResponse(id, Result.OkFromObject(request.AsSetBreakpointByUrlResponse()), token);
                return(true);
            }

            case "Debugger.removeBreakpoint": {
                return(await RemoveBreakpoint(id, args, token));
            }

            case "Debugger.resume": {
                await OnResume(id, token);

                break;
            }

            case "Debugger.stepInto": {
                return(await Step(id, StepKind.Into, token));
            }

            case "Debugger.stepOut": {
                return(await Step(id, StepKind.Out, token));
            }

            case "Debugger.stepOver": {
                return(await Step(id, StepKind.Over, token));
            }

            case "Runtime.getProperties": {
                var objId = args? ["objectId"]?.Value <string> ();
                if (objId.StartsWith("dotnet:", StringComparison.Ordinal))
                {
                    var parts = objId.Split(new char [] { ':' });
                    if (parts.Length < 3)
                    {
                        return(true);
                    }
                    switch (parts[1])
                    {
                    case "scope": {
                        await GetScopeProperties(id, int.Parse(parts[2]), token);

                        break;
                    }

                    case "object": {
                        await GetDetails(id, MonoCommands.GetObjectProperties(int.Parse(parts[2])), token);

                        break;
                    }

                    case "array": {
                        await GetDetails(id, MonoCommands.GetArrayValues(int.Parse(parts [2])), token);

                        break;
                    }
                    }
                    return(true);
                }
                break;
            }
            }

            return(false);
        }