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;
16 public class TestsBase
18 #pragma warning disable 0414
19 #pragma warning disable 0169
20 public int base_field_i;
21 public string base_field_s;
22 static int base_static_i = 57;
23 static string base_static_s = "C";
24 #pragma warning restore 0414
25 #pragma warning restore 0169
27 public virtual string virtual_method () {
37 public sealed class Tests3 {
38 public static void M1 () {
52 public static class Tests4 {
57 public class AAttribute : Attribute {
61 public class BAttribute : AAttribute {
65 [DebuggerDisplay ("Tests", Name="FOO", Target=typeof (int))]
66 [DebuggerTypeProxy (typeof (Tests))]
67 [BAttribute (afield = 1, bfield = 2)]
69 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
71 public static int static_field_j;
73 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
74 public int AProperty {
80 public void invoke () {
84 public struct AStruct : ITest2 {
99 public AStruct (int arg) {
107 [MethodImplAttribute (MethodImplOptions.NoInlining)]
108 public int foo (int val) {
112 [MethodImplAttribute (MethodImplOptions.NoInlining)]
113 public static int static_foo (int val) {
117 [MethodImplAttribute (MethodImplOptions.NoInlining)]
118 public int invoke_return_int () {
122 [MethodImplAttribute (MethodImplOptions.NoInlining)]
123 public static int invoke_static () {
127 [MethodImplAttribute (MethodImplOptions.NoInlining)]
128 public IntPtr invoke_return_intptr () {
132 [MethodImplAttribute (MethodImplOptions.NoInlining)]
133 public void invoke_mutate () {
137 public int invoke_iface () {
141 public override string ToString () {
142 return i.ToString ();
146 public class GClass<T> {
148 public static T static_field;
150 [MethodImplAttribute (MethodImplOptions.NoInlining)]
154 [MethodImplAttribute (MethodImplOptions.NoInlining)]
155 public void bp<T2> () {
159 public struct GStruct<T> {
164 [MethodImplAttribute (MethodImplOptions.NoInlining)]
165 public int invoke_return_int () {
170 public struct NestedStruct {
171 NestedInner nested1, nested2;
174 public struct NestedInner {
177 public interface IRecStruct {
181 struct RecStruct : IRecStruct {
184 public void foo (object o) {
201 class TestIfaces : ITest
209 TestIfaces<int> Baz () {
214 class TestIfaces<T> : ITest<T>
216 void ITest<T>.Foo () {
219 void ITest<T>.Bar () {
223 public interface ITest2
228 public class Tests : TestsBase, ITest2
230 #pragma warning disable 0414
234 bool field_bool1, field_bool2;
247 static int static_i = 55;
248 static string static_s = "A";
249 public const int literal_i = 56;
250 public const string literal_s = "B";
252 public AStruct field_struct;
253 public object field_boxed_struct;
254 public GStruct<int> generic_field_struct;
255 public KeyValuePair<int, object> boxed_struct_field;
257 public static int tls_i;
258 public static bool is_attached = Debugger.IsAttached;
259 public NestedStruct nested_struct;
261 #pragma warning restore 0414
263 public class NestedClass {
266 public int IntProperty {
275 public int ReadOnlyProperty {
281 public int this [int index] {
287 public static void wait_one ()
289 ManualResetEvent evt = new ManualResetEvent (false);
293 public static int Main (String[] args) {
296 if (args.Length > 0 && args [0] == "suspend-test")
297 /* This contains an infinite loop, so execute it conditionally */
299 if (args.Length >0 && args [0] == "unhandled-exception") {
300 unhandled_exception ();
303 if (args.Length >0 && args [0] == "unhandled-exception-endinvoke") {
304 unhandled_exception_endinvoke ();
307 if (args.Length >0 && args [0] == "unhandled-exception-user") {
308 unhandled_exception_user ();
311 if (args.Length >0 && args [0] == "wait-one") {
315 if (args.Length >0 && args [0] == "threadpool-io") {
341 if (args.Length > 0 && args [0] == "domain-test")
342 /* This takes a lot of time, so execute it conditionally */
344 if (args.Length > 0 && args [0] == "ref-emit-test")
346 if (args.Length > 0 && args [0] == "frames-in-native")
348 if (args.Length > 0 && args [0] == "invoke-single-threaded")
349 new Tests ().invoke_single_threaded ();
350 if (args.Length > 0 && args [0] == "invoke-abort")
351 new Tests ().invoke_abort ();
352 new Tests ().evaluate_method ();
356 public static void local_reflect () {
357 //Breakpoint line below, and reflect someField via ObjectMirror;
358 LocalReflectClass.RunMe ();
361 public static void breakpoints () {
362 /* Call these early so it is JITted by the time a breakpoint is placed on it */
374 bp6<string> (new GClass <int> ());
379 [MethodImplAttribute (MethodImplOptions.NoInlining)]
380 public static void bp1 () {
383 [MethodImplAttribute (MethodImplOptions.NoInlining)]
384 public static void bp2 () {
387 [MethodImplAttribute (MethodImplOptions.NoInlining)]
388 public static void bp3 () {
391 [MethodImplAttribute (MethodImplOptions.NoInlining)]
392 public static void bp4 () {
395 [MethodImplAttribute (MethodImplOptions.NoInlining)]
396 public static void bp5 () {
399 [MethodImplAttribute (MethodImplOptions.NoInlining)]
400 public static void bp6<T> (GClass<int> gc) {
404 [MethodImplAttribute (MethodImplOptions.NoInlining)]
405 public static void bp7<T> () {
408 [MethodImplAttribute (MethodImplOptions.NoInlining)]
409 public static void single_stepping () {
416 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
423 ss_regress_654694 ();
429 ss_recursive_chaotic ();
433 [MethodImplAttribute (MethodImplOptions.NoInlining)]
434 public static void ss1 () {
437 [MethodImplAttribute (MethodImplOptions.NoInlining)]
438 public static void ss2 () {
441 [MethodImplAttribute (MethodImplOptions.NoInlining)]
442 public static int ss3 () {
445 for (int i = 0; i < 10; ++i)
451 [MethodImplAttribute (MethodImplOptions.NoInlining)]
452 public static void ss3_2 () {
456 [MethodImplAttribute (MethodImplOptions.NoInlining)]
457 public static void ss3_2_2 () {
460 [MethodImplAttribute (MethodImplOptions.NoInlining)]
461 public static int ss4 () {
467 [MethodImplAttribute (MethodImplOptions.NoInlining)]
468 public static void ss5 (int[] arr, Func<int, bool> selector) {
469 // Call into linq which calls back into this assembly
470 arr.Count (selector);
473 [MethodImplAttribute (MethodImplOptions.NoInlining)]
474 public static void ss6 (bool b) {
477 throw new Exception ();
481 [MethodImplAttribute (MethodImplOptions.NoInlining)]
482 public static void ss6_2 () {
485 [MethodImplAttribute (MethodImplOptions.NoInlining)]
486 public static void ss7 () {
495 [MethodImplAttribute (MethodImplOptions.NoInlining)]
496 public static void ss7_2 () {
499 [MethodImplAttribute (MethodImplOptions.NoInlining)]
500 public static void ss7_3 () {
501 throw new Exception ();
504 [MethodImplAttribute (MethodImplOptions.NoInlining)]
505 public static void ss_nested () {
506 ss_nested_1 (ss_nested_2 ());
507 ss_nested_1 (ss_nested_2 ());
511 [MethodImplAttribute (MethodImplOptions.NoInlining)]
512 public static void ss_nested_1 (int i) {
515 [MethodImplAttribute (MethodImplOptions.NoInlining)]
516 public static int ss_nested_2 () {
520 [MethodImplAttribute (MethodImplOptions.NoInlining)]
521 public static void ss_nested_3 () {
524 [MethodImplAttribute (MethodImplOptions.NoInlining)]
525 public static void ss_step_through () {
527 StepThroughClass.step_through_2 ();
531 [DebuggerStepThrough]
532 [MethodImplAttribute (MethodImplOptions.NoInlining)]
533 public static void step_through_1 () {
536 [DebuggerStepThrough]
537 class StepThroughClass {
538 [MethodImplAttribute (MethodImplOptions.NoInlining)]
539 public static void step_through_2 () {
543 [DebuggerStepThrough]
544 [MethodImplAttribute (MethodImplOptions.NoInlining)]
545 public static void step_through_3 () {
548 [MethodImplAttribute (MethodImplOptions.NoInlining)]
549 public static void ss_non_user_code () {
551 StepNonUserCodeClass.non_user_code_2 ();
555 [DebuggerNonUserCode]
556 [MethodImplAttribute (MethodImplOptions.NoInlining)]
557 public static void non_user_code_1 () {
560 [DebuggerNonUserCode]
561 class StepNonUserCodeClass {
562 [MethodImplAttribute (MethodImplOptions.NoInlining)]
563 public static void non_user_code_2 () {
567 [DebuggerNonUserCode]
568 [MethodImplAttribute (MethodImplOptions.NoInlining)]
569 public static void non_user_code_3 () {
572 [MethodImplAttribute (MethodImplOptions.NoInlining)]
573 public static void ss_recursive (int n) {
576 ss_recursive (n + 1);
579 // Breakpoint will be placed here
580 [MethodImplAttribute (MethodImplOptions.NoInlining)]
581 public static void ss_recursive2_trap ()
585 public static void ss_recursive2_at (string s)
587 // Console.WriteLine (s);
590 // This method is used both for a step over and step out test.
591 [MethodImplAttribute (MethodImplOptions.NoInlining)]
592 public static void ss_recursive2 (int x)
594 ss_recursive2_at ( "ss_recursive2 in " + x);
597 ss_recursive2_at ("ss_recursive2 descend " + x);
598 ss_recursive2_trap ();
599 ss_recursive2 (next);
601 ss_recursive2_at ("ss_recursive2 out " + x);
604 // Breakpoint will be placed here
605 [MethodImplAttribute (MethodImplOptions.NoInlining)]
606 public static void ss_recursive_chaotic_trap ()
610 [MethodImplAttribute (MethodImplOptions.NoInlining)]
611 public static void ss_recursive_chaotic_at (bool exiting, string at, int n)
613 // string indent = "";
614 // for (int count = 5 - n; count > 0; count--)
616 // Console.WriteLine (indent + (exiting ? "<--" : "-->") + " " + at + " " + n);
619 [MethodImplAttribute (MethodImplOptions.NoInlining)]
620 public static void ss_recursive_chaotic_fizz (int n)
622 ss_recursive_chaotic_at (false, "fizz", n);
625 ss_recursive_chaotic_buzz (next);
626 ss_recursive_chaotic_fizzbuzz (next);
628 ss_recursive_chaotic_trap ();
630 ss_recursive_chaotic_at (true, "fizz", n);
633 [MethodImplAttribute (MethodImplOptions.NoInlining)]
634 public static void ss_recursive_chaotic_buzz (int n)
636 ss_recursive_chaotic_at (false, "buzz", n);
639 ss_recursive_chaotic_fizz (next);
640 ss_recursive_chaotic_fizzbuzz (next);
642 ss_recursive_chaotic_at (true, "buzz", n);
645 [MethodImplAttribute (MethodImplOptions.NoInlining)]
646 public static void ss_recursive_chaotic_fizzbuzz (int n)
648 ss_recursive_chaotic_at (false, "fizzbuzz", n);
651 ss_recursive_chaotic_fizz (next);
652 ss_recursive_chaotic_buzz (next);
653 ss_recursive_chaotic_fizzbuzz (next);
655 ss_recursive_chaotic_at (true, "fizzbuzz", n);
658 // Call a complex tree of recursive calls that has tripped up "step out" in the past.
659 [MethodImplAttribute (MethodImplOptions.NoInlining)]
660 public static void ss_recursive_chaotic ()
662 ss_recursive_chaotic_fizz (5);
665 [MethodImplAttribute (MethodImplOptions.NoInlining)]
666 public static void ss_fp_clobber () {
667 double v = ss_fp_clobber_1 (5.0);
671 [MethodImplAttribute (MethodImplOptions.NoInlining)]
672 public static double ss_fp_clobber_1 (double d) {
676 [MethodImplAttribute (MethodImplOptions.NoInlining)]
677 public static void ss_fp_clobber_2 (double d) {
680 [MethodImplAttribute (MethodImplOptions.NoInlining)]
681 public static bool is_even (int i) {
687 Console.WriteLine ("HIT!");
693 [MethodImplAttribute (MethodImplOptions.NoInlining)]
694 public static void arguments () {
695 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));
697 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object (), '\0'.ToString () + "A");
698 Tests t = new Tests () { field_i = 42, field_s = "S" };
702 [MethodImplAttribute (MethodImplOptions.NoInlining)]
703 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) {
704 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
707 [MethodImplAttribute (MethodImplOptions.NoInlining)]
708 public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2, string s4) {
709 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
712 [MethodImplAttribute (MethodImplOptions.NoInlining)]
713 public object arg3 (string s) {
714 return s + s + s + s + this;
717 [MethodImplAttribute (MethodImplOptions.NoInlining)]
718 public static void objects () {
719 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 };
720 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
721 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 });
724 [MethodImplAttribute (MethodImplOptions.NoInlining)]
725 public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
726 if (t == null || gc1 == null || gc2 == null)
732 [MethodImplAttribute (MethodImplOptions.NoInlining)]
733 public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
734 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
737 [MethodImplAttribute (MethodImplOptions.NoInlining)]
738 public static void objrefs () {
739 Tests t = new Tests () {};
747 [MethodImplAttribute (MethodImplOptions.NoInlining)]
748 public static void set_child (Tests t) {
749 t.child = new Tests ();
752 [MethodImplAttribute (MethodImplOptions.NoInlining)]
753 public void objrefs1 () {
756 [MethodImplAttribute (MethodImplOptions.NoInlining)]
757 public static void objrefs2 () {
760 public static void vtypes () {
761 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 ) };
762 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
763 AStruct[] arr = new AStruct[] {
764 new AStruct () { i = 1, s = "S1" },
765 new AStruct () { i = 2, s = "S2" } };
766 TypedReference typedref = __makeref (s);
767 t.vtypes1 (s, arr, typedref);
773 [MethodImplAttribute (MethodImplOptions.NoInlining)]
774 public object vtypes1 (AStruct s, AStruct[] arr, TypedReference typedref) {
781 [MethodImplAttribute (MethodImplOptions.NoInlining)]
782 public static void vtypes2 (AStruct s) {
786 [MethodImplAttribute (MethodImplOptions.NoInlining)]
787 public static void vtypes3 (AStruct s) {
788 AStruct.static_foo (5);
791 [MethodImplAttribute (MethodImplOptions.NoInlining)]
792 public static void vtypes4_2 (IRecStruct o) {
795 [MethodImplAttribute (MethodImplOptions.NoInlining)]
796 public static void vtypes4 () {
797 IRecStruct s = new RecStruct ();
802 [MethodImplAttribute (MethodImplOptions.NoInlining)]
803 public static void locals () {
805 var astruct = new AStruct () { i = 42 };
807 locals2<string> (null, 5, "ABC", ref s, ref astruct);
813 [MethodImplAttribute (MethodImplOptions.NoInlining)]
814 static void locals11 (double a, ref double b) {
817 [MethodImplAttribute (MethodImplOptions.NoInlining)]
818 public static void locals1 (string[] args) {
822 locals11 (b: ref ri, a: ri);
824 for (int j = 0; j < 10; ++j) {
829 [MethodImplAttribute (MethodImplOptions.NoInlining)]
831 [StateMachine (typeof (int))]
833 public static void locals2<T> (string[] args, int arg, T t, ref string rs, ref AStruct astruct) {
837 for (int j = 0; j < 10; ++j) {
842 astruct = new AStruct ();
845 List<int> alist = new List<int> () { 12 };
849 [MethodImplAttribute (MethodImplOptions.NoInlining)]
850 public static void locals3 () {
870 [MethodImplAttribute (MethodImplOptions.NoInlining)]
871 public static void locals4 () {
874 [MethodImplAttribute (MethodImplOptions.NoInlining)]
875 public static void locals5 () {
878 [MethodImplAttribute (MethodImplOptions.NoInlining)]
879 public static void locals6 () {
882 for (i = 0; i < 10; ++i)
885 for (i = 0; i < 10; ++i)
895 [MethodImplAttribute (MethodImplOptions.NoInlining)]
896 public static void locals6_1 () {
899 [MethodImplAttribute (MethodImplOptions.NoInlining)]
900 public static void locals6_2 (int arg) {
903 [MethodImplAttribute (MethodImplOptions.NoInlining)]
904 public static void locals6_3 () {
905 // Clobber all registers
906 int sum = 0, i, j, k, l, m;
907 for (i = 0; i < 100; ++i)
909 for (j = 0; j < 100; ++j)
911 for (k = 0; k < 100; ++k)
913 for (l = 0; l < 100; ++l)
915 for (m = 0; m < 100; ++m)
919 [MethodImplAttribute (MethodImplOptions.NoInlining)]
920 public static void locals6_4 (int arg) {
923 [MethodImplAttribute (MethodImplOptions.NoInlining)]
924 public static void locals6_5 () {
927 [MethodImplAttribute (MethodImplOptions.NoInlining)]
928 public static void locals6_6 (int arg) {
931 [MethodImplAttribute (MethodImplOptions.NoInlining)]
932 public static void locals7<T> (T arg) {
937 [MethodImplAttribute (MethodImplOptions.NoInlining)]
938 public static void line_numbers () {
942 [MethodImplAttribute (MethodImplOptions.NoInlining)]
943 public static void suspend () {
951 struct TypedRefTest {
955 [MethodImplAttribute (MethodImplOptions.NoInlining)]
956 public static void type_info () {
957 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
958 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
961 AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
962 TypedRefTest reftest = new TypedRefTest () { MaxValue = 12 };
963 TypedReference typedref = __makeref (reftest);
964 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);
968 [MethodImplAttribute (MethodImplOptions.NoInlining)]
969 public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
970 if (t == null || gc1 == null || gc2 == null)
976 [MethodImplAttribute (MethodImplOptions.NoInlining)]
977 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) {
978 return s2 [0] + s3 [0] + s4 [0, 0];
981 [MethodImplAttribute (MethodImplOptions.NoInlining)]
982 public static void assembly_load () {
986 [MethodImplAttribute (MethodImplOptions.NoInlining)]
987 public static void assembly_load_2 () {
988 // This will load System.dll while holding the loader lock
992 [MethodImplAttribute (MethodImplOptions.NoInlining)]
993 public static void invoke () {
994 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }, new GStruct<int> { j = 42 });
995 new Tests ().invoke_ex ();
998 [MethodImplAttribute (MethodImplOptions.NoInlining)]
999 public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
1003 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1004 public void invoke2 () {
1007 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1008 public void invoke_ex () {
1012 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1013 public void invoke_ex_inner () {
1015 throw new Exception ();
1022 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1023 public void invoke_single_threaded () {
1024 // Spawn a thread incrementing a counter
1025 bool finished = false;
1027 new Thread (delegate () {
1034 invoke_single_threaded_2 ();
1039 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1040 public void invoke_single_threaded_2 () {
1043 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1044 public void invoke_abort () {
1047 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1048 public void invoke_abort_2 () {
1049 Thread.Sleep (1000000);
1052 public void invoke_return_void () {
1055 public string invoke_return_ref () {
1059 public object invoke_return_null () {
1063 public int invoke_return_primitive () {
1067 public int? invoke_return_nullable () {
1071 public int? invoke_return_nullable_null () {
1075 public void invoke_type_load () {
1082 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) {
1083 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
1086 public int invoke_pass_primitive2 (bool b) {
1090 public string invoke_pass_ref (string s) {
1094 public static string invoke_static_pass_ref (string s) {
1098 public static void invoke_static_return_void () {
1101 public static void invoke_throws () {
1102 throw new Exception ();
1105 public int invoke_iface () {
1109 public void invoke_out (out int foo, out int[] arr) {
1114 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1115 public static void exceptions () {
1117 throw new OverflowException ();
1118 } catch (Exception) {
1121 throw new OverflowException ();
1122 } catch (Exception) {
1125 throw new ArgumentException ();
1126 } catch (Exception) {
1129 throw new OverflowException ();
1130 } catch (Exception) {
1134 throw new OverflowException ();
1135 } catch (Exception) {
1138 throw new Exception ();
1139 } catch (Exception) {
1145 } catch (Exception) {
1150 } catch (Exception) {
1154 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1155 public static void unhandled_exception () {
1156 ThreadPool.QueueUserWorkItem (delegate {
1157 throw new InvalidOperationException ();
1159 Thread.Sleep (10000);
1162 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1163 public static void unhandled_exception_endinvoke_2 () {
1166 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1167 public static void unhandled_exception_endinvoke () {
1168 Action action = new Action (() =>
1170 throw new Exception ("thrown");
1172 action.BeginInvoke ((ar) => {
1174 action.EndInvoke (ar);
1175 } catch (Exception ex) {
1176 //Console.WriteLine (ex);
1179 Thread.Sleep (1000);
1180 unhandled_exception_endinvoke_2 ();
1183 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1184 public static void unhandled_exception_user () {
1186 System.Threading.Tasks.Task.Factory.StartNew (() => {
1189 Thread.Sleep (10000);
1193 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1194 public static void Throw () {
1195 throw new Exception ();
1198 internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
1201 throw new ArgumentNullException ();
1202 if (dlg.Target != null)
1203 throw new ArgumentException ();
1204 if (dlg.Method == null)
1205 throw new ArgumentException ();
1207 var ret_type = dlg.Method.ReturnType;
1208 var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();
1210 var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
1211 var ig = dynamic.GetILGenerator ();
1213 LocalBuilder retval = null;
1214 if (ret_type != typeof (void))
1215 retval = ig.DeclareLocal (ret_type);
1217 var label = ig.BeginExceptionBlock ();
1219 for (int i = 0; i < param_types.Length; i++)
1220 ig.Emit (OpCodes.Ldarg, i);
1221 ig.Emit (OpCodes.Call, dlg.Method);
1224 ig.Emit (OpCodes.Stloc, retval);
1226 ig.Emit (OpCodes.Leave, label);
1228 ig.BeginExceptFilterBlock ();
1230 ig.Emit (OpCodes.Call, filter_method);
1232 ig.BeginCatchBlock (null);
1234 ig.Emit (OpCodes.Pop);
1236 ig.EndExceptionBlock ();
1239 ig.Emit (OpCodes.Ldloc, retval);
1241 ig.Emit (OpCodes.Ret);
1243 return dynamic.CreateDelegate (dlg.GetType ());
1246 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1247 static void exception_filter_method () {
1248 throw new InvalidOperationException ();
1251 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1252 static int exception_filter_filter (Exception exc) {
1256 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1257 public static void exception_filter () {
1258 var method = typeof (Tests).GetMethod (
1259 "exception_filter_method", BindingFlags.NonPublic | BindingFlags.Static);
1260 var filter_method = typeof (Tests).GetMethod (
1261 "exception_filter_filter", BindingFlags.NonPublic | BindingFlags.Static);
1263 var dlg = Delegate.CreateDelegate (typeof (Action), method);
1265 var wrapper = (Action) create_filter_delegate (dlg, filter_method);
1270 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1271 public static bool return_true () {
1275 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1276 public static void exceptions2 () {
1278 throw new Exception ();
1279 Console.WriteLine ();
1282 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1283 public static void threads () {
1284 Thread t = new Thread (delegate () {});
1290 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1291 public static void domains () {
1292 AppDomain domain = AppDomain.CreateDomain ("domain");
1294 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
1295 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
1297 domains_print_across (o);
1299 domains_2 (o, new CrossDomain ());
1307 AppDomain.Unload (domain);
1311 typeof (Tests).GetMethod ("called_from_invoke").Invoke (null, null);
1314 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1315 public static void called_from_invoke () {
1318 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1319 public static void domains_2 (object o, object o2) {
1322 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1323 public static void domains_print_across (object o) {
1326 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1327 public static void domains_3 () {
1330 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1331 public static void invoke_in_domain () {
1334 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1335 public static void invoke_in_domain_2 () {
1338 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1339 public static void dynamic_methods () {
1340 var m = new DynamicMethod ("dyn_method", typeof (void), new Type [] { typeof (int) }, typeof (object).Module);
1341 var ig = m.GetILGenerator ();
1343 ig.Emit (OpCodes.Ldstr, "FOO");
1344 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
1345 ig.Emit (OpCodes.Ret);
1347 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
1352 public static void dyn_call (string s) {
1355 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1356 public static void ref_emit () {
1357 AssemblyName assemblyName = new AssemblyName ();
1358 assemblyName.Name = "foo";
1360 AssemblyBuilder assembly =
1361 Thread.GetDomain ().DefineDynamicAssembly (
1362 assemblyName, AssemblyBuilderAccess.RunAndSave);
1364 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
1366 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
1367 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
1368 ILGenerator ig = mb.GetILGenerator ();
1369 ig.Emit (OpCodes.Ldstr, "FOO");
1370 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
1371 ig.Emit (OpCodes.Ret);
1373 Type t = tb.CreateType ();
1375 t.GetMethod ("ref_emit_method").Invoke (null, null);
1378 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1379 public static void ref_emit_call (string s) {
1382 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1383 public static void frames_in_native () {
1385 var evt = new ManualResetEvent (false);
1387 object mon = new object ();
1388 ThreadPool.QueueUserWorkItem (delegate {
1389 frames_in_native_2 ();
1395 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1396 static void frames_in_native_2 () {
1397 frames_in_native_3 ();
1400 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1401 static void frames_in_native_3 () {
1404 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1405 public static void string_call (string s) {
1408 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1409 public static void ss_regress_654694 () {
1416 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1417 public static void user () {
1420 Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
1423 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1424 public static void type_load () {
1428 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1429 static void type_load_2 () {
1430 var c1 = new Dictionary<int, int> ();
1432 var c = new TypeLoadClass ();
1434 var c2 = new TypeLoadClass2 ();
1438 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1439 public static void regress () {
1440 regress_2755 (DateTime.Now);
1443 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1444 public static unsafe void regress_2755 (DateTime d) {
1445 int* buffer = stackalloc int [128];
1450 for (int i = 0; i < 128; ++i)
1453 regress_2755_3 (sum);
1456 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1457 public static void regress_2755_2 () {
1460 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1461 public static void regress_2755_3 (int sum) {
1464 static object gc_suspend_field;
1466 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1467 static unsafe void set_gc_suspend_field () {
1468 set_gc_suspend_field_2 ();
1470 int* buffer = stackalloc int [4096];
1473 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1474 static void set_gc_suspend_field_2 () {
1475 gc_suspend_field = new object ();
1478 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1479 static void gc_suspend_1 () {
1482 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1483 public static void gc_suspend_invoke () {
1484 gc_suspend_field = null;
1486 GC.WaitForPendingFinalizers ();
1489 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1490 public static void gc_suspend () {
1491 set_gc_suspend_field ();
1495 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1496 public static void generic_method<T> () where T : class {
1499 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1500 public void evaluate_method_2 () {
1503 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1504 public void evaluate_method () {
1506 evaluate_method_2 ();
1509 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1510 static void set_ip_1 () {
1513 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1514 static void set_ip_2 () {
1517 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1518 public static void set_ip () {
1529 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1530 public static void step_filters () {
1531 ClassWithCctor.cctor_filter ();
1534 class ClassWithCctor {
1535 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1536 static ClassWithCctor () {
1541 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1542 public static void cctor_filter () {
1546 public override string virtual_method () {
1550 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1551 public static void threadpool_io () {
1552 Task<int> t = Task.Run (async () => {
1553 var wc = new System.Net.WebClient ();
1554 string filename = System.IO.Path.GetTempFileName ();
1556 var dl = wc.DownloadFileTaskAsync ("http://www.mono-project.com/", filename);
1558 System.IO.File.Delete (filename);
1565 class TypeLoadClass {
1568 class TypeLoadClass2 {
1571 public class SentinelClass : MarshalByRefObject {
1574 public class CrossDomain : MarshalByRefObject
1576 SentinelClass printMe = new SentinelClass ();
1578 public void invoke () {
1579 Tests.invoke_in_domain ();
1582 public void invoke_2 () {
1583 Tests.invoke_in_domain_2 ();
1586 public int invoke_3 () {
1593 public ProcessStartInfo info;
1596 // Class used for line number info testing, don't change its layout
1597 public class LineNumbers
1599 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1600 public static void ln1 () {
1606 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1607 public static void ln2 () {
1610 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1611 public static void ln3 () {
1612 #pragma warning disable 0219
1614 #pragma warning restore 0219
1619 class LocalReflectClass
1621 public static void RunMe ()
1623 var reflectMe = new someClass ();
1624 reflectMe.someMethod ();
1627 class someClass : ContextBoundObject
1629 public object someField;
1631 public void someMethod ()