Exemplo n.º 1
0
        async Task SetBreakPoint(MessageId msg_id, BreakPointRequest req, CancellationToken token)
        {
            var bp_loc = store?.FindBestBreakpoint(req);

            Log("info", $"BP request for '{req}' runtime ready {runtime_ready} location '{bp_loc}'");
            if (bp_loc == null)
            {
                Log("info", $"Could not resolve breakpoint request: {req}");
                SendResponse(msg_id, Result.Err(JObject.FromObject(new {
                    code    = (int)MonoErrorCodes.BpNotFound,
                    message = $"C# Breakpoint at {req} not found."
                })), token);
                return;
            }

            Breakpoint bp = null;

            if (!runtime_ready)
            {
                bp = new Breakpoint(bp_loc, local_breakpoint_id++, BreakPointState.Pending);
            }
            else
            {
                bp = new Breakpoint(bp_loc, local_breakpoint_id++, BreakPointState.Disabled);

                var res = await EnableBreakPoint(msg_id, bp, token);

                var ret_code = res.Value? ["result"]? ["value"]?.Value <int> ();

                //if we fail we just buble that to the IDE (and let it panic over it)
                if (!ret_code.HasValue)
                {
                    SendResponse(msg_id, res, token);
                    return;
                }
            }

            var locations = new List <JObject> ();

            locations.Add(JObject.FromObject(new {
                scriptId     = bp_loc.Id.ToString(),
                lineNumber   = bp_loc.Line,
                columnNumber = bp_loc.Column
            }));

            breakpoints.Add(bp);

            var ok = JObject.FromObject(new {
                breakpointId = $"dotnet:{bp.LocalId}",
                locations    = locations,
            });

            SendResponse(msg_id, Result.Ok(ok), token);
        }
Exemplo n.º 2
0
        protected override async Task <bool> AcceptCommand(MessageId id, string method, JObject args, CancellationToken token)
        {
            switch (method)
            {
            case "Target.attachToTarget": {
                break;
            }

            case "Target.attachToBrowserTarget": {
                break;
            }

            case "Debugger.getScriptSource": {
                var script_id = args? ["scriptId"]?.Value <string> ();
                if (script_id.StartsWith("dotnet://", StringComparison.InvariantCultureIgnoreCase))
                {
                    await OnGetScriptSource(id, script_id, token);

                    return(true);
                }
                break;
            }

            case "Runtime.compileScript": {
                var exp = args? ["expression"]?.Value <string> ();
                if (exp.StartsWith("//dotnet:", StringComparison.InvariantCultureIgnoreCase))
                {
                    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, 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(token);

                break;
            }

            case "Debugger.stepInto": {
                if (this.current_callstack != null)
                {
                    await Step(id, StepKind.Into, token);

                    return(true);
                }
                break;
            }

            case "Debugger.stepOut": {
                if (this.current_callstack != null)
                {
                    await Step(id, StepKind.Out, token);

                    return(true);
                }
                break;
            }

            case "Debugger.stepOver": {
                if (this.current_callstack != null)
                {
                    await Step(id, StepKind.Over, token);

                    return(true);
                }
                break;
            }

            case "Runtime.getProperties": {
                var objId = args? ["objectId"]?.Value <string> ();
                if (objId.StartsWith("dotnet:"))
                {
                    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, int.Parse(parts[2]), token, MonoCommands.GET_OBJECT_PROPERTIES);

                        break;
                    }

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

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

            return(false);
        }