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 NUnit.Framework;
14 #pragma warning disable 0219
17 public class DebuggerTests
20 MethodMirror entry_point;
21 StepEventRequest step_req;
23 void AssertThrows<ExType> (Action del) where ExType : Exception {
31 Assert.IsTrue (thrown);
34 // No other way to pass arguments to the tests ?
35 public static bool listening = Environment.GetEnvironmentVariable ("DBG_SUSPEND") != null;
36 public static string runtime = Environment.GetEnvironmentVariable ("DBG_RUNTIME");
37 public static string agent_args = Environment.GetEnvironmentVariable ("DBG_AGENT_ARGS");
39 void Start (string[] args) {
41 var pi = new Diag.ProcessStartInfo ();
44 pi.FileName = runtime;
47 pi.Arguments = String.Join (" ", args);
48 vm = VirtualMachineManager.Launch (pi, new LaunchOptions { AgentArgs = agent_args });
50 Console.WriteLine ("Listening...");
51 vm = VirtualMachineManager.Listen (new IPEndPoint (IPAddress.Any, 10000));
54 vm.EnableEvents (EventType.AssemblyLoad);
56 Event vmstart = vm.GetNextEvent ();
57 Assert.AreEqual (EventType.VMStart, vmstart.EventType);
66 /* Find out the entry point */
68 e = vm.GetNextEvent ();
70 if (e is AssemblyLoadEvent) {
71 AssemblyLoadEvent ae = (AssemblyLoadEvent)e;
72 entry_point = ae.Assembly.EntryPoint;
73 if (entry_point != null)
81 BreakpointEvent run_until (string name) {
83 MethodMirror m = entry_point.DeclaringType.GetMethod (name);
85 vm.SetBreakpoint (m, 0);
91 e = vm.GetNextEvent ();
92 if (e is BreakpointEvent)
96 Assert.IsInstanceOfType (typeof (BreakpointEvent), e);
97 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
99 return (e as BreakpointEvent);
102 Event single_step (ThreadMirror t) {
103 var req = vm.CreateStepRequest (t);
107 Event e = vm.GetNextEvent ();
108 Assert.IsTrue (e is StepEvent);
115 void check_arg_val (StackFrame frame, int pos, Type type, object eval) {
116 object val = frame.GetArgument (pos);
117 Assert.IsTrue (val is PrimitiveValue);
118 object v = (val as PrimitiveValue).Value;
119 Assert.AreEqual (type, v.GetType ());
121 Assert.IsTrue (Math.Abs ((float)eval - (float)v) < 0.0001);
122 else if (eval is double)
123 Assert.IsTrue (Math.Abs ((double)eval - (double)v) < 0.0001);
125 Assert.AreEqual (eval, v);
128 void AssertValue (object expected, object val) {
129 if (expected is string) {
130 Assert.IsTrue (val is StringMirror);
131 Assert.AreEqual (expected, (val as StringMirror).Value);
132 } else if (val is StructMirror && (val as StructMirror).Type.Name == "IntPtr") {
133 AssertValue (expected, (val as StructMirror).Fields [0]);
135 Assert.IsTrue (val is PrimitiveValue);
136 Assert.AreEqual (expected, (val as PrimitiveValue).Value);
141 public void SetUp () {
142 Start (new string [] { "dtest-app.exe" });
146 public void TearDown () {
150 if (step_req != null)
155 Event e = vm.GetNextEvent ();
157 if (e is VMDeathEvent)
165 public void SimpleBreakpoint () {
168 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp1");
169 Assert.IsNotNull (m);
171 vm.SetBreakpoint (m, 0);
175 e = vm.GetNextEvent ();
176 Assert.AreEqual (EventType.Breakpoint, e.EventType);
177 Assert.IsTrue (e is BreakpointEvent);
178 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
181 AssertThrows<ArgumentException> (delegate {
183 vm.SetBreakpoint (m, 1);
188 public void BreakpointsSameLocation () {
191 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp2");
192 Assert.IsNotNull (m);
194 vm.SetBreakpoint (m, 0);
195 vm.SetBreakpoint (m, 0);
199 e = vm.GetNextEvent ();
200 Assert.IsTrue (e is BreakpointEvent);
201 Assert.AreEqual (m, (e as BreakpointEvent).Method);
203 e = vm.GetNextEvent ();
204 Assert.IsTrue (e is BreakpointEvent);
205 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
209 public void BreakpointAlreadyJITted () {
210 Event e = run_until ("bp1");
212 /* Place a breakpoint on bp3 */
213 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp3");
214 Assert.IsNotNull (m);
215 vm.SetBreakpoint (m, 0);
217 /* Same with generic instances */
218 MethodMirror m2 = entry_point.DeclaringType.GetMethod ("bp7");
219 Assert.IsNotNull (m2);
220 vm.SetBreakpoint (m2, 0);
224 e = vm.GetNextEvent ();
225 Assert.AreEqual (EventType.Breakpoint, e.EventType);
226 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
230 /* Non-shared instance */
231 e = vm.GetNextEvent ();
232 Assert.AreEqual (EventType.Breakpoint, e.EventType);
233 Assert.AreEqual (m2.Name, (e as BreakpointEvent).Method.Name);
237 /* Shared instance */
238 e = vm.GetNextEvent ();
239 Assert.AreEqual (EventType.Breakpoint, e.EventType);
240 Assert.AreEqual (m2.Name, (e as BreakpointEvent).Method.Name);
244 public void ClearBreakpoint () {
247 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp4");
248 Assert.IsNotNull (m);
249 EventRequest req1 = vm.SetBreakpoint (m, 0);
250 EventRequest req2 = vm.SetBreakpoint (m, 0);
252 MethodMirror m2 = entry_point.DeclaringType.GetMethod ("bp5");
253 Assert.IsNotNull (m2);
254 vm.SetBreakpoint (m2, 0);
259 e = vm.GetNextEvent ();
260 Assert.AreEqual (EventType.Breakpoint, e.EventType);
261 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
262 e = vm.GetNextEvent ();
263 Assert.AreEqual (EventType.Breakpoint, e.EventType);
264 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
266 /* Clear one of them */
271 e = vm.GetNextEvent ();
272 Assert.AreEqual (EventType.Breakpoint, e.EventType);
273 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
275 /* Clear the other */
280 e = vm.GetNextEvent ();
281 Assert.AreEqual (EventType.Breakpoint, e.EventType);
282 Assert.AreEqual (m2.Name, (e as BreakpointEvent).Method.Name);
286 public void ClearAllBreakpoints () {
289 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp4");
290 Assert.IsNotNull (m);
291 vm.SetBreakpoint (m, 0);
293 MethodMirror m2 = entry_point.DeclaringType.GetMethod ("bp5");
294 Assert.IsNotNull (m2);
295 vm.SetBreakpoint (m2, 0);
297 vm.ClearAllBreakpoints ();
301 e = vm.GetNextEvent ();
302 Assert.IsTrue (!(e is BreakpointEvent));
303 if (e is VMDeathEvent)
308 public void BreakpointOnGShared () {
311 MethodMirror m = entry_point.DeclaringType.GetMethod ("bp6");
312 Assert.IsNotNull (m);
314 vm.SetBreakpoint (m, 0);
318 e = vm.GetNextEvent ();
319 Assert.AreEqual (EventType.Breakpoint, e.EventType);
320 Assert.IsTrue (e is BreakpointEvent);
321 Assert.AreEqual (m.Name, (e as BreakpointEvent).Method.Name);
325 public void SingleStepping () {
326 Event e = run_until ("single_stepping");
328 var req = vm.CreateStepRequest (e.Thread);
335 e = vm.GetNextEvent ();
336 Assert.IsTrue (e is StepEvent);
337 Assert.AreEqual ("ss1", (e as StepEvent).Method.Name);
341 e = vm.GetNextEvent ();
342 Assert.IsTrue (e is StepEvent);
343 Assert.AreEqual ("single_stepping", (e as StepEvent).Method.Name);
345 // Change to step over
347 req.Depth = StepDepth.Over;
352 e = vm.GetNextEvent ();
353 Assert.IsTrue (e is StepEvent);
354 Assert.AreEqual ("single_stepping", (e as StepEvent).Method.Name);
356 // Change to step into
358 req.Depth = StepDepth.Into;
363 e = vm.GetNextEvent ();
364 Assert.IsTrue (e is StepEvent);
365 Assert.AreEqual ("ss3", (e as StepEvent).Method.Name);
367 // Change to step out
369 req.Depth = StepDepth.Out;
372 // Step back into single_stepping
374 e = vm.GetNextEvent ();
375 Assert.IsTrue (e is StepEvent);
376 Assert.AreEqual ("single_stepping", (e as StepEvent).Method.Name);
378 // Change to step into
380 req.Depth = StepDepth.Into;
383 // Step into ss3_2 ()
385 e = vm.GetNextEvent ();
386 Assert.IsTrue (e is StepEvent);
387 Assert.AreEqual ("ss3_2", (e as StepEvent).Method.Name);
389 // Change to step over
391 req.Depth = StepDepth.Over;
394 // Step over ss3_2_2 ()
396 e = vm.GetNextEvent ();
397 Assert.IsTrue (e is StepEvent);
398 Assert.AreEqual ("ss3_2", (e as StepEvent).Method.Name);
400 // Recreate the request
404 // Step back into single_stepping () with the new request
406 e = vm.GetNextEvent ();
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;
417 e = vm.GetNextEvent ();
418 Assert.IsTrue (e is StepEvent);
419 Assert.AreEqual ("ss4", (e as StepEvent).Method.Name);
421 // Change to StepSize.Line
423 req.Depth = StepDepth.Over;
424 req.Size = StepSize.Line;
427 // Step over ss1 (); ss1 ();
429 e = vm.GetNextEvent ();
430 Assert.IsTrue (e is StepEvent);
434 req.Depth = StepDepth.Into;
438 e = vm.GetNextEvent ();
439 Assert.IsTrue (e is StepEvent);
440 Assert.AreEqual ("ss2", (e as StepEvent).Method.Name);
445 e = run_until ("ss5");
447 // Add an assembly filter
448 req.AssemblyFilter = new AssemblyMirror [] { (e as BreakpointEvent).Method.DeclaringType.Assembly };
451 // Step into is_even, skipping the linq stuff
453 e = vm.GetNextEvent ();
454 Assert.IsTrue (e is StepEvent);
455 Assert.AreEqual ("is_even", (e as StepEvent).Method.Name);
457 // FIXME: Check that single stepping works with lock (obj)
462 e = run_until ("ss6");
464 req = vm.CreateStepRequest (e.Thread);
465 req.Depth = StepDepth.Over;
468 // Check that single stepping works in out-of-line bblocks
470 e = vm.GetNextEvent ();
471 Assert.IsTrue (e is StepEvent);
473 e = vm.GetNextEvent ();
474 Assert.IsTrue (e is StepEvent);
475 Assert.AreEqual ("ss6", (e as StepEvent).Method.Name);
481 public void MethodEntryExit () {
482 run_until ("single_stepping");
484 var req1 = vm.CreateMethodEntryRequest ();
485 var req2 = vm.CreateMethodExitRequest ();
491 Event e = vm.GetNextEvent ();
492 Assert.IsTrue (e is MethodEntryEvent);
493 Assert.AreEqual ("ss1", (e as MethodEntryEvent).Method.Name);
496 e = vm.GetNextEvent ();
497 Assert.IsTrue (e is MethodExitEvent);
498 Assert.AreEqual ("ss1", (e as MethodExitEvent).Method.Name);
505 public void CountFilter () {
506 run_until ("single_stepping");
508 MethodMirror m2 = entry_point.DeclaringType.GetMethod ("ss3");
509 Assert.IsNotNull (m2);
510 vm.SetBreakpoint (m2, 0);
512 var req1 = vm.CreateMethodEntryRequest ();
516 // Enter ss2, ss1 is skipped
518 Event e = vm.GetNextEvent ();
519 Assert.IsTrue (e is MethodEntryEvent);
520 Assert.AreEqual ("ss2", (e as MethodEntryEvent).Method.Name);
522 // Breakpoint on ss3, the entry event is no longer reported
524 e = vm.GetNextEvent ();
525 Assert.IsTrue (e is BreakpointEvent);
531 public void Arguments () {
534 var e = run_until ("arg1");
536 StackFrame frame = e.Thread.GetFrames () [0];
538 check_arg_val (frame, 0, typeof (sbyte), SByte.MaxValue - 5);
539 check_arg_val (frame, 1, typeof (byte), Byte.MaxValue - 5);
540 check_arg_val (frame, 2, typeof (bool), true);
541 check_arg_val (frame, 3, typeof (short), Int16.MaxValue - 5);
542 check_arg_val (frame, 4, typeof (ushort), UInt16.MaxValue - 5);
543 check_arg_val (frame, 5, typeof (char), 'F');
544 check_arg_val (frame, 6, typeof (int), Int32.MaxValue - 5);
545 check_arg_val (frame, 7, typeof (uint), UInt32.MaxValue - 5);
546 check_arg_val (frame, 8, typeof (long), Int64.MaxValue - 5);
547 check_arg_val (frame, 9, typeof (ulong), UInt64.MaxValue - 5);
548 check_arg_val (frame, 10, typeof (float), 1.2345f);
549 check_arg_val (frame, 11, typeof (double), 6.78910);
551 e = run_until ("arg2");
553 frame = e.Thread.GetFrames () [0];
556 val = frame.GetArgument (0);
557 AssertValue ("FOO", val);
558 Assert.AreEqual ("String", (val as ObjectMirror).Type.Name);
561 val = frame.GetArgument (1);
562 AssertValue (null, val);
565 val = frame.GetArgument (2);
566 AssertValue ("BLA", val);
569 val = frame.GetArgument (3);
570 AssertValue (42, val);
573 val = frame.GetArgument (4);
574 Assert.IsTrue (val is ObjectMirror);
575 Assert.AreEqual ("GClass`1", (val as ObjectMirror).Type.Name);
578 val = frame.GetArgument (5);
579 Assert.IsTrue (val is ObjectMirror);
580 Assert.AreEqual ("Object", (val as ObjectMirror).Type.Name);
582 // this on static methods
583 val = frame.GetThis ();
584 AssertValue (null, val);
586 e = run_until ("arg3");
588 frame = e.Thread.GetFrames () [0];
591 val = frame.GetThis ();
592 Assert.IsTrue (val is ObjectMirror);
593 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
595 // objref in register
596 val = frame.GetArgument (0);
597 AssertValue ("BLA", val);
601 public void Arrays () {
604 var e = run_until ("o2");
606 StackFrame frame = e.Thread.GetFrames () [0];
609 val = frame.GetArgument (0);
610 Assert.IsTrue (val is ArrayMirror);
611 ArrayMirror arr = val as ArrayMirror;
612 Assert.AreEqual (2, arr.Length);
613 AssertValue ("BAR", arr [0]);
614 AssertValue ("BAZ", arr [1]);
616 var vals = arr.GetValues (0, 2);
617 Assert.AreEqual (2, vals.Count);
618 AssertValue ("BAR", vals [0]);
619 AssertValue ("BAZ", vals [1]);
621 arr [0] = vm.RootDomain.CreateString ("ABC");
622 AssertValue ("ABC", arr [0]);
624 arr [0] = vm.CreateValue (null);
625 AssertValue (null, arr [0]);
627 arr.SetValues (0, new Value [] { vm.RootDomain.CreateString ("D1"), vm.RootDomain.CreateString ("D2") });
628 AssertValue ("D1", arr [0]);
629 AssertValue ("D2", arr [1]);
632 val = frame.GetArgument (1);
633 Assert.IsTrue (val is ArrayMirror);
634 arr = val as ArrayMirror;
635 Assert.AreEqual (2, arr.Length);
636 AssertValue (42, arr [0]);
637 AssertValue (43, arr [1]);
640 AssertThrows<IndexOutOfRangeException> (delegate () {
644 AssertThrows<IndexOutOfRangeException> (delegate () {
645 val = arr [Int32.MinValue];
648 AssertThrows<IndexOutOfRangeException> (delegate () {
649 vals = arr.GetValues (0, 3);
652 AssertThrows<IndexOutOfRangeException> (delegate () {
653 arr [2] = vm.CreateValue (null);
656 AssertThrows<IndexOutOfRangeException> (delegate () {
657 arr [Int32.MinValue] = vm.CreateValue (null);
660 AssertThrows<IndexOutOfRangeException> (delegate () {
661 arr.SetValues (0, new Value [] { null, null, null });
665 val = frame.GetArgument (2);
666 Assert.IsTrue (val is ArrayMirror);
667 arr = val as ArrayMirror;
668 Assert.AreEqual (2, arr.Rank);
669 Assert.AreEqual (4, arr.Length);
670 Assert.AreEqual (2, arr.GetLength (0));
671 Assert.AreEqual (2, arr.GetLength (1));
672 Assert.AreEqual (0, arr.GetLowerBound (0));
673 Assert.AreEqual (0, arr.GetLowerBound (1));
674 vals = arr.GetValues (0, 4);
675 AssertValue (1, vals [0]);
676 AssertValue (2, vals [1]);
677 AssertValue (3, vals [2]);
678 AssertValue (4, vals [3]);
680 val = frame.GetArgument (3);
681 Assert.IsTrue (val is ArrayMirror);
682 arr = val as ArrayMirror;
683 Assert.AreEqual (2, arr.Rank);
684 Assert.AreEqual (4, arr.Length);
685 Assert.AreEqual (2, arr.GetLength (0));
686 Assert.AreEqual (2, arr.GetLength (1));
687 Assert.AreEqual (1, arr.GetLowerBound (0));
688 Assert.AreEqual (3, arr.GetLowerBound (1));
690 AssertThrows<ArgumentOutOfRangeException> (delegate () {
693 AssertThrows<ArgumentOutOfRangeException> (delegate () {
697 AssertThrows<ArgumentOutOfRangeException> (delegate () {
698 arr.GetLowerBound (-1);
700 AssertThrows<ArgumentOutOfRangeException> (delegate () {
701 arr.GetLowerBound (2);
704 // arrays treated as generic collections
705 val = frame.GetArgument (4);
706 Assert.IsTrue (val is ArrayMirror);
707 arr = val as ArrayMirror;
711 public void Object_GetValue () {
712 var e = run_until ("o1");
713 var frame = e.Thread.GetFrames () [0];
715 object val = frame.GetThis ();
716 Assert.IsTrue (val is ObjectMirror);
717 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
718 ObjectMirror o = (val as ObjectMirror);
720 TypeMirror t = o.Type;
723 object f = o.GetValue (t.GetField ("field_i"));
725 f = o.GetValue (t.GetField ("field_s"));
726 AssertValue ("S", f);
727 f = o.GetValue (t.GetField ("field_enum"));
728 Assert.IsTrue (f is EnumMirror);
729 Assert.AreEqual (1, (f as EnumMirror).Value);
730 Assert.AreEqual ("B", (f as EnumMirror).StringValue);
732 // Inherited object fields
733 TypeMirror parent = t.BaseType;
734 f = o.GetValue (parent.GetField ("base_field_i"));
736 f = o.GetValue (parent.GetField ("base_field_s"));
737 AssertValue ("T", f);
740 f = o.GetValue (o.Type.GetField ("static_i"));
744 ObjectMirror o2 = frame.GetValue (frame.Method.GetParameters ()[1]) as ObjectMirror;
745 Assert.AreEqual ("GClass`1", o2.Type.Name);
746 TypeMirror t2 = o2.Type;
747 f = o2.GetValue (t2.GetField ("field"));
750 ObjectMirror o3 = frame.GetValue (frame.Method.GetParameters ()[2]) as ObjectMirror;
751 Assert.AreEqual ("GClass`1", o3.Type.Name);
752 TypeMirror t3 = o3.Type;
753 f = o3.GetValue (t3.GetField ("field"));
754 AssertValue ("FOO", f);
757 AssertThrows<ArgumentNullException> (delegate () {
763 public void Object_GetValues () {
764 var e = run_until ("o1");
765 var frame = e.Thread.GetFrames () [0];
767 object val = frame.GetThis ();
768 Assert.IsTrue (val is ObjectMirror);
769 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
770 ObjectMirror o = (val as ObjectMirror);
772 ObjectMirror val2 = frame.GetValue (frame.Method.GetParameters ()[0]) as ObjectMirror;
774 TypeMirror t = o.Type;
776 object[] vals = o.GetValues (new FieldInfoMirror [] { t.GetField ("field_i"), t.GetField ("field_s") });
780 AssertValue ("S", f);
783 AssertThrows<ArgumentNullException> (delegate () {
787 AssertThrows<ArgumentNullException> (delegate () {
788 o.GetValues (new FieldInfoMirror [] { null });
791 // field of another class
792 AssertThrows<ArgumentException> (delegate () {
793 o.GetValue (val2.Type.GetField ("field_j"));
797 void TestSetValue (ObjectMirror o, string field_name, object val) {
799 o.SetValue (o.Type.GetField (field_name), vm.RootDomain.CreateString ((string)val));
801 o.SetValue (o.Type.GetField (field_name), vm.CreateValue (val));
802 Value f = o.GetValue (o.Type.GetField (field_name));
803 AssertValue (val, f);
807 public void Object_SetValues () {
808 var e = run_until ("o1");
809 var frame = e.Thread.GetFrames () [0];
811 object val = frame.GetThis ();
812 Assert.IsTrue (val is ObjectMirror);
813 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
814 ObjectMirror o = (val as ObjectMirror);
816 ObjectMirror val2 = frame.GetValue (frame.Method.GetParameters ()[0]) as ObjectMirror;
818 TestSetValue (o, "field_i", 22);
819 TestSetValue (o, "field_bool1", false);
820 TestSetValue (o, "field_bool2", true);
821 TestSetValue (o, "field_char", 'B');
822 TestSetValue (o, "field_byte", (byte)129);
823 TestSetValue (o, "field_sbyte", (sbyte)-33);
824 TestSetValue (o, "field_short", (short)(Int16.MaxValue - 5));
825 TestSetValue (o, "field_ushort", (ushort)(UInt16.MaxValue - 5));
826 TestSetValue (o, "field_long", Int64.MaxValue - 5);
827 TestSetValue (o, "field_ulong", (ulong)(UInt64.MaxValue - 5));
828 TestSetValue (o, "field_float", 6.28f);
829 TestSetValue (o, "field_double", 6.28);
830 TestSetValue (o, "static_i", 23);
831 TestSetValue (o, "field_s", "CDEF");
836 f = o.GetValue (o.Type.GetField ("field_intptr"));
837 Assert.IsInstanceOfType (typeof (StructMirror), f);
838 AssertValue (Int32.MaxValue - 5, (f as StructMirror).Fields [0]);
842 FieldInfoMirror field = o.Type.GetField ("field_enum");
843 f = o.GetValue (field);
844 (f as EnumMirror).Value = 5;
845 o.SetValue (field, f);
846 f = o.GetValue (field);
847 Assert.AreEqual (5, (f as EnumMirror).Value);
850 o.SetValue (o.Type.GetField ("field_s"), vm.CreateValue (null));
851 f = o.GetValue (o.Type.GetField ("field_s"));
852 AssertValue (null, f);
855 field = o.Type.GetField ("generic_field_struct");
856 f = o.GetValue (field);
857 o.SetValue (field, f);
860 AssertThrows<ArgumentNullException> (delegate () {
861 o.SetValues (null, new Value [0]);
864 AssertThrows<ArgumentNullException> (delegate () {
865 o.SetValues (new FieldInfoMirror [0], null);
868 AssertThrows<ArgumentNullException> (delegate () {
869 o.SetValues (new FieldInfoMirror [] { null }, new Value [1] { null });
872 // vtype with a wrong type
873 AssertThrows<ArgumentException> (delegate () {
874 o.SetValue (o.Type.GetField ("field_struct"), o.GetValue (o.Type.GetField ("field_enum")));
877 // reference type not assignment compatible
878 AssertThrows<ArgumentException> (delegate () {
879 o.SetValue (o.Type.GetField ("field_class"), o);
882 // field of another class
883 AssertThrows<ArgumentException> (delegate () {
884 o.SetValue (val2.Type.GetField ("field_j"), vm.CreateValue (1));
889 public void Type_SetValue () {
890 var e = run_until ("o1");
891 var frame = e.Thread.GetFrames () [0];
894 object val = frame.GetThis ();
895 Assert.IsTrue (val is ObjectMirror);
896 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
897 ObjectMirror o = (val as ObjectMirror);
899 ObjectMirror val2 = frame.GetValue (frame.Method.GetParameters ()[0]) as ObjectMirror;
901 o.Type.SetValue (o.Type.GetField ("static_i"), vm.CreateValue (55));
902 f = o.Type.GetValue (o.Type.GetField ("static_i"));
905 o.Type.SetValue (o.Type.GetField ("static_s"), vm.RootDomain.CreateString ("B"));
906 f = o.Type.GetValue (o.Type.GetField ("static_s"));
907 AssertValue ("B", f);
910 AssertThrows<ArgumentNullException> (delegate () {
911 o.Type.SetValue (null, vm.CreateValue (0));
914 AssertThrows<ArgumentNullException> (delegate () {
915 o.Type.SetValue (o.Type.GetField ("static_i"), null);
918 // field of another class
919 AssertThrows<ArgumentException> (delegate () {
920 o.SetValue (val2.Type.GetField ("field_j"), vm.CreateValue (1));
925 public void TypeInfo () {
926 Event e = run_until ("ti2");
927 StackFrame frame = e.Thread.GetFrames () [0];
932 t = frame.Method.GetParameters ()[0].ParameterType;
934 Assert.AreEqual ("String[]", t.Name);
935 Assert.AreEqual ("string[]", t.CSharpName);
936 Assert.AreEqual ("Array", t.BaseType.Name);
937 Assert.AreEqual (true, t.HasElementType);
938 Assert.AreEqual (true, t.IsArray);
939 Assert.AreEqual (1, t.GetArrayRank ());
940 Assert.AreEqual ("String", t.GetElementType ().Name);
942 t = frame.Method.GetParameters ()[2].ParameterType;
944 Assert.AreEqual ("Int32[,]", t.Name);
946 //Assert.AreEqual ("int[,]", t.CSharpName);
947 Assert.AreEqual ("Array", t.BaseType.Name);
948 Assert.AreEqual (true, t.HasElementType);
949 Assert.AreEqual (true, t.IsArray);
950 Assert.AreEqual (2, t.GetArrayRank ());
951 Assert.AreEqual ("Int32", t.GetElementType ().Name);
954 t = frame.Method.GetParameters ()[3].ParameterType;
956 //Assert.AreEqual ("Int32&", t.Name);
957 //Assert.AreEqual (true, t.IsByRef);
958 //Assert.AreEqual (true, t.HasElementType);
961 t = frame.Method.GetParameters ()[4].ParameterType;
963 //Assert.AreEqual ("Int32*", t.Name);
964 Assert.AreEqual (true, t.IsPointer);
965 Assert.AreEqual (true, t.HasElementType);
966 Assert.AreEqual ("Int32", t.GetElementType ().Name);
967 Assert.AreEqual (false, t.IsPrimitive);
970 t = frame.Method.GetParameters ()[5].ParameterType;
971 Assert.AreEqual (true, t.IsPrimitive);
974 t = frame.Method.GetParameters ()[6].ParameterType;
975 Assert.AreEqual ("AStruct", t.Name);
976 Assert.AreEqual (false, t.IsPrimitive);
977 Assert.AreEqual (true, t.IsValueType);
978 Assert.AreEqual (false, t.IsClass);
981 t = frame.Method.GetParameters ()[7].ParameterType;
982 Assert.AreEqual ("Tests", t.Name);
983 var nested = (from nt in t.GetNestedTypes () where nt.IsNestedPublic select nt).ToArray ();
984 Assert.AreEqual (1, nested.Length);
985 Assert.AreEqual ("NestedClass", nested [0].Name);
986 Assert.IsTrue (t.BaseType.IsAssignableFrom (t));
987 Assert.IsTrue (!t.IsAssignableFrom (t.BaseType));
990 t = frame.Method.GetParameters ()[9].ParameterType;
991 Assert.AreEqual ("GClass`1", t.Name);
994 t = frame.Method.GetParameters ()[10].ParameterType;
995 Assert.AreEqual ("AnEnum", t.Name);
996 Assert.IsTrue (t.IsEnum);
997 Assert.AreEqual ("Int32", t.EnumUnderlyingType.Name);
1000 t = frame.Method.GetParameters ()[7].ParameterType;
1002 var props = t.GetProperties ();
1003 Assert.AreEqual (3, props.Length);
1004 foreach (PropertyInfoMirror prop in props) {
1005 ParameterInfoMirror[] indexes = prop.GetIndexParameters ();
1007 if (prop.Name == "IntProperty") {
1008 Assert.AreEqual ("Int32", prop.PropertyType.Name);
1009 Assert.AreEqual ("get_IntProperty", prop.GetGetMethod ().Name);
1010 Assert.AreEqual ("set_IntProperty", prop.GetSetMethod ().Name);
1011 Assert.AreEqual (0, indexes.Length);
1012 } else if (prop.Name == "ReadOnlyProperty") {
1013 Assert.AreEqual ("Int32", prop.PropertyType.Name);
1014 Assert.AreEqual ("get_ReadOnlyProperty", prop.GetGetMethod ().Name);
1015 Assert.AreEqual (null, prop.GetSetMethod ());
1016 Assert.AreEqual (0, indexes.Length);
1017 } else if (prop.Name == "IndexedProperty") {
1018 Assert.AreEqual (1, indexes.Length);
1019 Assert.AreEqual ("Int32", indexes [0].ParameterType.Name);
1023 // custom attributes
1024 t = frame.Method.GetParameters ()[8].ParameterType;
1025 Assert.AreEqual ("Tests2", t.Name);
1026 var attrs = t.GetCustomAttributes (true);
1027 Assert.AreEqual (2, attrs.Length);
1028 foreach (var attr in attrs) {
1029 if (attr.Constructor.DeclaringType.Name == "DebuggerDisplayAttribute") {
1030 Assert.AreEqual (1, attr.ConstructorArguments.Count);
1031 Assert.AreEqual ("Tests", attr.ConstructorArguments [0].Value);
1032 Assert.AreEqual (2, attr.NamedArguments.Count);
1033 Assert.AreEqual ("Name", attr.NamedArguments [0].Property.Name);
1034 Assert.AreEqual ("FOO", attr.NamedArguments [0].TypedValue.Value);
1035 Assert.AreEqual ("Target", attr.NamedArguments [1].Property.Name);
1036 Assert.IsInstanceOfType (typeof (TypeMirror), attr.NamedArguments [1].TypedValue.Value);
1037 Assert.AreEqual ("Int32", (attr.NamedArguments [1].TypedValue.Value as TypeMirror).Name);
1038 } else if (attr.Constructor.DeclaringType.Name == "DebuggerTypeProxyAttribute") {
1039 Assert.AreEqual (1, attr.ConstructorArguments.Count);
1040 Assert.IsInstanceOfType (typeof (TypeMirror), attr.ConstructorArguments [0].Value);
1041 Assert.AreEqual ("Tests", (attr.ConstructorArguments [0].Value as TypeMirror).Name);
1043 Assert.Fail (attr.Constructor.DeclaringType.Name);
1049 public void FieldInfo () {
1050 Event e = run_until ("ti2");
1051 StackFrame frame = e.Thread.GetFrames () [0];
1055 t = frame.Method.GetParameters ()[8].ParameterType;
1056 Assert.AreEqual ("Tests2", t.Name);
1058 var fi = t.GetField ("field_j");
1059 var attrs = fi.GetCustomAttributes (true);
1060 Assert.AreEqual (1, attrs.Length);
1061 var attr = attrs [0];
1062 Assert.AreEqual ("DebuggerBrowsableAttribute", attr.Constructor.DeclaringType.Name);
1063 Assert.AreEqual (1, attr.ConstructorArguments.Count);
1064 Assert.IsInstanceOfType (typeof (EnumMirror), attr.ConstructorArguments [0].Value);
1065 Assert.AreEqual ((int)System.Diagnostics.DebuggerBrowsableState.Collapsed, (attr.ConstructorArguments [0].Value as EnumMirror).Value);
1069 public void PropertyInfo () {
1070 Event e = run_until ("ti2");
1071 StackFrame frame = e.Thread.GetFrames () [0];
1075 t = frame.Method.GetParameters ()[8].ParameterType;
1076 Assert.AreEqual ("Tests2", t.Name);
1078 var pi = t.GetProperty ("AProperty");
1079 var attrs = pi.GetCustomAttributes (true);
1080 Assert.AreEqual (1, attrs.Length);
1081 var attr = attrs [0];
1082 Assert.AreEqual ("DebuggerBrowsableAttribute", attr.Constructor.DeclaringType.Name);
1083 Assert.AreEqual (1, attr.ConstructorArguments.Count);
1084 Assert.IsInstanceOfType (typeof (EnumMirror), attr.ConstructorArguments [0].Value);
1085 Assert.AreEqual ((int)System.Diagnostics.DebuggerBrowsableState.Collapsed, (attr.ConstructorArguments [0].Value as EnumMirror).Value);
1089 public void Type_GetValue () {
1090 Event e = run_until ("o1");
1091 StackFrame frame = e.Thread.GetFrames () [0];
1093 ObjectMirror o = (frame.GetThis () as ObjectMirror);
1095 TypeMirror t = o.Type;
1097 ObjectMirror val2 = frame.GetValue (frame.Method.GetParameters ()[0]) as ObjectMirror;
1100 object f = t.GetValue (o.Type.GetField ("static_i"));
1101 AssertValue (55, f);
1103 f = t.GetValue (o.Type.GetField ("static_s"));
1104 AssertValue ("A", f);
1106 // literal static fields
1107 f = t.GetValue (o.Type.GetField ("literal_i"));
1108 AssertValue (56, f);
1110 f = t.GetValue (o.Type.GetField ("literal_s"));
1111 AssertValue ("B", f);
1113 // Inherited static fields
1114 TypeMirror parent = t.BaseType;
1115 f = t.GetValue (parent.GetField ("base_static_i"));
1116 AssertValue (57, f);
1118 f = t.GetValue (parent.GetField ("base_static_s"));
1119 AssertValue ("C", f);
1121 // Argument checking
1122 AssertThrows<ArgumentNullException> (delegate () {
1127 AssertThrows<ArgumentException> (delegate () {
1128 t.GetValue (o.Type.GetField ("field_i"));
1131 // field on another type
1132 AssertThrows<ArgumentException> (delegate () {
1133 t.GetValue (val2.Type.GetField ("static_field_j"));
1136 // special static field
1137 AssertThrows<ArgumentException> (delegate () {
1138 t.GetValue (t.GetField ("tls_i"));
1143 public void Type_GetValues () {
1144 Event e = run_until ("o1");
1145 StackFrame frame = e.Thread.GetFrames () [0];
1147 ObjectMirror o = (frame.GetThis () as ObjectMirror);
1149 TypeMirror t = o.Type;
1152 object[] vals = t.GetValues (new FieldInfoMirror [] { t.GetField ("static_i"), t.GetField ("static_s") });
1153 object f = vals [0];
1154 AssertValue (55, f);
1157 AssertValue ("A", f);
1159 // Argument checking
1160 AssertThrows<ArgumentNullException> (delegate () {
1164 AssertThrows<ArgumentNullException> (delegate () {
1165 t.GetValues (new FieldInfoMirror [] { null });
1170 public void ObjRefs () {
1171 Event e = run_until ("objrefs1");
1172 StackFrame frame = e.Thread.GetFrames () [0];
1174 ObjectMirror o = frame.GetThis () as ObjectMirror;
1175 ObjectMirror child = o.GetValue (o.Type.GetField ("child")) as ObjectMirror;
1177 Assert.IsTrue (child.Address > 0);
1179 // Check that object references are internalized correctly
1180 Assert.AreEqual (o, frame.GetThis ());
1182 run_until ("objrefs2");
1184 // child should be gc'd now
1185 Assert.IsTrue (child.IsCollected);
1187 AssertThrows<ObjectCollectedException> (delegate () {
1188 TypeMirror t = child.Type;
1191 AssertThrows<ObjectCollectedException> (delegate () {
1192 long addr = child.Address;
1197 public void Type_GetObject () {
1198 Event e = run_until ("o1");
1199 StackFrame frame = e.Thread.GetFrames () [0];
1201 ObjectMirror o = (frame.GetThis () as ObjectMirror);
1203 TypeMirror t = o.Type;
1205 Assert.AreEqual ("MonoType", t.GetTypeObject ().Type.Name);
1209 public void VTypes () {
1210 Event e = run_until ("vtypes1");
1211 StackFrame frame = e.Thread.GetFrames () [0];
1214 ObjectMirror o = frame.GetThis () as ObjectMirror;
1215 var obj = o.GetValue (o.Type.GetField ("field_struct"));
1216 Assert.IsTrue (obj is StructMirror);
1217 var s = obj as StructMirror;
1218 Assert.AreEqual ("AStruct", s.Type.Name);
1219 AssertValue (42, s ["i"]);
1221 AssertValue ("S", obj);
1222 AssertValue (43, s ["k"]);
1223 obj = o.GetValue (o.Type.GetField ("field_boxed_struct"));
1224 Assert.IsTrue (obj is StructMirror);
1225 s = obj as StructMirror;
1226 Assert.AreEqual ("AStruct", s.Type.Name);
1227 AssertValue (42, s ["i"]);
1229 // vtypes as arguments
1230 s = frame.GetArgument (0) as StructMirror;
1231 AssertValue (44, s ["i"]);
1233 AssertValue ("T", obj);
1234 AssertValue (45, s ["k"]);
1236 // vtypes as array entries
1237 var arr = frame.GetArgument (1) as ArrayMirror;
1239 Assert.IsTrue (obj is StructMirror);
1240 s = obj as StructMirror;
1241 AssertValue (1, s ["i"]);
1242 AssertValue ("S1", s ["s"]);
1244 Assert.IsTrue (obj is StructMirror);
1245 s = obj as StructMirror;
1246 AssertValue (2, s ["i"]);
1247 AssertValue ("S2", s ["s"]);
1249 // Argument checking
1250 s = frame.GetArgument (0) as StructMirror;
1251 AssertThrows<ArgumentException> (delegate () {
1255 // generic vtype instances
1256 o = frame.GetThis () as ObjectMirror;
1257 obj = o.GetValue (o.Type.GetField ("generic_field_struct"));
1258 Assert.IsTrue (obj is StructMirror);
1259 s = obj as StructMirror;
1260 Assert.AreEqual ("GStruct`1", s.Type.Name);
1261 AssertValue (42, s ["i"]);
1263 // this on vtype methods
1264 e = run_until ("vtypes2");
1266 e = single_step (e.Thread);
1268 frame = e.Thread.GetFrames () [0];
1270 Assert.AreEqual ("foo", (e as StepEvent).Method.Name);
1271 obj = frame.GetThis ();
1273 Assert.IsTrue (obj is StructMirror);
1274 s = obj as StructMirror;
1275 AssertValue (44, s ["i"]);
1276 AssertValue ("T", s ["s"]);
1277 AssertValue (45, s ["k"]);
1279 // this on static vtype methods
1280 e = run_until ("vtypes3");
1282 e = single_step (e.Thread);
1284 frame = e.Thread.GetFrames () [0];
1286 Assert.AreEqual ("static_foo", (e as StepEvent).Method.Name);
1287 obj = frame.GetThis ();
1288 AssertValue (null, obj);
1292 public void AssemblyInfo () {
1293 Event e = run_until ("single_stepping");
1295 StackFrame frame = e.Thread.GetFrames () [0];
1297 var aname = frame.Method.DeclaringType.Assembly.GetName ();
1298 Assert.AreEqual ("dtest-app, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", aname.ToString ());
1300 ModuleMirror m = frame.Method.DeclaringType.Module;
1302 Assert.AreEqual ("dtest-app.exe", m.Name);
1303 Assert.AreEqual ("dtest-app.exe", m.ScopeName);
1304 Assert.IsTrue (m.FullyQualifiedName.IndexOf ("dtest-app.exe") != -1);
1305 Guid guid = m.ModuleVersionId;
1306 Assert.AreEqual (frame.Method.DeclaringType.Assembly, m.Assembly);
1307 Assert.AreEqual (frame.Method.DeclaringType.Assembly.ManifestModule, m);
1309 Assert.AreEqual ("Assembly", frame.Method.DeclaringType.Assembly.GetAssemblyObject ().Type.Name);
1311 TypeMirror t = vm.RootDomain.Corlib.GetType ("System.Diagnostics.DebuggerDisplayAttribute");
1312 Assert.AreEqual ("DebuggerDisplayAttribute", t.Name);
1316 public void LocalsInfo () {
1317 Event e = run_until ("locals2");
1319 StackFrame frame = e.Thread.GetFrames () [0];
1321 var locals = frame.Method.GetLocals ();
1322 Assert.AreEqual (6, locals.Length);
1323 for (int i = 0; i < 6; ++i) {
1324 if (locals [i].Name == "args") {
1325 Assert.IsTrue (locals [i].IsArg);
1326 Assert.AreEqual ("String[]", locals [i].Type.Name);
1327 } else if (locals [i].Name == "arg") {
1328 Assert.IsTrue (locals [i].IsArg);
1329 Assert.AreEqual ("Int32", locals [i].Type.Name);
1330 } else if (locals [i].Name == "i") {
1331 Assert.IsFalse (locals [i].IsArg);
1332 Assert.AreEqual ("Int64", locals [i].Type.Name);
1333 } else if (locals [i].Name == "j") {
1334 Assert.IsFalse (locals [i].IsArg);
1335 Assert.AreEqual ("Int32", locals [i].Type.Name);
1336 } else if (locals [i].Name == "s") {
1337 Assert.IsFalse (locals [i].IsArg);
1338 Assert.AreEqual ("String", locals [i].Type.Name);
1339 } else if (locals [i].Name == "t") {
1341 Assert.IsTrue (locals [i].IsArg);
1342 Assert.AreEqual ("String", locals [i].Type.Name);
1351 public void Locals () {
1352 var be = run_until ("locals1");
1354 StackFrame frame = be.Thread.GetFrames () [0];
1356 MethodMirror m1 = frame.Method;
1358 be = run_until ("locals2");
1360 frame = be.Thread.GetFrames () [0];
1362 object val = frame.GetValue (frame.Method.GetLocal ("i"));
1363 AssertValue (0, val);
1366 var req = vm.CreateStepRequest (be.Thread);
1370 var e = vm.GetNextEvent ();
1371 Assert.IsTrue (e is StepEvent);
1372 Assert.AreEqual ("locals2", (e as StepEvent).Method.Name);
1374 // Execute s = "AB";
1376 e = vm.GetNextEvent ();
1377 Assert.IsTrue (e is StepEvent);
1378 Assert.AreEqual ("locals2", (e as StepEvent).Method.Name);
1380 frame = e.Thread.GetFrames () [0];
1382 val = frame.GetValue (frame.Method.GetLocal ("i"));
1383 AssertValue (42, val);
1385 LocalVariable[] locals = frame.Method.GetLocals ();
1386 var vals = frame.GetValues (locals);
1387 Assert.AreEqual (locals.Length, vals.Length);
1388 for (int i = 0; i < locals.Length; ++i) {
1389 if (locals [i].Name == "i")
1390 AssertValue (42, vals [i]);
1391 if (locals [i].Name == "s")
1392 AssertValue ("AB", vals [i]);
1393 if (locals [i].Name == "t")
1394 AssertValue ("ABC", vals [i]);
1397 // Argument checking
1400 AssertThrows<ArgumentNullException> (delegate () {
1401 frame.GetValue ((LocalVariable)null);
1403 // GetValue () local from another method
1404 AssertThrows<ArgumentException> (delegate () {
1405 frame.GetValue (m1.GetLocal ("foo"));
1409 AssertThrows<ArgumentNullException> (delegate () {
1410 frame.GetValue ((ParameterInfoMirror)null);
1412 // GetValue () local from another method
1413 AssertThrows<ArgumentException> (delegate () {
1414 frame.GetValue (m1.GetParameters ()[0]);
1417 // GetValues () null
1418 AssertThrows<ArgumentNullException> (delegate () {
1419 frame.GetValues (null);
1421 // GetValues () embedded null
1422 AssertThrows<ArgumentNullException> (delegate () {
1423 frame.GetValues (new LocalVariable [] { null });
1425 // GetValues () local from another method
1426 AssertThrows<ArgumentException> (delegate () {
1427 frame.GetValues (new LocalVariable [] { m1.GetLocal ("foo") });
1430 AssertThrows<ArgumentException> (delegate () {
1431 val = frame.GetValue (frame.Method.ReturnParameter);
1434 // invalid stack frames
1436 e = vm.GetNextEvent ();
1437 Assert.IsTrue (e is StepEvent);
1438 Assert.AreEqual ("locals2", (e as StepEvent).Method.Name);
1440 AssertThrows<InvalidStackFrameException> (delegate () {
1441 frame.GetValue (frame.Method.GetLocal ("i"));
1448 public void GetVisibleVariables () {
1449 Event e = run_until ("locals4");
1452 var locals = e.Thread.GetFrames ()[1].GetVisibleVariables ();
1453 Assert.AreEqual (2, locals.Count);
1454 var loc = locals.First (l => l.Name == "i");
1455 Assert.AreEqual ("Int64", loc.Type.Name);
1456 loc = locals.First (l => l.Name == "s");
1457 Assert.AreEqual ("String", loc.Type.Name);
1459 loc = e.Thread.GetFrames ()[1].GetVisibleVariableByName ("i");
1460 Assert.AreEqual ("i", loc.Name);
1461 Assert.AreEqual ("Int64", loc.Type.Name);
1463 e = run_until ("locals5");
1466 locals = e.Thread.GetFrames ()[1].GetVisibleVariables ();
1467 Assert.AreEqual (2, locals.Count);
1468 loc = locals.First (l => l.Name == "i");
1469 Assert.AreEqual ("String", loc.Type.Name);
1470 loc = locals.First (l => l.Name == "s");
1471 Assert.AreEqual ("String", loc.Type.Name);
1473 loc = e.Thread.GetFrames ()[1].GetVisibleVariableByName ("i");
1474 Assert.AreEqual ("i", loc.Name);
1475 Assert.AreEqual ("String", loc.Type.Name);
1477 // Variable in another scope
1478 loc = e.Thread.GetFrames ()[1].GetVisibleVariableByName ("j");
1479 Assert.IsNull (loc);
1483 public void Exit () {
1488 var e = vm.GetNextEvent ();
1489 Assert.IsInstanceOfType (typeof (VMDeathEvent), e);
1492 /* Could be a remote vm with no process */
1495 Assert.AreEqual (5, p.ExitCode);
1498 AssertThrows<VMDisconnectedException> (delegate () {
1507 public void Dispose () {
1512 var e = vm.GetNextEvent ();
1513 Assert.IsInstanceOfType (typeof (VMDisconnectEvent), e);
1516 /* Could be a remote vm with no process */
1519 Assert.AreEqual (3, p.ExitCode);
1522 AssertThrows<VMDisconnectedException> (delegate () {
1531 public void LineNumbers () {
1532 Event e = run_until ("line_numbers");
1534 step_req = vm.CreateStepRequest (e.Thread);
1535 step_req.Depth = StepDepth.Into;
1542 e = vm.GetNextEvent ();
1543 Assert.IsTrue (e is StepEvent);
1545 l = e.Thread.GetFrames ()[0].Location;
1547 Assert.IsTrue (l.SourceFile.IndexOf ("dtest-app.cs") != -1);
1548 Assert.AreEqual ("ln1", l.Method.Name);
1550 int line_base = l.LineNumber;
1553 e = vm.GetNextEvent ();
1554 Assert.IsTrue (e is StepEvent);
1555 l = e.Thread.GetFrames ()[0].Location;
1556 Assert.AreEqual ("ln2", l.Method.Name);
1557 Assert.AreEqual (line_base + 6, l.LineNumber);
1560 e = vm.GetNextEvent ();
1561 Assert.IsTrue (e is StepEvent);
1562 l = e.Thread.GetFrames ()[0].Location;
1563 Assert.AreEqual ("ln1", l.Method.Name);
1564 Assert.AreEqual (line_base + 1, l.LineNumber);
1567 e = vm.GetNextEvent ();
1568 Assert.IsTrue (e is StepEvent);
1569 l = e.Thread.GetFrames ()[0].Location;
1570 Assert.AreEqual ("ln3", l.Method.Name);
1571 Assert.AreEqual (line_base + 10, l.LineNumber);
1574 e = vm.GetNextEvent ();
1575 Assert.IsTrue (e is StepEvent);
1576 l = e.Thread.GetFrames ()[0].Location;
1577 Assert.AreEqual ("ln1", l.Method.Name);
1578 Assert.AreEqual (line_base + 2, l.LineNumber);
1580 // GetSourceFiles ()
1581 string[] sources = l.Method.DeclaringType.GetSourceFiles ();
1582 Assert.AreEqual (1, sources.Length);
1583 Assert.AreEqual ("dtest-app.cs", sources [0]);
1585 sources = l.Method.DeclaringType.GetSourceFiles (true);
1586 Assert.AreEqual (1, sources.Length);
1587 Assert.IsTrue (sources [0].EndsWith ("dtest-app.cs"));
1591 public void Suspend () {
1594 Start (new string [] { "dtest-app.exe", "suspend-test" });
1596 Event e = run_until ("suspend");
1598 ThreadMirror main = e.Thread;
1606 // The debuggee should be suspended while it is running the infinite loop
1608 StackFrame frame = main.GetFrames ()[0];
1609 Assert.AreEqual ("suspend", frame.Method.Name);
1613 // resuming when not suspended
1614 AssertThrows<InvalidOperationException> (delegate () {
1624 public void AssemblyLoad () {
1625 Event e = run_until ("assembly_load");
1629 e = vm.GetNextEvent ();
1630 Assert.IsInstanceOfType (typeof (AssemblyLoadEvent), e);
1631 Assert.IsTrue ((e as AssemblyLoadEvent).Assembly.Location.EndsWith ("System.dll"));
1633 var frames = e.Thread.GetFrames ();
1634 Assert.IsTrue (frames.Length > 0);
1635 Assert.AreEqual ("assembly_load", frames [0].Method.Name);
1639 public void CreateValue () {
1642 v = vm.CreateValue (1);
1643 Assert.AreEqual (vm, v.VirtualMachine);
1644 Assert.AreEqual (1, v.Value);
1646 v = vm.CreateValue (null);
1647 Assert.AreEqual (vm, v.VirtualMachine);
1648 Assert.AreEqual (null, v.Value);
1650 // Argument checking
1651 AssertThrows <ArgumentException> (delegate () {
1652 v = vm.CreateValue ("FOO");
1657 public void CreateString () {
1658 StringMirror s = vm.RootDomain.CreateString ("ABC");
1660 Assert.AreEqual (vm, s.VirtualMachine);
1661 Assert.AreEqual ("ABC", s.Value);
1662 Assert.AreEqual (vm.RootDomain, s.Domain);
1665 StringBuilder sb = new StringBuilder ();
1666 for (int i = 0; i < 1024; ++i)
1668 s = vm.RootDomain.CreateString (sb.ToString ());
1670 // Argument checking
1671 AssertThrows <ArgumentNullException> (delegate () {
1672 s = vm.RootDomain.CreateString (null);
1677 public void CreateBoxedValue () {
1678 ObjectMirror o = vm.RootDomain.CreateBoxedValue (new PrimitiveValue (vm, 42));
1680 Assert.AreEqual ("Int32", o.Type.Name);
1681 //AssertValue (42, m.GetValue (o.Type.GetField ("m_value")));
1683 // Argument checking
1684 AssertThrows <ArgumentNullException> (delegate () {
1685 vm.RootDomain.CreateBoxedValue (null);
1688 AssertThrows <ArgumentException> (delegate () {
1689 vm.RootDomain.CreateBoxedValue (o);
1694 public void Invoke () {
1695 Event e = run_until ("invoke1");
1697 StackFrame frame = e.Thread.GetFrames () [0];
1699 TypeMirror t = frame.Method.DeclaringType;
1700 ObjectMirror this_obj = (ObjectMirror)frame.GetThis ();
1702 TypeMirror t2 = frame.Method.GetParameters ()[0].ParameterType;
1708 m = t.GetMethod ("invoke_return_void");
1709 v = this_obj.InvokeMethod (e.Thread, m, null);
1713 m = t.GetMethod ("invoke_return_ref");
1714 v = this_obj.InvokeMethod (e.Thread, m, null);
1715 AssertValue ("ABC", v);
1718 m = t.GetMethod ("invoke_return_null");
1719 v = this_obj.InvokeMethod (e.Thread, m, null);
1720 AssertValue (null, v);
1723 m = t.GetMethod ("invoke_return_primitive");
1724 v = this_obj.InvokeMethod (e.Thread, m, null);
1725 AssertValue (42, v);
1728 m = t.GetMethod ("invoke_pass_primitive");
1729 Value[] args = new Value [] {
1730 vm.CreateValue ((byte)Byte.MaxValue),
1731 vm.CreateValue ((sbyte)SByte.MaxValue),
1732 vm.CreateValue ((short)1),
1733 vm.CreateValue ((ushort)1),
1734 vm.CreateValue ((int)1),
1735 vm.CreateValue ((uint)1),
1736 vm.CreateValue ((long)1),
1737 vm.CreateValue ((ulong)1),
1738 vm.CreateValue ('A'),
1739 vm.CreateValue (true),
1740 vm.CreateValue (3.14f),
1741 vm.CreateValue (3.14) };
1743 v = this_obj.InvokeMethod (e.Thread, m, args);
1744 AssertValue ((int)Byte.MaxValue + (int)SByte.MaxValue + 1 + 1 + 1 + 1 + 1 + 1 + 'A' + 1 + 3 + 3, v);
1747 m = t.GetMethod ("invoke_pass_ref");
1748 v = this_obj.InvokeMethod (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") });
1749 AssertValue ("ABC", v);
1752 m = t.GetMethod ("invoke_pass_ref");
1753 v = this_obj.InvokeMethod (e.Thread, m, new Value [] { vm.CreateValue (null) });
1754 AssertValue (null, v);
1757 m = t.GetMethod ("invoke_static_pass_ref");
1758 v = t.InvokeMethod (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") });
1759 AssertValue ("ABC", v);
1761 // static invoked using ObjectMirror.InvokeMethod
1762 m = t.GetMethod ("invoke_static_pass_ref");
1763 v = this_obj.InvokeMethod (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") });
1764 AssertValue ("ABC", v);
1766 // method which throws an exception
1768 m = t.GetMethod ("invoke_throws");
1769 v = this_obj.InvokeMethod (e.Thread, m, null);
1771 } catch (InvocationException ex) {
1772 Assert.AreEqual ("Exception", ex.Exception.Type.Name);
1776 m = t.GetMethod (".ctor");
1777 v = t.InvokeMethod (e.Thread, m, null);
1778 Assert.IsInstanceOfType (typeof (ObjectMirror), v);
1779 Assert.AreEqual ("Tests", (v as ObjectMirror).Type.Name);
1781 // Argument checking
1784 AssertThrows<ArgumentNullException> (delegate {
1785 m = t.GetMethod ("invoke_pass_ref");
1786 v = this_obj.InvokeMethod (null, m, new Value [] { vm.CreateValue (null) });
1790 AssertThrows<ArgumentNullException> (delegate {
1791 v = this_obj.InvokeMethod (e.Thread, null, new Value [] { vm.CreateValue (null) });
1794 // invalid number of arguments
1795 m = t.GetMethod ("invoke_pass_ref");
1796 AssertThrows<ArgumentException> (delegate {
1797 v = this_obj.InvokeMethod (e.Thread, m, null);
1800 // invalid type of argument (ref != primitive)
1801 m = t.GetMethod ("invoke_pass_ref");
1802 AssertThrows<ArgumentException> (delegate {
1803 v = this_obj.InvokeMethod (e.Thread, m, new Value [] { vm.CreateValue (1) });
1806 // invalid type of argument (primitive != primitive)
1807 m = t.GetMethod ("invoke_pass_primitive_2");
1808 AssertThrows<ArgumentException> (delegate {
1809 v = this_obj.InvokeMethod (e.Thread, m, new Value [] { vm.CreateValue (1) });
1812 // invoking a non-static method as static
1813 m = t.GetMethod ("invoke_pass_ref");
1814 AssertThrows<ArgumentException> (delegate {
1815 v = t.InvokeMethod (e.Thread, m, new Value [] { vm.RootDomain.CreateString ("ABC") });
1818 // invoking a method defined in another class
1819 m = t2.GetMethod ("invoke");
1820 AssertThrows<ArgumentException> (delegate {
1821 v = this_obj.InvokeMethod (e.Thread, m, null);
1826 public void InvokeVType () {
1827 Event e = run_until ("invoke1");
1829 StackFrame frame = e.Thread.GetFrames () [0];
1831 var s = frame.GetArgument (1) as StructMirror;
1833 TypeMirror t = s.Type;
1838 // Pass struct as this, receive int
1839 m = t.GetMethod ("invoke_return_int");
1840 v = s.InvokeMethod (e.Thread, m, null);
1841 AssertValue (42, v);
1843 // Pass struct as this, receive intptr
1844 m = t.GetMethod ("invoke_return_intptr");
1845 v = s.InvokeMethod (e.Thread, m, null);
1846 AssertValue (43, v);
1849 m = t.GetMethod ("invoke_static");
1850 v = t.InvokeMethod (e.Thread, m, null);
1853 // Pass generic struct as this
1854 s = frame.GetArgument (2) as StructMirror;
1856 m = t.GetMethod ("invoke_return_int");
1857 v = s.InvokeMethod (e.Thread, m, null);
1858 AssertValue (42, v);
1862 public void BreakpointDuringInvoke () {
1863 Event e = run_until ("invoke1");
1865 MethodMirror m = entry_point.DeclaringType.GetMethod ("invoke2");
1866 Assert.IsNotNull (m);
1867 vm.SetBreakpoint (m, 0);
1869 StackFrame frame = e.Thread.GetFrames () [0];
1870 var o = frame.GetThis () as ObjectMirror;
1872 bool failed = false;
1874 bool finished = false;
1875 object wait = new object ();
1877 // Have to invoke in a separate thread as the invoke is suspended until we
1878 // resume after the breakpoint
1879 Thread t = new Thread (delegate () {
1881 o.InvokeMethod (e.Thread, m, null);
1887 Monitor.Pulse (wait);
1893 StackFrame invoke_frame = null;
1896 e = vm.GetNextEvent ();
1897 Assert.IsInstanceOfType (typeof (BreakpointEvent), e);
1898 // Check stack trace support and invokes
1899 var frames = e.Thread.GetFrames ();
1900 invoke_frame = frames [0];
1901 Assert.AreEqual ("invoke2", frames [0].Method.Name);
1902 Assert.IsTrue (frames [0].IsDebuggerInvoke);
1903 Assert.AreEqual ("invoke1", frames [1].Method.Name);
1908 // Check that the invoke frames are no longer valid
1909 AssertThrows<InvalidStackFrameException> (delegate {
1910 invoke_frame.GetThis ();
1915 Monitor.Wait (wait);
1918 // Check InvokeOptions.DisableBreakpoints flag
1919 o.InvokeMethod (e.Thread, m, null, InvokeOptions.DisableBreakpoints);
1923 public void DisabledExceptionDuringInvoke () {
1924 Event e = run_until ("invoke_ex");
1926 MethodMirror m = entry_point.DeclaringType.GetMethod ("invoke_ex_inner");
1928 StackFrame frame = e.Thread.GetFrames () [0];
1929 var o = frame.GetThis () as ObjectMirror;
1931 var req = vm.CreateExceptionRequest (null);
1934 // Check InvokeOptions.DisableBreakpoints flag
1935 o.InvokeMethod (e.Thread, m, null, InvokeOptions.DisableBreakpoints);
1941 public void InvokeSingleThreaded () {
1944 Start (new string [] { "dtest-app.exe", "invoke-single-threaded" });
1946 Event e = run_until ("invoke_single_threaded_2");
1948 StackFrame f = e.Thread.GetFrames ()[0];
1950 var obj = f.GetThis () as ObjectMirror;
1952 // Check that the counter value incremented by the other thread does not increase
1953 // during the invoke.
1954 object counter1 = (obj.GetValue (obj.Type.GetField ("counter")) as PrimitiveValue).Value;
1956 var m = obj.Type.GetMethod ("invoke_return_void");
1957 obj.InvokeMethod (e.Thread, m, null, InvokeOptions.SingleThreaded);
1959 object counter2 = (obj.GetValue (obj.Type.GetField ("counter")) as PrimitiveValue).Value;
1961 Assert.AreEqual ((int)counter1, (int)counter2);
1963 // Test multiple invokes done in succession
1964 m = obj.Type.GetMethod ("invoke_return_void");
1965 obj.InvokeMethod (e.Thread, m, null, InvokeOptions.SingleThreaded);
1967 // Test events during single-threaded invokes
1968 vm.EnableEvents (EventType.TypeLoad);
1969 m = obj.Type.GetMethod ("invoke_type_load");
1970 obj.BeginInvokeMethod (e.Thread, m, null, InvokeOptions.SingleThreaded, delegate {
1974 e = vm.GetNextEvent ();
1975 Assert.AreEqual (EventType.TypeLoad, e.EventType);
1979 public void GetThreads () {
1984 public void Threads () {
1985 Event e = run_until ("threads");
1987 Assert.AreEqual (ThreadState.Running, e.Thread.ThreadState);
1989 Assert.IsTrue (e.Thread.ThreadId > 0);
1991 vm.EnableEvents (EventType.ThreadStart, EventType.ThreadDeath);
1995 e = vm.GetNextEvent ();
1996 Assert.IsInstanceOfType (typeof (ThreadStartEvent), e);
1997 var state = e.Thread.ThreadState;
1998 Assert.IsTrue (state == ThreadState.Running || state == ThreadState.Unstarted);
2002 e = vm.GetNextEvent ();
2003 Assert.IsInstanceOfType (typeof (ThreadDeathEvent), e);
2004 Assert.AreEqual (ThreadState.Stopped, e.Thread.ThreadState);
2009 public void Frame_SetValue () {
2010 Event e = run_until ("locals2");
2012 StackFrame frame = e.Thread.GetFrames () [0];
2015 var l = frame.Method.GetLocal ("i");
2016 frame.SetValue (l, vm.CreateValue ((long)55));
2017 AssertValue (55, frame.GetValue (l));
2020 l = frame.Method.GetLocal ("s");
2021 frame.SetValue (l, vm.RootDomain.CreateString ("DEF"));
2022 AssertValue ("DEF", frame.GetValue (l));
2024 // argument as local
2025 l = frame.Method.GetLocal ("arg");
2026 frame.SetValue (l, vm.CreateValue (6));
2027 AssertValue (6, frame.GetValue (l));
2030 var p = frame.Method.GetParameters ()[1];
2031 frame.SetValue (p, vm.CreateValue (7));
2032 AssertValue (7, frame.GetValue (p));
2035 p = frame.Method.GetParameters ()[2];
2036 frame.SetValue (p, vm.RootDomain.CreateString ("DEF"));
2037 AssertValue ("DEF", frame.GetValue (p));
2039 // argument checking
2042 AssertThrows<ArgumentNullException> (delegate () {
2043 frame.SetValue ((LocalVariable)null, vm.CreateValue (55));
2047 AssertThrows<ArgumentNullException> (delegate () {
2048 l = frame.Method.GetLocal ("i");
2049 frame.SetValue (l, null);
2052 // value of invalid type
2053 AssertThrows<ArgumentException> (delegate () {
2054 l = frame.Method.GetLocal ("i");
2055 frame.SetValue (l, vm.CreateValue (55));
2060 public void InvokeRegress () {
2061 Event e = run_until ("invoke1");
2063 StackFrame frame = e.Thread.GetFrames () [0];
2065 TypeMirror t = frame.Method.DeclaringType;
2066 ObjectMirror this_obj = (ObjectMirror)frame.GetThis ();
2068 TypeMirror t2 = frame.Method.GetParameters ()[0].ParameterType;
2074 m = t.GetMethod ("invoke_return_void");
2075 v = this_obj.InvokeMethod (e.Thread, m, null);
2078 // Check that the stack frames remain valid during the invoke
2079 Assert.AreEqual ("Tests", (frame.GetThis () as ObjectMirror).Type.Name);
2081 // do another invoke
2082 m = t.GetMethod ("invoke_return_void");
2083 v = this_obj.InvokeMethod (e.Thread, m, null);
2086 // Try a single step after the invoke
2087 var req = vm.CreateStepRequest (e.Thread);
2088 req.Depth = StepDepth.Into;
2089 req.Size = StepSize.Line;
2094 // Step into invoke2
2096 e = vm.GetNextEvent ();
2097 Assert.IsTrue (e is StepEvent);
2098 Assert.AreEqual ("invoke2", (e as StepEvent).Method.Name);
2102 frame = e.Thread.GetFrames () [0];
2106 public void Exceptions () {
2107 Event e = run_until ("exceptions");
2108 var req = vm.CreateExceptionRequest (null);
2113 e = vm.GetNextEvent ();
2114 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2115 Assert.AreEqual ("OverflowException", (e as ExceptionEvent).Exception.Type.Name);
2117 var frames = e.Thread.GetFrames ();
2118 Assert.AreEqual ("exceptions", frames [0].Method.Name);
2121 // exception type filter
2123 req = vm.CreateExceptionRequest (vm.RootDomain.Corlib.GetType ("System.ArgumentException"));
2126 // Skip the throwing of the second OverflowException
2129 e = vm.GetNextEvent ();
2130 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2131 Assert.AreEqual ("ArgumentException", (e as ExceptionEvent).Exception.Type.Name);
2134 // exception type filter for subclasses
2135 req = vm.CreateExceptionRequest (vm.RootDomain.Corlib.GetType ("System.Exception"));
2140 e = vm.GetNextEvent ();
2141 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2142 Assert.AreEqual ("OverflowException", (e as ExceptionEvent).Exception.Type.Name);
2145 // Implicit exceptions
2146 req = vm.CreateExceptionRequest (null);
2151 e = vm.GetNextEvent ();
2152 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2153 Assert.AreEqual ("NullReferenceException", (e as ExceptionEvent).Exception.Type.Name);
2156 // Single stepping after an exception
2157 req = vm.CreateExceptionRequest (null);
2162 e = vm.GetNextEvent ();
2163 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2164 Assert.AreEqual ("Exception", (e as ExceptionEvent).Exception.Type.Name);
2165 frames = e.Thread.GetFrames ();
2166 Assert.AreEqual ("exceptions2", frames [0].Method.Name);
2169 var sreq = vm.CreateStepRequest (e.Thread);
2170 sreq.Depth = StepDepth.Over;
2171 sreq.Size = StepSize.Line;
2175 e = vm.GetNextEvent ();
2176 Assert.IsInstanceOfType (typeof (StepEvent), e);
2177 frames = e.Thread.GetFrames ();
2178 Assert.AreEqual ("exceptions", frames [0].Method.Name);
2181 // Argument checking
2182 AssertThrows<ArgumentException> (delegate {
2183 vm.CreateExceptionRequest (e.Thread.Type);
2188 public void EventSets () {
2190 // Create two filter which both match the same exception
2192 Event e = run_until ("exceptions");
2194 var req = vm.CreateExceptionRequest (null);
2197 var req2 = vm.CreateExceptionRequest (vm.RootDomain.Corlib.GetType ("System.OverflowException"));
2202 var es = vm.GetNextEventSet ();
2203 Assert.AreEqual (2, es.Events.Length);
2206 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2207 Assert.AreEqual ("OverflowException", (e as ExceptionEvent).Exception.Type.Name);
2210 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2211 Assert.AreEqual ("OverflowException", (e as ExceptionEvent).Exception.Type.Name);
2218 // Test single threaded invokes during processing of nullref exceptions.
2219 // These won't work if the exception handling is done from the sigsegv signal
2220 // handler, since the sigsegv signal is disabled until control returns from the
2224 [Category ("only3")]
2225 public void NullRefExceptionAndSingleThreadedInvoke () {
2226 Event e = run_until ("exceptions");
2227 var req = vm.CreateExceptionRequest (vm.RootDomain.Corlib.GetType ("System.NullReferenceException"));
2232 e = vm.GetNextEvent ();
2233 Assert.IsInstanceOfType (typeof (ExceptionEvent), e);
2234 Assert.AreEqual ("NullReferenceException", (e as ExceptionEvent).Exception.Type.Name);
2236 var ex = (e as ExceptionEvent).Exception;
2237 var tostring_method = vm.RootDomain.Corlib.GetType ("System.Object").GetMethod ("ToString");
2238 ex.InvokeMethod (e.Thread, tostring_method, null, InvokeOptions.SingleThreaded);
2242 public void Domains () {
2245 Start (new string [] { "dtest-app.exe", "domain-test" });
2247 vm.EnableEvents (EventType.AppDomainCreate, EventType.AppDomainUnload, EventType.AssemblyUnload);
2249 Event e = run_until ("domains");
2253 e = vm.GetNextEvent ();
2254 Assert.IsInstanceOfType (typeof (AppDomainCreateEvent), e);
2256 var domain = (e as AppDomainCreateEvent).Domain;
2258 // Run until the callback in the domain
2259 MethodMirror m = entry_point.DeclaringType.GetMethod ("invoke_in_domain");
2260 Assert.IsNotNull (m);
2261 vm.SetBreakpoint (m, 0);
2265 e = vm.GetNextEvent ();
2266 if (e is BreakpointEvent)
2270 Assert.AreEqual ("invoke_in_domain", (e as BreakpointEvent).Method.Name);
2272 // d_method is from another domain
2273 MethodMirror d_method = (e as BreakpointEvent).Method;
2274 Assert.IsTrue (m != d_method);
2276 var frames = e.Thread.GetFrames ();
2277 Assert.AreEqual ("invoke_in_domain", frames [0].Method.Name);
2278 Assert.AreEqual ("invoke", frames [1].Method.Name);
2279 Assert.AreEqual ("domains", frames [2].Method.Name);
2281 // Test breakpoints on already JITted methods in other domains
2282 m = entry_point.DeclaringType.GetMethod ("invoke_in_domain_2");
2283 Assert.IsNotNull (m);
2284 vm.SetBreakpoint (m, 0);
2288 e = vm.GetNextEvent ();
2289 if (e is BreakpointEvent)
2293 Assert.AreEqual ("invoke_in_domain_2", (e as BreakpointEvent).Method.Name);
2295 // This is empty when receiving the AppDomainCreateEvent
2296 Assert.AreEqual ("domain", domain.FriendlyName);
2298 // Run until the unload
2301 e = vm.GetNextEvent ();
2302 if (e is AssemblyUnloadEvent) {
2308 Assert.IsInstanceOfType (typeof (AppDomainUnloadEvent), e);
2309 Assert.AreEqual (domain, (e as AppDomainUnloadEvent).Domain);
2311 // Run past the unload
2312 e = run_until ("domains_2");
2314 // Test access to unloaded types
2315 // FIXME: Add an exception type for this
2316 AssertThrows<Exception> (delegate {
2317 d_method.DeclaringType.GetValue (d_method.DeclaringType.GetField ("static_i"));
2322 public void DynamicMethods () {
2323 Event e = run_until ("dyn_call");
2325 var m = e.Thread.GetFrames ()[1].Method;
2326 Assert.AreEqual ("dyn_method", m.Name);
2328 // Test access to IL
2329 var body = m.GetMethodBody ();
2331 ILInstruction ins = body.Instructions [0];
2332 Assert.AreEqual (OpCodes.Ldstr, ins.OpCode);
2333 Assert.AreEqual ("FOO", ins.Operand);
2337 public void RefEmit () {
2340 Start (new string [] { "dtest-app.exe", "ref-emit-test" });
2342 Event e = run_until ("ref_emit_call");
2344 var m = e.Thread.GetFrames ()[1].Method;
2345 Assert.AreEqual ("ref_emit_method", m.Name);
2347 // Test access to IL
2348 var body = m.GetMethodBody ();
2352 ins = body.Instructions [0];
2353 Assert.AreEqual (OpCodes.Ldstr, ins.OpCode);
2354 Assert.AreEqual ("FOO", ins.Operand);
2356 ins = body.Instructions [1];
2357 Assert.AreEqual (OpCodes.Call, ins.OpCode);
2358 Assert.IsInstanceOfType (typeof (MethodMirror), ins.Operand);
2359 Assert.AreEqual ("ref_emit_call", (ins.Operand as MethodMirror).Name);
2363 public void IsAttached () {
2364 var f = entry_point.DeclaringType.GetField ("is_attached");
2366 Event e = run_until ("Main");
2368 AssertValue (true, entry_point.DeclaringType.GetValue (f));
2372 public void StackTraceInNative () {
2373 // Check that stack traces can be produced for threads in native code
2376 Start (new string [] { "dtest-app.exe", "frames-in-native" });
2378 var e = run_until ("frames_in_native");
2380 // FIXME: This is racy
2387 StackFrame[] frames = e.Thread.GetFrames ();
2389 int frame_index = -1;
2390 for (int i = 0; i < frames.Length; ++i) {
2391 if (frames [i].Method.Name == "Sleep") {
2397 Assert.IsTrue (frame_index != -1);
2398 Assert.AreEqual ("Sleep", frames [frame_index].Method.Name);
2399 Assert.AreEqual ("frames_in_native", frames [frame_index + 1].Method.Name);
2400 Assert.AreEqual ("Main", frames [frame_index + 2].Method.Name);
2402 // Check that invokes are disabled for such threads
2403 TypeMirror t = frames [frame_index + 1].Method.DeclaringType;
2406 var m = t.GetMethod ("invoke_static_return_void");
2407 AssertThrows<InvalidOperationException> (delegate {
2408 t.InvokeMethod (e.Thread, m, null);
2413 public void VirtualMachine_CreateEnumMirror () {
2414 var e = run_until ("o1");
2415 var frame = e.Thread.GetFrames () [0];
2417 object val = frame.GetThis ();
2418 Assert.IsTrue (val is ObjectMirror);
2419 Assert.AreEqual ("Tests", (val as ObjectMirror).Type.Name);
2420 ObjectMirror o = (val as ObjectMirror);
2422 FieldInfoMirror field = o.Type.GetField ("field_enum");
2423 Value f = o.GetValue (field);
2424 TypeMirror enumType = (f as EnumMirror).Type;
2426 o.SetValue (field, vm.CreateEnumMirror (enumType, vm.CreateValue (1)));
2427 f = o.GetValue (field);
2428 Assert.AreEqual (1, (f as EnumMirror).Value);
2430 // Argument checking
2431 AssertThrows<ArgumentNullException> (delegate () {
2432 vm.CreateEnumMirror (enumType, null);
2435 AssertThrows<ArgumentNullException> (delegate () {
2436 vm.CreateEnumMirror (null, vm.CreateValue (1));
2440 AssertThrows<ArgumentException> (delegate () {
2441 vm.CreateEnumMirror (enumType, vm.CreateValue (null));
2444 // value of a wrong type
2445 AssertThrows<ArgumentException> (delegate () {
2446 vm.CreateEnumMirror (enumType, vm.CreateValue ((long)1));
2451 public void VirtualMachine_EnableEvents_Breakpoint () {
2452 AssertThrows<ArgumentException> (delegate () {
2453 vm.EnableEvents (EventType.Breakpoint);