public static string runtime = Environment.GetEnvironmentVariable ("DBG_RUNTIME");
public static string agent_args = Environment.GetEnvironmentVariable ("DBG_AGENT_ARGS");
+ // Not currently used, but can be useful when debugging individual tests.
+ void StackTraceDump (Event e)
+ {
+ int i = 0;
+ foreach (var frame in e.Thread.GetFrames ())
+ {
+ i++;
+ Console.WriteLine ("Frame " + i + ", " + frame.Method.Name);
+ }
+ }
+
Event GetNextEvent () {
var es = vm.GetNextEventSet ();
Assert.AreEqual (1, es.Events.Length);
return (e as BreakpointEvent);
}
+ class ReusableBreakpoint {
+ DebuggerTests owner;
+ public string method_name;
+ public BreakpointEventRequest req;
+ public BreakpointEvent lastEvent = null;
+ public ReusableBreakpoint (DebuggerTests owner, string method_name)
+ {
+ this.owner = owner;
+ this.method_name = method_name;
+ MethodMirror m = owner.entry_point.DeclaringType.GetMethod (method_name);
+ Assert.IsNotNull (m);
+ req = owner.vm.SetBreakpoint (m, m.ILOffsets [0]);
+ }
+
+ public void Continue ()
+ {
+ bool survived = false;
+
+ try {
+ Event e = null;
+
+ while (true) {
+ owner.vm.Resume ();
+ e = owner.GetNextEvent ();
+ if (e is BreakpointEvent)
+ break;
+ }
+
+ Assert.IsInstanceOfType (typeof (BreakpointEvent), e);
+ Assert.AreEqual (method_name, (e as BreakpointEvent).Method.Name);
+
+ lastEvent = e as BreakpointEvent;
+
+ survived = true;
+ } finally {
+ if (!survived) { // Ensure cleanup if we triggered an assert
+ Disable ();
+ }
+ }
+ }
+
+ public void Disable ()
+ {
+ req.Disable ();
+ }
+ }
+
+ /* One of the tests executes a complex tree of recursive functions.
+ The only good way to specify how its behavior should appear from this side
+ is to just run the function tree once over here and record what it does. */
+ public struct RecursiveChaoticPoint
+ {
+ public bool breakpoint;
+ public string name;
+ public int depth;
+
+ public RecursiveChaoticPoint (bool breakpoint, string name, int depth)
+ {
+ this.breakpoint = breakpoint;
+ this.name = name;
+ this.depth = depth;
+ }
+ }
+
+ // The breakpoint is placed here in dtest-app.cs
+ public static void ss_recursive_chaotic_trap (int n, List<RecursiveChaoticPoint> trace, ref bool didLast, ref bool didAny)
+ {
+ // Depth is calculated as:
+ // Main + single_stepping + ss_recursive_chaotic + (n is 5 at outermost frame and 0 at innermost frame) + ss_recursive_chaotic_trap
+ trace.Add (new RecursiveChaoticPoint (true, "ss_recursive_chaotic_trap", 5 - n + 5));
+ didLast = true;
+ }
+
+ public static void ss_recursive_chaotic_at (string at, int n, List<RecursiveChaoticPoint> trace, ref bool didLast, ref bool didAny)
+ {
+ // This will be called after every return from a function. The other function will return whether "step out" is currently active, and it will be passed in here as didLast.
+ if (didLast) {
+ // Depth is calculated as:
+ // Main + single_stepping + ss_recursive_chaotic + (n is 5 at outermost frame and 0 at innermost frame)
+ trace.Add (new RecursiveChaoticPoint (false, "ss_recursive_chaotic_" + at, 5 - n + 4));
+ didAny = true;
+ didLast = false;
+ }
+ }
+
+ public static bool ss_recursive_chaotic_fizz (int n, List<RecursiveChaoticPoint> trace)
+ {
+ bool didLast = false, didAny = false;
+ if (n > 0) {
+ int next = n - 1;
+ didLast = ss_recursive_chaotic_buzz (next, trace);
+ ss_recursive_chaotic_at ("fizz", n, trace, ref didLast, ref didAny);
+ didLast = ss_recursive_chaotic_fizzbuzz (next, trace);
+ ss_recursive_chaotic_at ("fizz", n, trace, ref didLast, ref didAny);
+ } else {
+ ss_recursive_chaotic_trap (n, trace, ref didLast, ref didAny);
+ ss_recursive_chaotic_at ("fizz", n, trace, ref didLast, ref didAny);
+ }
+ return didAny;
+ }
+
+ public static bool ss_recursive_chaotic_buzz (int n, List<RecursiveChaoticPoint> trace)
+ {
+ bool didLast = false, didAny = false;
+ if (n > 0) {
+ int next = n - 1;
+ didLast = ss_recursive_chaotic_fizz (next, trace);
+ ss_recursive_chaotic_at ("buzz", n, trace, ref didLast, ref didAny);
+ didLast = ss_recursive_chaotic_fizzbuzz (next, trace);
+ ss_recursive_chaotic_at ("buzz", n, trace, ref didLast, ref didAny);
+ }
+ return didAny;
+ }
+
+ public static bool ss_recursive_chaotic_fizzbuzz (int n, List<RecursiveChaoticPoint> trace)
+ {
+ bool didLast = false, didAny = false;
+ if (n > 0) {
+ int next = n - 1;
+ didLast = ss_recursive_chaotic_fizz (next, trace);
+ ss_recursive_chaotic_at ("fizzbuzz", n, trace, ref didLast, ref didAny);
+ didLast = ss_recursive_chaotic_buzz (next, trace);
+ ss_recursive_chaotic_at ("fizzbuzz", n, trace, ref didLast, ref didAny);
+ didLast = ss_recursive_chaotic_fizzbuzz (next, trace);
+ ss_recursive_chaotic_at ("fizzbuzz", n, trace, ref didLast, ref didAny);
+ }
+ return didAny;
+ }
+
+ public static void trace_ss_recursive_chaotic (List<RecursiveChaoticPoint> trace)
+ {
+ ss_recursive_chaotic_fizz (5, trace);
+ }
+
Event single_step (ThreadMirror t) {
var req = vm.CreateStepRequest (t);
req.Enable ();
Assert.AreEqual (m2.Name, (e as BreakpointEvent).Method.Name);
}
+ // Assert we have stepped to a location
void assert_location (Event e, string method) {
Assert.IsTrue (e is StepEvent);
Assert.AreEqual (method, (e as StepEvent).Method.Name);
}
+ // Assert we have breakpointed at a location
+ void assert_location_at_breakpoint (Event e, string method) {
+ Assert.IsTrue (e is BreakpointEvent);
+ Assert.AreEqual (method, (e as BreakpointEvent).Method.Name);
+ }
+
+ // Assert we have stepped to or breakpointed at a location
+ void assert_location_allow_breakpoint (Event e, string method) {
+ if (e is StepEvent)
+ Assert.AreEqual (method, (e as StepEvent).Method.Name);
+ else if (e is BreakpointEvent)
+ Assert.AreEqual (method, (e as BreakpointEvent).Method.Name);
+ else
+ Assert.Fail ("Neither step nor breakpoint event");
+ }
+
StepEventRequest create_step (Event e) {
var req = vm.CreateStepRequest (e.Thread);
step_req = req;
AssertValue (1, f.GetValue (f.Method.GetLocal ("n")));
req.Disable ();
+ // Check that step-over stops correctly when inner frames with recursive functions contain breakpoints
+ e = run_until ("ss_recursive2");
+ ReusableBreakpoint breakpoint = new ReusableBreakpoint (this, "ss_recursive2_trap");
+ try {
+ breakpoint.Continue ();
+ e = breakpoint.lastEvent;
+ req = create_step (e);
+ for (int c = 1; c <= 4; c++) {
+ // The first five times we try to step over this function, the breakpoint will stop us
+ assert_location_at_breakpoint (e, "ss_recursive2_trap");
+
+ req.Disable ();
+ req = create_step (e);
+ req.Size = StepSize.Line;
+
+ e = step_out ();
+ assert_location (e, "ss_recursive2");
+
+ // Stack should consist of Main + single_stepping + (1 ss_recursive2 frame per loop iteration)
+ Assert.AreEqual (c+2, e.Thread.GetFrames ().Length);
+ e = step_over_or_breakpoint ();
+ }
+ // At this point we should have escaped the breakpoints and this will be a normal step stop
+ assert_location (e, "ss_recursive2");
+ Assert.AreEqual (6, e.Thread.GetFrames ().Length);
+ } finally {
+ req.Disable ();
+ breakpoint.Disable ();
+ }
+
+ // Check that step-out stops correctly when inner frames with recursive functions contain breakpoints
+ e = run_until ("ss_recursive2");
+ breakpoint = new ReusableBreakpoint (this, "ss_recursive2_trap");
+ try {
+ breakpoint.Continue ();
+ e = breakpoint.lastEvent;
+ req = create_step (e);
+ for (int c = 1; c <= 4; c++) {
+ // The first five times we try to step over this function, the breakpoint will stop us
+ assert_location_at_breakpoint (e, "ss_recursive2_trap");
+
+ req.Disable ();
+ req = create_step (e);
+ req.Size = StepSize.Line;
+
+ e = step_out ();
+ assert_location (e, "ss_recursive2");
+
+ // Stack should consist of Main + single_stepping + (1 ss_recursive2 frame per loop iteration)
+ Assert.AreEqual (c+2, e.Thread.GetFrames ().Length);
+ e = step_out_or_breakpoint ();
+ }
+ for (int c = 3; c >= 1; c--) {
+ assert_location (e, "ss_recursive2");
+ Assert.AreEqual (c + 2, e.Thread.GetFrames ().Length);
+
+ e = step_out ();
+ }
+ } finally {
+ req.Disable ();
+ breakpoint.Disable ();
+ }
+
+ // Test step out with a really complicated call tree
+ List<RecursiveChaoticPoint> trace = new List<RecursiveChaoticPoint>();
+ trace_ss_recursive_chaotic (trace);
+ e = run_until ("ss_recursive_chaotic");
+ try {
+ breakpoint = new ReusableBreakpoint (this, "ss_recursive_chaotic_trap");
+ breakpoint.Continue ();
+ e = breakpoint.lastEvent;
+ foreach (RecursiveChaoticPoint point in trace)
+ {
+ if (point.breakpoint)
+ assert_location_at_breakpoint (e, point.name);
+ else
+ assert_location (e, point.name);
+ Assert.AreEqual (point.depth, e.Thread.GetFrames ().Length);
+
+ req.Disable ();
+ req = create_step (e);
+ req.Size = StepSize.Line;
+ e = step_out_or_breakpoint ();
+ }
+ } finally {
+ req.Disable ();
+ breakpoint.Disable ();
+ }
+
// Check that single stepping doesn't clobber fp values
e = run_until ("ss_fp_clobber");
req = create_step (e);
TypeMirror t = o.Type;
- Assert.AreEqual ("MonoType", t.GetTypeObject ().Type.Name);
+ Assert.AreEqual ("RuntimeType", t.GetTypeObject ().Type.Name);
}
[Test]
return step_once ();
}
+ Event step_once_or_breakpoint () {
+ vm.Resume ();
+ var e = GetNextEvent ();
+ Assert.IsTrue (e is StepEvent || e is BreakpointEvent);
+ return e;
+ }
+
+ Event step_over_or_breakpoint () {
+ step_req.Disable ();
+ step_req.Depth = StepDepth.Over;
+ step_req.Enable ();
+ return step_once_or_breakpoint ();
+ }
+
+ Event step_out_or_breakpoint () {
+ step_req.Disable ();
+ step_req.Depth = StepDepth.Out;
+ step_req.Enable ();
+ return step_once_or_breakpoint ();
+ }
+
[Test]
public void Locals () {
var be = run_until ("locals1");
}
[Test]
- public void InvokeNested () {
- Event e = run_until ("invoke1");
-
- MethodMirror m = entry_point.DeclaringType.GetMethod ("invoke2");
- Assert.IsNotNull (m);
- vm.SetBreakpoint (m, 0);
-
- StackFrame frame = e.Thread.GetFrames () [0];
- var o = frame.GetThis () as ObjectMirror;
-
- bool failed = false;
-
- bool finished = false;
- object wait = new object ();
-
- Thread t = new Thread (delegate () {
- try {
- o.InvokeMethod (e.Thread, m, null);
- } catch {
- failed = true;
- }
- lock (wait) {
- finished = true;
- Monitor.Pulse (wait);
- }
- });
+ public void InvokeAbort () {
+ vm.Detach ();
- t.Start ();
+ Start (new string [] { "dtest-app.exe", "invoke-abort" });
- StackFrame invoke_frame = null;
+ Event e = run_until ("invoke_abort");
- e = GetNextEvent ();
- Assert.IsInstanceOfType (typeof (BreakpointEvent), e);
+ StackFrame f = e.Thread.GetFrames ()[0];
- // Check that nested invokes are not allowed
- AssertThrows<VMNotSuspendedException> (delegate {
- o.InvokeMethod (e.Thread, m, null);
+ var obj = f.GetThis () as ObjectMirror;
+ var t = obj.Type;
+ var m = t.GetMethod ("invoke_abort_2");
+ // Invoke multiple times to check that the subsequent invokes are aborted too
+ var res = (IInvokeAsyncResult)obj.BeginInvokeMultiple (e.Thread, new MethodMirror[] { m, m, m, m }, null, InvokeOptions.None, delegate { }, null);
+ Thread.Sleep (500);
+ res.Abort ();
+ AssertThrows<CommandException> (delegate {
+ obj.EndInvokeMethod (res);
});
-
- vm.Resume ();
- lock (wait) {
- if (!finished)
- Monitor.Wait (wait);
- }
}
[Test]
ex.InvokeMethod (e.Thread, tostring_method, null, InvokeOptions.SingleThreaded);
}
+ [Test]
+ public void MemberInOtherDomain () {
+ vm.Detach ();
+
+ Start (new string [] { "dtest-app.exe", "domain-test" });
+
+ vm.EnableEvents (EventType.AppDomainCreate, EventType.AppDomainUnload, EventType.AssemblyUnload);
+
+ Event e = run_until ("domains_print_across");
+
+ var frame = e.Thread.GetFrames ()[0];
+ var inOtherDomain = frame.GetArgument (0) as ObjectMirror;
+ var crossDomainField = (ObjectMirror) inOtherDomain.GetValue (inOtherDomain.Type.GetField("printMe"));
+ Assert.AreEqual ("SentinelClass", crossDomainField.Type.Name);
+ }
+
[Test]
public void Domains () {
vm.Detach ();
Assert.AreEqual (ThreadState.WaitSleepJoin, thread.ThreadState, "#6");
frames = thread.GetFrames ();
- Assert.AreEqual (4, frames.Length, "#7");
- Assert.AreEqual ("WaitOne_internal", frames [0].Method.Name, "#8");
- Assert.AreEqual ("WaitOne", frames [1].Method.Name, "#8.1");
- Assert.AreEqual ("wait_one", frames [2].Method.Name, "#9");
- Assert.AreEqual ("Main", frames [3].Method.Name, "#10");
-
+ Assert.AreEqual (8, frames.Length, "#7");
+ Assert.AreEqual ("WaitOne_internal", frames [0].Method.Name, "#8.0");
+ Assert.AreEqual ("WaitOneNative", frames [1].Method.Name, "#8.1");
+ Assert.AreEqual ("InternalWaitOne", frames [2].Method.Name, "#8.2");
+ Assert.AreEqual ("WaitOne", frames [3].Method.Name, "#8.3");
+ Assert.AreEqual ("WaitOne", frames [4].Method.Name, "#8.4");
+ Assert.AreEqual ("WaitOne", frames [5].Method.Name, "#8.5");
+ Assert.AreEqual ("wait_one", frames [6].Method.Name, "#8.6");
+ Assert.AreEqual ("Main", frames [7].Method.Name, "#8.7");
var frame = frames [0];
Assert.IsTrue (frame.IsNativeTransition, "#11.1");
Assert.Fail ("Known limitation - can't get info from m2n frames");
} catch (AbsentInformationException) {}
- frame = frames [1];
+ frame = frames [3];
Assert.IsFalse (frame.IsNativeTransition, "#12.1");
var wait_one_this = frame.GetThis ();
Assert.IsNotNull (wait_one_this, "#12.2");
- frame = frames [2];
+ frame = frames [6];
var locals = frame.GetVisibleVariables ();
Assert.AreEqual (1, locals.Count, "#13.1");