[sdb] Add support for out arguments in invokes.
[mono-project.git] / mcs / class / Mono.Debugger.Soft / Test / dtest-app.cs
blob06c7830a0f558fe13f0abc6b45fa2fa41b1943b5
1 /*
2 * dtest-app.cs:
4 * Application program used by the debugger tests.
5 */
6 using System;
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;
13 using System.Linq;
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
27 public enum AnEnum {
28 A = 0,
29 B= 1
32 public sealed class Tests3 {
33 public static void M1 () {
36 static void M2 () {
39 public void M3 () {
42 void M4 () {
47 public static class Tests4 {
48 static Tests4 () {
52 public class AAttribute : Attribute {
53 public int afield;
56 public class BAttribute : AAttribute {
57 public int bfield;
60 [DebuggerDisplay ("Tests", Name="FOO", Target=typeof (int))]
61 [DebuggerTypeProxy (typeof (Tests))]
62 [BAttribute (afield = 1, bfield = 2)]
63 public class Tests2 {
64 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
65 public int field_j;
66 public static int static_field_j;
68 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
69 public int AProperty {
70 get {
71 return 0;
75 public void invoke () {
79 public struct AStruct {
80 public int i;
81 public string s;
82 public byte k;
83 public IntPtr j;
84 public int l;
86 [MethodImplAttribute (MethodImplOptions.NoInlining)]
87 public int foo (int val) {
88 return val;
91 [MethodImplAttribute (MethodImplOptions.NoInlining)]
92 public static int static_foo (int val) {
93 return val;
96 [MethodImplAttribute (MethodImplOptions.NoInlining)]
97 public int invoke_return_int () {
98 return i;
101 [MethodImplAttribute (MethodImplOptions.NoInlining)]
102 public static int invoke_static () {
103 return 5;
106 [MethodImplAttribute (MethodImplOptions.NoInlining)]
107 public IntPtr invoke_return_intptr () {
108 return j;
111 [MethodImplAttribute (MethodImplOptions.NoInlining)]
112 public void invoke_mutate () {
113 l = 5;
117 public class GClass<T> {
118 public T field;
119 public static T static_field;
121 [MethodImplAttribute (MethodImplOptions.NoInlining)]
122 public GClass () {
125 [MethodImplAttribute (MethodImplOptions.NoInlining)]
126 public void bp<T2> () {
130 public struct GStruct<T> {
131 public T i;
133 public int j;
135 [MethodImplAttribute (MethodImplOptions.NoInlining)]
136 public int invoke_return_int () {
137 return j;
141 public struct NestedStruct {
142 NestedInner nested1, nested2;
145 public struct NestedInner {
148 public interface IRecStruct {
149 void foo (object o);
152 struct RecStruct : IRecStruct {
153 public object o;
155 public void foo (object o) {
156 this.o = o;
160 interface ITest
162 void Foo ();
163 void Bar ();
166 interface ITest<T>
168 void Foo ();
169 void Bar ();
172 class TestIfaces : ITest
174 void ITest.Foo () {
177 void ITest.Bar () {
180 TestIfaces<int> Baz () {
181 return null;
185 class TestIfaces<T> : ITest<T>
187 void ITest<T>.Foo () {
190 void ITest<T>.Bar () {
194 public interface ITest2
196 int invoke_iface ();
199 public class Tests : TestsBase, ITest2
201 #pragma warning disable 0414
202 int field_i;
203 string field_s;
204 AnEnum field_enum;
205 bool field_bool1, field_bool2;
206 char field_char;
207 byte field_byte;
208 sbyte field_sbyte;
209 short field_short;
210 ushort field_ushort;
211 long field_long;
212 ulong field_ulong;
213 float field_float;
214 double field_double;
215 Thread field_class;
216 IntPtr field_intptr;
217 int? field_nullable;
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";
222 public object child;
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;
227 [ThreadStatic]
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 {
238 get {
239 return field_i;
241 set {
242 field_i = value;
246 public int ReadOnlyProperty {
247 get {
248 return field_i;
252 public int this [int index] {
253 get {
254 return field_i;
258 public static void wait_one ()
260 ManualResetEvent evt = new ManualResetEvent (false);
261 evt.WaitOne ();
264 public static int Main (String[] args) {
265 tls_i = 42;
267 if (args.Length > 0 && args [0] == "suspend-test")
268 /* This contains an infinite loop, so execute it conditionally */
269 suspend ();
270 if (args.Length >0 && args [0] == "unhandled-exception") {
271 unhandled_exception ();
272 return 0;
274 if (args.Length >0 && args [0] == "unhandled-exception-endinvoke") {
275 unhandled_exception_endinvoke ();
276 return 0;
278 if (args.Length >0 && args [0] == "unhandled-exception-user") {
279 unhandled_exception_user ();
280 return 0;
282 if (args.Length >0 && args [0] == "wait-one") {
283 wait_one ();
284 return 0;
286 breakpoints ();
287 single_stepping ();
288 arguments ();
289 objects ();
290 objrefs ();
291 vtypes ();
292 locals ();
293 line_numbers ();
294 type_info ();
295 assembly_load ();
296 invoke ();
297 exceptions ();
298 exception_filter ();
299 threads ();
300 dynamic_methods ();
301 user ();
302 type_load ();
303 regress ();
304 gc_suspend ();
305 set_ip ();
306 if (args.Length > 0 && args [0] == "domain-test")
307 /* This takes a lot of time, so execute it conditionally */
308 domains ();
309 if (args.Length > 0 && args [0] == "ref-emit-test")
310 ref_emit ();
311 if (args.Length > 0 && args [0] == "frames-in-native")
312 frames_in_native ();
313 if (args.Length > 0 && args [0] == "invoke-single-threaded")
314 new Tests ().invoke_single_threaded ();
315 new Tests ().evaluate_method ();
316 return 3;
319 public static void breakpoints () {
320 /* Call these early so it is JITted by the time a breakpoint is placed on it */
321 bp3 ();
322 bp7<int> ();
323 bp7<string> ();
325 bp1 ();
326 bp2 ();
327 bp3 ();
328 bp4 ();
329 bp4 ();
330 bp4 ();
331 bp5 ();
332 bp6<string> (new GClass <int> ());
333 bp7<int> ();
334 bp7<string> ();
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) {
359 gc.bp<int> ();
362 [MethodImplAttribute (MethodImplOptions.NoInlining)]
363 public static void bp7<T> () {
366 [MethodImplAttribute (MethodImplOptions.NoInlining)]
367 public static void single_stepping () {
368 bool b = true;
369 ss1 ();
370 ss2 ();
371 ss3 ();
372 ss3_2 ();
373 ss4 ();
374 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
375 try {
376 ss6 (b);
377 } catch {
379 ss7 ();
380 ss_nested ();
381 ss_regress_654694 ();
382 ss_step_through ();
383 ss_non_user_code ();
384 ss_recursive (1);
385 ss_fp_clobber ();
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 () {
398 int sum = 0;
400 for (int i = 0; i < 10; ++i)
401 sum += i;
403 return sum;
406 [MethodImplAttribute (MethodImplOptions.NoInlining)]
407 public static void ss3_2 () {
408 ss3_2_2 ();
411 [MethodImplAttribute (MethodImplOptions.NoInlining)]
412 public static void ss3_2_2 () {
415 [MethodImplAttribute (MethodImplOptions.NoInlining)]
416 public static int ss4 () {
417 ss1 (); ss1 ();
418 ss2 ();
419 return 0;
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) {
430 if (b) {
431 ss6_2 ();
432 throw new Exception ();
436 [MethodImplAttribute (MethodImplOptions.NoInlining)]
437 public static void ss6_2 () {
440 [MethodImplAttribute (MethodImplOptions.NoInlining)]
441 public static void ss7 () {
442 try {
443 ss7_2 ();
444 ss7_3 ();
445 } catch {
447 ss7_2 ();
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 ());
463 ss_nested_3 ();
466 [MethodImplAttribute (MethodImplOptions.NoInlining)]
467 public static void ss_nested_1 (int i) {
470 [MethodImplAttribute (MethodImplOptions.NoInlining)]
471 public static int ss_nested_2 () {
472 return 0;
475 [MethodImplAttribute (MethodImplOptions.NoInlining)]
476 public static void ss_nested_3 () {
479 [MethodImplAttribute (MethodImplOptions.NoInlining)]
480 public static void ss_step_through () {
481 step_through_1 ();
482 StepThroughClass.step_through_2 ();
483 step_through_3 ();
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 () {
505 non_user_code_1 ();
506 StepNonUserCodeClass.non_user_code_2 ();
507 non_user_code_3 ();
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) {
529 if (n == 10)
530 return;
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);
537 ss_fp_clobber_2 (v);
540 [MethodImplAttribute (MethodImplOptions.NoInlining)]
541 public static double ss_fp_clobber_1 (double d) {
542 return d + 2.0;
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) {
551 return i % 2 == 0;
555 lock (static_s) {
556 Console.WriteLine ("HIT!");
558 return 0;
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));
565 int i = 42;
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" };
568 t.arg3 ("BLA");
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)
596 return null;
597 else
598 return this;
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 () {};
609 set_child (t);
610 t.objrefs1 ();
611 t.child = null;
612 GC.Collect ();
613 objrefs2 ();
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" } };
635 t.vtypes1 (s, arr);
636 vtypes2 (s);
637 vtypes3 (s);
638 vtypes4 ();
641 [MethodImplAttribute (MethodImplOptions.NoInlining)]
642 public object vtypes1 (AStruct s, AStruct[] arr) {
643 if (arr != null)
644 return this;
645 else
646 return null;
649 [MethodImplAttribute (MethodImplOptions.NoInlining)]
650 public static void vtypes2 (AStruct s) {
651 s.foo (5);
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 ();
666 s.foo (s);
667 vtypes4_2 (s);
670 [MethodImplAttribute (MethodImplOptions.NoInlining)]
671 public static void locals () {
672 string s = null;
673 var astruct = new AStruct () { i = 42 };
674 locals1 (null);
675 locals2<string> (null, 5, "ABC", ref s, ref astruct);
676 locals3 ();
677 locals6 ();
678 locals7<int> (22);
681 [MethodImplAttribute (MethodImplOptions.NoInlining)]
682 static void locals11 (double a, ref double b) {
685 [MethodImplAttribute (MethodImplOptions.NoInlining)]
686 public static void locals1 (string[] args) {
687 long foo = 42;
689 double ri = 1;
690 locals11 (b: ref ri, a: ri);
692 for (int j = 0; j < 10; ++j) {
693 foo ++;
697 [MethodImplAttribute (MethodImplOptions.NoInlining)]
698 #if NET_4_5
699 [StateMachine (typeof (int))]
700 #endif
701 public static void locals2<T> (string[] args, int arg, T t, ref string rs, ref AStruct astruct) {
702 long i = 42;
703 string s = "AB";
705 for (int j = 0; j < 10; ++j) {
706 if (s != null)
707 i ++;
708 if (t != null)
709 i ++;
710 astruct = new AStruct ();
712 rs = "A";
716 [MethodImplAttribute (MethodImplOptions.NoInlining)]
717 public static void locals3 () {
718 string s = "B";
719 s.ToString ();
722 long i = 42;
723 i ++;
724 locals4 ();
727 string i = "A";
728 i.ToString ();
729 locals5 ();
732 long j = 42;
733 j ++;
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 () {
747 int i = 0;
748 int j = 0;
749 for (i = 0; i < 10; ++i)
750 j ++;
751 sbyte sb = 0;
752 for (i = 0; i < 10; ++i)
753 sb ++;
754 locals6_1 ();
755 locals6_2 (j);
756 locals6_3 ();
757 locals6_4 (j);
758 locals6_5 ();
759 locals6_6 (sb);
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)
775 sum ++;
776 for (j = 0; j < 100; ++j)
777 sum ++;
778 for (k = 0; k < 100; ++k)
779 sum ++;
780 for (l = 0; l < 100; ++l)
781 sum ++;
782 for (m = 0; m < 100; ++m)
783 sum ++;
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) {
800 T t = arg;
801 T t2 = t;
804 [MethodImplAttribute (MethodImplOptions.NoInlining)]
805 public static void line_numbers () {
806 LineNumbers.ln1 ();
809 [MethodImplAttribute (MethodImplOptions.NoInlining)]
810 public static void suspend () {
811 long i = 5;
813 while (true) {
814 i ++;
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" });
822 int val = 0;
823 unsafe {
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)
833 return null;
834 else
835 return this;
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 () {
845 assembly_load_2 ();
848 [MethodImplAttribute (MethodImplOptions.NoInlining)]
849 public static void assembly_load_2 () {
850 // This will load System.dll while holding the loader lock
851 new Foo ();
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) {
862 invoke2 ();
865 [MethodImplAttribute (MethodImplOptions.NoInlining)]
866 public void invoke2 () {
869 [MethodImplAttribute (MethodImplOptions.NoInlining)]
870 public void invoke_ex () {
871 invoke_ex_inner ();
874 [MethodImplAttribute (MethodImplOptions.NoInlining)]
875 public void invoke_ex_inner () {
876 try {
877 throw new Exception ();
878 } catch {
882 int counter;
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 () {
890 while (!finished)
891 counter ++;
892 }).Start ();
894 Thread.Sleep (100);
896 invoke_single_threaded_2 ();
898 finished = true;
901 [MethodImplAttribute (MethodImplOptions.NoInlining)]
902 public void invoke_single_threaded_2 () {
905 public void invoke_return_void () {
908 public string invoke_return_ref () {
909 return "ABC";
912 public object invoke_return_null () {
913 return null;
916 public int invoke_return_primitive () {
917 return 42;
920 public int? invoke_return_nullable () {
921 return 42;
924 public int? invoke_return_nullable_null () {
925 return null;
928 public void invoke_type_load () {
929 new Class3 ();
932 class Class3 {
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) {
940 return b ? 1 : 0;
943 public string invoke_pass_ref (string s) {
944 return s;
947 public static string invoke_static_pass_ref (string s) {
948 return s;
951 public static void invoke_static_return_void () {
954 public static void invoke_throws () {
955 throw new Exception ();
958 public int invoke_iface () {
959 return 42;
962 public void invoke_out (out int foo) {
963 foo = 5;
966 [MethodImplAttribute (MethodImplOptions.NoInlining)]
967 public static void exceptions () {
968 try {
969 throw new OverflowException ();
970 } catch (Exception) {
972 try {
973 throw new OverflowException ();
974 } catch (Exception) {
976 try {
977 throw new ArgumentException ();
978 } catch (Exception) {
980 try {
981 throw new OverflowException ();
982 } catch (Exception) {
984 // no subclasses
985 try {
986 throw new OverflowException ();
987 } catch (Exception) {
989 try {
990 throw new Exception ();
991 } catch (Exception) {
994 object o = null;
995 try {
996 o.GetType ();
997 } catch (Exception) {
1000 try {
1001 exceptions2 ();
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) => {
1025 try {
1026 action.EndInvoke (ar);
1027 } catch (Exception ex) {
1028 //Console.WriteLine (ex);
1030 }, null);
1031 Thread.Sleep (1000);
1032 unhandled_exception_endinvoke_2 ();
1035 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1036 public static void unhandled_exception_user () {
1037 #if NET_4_5
1038 System.Threading.Tasks.Task.Factory.StartNew (() => {
1039 Throw ();
1041 Thread.Sleep (10000);
1042 #endif
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)
1052 if (dlg == null)
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);
1075 if (retval != null)
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 ();
1090 if (retval != null)
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) {
1105 return 1;
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);
1119 wrapper ();
1122 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1123 public static bool return_true () {
1124 return true;
1127 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1128 public static void exceptions2 () {
1129 if (return_true ())
1130 throw new Exception ();
1131 Console.WriteLine ();
1134 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1135 public static void threads () {
1136 Thread t = new Thread (delegate () {});
1138 t.Start ();
1139 t.Join ();
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 ());
1151 o.invoke_2 ();
1153 o.invoke ();
1155 o.invoke_2 ();
1157 AppDomain.Unload (domain);
1159 domains_3 ();
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>));
1189 del (0);
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 () {
1224 Thread.Sleep (500);
1225 var evt = new ManualResetEvent (false);
1227 object mon = new object ();
1228 ThreadPool.QueueUserWorkItem (delegate {
1229 frames_in_native_2 ();
1230 evt.Set ();
1232 evt.WaitOne ();
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 () {
1250 if (true) {
1251 string h = "hi";
1252 string_call (h);
1256 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1257 public static void user () {
1258 Debugger.Break ();
1260 Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
1263 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1264 public static void type_load () {
1265 type_load_2 ();
1268 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1269 static void type_load_2 () {
1270 var c1 = new Dictionary<int, int> ();
1271 c1.ToString ();
1272 var c = new TypeLoadClass ();
1273 c.ToString ();
1274 var c2 = new TypeLoadClass2 ();
1275 c2.ToString ();
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];
1287 regress_2755_2 ();
1289 int sum = 0;
1290 for (int i = 0; i < 128; ++i)
1291 sum += buffer [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 ();
1309 // Clear stack
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;
1325 GC.Collect ();
1326 GC.WaitForPendingFinalizers ();
1329 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1330 public static void gc_suspend () {
1331 set_gc_suspend_field ();
1332 gc_suspend_1 ();
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 () {
1345 field_i = 42;
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 () {
1359 int i, j;
1361 i = 1;
1362 set_ip_1 ();
1363 i = 5;
1364 j = 5;
1365 set_ip_2 ();
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 () {
1386 return 42;
1390 public class Foo
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 () {
1400 // Column 3
1401 ln2 ();
1402 ln3 ();
1405 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1406 public static void ln2 () {
1409 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1410 public static void ln3 () {
1411 #pragma warning disable 0219
1412 int i = 5;
1413 #pragma warning restore 0219
1414 #line 55 "FOO"