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
32 public sealed class Tests3
{
33 public static void M1 () {
47 public static class Tests4
{
52 public class AAttribute
: Attribute
{
56 public class BAttribute
: AAttribute
{
60 [DebuggerDisplay ("Tests", Name
="FOO", Target
=typeof (int))]
61 [DebuggerTypeProxy (typeof (Tests
))]
62 [BAttribute (afield
= 1, bfield
= 2)]
64 [DebuggerBrowsableAttribute (DebuggerBrowsableState
.Collapsed
)]
66 public static int static_field_j
;
68 [DebuggerBrowsableAttribute (DebuggerBrowsableState
.Collapsed
)]
69 public int AProperty
{
75 public void invoke () {
79 public struct AStruct
{
86 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
87 public int foo (int val
) {
91 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
92 public static int static_foo (int val
) {
96 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
97 public int invoke_return_int () {
101 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
102 public static int invoke_static () {
106 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
107 public IntPtr
invoke_return_intptr () {
111 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
112 public void invoke_mutate () {
117 public class GClass
<T
> {
119 public static T static_field
;
121 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
125 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
126 public void bp
<T2
> () {
130 public struct GStruct
<T
> {
135 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
136 public int invoke_return_int () {
141 public struct NestedStruct
{
142 NestedInner nested1
, nested2
;
145 public struct NestedInner
{
148 public interface IRecStruct
{
152 struct RecStruct
: IRecStruct
{
155 public void foo (object o
) {
172 class TestIfaces
: ITest
180 TestIfaces
<int> Baz () {
185 class TestIfaces
<T
> : ITest
<T
>
187 void ITest
<T
>.Foo () {
190 void ITest
<T
>.Bar () {
194 public interface ITest2
199 public class Tests
: TestsBase
, ITest2
201 #pragma warning disable 0414
205 bool field_bool1
, field_bool2
;
218 static int static_i
= 55;
219 static string static_s
= "A";
220 public const int literal_i
= 56;
221 public const string literal_s
= "B";
223 public AStruct field_struct
;
224 public object field_boxed_struct
;
225 public GStruct
<int> generic_field_struct
;
226 public KeyValuePair
<int, object> boxed_struct_field
;
228 public static int tls_i
;
229 public static bool is_attached
= Debugger
.IsAttached
;
230 public NestedStruct nested_struct
;
232 #pragma warning restore 0414
234 public class NestedClass
{
237 public int IntProperty
{
246 public int ReadOnlyProperty
{
252 public int this [int index
] {
258 public static void wait_one ()
260 ManualResetEvent evt
= new ManualResetEvent (false);
264 public static int Main (String
[] args
) {
267 if (args
.Length
> 0 && args
[0] == "suspend-test")
268 /* This contains an infinite loop, so execute it conditionally */
270 if (args
.Length
>0 && args
[0] == "unhandled-exception") {
271 unhandled_exception ();
274 if (args
.Length
>0 && args
[0] == "unhandled-exception-endinvoke") {
275 unhandled_exception_endinvoke ();
278 if (args
.Length
>0 && args
[0] == "unhandled-exception-user") {
279 unhandled_exception_user ();
282 if (args
.Length
>0 && args
[0] == "wait-one") {
306 if (args
.Length
> 0 && args
[0] == "domain-test")
307 /* This takes a lot of time, so execute it conditionally */
309 if (args
.Length
> 0 && args
[0] == "ref-emit-test")
311 if (args
.Length
> 0 && args
[0] == "frames-in-native")
313 if (args
.Length
> 0 && args
[0] == "invoke-single-threaded")
314 new Tests ().invoke_single_threaded ();
315 new Tests ().evaluate_method ();
319 public static void breakpoints () {
320 /* Call these early so it is JITted by the time a breakpoint is placed on it */
332 bp6
<string> (new GClass
<int> ());
337 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
338 public static void bp1 () {
341 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
342 public static void bp2 () {
345 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
346 public static void bp3 () {
349 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
350 public static void bp4 () {
353 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
354 public static void bp5 () {
357 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
358 public static void bp6
<T
> (GClass
<int> gc
) {
362 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
363 public static void bp7
<T
> () {
366 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
367 public static void single_stepping () {
374 ss5 (new int [] { 1, 2, 3 }
, new Func
<int, bool> (is_even
));
381 ss_regress_654694 ();
388 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
389 public static void ss1 () {
392 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
393 public static void ss2 () {
396 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
397 public static int ss3 () {
400 for (int i
= 0; i
< 10; ++i
)
406 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
407 public static void ss3_2 () {
411 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
412 public static void ss3_2_2 () {
415 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
416 public static int ss4 () {
422 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
423 public static void ss5 (int[] arr
, Func
<int, bool> selector
) {
424 // Call into linq which calls back into this assembly
425 arr
.Count (selector
);
428 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
429 public static void ss6 (bool b
) {
432 throw new Exception ();
436 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
437 public static void ss6_2 () {
440 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
441 public static void ss7 () {
450 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
451 public static void ss7_2 () {
454 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
455 public static void ss7_3 () {
456 throw new Exception ();
459 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
460 public static void ss_nested () {
461 ss_nested_1 (ss_nested_2 ());
462 ss_nested_1 (ss_nested_2 ());
466 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
467 public static void ss_nested_1 (int i
) {
470 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
471 public static int ss_nested_2 () {
475 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
476 public static void ss_nested_3 () {
479 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
480 public static void ss_step_through () {
482 StepThroughClass
.step_through_2 ();
486 [DebuggerStepThrough
]
487 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
488 public static void step_through_1 () {
491 [DebuggerStepThrough
]
492 class StepThroughClass
{
493 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
494 public static void step_through_2 () {
498 [DebuggerStepThrough
]
499 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
500 public static void step_through_3 () {
503 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
504 public static void ss_non_user_code () {
506 StepNonUserCodeClass
.non_user_code_2 ();
510 [DebuggerNonUserCode
]
511 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
512 public static void non_user_code_1 () {
515 [DebuggerNonUserCode
]
516 class StepNonUserCodeClass
{
517 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
518 public static void non_user_code_2 () {
522 [DebuggerNonUserCode
]
523 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
524 public static void non_user_code_3 () {
527 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
528 public static void ss_recursive (int n
) {
531 ss_recursive (n
+ 1);
534 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
535 public static void ss_fp_clobber () {
536 double v
= ss_fp_clobber_1 (5.0);
540 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
541 public static double ss_fp_clobber_1 (double d
) {
545 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
546 public static void ss_fp_clobber_2 (double d
) {
549 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
550 public static bool is_even (int i
) {
556 Console.WriteLine ("HIT!");
562 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
563 public static void arguments () {
564 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));
566 arg2 ("FOO", null, "BLA", ref i
, new GClass
<int> { field = 42 }
, new object ());
567 Tests t
= new Tests () { field_i = 42, field_s = "S" }
;
571 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
572 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
) {
573 return (int)(sb
+ b
+ (bl
? 0 : 1) + s
+ us
+ (int)c
+ i
+ ui
+ l
+ (long)ul
+ f
+ d
+ (int)ip
+ (int)uip
);
576 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
577 public static string arg2 (string s
, string s3
, object o
, ref int i
, GClass
<int> gc
, object o2
) {
578 return s
+ (s3
!= null ? "" : "") + o
+ i
+ gc
.field
+ o2
;
581 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
582 public object arg3 (string s
) {
583 return s
+ s
+ s
+ s
+ this;
586 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
587 public static void objects () {
588 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 }
;
589 t
.o1 (new Tests2 () { field_j = 43 }
, new GClass
<int> { field = 42 }
, new GClass
<string> { field = "FOO" }
);
590 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 }
);
593 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
594 public object o1 (Tests2 t
, GClass
<int> gc1
, GClass
<string> gc2
) {
595 if (t
== null || gc1
== null || gc2
== null)
601 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
602 public static string o2 (string[] s2
, int[] s3
, int[,] s4
, int[,] s5
, IList
<int> s6
) {
603 return s2
[0] + s3
[0] + s4
[0, 0] + s6
[0];
606 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
607 public static void objrefs () {
608 Tests t
= new Tests () {};
616 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
617 public static void set_child (Tests t
) {
618 t
.child
= new Tests ();
621 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
622 public void objrefs1 () {
625 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
626 public static void objrefs2 () {
629 public static void vtypes () {
630 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 ) };
631 AStruct s
= new AStruct { i = 44, s = "T", k = 45 }
;
632 AStruct
[] arr
= new AStruct
[] {
633 new AStruct () { i = 1, s = "S1" }
,
634 new AStruct () { i = 2, s = "S2" }
};
641 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
642 public object vtypes1 (AStruct s
, AStruct
[] arr
) {
649 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
650 public static void vtypes2 (AStruct s
) {
654 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
655 public static void vtypes3 (AStruct s
) {
656 AStruct
.static_foo (5);
659 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
660 public static void vtypes4_2 (IRecStruct o
) {
663 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
664 public static void vtypes4 () {
665 IRecStruct s
= new RecStruct ();
670 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
671 public static void locals () {
673 var astruct
= new AStruct () { i = 42 }
;
675 locals2
<string> (null, 5, "ABC", ref s
, ref astruct
);
681 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
682 static void locals11 (double a
, ref double b
) {
685 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
686 public static void locals1 (string[] args
) {
690 locals11 (b
: ref ri
, a
: ri
);
692 for (int j
= 0; j
< 10; ++j
) {
697 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
699 [StateMachine (typeof (int))]
701 public static void locals2
<T
> (string[] args
, int arg
, T t
, ref string rs
, ref AStruct astruct
) {
705 for (int j
= 0; j
< 10; ++j
) {
710 astruct
= new AStruct ();
716 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
717 public static void locals3 () {
737 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
738 public static void locals4 () {
741 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
742 public static void locals5 () {
745 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
746 public static void locals6 () {
749 for (i
= 0; i
< 10; ++i
)
752 for (i
= 0; i
< 10; ++i
)
762 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
763 public static void locals6_1 () {
766 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
767 public static void locals6_2 (int arg
) {
770 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
771 public static void locals6_3 () {
772 // Clobber all registers
773 int sum
= 0, i
, j
, k
, l
, m
;
774 for (i
= 0; i
< 100; ++i
)
776 for (j
= 0; j
< 100; ++j
)
778 for (k
= 0; k
< 100; ++k
)
780 for (l
= 0; l
< 100; ++l
)
782 for (m
= 0; m
< 100; ++m
)
786 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
787 public static void locals6_4 (int arg
) {
790 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
791 public static void locals6_5 () {
794 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
795 public static void locals6_6 (int arg
) {
798 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
799 public static void locals7
<T
> (T arg
) {
804 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
805 public static void line_numbers () {
809 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
810 public static void suspend () {
818 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
819 public static void type_info () {
820 Tests t
= new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B }
;
821 t
.ti1 (new Tests2 () { field_j = 43 }
, new GClass
<int> { field = 42 }
, new GClass
<string> { field = "FOO" }
);
824 AStruct s
= new AStruct () { i = 42, s = "S", k = 43 }
;
826 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
);
830 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
831 public object ti1 (Tests2 t
, GClass
<int> gc1
, GClass
<string> gc2
) {
832 if (t
== null || gc1
== null || gc2
== null)
838 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
839 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
) {
840 return s2
[0] + s3
[0] + s4
[0, 0];
843 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
844 public static void assembly_load () {
848 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
849 public static void assembly_load_2 () {
850 // This will load System.dll while holding the loader lock
854 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
855 public static void invoke () {
856 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }
, new GStruct
<int> { j = 42 }
);
857 new Tests ().invoke_ex ();
860 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
861 public void invoke1 (Tests2 t
, AStruct s
, GStruct
<int> g
) {
865 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
866 public void invoke2 () {
869 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
870 public void invoke_ex () {
874 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
875 public void invoke_ex_inner () {
877 throw new Exception ();
884 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
885 public void invoke_single_threaded () {
886 // Spawn a thread incrementing a counter
887 bool finished
= false;
889 new Thread (delegate () {
896 invoke_single_threaded_2 ();
901 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
902 public void invoke_single_threaded_2 () {
905 public void invoke_return_void () {
908 public string invoke_return_ref () {
912 public object invoke_return_null () {
916 public int invoke_return_primitive () {
920 public int? invoke_return_nullable () {
924 public int? invoke_return_nullable_null () {
928 public void invoke_type_load () {
935 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
) {
936 return ub
+ sb
+ ss
+ us
+ i
+ ui
+ l
+ (long)ul
+ (int)c
+ (b
? 1 : 0) + (int)f
+ (int)d
;
939 public int invoke_pass_primitive2 (bool b
) {
943 public string invoke_pass_ref (string s
) {
947 public static string invoke_static_pass_ref (string s
) {
951 public static void invoke_static_return_void () {
954 public static void invoke_throws () {
955 throw new Exception ();
958 public int invoke_iface () {
962 public void invoke_out (out int foo
) {
966 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
967 public static void exceptions () {
969 throw new OverflowException ();
970 } catch (Exception
) {
973 throw new OverflowException ();
974 } catch (Exception
) {
977 throw new ArgumentException ();
978 } catch (Exception
) {
981 throw new OverflowException ();
982 } catch (Exception
) {
986 throw new OverflowException ();
987 } catch (Exception
) {
990 throw new Exception ();
991 } catch (Exception
) {
997 } catch (Exception
) {
1002 } catch (Exception
) {
1006 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1007 public static void unhandled_exception () {
1008 ThreadPool
.QueueUserWorkItem (delegate {
1009 throw new InvalidOperationException ();
1011 Thread
.Sleep (10000);
1014 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1015 public static void unhandled_exception_endinvoke_2 () {
1018 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1019 public static void unhandled_exception_endinvoke () {
1020 Action action
= new Action (() =>
1022 throw new Exception ("thrown");
1024 action
.BeginInvoke ((ar
) => {
1026 action
.EndInvoke (ar
);
1027 } catch (Exception ex
) {
1028 //Console.WriteLine (ex);
1031 Thread
.Sleep (1000);
1032 unhandled_exception_endinvoke_2 ();
1035 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1036 public static void unhandled_exception_user () {
1038 System
.Threading
.Tasks
.Task
.Factory
.StartNew (() => {
1041 Thread
.Sleep (10000);
1045 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1046 public static void Throw () {
1047 throw new Exception ();
1050 internal static Delegate
create_filter_delegate (Delegate dlg
, MethodInfo filter_method
)
1053 throw new ArgumentNullException ();
1054 if (dlg
.Target
!= null)
1055 throw new ArgumentException ();
1056 if (dlg
.Method
== null)
1057 throw new ArgumentException ();
1059 var ret_type
= dlg
.Method
.ReturnType
;
1060 var param_types
= dlg
.Method
.GetParameters ().Select (x
=> x
.ParameterType
).ToArray ();
1062 var dynamic = new DynamicMethod (Guid
.NewGuid ().ToString (), ret_type
, param_types
, typeof (object), true);
1063 var ig
= dynamic.GetILGenerator ();
1065 LocalBuilder retval
= null;
1066 if (ret_type
!= typeof (void))
1067 retval
= ig
.DeclareLocal (ret_type
);
1069 var label
= ig
.BeginExceptionBlock ();
1071 for (int i
= 0; i
< param_types
.Length
; i
++)
1072 ig
.Emit (OpCodes
.Ldarg
, i
);
1073 ig
.Emit (OpCodes
.Call
, dlg
.Method
);
1076 ig
.Emit (OpCodes
.Stloc
, retval
);
1078 ig
.Emit (OpCodes
.Leave
, label
);
1080 ig
.BeginExceptFilterBlock ();
1082 ig
.Emit (OpCodes
.Call
, filter_method
);
1084 ig
.BeginCatchBlock (null);
1086 ig
.Emit (OpCodes
.Pop
);
1088 ig
.EndExceptionBlock ();
1091 ig
.Emit (OpCodes
.Ldloc
, retval
);
1093 ig
.Emit (OpCodes
.Ret
);
1095 return dynamic.CreateDelegate (dlg
.GetType ());
1098 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1099 static void exception_filter_method () {
1100 throw new InvalidOperationException ();
1103 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1104 static int exception_filter_filter (Exception exc
) {
1108 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1109 public static void exception_filter () {
1110 var method
= typeof (Tests
).GetMethod (
1111 "exception_filter_method", BindingFlags
.NonPublic
| BindingFlags
.Static
);
1112 var filter_method
= typeof (Tests
).GetMethod (
1113 "exception_filter_filter", BindingFlags
.NonPublic
| BindingFlags
.Static
);
1115 var dlg
= Delegate
.CreateDelegate (typeof (Action
), method
);
1117 var wrapper
= (Action
) create_filter_delegate (dlg
, filter_method
);
1122 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1123 public static bool return_true () {
1127 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1128 public static void exceptions2 () {
1130 throw new Exception ();
1131 Console
.WriteLine ();
1134 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1135 public static void threads () {
1136 Thread t
= new Thread (delegate () {});
1142 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1143 public static void domains () {
1144 AppDomain domain
= AppDomain
.CreateDomain ("domain");
1146 CrossDomain o
= (CrossDomain
)domain
.CreateInstanceAndUnwrap (
1147 typeof (CrossDomain
).Assembly
.FullName
, "CrossDomain");
1149 domains_2 (o
, new CrossDomain ());
1157 AppDomain
.Unload (domain
);
1162 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1163 public static void domains_2 (object o
, object o2
) {
1166 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1167 public static void domains_3 () {
1170 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1171 public static void invoke_in_domain () {
1174 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1175 public static void invoke_in_domain_2 () {
1178 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1179 public static void dynamic_methods () {
1180 var m
= new DynamicMethod ("dyn_method", typeof (void), new Type
[] { typeof (int) }
, typeof (object).Module
);
1181 var ig
= m
.GetILGenerator ();
1183 ig
.Emit (OpCodes
.Ldstr
, "FOO");
1184 ig
.Emit (OpCodes
.Call
, typeof (Tests
).GetMethod ("dyn_call"));
1185 ig
.Emit (OpCodes
.Ret
);
1187 var del
= (Action
<int>)m
.CreateDelegate (typeof (Action
<int>));
1192 public static void dyn_call (string s
) {
1195 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1196 public static void ref_emit () {
1197 AssemblyName assemblyName
= new AssemblyName ();
1198 assemblyName
.Name
= "foo";
1200 AssemblyBuilder assembly
=
1201 Thread
.GetDomain ().DefineDynamicAssembly (
1202 assemblyName
, AssemblyBuilderAccess
.RunAndSave
);
1204 ModuleBuilder module
= assembly
.DefineDynamicModule ("foo.dll");
1206 TypeBuilder tb
= module
.DefineType ("foo", TypeAttributes
.Public
, typeof (object));
1207 MethodBuilder mb
= tb
.DefineMethod ("ref_emit_method", MethodAttributes
.Public
|MethodAttributes
.Static
, CallingConventions
.Standard
, typeof (void), new Type
[] { }
);
1208 ILGenerator ig
= mb
.GetILGenerator ();
1209 ig
.Emit (OpCodes
.Ldstr
, "FOO");
1210 ig
.Emit (OpCodes
.Call
, typeof (Tests
).GetMethod ("ref_emit_call"));
1211 ig
.Emit (OpCodes
.Ret
);
1213 Type t
= tb
.CreateType ();
1215 t
.GetMethod ("ref_emit_method").Invoke (null, null);
1218 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1219 public static void ref_emit_call (string s
) {
1222 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1223 public static void frames_in_native () {
1225 var evt
= new ManualResetEvent (false);
1227 object mon
= new object ();
1228 ThreadPool
.QueueUserWorkItem (delegate {
1229 frames_in_native_2 ();
1235 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1236 static void frames_in_native_2 () {
1237 frames_in_native_3 ();
1240 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1241 static void frames_in_native_3 () {
1244 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1245 public static void string_call (string s
) {
1248 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1249 public static void ss_regress_654694 () {
1256 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1257 public static void user () {
1260 Debugger
.Log (5, Debugger
.IsLogging () ? "A" : "", "B");
1263 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1264 public static void type_load () {
1268 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1269 static void type_load_2 () {
1270 var c1
= new Dictionary
<int, int> ();
1272 var c
= new TypeLoadClass ();
1274 var c2
= new TypeLoadClass2 ();
1278 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1279 public static void regress () {
1280 regress_2755 (DateTime
.Now
);
1283 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1284 public static unsafe void regress_2755 (DateTime d
) {
1285 int* buffer
= stackalloc int [128];
1290 for (int i
= 0; i
< 128; ++i
)
1293 regress_2755_3 (sum
);
1296 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1297 public static void regress_2755_2 () {
1300 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1301 public static void regress_2755_3 (int sum
) {
1304 static object gc_suspend_field
;
1306 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1307 static unsafe void set_gc_suspend_field () {
1308 set_gc_suspend_field_2 ();
1310 int* buffer
= stackalloc int [4096];
1313 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1314 static void set_gc_suspend_field_2 () {
1315 gc_suspend_field
= new object ();
1318 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1319 static void gc_suspend_1 () {
1322 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1323 public static void gc_suspend_invoke () {
1324 gc_suspend_field
= null;
1326 GC
.WaitForPendingFinalizers ();
1329 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1330 public static void gc_suspend () {
1331 set_gc_suspend_field ();
1335 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1336 public static void generic_method
<T
> () where T
: class {
1339 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1340 public void evaluate_method_2 () {
1343 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1344 public void evaluate_method () {
1346 evaluate_method_2 ();
1349 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1350 static void set_ip_1 () {
1353 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1354 static void set_ip_2 () {
1357 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1358 public static void set_ip () {
1369 class TypeLoadClass
{
1372 class TypeLoadClass2
{
1375 public class CrossDomain
: MarshalByRefObject
1377 public void invoke () {
1378 Tests
.invoke_in_domain ();
1381 public void invoke_2 () {
1382 Tests
.invoke_in_domain_2 ();
1385 public int invoke_3 () {
1392 public ProcessStartInfo info
;
1395 // Class used for line number info testing, don't change its layout
1396 public class LineNumbers
1398 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1399 public static void ln1 () {
1405 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1406 public static void ln2 () {
1409 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1410 public static void ln3 () {
1411 #pragma warning disable 0219
1413 #pragma warning restore 0219