[build] Roslyn switch
[mono.git] / mcs / class / Mono.Debugger.Soft / Test / dtest.cs
index c0af12cb38ac15d9f023d11cfffa62408e2fb559..05896473e395ffdeead91a2a52ee74b64e90f198 100644 (file)
@@ -69,9 +69,17 @@ public class DebuggerTests
                if (!listening) {
                        var pi = new Diag.ProcessStartInfo ();
 
-                       if (runtime != null)
+                       if (runtime != null) {
                                pi.FileName = runtime;
-                       else
+                       } else if (Path.DirectorySeparatorChar == '\\') {
+                               string processExe = Diag.Process.GetCurrentProcess ().MainModule.FileName;
+                               if (processExe != null) {
+                                       string fileName = Path.GetFileName (processExe);
+                                       if (fileName.StartsWith ("mono") && fileName.EndsWith (".exe"))
+                                               pi.FileName = processExe;
+                               }
+                       }
+                       if (string.IsNullOrEmpty (pi.FileName))
                                pi.FileName = "mono";
                        pi.Arguments = String.Join (" ", args);
                        vm = VirtualMachineManager.Launch (pi, new LaunchOptions { AgentArgs = agent_args });
@@ -550,7 +558,11 @@ public class DebuggerTests
                MethodMirror m = entry_point.DeclaringType.Assembly.GetType ("LocalReflectClass").GetMethod ("RunMe");
 
                Assert.IsNotNull (m);
-               //Console.WriteLine ("X: " + name + " " + m.ILOffsets.Count + " " + m.Locations.Count);
+
+//             foreach (var x in m.Locations) {
+//                     Console.WriteLine (x);
+//             }
+
                var offset = -1;
                int method_base_linum = m.Locations [0].LineNumber;
                foreach (var location in m.Locations)
@@ -578,7 +590,11 @@ public class DebuggerTests
                e = single_step (e.Thread);
 
                var frame = e.Thread.GetFrames ()[0];
-               Value variable = frame.GetValue (frame.Method.GetLocal ("reflectMe"));
+
+               Assert.IsNotNull (frame);
+               var field = frame.Method.GetLocal ("reflectMe");
+               Assert.IsNotNull (field);
+               Value variable = frame.GetValue (field);
 
                ObjectMirror thisObj = (ObjectMirror)variable;
                TypeMirror thisType = thisObj.Type;
@@ -592,6 +608,7 @@ public class DebuggerTests
        }
 
        [Test]
+       [Category ("NotWorking")] // https://bugzilla.xamarin.com/show_bug.cgi?id=44974
        public void SingleStepping () {
                Event e = run_until ("single_stepping");
 
@@ -890,6 +907,28 @@ public class DebuggerTests
                req.Disable ();
        }
 
+       [Test]
+       public void SingleSteppingNoFrames () {
+               //
+               // Test what happens when starting a single step operation on a thread
+               // with no managed frames
+               //
+               // Run a delegate on a tp thread
+               var e = run_until ("ss_no_frames_2");
+
+               var this_type = e.Thread.GetFrames ()[0].Method.DeclaringType;
+               this_type.SetValue (this_type.GetField ("static_i"), vm.CreateValue (56));
+
+               var thread = e.Thread;
+               var e2 = run_until ("ss_no_frames_3");
+               // The tp thread should be idle now
+               step_req = vm.CreateStepRequest (thread);
+               step_req.Depth = StepDepth.Over;
+               AssertThrows<Exception> (delegate {
+                       step_req.Enable ();
+                       });
+       }
+
        [Test]
        public void MethodEntryExit () {
                run_until ("single_stepping");
@@ -1767,6 +1806,16 @@ public class DebuggerTests
                AssertValue ("T", s ["s"]);
                AssertValue (45, s ["k"]);
 
+               // Test SetThis ()
+               s ["i"] = vm.CreateValue (55);
+               frame.SetThis (s);
+               obj = frame.GetThis ();
+               Assert.IsTrue (obj is StructMirror);
+               s = obj as StructMirror;
+               AssertValue (55, s ["i"]);
+               AssertValue ("T", s ["s"]);
+               AssertValue (45, s ["k"]);
+
                // this on static vtype methods
                e = run_until ("vtypes3");
                e = step_until (e.Thread, "static_foo");
@@ -1846,6 +1895,9 @@ public class DebuggerTests
                                Assert.Fail ();
                        }
                }
+
+               var scopes = frame.Method.GetScopes ();
+               Assert.AreEqual (2, scopes.Length);
        }
 
        Event step_once () {
@@ -2447,7 +2499,6 @@ public class DebuggerTests
                        Assert.AreEqual ("Exception", ex.Exception.Type.Name);
                }
 
-#if NET_4_5
                // out argument
                m = t.GetMethod ("invoke_out");
                var out_task = this_obj.InvokeMethodAsyncWithResult (e.Thread, m, new Value [] { vm.CreateValue (1), vm.CreateValue (null) }, InvokeOptions.ReturnOutArgs);
@@ -2460,7 +2511,6 @@ public class DebuggerTests
                out_task = this_obj.InvokeMethodAsyncWithResult (e.Thread, m, new Value [] { vm.CreateValue (1), vm.CreateValue (null) });
                out_args = out_task.Result.OutArgs;
                Assert.IsNull (out_args);
-#endif
 
                // newobj
                m = t.GetMethod (".ctor");
@@ -2484,7 +2534,6 @@ public class DebuggerTests
                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");
                var task = this_obj.InvokeMethodAsync (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") });
@@ -2494,7 +2543,6 @@ public class DebuggerTests
                m = t.GetMethod ("invoke_static_pass_ref");
                task = t.InvokeMethodAsync (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") });
                AssertValue ("ABC", task.Result);
-#endif
 
                // Argument checking
                
@@ -2588,7 +2636,6 @@ public class DebuggerTests
                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;
                t = s.Type;
@@ -2615,7 +2662,6 @@ public class DebuggerTests
                m = vm.RootDomain.Corlib.GetType ("System.Object").GetMethod ("ToString");
                v = s.InvokeMethod (e.Thread, m, null, InvokeOptions.Virtual);
                AssertValue ("42", v);
-#endif
        }
 
        [Test]
@@ -3300,6 +3346,9 @@ public class DebuggerTests
                        vm.Resume ();
                        e = GetNextEvent ();
                        if (e is AssemblyUnloadEvent) {
+                               AssertThrows<Exception> (delegate () {
+                                               var assembly_obj = (e as AssemblyUnloadEvent).Assembly.GetAssemblyObject ();
+                                       });
                                continue;
                        } else {
                                break;
@@ -3578,6 +3627,8 @@ public class DebuggerTests
                        return;
 
                string srcfile = (e as BreakpointEvent).Method.DeclaringType.GetSourceFiles (true)[0];
+               srcfile = srcfile.Replace ("dtest-app.cs", "TypeLoadClass.cs");
+               Assert.IsTrue (srcfile.Contains ("TypeLoadClass.cs"));
 
                var req = vm.CreateTypeLoadRequest ();
                req.SourceFileFilter = new string [] { srcfile.ToUpper () };
@@ -3790,7 +3841,6 @@ public class DebuggerTests
                vm = null;
        }
 
-#if NET_4_5
        [Test]
        public void UnhandledExceptionUserCode () {
                vm.Detach ();
@@ -3811,7 +3861,6 @@ public class DebuggerTests
                vm.Exit (0);
                vm = null;
        }
-#endif
 
        [Test]
        public void GCWhileSuspended () {
@@ -3960,7 +4009,8 @@ public class DebuggerTests
                req.Disable ();
                var frames = e.Thread.GetFrames ();
                var locs = frames [0].Method.Locations;
-               var next_loc = locs.First (l => (l.LineNumber == frames [0].Location.LineNumber + 2));
+
+               var next_loc = locs.First (l => (l.LineNumber == frames [0].Location.LineNumber + 3));
 
                e.Thread.SetIP (next_loc);
 
@@ -3993,7 +4043,7 @@ public class DebuggerTests
                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));
+               var prev_loc = locs.First (l => (l.LineNumber == frames [0].Location.LineNumber - 1));
                AssertValue (2, frames [0].GetValue (frames [0].Method.GetLocal ("i")));
 
                // Set back the ip to the first i ++; line
@@ -4035,6 +4085,22 @@ public class DebuggerTests
                // Make sure we are still in the cctor
                Assert.AreEqual (".cctor", e.Thread.GetFrames ()[0].Location.Method.Name);
        }
+
+       [Test]
+       public void ThreadpoolIOsinglestep () {
+               TearDown ();
+               Start ("dtest-app.exe", "threadpool-io");
+               // This is a regression test for #42625.  It tests the
+               // interaction (particularly in coop GC) of the
+               // threadpool I/O mechanism and the soft debugger.
+               Event e = run_until ("threadpool_io");
+               // run until we sent the task half the bytes it
+               // expects, so that it blocks waiting for the rest.
+               e = run_until ("threadpool_bp");
+               var req = create_step (e);
+               e = step_out (); // leave threadpool_bp
+               e = step_out (); // leave threadpool_io
+       }
 }
 
 }