Exemple #1
0
        public async Task TrivalStepping()
        {
            var insp = new Inspector();
            //Collect events
            var scripts = SubscribeToScripts(insp);

            await Ready();

            await insp.Ready(async (cli, token) => {
                var bp1_req = JObject.FromObject(new {
                    lineNumber   = 5,
                    columnNumber = 2,
                    url          = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"],
                });

                var bp1_res = await cli.SendCommand("Debugger.setBreakpointByUrl", bp1_req, token);
                Assert.True(bp1_res.IsOk);

                var eval_req = JObject.FromObject(new {
                    expression = "window.setTimeout(function() { invoke_add(); }, 1);",
                });

                var eval_res = await cli.SendCommand("Runtime.evaluate", eval_req, token);
                Assert.True(eval_res.IsOk);

                var pause_location = await insp.WaitFor(Inspector.PAUSE);
                //make sure we're on the right bp
                Assert.Equal("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value <string> ());
                var top_frame = pause_location ["callFrames"][0];
                System.Console.WriteLine("TrivalStepping1");
                CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, top_frame["functionLocation"]);
                System.Console.WriteLine("TrivalStepping2");
                CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 5, 2, scripts, top_frame["location"]);
                System.Console.WriteLine("TrivalStepping3");
                var step_res = await cli.SendCommand("Debugger.stepOver", null, token);
                Assert.True(step_res.IsOk);
                System.Console.WriteLine("TrivalStepping4");
                var pause_location2 = await insp.WaitFor(Inspector.PAUSE);
                System.Console.WriteLine("TrivalStepping5");
                var top_frame2 = pause_location2 ["callFrames"][0];
                System.Console.WriteLine("TrivalStepping6");
                CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, top_frame2["functionLocation"]);
                System.Console.WriteLine("TrivalStepping7");
                CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 6, 2, scripts, top_frame2["location"]);                  //it moved one line!
                System.Console.WriteLine("TrivalStepping8");
            });
        }
Exemple #2
0
        public async Task InspectLocalsAtBreakpointSite()
        {
            var insp = new Inspector();
            //Collect events
            var scripts = SubscribeToScripts(insp);

            await Ready();

            await insp.Ready(async (cli, token) => {
                var bp1_req = JObject.FromObject(new {
                    lineNumber   = 5,
                    columnNumber = 2,
                    url          = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"],
                });
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-1");
                var bp1_res = await cli.SendCommand("Debugger.setBreakpointByUrl", bp1_req, token);
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-2");
                Assert.True(bp1_res.IsOk);
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-3");
                var eval_req = JObject.FromObject(new {
                    expression = "window.setTimeout(function() { invoke_add(); }, 1);",
                });
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-4");
                var eval_res = await cli.SendCommand("Runtime.evaluate", eval_req, token);
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-5");
                Assert.True(eval_res.IsOk);
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-6");
                var pause_location = await insp.WaitFor(Inspector.PAUSE);
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-7");
                //make sure we're on the right bp
                Assert.Equal("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value <string> ());

                var top_frame = pause_location ["callFrames"][0];

                var scope = top_frame ["scopeChain"][0];
                Assert.Equal("dotnet:scope:0", scope ["object"]["objectId"]);

                //ok, what's on that scope?
                var get_prop_req = JObject.FromObject(new {
                    objectId = "dotnet:scope:0",
                });

                var frame_props = await cli.SendCommand("Runtime.getProperties", get_prop_req, token);
                Assert.True(frame_props.IsOk);

                var locals = frame_props.Value ["result"];
                CheckNumber(locals, "a", 10);
                CheckNumber(locals, "b", 20);
                CheckNumber(locals, "c", 30);
                CheckNumber(locals, "d", 0);
                CheckNumber(locals, "e", 0);
            });
        }
Exemple #3
0
        async Task CheckInspectLocalsAtBreakpointSite(Func <JObject> bp_req_fn, Func <JObject> eval_req_fn, Action <JToken> test_fn)
        {
            var insp = new Inspector();
            //Collect events
            var scripts = SubscribeToScripts(insp);

            await Ready();

            await insp.Ready(async (cli, token) => {
                var bp_req = bp_req_fn();
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-1");
                var bp_res = await cli.SendCommand("Debugger.setBreakpointByUrl", bp_req, token);
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-2");
                Assert.True(bp_res.IsOk);
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-3");
                var eval_req = eval_req_fn();
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-4");
                var eval_res = await cli.SendCommand("Runtime.evaluate", eval_req, token);
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-5");
                Assert.True(eval_res.IsOk);
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-6");
                var pause_location = await insp.WaitFor(Inspector.PAUSE);
                System.Console.WriteLine("InspectLocalsAtBreakpointSite-7");
                //make sure we're on the right bp
                Assert.Equal("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value <string> ());

                var top_frame = pause_location ["callFrames"][0];

                var scope = top_frame ["scopeChain"][0];
                Assert.Equal("dotnet:scope:0", scope ["object"]["objectId"]);

                //ok, what's on that scope?
                var get_prop_req = JObject.FromObject(new {
                    objectId = "dotnet:scope:0",
                });

                var frame_props = await cli.SendCommand("Runtime.getProperties", get_prop_req, token);
                if (frame_props.IsErr)
                {
                    Console.WriteLine($"frame_props: {frame_props.Error.ToString ()}");
                }
                Assert.True(frame_props.IsOk);

                var locals = frame_props.Value ["result"];
                if (test_fn != null)
                {
                    test_fn(locals);
                }
            });
        }
Exemple #4
0
        public async Task CreateGoodBreakpointAndHit()
        {
            var insp = new Inspector();

            //Collect events
            var scripts = SubscribeToScripts(insp);

            await Ready();

            await insp.Ready(async (cli, token) => {
                var bp1_req = JObject.FromObject(new {
                    lineNumber   = 5,
                    columnNumber = 2,
                    url          = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"],
                });

                var bp1_res = await cli.SendCommand("Debugger.setBreakpointByUrl", bp1_req, token);
                Assert.True(bp1_res.IsOk);

                var eval_req = JObject.FromObject(new {
                    expression = "window.setTimeout(function() { invoke_add(); }, 1);",
                });

                var eval_res = await cli.SendCommand("Runtime.evaluate", eval_req, token);
                Assert.True(eval_res.IsOk);

                var pause_location = await insp.WaitFor(Inspector.PAUSE);

                Assert.Equal("other", pause_location ["reason"]?.Value <string> ());
                Assert.Equal("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value <string> ());

                var top_frame = pause_location ["callFrames"][0];

                Assert.Equal("IntAdd", top_frame ["functionName"].Value <string>());
                Assert.Contains("debugger-test.cs", top_frame ["url"].Value <string> ());

                CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, top_frame["functionLocation"]);
                CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 5, 2, scripts, top_frame["location"]);

                //now check the scope
                var scope = top_frame ["scopeChain"][0];
                Assert.Equal("local", scope ["type"]);
                Assert.Equal("IntAdd", scope ["name"]);

                Assert.Equal("object", scope ["object"]["type"]);
                Assert.Equal("dotnet:scope:0", scope ["object"]["objectId"]);
                CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, scope["startLocation"]);
                CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 9, 1, scripts, scope["endLocation"]);
            });
        }
Exemple #5
0
        public async Task RuntimeGetPropertiesWithInvalidScopeIdTest()
        {
            var insp = new Inspector();
            //Collect events
            var scripts = SubscribeToScripts(insp);

            await Ready();

            await insp.Ready(async (cli, token) => {
                var bp_req = JObject.FromObject(new {
                    lineNumber   = 41,
                    columnNumber = 2,
                    url          = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"],
                });

                var bp_res = await cli.SendCommand("Debugger.setBreakpointByUrl", bp_req, token);
                Assert.True(bp_res.IsOk);
                var eval_req = JObject.FromObject(new {
                    expression = "window.setTimeout(function() { invoke_delegates_test (); }, 1);",
                });
                var eval_res = await cli.SendCommand("Runtime.evaluate", eval_req, token);
                Assert.True(eval_res.IsOk);
                var pause_location = await insp.WaitFor(Inspector.PAUSE);

                //make sure we're on the right bp
                Assert.Equal("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value <string> ());

                var top_frame = pause_location ["callFrames"][0];

                var scope = top_frame ["scopeChain"][0];
                Assert.Equal("dotnet:scope:0", scope ["object"]["objectId"]);

                // Try to get an invalid scope!
                var get_prop_req = JObject.FromObject(new {
                    objectId = "dotnet:scope:23490871",
                });

                var frame_props = await cli.SendCommand("Runtime.getProperties", get_prop_req, token);
                Assert.True(frame_props.IsErr);
            });
        }
Exemple #6
0
        public async Task InspectLocalsDuringStepping()
        {
            var insp = new Inspector();
            //Collect events
            var scripts = SubscribeToScripts(insp);

            await Ready();

            await insp.Ready(async (cli, token) => {
                var bp1_req = JObject.FromObject(new {
                    lineNumber   = 4,
                    columnNumber = 2,
                    url          = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"],
                });

                var bp1_res = await cli.SendCommand("Debugger.setBreakpointByUrl", bp1_req, token);
                Assert.True(bp1_res.IsOk);

                var eval_req = JObject.FromObject(new {
                    expression = "window.setTimeout(function() { invoke_add(); }, 1);",
                });

                var eval_res = await cli.SendCommand("Runtime.evaluate", eval_req, token);
                Assert.True(eval_res.IsOk);

                var pause_location = await insp.WaitFor(Inspector.PAUSE);

                //ok, what's on that scope?
                var get_prop_req = JObject.FromObject(new {
                    objectId = "dotnet:scope:0",
                });

                var frame_props = await cli.SendCommand("Runtime.getProperties", get_prop_req, token);
                Assert.True(frame_props.IsOk);
                var locals = frame_props.Value ["result"];
                CheckNumber(locals, "a", 10);
                CheckNumber(locals, "b", 20);
                CheckNumber(locals, "c", 0);
                CheckNumber(locals, "d", 0);
                CheckNumber(locals, "e", 0);

                //step and get locals
                var step_res = await cli.SendCommand("Debugger.stepOver", null, token);
                Assert.True(step_res.IsOk);
                pause_location = await insp.WaitFor(Inspector.PAUSE);
                frame_props    = await cli.SendCommand("Runtime.getProperties", get_prop_req, token);
                Assert.True(frame_props.IsOk);

                locals = frame_props.Value ["result"];
                CheckNumber(locals, "a", 10);
                CheckNumber(locals, "b", 20);
                CheckNumber(locals, "c", 30);
                CheckNumber(locals, "d", 0);
                CheckNumber(locals, "e", 0);

                //step and get locals
                step_res = await cli.SendCommand("Debugger.stepOver", null, token);
                Assert.True(step_res.IsOk);
                pause_location = await insp.WaitFor(Inspector.PAUSE);
                frame_props    = await cli.SendCommand("Runtime.getProperties", get_prop_req, token);
                Assert.True(frame_props.IsOk);

                locals = frame_props.Value ["result"];
                CheckNumber(locals, "a", 10);
                CheckNumber(locals, "b", 20);
                CheckNumber(locals, "c", 30);
                CheckNumber(locals, "d", 50);
                CheckNumber(locals, "e", 0);
            });
        }
Exemple #7
0
        public async Task ExceptionThrownInJSOutOfBand()
        {
            var insp = new Inspector();

            //Collect events
            var scripts = SubscribeToScripts(insp);

            await Ready();

            await insp.Ready(async (cli, token) => {
                var bp1_req = JObject.FromObject(new {
                    lineNumber   = 27,
                    columnNumber = 2,
                    url          = dicFileToUrl["/debugger-driver.html"],
                });

                var bp1_res = await cli.SendCommand("Debugger.setBreakpointByUrl", bp1_req, token);
                Assert.True(bp1_res.IsOk);

                var eval_req = JObject.FromObject(new {
                    expression = "window.setTimeout(function() { invoke_bad_js_test(); }, 1);",
                });

                var eval_res = await cli.SendCommand("Runtime.evaluate", eval_req, token);
                // Response here will be the id for the timer from JS!
                Assert.True(eval_res.IsOk);

                var ex      = await Assert.ThrowsAsync <ArgumentException> (async() => await insp.WaitFor("Runtime.exceptionThrown"));
                var ex_json = JObject.Parse(ex.Message);
                Assert.Equal(dicFileToUrl["/debugger-driver.html"], ex_json ["exceptionDetails"]? ["url"]? .Value <string> ());
            });
        }