2 using System.Collections.Generic;
3 using System.Threading;
5 using System.Reflection;
8 using Mono.Debugger.Soft;
9 using Diag = System.Diagnostics;
12 using System.Security.Cryptography;
14 using NUnit.Framework;
16 #pragma warning disable 0219
22 public class DebuggerTests
25 MethodMirror entry_point;
26 StepEventRequest step_req;
28 void AssertThrows<ExType> (Action del) where ExType : Exception {
36 Assert.IsTrue (thrown);
39 // No other way to pass arguments to the tests ?
40 public static bool listening = Environment.GetEnvironmentVariable ("DBG_SUSPEND") != null;
41 public static string runtime = Environment.GetEnvironmentVariable ("DBG_RUNTIME");
42 public static string agent_args = Environment.GetEnvironmentVariable ("DBG_AGENT_ARGS");
44 Event GetNextEvent () {
45 var es = vm.GetNextEventSet ();
46 Assert.AreEqual (1, es.Events.Length);
50 void Start (string[] args) {
52 var pi = new Diag.ProcessStartInfo ();
55 pi.FileName = runtime;
58 pi.Arguments = String.Join (" ", args);
59 vm = VirtualMachineManager.Launch (pi, new LaunchOptions { AgentArgs = agent_args });
61 var ep = new IPEndPoint (IPAddress.Any, 10000);
62 Console.WriteLine ("Listening on " + ep + "...");
63 vm = VirtualMachineManager.Listen (ep);
66 var load_req = vm.CreateAssemblyLoadRequest ();
69 Event vmstart = GetNextEvent ();
70 Assert.AreEqual (EventType.VMStart, vmstart.EventType);
79 /* Find out the entry point */
83 if (e is AssemblyLoadEvent) {
84 AssemblyLoadEvent ae = (AssemblyLoadEvent)e;
85 entry_point = ae.Assembly.EntryPoint;
86 if (entry_point != null)
96 BreakpointEvent run_until (string name) {
98 MethodMirror m = entry_point.DeclaringType.GetMethod (name);
100 vm.SetBreakpoint (m, 0);
107 if (e is BreakpointEvent)
111 Assert.IsInstanceOfType (typeof (BreakpointEvent), e);
112 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
114 return (e as BreakpointEvent);
117 Event single_step (ThreadMirror t) {
118 var req = vm.CreateStepRequest (t);
122 Event e = GetNextEvent ();
123 Assert.IsTrue (e is StepEvent);
130 void check_arg_val (StackFrame frame, int pos, Type type, object eval) {
131 object val = frame.GetArgument (pos);
132 Assert.IsTrue (val is PrimitiveValue);
133 object v = (val as PrimitiveValue).Value;
134 Assert.AreEqual (type, v.GetType ());
136 Assert.IsTrue (Math.Abs ((float)eval - (float)v) < 0.0001);
137 else if (eval is double)
138 Assert.IsTrue (Math.Abs ((double)eval - (double)v) < 0.0001);
140 Assert.AreEqual (eval, v);
143 void AssertValue (object expected, object val) {
144 if (expected is string) {
145 Assert.IsTrue (val is StringMirror);
146 Assert.AreEqual (expected, (val as StringMirror).Value);
147 } else if (val is StructMirror && (val as StructMirror).Type.Name == "IntPtr") {
148 AssertValue (expected, (val as StructMirror).Fields [0]);
150 Assert.IsTrue (val is PrimitiveValue);
151 Assert.AreEqual (expected, (val as PrimitiveValue).Value);
156 public void SetUp () {
157 Start (new string [] { "dtest-app.exe" });
161 public void TearDown () {
165 if (step_req != null)
170 Event e = GetNextEvent ();
172 if (e is VMDeathEvent)
180 public void SimpleBreakpoint () {
183 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp1");
184 Assert.IsNotNull (m);
186 vm.SetBreakpoint (m, 0);
191 Assert.AreEqual (EventType.Breakpoint, e.EventType);
192 Assert.IsTrue (e is BreakpointEvent);
193 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
196 AssertThrows<ArgumentException> (delegate {
198 vm.SetBreakpoint (m, 2);
203 public void BreakpointsSameLocation () {
204 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp2");
205 Assert.IsNotNull (m);
207 vm.SetBreakpoint (m, 0);
208 vm.SetBreakpoint (m, 0);
212 var es = vm.GetNextEventSet ();
213 Assert.AreEqual (2, es.Events.Length);
214 Assert.IsTrue (es [0] is BreakpointEvent);
215 Assert.AreEqual (m, (es [0] as BreakpointEvent).Method);
217 Assert.IsTrue (es [1] is BreakpointEvent);
218 Assert.AreEqual (m.Name, (es [1] as BreakpointEvent).Method.Name);
222 public void BreakpointAlreadyJITted () {
223 Event e = run_until ("bp1");
225 /* Place a breakpoint on bp3 */
226 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp3");
227 Assert.IsNotNull (m);
228 vm.SetBreakpoint (m, 0);
230 /* Same with generic instances */
231 MethodMirror m2 = entry_point.DeclaringType.GetMethod ("bp7");
232 Assert.IsNotNull (m2);
233 vm.SetBreakpoint (m2, 0);
238 Assert.AreEqual (EventType.Breakpoint, e.EventType);
239 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
243 /* Non-shared instance */
245 Assert.AreEqual (EventType.Breakpoint, e.EventType);
246 Assert.AreEqual (m2.Name, (e as BreakpointEvent).Method.Name);
250 /* Shared instance */
252 Assert.AreEqual (EventType.Breakpoint, e.EventType);
253 Assert.AreEqual (m2.Name, (e as BreakpointEvent).Method.Name);
257 public void ClearBreakpoint () {
260 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp4");
261 Assert.IsNotNull (m);
262 EventRequest req1 = vm.SetBreakpoint (m, 0);
263 EventRequest req2 = vm.SetBreakpoint (m, 0);
265 MethodMirror m2 = entry_point.DeclaringType.GetMethod ("bp5");
266 Assert.IsNotNull (m2);
267 vm.SetBreakpoint (m2, 0);
272 var es = vm.GetNextEventSet ();
273 Assert.AreEqual (2, es.Events.Length);
274 Assert.AreEqual (EventType.Breakpoint, es [0].EventType);
275 Assert.AreEqual (m.Name, (es [0] as BreakpointEvent).Method.Name);
276 Assert.AreEqual (EventType.Breakpoint, es [1].EventType);
277 Assert.AreEqual (m.Name, (es [1] as BreakpointEvent).Method.Name);
279 /* Clear one of them */
285 Assert.AreEqual (EventType.Breakpoint, e.EventType);
286 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
288 /* Clear the other */
294 Assert.AreEqual (EventType.Breakpoint, e.EventType);
295 Assert.AreEqual (m2.Name, (e as BreakpointEvent).Method.Name);
299 public void ClearAllBreakpoints () {
302 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp4");
303 Assert.IsNotNull (m);
304 vm.SetBreakpoint (m, 0);
306 MethodMirror m2 = entry_point.DeclaringType.GetMethod ("bp5");
307 Assert.IsNotNull (m2);
308 vm.SetBreakpoint (m2, 0);
310 vm.ClearAllBreakpoints ();
315 Assert.IsTrue (!(e is BreakpointEvent));
316 if (e is VMDeathEvent)
321 public void BreakpointOnGShared () {
324 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp6");
325 Assert.IsNotNull (m);
327 vm.SetBreakpoint (m, 0);
332 Assert.AreEqual (EventType.Breakpoint, e.EventType);
333 Assert.IsTrue (e is BreakpointEvent);
334 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
336 // Breakpoint on an open generic method of a closed generic class (#3422)
337 var frame = e.Thread.GetFrames ()[0];
338 var ginst = frame.GetValue (frame.Method.GetLocal ("gc"));
339 var m2 = (ginst as ObjectMirror).Type.GetMethod ("bp");
340 vm.SetBreakpoint (m2, 0);
345 Assert.AreEqual (EventType.Breakpoint, e.EventType);
346 Assert.IsTrue (e is BreakpointEvent);
347 Assert.AreEqual (m2.Name, (e as BreakpointEvent).Method.Name);
351 public void SingleStepping () {
352 Event e = run_until ("single_stepping");
354 var req = vm.CreateStepRequest (e.Thread);
359 // Step over 'bool b = true'
362 Assert.IsTrue (e is StepEvent);
363 Assert.AreEqual ("single_stepping", (e as StepEvent).Method.Name);
368 Assert.IsTrue (e is StepEvent);
369 Assert.AreEqual ("ss1", (e as StepEvent).Method.Name);
374 Assert.IsTrue (e is StepEvent);
375 Assert.AreEqual ("single_stepping", (e as StepEvent).Method.Name);
377 // Change to step over
379 req.Depth = StepDepth.Over;
385 Assert.IsTrue (e is StepEvent);
386 Assert.AreEqual ("single_stepping", (e as StepEvent).Method.Name);
388 // Change to step into
390 req.Depth = StepDepth.Into;
396 Assert.IsTrue (e is StepEvent);
397 Assert.AreEqual ("ss3", (e as StepEvent).Method.Name);
399 // Change to step out
401 req.Depth = StepDepth.Out;
404 // Step back into single_stepping
407 Assert.IsTrue (e is StepEvent);
408 Assert.AreEqual ("single_stepping", (e as StepEvent).Method.Name);
410 // Change to step into
412 req.Depth = StepDepth.Into;
415 // Step into ss3_2 ()
418 Assert.IsTrue (e is StepEvent);
419 Assert.AreEqual ("ss3_2", (e as StepEvent).Method.Name);
421 // Change to step over
423 req.Depth = StepDepth.Over;
426 // Step over ss3_2_2 ()
429 Assert.IsTrue (e is StepEvent);
430 Assert.AreEqual ("ss3_2", (e as StepEvent).Method.Name);
432 // Recreate the request
436 // Step back into single_stepping () with the new request
439 Assert.IsTrue (e is StepEvent);
440 Assert.AreEqual ("single_stepping", (e as StepEvent).Method.Name);
442 // Change to step into
444 req.Depth = StepDepth.Into;
450 Assert.IsTrue (e is StepEvent);
451 Assert.AreEqual ("ss4", (e as StepEvent).Method.Name);
453 // Change to StepSize.Line
455 req.Depth = StepDepth.Over;
456 req.Size = StepSize.Line;
459 // Step over ss1 (); ss1 ();
462 Assert.IsTrue (e is StepEvent);
466 req.Depth = StepDepth.Into;
471 Assert.IsTrue (e is StepEvent);
472 Assert.AreEqual ("ss2", (e as StepEvent).Method.Name);
477 e = run_until ("ss5");
479 // Add an assembly filter
480 req.AssemblyFilter = new AssemblyMirror [] { (e as BreakpointEvent).Method.DeclaringType.Assembly };
483 // Step into is_even, skipping the linq stuff
486 Assert.IsTrue (e is StepEvent);
487 Assert.AreEqual ("is_even", (e as StepEvent).Method.Name);
489 // FIXME: Check that single stepping works with lock (obj)
494 e = run_until ("ss6");
496 req = vm.CreateStepRequest (e.Thread);
497 req.Depth = StepDepth.Over;
500 // Check that single stepping works in out-of-line bblocks
503 Assert.IsTrue (e is StepEvent);
506 Assert.IsTrue (e is StepEvent);
507 Assert.AreEqual ("ss6", (e as StepEvent).Method.Name);
510 // Check that a step over stops at an EH clause
511 e = run_until ("ss7_2");
512 req = vm.CreateStepRequest (e.Thread);
513 req.Depth = StepDepth.Out;
517 Assert.IsTrue (e is StepEvent);
518 Assert.AreEqual ("ss7", (e as StepEvent).Method.Name);
520 req = vm.CreateStepRequest (e.Thread);
521 req.Depth = StepDepth.Over;
525 Assert.IsTrue (e is StepEvent);
526 Assert.AreEqual ("ss7", (e as StepEvent).Method.Name);
531 public void MethodEntryExit () {
532 run_until ("single_stepping");
534 var req1 = vm.CreateMethodEntryRequest ();
535 var req2 = vm.CreateMethodExitRequest ();
541 Event e = GetNextEvent ();
542 Assert.IsTrue (e is MethodEntryEvent);
543 Assert.AreEqual ("ss1", (e as MethodEntryEvent).Method.Name);
547 Assert.IsTrue (e is MethodExitEvent);
548 Assert.AreEqual ("ss1", (e as MethodExitEvent).Method.Name);
555 public void CountFilter () {
556 run_until ("single_stepping");
558 MethodMirror m2 = entry_point.DeclaringType.GetMethod ("ss3");
559 Assert.IsNotNull (m2);
560 vm.SetBreakpoint (m2, 0);
562 var req1 = vm.CreateMethodEntryRequest ();
566 // Enter ss2, ss1 is skipped
568 Event e = GetNextEvent ();
569 Assert.IsTrue (e is MethodEntryEvent);
570 Assert.AreEqual ("ss2", (e as MethodEntryEvent).Method.Name);
572 // Breakpoint on ss3, the entry event is no longer reported
575 Assert.IsTrue (e is BreakpointEvent);
581 public void Arguments () {
584 var e = run_until ("arg1");
586 StackFrame frame = e.Thread.GetFrames () [0];
588 check_arg_val (frame, 0, typeof (sbyte), SByte.MaxValue - 5);
589 check_arg_val (frame, 1, typeof (byte), Byte.MaxValue - 5);
590 check_arg_val (frame, 2, typeof (bool), true);
591 check_arg_val (frame, 3, typeof (short), Int16.MaxValue - 5);
592 check_arg_val (frame, 4, typeof (ushort), UInt16.MaxValue - 5);
593 check_arg_val (frame, 5, typeof (char), 'F');
594 check_arg_val (frame, 6, typeof (int), Int32.MaxValue - 5);
595 check_arg_val (frame, 7, typeof (uint), UInt32.MaxValue - 5);
596 check_arg_val (frame, 8, typeof (long), Int64.MaxValue - 5);
597 check_arg_val (frame, 9, typeof (ulong), UInt64.MaxValue - 5);
598 check_arg_val (frame, 10, typeof (float), 1.2345f);
599 check_arg_val (frame, 11, typeof (double), 6.78910);
601 e = run_until ("arg2");
603 frame = e.Thread.GetFrames () [0];
606 val = frame.GetArgument (0);
607 AssertValue ("FOO", val);
608 Assert.AreEqual ("String", (val as ObjectMirror).Type.Name);
611 val = frame.GetArgument (1);
612 AssertValue (null, val);
615 val = frame.GetArgument (2);
616 AssertValue ("BLA", val);
619 val = frame.GetArgument (3);
620 AssertValue (42, val);
623 val = frame.GetArgument (4);
624 Assert.IsTrue (val is ObjectMirror);
625 Assert.AreEqual ("GClass`1", (val as ObjectMirror).Type.Name);
628 val = frame.GetArgument (5);
629 Assert.IsTrue (val is ObjectMirror);
630 Assert.AreEqual ("Object", (val as ObjectMirror).Type.Name);
632 // this on static methods
633 val = frame.GetThis ();
634 AssertValue (null, val);
636 e = run_until ("arg3");
638 frame = e.Thread.GetFrames () [0];
641 val = frame.GetThis ();
642 Assert.IsTrue (val is ObjectMirror);
643 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
645 // objref in register
646 val = frame.GetArgument (0);
647 AssertValue ("BLA", val);
651 public void Arrays () {
654 var e = run_until ("o2");
656 StackFrame frame = e.Thread.GetFrames () [0];
659 val = frame.GetArgument (0);
660 Assert.IsTrue (val is ArrayMirror);
661 ArrayMirror arr = val as ArrayMirror;
662 Assert.AreEqual (2, arr.Length);
663 AssertValue ("BAR", arr [0]);
664 AssertValue ("BAZ", arr [1]);
666 var vals = arr.GetValues (0, 2);
667 Assert.AreEqual (2, vals.Count);
668 AssertValue ("BAR", vals [0]);
669 AssertValue ("BAZ", vals [1]);
671 arr [0] = vm.RootDomain.CreateString ("ABC");
672 AssertValue ("ABC", arr [0]);
674 arr [0] = vm.CreateValue (null);
675 AssertValue (null, arr [0]);
677 arr.SetValues (0, new Value [] { vm.RootDomain.CreateString ("D1"), vm.RootDomain.CreateString ("D2") });
678 AssertValue ("D1", arr [0]);
679 AssertValue ("D2", arr [1]);
682 val = frame.GetArgument (1);
683 Assert.IsTrue (val is ArrayMirror);
684 arr = val as ArrayMirror;
685 Assert.AreEqual (2, arr.Length);
686 AssertValue (42, arr [0]);
687 AssertValue (43, arr [1]);
690 AssertThrows<IndexOutOfRangeException> (delegate () {
694 AssertThrows<IndexOutOfRangeException> (delegate () {
695 val = arr [Int32.MinValue];
698 AssertThrows<IndexOutOfRangeException> (delegate () {
699 vals = arr.GetValues (0, 3);
702 AssertThrows<IndexOutOfRangeException> (delegate () {
703 arr [2] = vm.CreateValue (null);
706 AssertThrows<IndexOutOfRangeException> (delegate () {
707 arr [Int32.MinValue] = vm.CreateValue (null);
710 AssertThrows<IndexOutOfRangeException> (delegate () {
711 arr.SetValues (0, new Value [] { null, null, null });
715 val = frame.GetArgument (2);
716 Assert.IsTrue (val is ArrayMirror);
717 arr = val as ArrayMirror;
718 Assert.AreEqual (2, arr.Rank);
719 Assert.AreEqual (4, arr.Length);
720 Assert.AreEqual (2, arr.GetLength (0));
721 Assert.AreEqual (2, arr.GetLength (1));
722 Assert.AreEqual (0, arr.GetLowerBound (0));
723 Assert.AreEqual (0, arr.GetLowerBound (1));
724 vals = arr.GetValues (0, 4);
725 AssertValue (1, vals [0]);
726 AssertValue (2, vals [1]);
727 AssertValue (3, vals [2]);
728 AssertValue (4, vals [3]);
730 val = frame.GetArgument (3);
731 Assert.IsTrue (val is ArrayMirror);
732 arr = val as ArrayMirror;
733 Assert.AreEqual (2, arr.Rank);
734 Assert.AreEqual (4, arr.Length);
735 Assert.AreEqual (2, arr.GetLength (0));
736 Assert.AreEqual (2, arr.GetLength (1));
737 Assert.AreEqual (1, arr.GetLowerBound (0));
738 Assert.AreEqual (3, arr.GetLowerBound (1));
740 AssertThrows<ArgumentOutOfRangeException> (delegate () {
743 AssertThrows<ArgumentOutOfRangeException> (delegate () {
747 AssertThrows<ArgumentOutOfRangeException> (delegate () {
748 arr.GetLowerBound (-1);
750 AssertThrows<ArgumentOutOfRangeException> (delegate () {
751 arr.GetLowerBound (2);
754 // arrays treated as generic collections
755 val = frame.GetArgument (4);
756 Assert.IsTrue (val is ArrayMirror);
757 arr = val as ArrayMirror;
761 public void Object_GetValue () {
762 var e = run_until ("o1");
763 var frame = e.Thread.GetFrames () [0];
765 object val = frame.GetThis ();
766 Assert.IsTrue (val is ObjectMirror);
767 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
768 ObjectMirror o = (val as ObjectMirror);
770 TypeMirror t = o.Type;
773 object f = o.GetValue (t.GetField ("field_i"));
775 f = o.GetValue (t.GetField ("field_s"));
776 AssertValue ("S", f);
777 f = o.GetValue (t.GetField ("field_enum"));
778 Assert.IsTrue (f is EnumMirror);
779 Assert.AreEqual (1, (f as EnumMirror).Value);
780 Assert.AreEqual ("B", (f as EnumMirror).StringValue);
782 // Inherited object fields
783 TypeMirror parent = t.BaseType;
784 f = o.GetValue (parent.GetField ("base_field_i"));
786 f = o.GetValue (parent.GetField ("base_field_s"));
787 AssertValue ("T", f);
790 f = o.GetValue (o.Type.GetField ("static_i"));
794 ObjectMirror o2 = frame.GetValue (frame.Method.GetParameters ()[1]) as ObjectMirror;
795 Assert.AreEqual ("GClass`1", o2.Type.Name);
796 TypeMirror t2 = o2.Type;
797 f = o2.GetValue (t2.GetField ("field"));
800 ObjectMirror o3 = frame.GetValue (frame.Method.GetParameters ()[2]) as ObjectMirror;
801 Assert.AreEqual ("GClass`1", o3.Type.Name);
802 TypeMirror t3 = o3.Type;
803 f = o3.GetValue (t3.GetField ("field"));
804 AssertValue ("FOO", f);
807 AssertThrows<ArgumentNullException> (delegate () {
813 public void Object_GetValues () {
814 var e = run_until ("o1");
815 var frame = e.Thread.GetFrames () [0];
817 object val = frame.GetThis ();
818 Assert.IsTrue (val is ObjectMirror);
819 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
820 ObjectMirror o = (val as ObjectMirror);
822 ObjectMirror val2 = frame.GetValue (frame.Method.GetParameters ()[0]) as ObjectMirror;
824 TypeMirror t = o.Type;
826 object[] vals = o.GetValues (new FieldInfoMirror [] { t.GetField ("field_i"), t.GetField ("field_s") });
830 AssertValue ("S", f);
833 AssertThrows<ArgumentNullException> (delegate () {
837 AssertThrows<ArgumentNullException> (delegate () {
838 o.GetValues (new FieldInfoMirror [] { null });
841 // field of another class
842 AssertThrows<ArgumentException> (delegate () {
843 o.GetValue (val2.Type.GetField ("field_j"));
847 void TestSetValue (ObjectMirror o, string field_name, object val) {
849 o.SetValue (o.Type.GetField (field_name), vm.RootDomain.CreateString ((string)val));
851 o.SetValue (o.Type.GetField (field_name), vm.CreateValue (val));
852 Value f = o.GetValue (o.Type.GetField (field_name));
853 AssertValue (val, f);
857 public void Object_SetValues () {
858 var e = run_until ("o1");
859 var frame = e.Thread.GetFrames () [0];
861 object val = frame.GetThis ();
862 Assert.IsTrue (val is ObjectMirror);
863 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
864 ObjectMirror o = (val as ObjectMirror);
866 ObjectMirror val2 = frame.GetValue (frame.Method.GetParameters ()[0]) as ObjectMirror;
868 TestSetValue (o, "field_i", 22);
869 TestSetValue (o, "field_bool1", false);
870 TestSetValue (o, "field_bool2", true);
871 TestSetValue (o, "field_char", 'B');
872 TestSetValue (o, "field_byte", (byte)129);
873 TestSetValue (o, "field_sbyte", (sbyte)-33);
874 TestSetValue (o, "field_short", (short)(Int16.MaxValue - 5));
875 TestSetValue (o, "field_ushort", (ushort)(UInt16.MaxValue - 5));
876 TestSetValue (o, "field_long", Int64.MaxValue - 5);
877 TestSetValue (o, "field_ulong", (ulong)(UInt64.MaxValue - 5));
878 TestSetValue (o, "field_float", 6.28f);
879 TestSetValue (o, "field_double", 6.28);
880 TestSetValue (o, "static_i", 23);
881 TestSetValue (o, "field_s", "CDEF");
886 f = o.GetValue (o.Type.GetField ("field_intptr"));
887 Assert.IsInstanceOfType (typeof (StructMirror), f);
888 AssertValue (Int32.MaxValue - 5, (f as StructMirror).Fields [0]);
891 FieldInfoMirror field = o.Type.GetField ("field_enum");
892 f = o.GetValue (field);
893 (f as EnumMirror).Value = 5;
894 o.SetValue (field, f);
895 f = o.GetValue (field);
896 Assert.AreEqual (5, (f as EnumMirror).Value);
899 o.SetValue (o.Type.GetField ("field_s"), vm.CreateValue (null));
900 f = o.GetValue (o.Type.GetField ("field_s"));
901 AssertValue (null, f);
904 field = o.Type.GetField ("generic_field_struct");
905 f = o.GetValue (field);
906 o.SetValue (field, f);
909 field = o.Type.GetField ("field_nullable");
910 f = o.GetValue (field);
911 AssertValue (0, (f as StructMirror).Fields [0]);
912 AssertValue (false, (f as StructMirror).Fields [1]);
913 o.SetValue (field, vm.CreateValue (6));
914 f = o.GetValue (field);
915 AssertValue (6, (f as StructMirror).Fields [0]);
916 AssertValue (true, (f as StructMirror).Fields [1]);
917 o.SetValue (field, vm.CreateValue (null));
918 f = o.GetValue (field);
919 AssertValue (0, (f as StructMirror).Fields [0]);
920 AssertValue (false, (f as StructMirror).Fields [1]);
923 AssertThrows<ArgumentNullException> (delegate () {
924 o.SetValues (null, new Value [0]);
927 AssertThrows<ArgumentNullException> (delegate () {
928 o.SetValues (new FieldInfoMirror [0], null);
931 AssertThrows<ArgumentNullException> (delegate () {
932 o.SetValues (new FieldInfoMirror [] { null }, new Value [1] { null });
935 // vtype with a wrong type
936 AssertThrows<ArgumentException> (delegate () {
937 o.SetValue (o.Type.GetField ("field_struct"), o.GetValue (o.Type.GetField ("field_enum")));
940 // reference type not assignment compatible
941 AssertThrows<ArgumentException> (delegate () {
942 o.SetValue (o.Type.GetField ("field_class"), o);
945 // field of another class
946 AssertThrows<ArgumentException> (delegate () {
947 o.SetValue (val2.Type.GetField ("field_j"), vm.CreateValue (1));
952 public void Type_SetValue () {
953 var e = run_until ("o1");
954 var frame = e.Thread.GetFrames () [0];
957 object val = frame.GetThis ();
958 Assert.IsTrue (val is ObjectMirror);
959 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
960 ObjectMirror o = (val as ObjectMirror);
962 ObjectMirror val2 = frame.GetValue (frame.Method.GetParameters ()[0]) as ObjectMirror;
964 o.Type.SetValue (o.Type.GetField ("static_i"), vm.CreateValue (55));
965 f = o.Type.GetValue (o.Type.GetField ("static_i"));
968 o.Type.SetValue (o.Type.GetField ("static_s"), vm.RootDomain.CreateString ("B"));
969 f = o.Type.GetValue (o.Type.GetField ("static_s"));
970 AssertValue ("B", f);
973 AssertThrows<ArgumentNullException> (delegate () {
974 o.Type.SetValue (null, vm.CreateValue (0));
977 AssertThrows<ArgumentNullException> (delegate () {
978 o.Type.SetValue (o.Type.GetField ("static_i"), null);
981 // field of another class
982 AssertThrows<ArgumentException> (delegate () {
983 o.SetValue (val2.Type.GetField ("field_j"), vm.CreateValue (1));
988 public void TypeInfo () {
989 Event e = run_until ("ti2");
990 StackFrame frame = e.Thread.GetFrames () [0];
995 t = frame.Method.GetParameters ()[0].ParameterType;
997 Assert.AreEqual ("String[]", t.Name);
998 Assert.AreEqual ("string[]", t.CSharpName);
999 Assert.AreEqual ("Array", t.BaseType.Name);
1000 Assert.AreEqual (true, t.HasElementType);
1001 Assert.AreEqual (true, t.IsArray);
1002 Assert.AreEqual (1, t.GetArrayRank ());
1003 Assert.AreEqual ("String", t.GetElementType ().Name);
1005 t = frame.Method.GetParameters ()[2].ParameterType;
1007 Assert.AreEqual ("Int32[,]", t.Name);
1009 //Assert.AreEqual ("int[,]", t.CSharpName);
1010 Assert.AreEqual ("Array", t.BaseType.Name);
1011 Assert.AreEqual (true, t.HasElementType);
1012 Assert.AreEqual (true, t.IsArray);
1013 Assert.AreEqual (2, t.GetArrayRank ());
1014 Assert.AreEqual ("Int32", t.GetElementType ().Name);
1017 t = frame.Method.GetParameters ()[3].ParameterType;
1019 //Assert.AreEqual ("Int32&", t.Name);
1020 //Assert.AreEqual (true, t.IsByRef);
1021 //Assert.AreEqual (true, t.HasElementType);
1024 t = frame.Method.GetParameters ()[4].ParameterType;
1026 //Assert.AreEqual ("Int32*", t.Name);
1027 Assert.AreEqual (true, t.IsPointer);
1028 Assert.AreEqual (true, t.HasElementType);
1029 Assert.AreEqual ("Int32", t.GetElementType ().Name);
1030 Assert.AreEqual (false, t.IsPrimitive);
1033 t = frame.Method.GetParameters ()[5].ParameterType;
1034 Assert.AreEqual (true, t.IsPrimitive);
1037 t = frame.Method.GetParameters ()[6].ParameterType;
1038 Assert.AreEqual ("AStruct", t.Name);
1039 Assert.AreEqual (false, t.IsPrimitive);
1040 Assert.AreEqual (true, t.IsValueType);
1041 Assert.AreEqual (false, t.IsClass);
1044 t = frame.Method.GetParameters ()[7].ParameterType;
1045 Assert.AreEqual ("Tests", t.Name);
1046 var nested = (from nt in t.GetNestedTypes () where nt.IsNestedPublic select nt).ToArray ();
1047 Assert.AreEqual (1, nested.Length);
1048 Assert.AreEqual ("NestedClass", nested [0].Name);
1049 Assert.IsTrue (t.BaseType.IsAssignableFrom (t));
1050 Assert.IsTrue (!t.IsAssignableFrom (t.BaseType));
1052 // generic instances
1053 t = frame.Method.GetParameters ()[9].ParameterType;
1054 Assert.AreEqual ("GClass`1", t.Name);
1055 Assert.IsTrue (t.IsGenericType);
1056 Assert.IsFalse (t.IsGenericTypeDefinition);
1058 var args = t.GetGenericArguments ();
1059 Assert.AreEqual (1, args.Length);
1060 Assert.AreEqual ("Int32", args [0].Name);
1062 // generic type definitions
1063 var gtd = t.GetGenericTypeDefinition ();
1064 Assert.AreEqual ("GClass`1", gtd.Name);
1065 Assert.IsTrue (gtd.IsGenericType);
1066 Assert.IsTrue (gtd.IsGenericTypeDefinition);
1067 Assert.AreEqual (gtd, gtd.GetGenericTypeDefinition ());
1069 args = gtd.GetGenericArguments ();
1070 Assert.AreEqual (1, args.Length);
1071 Assert.AreEqual ("T", args [0].Name);
1074 t = frame.Method.GetParameters ()[10].ParameterType;
1075 Assert.AreEqual ("AnEnum", t.Name);
1076 Assert.IsTrue (t.IsEnum);
1077 Assert.AreEqual ("Int32", t.EnumUnderlyingType.Name);
1080 t = frame.Method.GetParameters ()[7].ParameterType;
1082 var props = t.GetProperties ();
1083 Assert.AreEqual (3, props.Length);
1084 foreach (PropertyInfoMirror prop in props) {
1085 ParameterInfoMirror[] indexes = prop.GetIndexParameters ();
1087 if (prop.Name == "IntProperty") {
1088 Assert.AreEqual ("Int32", prop.PropertyType.Name);
1089 Assert.AreEqual ("get_IntProperty", prop.GetGetMethod ().Name);
1090 Assert.AreEqual ("set_IntProperty", prop.GetSetMethod ().Name);
1091 Assert.AreEqual (0, indexes.Length);
1092 } else if (prop.Name == "ReadOnlyProperty") {
1093 Assert.AreEqual ("Int32", prop.PropertyType.Name);
1094 Assert.AreEqual ("get_ReadOnlyProperty", prop.GetGetMethod ().Name);
1095 Assert.AreEqual (null, prop.GetSetMethod ());
1096 Assert.AreEqual (0, indexes.Length);
1097 } else if (prop.Name == "IndexedProperty") {
1098 Assert.AreEqual (1, indexes.Length);
1099 Assert.AreEqual ("Int32", indexes [0].ParameterType.Name);
1103 // custom attributes
1104 t = frame.Method.GetParameters ()[8].ParameterType;
1105 Assert.AreEqual ("Tests2", t.Name);
1106 var attrs = t.GetCustomAttributes (true);
1107 Assert.AreEqual (2, attrs.Length);
1108 foreach (var attr in attrs) {
1109 if (attr.Constructor.DeclaringType.Name == "DebuggerDisplayAttribute") {
1110 Assert.AreEqual (1, attr.ConstructorArguments.Count);
1111 Assert.AreEqual ("Tests", attr.ConstructorArguments [0].Value);
1112 Assert.AreEqual (2, attr.NamedArguments.Count);
1113 Assert.AreEqual ("Name", attr.NamedArguments [0].Property.Name);
1114 Assert.AreEqual ("FOO", attr.NamedArguments [0].TypedValue.Value);
1115 Assert.AreEqual ("Target", attr.NamedArguments [1].Property.Name);
1116 Assert.IsInstanceOfType (typeof (TypeMirror), attr.NamedArguments [1].TypedValue.Value);
1117 Assert.AreEqual ("Int32", (attr.NamedArguments [1].TypedValue.Value as TypeMirror).Name);
1118 } else if (attr.Constructor.DeclaringType.Name == "DebuggerTypeProxyAttribute") {
1119 Assert.AreEqual (1, attr.ConstructorArguments.Count);
1120 Assert.IsInstanceOfType (typeof (TypeMirror), attr.ConstructorArguments [0].Value);
1121 Assert.AreEqual ("Tests", (attr.ConstructorArguments [0].Value as TypeMirror).Name);
1123 Assert.Fail (attr.Constructor.DeclaringType.Name);
1129 public void FieldInfo () {
1130 Event e = run_until ("ti2");
1131 StackFrame frame = e.Thread.GetFrames () [0];
1135 t = frame.Method.GetParameters ()[8].ParameterType;
1136 Assert.AreEqual ("Tests2", t.Name);
1138 var fi = t.GetField ("field_j");
1139 var attrs = fi.GetCustomAttributes (true);
1140 Assert.AreEqual (1, attrs.Length);
1141 var attr = attrs [0];
1142 Assert.AreEqual ("DebuggerBrowsableAttribute", attr.Constructor.DeclaringType.Name);
1143 Assert.AreEqual (1, attr.ConstructorArguments.Count);
1144 Assert.IsInstanceOfType (typeof (EnumMirror), attr.ConstructorArguments [0].Value);
1145 Assert.AreEqual ((int)System.Diagnostics.DebuggerBrowsableState.Collapsed, (attr.ConstructorArguments [0].Value as EnumMirror).Value);
1149 public void PropertyInfo () {
1150 Event e = run_until ("ti2");
1151 StackFrame frame = e.Thread.GetFrames () [0];
1155 t = frame.Method.GetParameters ()[8].ParameterType;
1156 Assert.AreEqual ("Tests2", t.Name);
1158 var pi = t.GetProperty ("AProperty");
1159 var attrs = pi.GetCustomAttributes (true);
1160 Assert.AreEqual (1, attrs.Length);
1161 var attr = attrs [0];
1162 Assert.AreEqual ("DebuggerBrowsableAttribute", attr.Constructor.DeclaringType.Name);
1163 Assert.AreEqual (1, attr.ConstructorArguments.Count);
1164 Assert.IsInstanceOfType (typeof (EnumMirror), attr.ConstructorArguments [0].Value);
1165 Assert.AreEqual ((int)System.Diagnostics.DebuggerBrowsableState.Collapsed, (attr.ConstructorArguments [0].Value as EnumMirror).Value);
1169 [Category ("only5")]
1170 public void Type_GetValue () {
1171 Event e = run_until ("o1");
1172 StackFrame frame = e.Thread.GetFrames () [0];
1174 ObjectMirror o = (frame.GetThis () as ObjectMirror);
1176 TypeMirror t = o.Type;
1178 ObjectMirror val2 = frame.GetValue (frame.Method.GetParameters ()[0]) as ObjectMirror;
1181 object f = t.GetValue (o.Type.GetField ("static_i"));
1182 AssertValue (55, f);
1184 f = t.GetValue (o.Type.GetField ("static_s"));
1185 AssertValue ("A", f);
1187 // literal static fields
1188 f = t.GetValue (o.Type.GetField ("literal_i"));
1189 AssertValue (56, f);
1191 f = t.GetValue (o.Type.GetField ("literal_s"));
1192 AssertValue ("B", f);
1194 // Inherited static fields
1195 TypeMirror parent = t.BaseType;
1196 f = t.GetValue (parent.GetField ("base_static_i"));
1197 AssertValue (57, f);
1199 f = t.GetValue (parent.GetField ("base_static_s"));
1200 AssertValue ("C", f);
1202 // thread static field
1203 f = t.GetValue (t.GetField ("tls_i"), e.Thread);
1204 AssertValue (42, f);
1206 // Argument checking
1207 AssertThrows<ArgumentNullException> (delegate () {
1212 AssertThrows<ArgumentException> (delegate () {
1213 t.GetValue (o.Type.GetField ("field_i"));
1216 // field on another type
1217 AssertThrows<ArgumentException> (delegate () {
1218 t.GetValue (val2.Type.GetField ("static_field_j"));
1221 // special static field
1222 AssertThrows<ArgumentException> (delegate () {
1223 t.GetValue (t.GetField ("tls_i"));
1228 public void Type_GetValues () {
1229 Event e = run_until ("o1");
1230 StackFrame frame = e.Thread.GetFrames () [0];
1232 ObjectMirror o = (frame.GetThis () as ObjectMirror);
1234 TypeMirror t = o.Type;
1237 object[] vals = t.GetValues (new FieldInfoMirror [] { t.GetField ("static_i"), t.GetField ("static_s") });
1238 object f = vals [0];
1239 AssertValue (55, f);
1242 AssertValue ("A", f);
1244 // Argument checking
1245 AssertThrows<ArgumentNullException> (delegate () {
1249 AssertThrows<ArgumentNullException> (delegate () {
1250 t.GetValues (new FieldInfoMirror [] { null });
1255 public void ObjRefs () {
1256 Event e = run_until ("objrefs1");
1257 StackFrame frame = e.Thread.GetFrames () [0];
1259 ObjectMirror o = frame.GetThis () as ObjectMirror;
1260 ObjectMirror child = o.GetValue (o.Type.GetField ("child")) as ObjectMirror;
1262 Assert.IsTrue (child.Address != 0);
1264 // Check that object references are internalized correctly
1265 Assert.AreEqual (o, frame.GetThis ());
1267 run_until ("objrefs2");
1269 // child should be gc'd now
1270 Assert.IsTrue (child.IsCollected);
1273 * No longer works since Type is read eagerly
1276 AssertThrows<ObjectCollectedException> (delegate () {
1277 TypeMirror t = child.Type;
1281 AssertThrows<ObjectCollectedException> (delegate () {
1282 long addr = child.Address;
1287 public void Type_GetObject () {
1288 Event e = run_until ("o1");
1289 StackFrame frame = e.Thread.GetFrames () [0];
1291 ObjectMirror o = (frame.GetThis () as ObjectMirror);
1293 TypeMirror t = o.Type;
1295 Assert.AreEqual ("MonoType", t.GetTypeObject ().Type.Name);
1299 public void VTypes () {
1300 Event e = run_until ("vtypes1");
1301 StackFrame frame = e.Thread.GetFrames () [0];
1304 ObjectMirror o = frame.GetThis () as ObjectMirror;
1305 var obj = o.GetValue (o.Type.GetField ("field_struct"));
1306 Assert.IsTrue (obj is StructMirror);
1307 var s = obj as StructMirror;
1308 Assert.AreEqual ("AStruct", s.Type.Name);
1309 AssertValue (42, s ["i"]);
1311 AssertValue ("S", obj);
1312 AssertValue (43, s ["k"]);
1313 obj = o.GetValue (o.Type.GetField ("field_boxed_struct"));
1314 Assert.IsTrue (obj is StructMirror);
1315 s = obj as StructMirror;
1316 Assert.AreEqual ("AStruct", s.Type.Name);
1317 AssertValue (42, s ["i"]);
1319 // vtypes as arguments
1320 s = frame.GetArgument (0) as StructMirror;
1321 AssertValue (44, s ["i"]);
1323 AssertValue ("T", obj);
1324 AssertValue (45, s ["k"]);
1326 // vtypes as array entries
1327 var arr = frame.GetArgument (1) as ArrayMirror;
1329 Assert.IsTrue (obj is StructMirror);
1330 s = obj as StructMirror;
1331 AssertValue (1, s ["i"]);
1332 AssertValue ("S1", s ["s"]);
1334 Assert.IsTrue (obj is StructMirror);
1335 s = obj as StructMirror;
1336 AssertValue (2, s ["i"]);
1337 AssertValue ("S2", s ["s"]);
1339 // Argument checking
1340 s = frame.GetArgument (0) as StructMirror;
1341 AssertThrows<ArgumentException> (delegate () {
1345 // generic vtype instances
1346 o = frame.GetThis () as ObjectMirror;
1347 obj = o.GetValue (o.Type.GetField ("generic_field_struct"));
1348 Assert.IsTrue (obj is StructMirror);
1349 s = obj as StructMirror;
1350 Assert.AreEqual ("GStruct`1", s.Type.Name);
1351 AssertValue (42, s ["i"]);
1353 // this on vtype methods
1354 e = run_until ("vtypes2");
1356 e = single_step (e.Thread);
1358 frame = e.Thread.GetFrames () [0];
1360 Assert.AreEqual ("foo", (e as StepEvent).Method.Name);
1361 obj = frame.GetThis ();
1363 Assert.IsTrue (obj is StructMirror);
1364 s = obj as StructMirror;
1365 AssertValue (44, s ["i"]);
1366 AssertValue ("T", s ["s"]);
1367 AssertValue (45, s ["k"]);
1369 // this on static vtype methods
1370 e = run_until ("vtypes3");
1372 e = single_step (e.Thread);
1374 frame = e.Thread.GetFrames () [0];
1376 Assert.AreEqual ("static_foo", (e as StepEvent).Method.Name);
1377 obj = frame.GetThis ();
1378 AssertValue (null, obj);
1382 public void AssemblyInfo () {
1383 Event e = run_until ("single_stepping");
1385 StackFrame frame = e.Thread.GetFrames () [0];
1387 var aname = frame.Method.DeclaringType.Assembly.GetName ();
1388 Assert.AreEqual ("dtest-app, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", aname.ToString ());
1390 ModuleMirror m = frame.Method.DeclaringType.Module;
1392 Assert.AreEqual ("dtest-app.exe", m.Name);
1393 Assert.AreEqual ("dtest-app.exe", m.ScopeName);
1394 Assert.IsTrue (m.FullyQualifiedName.IndexOf ("dtest-app.exe") != -1);
1395 Guid guid = m.ModuleVersionId;
1396 Assert.AreEqual (frame.Method.DeclaringType.Assembly, m.Assembly);
1397 Assert.AreEqual (frame.Method.DeclaringType.Assembly.ManifestModule, m);
1399 // This is no longer true on 4.0
1400 //Assert.AreEqual ("Assembly", frame.Method.DeclaringType.Assembly.GetAssemblyObject ().Type.Name);
1402 TypeMirror t = vm.RootDomain.Corlib.GetType ("System.Diagnostics.DebuggerDisplayAttribute");
1403 Assert.AreEqual ("DebuggerDisplayAttribute", t.Name);
1407 public void LocalsInfo () {
1408 Event e = run_until ("locals2");
1410 StackFrame frame = e.Thread.GetFrames () [0];
1412 var locals = frame.Method.GetLocals ();
1413 Assert.AreEqual (7, locals.Length);
1414 for (int i = 0; i < 7; ++i) {
1415 if (locals [i].Name == "args") {
1416 Assert.IsTrue (locals [i].IsArg);
1417 Assert.AreEqual ("String[]", locals [i].Type.Name);
1418 } else if (locals [i].Name == "arg") {
1419 Assert.IsTrue (locals [i].IsArg);
1420 Assert.AreEqual ("Int32", locals [i].Type.Name);
1421 } else if (locals [i].Name == "i") {
1422 Assert.IsFalse (locals [i].IsArg);
1423 Assert.AreEqual ("Int64", locals [i].Type.Name);
1424 } else if (locals [i].Name == "j") {
1425 Assert.IsFalse (locals [i].IsArg);
1426 Assert.AreEqual ("Int32", locals [i].Type.Name);
1427 } else if (locals [i].Name == "s") {
1428 Assert.IsFalse (locals [i].IsArg);
1429 Assert.AreEqual ("String", locals [i].Type.Name);
1430 } else if (locals [i].Name == "t") {
1432 Assert.IsTrue (locals [i].IsArg);
1433 Assert.AreEqual ("String", locals [i].Type.Name);
1434 } else if (locals [i].Name == "rs") {
1435 Assert.IsTrue (locals [i].IsArg);
1436 Assert.AreEqual ("String", locals [i].Type.Name);
1444 public void Locals () {
1445 var be = run_until ("locals1");
1447 StackFrame frame = be.Thread.GetFrames () [0];
1449 MethodMirror m1 = frame.Method;
1451 be = run_until ("locals2");
1453 frame = be.Thread.GetFrames () [0];
1455 object val = frame.GetValue (frame.Method.GetLocal ("i"));
1456 AssertValue (0, val);
1459 var req = vm.CreateStepRequest (be.Thread);
1463 var e = GetNextEvent ();
1464 Assert.IsTrue (e is StepEvent);
1465 Assert.AreEqual ("locals2", (e as StepEvent).Method.Name);
1467 // Execute s = "AB";
1469 e = GetNextEvent ();
1470 Assert.IsTrue (e is StepEvent);
1471 Assert.AreEqual ("locals2", (e as StepEvent).Method.Name);
1473 frame = e.Thread.GetFrames () [0];
1475 val = frame.GetValue (frame.Method.GetLocal ("i"));
1476 AssertValue (42, val);
1478 LocalVariable[] locals = frame.Method.GetLocals ();
1479 var vals = frame.GetValues (locals);
1480 Assert.AreEqual (locals.Length, vals.Length);
1481 for (int i = 0; i < locals.Length; ++i) {
1482 if (locals [i].Name == "i")
1483 AssertValue (42, vals [i]);
1484 if (locals [i].Name == "s")
1485 AssertValue ("AB", vals [i]);
1486 if (locals [i].Name == "t")
1487 AssertValue ("ABC", vals [i]);
1490 // Argument checking
1493 AssertThrows<ArgumentNullException> (delegate () {
1494 frame.GetValue ((LocalVariable)null);
1496 // GetValue () local from another method
1497 AssertThrows<ArgumentException> (delegate () {
1498 frame.GetValue (m1.GetLocal ("foo"));
1502 AssertThrows<ArgumentNullException> (delegate () {
1503 frame.GetValue ((ParameterInfoMirror)null);
1505 // GetValue () local from another method
1506 AssertThrows<ArgumentException> (delegate () {
1507 frame.GetValue (m1.GetParameters ()[0]);
1510 // GetValues () null
1511 AssertThrows<ArgumentNullException> (delegate () {
1512 frame.GetValues (null);
1514 // GetValues () embedded null
1515 AssertThrows<ArgumentNullException> (delegate () {
1516 frame.GetValues (new LocalVariable [] { null });
1518 // GetValues () local from another method
1519 AssertThrows<ArgumentException> (delegate () {
1520 frame.GetValues (new LocalVariable [] { m1.GetLocal ("foo") });
1523 AssertThrows<ArgumentException> (delegate () {
1524 val = frame.GetValue (frame.Method.ReturnParameter);
1527 // invalid stack frames
1529 e = GetNextEvent ();
1530 Assert.IsTrue (e is StepEvent);
1531 Assert.AreEqual ("locals2", (e as StepEvent).Method.Name);
1533 AssertThrows<InvalidStackFrameException> (delegate () {
1534 frame.GetValue (frame.Method.GetLocal ("i"));
1541 public void GetVisibleVariables () {
1542 Event e = run_until ("locals4");
1545 var locals = e.Thread.GetFrames ()[1].GetVisibleVariables ();
1546 Assert.AreEqual (2, locals.Count);
1547 var loc = locals.First (l => l.Name == "i");
1548 Assert.AreEqual ("Int64", loc.Type.Name);
1549 loc = locals.First (l => l.Name == "s");
1550 Assert.AreEqual ("String", loc.Type.Name);
1552 loc = e.Thread.GetFrames ()[1].GetVisibleVariableByName ("i");
1553 Assert.AreEqual ("i", loc.Name);
1554 Assert.AreEqual ("Int64", loc.Type.Name);
1556 e = run_until ("locals5");
1559 locals = e.Thread.GetFrames ()[1].GetVisibleVariables ();
1560 Assert.AreEqual (2, locals.Count);
1561 loc = locals.First (l => l.Name == "i");
1562 Assert.AreEqual ("String", loc.Type.Name);
1563 loc = locals.First (l => l.Name == "s");
1564 Assert.AreEqual ("String", loc.Type.Name);
1566 loc = e.Thread.GetFrames ()[1].GetVisibleVariableByName ("i");
1567 Assert.AreEqual ("i", loc.Name);
1568 Assert.AreEqual ("String", loc.Type.Name);
1570 // Variable in another scope
1571 loc = e.Thread.GetFrames ()[1].GetVisibleVariableByName ("j");
1572 Assert.IsNull (loc);
1576 public void Exit () {
1581 var e = GetNextEvent ();
1582 Assert.IsInstanceOfType (typeof (VMDeathEvent), e);
1585 /* Could be a remote vm with no process */
1588 Assert.AreEqual (5, p.ExitCode);
1591 AssertThrows<VMDisconnectedException> (delegate () {
1600 public void Dispose () {
1605 var e = GetNextEvent ();
1606 Assert.IsInstanceOfType (typeof (VMDisconnectEvent), e);
1609 /* Could be a remote vm with no process */
1612 Assert.AreEqual (3, p.ExitCode);
1615 AssertThrows<VMDisconnectedException> (delegate () {
1624 public void ColumnNumbers () {
1625 Event e = run_until ("line_numbers");
1627 // FIXME: Merge this with LineNumbers () when its fixed
1629 step_req = vm.CreateStepRequest (e.Thread);
1630 step_req.Depth = StepDepth.Into;
1637 e = GetNextEvent ();
1638 Assert.IsTrue (e is StepEvent);
1640 l = e.Thread.GetFrames ()[0].Location;
1642 Assert.AreEqual (3, l.ColumnNumber);
1644 step_req.Disable ();
1648 // Broken by mcs+runtime changes (#5438)
1649 [Category("NotWorking")]
1650 public void LineNumbers () {
1651 Event e = run_until ("line_numbers");
1653 step_req = vm.CreateStepRequest (e.Thread);
1654 step_req.Depth = StepDepth.Into;
1661 e = GetNextEvent ();
1662 Assert.IsTrue (e is StepEvent);
1664 l = e.Thread.GetFrames ()[0].Location;
1666 Assert.IsTrue (l.SourceFile.IndexOf ("dtest-app.cs") != -1);
1667 Assert.AreEqual ("ln1", l.Method.Name);
1670 using (FileStream fs = new FileStream (l.SourceFile, FileMode.Open, FileAccess.Read)) {
1671 MD5 md5 = MD5.Create ();
1672 var hash = md5.ComputeHash (fs);
1674 for (int i = 0; i < 16; ++i)
1675 Assert.AreEqual (hash [i], l.SourceFileHash [i]);
1678 int line_base = l.LineNumber;
1681 e = GetNextEvent ();
1682 Assert.IsTrue (e is StepEvent);
1683 l = e.Thread.GetFrames ()[0].Location;
1684 Assert.AreEqual ("ln2", l.Method.Name);
1685 Assert.AreEqual (line_base + 6, l.LineNumber);
1688 e = GetNextEvent ();
1689 Assert.IsTrue (e is StepEvent);
1690 l = e.Thread.GetFrames ()[0].Location;
1691 Assert.AreEqual ("ln1", l.Method.Name);
1692 Assert.AreEqual (line_base + 1, l.LineNumber);
1695 e = GetNextEvent ();
1696 Assert.IsTrue (e is StepEvent);
1697 l = e.Thread.GetFrames ()[0].Location;
1698 Assert.AreEqual ("ln3", l.Method.Name);
1699 Assert.AreEqual (line_base + 11, l.LineNumber);
1702 e = GetNextEvent ();
1703 Assert.IsTrue (e is StepEvent);
1704 l = e.Thread.GetFrames ()[0].Location;
1705 Assert.AreEqual ("ln3", l.Method.Name);
1706 Assert.IsTrue (l.SourceFile.EndsWith ("FOO"));
1707 Assert.AreEqual (55, l.LineNumber);
1710 e = GetNextEvent ();
1711 Assert.IsTrue (e is StepEvent);
1712 l = e.Thread.GetFrames ()[0].Location;
1713 Assert.AreEqual ("ln1", l.Method.Name);
1714 Assert.AreEqual (line_base + 2, l.LineNumber);
1716 // GetSourceFiles ()
1717 string[] sources = l.Method.DeclaringType.GetSourceFiles ();
1718 Assert.AreEqual (2, sources.Length);
1719 Assert.AreEqual ("dtest-app.cs", sources [0]);
1720 Assert.AreEqual ("FOO", sources [1]);
1722 sources = l.Method.DeclaringType.GetSourceFiles (true);
1723 Assert.AreEqual (2, sources.Length);
1724 Assert.IsTrue (sources [0].EndsWith ("dtest-app.cs"));
1725 Assert.IsTrue (sources [1].EndsWith ("FOO"));
1729 public void Suspend () {
1732 Start (new string [] { "dtest-app.exe", "suspend-test" });
1734 Event e = run_until ("suspend");
1736 ThreadMirror main = e.Thread;
1744 // The debuggee should be suspended while it is running the infinite loop
1746 StackFrame frame = main.GetFrames ()[0];
1747 Assert.AreEqual ("suspend", frame.Method.Name);
1751 // resuming when not suspended
1752 AssertThrows<InvalidOperationException> (delegate () {
1762 public void AssemblyLoad () {
1763 Event e = run_until ("assembly_load");
1765 var load_req = vm.CreateAssemblyLoadRequest ();
1770 e = GetNextEvent ();
1771 Assert.IsInstanceOfType (typeof (AssemblyLoadEvent), e);
1772 Assert.IsTrue ((e as AssemblyLoadEvent).Assembly.Location.EndsWith ("System.dll"));
1774 var frames = e.Thread.GetFrames ();
1775 Assert.IsTrue (frames.Length > 0);
1776 Assert.AreEqual ("assembly_load", frames [0].Method.Name);
1780 public void CreateValue () {
1783 v = vm.CreateValue (1);
1784 Assert.AreEqual (vm, v.VirtualMachine);
1785 Assert.AreEqual (1, v.Value);
1787 v = vm.CreateValue (null);
1788 Assert.AreEqual (vm, v.VirtualMachine);
1789 Assert.AreEqual (null, v.Value);
1791 // Argument checking
1792 AssertThrows <ArgumentException> (delegate () {
1793 v = vm.CreateValue ("FOO");
1798 public void CreateString () {
1799 StringMirror s = vm.RootDomain.CreateString ("ABC");
1801 Assert.AreEqual (vm, s.VirtualMachine);
1802 Assert.AreEqual ("ABC", s.Value);
1803 Assert.AreEqual (vm.RootDomain, s.Domain);
1806 StringBuilder sb = new StringBuilder ();
1807 for (int i = 0; i < 1024; ++i)
1809 s = vm.RootDomain.CreateString (sb.ToString ());
1811 // Argument checking
1812 AssertThrows <ArgumentNullException> (delegate () {
1813 s = vm.RootDomain.CreateString (null);
1818 public void CreateBoxedValue () {
1819 ObjectMirror o = vm.RootDomain.CreateBoxedValue (new PrimitiveValue (vm, 42));
1821 Assert.AreEqual ("Int32", o.Type.Name);
1822 //AssertValue (42, m.GetValue (o.Type.GetField ("m_value")));
1824 // Argument checking
1825 AssertThrows <ArgumentNullException> (delegate () {
1826 vm.RootDomain.CreateBoxedValue (null);
1829 AssertThrows <ArgumentException> (delegate () {
1830 vm.RootDomain.CreateBoxedValue (o);
1835 public void Invoke () {
1836 Event e = run_until ("invoke1");
1838 StackFrame frame = e.Thread.GetFrames () [0];
1840 TypeMirror t = frame.Method.DeclaringType;
1841 ObjectMirror this_obj = (ObjectMirror)frame.GetThis ();
1843 TypeMirror t2 = frame.Method.GetParameters ()[0].ParameterType;
1849 m = t.GetMethod ("invoke_return_void");
1850 v = this_obj.InvokeMethod (e.Thread, m, null);
1854 m = t.GetMethod ("invoke_return_ref");
1855 v = this_obj.InvokeMethod (e.Thread, m, null);
1856 AssertValue ("ABC", v);
1859 m = t.GetMethod ("invoke_return_null");
1860 v = this_obj.InvokeMethod (e.Thread, m, null);
1861 AssertValue (null, v);
1864 m = t.GetMethod ("invoke_return_primitive");
1865 v = this_obj.InvokeMethod (e.Thread, m, null);
1866 AssertValue (42, v);
1869 m = t.GetMethod ("invoke_return_nullable");
1870 v = this_obj.InvokeMethod (e.Thread, m, null);
1871 Assert.IsInstanceOfType (typeof (StructMirror), v);
1872 var s = v as StructMirror;
1873 AssertValue (42, s.Fields [0]);
1874 AssertValue (true, s.Fields [1]);
1876 // pass nullable as this
1877 //m = vm.RootDomain.Corlib.GetType ("System.Object").GetMethod ("ToString");
1878 m = s.Type.GetMethod ("ToString");
1879 v = s.InvokeMethod (e.Thread, m, null);
1881 // return nullable null
1882 m = t.GetMethod ("invoke_return_nullable_null");
1883 v = this_obj.InvokeMethod (e.Thread, m, null);
1884 Assert.IsInstanceOfType (typeof (StructMirror), v);
1885 s = v as StructMirror;
1886 AssertValue (0, s.Fields [0]);
1887 AssertValue (false, s.Fields [1]);
1889 // pass nullable as this
1890 //m = vm.RootDomain.Corlib.GetType ("System.Object").GetMethod ("ToString");
1891 m = s.Type.GetMethod ("ToString");
1892 v = s.InvokeMethod (e.Thread, m, null);
1895 m = t.GetMethod ("invoke_pass_primitive");
1896 Value[] args = new Value [] {
1897 vm.CreateValue ((byte)Byte.MaxValue),
1898 vm.CreateValue ((sbyte)SByte.MaxValue),
1899 vm.CreateValue ((short)1),
1900 vm.CreateValue ((ushort)1),
1901 vm.CreateValue ((int)1),
1902 vm.CreateValue ((uint)1),
1903 vm.CreateValue ((long)1),
1904 vm.CreateValue ((ulong)1),
1905 vm.CreateValue ('A'),
1906 vm.CreateValue (true),
1907 vm.CreateValue (3.14f),
1908 vm.CreateValue (3.14) };
1910 v = this_obj.InvokeMethod (e.Thread, m, args);
1911 AssertValue ((int)Byte.MaxValue + (int)SByte.MaxValue + 1 + 1 + 1 + 1 + 1 + 1 + 'A' + 1 + 3 + 3, v);
1914 m = t.GetMethod ("invoke_pass_ref");
1915 v = this_obj.InvokeMethod (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") });
1916 AssertValue ("ABC", v);
1919 m = t.GetMethod ("invoke_pass_ref");
1920 v = this_obj.InvokeMethod (e.Thread, m, new Value [] { vm.CreateValue (null) });
1921 AssertValue (null, v);
1924 m = t.GetMethod ("invoke_static_pass_ref");
1925 v = t.InvokeMethod (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") });
1926 AssertValue ("ABC", v);
1928 // static invoked using ObjectMirror.InvokeMethod
1929 m = t.GetMethod ("invoke_static_pass_ref");
1930 v = this_obj.InvokeMethod (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") });
1931 AssertValue ("ABC", v);
1933 // method which throws an exception
1935 m = t.GetMethod ("invoke_throws");
1936 v = this_obj.InvokeMethod (e.Thread, m, null);
1938 } catch (InvocationException ex) {
1939 Assert.AreEqual ("Exception", ex.Exception.Type.Name);
1943 m = t.GetMethod (".ctor");
1944 v = t.InvokeMethod (e.Thread, m, null);
1945 Assert.IsInstanceOfType (typeof (ObjectMirror), v);
1946 Assert.AreEqual ("Tests", (v as ObjectMirror).Type.Name);
1948 // Argument checking
1951 AssertThrows<ArgumentNullException> (delegate {
1952 m = t.GetMethod ("invoke_pass_ref");
1953 v = this_obj.InvokeMethod (null, m, new Value [] { vm.CreateValue (null) });
1957 AssertThrows<ArgumentNullException> (delegate {
1958 v = this_obj.InvokeMethod (e.Thread, null, new Value [] { vm.CreateValue (null) });
1961 // invalid number of arguments
1962 m = t.GetMethod ("invoke_pass_ref");
1963 AssertThrows<ArgumentException> (delegate {
1964 v = this_obj.InvokeMethod (e.Thread, m, null);
1967 // invalid type of argument (ref != primitive)
1968 m = t.GetMethod ("invoke_pass_ref");
1969 AssertThrows<ArgumentException> (delegate {
1970 v = this_obj.InvokeMethod (e.Thread, m, new Value [] { vm.CreateValue (1) });
1973 // invalid type of argument (primitive != primitive)
1974 m = t.GetMethod ("invoke_pass_primitive_2");
1975 AssertThrows<ArgumentException> (delegate {
1976 v = this_obj.InvokeMethod (e.Thread, m, new Value [] { vm.CreateValue (1) });
1979 // invoking a non-static method as static
1980 m = t.GetMethod ("invoke_pass_ref");
1981 AssertThrows<ArgumentException> (delegate {
1982 v = t.InvokeMethod (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") });
1985 // invoking a method defined in another class
1986 m = t2.GetMethod ("invoke");
1987 AssertThrows<ArgumentException> (delegate {
1988 v = this_obj.InvokeMethod (e.Thread, m, null);
1993 public void InvokeVType () {
1994 Event e = run_until ("invoke1");
1996 StackFrame frame = e.Thread.GetFrames () [0];
1998 var s = frame.GetArgument (1) as StructMirror;
2000 TypeMirror t = s.Type;
2005 // Pass struct as this, receive int
2006 m = t.GetMethod ("invoke_return_int");
2007 v = s.InvokeMethod (e.Thread, m, null);
2008 AssertValue (42, v);
2010 // Pass struct as this, receive intptr
2011 m = t.GetMethod ("invoke_return_intptr");
2012 v = s.InvokeMethod (e.Thread, m, null);
2013 AssertValue (43, v);
2016 m = t.GetMethod ("invoke_static");
2017 v = t.InvokeMethod (e.Thread, m, null);
2020 // Pass generic struct as this
2021 s = frame.GetArgument (2) as StructMirror;
2023 m = t.GetMethod ("invoke_return_int");
2024 v = s.InvokeMethod (e.Thread, m, null);
2025 AssertValue (42, v);
2029 public void BreakpointDuringInvoke () {
2030 Event e = run_until ("invoke1");
2032 MethodMirror m = entry_point.DeclaringType.GetMethod ("invoke2");
2033 Assert.IsNotNull (m);
2034 vm.SetBreakpoint (m, 0);
2036 StackFrame frame = e.Thread.GetFrames () [0];
2037 var o = frame.GetThis () as ObjectMirror;
2039 bool failed = false;
2041 bool finished = false;
2042 object wait = new object ();
2044 // Have to invoke in a separate thread as the invoke is suspended until we
2045 // resume after the breakpoint
2046 Thread t = new Thread (delegate () {
2048 o.InvokeMethod (e.Thread, m, null);
2054 Monitor.Pulse (wait);
2060 StackFrame invoke_frame = null;
2063 e = GetNextEvent ();
2064 Assert.IsInstanceOfType (typeof (BreakpointEvent), e);
2065 // Check stack trace support and invokes
2066 var frames = e.Thread.GetFrames ();
2067 invoke_frame = frames [0];
2068 Assert.AreEqual ("invoke2", frames [0].Method.Name);
2069 Assert.IsTrue (frames [0].IsDebuggerInvoke);
2070 Assert.AreEqual ("invoke1", frames [1].Method.Name);
2077 Monitor.Wait (wait);
2080 // Check that the invoke frames are no longer valid
2081 AssertThrows<InvalidStackFrameException> (delegate {
2082 invoke_frame.GetThis ();
2085 // Check InvokeOptions.DisableBreakpoints flag
2086 o.InvokeMethod (e.Thread, m, null, InvokeOptions.DisableBreakpoints);
2090 public void DisabledExceptionDuringInvoke () {
2091 Event e = run_until ("invoke_ex");
2093 MethodMirror m = entry_point.DeclaringType.GetMethod ("invoke_ex_inner");
2095 StackFrame frame = e.Thread.GetFrames () [0];
2096 var o = frame.GetThis () as ObjectMirror;
2098 var req = vm.CreateExceptionRequest (null);
2101 // Check InvokeOptions.DisableBreakpoints flag
2102 o.InvokeMethod (e.Thread, m, null, InvokeOptions.DisableBreakpoints);
2108 public void InvokeSingleThreaded () {
2111 Start (new string [] { "dtest-app.exe", "invoke-single-threaded" });
2113 Event e = run_until ("invoke_single_threaded_2");
2115 StackFrame f = e.Thread.GetFrames ()[0];
2117 var obj = f.GetThis () as ObjectMirror;
2119 // Check that the counter value incremented by the other thread does not increase
2120 // during the invoke.
2121 object counter1 = (obj.GetValue (obj.Type.GetField ("counter")) as PrimitiveValue).Value;
2123 var m = obj.Type.GetMethod ("invoke_return_void");
2124 obj.InvokeMethod (e.Thread, m, null, InvokeOptions.SingleThreaded);
2126 object counter2 = (obj.GetValue (obj.Type.GetField ("counter")) as PrimitiveValue).Value;
2128 Assert.AreEqual ((int)counter1, (int)counter2);
2130 // Test multiple invokes done in succession
2131 m = obj.Type.GetMethod ("invoke_return_void");
2132 obj.InvokeMethod (e.Thread, m, null, InvokeOptions.SingleThreaded);
2134 // Test events during single-threaded invokes
2135 vm.EnableEvents (EventType.TypeLoad);
2136 m = obj.Type.GetMethod ("invoke_type_load");
2137 obj.BeginInvokeMethod (e.Thread, m, null, InvokeOptions.SingleThreaded, delegate {
2141 e = GetNextEvent ();
2142 Assert.AreEqual (EventType.TypeLoad, e.EventType);
2145 List<Value> invoke_results;
2148 public void InvokeMultiple () {
2149 Event e = run_until ("invoke1");
2151 StackFrame frame = e.Thread.GetFrames () [0];
2153 TypeMirror t = frame.Method.DeclaringType;
2154 ObjectMirror this_obj = (ObjectMirror)frame.GetThis ();
2156 TypeMirror t2 = frame.Method.GetParameters ()[0].ParameterType;
2158 var methods = new MethodMirror [2];
2159 methods [0] = t.GetMethod ("invoke_return_ref");
2160 methods [1] = t.GetMethod ("invoke_return_primitive");
2162 invoke_results = new List<Value> ();
2164 var r = this_obj.BeginInvokeMultiple (e.Thread, methods, null, InvokeOptions.SingleThreaded, invoke_multiple_cb, this_obj);
2165 WaitHandle.WaitAll (new WaitHandle[] { r.AsyncWaitHandle });
2166 this_obj.EndInvokeMultiple (r);
2167 // The callback might still be running
2168 while (invoke_results.Count < 2) {
2171 AssertValue ("ABC", invoke_results [0]);
2172 AssertValue (42, invoke_results [1]);
2175 void invoke_multiple_cb (IAsyncResult ar) {
2176 ObjectMirror this_obj = (ObjectMirror)ar.AsyncState;
2178 Console.WriteLine ("CB!");
2180 var res = this_obj.EndInvokeMethod (ar);
2181 lock (invoke_results)
2182 invoke_results.Add (res);
2186 public void GetThreads () {
2191 public void Threads () {
2192 Event e = run_until ("threads");
2194 Assert.AreEqual (ThreadState.Running, e.Thread.ThreadState);
2196 Assert.IsTrue (e.Thread.ThreadId > 0);
2198 Assert.AreEqual (e.Thread.TID, e.Thread.TID);
2200 vm.EnableEvents (EventType.ThreadStart, EventType.ThreadDeath);
2204 e = GetNextEvent ();
2205 Assert.IsInstanceOfType (typeof (ThreadStartEvent), e);
2206 var state = e.Thread.ThreadState;
2207 Assert.IsTrue (state == ThreadState.Running || state == ThreadState.Unstarted);
2211 e = GetNextEvent ();
2212 Assert.IsInstanceOfType (typeof (ThreadDeathEvent), e);
2213 Assert.AreEqual (ThreadState.Stopped, e.Thread.ThreadState);
2217 public void Frame_SetValue () {
2218 Event e = run_until ("locals2");
2220 StackFrame frame = e.Thread.GetFrames () [0];
2223 var l = frame.Method.GetLocal ("i");
2224 frame.SetValue (l, vm.CreateValue ((long)55));
2225 AssertValue (55, frame.GetValue (l));
2228 l = frame.Method.GetLocal ("s");
2229 frame.SetValue (l, vm.RootDomain.CreateString ("DEF"));
2230 AssertValue ("DEF", frame.GetValue (l));
2232 // argument as local
2233 l = frame.Method.GetLocal ("arg");
2234 frame.SetValue (l, vm.CreateValue (6));
2235 AssertValue (6, frame.GetValue (l));
2238 var p = frame.Method.GetParameters ()[1];
2239 frame.SetValue (p, vm.CreateValue (7));
2240 AssertValue (7, frame.GetValue (p));
2243 p = frame.Method.GetParameters ()[2];
2244 frame.SetValue (p, vm.RootDomain.CreateString ("DEF"));
2245 AssertValue ("DEF", frame.GetValue (p));
2248 p = frame.Method.GetParameters ()[3];
2249 frame.SetValue (p, vm.RootDomain.CreateString ("DEF2"));
2250 AssertValue ("DEF2", frame.GetValue (p));
2252 // argument checking
2255 AssertThrows<ArgumentNullException> (delegate () {
2256 frame.SetValue ((LocalVariable)null, vm.CreateValue (55));
2260 AssertThrows<ArgumentNullException> (delegate () {
2261 l = frame.Method.GetLocal ("i");
2262 frame.SetValue (l, null);
2265 // value of invalid type
2266 AssertThrows<ArgumentException> (delegate () {
2267 l = frame.Method.GetLocal ("i");
2268 frame.SetValue (l, vm.CreateValue (55));
2274 public void Frame_SetValue_Registers () {
2275 Event e = run_until ("locals6_1");
2277 StackFrame frame = e.Thread.GetFrames () [1];
2280 var l = frame.Method.GetLocal ("j");
2281 frame.SetValue (l, vm.CreateValue (99));
2282 AssertValue (99, frame.GetValue (l));
2284 // Check it during execution
2285 e = run_until ("locals6_2");
2286 frame = e.Thread.GetFrames () [0];
2287 AssertValue (99, frame.GetValue (frame.Method.GetParameters ()[0]));
2289 // Set it while in a frame which clobbers its register
2290 e = run_until ("locals6_3");
2291 frame = e.Thread.GetFrames () [1];
2292 frame.SetValue (l, vm.CreateValue (100));
2293 AssertValue (100, frame.GetValue (l));
2295 // Check it during execution
2296 e = run_until ("locals6_4");
2297 frame = e.Thread.GetFrames () [0];
2298 AssertValue (100, frame.GetValue (frame.Method.GetParameters ()[0]));
2300 // Signed byte value
2301 e = run_until ("locals6_5");
2302 frame = e.Thread.GetFrames () [1];
2303 var l2 = frame.Method.GetLocal ("sb");
2304 frame.SetValue (l2, vm.CreateValue ((sbyte)-99));
2305 AssertValue (-99, frame.GetValue (l2));
2307 // Check it during execution
2308 e = run_until ("locals6_6");
2309 frame = e.Thread.GetFrames () [0];
2310 AssertValue (-99, frame.GetValue (frame.Method.GetParameters ()[0]));
2314 public void InvokeRegress () {
2315 Event e = run_until ("invoke1");
2317 StackFrame frame = e.Thread.GetFrames () [0];
2319 TypeMirror t = frame.Method.DeclaringType;
2320 ObjectMirror this_obj = (ObjectMirror)frame.GetThis ();
2322 TypeMirror t2 = frame.Method.GetParameters ()[0].ParameterType;
2328 m = t.GetMethod ("invoke_return_void");
2329 v = this_obj.InvokeMethod (e.Thread, m, null);
2332 // Check that the stack frames remain valid during the invoke
2333 Assert.AreEqual ("Tests", (frame.GetThis () as ObjectMirror).Type.Name);
2335 // do another invoke
2336 m = t.GetMethod ("invoke_return_void");
2337 v = this_obj.InvokeMethod (e.Thread, m, null);
2340 // Try a single step after the invoke
2341 var req = vm.CreateStepRequest (e.Thread);
2342 req.Depth = StepDepth.Into;
2343 req.Size = StepSize.Line;
2348 // Step into invoke2
2350 e = GetNextEvent ();
2351 Assert.IsTrue (e is StepEvent);
2352 Assert.AreEqual ("invoke2", (e as StepEvent).Method.Name);
2356 frame = e.Thread.GetFrames () [0];
2360 public void Exceptions () {
2361 Event e = run_until ("exceptions");
2362 var req = vm.CreateExceptionRequest (null);
2367 e = GetNextEvent ();
2368 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2369 Assert.AreEqual ("OverflowException", (e as ExceptionEvent).Exception.Type.Name);
2371 var frames = e.Thread.GetFrames ();
2372 Assert.AreEqual ("exceptions", frames [0].Method.Name);
2375 // exception type filter
2377 req = vm.CreateExceptionRequest (vm.RootDomain.Corlib.GetType ("System.ArgumentException"));
2380 // Skip the throwing of the second OverflowException
2383 e = GetNextEvent ();
2384 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2385 Assert.AreEqual ("ArgumentException", (e as ExceptionEvent).Exception.Type.Name);
2388 // exception type filter for subclasses
2389 req = vm.CreateExceptionRequest (vm.RootDomain.Corlib.GetType ("System.Exception"));
2394 e = GetNextEvent ();
2395 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2396 Assert.AreEqual ("OverflowException", (e as ExceptionEvent).Exception.Type.Name);
2399 // Implicit exceptions
2400 req = vm.CreateExceptionRequest (null);
2405 e = GetNextEvent ();
2406 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2407 Assert.AreEqual ("NullReferenceException", (e as ExceptionEvent).Exception.Type.Name);
2410 // Single stepping after an exception
2411 req = vm.CreateExceptionRequest (null);
2416 e = GetNextEvent ();
2417 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2418 Assert.AreEqual ("Exception", (e as ExceptionEvent).Exception.Type.Name);
2419 frames = e.Thread.GetFrames ();
2420 Assert.AreEqual ("exceptions2", frames [0].Method.Name);
2423 var sreq = vm.CreateStepRequest (e.Thread);
2424 sreq.Depth = StepDepth.Over;
2425 sreq.Size = StepSize.Line;
2429 e = GetNextEvent ();
2430 Assert.IsInstanceOfType (typeof (StepEvent), e);
2431 frames = e.Thread.GetFrames ();
2432 Assert.AreEqual ("exceptions", frames [0].Method.Name);
2435 // Argument checking
2436 AssertThrows<ArgumentException> (delegate {
2437 vm.CreateExceptionRequest (e.Thread.Type);
2442 public void ExceptionFilter () {
2443 Event e = run_until ("exception_filter");
2445 MethodMirror m = entry_point.DeclaringType.GetMethod ("exception_filter_filter");
2446 Assert.IsNotNull (m);
2448 vm.SetBreakpoint (m, 0);
2452 e = GetNextEvent ();
2453 Assert.AreEqual (EventType.Breakpoint, e.EventType);
2454 Assert.IsTrue (e is BreakpointEvent);
2455 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
2457 var frames = e.Thread.GetFrames ();
2459 Assert.IsTrue (frames [0].Location.SourceFile.IndexOf ("dtest-app.cs") != -1);
2460 Assert.AreEqual ("exception_filter_filter", frames [0].Location.Method.Name);
2462 Assert.AreEqual (0, frames [1].Location.Method.MetadataToken);
2463 Assert.AreEqual (0x0f, frames [1].Location.ILOffset);
2465 Assert.AreEqual ("exception_filter_method", frames [2].Location.Method.Name);
2466 Assert.AreEqual (0x05, frames [2].Location.ILOffset);
2468 Assert.AreEqual (0, frames [3].Location.Method.MetadataToken, 0);
2469 Assert.AreEqual (0, frames [3].Location.ILOffset);
2471 Assert.AreEqual ("exception_filter", frames [4].Location.Method.Name);
2475 public void ExceptionFilter2 () {
2478 Start (new string [] { "dtest-excfilter.exe" });
2480 MethodMirror filter_method = entry_point.DeclaringType.GetMethod ("Filter");
2481 Assert.IsNotNull (filter_method);
2483 MethodMirror test_method = entry_point.DeclaringType.GetMethod ("Test");
2484 Assert.IsNotNull (test_method);
2486 vm.SetBreakpoint (filter_method, 0);
2490 var e = GetNextEvent ();
2491 Assert.AreEqual (EventType.Breakpoint, e.EventType);
2492 Assert.IsTrue (e is BreakpointEvent);
2493 Assert.AreEqual (filter_method.Name, (e as BreakpointEvent).Method.Name);
2495 var frames = e.Thread.GetFrames ();
2497 Assert.AreEqual (4, frames.Count ());
2499 Assert.AreEqual (filter_method.Name, frames [0].Location.Method.Name);
2500 Assert.AreEqual (20, frames [0].Location.LineNumber);
2501 Assert.AreEqual (0, frames [0].Location.ILOffset);
2503 Assert.AreEqual (test_method.Name, frames [1].Location.Method.Name);
2504 Assert.AreEqual (37, frames [1].Location.LineNumber);
2505 Assert.AreEqual (0x0b, frames [1].Location.ILOffset);
2507 Assert.AreEqual (test_method.Name, frames [2].Location.Method.Name);
2508 Assert.AreEqual (33, frames [2].Location.LineNumber);
2509 Assert.AreEqual (0x05, frames [2].Location.ILOffset);
2511 Assert.AreEqual (entry_point.Name, frames [3].Location.Method.Name);
2512 Assert.AreEqual (14, frames [3].Location.LineNumber);
2513 Assert.AreEqual (0x00, frames [3].Location.ILOffset);
2521 public void EventSets () {
2523 // Create two filter which both match the same exception
2525 Event e = run_until ("exceptions");
2527 var req = vm.CreateExceptionRequest (null);
2530 var req2 = vm.CreateExceptionRequest (vm.RootDomain.Corlib.GetType ("System.OverflowException"));
2535 var es = vm.GetNextEventSet ();
2536 Assert.AreEqual (2, es.Events.Length);
2539 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2540 Assert.AreEqual ("OverflowException", (e as ExceptionEvent).Exception.Type.Name);
2543 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2544 Assert.AreEqual ("OverflowException", (e as ExceptionEvent).Exception.Type.Name);
2551 // Test single threaded invokes during processing of nullref exceptions.
2552 // These won't work if the exception handling is done from the sigsegv signal
2553 // handler, since the sigsegv signal is disabled until control returns from the
2557 [Category ("only3")]
2558 public void NullRefExceptionAndSingleThreadedInvoke () {
2559 Event e = run_until ("exceptions");
2560 var req = vm.CreateExceptionRequest (vm.RootDomain.Corlib.GetType ("System.NullReferenceException"));
2565 e = GetNextEvent ();
2566 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2567 Assert.AreEqual ("NullReferenceException", (e as ExceptionEvent).Exception.Type.Name);
2569 var ex = (e as ExceptionEvent).Exception;
2570 var tostring_method = vm.RootDomain.Corlib.GetType ("System.Object").GetMethod ("ToString");
2571 ex.InvokeMethod (e.Thread, tostring_method, null, InvokeOptions.SingleThreaded);
2575 public void Domains () {
2578 Start (new string [] { "dtest-app.exe", "domain-test" });
2580 vm.EnableEvents (EventType.AppDomainCreate, EventType.AppDomainUnload, EventType.AssemblyUnload);
2582 Event e = run_until ("domains");
2586 e = GetNextEvent ();
2587 Assert.IsInstanceOfType (typeof (AppDomainCreateEvent), e);
2589 var domain = (e as AppDomainCreateEvent).Domain;
2591 // Check the object type
2592 e = run_until ("domains_2");
2593 var frame = e.Thread.GetFrames ()[0];
2594 var o = frame.GetArgument (0) as ObjectMirror;
2595 Assert.AreEqual ("CrossDomain", o.Type.Name);
2597 // Do a remoting invoke
2598 var cross_domain_type = o.Type;
2599 var v = o.InvokeMethod (e.Thread, cross_domain_type.GetMethod ("invoke_3"), null);
2600 AssertValue (42, v);
2602 // Run until the callback in the domain
2603 MethodMirror m = entry_point.DeclaringType.GetMethod ("invoke_in_domain");
2604 Assert.IsNotNull (m);
2605 vm.SetBreakpoint (m, 0);
2609 e = GetNextEvent ();
2610 if (e is BreakpointEvent)
2614 Assert.AreEqual ("invoke_in_domain", (e as BreakpointEvent).Method.Name);
2616 // d_method is from another domain
2617 MethodMirror d_method = (e as BreakpointEvent).Method;
2618 Assert.IsTrue (m != d_method);
2620 var frames = e.Thread.GetFrames ();
2621 Assert.AreEqual ("invoke_in_domain", frames [0].Method.Name);
2622 Assert.AreEqual ("invoke", frames [1].Method.Name);
2623 Assert.AreEqual ("domains", frames [2].Method.Name);
2625 // Test breakpoints on already JITted methods in other domains
2626 m = entry_point.DeclaringType.GetMethod ("invoke_in_domain_2");
2627 Assert.IsNotNull (m);
2628 vm.SetBreakpoint (m, 0);
2632 e = GetNextEvent ();
2633 if (e is BreakpointEvent)
2637 Assert.AreEqual ("invoke_in_domain_2", (e as BreakpointEvent).Method.Name);
2639 // This is empty when receiving the AppDomainCreateEvent
2640 Assert.AreEqual ("domain", domain.FriendlyName);
2642 // Run until the unload
2645 e = GetNextEvent ();
2646 if (e is AssemblyUnloadEvent) {
2652 Assert.IsInstanceOfType (typeof (AppDomainUnloadEvent), e);
2653 Assert.AreEqual (domain, (e as AppDomainUnloadEvent).Domain);
2655 // Run past the unload
2656 e = run_until ("domains_3");
2658 // Test access to unloaded types
2659 // FIXME: Add an exception type for this
2660 AssertThrows<Exception> (delegate {
2661 d_method.DeclaringType.GetValue (d_method.DeclaringType.GetField ("static_i"));
2666 public void DynamicMethods () {
2667 Event e = run_until ("dyn_call");
2669 var m = e.Thread.GetFrames ()[1].Method;
2670 Assert.AreEqual ("dyn_method", m.Name);
2672 // Test access to IL
2673 var body = m.GetMethodBody ();
2675 ILInstruction ins = body.Instructions [0];
2676 Assert.AreEqual (OpCodes.Ldstr, ins.OpCode);
2677 Assert.AreEqual ("FOO", ins.Operand);
2681 public void RefEmit () {
2684 Start (new string [] { "dtest-app.exe", "ref-emit-test" });
2686 Event e = run_until ("ref_emit_call");
2688 var m = e.Thread.GetFrames ()[1].Method;
2689 Assert.AreEqual ("ref_emit_method", m.Name);
2691 // Test access to IL
2692 var body = m.GetMethodBody ();
2696 ins = body.Instructions [0];
2697 Assert.AreEqual (OpCodes.Ldstr, ins.OpCode);
2698 Assert.AreEqual ("FOO", ins.Operand);
2700 ins = body.Instructions [1];
2701 Assert.AreEqual (OpCodes.Call, ins.OpCode);
2702 Assert.IsInstanceOfType (typeof (MethodMirror), ins.Operand);
2703 Assert.AreEqual ("ref_emit_call", (ins.Operand as MethodMirror).Name);
2707 public void IsAttached () {
2708 var f = entry_point.DeclaringType.GetField ("is_attached");
2710 Event e = run_until ("Main");
2712 AssertValue (true, entry_point.DeclaringType.GetValue (f));
2716 public void StackTraceInNative () {
2717 // Check that stack traces can be produced for threads in native code
2720 Start (new string [] { "dtest-app.exe", "frames-in-native" });
2722 var e = run_until ("frames_in_native");
2724 // FIXME: This is racy
2731 StackFrame[] frames = e.Thread.GetFrames ();
2733 int frame_index = -1;
2734 for (int i = 0; i < frames.Length; ++i) {
2735 if (frames [i].Method.Name == "Sleep") {
2741 Assert.IsTrue (frame_index != -1);
2742 Assert.AreEqual ("Sleep", frames [frame_index].Method.Name);
2743 Assert.AreEqual ("frames_in_native", frames [frame_index + 1].Method.Name);
2744 Assert.AreEqual ("Main", frames [frame_index + 2].Method.Name);
2746 // Check that invokes are disabled for such threads
2747 TypeMirror t = frames [frame_index + 1].Method.DeclaringType;
2750 var m = t.GetMethod ("invoke_static_return_void");
2751 AssertThrows<InvalidOperationException> (delegate {
2752 t.InvokeMethod (e.Thread, m, null);
2757 public void VirtualMachine_CreateEnumMirror () {
2758 var e = run_until ("o1");
2759 var frame = e.Thread.GetFrames () [0];
2761 object val = frame.GetThis ();
2762 Assert.IsTrue (val is ObjectMirror);
2763 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
2764 ObjectMirror o = (val as ObjectMirror);
2766 FieldInfoMirror field = o.Type.GetField ("field_enum");
2767 Value f = o.GetValue (field);
2768 TypeMirror enumType = (f as EnumMirror).Type;
2770 o.SetValue (field, vm.CreateEnumMirror (enumType, vm.CreateValue (1)));
2771 f = o.GetValue (field);
2772 Assert.AreEqual (1, (f as EnumMirror).Value);
2774 // Argument checking
2775 AssertThrows<ArgumentNullException> (delegate () {
2776 vm.CreateEnumMirror (enumType, null);
2779 AssertThrows<ArgumentNullException> (delegate () {
2780 vm.CreateEnumMirror (null, vm.CreateValue (1));
2784 AssertThrows<ArgumentException> (delegate () {
2785 vm.CreateEnumMirror (enumType, vm.CreateValue (null));
2788 // value of a wrong type
2789 AssertThrows<ArgumentException> (delegate () {
2790 vm.CreateEnumMirror (enumType, vm.CreateValue ((long)1));
2795 public void VirtualMachine_EnableEvents_Breakpoint () {
2796 AssertThrows<ArgumentException> (delegate () {
2797 vm.EnableEvents (EventType.Breakpoint);
2802 public void SingleStepRegress654694 () {
2805 MethodMirror m = entry_point.DeclaringType.GetMethod ("ss_regress_654694");
2806 foreach (Location l in m.Locations) {
2807 if (l.ILOffset > 0 && il_offset == -1)
2808 il_offset = l.ILOffset;
2811 Event e = run_until ("ss_regress_654694");
2813 Assert.IsNotNull (m);
2814 vm.SetBreakpoint (m, il_offset);
2818 e = GetNextEvent ();
2819 Assert.IsTrue (e is BreakpointEvent);
2821 var req = vm.CreateStepRequest (e.Thread);
2822 req.Depth = StepDepth.Over;
2823 req.Size = StepSize.Line;
2828 e = GetNextEvent ();
2829 Assert.IsTrue (e is StepEvent);
2835 public void DebugBreak () {
2836 vm.EnableEvents (EventType.UserBreak);
2841 var e = GetNextEvent ();
2842 Assert.IsTrue (e is UserBreakEvent);
2846 public void DebugLog () {
2847 vm.EnableEvents (EventType.UserLog);
2852 var e = GetNextEvent ();
2853 Assert.IsTrue (e is UserLogEvent);
2854 var le = e as UserLogEvent;
2856 Assert.AreEqual (5, le.Level);
2857 Assert.AreEqual ("A", le.Category);
2858 Assert.AreEqual ("B", le.Message);
2862 public void TypeGetMethodsByNameFlags () {
2864 var assembly = entry_point.DeclaringType.Assembly;
2865 var type = assembly.GetType ("Tests3");
2867 Assert.IsNotNull (type);
2869 mm = type.GetMethodsByNameFlags (null, BindingFlags.Static | BindingFlags.Public, false);
2870 Assert.AreEqual (1, mm.Length, "#1");
2871 Assert.AreEqual ("M1", mm[0].Name, "#2");
2873 mm = type.GetMethodsByNameFlags (null, BindingFlags.Static | BindingFlags.NonPublic, false);
2874 Assert.AreEqual (1, mm.Length, "#3");
2875 Assert.AreEqual ("M2", mm[0].Name, "#4");
2877 mm = type.GetMethodsByNameFlags (null, BindingFlags.Instance | BindingFlags.Public, false);
2878 Assert.AreEqual (7, mm.Length, "#5"); //M3 plus Equals, GetHashCode, GetType, ToString, .ctor
2880 mm = type.GetMethodsByNameFlags (null, BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly, false);
2881 Assert.AreEqual (2, mm.Length, "#7");
2883 mm = type.GetMethodsByNameFlags (null, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly, false);
2884 Assert.AreEqual (1, mm.Length, "#9");
2886 mm = type.GetMethodsByNameFlags (null, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly, false);
2887 Assert.AreEqual (5, mm.Length, "#11");
2890 mm = type.GetMethodsByNameFlags ("M1", BindingFlags.Static | BindingFlags.Public, false);
2891 Assert.AreEqual (1, mm.Length, "#12");
2892 Assert.AreEqual ("M1", mm[0].Name, "#13");
2894 mm = type.GetMethodsByNameFlags ("m1", BindingFlags.Static | BindingFlags.Public, true);
2895 Assert.AreEqual (1, mm.Length, "#14");
2896 Assert.AreEqual ("M1", mm[0].Name, "#15");
2898 mm = type.GetMethodsByNameFlags ("M1", BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, false);
2899 Assert.AreEqual (1, mm.Length, "#16");
2900 Assert.AreEqual ("M1", mm[0].Name, "#17");
2904 [Category ("only88")]
2905 public void TypeLoadSourceFileFilter () {
2906 Event e = run_until ("type_load");
2908 if (!vm.Version.AtLeast (2, 7))
2911 string srcfile = (e as BreakpointEvent).Method.DeclaringType.GetSourceFiles (true)[0];
2913 var req = vm.CreateTypeLoadRequest ();
2914 req.SourceFileFilter = new string [] { srcfile.ToUpper () };
2918 e = GetNextEvent ();
2919 Assert.IsTrue (e is TypeLoadEvent);
2920 Assert.AreEqual ("TypeLoadClass", (e as TypeLoadEvent).Type.FullName);
2924 public void TypeLoadTypeNameFilter () {
2925 Event e = run_until ("type_load");
2927 var req = vm.CreateTypeLoadRequest ();
2928 req.TypeNameFilter = new string [] { "TypeLoadClass2" };
2932 e = GetNextEvent ();
2933 Assert.IsTrue (e is TypeLoadEvent);
2934 Assert.AreEqual ("TypeLoadClass2", (e as TypeLoadEvent).Type.FullName);
2938 public void GetTypesForSourceFile () {
2941 var types = vm.GetTypesForSourceFile ("dtest-app.cs", false);
2942 Assert.IsTrue (types.Any (t => t.FullName == "Tests"));
2943 Assert.IsFalse (types.Any (t => t.FullName == "System.Int32"));
2945 types = vm.GetTypesForSourceFile ("DTEST-app.cs", true);
2946 Assert.IsTrue (types.Any (t => t.FullName == "Tests"));
2947 Assert.IsFalse (types.Any (t => t.FullName == "System.Int32"));
2951 public void GetTypesNamed () {
2954 var types = vm.GetTypes ("Tests", false);
2955 Assert.AreEqual (1, types.Count);
2956 Assert.AreEqual ("Tests", types [0].FullName);
2958 types = vm.GetTypes ("System.Exception", false);
2959 Assert.AreEqual (1, types.Count);
2960 Assert.AreEqual ("System.Exception", types [0].FullName);
2964 public void String_GetChars () {
2968 var e = run_until ("arg2");
2970 var frame = e.Thread.GetFrames () [0];
2972 val = frame.GetArgument (0);
2973 Assert.IsTrue (val is StringMirror);
2974 AssertValue ("FOO", val);
2975 var s = (val as StringMirror);
2976 Assert.AreEqual (3, s.Length);
2978 var c = s.GetChars (0, 2);
2979 Assert.AreEqual (2, c.Length);
2980 Assert.AreEqual ('F', c [0]);
2981 Assert.AreEqual ('O', c [1]);
2983 AssertThrows<ArgumentException> (delegate () {
2989 public void GetInterfaces () {
2990 var e = run_until ("arg2");
2992 var frame = e.Thread.GetFrames () [0];
2994 var cl1 = frame.Method.DeclaringType.Assembly.GetType ("TestIfaces");
2995 var ifaces = cl1.GetInterfaces ();
2996 Assert.AreEqual (1, ifaces.Length);
2997 Assert.AreEqual ("ITest", ifaces [0].Name);
2999 var cl2 = cl1.GetMethod ("Baz").ReturnType;
3000 var ifaces2 = cl2.GetInterfaces ();
3001 Assert.AreEqual (1, ifaces2.Length);
3002 Assert.AreEqual ("ITest`1", ifaces2 [0].Name);
3006 public void GetInterfaceMap () {
3007 var e = run_until ("arg2");
3009 var frame = e.Thread.GetFrames () [0];
3011 var cl1 = frame.Method.DeclaringType.Assembly.GetType ("TestIfaces");
3012 var iface = cl1.Assembly.GetType ("ITest");
3013 var map = cl1.GetInterfaceMap (iface);
3014 Assert.AreEqual (cl1, map.TargetType);
3015 Assert.AreEqual (iface, map.InterfaceType);
3016 Assert.AreEqual (2, map.InterfaceMethods.Length);
3017 Assert.AreEqual (2, map.TargetMethods.Length);
3021 public void StackAlloc_Breakpoints_Regress2775 () {
3022 // Check that breakpoints on arm don't overwrite stackalloc-ed memory
3023 var e = run_until ("regress_2755");
3025 var frame = e.Thread.GetFrames () [0];
3027 // This breaks at the call site
3028 vm.SetBreakpoint (m, m.Locations [2].ILOffset);
3031 var e2 = GetNextEvent ();
3032 Assert.IsTrue (e2 is BreakpointEvent);
3034 e = run_until ("regress_2755_3");
3035 frame = e.Thread.GetFrames () [1];
3036 var res = frame.GetValue (m.GetLocal ("sum"));
3037 AssertValue (0, res);
3041 public void MethodInfo () {
3042 Event e = run_until ("locals2");
3044 StackFrame frame = e.Thread.GetFrames () [0];
3045 var m = frame.Method;
3047 Assert.IsTrue (m.IsGenericMethod);
3048 Assert.IsFalse (m.IsGenericMethodDefinition);
3050 var args = m.GetGenericArguments ();
3051 Assert.AreEqual (1, args.Length);
3052 Assert.AreEqual ("String", args [0].Name);
3054 var gmd = m.GetGenericMethodDefinition ();
3055 Assert.IsTrue (gmd.IsGenericMethod);
3056 Assert.IsTrue (gmd.IsGenericMethodDefinition);
3057 Assert.AreEqual (gmd, gmd.GetGenericMethodDefinition ());
3059 args = gmd.GetGenericArguments ();
3060 Assert.AreEqual (1, args.Length);
3061 Assert.AreEqual ("T", args [0].Name);
3063 var attrs = m.GetCustomAttributes (true);
3064 Assert.AreEqual (1, attrs.Length);
3065 Assert.AreEqual ("StateMachineAttribute", attrs [0].Constructor.DeclaringType.Name);
3069 public void UnhandledException () {
3072 Start (new string [] { "dtest-app.exe", "unhandled-exception" });
3074 var req = vm.CreateExceptionRequest (null, false, true);
3077 var e = run_until ("unhandled_exception");
3080 var e2 = GetNextEvent ();
3081 Assert.IsTrue (e2 is ExceptionEvent);