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") {
343 if (args.Length > 0 && args [0] == "domain-test")
344 /* This takes a lot of time, so execute it conditionally */
346 if (args.Length > 0 && args [0] == "ref-emit-test")
348 if (args.Length > 0 && args [0] == "frames-in-native")
350 if (args.Length > 0 && args [0] == "invoke-single-threaded")
351 new Tests ().invoke_single_threaded ();
352 if (args.Length > 0 && args [0] == "invoke-abort")
353 new Tests ().invoke_abort ();
354 new Tests ().evaluate_method ();
358 public static void local_reflect () {
359 //Breakpoint line below, and reflect someField via ObjectMirror;
360 LocalReflectClass.RunMe ();
363 public static void breakpoints () {
364 /* Call these early so it is JITted by the time a breakpoint is placed on it */
376 bp6<string> (new GClass <int> ());
381 [MethodImplAttribute (MethodImplOptions.NoInlining)]
382 public static void bp1 () {
385 [MethodImplAttribute (MethodImplOptions.NoInlining)]
386 public static void bp2 () {
389 [MethodImplAttribute (MethodImplOptions.NoInlining)]
390 public static void bp3 () {
393 [MethodImplAttribute (MethodImplOptions.NoInlining)]
394 public static void bp4 () {
397 [MethodImplAttribute (MethodImplOptions.NoInlining)]
398 public static void bp5 () {
401 [MethodImplAttribute (MethodImplOptions.NoInlining)]
402 public static void bp6<T> (GClass<int> gc) {
406 [MethodImplAttribute (MethodImplOptions.NoInlining)]
407 public static void bp7<T> () {
410 [MethodImplAttribute (MethodImplOptions.NoInlining)]
411 public static void single_stepping () {
418 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
425 ss_regress_654694 ();
431 ss_recursive_chaotic ();
436 [MethodImplAttribute (MethodImplOptions.NoInlining)]
437 public static void ss1 () {
440 [MethodImplAttribute (MethodImplOptions.NoInlining)]
441 public static void ss2 () {
444 [MethodImplAttribute (MethodImplOptions.NoInlining)]
445 public static int ss3 () {
448 for (int i = 0; i < 10; ++i)
454 [MethodImplAttribute (MethodImplOptions.NoInlining)]
455 public static void ss3_2 () {
459 [MethodImplAttribute (MethodImplOptions.NoInlining)]
460 public static void ss3_2_2 () {
463 [MethodImplAttribute (MethodImplOptions.NoInlining)]
464 public static int ss4 () {
470 [MethodImplAttribute (MethodImplOptions.NoInlining)]
471 public static void ss5 (int[] arr, Func<int, bool> selector) {
472 // Call into linq which calls back into this assembly
473 arr.Count (selector);
476 [MethodImplAttribute (MethodImplOptions.NoInlining)]
477 public static void ss6 (bool b) {
480 throw new Exception ();
484 [MethodImplAttribute (MethodImplOptions.NoInlining)]
485 public static void ss6_2 () {
488 [MethodImplAttribute(MethodImplOptions.NoInlining)]
489 public static void ss7 ()
491 ss7_2();//Used to test stepout inside ss7_2, which may not go to catch
492 ss7_2();//Used to test stepout inside ss7_2_1, which must go to catch
493 ss7_2();//Used to test stepover inside ss7_2, which must go to catch
494 ss7_2();//Used to test stepover inside ss7_2_1, which must go to catch
495 ss7_3();//Used to test stepin inside ss7_3, which must go to catch
496 ss7_2();//Used to test stepin inside ss7_2_1, which must go to catch
499 [MethodImplAttribute(MethodImplOptions.NoInlining)]
500 public static void ss7_2_1 ()
502 throw new Exception ();
505 [MethodImplAttribute(MethodImplOptions.NoInlining)]
506 public static void ss7_2_2 ()
511 [MethodImplAttribute(MethodImplOptions.NoInlining)]
512 public static void ss7_2 ()
522 [MethodImplAttribute(MethodImplOptions.NoInlining)]
523 public static void ss7_3 ()
526 throw new Exception ();
533 [MethodImplAttribute (MethodImplOptions.NoInlining)]
534 public static void ss_nested () {
535 ss_nested_1 (ss_nested_2 ());
536 ss_nested_1 (ss_nested_2 ());
540 [MethodImplAttribute (MethodImplOptions.NoInlining)]
541 public static void ss_nested_1 (int i) {
544 [MethodImplAttribute (MethodImplOptions.NoInlining)]
545 public static int ss_nested_2 () {
549 [MethodImplAttribute (MethodImplOptions.NoInlining)]
550 public static void ss_nested_3 () {
553 [MethodImplAttribute (MethodImplOptions.NoInlining)]
554 public static void ss_step_through () {
556 StepThroughClass.step_through_2 ();
560 [DebuggerStepThrough]
561 [MethodImplAttribute (MethodImplOptions.NoInlining)]
562 public static void step_through_1 () {
565 [DebuggerStepThrough]
566 class StepThroughClass {
567 [MethodImplAttribute (MethodImplOptions.NoInlining)]
568 public static void step_through_2 () {
572 [DebuggerStepThrough]
573 [MethodImplAttribute (MethodImplOptions.NoInlining)]
574 public static void step_through_3 () {
577 [MethodImplAttribute (MethodImplOptions.NoInlining)]
578 public static void ss_non_user_code () {
580 StepNonUserCodeClass.non_user_code_2 ();
584 [DebuggerNonUserCode]
585 [MethodImplAttribute (MethodImplOptions.NoInlining)]
586 public static void non_user_code_1 () {
589 [DebuggerNonUserCode]
590 class StepNonUserCodeClass {
591 [MethodImplAttribute (MethodImplOptions.NoInlining)]
592 public static void non_user_code_2 () {
596 [DebuggerNonUserCode]
597 [MethodImplAttribute (MethodImplOptions.NoInlining)]
598 public static void non_user_code_3 () {
601 [MethodImplAttribute (MethodImplOptions.NoInlining)]
602 public static void ss_recursive (int n) {
605 ss_recursive (n + 1);
608 // Breakpoint will be placed here
609 [MethodImplAttribute (MethodImplOptions.NoInlining)]
610 public static void ss_recursive2_trap ()
614 public static void ss_recursive2_at (string s)
616 // Console.WriteLine (s);
619 // This method is used both for a step over and step out test.
620 [MethodImplAttribute (MethodImplOptions.NoInlining)]
621 public static void ss_recursive2 (int x)
623 ss_recursive2_at ( "ss_recursive2 in " + x);
626 ss_recursive2_at ("ss_recursive2 descend " + x);
627 ss_recursive2_trap ();
628 ss_recursive2 (next);
630 ss_recursive2_at ("ss_recursive2 out " + x);
633 // Breakpoint will be placed here
634 [MethodImplAttribute (MethodImplOptions.NoInlining)]
635 public static void ss_recursive_chaotic_trap ()
639 [MethodImplAttribute (MethodImplOptions.NoInlining)]
640 public static void ss_recursive_chaotic_at (bool exiting, string at, int n)
642 // string indent = "";
643 // for (int count = 5 - n; count > 0; count--)
645 // Console.WriteLine (indent + (exiting ? "<--" : "-->") + " " + at + " " + n);
648 [MethodImplAttribute (MethodImplOptions.NoInlining)]
649 public static void ss_recursive_chaotic_fizz (int n)
651 ss_recursive_chaotic_at (false, "fizz", n);
654 ss_recursive_chaotic_buzz (next);
655 ss_recursive_chaotic_fizzbuzz (next);
657 ss_recursive_chaotic_trap ();
659 ss_recursive_chaotic_at (true, "fizz", n);
662 [MethodImplAttribute (MethodImplOptions.NoInlining)]
663 public static void ss_recursive_chaotic_buzz (int n)
665 ss_recursive_chaotic_at (false, "buzz", n);
668 ss_recursive_chaotic_fizz (next);
669 ss_recursive_chaotic_fizzbuzz (next);
671 ss_recursive_chaotic_at (true, "buzz", n);
674 [MethodImplAttribute (MethodImplOptions.NoInlining)]
675 public static void ss_recursive_chaotic_fizzbuzz (int n)
677 ss_recursive_chaotic_at (false, "fizzbuzz", n);
680 ss_recursive_chaotic_fizz (next);
681 ss_recursive_chaotic_buzz (next);
682 ss_recursive_chaotic_fizzbuzz (next);
684 ss_recursive_chaotic_at (true, "fizzbuzz", n);
687 // Call a complex tree of recursive calls that has tripped up "step out" in the past.
688 [MethodImplAttribute (MethodImplOptions.NoInlining)]
689 public static void ss_recursive_chaotic ()
691 ss_recursive_chaotic_fizz (5);
694 [MethodImplAttribute (MethodImplOptions.NoInlining)]
695 public static void ss_fp_clobber () {
696 double v = ss_fp_clobber_1 (5.0);
700 [MethodImplAttribute (MethodImplOptions.NoInlining)]
701 public static double ss_fp_clobber_1 (double d) {
705 [MethodImplAttribute (MethodImplOptions.NoInlining)]
706 public static void ss_fp_clobber_2 (double d) {
709 [MethodImplAttribute (MethodImplOptions.NoInlining)]
710 public static void ss_no_frames () {
711 Action a = ss_no_frames_2;
712 var ar = a.BeginInvoke (null, null);
713 ar.AsyncWaitHandle.WaitOne ();
714 // Avoid waiting every time this runs
720 [MethodImplAttribute (MethodImplOptions.NoInlining)]
721 public static void ss_no_frames_2 () {
724 [MethodImplAttribute (MethodImplOptions.NoInlining)]
725 public static void ss_no_frames_3 () {
728 [MethodImplAttribute (MethodImplOptions.NoInlining)]
729 public static bool is_even (int i) {
735 Console.WriteLine ("HIT!");
741 [MethodImplAttribute (MethodImplOptions.NoInlining)]
742 public static void arguments () {
743 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));
745 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object (), '\0'.ToString () + "A");
746 Tests t = new Tests () { field_i = 42, field_s = "S" };
750 [MethodImplAttribute (MethodImplOptions.NoInlining)]
751 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) {
752 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
755 [MethodImplAttribute (MethodImplOptions.NoInlining)]
756 public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2, string s4) {
757 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
760 [MethodImplAttribute (MethodImplOptions.NoInlining)]
761 public object arg3 (string s) {
762 return s + s + s + s + this;
765 [MethodImplAttribute (MethodImplOptions.NoInlining)]
766 public static void objects () {
767 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 };
768 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
769 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 });
772 [MethodImplAttribute (MethodImplOptions.NoInlining)]
773 public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
774 if (t == null || gc1 == null || gc2 == null)
780 [MethodImplAttribute (MethodImplOptions.NoInlining)]
781 public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
782 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
785 [MethodImplAttribute (MethodImplOptions.NoInlining)]
786 public static void objrefs () {
787 Tests t = new Tests () {};
795 [MethodImplAttribute (MethodImplOptions.NoInlining)]
796 public static void set_child (Tests t) {
797 t.child = new Tests ();
800 [MethodImplAttribute (MethodImplOptions.NoInlining)]
801 public void objrefs1 () {
804 [MethodImplAttribute (MethodImplOptions.NoInlining)]
805 public static void objrefs2 () {
808 public static void vtypes () {
809 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 ) };
810 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
811 AStruct[] arr = new AStruct[] {
812 new AStruct () { i = 1, s = "S1" },
813 new AStruct () { i = 2, s = "S2" } };
814 TypedReference typedref = __makeref (s);
815 t.vtypes1 (s, arr, typedref);
821 [MethodImplAttribute (MethodImplOptions.NoInlining)]
822 public object vtypes1 (AStruct s, AStruct[] arr, TypedReference typedref) {
829 [MethodImplAttribute (MethodImplOptions.NoInlining)]
830 public static void vtypes2 (AStruct s) {
834 [MethodImplAttribute (MethodImplOptions.NoInlining)]
835 public static void vtypes3 (AStruct s) {
836 AStruct.static_foo (5);
839 [MethodImplAttribute (MethodImplOptions.NoInlining)]
840 public static void vtypes4_2 (IRecStruct o) {
843 [MethodImplAttribute (MethodImplOptions.NoInlining)]
844 public static void vtypes4 () {
845 IRecStruct s = new RecStruct ();
850 [MethodImplAttribute (MethodImplOptions.NoInlining)]
851 public static void locals () {
853 var astruct = new AStruct () { i = 42 };
855 locals2<string> (null, 5, "ABC", ref s, ref astruct);
861 [MethodImplAttribute (MethodImplOptions.NoInlining)]
862 static void locals11 (double a, ref double b) {
865 [MethodImplAttribute (MethodImplOptions.NoInlining)]
866 public static void locals1 (string[] args) {
870 locals11 (b: ref ri, a: ri);
872 for (int j = 0; j < 10; ++j) {
877 [MethodImplAttribute (MethodImplOptions.NoInlining)]
878 [StateMachine (typeof (int))]
879 public static void locals2<T> (string[] args, int arg, T t, ref string rs, ref AStruct astruct) {
883 for (int j = 0; j < 10; ++j) {
888 astruct = new AStruct ();
891 List<int> alist = new List<int> () { 12 };
895 [MethodImplAttribute (MethodImplOptions.NoInlining)]
896 public static void locals3 () {
916 [MethodImplAttribute (MethodImplOptions.NoInlining)]
917 public static void locals4 () {
920 [MethodImplAttribute (MethodImplOptions.NoInlining)]
921 public static void locals5 () {
924 [MethodImplAttribute (MethodImplOptions.NoInlining)]
925 public static void locals6 () {
928 for (i = 0; i < 10; ++i)
931 for (i = 0; i < 10; ++i)
941 [MethodImplAttribute (MethodImplOptions.NoInlining)]
942 public static void locals6_1 () {
945 [MethodImplAttribute (MethodImplOptions.NoInlining)]
946 public static void locals6_2 (int arg) {
949 [MethodImplAttribute (MethodImplOptions.NoInlining)]
950 public static void locals6_3 () {
951 // Clobber all registers
952 int sum = 0, i, j, k, l, m;
953 for (i = 0; i < 100; ++i)
955 for (j = 0; j < 100; ++j)
957 for (k = 0; k < 100; ++k)
959 for (l = 0; l < 100; ++l)
961 for (m = 0; m < 100; ++m)
965 [MethodImplAttribute (MethodImplOptions.NoInlining)]
966 public static void locals6_4 (int arg) {
969 [MethodImplAttribute (MethodImplOptions.NoInlining)]
970 public static void locals6_5 () {
973 [MethodImplAttribute (MethodImplOptions.NoInlining)]
974 public static void locals6_6 (int arg) {
977 [MethodImplAttribute (MethodImplOptions.NoInlining)]
978 public static void locals7<T> (T arg) {
983 [MethodImplAttribute (MethodImplOptions.NoInlining)]
984 public static void line_numbers () {
988 [MethodImplAttribute (MethodImplOptions.NoInlining)]
989 public static void suspend () {
997 struct TypedRefTest {
1001 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1002 public static void type_info () {
1003 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
1004 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
1007 AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
1008 TypedRefTest reftest = new TypedRefTest () { MaxValue = 12 };
1009 TypedReference typedref = __makeref (reftest);
1010 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);
1014 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1015 public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
1016 if (t == null || gc1 == null || gc2 == null)
1022 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1023 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) {
1024 return s2 [0] + s3 [0] + s4 [0, 0];
1027 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1028 public static void assembly_load () {
1032 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1033 public static void assembly_load_2 () {
1034 // This will load System.dll while holding the loader lock
1038 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1039 public static void invoke () {
1040 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }, new GStruct<int> { j = 42 });
1041 new Tests ().invoke_ex ();
1044 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1045 public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
1049 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1050 public void invoke2 () {
1053 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1054 public void invoke_ex () {
1058 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1059 public void invoke_ex_inner () {
1061 throw new Exception ();
1068 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1069 public void invoke_single_threaded () {
1070 // Spawn a thread incrementing a counter
1071 bool finished = false;
1073 new Thread (delegate () {
1080 invoke_single_threaded_2 ();
1085 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1086 public void invoke_single_threaded_2 () {
1089 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1090 public void invoke_abort () {
1093 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1094 public void invoke_abort_2 () {
1095 Thread.Sleep (1000000);
1098 public void invoke_return_void () {
1101 public string invoke_return_ref () {
1105 public object invoke_return_null () {
1109 public int invoke_return_primitive () {
1113 public int? invoke_return_nullable () {
1117 public int? invoke_return_nullable_null () {
1121 public void invoke_type_load () {
1128 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) {
1129 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
1132 public int invoke_pass_primitive2 (bool b) {
1136 public string invoke_pass_ref (string s) {
1140 public static string invoke_static_pass_ref (string s) {
1144 public static void invoke_static_return_void () {
1147 public static void invoke_throws () {
1148 throw new Exception ();
1151 public int invoke_iface () {
1155 public void invoke_out (out int foo, out int[] arr) {
1160 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1161 public static void exceptions () {
1163 throw new OverflowException ();
1164 } catch (Exception) {
1167 throw new OverflowException ();
1168 } catch (Exception) {
1171 throw new ArgumentException ();
1172 } catch (Exception) {
1175 throw new OverflowException ();
1176 } catch (Exception) {
1180 throw new OverflowException ();
1181 } catch (Exception) {
1184 throw new Exception ();
1185 } catch (Exception) {
1191 } catch (Exception) {
1196 } catch (Exception) {
1200 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1201 public static void unhandled_exception () {
1202 ThreadPool.QueueUserWorkItem (delegate {
1203 throw new InvalidOperationException ();
1205 Thread.Sleep (10000);
1208 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1209 public static void unhandled_exception_endinvoke_2 () {
1212 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1213 public static void unhandled_exception_endinvoke () {
1214 Action action = new Action (() =>
1216 throw new Exception ("thrown");
1218 action.BeginInvoke ((ar) => {
1220 action.EndInvoke (ar);
1221 } catch (Exception ex) {
1222 //Console.WriteLine (ex);
1225 Thread.Sleep (1000);
1226 unhandled_exception_endinvoke_2 ();
1229 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1230 public static void unhandled_exception_user () {
1231 System.Threading.Tasks.Task.Factory.StartNew (() => {
1234 Thread.Sleep (10000);
1237 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1238 public static void Throw () {
1239 throw new Exception ();
1242 internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
1245 throw new ArgumentNullException ();
1246 if (dlg.Target != null)
1247 throw new ArgumentException ();
1248 if (dlg.Method == null)
1249 throw new ArgumentException ();
1251 var ret_type = dlg.Method.ReturnType;
1252 var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();
1254 var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
1255 var ig = dynamic.GetILGenerator ();
1257 LocalBuilder retval = null;
1258 if (ret_type != typeof (void))
1259 retval = ig.DeclareLocal (ret_type);
1261 var label = ig.BeginExceptionBlock ();
1263 for (int i = 0; i < param_types.Length; i++)
1264 ig.Emit (OpCodes.Ldarg, i);
1265 ig.Emit (OpCodes.Call, dlg.Method);
1268 ig.Emit (OpCodes.Stloc, retval);
1270 ig.Emit (OpCodes.Leave, label);
1272 ig.BeginExceptFilterBlock ();
1274 ig.Emit (OpCodes.Call, filter_method);
1276 ig.BeginCatchBlock (null);
1278 ig.Emit (OpCodes.Pop);
1280 ig.EndExceptionBlock ();
1283 ig.Emit (OpCodes.Ldloc, retval);
1285 ig.Emit (OpCodes.Ret);
1287 return dynamic.CreateDelegate (dlg.GetType ());
1290 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1291 static void exception_filter_method () {
1292 throw new InvalidOperationException ();
1295 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1296 static int exception_filter_filter (Exception exc) {
1300 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1301 public static void exception_filter () {
1302 var method = typeof (Tests).GetMethod (
1303 "exception_filter_method", BindingFlags.NonPublic | BindingFlags.Static);
1304 var filter_method = typeof (Tests).GetMethod (
1305 "exception_filter_filter", BindingFlags.NonPublic | BindingFlags.Static);
1307 var dlg = Delegate.CreateDelegate (typeof (Action), method);
1309 var wrapper = (Action) create_filter_delegate (dlg, filter_method);
1314 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1315 public static bool return_true () {
1319 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1320 public static void exceptions2 () {
1322 throw new Exception ();
1323 Console.WriteLine ();
1326 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1327 public static void threads () {
1328 Thread t = new Thread (delegate () {});
1334 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1335 public static void domains () {
1336 AppDomain domain = AppDomain.CreateDomain ("domain");
1338 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
1339 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
1341 domains_print_across (o);
1343 domains_2 (o, new CrossDomain ());
1353 AppDomain.Unload (domain);
1357 typeof (Tests).GetMethod ("called_from_invoke").Invoke (null, null);
1360 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1361 public static void called_from_invoke () {
1364 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1365 public static void domains_2 (object o, object o2) {
1368 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1369 public static void domains_print_across (object o) {
1372 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1373 public static void domains_3 () {
1376 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1377 public static void invoke_in_domain () {
1380 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1381 public static void invoke_in_domain_2 () {
1384 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1385 public static void assembly_load_in_domain () {
1386 Assembly.Load ("System.Transactions");
1389 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1390 public static void dynamic_methods () {
1391 var m = new DynamicMethod ("dyn_method", typeof (void), new Type [] { typeof (int) }, typeof (object).Module);
1392 var ig = m.GetILGenerator ();
1394 ig.Emit (OpCodes.Ldstr, "FOO");
1395 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
1396 ig.Emit (OpCodes.Ret);
1398 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
1403 public static void dyn_call (string s) {
1406 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1407 public static void ref_emit () {
1408 AssemblyName assemblyName = new AssemblyName ();
1409 assemblyName.Name = "foo";
1411 AssemblyBuilder assembly =
1412 Thread.GetDomain ().DefineDynamicAssembly (
1413 assemblyName, AssemblyBuilderAccess.RunAndSave);
1415 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
1417 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
1418 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
1419 ILGenerator ig = mb.GetILGenerator ();
1420 ig.Emit (OpCodes.Ldstr, "FOO");
1421 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
1422 ig.Emit (OpCodes.Ret);
1424 Type t = tb.CreateType ();
1426 t.GetMethod ("ref_emit_method").Invoke (null, null);
1429 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1430 public static void ref_emit_call (string s) {
1433 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1434 public static void frames_in_native () {
1436 var evt = new ManualResetEvent (false);
1438 object mon = new object ();
1439 ThreadPool.QueueUserWorkItem (delegate {
1440 frames_in_native_2 ();
1446 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1447 static void frames_in_native_2 () {
1448 frames_in_native_3 ();
1451 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1452 static void frames_in_native_3 () {
1455 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1456 public static void string_call (string s) {
1459 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1460 public static void ss_regress_654694 () {
1467 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1468 public static void user () {
1471 Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
1474 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1475 public static void type_load () {
1479 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1480 static void type_load_2 () {
1481 var c1 = new Dictionary<int, int> ();
1483 var c = new TypeLoadClass ();
1485 var c2 = new TypeLoadClass2 ();
1489 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1490 public static void regress () {
1491 regress_2755 (DateTime.Now);
1494 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1495 public static unsafe void regress_2755 (DateTime d) {
1496 int* buffer = stackalloc int [128];
1501 for (int i = 0; i < 128; ++i)
1504 regress_2755_3 (sum);
1507 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1508 public static void regress_2755_2 () {
1511 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1512 public static void regress_2755_3 (int sum) {
1515 static object gc_suspend_field;
1517 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1518 static unsafe void set_gc_suspend_field () {
1519 set_gc_suspend_field_2 ();
1521 int* buffer = stackalloc int [4096];
1524 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1525 static void set_gc_suspend_field_2 () {
1526 gc_suspend_field = new object ();
1529 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1530 static void gc_suspend_1 () {
1533 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1534 public static void gc_suspend_invoke () {
1535 gc_suspend_field = null;
1537 GC.WaitForPendingFinalizers ();
1540 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1541 public static void gc_suspend () {
1542 set_gc_suspend_field ();
1546 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1547 public static void generic_method<T> () where T : class {
1550 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1551 public void evaluate_method_2 () {
1554 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1555 public void evaluate_method () {
1557 evaluate_method_2 ();
1560 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1561 static void set_ip_1 () {
1564 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1565 static void set_ip_2 () {
1568 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1569 public static void set_ip () {
1580 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1581 public static void step_filters () {
1582 ClassWithCctor.cctor_filter ();
1585 class ClassWithCctor {
1586 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1587 static ClassWithCctor () {
1592 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1593 public static void cctor_filter () {
1597 public override string virtual_method () {
1601 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1602 public static void threadpool_bp () { }
1604 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1605 public static void threadpool_io () {
1606 // Start a threadpool task that blocks on I/O.
1607 // Regression test for #42625
1608 const int nbytes = 16;
1609 var bsOut = new byte[nbytes];
1610 for (int i = 0; i < nbytes; i++) {
1613 var endPoint = NetworkHelpers.LocalEphemeralEndPoint ();
1614 var l = new TcpListener (endPoint);
1616 Task<byte[]> t = Task.Run (async () => {
1617 var c = new TcpClient ();
1618 await c.ConnectAsync (endPoint.Address, endPoint.Port);
1619 var streamIn = c.GetStream ();
1620 var bs = new byte[nbytes];
1622 int nremain = nbytes;
1623 while (nread < nbytes) {
1624 int r = await streamIn.ReadAsync (bs, nread, nremain);
1631 var s = l.AcceptTcpClient ();
1633 // write bytes in two groups so that the task blocks on the ReadAsync
1634 var streamOut = s.GetStream ();
1635 var nbytesFirst = nbytes / 2;
1636 var nbytesRest = nbytes - nbytesFirst;
1637 streamOut.Write (bsOut, 0, nbytesFirst);
1639 streamOut.Write (bsOut, nbytesFirst, nbytesRest);
1641 var bsIn = t.Result;
1645 public class SentinelClass : MarshalByRefObject {
1648 public class CrossDomain : MarshalByRefObject
1650 SentinelClass printMe = new SentinelClass ();
1652 public void invoke () {
1653 Tests.invoke_in_domain ();
1656 public void invoke_2 () {
1657 Tests.invoke_in_domain_2 ();
1660 public int invoke_3 () {
1664 public void assembly_load () {
1665 Tests.assembly_load_in_domain ();
1671 public ProcessStartInfo info;
1674 class LocalReflectClass
1676 public static void RunMe ()
1678 var reflectMe = new someClass ();
1679 var temp = reflectMe; // Breakpoint location
1680 reflectMe.someMethod ();
1683 class someClass : ContextBoundObject
1685 public object someField;
1687 public void someMethod ()
1693 // Class used for line number info testing, don't change its layout
1694 public class LineNumbers
1696 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1697 public static void ln1 () {
1703 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1704 public static void ln2 () {
1707 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1708 public static void ln3 () {
1709 #pragma warning disable 0219
1711 #pragma warning restore 0219