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.Collections.Generic;
15 public class TestsBase
17 #pragma warning disable 0414
18 #pragma warning disable 0169
19 public int base_field_i;
20 public string base_field_s;
21 static int base_static_i = 57;
22 static string base_static_s = "C";
23 #pragma warning restore 0414
24 #pragma warning restore 0169
26 public virtual string virtual_method () {
36 public sealed class Tests3 {
37 public static void M1 () {
51 public static class Tests4 {
56 public class AAttribute : Attribute {
60 public class BAttribute : AAttribute {
64 [DebuggerDisplay ("Tests", Name="FOO", Target=typeof (int))]
65 [DebuggerTypeProxy (typeof (Tests))]
66 [BAttribute (afield = 1, bfield = 2)]
68 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
70 public static int static_field_j;
72 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
73 public int AProperty {
79 public void invoke () {
83 public struct AStruct : ITest2 {
98 public AStruct (int arg) {
106 [MethodImplAttribute (MethodImplOptions.NoInlining)]
107 public int foo (int val) {
111 [MethodImplAttribute (MethodImplOptions.NoInlining)]
112 public static int static_foo (int val) {
116 [MethodImplAttribute (MethodImplOptions.NoInlining)]
117 public int invoke_return_int () {
121 [MethodImplAttribute (MethodImplOptions.NoInlining)]
122 public static int invoke_static () {
126 [MethodImplAttribute (MethodImplOptions.NoInlining)]
127 public IntPtr invoke_return_intptr () {
131 [MethodImplAttribute (MethodImplOptions.NoInlining)]
132 public void invoke_mutate () {
136 public int invoke_iface () {
140 public override string ToString () {
141 return i.ToString ();
145 public class GClass<T> {
147 public static T static_field;
149 [MethodImplAttribute (MethodImplOptions.NoInlining)]
153 [MethodImplAttribute (MethodImplOptions.NoInlining)]
154 public void bp<T2> () {
158 public struct GStruct<T> {
163 [MethodImplAttribute (MethodImplOptions.NoInlining)]
164 public int invoke_return_int () {
169 public struct NestedStruct {
170 NestedInner nested1, nested2;
173 public struct NestedInner {
176 public interface IRecStruct {
180 struct RecStruct : IRecStruct {
183 public void foo (object o) {
200 class TestIfaces : ITest
208 TestIfaces<int> Baz () {
213 class TestIfaces<T> : ITest<T>
215 void ITest<T>.Foo () {
218 void ITest<T>.Bar () {
222 public interface ITest2
227 public class Tests : TestsBase, ITest2
229 #pragma warning disable 0414
233 bool field_bool1, field_bool2;
246 static int static_i = 55;
247 static string static_s = "A";
248 public const int literal_i = 56;
249 public const string literal_s = "B";
251 public AStruct field_struct;
252 public object field_boxed_struct;
253 public GStruct<int> generic_field_struct;
254 public KeyValuePair<int, object> boxed_struct_field;
256 public static int tls_i;
257 public static bool is_attached = Debugger.IsAttached;
258 public NestedStruct nested_struct;
260 #pragma warning restore 0414
262 public class NestedClass {
265 public int IntProperty {
274 public int ReadOnlyProperty {
280 public int this [int index] {
286 public static void wait_one ()
288 ManualResetEvent evt = new ManualResetEvent (false);
292 public static int Main (String[] args) {
295 if (args.Length > 0 && args [0] == "suspend-test")
296 /* This contains an infinite loop, so execute it conditionally */
298 if (args.Length >0 && args [0] == "unhandled-exception") {
299 unhandled_exception ();
302 if (args.Length >0 && args [0] == "unhandled-exception-endinvoke") {
303 unhandled_exception_endinvoke ();
306 if (args.Length >0 && args [0] == "unhandled-exception-user") {
307 unhandled_exception_user ();
310 if (args.Length >0 && args [0] == "wait-one") {
336 if (args.Length > 0 && args [0] == "domain-test")
337 /* This takes a lot of time, so execute it conditionally */
339 if (args.Length > 0 && args [0] == "ref-emit-test")
341 if (args.Length > 0 && args [0] == "frames-in-native")
343 if (args.Length > 0 && args [0] == "invoke-single-threaded")
344 new Tests ().invoke_single_threaded ();
345 if (args.Length > 0 && args [0] == "invoke-abort")
346 new Tests ().invoke_abort ();
347 new Tests ().evaluate_method ();
351 public static void local_reflect () {
352 //Breakpoint line below, and reflect someField via ObjectMirror;
353 LocalReflectClass.RunMe ();
356 public static void breakpoints () {
357 /* Call these early so it is JITted by the time a breakpoint is placed on it */
369 bp6<string> (new GClass <int> ());
374 [MethodImplAttribute (MethodImplOptions.NoInlining)]
375 public static void bp1 () {
378 [MethodImplAttribute (MethodImplOptions.NoInlining)]
379 public static void bp2 () {
382 [MethodImplAttribute (MethodImplOptions.NoInlining)]
383 public static void bp3 () {
386 [MethodImplAttribute (MethodImplOptions.NoInlining)]
387 public static void bp4 () {
390 [MethodImplAttribute (MethodImplOptions.NoInlining)]
391 public static void bp5 () {
394 [MethodImplAttribute (MethodImplOptions.NoInlining)]
395 public static void bp6<T> (GClass<int> gc) {
399 [MethodImplAttribute (MethodImplOptions.NoInlining)]
400 public static void bp7<T> () {
403 [MethodImplAttribute (MethodImplOptions.NoInlining)]
404 public static void single_stepping () {
411 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
418 ss_regress_654694 ();
424 ss_recursive_chaotic ();
428 [MethodImplAttribute (MethodImplOptions.NoInlining)]
429 public static void ss1 () {
432 [MethodImplAttribute (MethodImplOptions.NoInlining)]
433 public static void ss2 () {
436 [MethodImplAttribute (MethodImplOptions.NoInlining)]
437 public static int ss3 () {
440 for (int i = 0; i < 10; ++i)
446 [MethodImplAttribute (MethodImplOptions.NoInlining)]
447 public static void ss3_2 () {
451 [MethodImplAttribute (MethodImplOptions.NoInlining)]
452 public static void ss3_2_2 () {
455 [MethodImplAttribute (MethodImplOptions.NoInlining)]
456 public static int ss4 () {
462 [MethodImplAttribute (MethodImplOptions.NoInlining)]
463 public static void ss5 (int[] arr, Func<int, bool> selector) {
464 // Call into linq which calls back into this assembly
465 arr.Count (selector);
468 [MethodImplAttribute (MethodImplOptions.NoInlining)]
469 public static void ss6 (bool b) {
472 throw new Exception ();
476 [MethodImplAttribute (MethodImplOptions.NoInlining)]
477 public static void ss6_2 () {
480 [MethodImplAttribute (MethodImplOptions.NoInlining)]
481 public static void ss7 () {
490 [MethodImplAttribute (MethodImplOptions.NoInlining)]
491 public static void ss7_2 () {
494 [MethodImplAttribute (MethodImplOptions.NoInlining)]
495 public static void ss7_3 () {
496 throw new Exception ();
499 [MethodImplAttribute (MethodImplOptions.NoInlining)]
500 public static void ss_nested () {
501 ss_nested_1 (ss_nested_2 ());
502 ss_nested_1 (ss_nested_2 ());
506 [MethodImplAttribute (MethodImplOptions.NoInlining)]
507 public static void ss_nested_1 (int i) {
510 [MethodImplAttribute (MethodImplOptions.NoInlining)]
511 public static int ss_nested_2 () {
515 [MethodImplAttribute (MethodImplOptions.NoInlining)]
516 public static void ss_nested_3 () {
519 [MethodImplAttribute (MethodImplOptions.NoInlining)]
520 public static void ss_step_through () {
522 StepThroughClass.step_through_2 ();
526 [DebuggerStepThrough]
527 [MethodImplAttribute (MethodImplOptions.NoInlining)]
528 public static void step_through_1 () {
531 [DebuggerStepThrough]
532 class StepThroughClass {
533 [MethodImplAttribute (MethodImplOptions.NoInlining)]
534 public static void step_through_2 () {
538 [DebuggerStepThrough]
539 [MethodImplAttribute (MethodImplOptions.NoInlining)]
540 public static void step_through_3 () {
543 [MethodImplAttribute (MethodImplOptions.NoInlining)]
544 public static void ss_non_user_code () {
546 StepNonUserCodeClass.non_user_code_2 ();
550 [DebuggerNonUserCode]
551 [MethodImplAttribute (MethodImplOptions.NoInlining)]
552 public static void non_user_code_1 () {
555 [DebuggerNonUserCode]
556 class StepNonUserCodeClass {
557 [MethodImplAttribute (MethodImplOptions.NoInlining)]
558 public static void non_user_code_2 () {
562 [DebuggerNonUserCode]
563 [MethodImplAttribute (MethodImplOptions.NoInlining)]
564 public static void non_user_code_3 () {
567 [MethodImplAttribute (MethodImplOptions.NoInlining)]
568 public static void ss_recursive (int n) {
571 ss_recursive (n + 1);
574 // Breakpoint will be placed here
575 [MethodImplAttribute (MethodImplOptions.NoInlining)]
576 public static void ss_recursive2_trap ()
580 public static void ss_recursive2_at (string s)
582 // Console.WriteLine (s);
585 // This method is used both for a step over and step out test.
586 [MethodImplAttribute (MethodImplOptions.NoInlining)]
587 public static void ss_recursive2 (int x)
589 ss_recursive2_at ( "ss_recursive2 in " + x);
592 ss_recursive2_at ("ss_recursive2 descend " + x);
593 ss_recursive2_trap ();
594 ss_recursive2 (next);
596 ss_recursive2_at ("ss_recursive2 out " + x);
599 // Breakpoint will be placed here
600 [MethodImplAttribute (MethodImplOptions.NoInlining)]
601 public static void ss_recursive_chaotic_trap ()
605 [MethodImplAttribute (MethodImplOptions.NoInlining)]
606 public static void ss_recursive_chaotic_at (bool exiting, string at, int n)
608 // string indent = "";
609 // for (int count = 12 - n; count > 0; count--)
611 // Console.WriteLine (indent + (exiting ? "<--" : "-->") + " " + at + " " + n);
614 [MethodImplAttribute (MethodImplOptions.NoInlining)]
615 public static void ss_recursive_chaotic_fizz (int n)
617 ss_recursive_chaotic_at (false, "fizz", n);
620 ss_recursive_chaotic_buzz (next);
621 ss_recursive_chaotic_fizzbuzz (next);
623 ss_recursive_chaotic_trap ();
625 ss_recursive_chaotic_at (true, "fizz", n);
628 [MethodImplAttribute (MethodImplOptions.NoInlining)]
629 public static void ss_recursive_chaotic_buzz (int n)
631 ss_recursive_chaotic_at (false, "buzz", n);
634 ss_recursive_chaotic_fizz (next);
635 ss_recursive_chaotic_fizzbuzz (next);
637 ss_recursive_chaotic_at (true, "buzz", n);
640 [MethodImplAttribute (MethodImplOptions.NoInlining)]
641 public static void ss_recursive_chaotic_fizzbuzz (int n)
643 ss_recursive_chaotic_at (false, "fizzbuzz", n);
646 ss_recursive_chaotic_fizz (next);
647 ss_recursive_chaotic_buzz (next);
648 ss_recursive_chaotic_fizzbuzz (next);
650 ss_recursive_chaotic_at (true, "fizzbuzz", n);
653 // Call a complex tree of recursive calls that has tripped up "step out" in the past.
654 [MethodImplAttribute (MethodImplOptions.NoInlining)]
655 public static void ss_recursive_chaotic ()
657 ss_recursive_chaotic_fizz (12);
660 [MethodImplAttribute (MethodImplOptions.NoInlining)]
661 public static void ss_fp_clobber () {
662 double v = ss_fp_clobber_1 (5.0);
666 [MethodImplAttribute (MethodImplOptions.NoInlining)]
667 public static double ss_fp_clobber_1 (double d) {
671 [MethodImplAttribute (MethodImplOptions.NoInlining)]
672 public static void ss_fp_clobber_2 (double d) {
675 [MethodImplAttribute (MethodImplOptions.NoInlining)]
676 public static bool is_even (int i) {
682 Console.WriteLine ("HIT!");
688 [MethodImplAttribute (MethodImplOptions.NoInlining)]
689 public static void arguments () {
690 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));
692 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object (), '\0'.ToString () + "A");
693 Tests t = new Tests () { field_i = 42, field_s = "S" };
697 [MethodImplAttribute (MethodImplOptions.NoInlining)]
698 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) {
699 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
702 [MethodImplAttribute (MethodImplOptions.NoInlining)]
703 public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2, string s4) {
704 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
707 [MethodImplAttribute (MethodImplOptions.NoInlining)]
708 public object arg3 (string s) {
709 return s + s + s + s + this;
712 [MethodImplAttribute (MethodImplOptions.NoInlining)]
713 public static void objects () {
714 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 };
715 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
716 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 });
719 [MethodImplAttribute (MethodImplOptions.NoInlining)]
720 public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
721 if (t == null || gc1 == null || gc2 == null)
727 [MethodImplAttribute (MethodImplOptions.NoInlining)]
728 public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
729 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
732 [MethodImplAttribute (MethodImplOptions.NoInlining)]
733 public static void objrefs () {
734 Tests t = new Tests () {};
742 [MethodImplAttribute (MethodImplOptions.NoInlining)]
743 public static void set_child (Tests t) {
744 t.child = new Tests ();
747 [MethodImplAttribute (MethodImplOptions.NoInlining)]
748 public void objrefs1 () {
751 [MethodImplAttribute (MethodImplOptions.NoInlining)]
752 public static void objrefs2 () {
755 public static void vtypes () {
756 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 ) };
757 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
758 AStruct[] arr = new AStruct[] {
759 new AStruct () { i = 1, s = "S1" },
760 new AStruct () { i = 2, s = "S2" } };
761 TypedReference typedref = __makeref (s);
762 t.vtypes1 (s, arr, typedref);
768 [MethodImplAttribute (MethodImplOptions.NoInlining)]
769 public object vtypes1 (AStruct s, AStruct[] arr, TypedReference typedref) {
776 [MethodImplAttribute (MethodImplOptions.NoInlining)]
777 public static void vtypes2 (AStruct s) {
781 [MethodImplAttribute (MethodImplOptions.NoInlining)]
782 public static void vtypes3 (AStruct s) {
783 AStruct.static_foo (5);
786 [MethodImplAttribute (MethodImplOptions.NoInlining)]
787 public static void vtypes4_2 (IRecStruct o) {
790 [MethodImplAttribute (MethodImplOptions.NoInlining)]
791 public static void vtypes4 () {
792 IRecStruct s = new RecStruct ();
797 [MethodImplAttribute (MethodImplOptions.NoInlining)]
798 public static void locals () {
800 var astruct = new AStruct () { i = 42 };
802 locals2<string> (null, 5, "ABC", ref s, ref astruct);
808 [MethodImplAttribute (MethodImplOptions.NoInlining)]
809 static void locals11 (double a, ref double b) {
812 [MethodImplAttribute (MethodImplOptions.NoInlining)]
813 public static void locals1 (string[] args) {
817 locals11 (b: ref ri, a: ri);
819 for (int j = 0; j < 10; ++j) {
824 [MethodImplAttribute (MethodImplOptions.NoInlining)]
826 [StateMachine (typeof (int))]
828 public static void locals2<T> (string[] args, int arg, T t, ref string rs, ref AStruct astruct) {
832 for (int j = 0; j < 10; ++j) {
837 astruct = new AStruct ();
840 List<int> alist = new List<int> () { 12 };
844 [MethodImplAttribute (MethodImplOptions.NoInlining)]
845 public static void locals3 () {
865 [MethodImplAttribute (MethodImplOptions.NoInlining)]
866 public static void locals4 () {
869 [MethodImplAttribute (MethodImplOptions.NoInlining)]
870 public static void locals5 () {
873 [MethodImplAttribute (MethodImplOptions.NoInlining)]
874 public static void locals6 () {
877 for (i = 0; i < 10; ++i)
880 for (i = 0; i < 10; ++i)
890 [MethodImplAttribute (MethodImplOptions.NoInlining)]
891 public static void locals6_1 () {
894 [MethodImplAttribute (MethodImplOptions.NoInlining)]
895 public static void locals6_2 (int arg) {
898 [MethodImplAttribute (MethodImplOptions.NoInlining)]
899 public static void locals6_3 () {
900 // Clobber all registers
901 int sum = 0, i, j, k, l, m;
902 for (i = 0; i < 100; ++i)
904 for (j = 0; j < 100; ++j)
906 for (k = 0; k < 100; ++k)
908 for (l = 0; l < 100; ++l)
910 for (m = 0; m < 100; ++m)
914 [MethodImplAttribute (MethodImplOptions.NoInlining)]
915 public static void locals6_4 (int arg) {
918 [MethodImplAttribute (MethodImplOptions.NoInlining)]
919 public static void locals6_5 () {
922 [MethodImplAttribute (MethodImplOptions.NoInlining)]
923 public static void locals6_6 (int arg) {
926 [MethodImplAttribute (MethodImplOptions.NoInlining)]
927 public static void locals7<T> (T arg) {
932 [MethodImplAttribute (MethodImplOptions.NoInlining)]
933 public static void line_numbers () {
937 [MethodImplAttribute (MethodImplOptions.NoInlining)]
938 public static void suspend () {
946 struct TypedRefTest {
950 [MethodImplAttribute (MethodImplOptions.NoInlining)]
951 public static void type_info () {
952 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
953 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
956 AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
957 TypedRefTest reftest = new TypedRefTest () { MaxValue = 12 };
958 TypedReference typedref = __makeref (reftest);
959 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);
963 [MethodImplAttribute (MethodImplOptions.NoInlining)]
964 public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
965 if (t == null || gc1 == null || gc2 == null)
971 [MethodImplAttribute (MethodImplOptions.NoInlining)]
972 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) {
973 return s2 [0] + s3 [0] + s4 [0, 0];
976 [MethodImplAttribute (MethodImplOptions.NoInlining)]
977 public static void assembly_load () {
981 [MethodImplAttribute (MethodImplOptions.NoInlining)]
982 public static void assembly_load_2 () {
983 // This will load System.dll while holding the loader lock
987 [MethodImplAttribute (MethodImplOptions.NoInlining)]
988 public static void invoke () {
989 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }, new GStruct<int> { j = 42 });
990 new Tests ().invoke_ex ();
993 [MethodImplAttribute (MethodImplOptions.NoInlining)]
994 public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
998 [MethodImplAttribute (MethodImplOptions.NoInlining)]
999 public void invoke2 () {
1002 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1003 public void invoke_ex () {
1007 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1008 public void invoke_ex_inner () {
1010 throw new Exception ();
1017 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1018 public void invoke_single_threaded () {
1019 // Spawn a thread incrementing a counter
1020 bool finished = false;
1022 new Thread (delegate () {
1029 invoke_single_threaded_2 ();
1034 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1035 public void invoke_single_threaded_2 () {
1038 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1039 public void invoke_abort () {
1042 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1043 public void invoke_abort_2 () {
1044 Thread.Sleep (1000000);
1047 public void invoke_return_void () {
1050 public string invoke_return_ref () {
1054 public object invoke_return_null () {
1058 public int invoke_return_primitive () {
1062 public int? invoke_return_nullable () {
1066 public int? invoke_return_nullable_null () {
1070 public void invoke_type_load () {
1077 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) {
1078 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
1081 public int invoke_pass_primitive2 (bool b) {
1085 public string invoke_pass_ref (string s) {
1089 public static string invoke_static_pass_ref (string s) {
1093 public static void invoke_static_return_void () {
1096 public static void invoke_throws () {
1097 throw new Exception ();
1100 public int invoke_iface () {
1104 public void invoke_out (out int foo, out int[] arr) {
1109 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1110 public static void exceptions () {
1112 throw new OverflowException ();
1113 } catch (Exception) {
1116 throw new OverflowException ();
1117 } catch (Exception) {
1120 throw new ArgumentException ();
1121 } catch (Exception) {
1124 throw new OverflowException ();
1125 } catch (Exception) {
1129 throw new OverflowException ();
1130 } catch (Exception) {
1133 throw new Exception ();
1134 } catch (Exception) {
1140 } catch (Exception) {
1145 } catch (Exception) {
1149 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1150 public static void unhandled_exception () {
1151 ThreadPool.QueueUserWorkItem (delegate {
1152 throw new InvalidOperationException ();
1154 Thread.Sleep (10000);
1157 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1158 public static void unhandled_exception_endinvoke_2 () {
1161 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1162 public static void unhandled_exception_endinvoke () {
1163 Action action = new Action (() =>
1165 throw new Exception ("thrown");
1167 action.BeginInvoke ((ar) => {
1169 action.EndInvoke (ar);
1170 } catch (Exception ex) {
1171 //Console.WriteLine (ex);
1174 Thread.Sleep (1000);
1175 unhandled_exception_endinvoke_2 ();
1178 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1179 public static void unhandled_exception_user () {
1181 System.Threading.Tasks.Task.Factory.StartNew (() => {
1184 Thread.Sleep (10000);
1188 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1189 public static void Throw () {
1190 throw new Exception ();
1193 internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
1196 throw new ArgumentNullException ();
1197 if (dlg.Target != null)
1198 throw new ArgumentException ();
1199 if (dlg.Method == null)
1200 throw new ArgumentException ();
1202 var ret_type = dlg.Method.ReturnType;
1203 var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();
1205 var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
1206 var ig = dynamic.GetILGenerator ();
1208 LocalBuilder retval = null;
1209 if (ret_type != typeof (void))
1210 retval = ig.DeclareLocal (ret_type);
1212 var label = ig.BeginExceptionBlock ();
1214 for (int i = 0; i < param_types.Length; i++)
1215 ig.Emit (OpCodes.Ldarg, i);
1216 ig.Emit (OpCodes.Call, dlg.Method);
1219 ig.Emit (OpCodes.Stloc, retval);
1221 ig.Emit (OpCodes.Leave, label);
1223 ig.BeginExceptFilterBlock ();
1225 ig.Emit (OpCodes.Call, filter_method);
1227 ig.BeginCatchBlock (null);
1229 ig.Emit (OpCodes.Pop);
1231 ig.EndExceptionBlock ();
1234 ig.Emit (OpCodes.Ldloc, retval);
1236 ig.Emit (OpCodes.Ret);
1238 return dynamic.CreateDelegate (dlg.GetType ());
1241 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1242 static void exception_filter_method () {
1243 throw new InvalidOperationException ();
1246 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1247 static int exception_filter_filter (Exception exc) {
1251 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1252 public static void exception_filter () {
1253 var method = typeof (Tests).GetMethod (
1254 "exception_filter_method", BindingFlags.NonPublic | BindingFlags.Static);
1255 var filter_method = typeof (Tests).GetMethod (
1256 "exception_filter_filter", BindingFlags.NonPublic | BindingFlags.Static);
1258 var dlg = Delegate.CreateDelegate (typeof (Action), method);
1260 var wrapper = (Action) create_filter_delegate (dlg, filter_method);
1265 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1266 public static bool return_true () {
1270 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1271 public static void exceptions2 () {
1273 throw new Exception ();
1274 Console.WriteLine ();
1277 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1278 public static void threads () {
1279 Thread t = new Thread (delegate () {});
1285 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1286 public static void domains () {
1287 AppDomain domain = AppDomain.CreateDomain ("domain");
1289 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
1290 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
1292 domains_print_across (o);
1294 domains_2 (o, new CrossDomain ());
1302 AppDomain.Unload (domain);
1306 typeof (Tests).GetMethod ("called_from_invoke").Invoke (null, null);
1309 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1310 public static void called_from_invoke () {
1313 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1314 public static void domains_2 (object o, object o2) {
1317 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1318 public static void domains_print_across (object o) {
1321 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1322 public static void domains_3 () {
1325 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1326 public static void invoke_in_domain () {
1329 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1330 public static void invoke_in_domain_2 () {
1333 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1334 public static void dynamic_methods () {
1335 var m = new DynamicMethod ("dyn_method", typeof (void), new Type [] { typeof (int) }, typeof (object).Module);
1336 var ig = m.GetILGenerator ();
1338 ig.Emit (OpCodes.Ldstr, "FOO");
1339 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
1340 ig.Emit (OpCodes.Ret);
1342 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
1347 public static void dyn_call (string s) {
1350 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1351 public static void ref_emit () {
1352 AssemblyName assemblyName = new AssemblyName ();
1353 assemblyName.Name = "foo";
1355 AssemblyBuilder assembly =
1356 Thread.GetDomain ().DefineDynamicAssembly (
1357 assemblyName, AssemblyBuilderAccess.RunAndSave);
1359 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
1361 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
1362 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
1363 ILGenerator ig = mb.GetILGenerator ();
1364 ig.Emit (OpCodes.Ldstr, "FOO");
1365 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
1366 ig.Emit (OpCodes.Ret);
1368 Type t = tb.CreateType ();
1370 t.GetMethod ("ref_emit_method").Invoke (null, null);
1373 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1374 public static void ref_emit_call (string s) {
1377 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1378 public static void frames_in_native () {
1380 var evt = new ManualResetEvent (false);
1382 object mon = new object ();
1383 ThreadPool.QueueUserWorkItem (delegate {
1384 frames_in_native_2 ();
1390 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1391 static void frames_in_native_2 () {
1392 frames_in_native_3 ();
1395 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1396 static void frames_in_native_3 () {
1399 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1400 public static void string_call (string s) {
1403 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1404 public static void ss_regress_654694 () {
1411 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1412 public static void user () {
1415 Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
1418 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1419 public static void type_load () {
1423 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1424 static void type_load_2 () {
1425 var c1 = new Dictionary<int, int> ();
1427 var c = new TypeLoadClass ();
1429 var c2 = new TypeLoadClass2 ();
1433 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1434 public static void regress () {
1435 regress_2755 (DateTime.Now);
1438 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1439 public static unsafe void regress_2755 (DateTime d) {
1440 int* buffer = stackalloc int [128];
1445 for (int i = 0; i < 128; ++i)
1448 regress_2755_3 (sum);
1451 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1452 public static void regress_2755_2 () {
1455 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1456 public static void regress_2755_3 (int sum) {
1459 static object gc_suspend_field;
1461 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1462 static unsafe void set_gc_suspend_field () {
1463 set_gc_suspend_field_2 ();
1465 int* buffer = stackalloc int [4096];
1468 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1469 static void set_gc_suspend_field_2 () {
1470 gc_suspend_field = new object ();
1473 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1474 static void gc_suspend_1 () {
1477 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1478 public static void gc_suspend_invoke () {
1479 gc_suspend_field = null;
1481 GC.WaitForPendingFinalizers ();
1484 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1485 public static void gc_suspend () {
1486 set_gc_suspend_field ();
1490 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1491 public static void generic_method<T> () where T : class {
1494 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1495 public void evaluate_method_2 () {
1498 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1499 public void evaluate_method () {
1501 evaluate_method_2 ();
1504 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1505 static void set_ip_1 () {
1508 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1509 static void set_ip_2 () {
1512 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1513 public static void set_ip () {
1524 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1525 public static void step_filters () {
1526 ClassWithCctor.cctor_filter ();
1529 class ClassWithCctor {
1530 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1531 static ClassWithCctor () {
1536 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1537 public static void cctor_filter () {
1541 public override string virtual_method () {
1546 class TypeLoadClass {
1549 class TypeLoadClass2 {
1552 public class SentinelClass : MarshalByRefObject {
1555 public class CrossDomain : MarshalByRefObject
1557 SentinelClass printMe = new SentinelClass ();
1559 public void invoke () {
1560 Tests.invoke_in_domain ();
1563 public void invoke_2 () {
1564 Tests.invoke_in_domain_2 ();
1567 public int invoke_3 () {
1574 public ProcessStartInfo info;
1577 // Class used for line number info testing, don't change its layout
1578 public class LineNumbers
1580 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1581 public static void ln1 () {
1587 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1588 public static void ln2 () {
1591 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1592 public static void ln3 () {
1593 #pragma warning disable 0219
1595 #pragma warning restore 0219
1600 class LocalReflectClass
1602 public static void RunMe ()
1604 var reflectMe = new someClass ();
1605 reflectMe.someMethod ();
1608 class someClass : ContextBoundObject
1610 public object someField;
1612 public void someMethod ()