Revert "[sdb] Disallow nested invokes."
[mono.git] / mcs / class / Mono.Debugger.Soft / Test / dtest.cs
index 9a671202a82027cf99d0b9ded34611eb72772d33..0b47f1fbeb2c75de4f83067cd1412c5298cd8c63 100644 (file)
@@ -383,6 +383,52 @@ public class DebuggerTests
                return req;
        }
 
+       [Test]
+       public void ClassLocalReflection () {
+               MethodMirror m = entry_point.DeclaringType.Assembly.GetType ("LocalReflectClass").GetMethod ("RunMe");
+
+               Assert.IsNotNull (m);
+               //Console.WriteLine ("X: " + name + " " + m.ILOffsets.Count + " " + m.Locations.Count);
+               var offset = -1;
+               int method_base_linum = m.Locations [0].LineNumber;
+               foreach (var location in m.Locations)
+                       if (location.LineNumber == method_base_linum + 2) {
+                               offset = location.ILOffset;
+                               break;
+                       }
+
+               var req = vm.SetBreakpoint (m, offset);
+
+               Event e = null;
+
+               while (true) {
+                       vm.Resume ();
+                       e = GetNextEvent ();
+                       if (e is BreakpointEvent)
+                               break;
+               }
+
+               req.Disable ();
+
+               Assert.IsInstanceOfType (typeof (BreakpointEvent), e);
+               Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
+
+               e = single_step (e.Thread);
+
+               var frame = e.Thread.GetFrames ()[0];
+               Value variable = frame.GetValue (frame.Method.GetLocal ("reflectMe"));
+
+               ObjectMirror thisObj = (ObjectMirror)variable;
+               TypeMirror thisType = thisObj.Type;
+               FieldInfoMirror thisFi = null;
+               foreach (var fi in thisType.GetFields ())
+                       if (fi.Name == "someField")
+                               thisFi = fi;
+
+               var gotVal = thisObj.GetValue (thisFi);
+               // If we got this far, we're good.
+       }
+
        [Test]
        public void SingleStepping () {
                Event e = run_until ("single_stepping");
@@ -420,6 +466,10 @@ public class DebuggerTests
                e = step_out ();
                assert_location (e, "single_stepping");
 
+               // Step into next line
+               e = step_into ();
+               assert_location (e, "single_stepping");
+
                // Step into ss3_2 ()
                e = step_into ();
                assert_location (e, "ss3_2");
@@ -522,7 +572,11 @@ public class DebuggerTests
                e = step_over ();
                assert_location (e, "ss_nested");
                e = step_into ();
-               assert_location (e, "ss_nested_3");
+               assert_location (e, "ss_nested_1");
+               e = step_into ();
+               assert_location (e, "ss_nested_1");
+               e = step_into ();
+               assert_location (e, "ss_nested");
                req.Disable ();
 
                // Check DebuggerStepThrough support
@@ -1134,6 +1188,10 @@ public class DebuggerTests
                Assert.IsTrue (t.IsEnum);
                Assert.AreEqual ("Int32", t.EnumUnderlyingType.Name);
 
+               // TypedReferences
+               t = frame.Method.GetParameters ()[11].ParameterType;
+               Assert.AreEqual ("TypedReference", t.Name);
+
                // properties
                t = frame.Method.GetParameters ()[7].ParameterType;
 
@@ -1425,6 +1483,10 @@ public class DebuggerTests
                AssertValue (2, s ["i"]);
                AssertValue ("S2", s ["s"]);
 
+               // typedbyref
+               var typedref = frame.GetArgument (2) as StructMirror;
+               Assert.IsTrue (typedref is StructMirror);
+
                // Argument checking
                s = frame.GetArgument (0) as StructMirror;
                AssertThrows<ArgumentException> (delegate () {
@@ -1503,8 +1565,8 @@ public class DebuggerTests
                StackFrame frame = e.Thread.GetFrames () [0];
 
                var locals = frame.Method.GetLocals ();
-               Assert.AreEqual (8, locals.Length);
-               for (int i = 0; i < 8; ++i) {
+               Assert.AreEqual (9, locals.Length);
+               for (int i = 0; i < 9; ++i) {
                        if (locals [i].Name == "args") {
                                Assert.IsTrue (locals [i].IsArg);
                                Assert.AreEqual ("String[]", locals [i].Type.Name);
@@ -1528,6 +1590,7 @@ public class DebuggerTests
                                Assert.IsTrue (locals [i].IsArg);
                                Assert.AreEqual ("String", locals [i].Type.Name);
                        } else if (locals [i].Name == "astruct") {
+                       } else if (locals [i].Name == "alist") {
                        } else {
                                Assert.Fail ();
                        }
@@ -1612,6 +1675,8 @@ public class DebuggerTests
                                AssertValue ("AB", vals [i]);
                        if (locals [i].Name == "t")
                                AssertValue ("ABC", vals [i]);
+                       if (locals [i].Name == "alist") {
+                       }
                }
 
                // Argument checking
@@ -2137,6 +2202,16 @@ public class DebuggerTests
                v = this_obj.InvokeMethod (e.Thread, m, null);
                AssertValue (42, v);
 
+               // virtual call
+               m = t.BaseType.GetMethod ("virtual_method");
+               v = this_obj.InvokeMethod (e.Thread, m, null, InvokeOptions.Virtual);
+               AssertValue ("V2", v);
+
+               // virtual call on static method
+               m = t.GetMethod ("invoke_static_pass_ref");
+               v = t.InvokeMethod (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") }, InvokeOptions.Virtual);
+               AssertValue ("ABC", v);
+
 #if NET_4_5
                // instance
                m = t.GetMethod ("invoke_pass_ref");
@@ -2211,6 +2286,12 @@ public class DebuggerTests
                v = s.InvokeMethod (e.Thread, m, null);
                AssertValue (42, v);
 
+               // Pass boxed struct as this
+               var boxed_this = t.NewInstance () as ObjectMirror;
+               m = t.GetMethod ("invoke_return_int");
+               v = boxed_this.InvokeMethod (e.Thread, m, null);
+               AssertValue (0, v);
+
                // Pass struct as this, receive intptr
                m = t.GetMethod ("invoke_return_intptr");
                v = s.InvokeMethod (e.Thread, m, null);
@@ -2228,6 +2309,13 @@ public class DebuggerTests
                v = s.InvokeMethod (e.Thread, m, null);
                AssertValue (42, v);
 
+               // .ctor
+               s = frame.GetArgument (1) as StructMirror;
+               t = s.Type;
+               m = t.GetMethods ().First (method => method.Name == ".ctor" && method.GetParameters ().Length == 1);
+               v = t.InvokeMethod (e.Thread, m, new Value [] { vm.CreateValue (1) });
+               AssertValue (1, (v as StructMirror)["i"]);
+
 #if NET_4_5
                // Invoke a method which changes state
                s = frame.GetArgument (1) as StructMirror;
@@ -2244,6 +2332,17 @@ public class DebuggerTests
                task = s.InvokeMethodAsyncWithResult (e.Thread, m, null);
                out_this = task.Result.OutThis as StructMirror;
                Assert.AreEqual (null, out_this);
+
+               // interface method
+               var cl1 = frame.Method.DeclaringType.Assembly.GetType ("ITest2");
+               m = cl1.GetMethod ("invoke_iface");
+               v = s.InvokeMethod (e.Thread, m, null);
+               AssertValue (42, v);
+
+               // virtual method
+               m = vm.RootDomain.Corlib.GetType ("System.Object").GetMethod ("ToString");
+               v = s.InvokeMethod (e.Thread, m, null, InvokeOptions.Virtual);
+               AssertValue ("42", v);
 #endif
        }
 
@@ -2864,8 +2963,10 @@ public class DebuggerTests
 
                var frames = e.Thread.GetFrames ();
                Assert.AreEqual ("invoke_in_domain", frames [0].Method.Name);
+               Assert.AreEqual (domain, frames [0].Domain);
                Assert.AreEqual ("invoke", frames [1].Method.Name);
                Assert.AreEqual ("domains", frames [2].Method.Name);
+               Assert.AreEqual (vm.RootDomain, frames [2].Domain);
 
                // Test breakpoints on already JITted methods in other domains
                m = entry_point.DeclaringType.GetMethod ("invoke_in_domain_2");
@@ -2905,6 +3006,13 @@ public class DebuggerTests
                AssertThrows<Exception> (delegate {
                                d_method.DeclaringType.GetValue (d_method.DeclaringType.GetField ("static_i"));
                        });
+
+               // Check that .Domain is accessible for stack frames with native transitions
+               e = run_until ("called_from_invoke");
+               ThreadMirror.NativeTransitions = true;
+               foreach (var f in e.Thread.GetFrames ()) {
+                       var dom = f.Domain;
+               }
        }
 
        [Test]
@@ -3211,6 +3319,20 @@ public class DebuggerTests
                Assert.AreEqual ("System.Exception", types [0].FullName);
        }
 
+       [Test]
+       public void String_GetValue () {
+               // Embedded nulls
+               object val;
+
+               // Reuse this test
+               var e = run_until ("arg2");
+
+               var frame = e.Thread.GetFrames () [0];
+
+               val = frame.GetArgument (6);
+               Assert.AreEqual ('\0'.ToString () + "A", (val as StringMirror).Value);
+       }
+
        [Test]
        public void String_GetChars () {
                object val;
@@ -3529,10 +3651,10 @@ public class DebuggerTests
 
                e.Thread.SetIP (next_loc);
 
-               /* Check that i = 5; j = 5; was skipped */
+               /* Check that i ++; j = 5; was skipped */
                bevent = run_until ("set_ip_2");
                var f = bevent.Thread.GetFrames ()[1];
-               AssertValue (1, f.GetValue (f.Method.GetLocal ("i")));
+               AssertValue (2, f.GetValue (f.Method.GetLocal ("i")));
                AssertValue (0, f.GetValue (f.Method.GetLocal ("j")));
 
                // Error handling
@@ -3545,6 +3667,30 @@ public class DebuggerTests
                        });
        }
 
+       [Test]
+       public void SetIPSingleStep () {
+               // Check that single stepping after set-ip steps from the new ip
+               var bevent = run_until ("set_ip_1");
+
+               var invalid_loc = bevent.Thread.GetFrames ()[0].Location;
+
+               var req = create_step (bevent);
+               req.Size = StepSize.Line;
+               var e = step_out ();
+               req.Disable ();
+               var frames = e.Thread.GetFrames ();
+               var locs = frames [0].Method.Locations;
+               var prev_loc = locs.First (l => (l.LineNumber == frames [0].Location.LineNumber - 3));
+               AssertValue (2, frames [0].GetValue (frames [0].Method.GetLocal ("i")));
+
+               // Set back the ip to the first i ++; line
+               e.Thread.SetIP (prev_loc);
+
+               e = step_over ();
+               var f = e.Thread.GetFrames ()[0];
+               AssertValue (3, f.GetValue (f.Method.GetLocal ("i")));
+       }
+
        [Test]
        public void NewInstanceNoCtor () {
                var bevent = run_until ("Main");
@@ -3554,6 +3700,28 @@ public class DebuggerTests
                Assert.IsTrue (obj is ObjectMirror);
                Assert.AreEqual ("AStruct", (obj as ObjectMirror).Type.Name);
        }
+
+       [Test]
+       public void StaticCtorFilterInCctor () {
+               // Check that single stepping when in a cctor only ignores
+               // other cctors, not the current one
+               var bevent = run_until ("step_filters");
+
+               var assembly = entry_point.DeclaringType.Assembly;
+               var type = assembly.GetType ("Tests/ClassWithCctor");
+               var cctor = type.GetMethod (".cctor");
+               vm.SetBreakpoint (cctor, 0);
+
+               vm.Resume ();
+               var e = vm.GetNextEvent ();
+               Assert.IsTrue (e is BreakpointEvent);
+
+               var req = create_step (e);
+               req.Filter = StepFilter.StaticCtor;
+               e = step_into ();
+               // Make sure we are still in the cctor
+               Assert.AreEqual (".cctor", e.Thread.GetFrames ()[0].Location.Method.Name);
+       }
 }
 
 }