4 * Application program used by the debugger tests.
7 using System.Runtime.CompilerServices;
8 using System.Reflection;
9 using System.Reflection.Emit;
10 using System.Diagnostics;
11 using System.Threading;
12 using System.Threading.Tasks;
13 using System.Collections.Generic;
15 using System.Net.Sockets;
16 using MonoTests.Helpers;
18 public class TestsBase
20 #pragma warning disable 0414
21 #pragma warning disable 0169
22 public int base_field_i;
23 public string base_field_s;
24 static int base_static_i = 57;
25 static string base_static_s = "C";
26 #pragma warning restore 0414
27 #pragma warning restore 0169
29 public virtual string virtual_method () {
39 public sealed class Tests3 {
40 public static void M1 () {
54 public static class Tests4 {
59 public class AAttribute : Attribute {
63 public class BAttribute : AAttribute {
67 [DebuggerDisplay ("Tests", Name="FOO", Target=typeof (int))]
68 [DebuggerTypeProxy (typeof (Tests))]
69 [BAttribute (afield = 1, bfield = 2)]
71 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
73 public static int static_field_j;
75 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
76 public int AProperty {
82 public void invoke () {
86 public struct AStruct : ITest2 {
101 public AStruct (int arg) {
109 [MethodImplAttribute (MethodImplOptions.NoInlining)]
110 public int foo (int val) {
114 [MethodImplAttribute (MethodImplOptions.NoInlining)]
115 public static int static_foo (int val) {
119 [MethodImplAttribute (MethodImplOptions.NoInlining)]
120 public int invoke_return_int () {
124 [MethodImplAttribute (MethodImplOptions.NoInlining)]
125 public static int invoke_static () {
129 [MethodImplAttribute (MethodImplOptions.NoInlining)]
130 public IntPtr invoke_return_intptr () {
134 [MethodImplAttribute (MethodImplOptions.NoInlining)]
135 public void invoke_mutate () {
139 public int invoke_iface () {
143 public override string ToString () {
144 return i.ToString ();
148 public class GClass<T> {
150 public static T static_field;
152 [MethodImplAttribute (MethodImplOptions.NoInlining)]
156 [MethodImplAttribute (MethodImplOptions.NoInlining)]
157 public void bp<T2> () {
161 public struct GStruct<T> {
166 [MethodImplAttribute (MethodImplOptions.NoInlining)]
167 public int invoke_return_int () {
172 public struct NestedStruct {
173 NestedInner nested1, nested2;
176 public struct NestedInner {
179 public interface IRecStruct {
183 struct RecStruct : IRecStruct {
186 public void foo (object o) {
203 class TestIfaces : ITest
211 TestIfaces<int> Baz () {
216 class TestIfaces<T> : ITest<T>
218 void ITest<T>.Foo () {
221 void ITest<T>.Bar () {
225 public interface ITest2
230 public class Tests : TestsBase, ITest2
232 #pragma warning disable 0414
236 bool field_bool1, field_bool2;
249 static int static_i = 55;
250 static string static_s = "A";
251 public const int literal_i = 56;
252 public const string literal_s = "B";
254 public AStruct field_struct;
255 public object field_boxed_struct;
256 public GStruct<int> generic_field_struct;
257 public KeyValuePair<int, object> boxed_struct_field;
259 public static int tls_i;
260 public static bool is_attached = Debugger.IsAttached;
261 public NestedStruct nested_struct;
263 #pragma warning restore 0414
265 public class NestedClass {
268 public int IntProperty {
277 public int ReadOnlyProperty {
283 public int this [int index] {
289 public static void wait_one ()
291 ManualResetEvent evt = new ManualResetEvent (false);
295 public static int Main (String[] args) {
298 if (args.Length > 0 && args [0] == "suspend-test")
299 /* This contains an infinite loop, so execute it conditionally */
301 if (args.Length >0 && args [0] == "unhandled-exception") {
302 unhandled_exception ();
305 if (args.Length >0 && args [0] == "unhandled-exception-endinvoke") {
306 unhandled_exception_endinvoke ();
309 if (args.Length >0 && args [0] == "unhandled-exception-user") {
310 unhandled_exception_user ();
313 if (args.Length >0 && args [0] == "wait-one") {
317 if (args.Length >0 && args [0] == "threadpool-io") {
321 if (args.Length > 0 && args [0] == "attach") {
322 new Tests ().attach ();
347 if (args.Length > 0 && args [0] == "domain-test")
348 /* This takes a lot of time, so execute it conditionally */
350 if (args.Length > 0 && args [0] == "ref-emit-test")
352 if (args.Length > 0 && args [0] == "frames-in-native")
354 if (args.Length > 0 && args [0] == "invoke-single-threaded")
355 new Tests ().invoke_single_threaded ();
356 if (args.Length > 0 && args [0] == "invoke-abort")
357 new Tests ().invoke_abort ();
358 new Tests ().evaluate_method ();
362 public static void local_reflect () {
363 //Breakpoint line below, and reflect someField via ObjectMirror;
364 LocalReflectClass.RunMe ();
367 public static void breakpoints () {
368 /* Call these early so it is JITted by the time a breakpoint is placed on it */
380 bp6<string> (new GClass <int> ());
385 [MethodImplAttribute (MethodImplOptions.NoInlining)]
386 public static void bp1 () {
389 [MethodImplAttribute (MethodImplOptions.NoInlining)]
390 public static void bp2 () {
393 [MethodImplAttribute (MethodImplOptions.NoInlining)]
394 public static void bp3 () {
397 [MethodImplAttribute (MethodImplOptions.NoInlining)]
398 public static void bp4 () {
401 [MethodImplAttribute (MethodImplOptions.NoInlining)]
402 public static void bp5 () {
405 [MethodImplAttribute (MethodImplOptions.NoInlining)]
406 public static void bp6<T> (GClass<int> gc) {
410 [MethodImplAttribute (MethodImplOptions.NoInlining)]
411 public static void bp7<T> () {
414 [MethodImplAttribute (MethodImplOptions.NoInlining)]
415 public static void single_stepping () {
422 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
429 ss_regress_654694 ();
435 ss_recursive_chaotic ();
441 [MethodImplAttribute (MethodImplOptions.NoInlining)]
442 public static void ss1 () {
445 [MethodImplAttribute (MethodImplOptions.NoInlining)]
446 public static void ss2 () {
449 [MethodImplAttribute (MethodImplOptions.NoInlining)]
450 public static int ss3 () {
453 for (int i = 0; i < 10; ++i)
459 [MethodImplAttribute (MethodImplOptions.NoInlining)]
460 public static void ss3_2 () {
464 [MethodImplAttribute (MethodImplOptions.NoInlining)]
465 public static void ss3_2_2 () {
468 [MethodImplAttribute (MethodImplOptions.NoInlining)]
469 public static int ss4 () {
475 [MethodImplAttribute (MethodImplOptions.NoInlining)]
476 public static void ss5 (int[] arr, Func<int, bool> selector) {
477 // Call into linq which calls back into this assembly
478 arr.Count (selector);
481 [MethodImplAttribute (MethodImplOptions.NoInlining)]
482 public static void ss6 (bool b) {
485 throw new Exception ();
489 [MethodImplAttribute (MethodImplOptions.NoInlining)]
490 public static void ss6_2 () {
493 [MethodImplAttribute(MethodImplOptions.NoInlining)]
494 public static void ss7 ()
496 ss7_2();//Used to test stepout inside ss7_2, which may not go to catch
497 ss7_2();//Used to test stepout inside ss7_2_1, which must go to catch
498 ss7_2();//Used to test stepover inside ss7_2, which must go to catch
499 ss7_2();//Used to test stepover inside ss7_2_1, which must go to catch
500 ss7_3();//Used to test stepin inside ss7_3, which must go to catch
501 ss7_2();//Used to test stepin inside ss7_2_1, which must go to catch
504 [MethodImplAttribute(MethodImplOptions.NoInlining)]
505 public static void ss7_2_1 ()
507 throw new Exception ();
510 [MethodImplAttribute(MethodImplOptions.NoInlining)]
511 public static void ss7_2_2 ()
516 [MethodImplAttribute(MethodImplOptions.NoInlining)]
517 public static void ss7_2 ()
527 [MethodImplAttribute(MethodImplOptions.NoInlining)]
528 public static void ss7_3 ()
531 throw new Exception ();
538 [MethodImplAttribute (MethodImplOptions.NoInlining)]
539 public static void ss_nested () {
540 ss_nested_1 (ss_nested_2 ());
541 ss_nested_1 (ss_nested_2 ());
545 [MethodImplAttribute (MethodImplOptions.NoInlining)]
546 public static void ss_nested_1 (int i) {
549 [MethodImplAttribute (MethodImplOptions.NoInlining)]
550 public static int ss_nested_2 () {
554 [MethodImplAttribute (MethodImplOptions.NoInlining)]
555 public static void ss_nested_3 () {
558 [MethodImplAttribute (MethodImplOptions.NoInlining)]
559 public static void ss_step_through () {
561 StepThroughClass.step_through_2 ();
565 [DebuggerStepThrough]
566 [MethodImplAttribute (MethodImplOptions.NoInlining)]
567 public static void step_through_1 () {
570 [DebuggerStepThrough]
571 class StepThroughClass {
572 [MethodImplAttribute (MethodImplOptions.NoInlining)]
573 public static void step_through_2 () {
577 [DebuggerStepThrough]
578 [MethodImplAttribute (MethodImplOptions.NoInlining)]
579 public static void step_through_3 () {
582 [MethodImplAttribute (MethodImplOptions.NoInlining)]
583 public static void ss_non_user_code () {
585 StepNonUserCodeClass.non_user_code_2 ();
589 [DebuggerNonUserCode]
590 [MethodImplAttribute (MethodImplOptions.NoInlining)]
591 public static void non_user_code_1 () {
594 [DebuggerNonUserCode]
595 class StepNonUserCodeClass {
596 [MethodImplAttribute (MethodImplOptions.NoInlining)]
597 public static void non_user_code_2 () {
601 [DebuggerNonUserCode]
602 [MethodImplAttribute (MethodImplOptions.NoInlining)]
603 public static void non_user_code_3 () {
606 [MethodImplAttribute (MethodImplOptions.NoInlining)]
607 public static void ss_recursive (int n) {
610 ss_recursive (n + 1);
613 // Breakpoint will be placed here
614 [MethodImplAttribute (MethodImplOptions.NoInlining)]
615 public static void ss_recursive2_trap ()
619 public static void ss_recursive2_at (string s)
621 // Console.WriteLine (s);
624 // This method is used both for a step over and step out test.
625 [MethodImplAttribute (MethodImplOptions.NoInlining)]
626 public static void ss_recursive2 (int x)
628 ss_recursive2_at ( "ss_recursive2 in " + x);
631 ss_recursive2_at ("ss_recursive2 descend " + x);
632 ss_recursive2_trap ();
633 ss_recursive2 (next);
635 ss_recursive2_at ("ss_recursive2 out " + x);
638 // Breakpoint will be placed here
639 [MethodImplAttribute (MethodImplOptions.NoInlining)]
640 public static void ss_recursive_chaotic_trap ()
644 [MethodImplAttribute (MethodImplOptions.NoInlining)]
645 public static void ss_recursive_chaotic_at (bool exiting, string at, int n)
647 // string indent = "";
648 // for (int count = 5 - n; count > 0; count--)
650 // Console.WriteLine (indent + (exiting ? "<--" : "-->") + " " + at + " " + n);
653 [MethodImplAttribute (MethodImplOptions.NoInlining)]
654 public static void ss_recursive_chaotic_fizz (int n)
656 ss_recursive_chaotic_at (false, "fizz", n);
659 ss_recursive_chaotic_buzz (next);
660 ss_recursive_chaotic_fizzbuzz (next);
662 ss_recursive_chaotic_trap ();
664 ss_recursive_chaotic_at (true, "fizz", n);
667 [MethodImplAttribute (MethodImplOptions.NoInlining)]
668 public static void ss_recursive_chaotic_buzz (int n)
670 ss_recursive_chaotic_at (false, "buzz", n);
673 ss_recursive_chaotic_fizz (next);
674 ss_recursive_chaotic_fizzbuzz (next);
676 ss_recursive_chaotic_at (true, "buzz", n);
679 [MethodImplAttribute (MethodImplOptions.NoInlining)]
680 public static void ss_recursive_chaotic_fizzbuzz (int n)
682 ss_recursive_chaotic_at (false, "fizzbuzz", n);
685 ss_recursive_chaotic_fizz (next);
686 ss_recursive_chaotic_buzz (next);
687 ss_recursive_chaotic_fizzbuzz (next);
689 ss_recursive_chaotic_at (true, "fizzbuzz", n);
692 // Call a complex tree of recursive calls that has tripped up "step out" in the past.
693 [MethodImplAttribute (MethodImplOptions.NoInlining)]
694 public static void ss_recursive_chaotic ()
696 ss_recursive_chaotic_fizz (5);
699 [MethodImplAttribute (MethodImplOptions.NoInlining)]
700 public static void ss_fp_clobber () {
701 double v = ss_fp_clobber_1 (5.0);
705 [MethodImplAttribute (MethodImplOptions.NoInlining)]
706 public static double ss_fp_clobber_1 (double d) {
710 [MethodImplAttribute (MethodImplOptions.NoInlining)]
711 public static void ss_fp_clobber_2 (double d) {
714 [MethodImplAttribute (MethodImplOptions.NoInlining)]
715 public static void ss_no_frames () {
716 Action a = ss_no_frames_2;
717 var ar = a.BeginInvoke (null, null);
718 ar.AsyncWaitHandle.WaitOne ();
719 // Avoid waiting every time this runs
725 [MethodImplAttribute (MethodImplOptions.NoInlining)]
726 public static void ss_await ()
728 ss_await_1 ().Wait ();//in
729 ss_await_1 ().Wait ();//over
730 ss_await_1 ().Wait ();//out before
731 ss_await_1 ().Wait ();//out after
732 ss_await_1_exc (true, true).Wait ();//in
733 ss_await_1_exc (true, true).Wait ();//over
734 ss_await_1_exc (true, true).Wait ();//out
736 ss_await_1_exc (true, false).Wait ();//in
739 ss_await_1_exc (true, false).Wait ();//over
742 ss_await_1_exc (true, false).Wait ();//out
746 [MethodImplAttribute (MethodImplOptions.NoInlining)]
747 public static async Task<int> ss_await_1 () {
749 await Task.Delay (10);
753 [MethodImplAttribute (MethodImplOptions.NoInlining)]
754 public static async Task<int> ss_await_1_exc (bool exc, bool handled)
757 await Task.Delay (10);
761 throw new Exception ();
765 throw new Exception ();
771 [MethodImplAttribute (MethodImplOptions.NoInlining)]
772 public static void ss_no_frames_2 () {
775 [MethodImplAttribute (MethodImplOptions.NoInlining)]
776 public static void ss_no_frames_3 () {
779 [MethodImplAttribute (MethodImplOptions.NoInlining)]
780 public static bool is_even (int i) {
786 Console.WriteLine ("HIT!");
792 [MethodImplAttribute (MethodImplOptions.NoInlining)]
793 public static void arguments () {
794 arg1 (SByte.MaxValue - 5, Byte.MaxValue - 5, true, Int16.MaxValue - 5, UInt16.MaxValue - 5, 'F', Int32.MaxValue - 5, UInt32.MaxValue - 5, Int64.MaxValue - 5, UInt64.MaxValue - 5, 1.2345f, 6.78910, new IntPtr (Int32.MaxValue - 5), new UIntPtr (UInt32.MaxValue - 5));
796 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object (), '\0'.ToString () + "A");
797 Tests t = new Tests () { field_i = 42, field_s = "S" };
801 [MethodImplAttribute (MethodImplOptions.NoInlining)]
802 public static int arg1 (sbyte sb, byte b, bool bl, short s, ushort us, char c, int i, uint ui, long l, ulong ul, float f, double d, IntPtr ip, UIntPtr uip) {
803 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
806 [MethodImplAttribute (MethodImplOptions.NoInlining)]
807 public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2, string s4) {
808 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
811 [MethodImplAttribute (MethodImplOptions.NoInlining)]
812 public object arg3 (string s) {
813 return s + s + s + s + this;
816 [MethodImplAttribute (MethodImplOptions.NoInlining)]
817 public static void objects () {
818 Tests t = new Tests () { field_i = 42, field_bool1 = true, field_bool2 = false, field_char = 'A', field_byte = 129, field_sbyte = -33, field_short = Int16.MaxValue - 5, field_ushort = UInt16.MaxValue - 5, field_long = Int64.MaxValue - 5, field_ulong = UInt64.MaxValue - 5, field_float = 3.14f, field_double = 3.14f, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B, field_class = null, field_intptr = new IntPtr (Int32.MaxValue - 5), field_nullable = null };
819 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
820 o2 (new string [] { "BAR", "BAZ" }, new int[] { 42, 43 }, new int [,] { { 1, 2 }, { 3, 4 }}, (int[,])Array.CreateInstance (typeof (int), new int [] { 2, 2}, new int [] { 1, 3}), new int[] { 0 });
823 [MethodImplAttribute (MethodImplOptions.NoInlining)]
824 public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
825 if (t == null || gc1 == null || gc2 == null)
831 [MethodImplAttribute (MethodImplOptions.NoInlining)]
832 public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
833 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
836 [MethodImplAttribute (MethodImplOptions.NoInlining)]
837 public static void objrefs () {
838 Tests t = new Tests () {};
846 [MethodImplAttribute (MethodImplOptions.NoInlining)]
847 public static void set_child (Tests t) {
848 t.child = new Tests ();
851 [MethodImplAttribute (MethodImplOptions.NoInlining)]
852 public void objrefs1 () {
855 [MethodImplAttribute (MethodImplOptions.NoInlining)]
856 public static void objrefs2 () {
859 public static void vtypes () {
860 Tests t = new Tests () { field_struct = new AStruct () { i = 42, s = "S", k = 43 }, generic_field_struct = new GStruct<int> () { i = 42 }, field_boxed_struct = new AStruct () { i = 42 }, boxed_struct_field = new KeyValuePair<int, object> (1, (long)42 ) };
861 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
862 AStruct[] arr = new AStruct[] {
863 new AStruct () { i = 1, s = "S1" },
864 new AStruct () { i = 2, s = "S2" } };
865 TypedReference typedref = __makeref (s);
866 t.vtypes1 (s, arr, typedref);
872 [MethodImplAttribute (MethodImplOptions.NoInlining)]
873 public object vtypes1 (AStruct s, AStruct[] arr, TypedReference typedref) {
880 [MethodImplAttribute (MethodImplOptions.NoInlining)]
881 public static void vtypes2 (AStruct s) {
885 [MethodImplAttribute (MethodImplOptions.NoInlining)]
886 public static void vtypes3 (AStruct s) {
887 AStruct.static_foo (5);
890 [MethodImplAttribute (MethodImplOptions.NoInlining)]
891 public static void vtypes4_2 (IRecStruct o) {
894 [MethodImplAttribute (MethodImplOptions.NoInlining)]
895 public static void vtypes4 () {
896 IRecStruct s = new RecStruct ();
901 [MethodImplAttribute (MethodImplOptions.NoInlining)]
902 public static void locals () {
904 var astruct = new AStruct () { i = 42 };
906 locals2<string> (null, 5, "ABC", ref s, ref astruct);
912 [MethodImplAttribute (MethodImplOptions.NoInlining)]
913 static void locals11 (double a, ref double b) {
916 [MethodImplAttribute (MethodImplOptions.NoInlining)]
917 public static void locals1 (string[] args) {
921 locals11 (b: ref ri, a: ri);
923 for (int j = 0; j < 10; ++j) {
928 [MethodImplAttribute (MethodImplOptions.NoInlining)]
929 [StateMachine (typeof (int))]
930 public static void locals2<T> (string[] args, int arg, T t, ref string rs, ref AStruct astruct) {
934 for (int j = 0; j < 10; ++j) {
939 astruct = new AStruct ();
942 List<int> alist = new List<int> () { 12 };
946 [MethodImplAttribute (MethodImplOptions.NoInlining)]
947 public static void locals3 () {
967 [MethodImplAttribute (MethodImplOptions.NoInlining)]
968 public static void locals4 () {
971 [MethodImplAttribute (MethodImplOptions.NoInlining)]
972 public static void locals5 () {
975 [MethodImplAttribute (MethodImplOptions.NoInlining)]
976 public static void locals6 () {
979 for (i = 0; i < 10; ++i)
982 for (i = 0; i < 10; ++i)
992 [MethodImplAttribute (MethodImplOptions.NoInlining)]
993 public static void locals6_1 () {
996 [MethodImplAttribute (MethodImplOptions.NoInlining)]
997 public static void locals6_2 (int arg) {
1000 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1001 public static void locals6_3 () {
1002 // Clobber all registers
1003 int sum = 0, i, j, k, l, m;
1004 for (i = 0; i < 100; ++i)
1006 for (j = 0; j < 100; ++j)
1008 for (k = 0; k < 100; ++k)
1010 for (l = 0; l < 100; ++l)
1012 for (m = 0; m < 100; ++m)
1016 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1017 public static void locals6_4 (int arg) {
1020 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1021 public static void locals6_5 () {
1024 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1025 public static void locals6_6 (int arg) {
1028 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1029 public static void locals7<T> (T arg) {
1034 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1035 public static void line_numbers () {
1039 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1040 public static void suspend () {
1048 struct TypedRefTest {
1049 public int MaxValue;
1052 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1053 public static void type_info () {
1054 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
1055 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
1058 AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
1059 TypedRefTest reftest = new TypedRefTest () { MaxValue = 12 };
1060 TypedReference typedref = __makeref (reftest);
1061 ti2 (new string [] { "BAR", "BAZ" }, new int[] { 42, 43 }, new int [,] { { 1, 2 }, { 3, 4 }}, ref val, (int*)IntPtr.Zero, 5, s, new Tests (), new Tests2 (), new GClass <int> (), AnEnum.B, typedref);
1065 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1066 public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
1067 if (t == null || gc1 == null || gc2 == null)
1073 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1074 public static unsafe string ti2 (string[] s2, int[] s3, int[,] s4, ref int ri, int* ptr, int i, AStruct s, Tests t, Tests2 t2, GClass<int> g, AnEnum ae, TypedReference typedref) {
1075 return s2 [0] + s3 [0] + s4 [0, 0];
1078 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1079 public static void assembly_load () {
1083 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1084 public static void assembly_load_2 () {
1085 // This will load System.dll while holding the loader lock
1089 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1090 public static void invoke () {
1091 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }, new GStruct<int> { j = 42 });
1092 new Tests ().invoke_ex ();
1095 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1096 public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
1100 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1101 public void invoke2 () {
1104 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1105 public void invoke_ex () {
1109 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1110 public void invoke_ex_inner () {
1112 throw new Exception ();
1119 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1120 public void invoke_single_threaded () {
1121 // Spawn a thread incrementing a counter
1122 bool finished = false;
1124 new Thread (delegate () {
1131 invoke_single_threaded_2 ();
1136 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1137 public void invoke_single_threaded_2 () {
1140 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1141 public void invoke_abort () {
1144 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1145 public void invoke_abort_2 () {
1146 Thread.Sleep (1000000);
1149 public void invoke_return_void () {
1152 public string invoke_return_ref () {
1156 public object invoke_return_null () {
1160 public int invoke_return_primitive () {
1164 public int? invoke_return_nullable () {
1168 public int? invoke_return_nullable_null () {
1172 public void invoke_type_load () {
1179 public long invoke_pass_primitive (byte ub, sbyte sb, short ss, ushort us, int i, uint ui, long l, ulong ul, char c, bool b, float f, double d) {
1180 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
1183 public int invoke_pass_primitive2 (bool b) {
1187 public string invoke_pass_ref (string s) {
1191 public static string invoke_static_pass_ref (string s) {
1195 public static void invoke_static_return_void () {
1198 public static void invoke_throws () {
1199 throw new Exception ();
1202 public int invoke_iface () {
1206 public void invoke_out (out int foo, out int[] arr) {
1211 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1212 public static void exceptions () {
1214 throw new OverflowException ();
1215 } catch (Exception) {
1218 throw new OverflowException ();
1219 } catch (Exception) {
1222 throw new ArgumentException ();
1223 } catch (Exception) {
1226 throw new OverflowException ();
1227 } catch (Exception) {
1231 throw new OverflowException ();
1232 } catch (Exception) {
1235 throw new Exception ();
1236 } catch (Exception) {
1242 } catch (Exception) {
1247 } catch (Exception) {
1251 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1252 public static void unhandled_exception () {
1253 ThreadPool.QueueUserWorkItem (delegate {
1254 throw new InvalidOperationException ();
1256 Thread.Sleep (10000);
1259 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1260 public static void unhandled_exception_endinvoke_2 () {
1263 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1264 public static void unhandled_exception_endinvoke () {
1265 Action action = new Action (() =>
1267 throw new Exception ("thrown");
1269 action.BeginInvoke ((ar) => {
1271 action.EndInvoke (ar);
1272 } catch (Exception ex) {
1273 //Console.WriteLine (ex);
1276 Thread.Sleep (1000);
1277 unhandled_exception_endinvoke_2 ();
1280 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1281 public static void unhandled_exception_user () {
1282 System.Threading.Tasks.Task.Factory.StartNew (() => {
1285 Thread.Sleep (10000);
1288 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1289 public static void Throw () {
1290 throw new Exception ();
1293 internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
1296 throw new ArgumentNullException ();
1297 if (dlg.Target != null)
1298 throw new ArgumentException ();
1299 if (dlg.Method == null)
1300 throw new ArgumentException ();
1302 var ret_type = dlg.Method.ReturnType;
1303 var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();
1305 var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
1306 var ig = dynamic.GetILGenerator ();
1308 LocalBuilder retval = null;
1309 if (ret_type != typeof (void))
1310 retval = ig.DeclareLocal (ret_type);
1312 var label = ig.BeginExceptionBlock ();
1314 for (int i = 0; i < param_types.Length; i++)
1315 ig.Emit (OpCodes.Ldarg, i);
1316 ig.Emit (OpCodes.Call, dlg.Method);
1319 ig.Emit (OpCodes.Stloc, retval);
1321 ig.Emit (OpCodes.Leave, label);
1323 ig.BeginExceptFilterBlock ();
1325 ig.Emit (OpCodes.Call, filter_method);
1327 ig.BeginCatchBlock (null);
1329 ig.Emit (OpCodes.Pop);
1331 ig.EndExceptionBlock ();
1334 ig.Emit (OpCodes.Ldloc, retval);
1336 ig.Emit (OpCodes.Ret);
1338 return dynamic.CreateDelegate (dlg.GetType ());
1341 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1342 static void exception_filter_method () {
1343 throw new InvalidOperationException ();
1346 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1347 static int exception_filter_filter (Exception exc) {
1351 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1352 public static void exception_filter () {
1353 var method = typeof (Tests).GetMethod (
1354 "exception_filter_method", BindingFlags.NonPublic | BindingFlags.Static);
1355 var filter_method = typeof (Tests).GetMethod (
1356 "exception_filter_filter", BindingFlags.NonPublic | BindingFlags.Static);
1358 var dlg = Delegate.CreateDelegate (typeof (Action), method);
1360 var wrapper = (Action) create_filter_delegate (dlg, filter_method);
1365 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1366 public static bool return_true () {
1370 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1371 public static void exceptions2 () {
1373 throw new Exception ();
1374 Console.WriteLine ();
1377 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1378 public static void threads () {
1379 Thread t = new Thread (delegate () {});
1385 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1386 public static void domains () {
1387 AppDomain domain = AppDomain.CreateDomain ("domain");
1389 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
1390 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
1392 domains_print_across (o);
1394 domains_2 (o, new CrossDomain ());
1404 AppDomain.Unload (domain);
1408 typeof (Tests).GetMethod ("called_from_invoke").Invoke (null, null);
1411 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1412 public static void called_from_invoke () {
1415 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1416 public static void domains_2 (object o, object o2) {
1419 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1420 public static void domains_print_across (object o) {
1423 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1424 public static void domains_3 () {
1427 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1428 public static void invoke_in_domain () {
1431 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1432 public static void invoke_in_domain_2 () {
1435 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1436 public static void assembly_load_in_domain () {
1437 Assembly.Load ("System.Transactions");
1440 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1441 public static void dynamic_methods () {
1442 var m = new DynamicMethod ("dyn_method", typeof (void), new Type [] { typeof (int) }, typeof (object).Module);
1443 var ig = m.GetILGenerator ();
1445 ig.Emit (OpCodes.Ldstr, "FOO");
1446 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
1447 ig.Emit (OpCodes.Ret);
1449 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
1454 public static void dyn_call (string s) {
1457 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1458 public static void ref_emit () {
1459 AssemblyName assemblyName = new AssemblyName ();
1460 assemblyName.Name = "foo";
1462 AssemblyBuilder assembly =
1463 Thread.GetDomain ().DefineDynamicAssembly (
1464 assemblyName, AssemblyBuilderAccess.RunAndSave);
1466 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
1468 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
1469 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
1470 ILGenerator ig = mb.GetILGenerator ();
1471 ig.Emit (OpCodes.Ldstr, "FOO");
1472 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
1473 ig.Emit (OpCodes.Ret);
1475 Type t = tb.CreateType ();
1477 t.GetMethod ("ref_emit_method").Invoke (null, null);
1480 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1481 public static void ref_emit_call (string s) {
1484 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1485 public static void frames_in_native () {
1487 var evt = new ManualResetEvent (false);
1489 object mon = new object ();
1490 ThreadPool.QueueUserWorkItem (delegate {
1491 frames_in_native_2 ();
1497 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1498 static void frames_in_native_2 () {
1499 frames_in_native_3 ();
1502 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1503 static void frames_in_native_3 () {
1506 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1507 public static void string_call (string s) {
1510 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1511 public static void ss_regress_654694 () {
1518 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1519 public static void user () {
1522 Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
1525 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1526 public static void type_load () {
1530 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1531 static void type_load_2 () {
1532 var c1 = new Dictionary<int, int> ();
1534 var c = new TypeLoadClass ();
1536 var c2 = new TypeLoadClass2 ();
1540 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1541 public static void regress () {
1542 regress_2755 (DateTime.Now);
1545 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1546 public static unsafe void regress_2755 (DateTime d) {
1547 int* buffer = stackalloc int [128];
1552 for (int i = 0; i < 128; ++i)
1555 regress_2755_3 (sum);
1558 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1559 public static void regress_2755_2 () {
1562 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1563 public static void regress_2755_3 (int sum) {
1566 static object gc_suspend_field;
1568 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1569 static unsafe void set_gc_suspend_field () {
1570 set_gc_suspend_field_2 ();
1572 int* buffer = stackalloc int [4096];
1575 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1576 static void set_gc_suspend_field_2 () {
1577 gc_suspend_field = new object ();
1580 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1581 static void gc_suspend_1 () {
1584 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1585 public static void gc_suspend_invoke () {
1586 gc_suspend_field = null;
1588 GC.WaitForPendingFinalizers ();
1591 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1592 public static void gc_suspend () {
1593 set_gc_suspend_field ();
1597 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1598 public static void generic_method<T> () where T : class {
1601 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1602 public void evaluate_method_2 () {
1605 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1606 public void evaluate_method () {
1608 evaluate_method_2 ();
1611 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1612 static void set_ip_1 () {
1615 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1616 static void set_ip_2 () {
1619 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1620 public static void set_ip () {
1631 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1632 public static void step_filters () {
1633 ClassWithCctor.cctor_filter ();
1636 class ClassWithCctor {
1637 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1638 static ClassWithCctor () {
1643 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1644 public static void cctor_filter () {
1648 public override string virtual_method () {
1652 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1653 public static void threadpool_bp () { }
1655 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1656 public static void threadpool_io () {
1657 // Start a threadpool task that blocks on I/O.
1658 // Regression test for #42625
1659 const int nbytes = 16;
1660 var bsOut = new byte[nbytes];
1661 for (int i = 0; i < nbytes; i++) {
1664 var endPoint = NetworkHelpers.LocalEphemeralEndPoint ();
1665 var l = new TcpListener (endPoint);
1667 Task<byte[]> t = Task.Run (async () => {
1668 var c = new TcpClient ();
1669 await c.ConnectAsync (endPoint.Address, endPoint.Port);
1670 var streamIn = c.GetStream ();
1671 var bs = new byte[nbytes];
1673 int nremain = nbytes;
1674 while (nread < nbytes) {
1675 int r = await streamIn.ReadAsync (bs, nread, nremain);
1682 var s = l.AcceptTcpClient ();
1684 // write bytes in two groups so that the task blocks on the ReadAsync
1685 var streamOut = s.GetStream ();
1686 var nbytesFirst = nbytes / 2;
1687 var nbytesRest = nbytes - nbytesFirst;
1688 streamOut.Write (bsOut, 0, nbytesFirst);
1690 streamOut.Write (bsOut, nbytesFirst, nbytesRest);
1692 var bsIn = t.Result;
1695 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1696 public void attach_break () {
1699 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1700 public void attach () {
1701 AppDomain domain = AppDomain.CreateDomain ("domain");
1703 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
1704 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
1708 // Wait for the client to attach
1716 public class SentinelClass : MarshalByRefObject {
1719 public class CrossDomain : MarshalByRefObject
1721 SentinelClass printMe = new SentinelClass ();
1723 public void invoke () {
1724 Tests.invoke_in_domain ();
1727 public void invoke_2 () {
1728 Tests.invoke_in_domain_2 ();
1731 public int invoke_3 () {
1735 public void assembly_load () {
1736 Tests.assembly_load_in_domain ();
1739 public void type_load () {
1740 //Activator.CreateInstance (typeof (int).Assembly.GetType ("Microsoft.Win32.RegistryOptions"));
1741 var is_server = System.Runtime.GCSettings.IsServerGC;
1747 public ProcessStartInfo info;
1750 class LocalReflectClass
1752 public static void RunMe ()
1754 var reflectMe = new someClass ();
1755 var temp = reflectMe; // Breakpoint location
1756 reflectMe.someMethod ();
1759 class someClass : ContextBoundObject
1761 public object someField;
1763 public void someMethod ()
1769 // Class used for line number info testing, don't change its layout
1770 public class LineNumbers
1772 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1773 public static void ln1 () {
1779 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1780 public static void ln2 () {
1783 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1784 public static void ln3 () {
1785 #pragma warning disable 0219
1787 #pragma warning restore 0219