Bug 15572. Lookup KnownTypeCollection element types in MSSimpleNamespace
[mono.git] / mcs / class / Mono.Debugger.Soft / Test / dtest-app.cs
1 /*
2  * dtest-app.cs:
3  *
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;
14
15 public class TestsBase
16 {
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
25 }
26
27 public enum AnEnum {
28         A = 0,
29         B= 1
30 }
31
32 public sealed class Tests3 {
33         public static void M1 () {
34         }
35
36         static void M2 () {
37         }
38
39         public void M3 () {
40         }
41
42         void M4 () {
43         }
44
45 }
46
47 public static class Tests4 {
48         static Tests4 () {
49         }
50 }
51
52 public class AAttribute : Attribute {
53         public int afield;
54 }
55
56 public class BAttribute : AAttribute {
57         public int bfield;
58 }
59
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;
67
68         [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
69         public int AProperty {
70                 get {
71                         return 0;
72                 }
73         }
74
75         public void invoke () {
76         }
77 }
78
79 public struct AStruct {
80         public int i;
81         public string s;
82         public byte k;
83         public IntPtr j;
84
85         [MethodImplAttribute (MethodImplOptions.NoInlining)]
86         public int foo (int val) {
87                 return val;
88         }
89
90         [MethodImplAttribute (MethodImplOptions.NoInlining)]
91         public static int static_foo (int val) {
92                 return val;
93         }
94
95         [MethodImplAttribute (MethodImplOptions.NoInlining)]
96         public int invoke_return_int () {
97                 return i;
98         }
99
100         [MethodImplAttribute (MethodImplOptions.NoInlining)]
101         public static int invoke_static () {
102                 return 5;
103         }
104
105         [MethodImplAttribute (MethodImplOptions.NoInlining)]
106         public IntPtr invoke_return_intptr () {
107                 return j;
108         }
109 }
110
111 public class GClass<T> {
112         public T field;
113         public static T static_field;
114
115         [MethodImplAttribute (MethodImplOptions.NoInlining)]
116         public GClass () {
117         }
118
119         [MethodImplAttribute (MethodImplOptions.NoInlining)]
120         public void bp<T2> () {
121         }
122 }
123
124 public struct GStruct<T> {
125         public T i;
126
127         public int j;
128
129         [MethodImplAttribute (MethodImplOptions.NoInlining)]
130         public int invoke_return_int () {
131                 return j;
132         }
133 }
134
135 public struct NestedStruct {
136         NestedInner nested1, nested2;
137 }
138
139 public struct NestedInner {
140 }
141
142 interface ITest
143 {
144         void Foo ();
145         void Bar ();
146 }
147
148 interface ITest<T>
149 {
150         void Foo ();
151         void Bar ();
152 }
153
154 class TestIfaces : ITest
155 {
156         void ITest.Foo () {
157         }
158
159         void ITest.Bar () {
160         }
161
162         TestIfaces<int> Baz () {
163                 return null;
164         }
165 }
166
167 class TestIfaces<T> : ITest<T>
168 {
169         void ITest<T>.Foo () {
170         }
171
172         void ITest<T>.Bar () {
173         }
174 }
175
176 public interface ITest2
177 {
178         int invoke_iface ();
179 }
180
181 public class Tests : TestsBase, ITest2
182 {
183 #pragma warning disable 0414
184         int field_i;
185         string field_s;
186         AnEnum field_enum;
187         bool field_bool1, field_bool2;
188         char field_char;
189         byte field_byte;
190         sbyte field_sbyte;
191         short field_short;
192         ushort field_ushort;
193         long field_long;
194         ulong field_ulong;
195         float field_float;
196         double field_double;
197         Thread field_class;
198         IntPtr field_intptr;
199         int? field_nullable;
200         static int static_i = 55;
201         static string static_s = "A";
202         public const int literal_i = 56;
203         public const string literal_s = "B";
204         public object child;
205         public AStruct field_struct;
206         public object field_boxed_struct;
207         public GStruct<int> generic_field_struct;
208         public KeyValuePair<int, object> boxed_struct_field;
209         [ThreadStatic]
210         public static int tls_i;
211         public static bool is_attached = Debugger.IsAttached;
212         public NestedStruct nested_struct;
213
214 #pragma warning restore 0414
215
216         public class NestedClass {
217         }
218
219         public int IntProperty {
220                 get {
221                         return field_i;
222                 }
223                 set {
224                         field_i = value;
225                 }
226         }
227
228         public int ReadOnlyProperty {
229                 get {
230                         return field_i;
231                 }
232         }
233
234         public int this [int index] {
235                 get {
236                         return field_i;
237                 }
238         }
239
240         public static void wait_one ()
241         {
242                 ManualResetEvent evt = new ManualResetEvent (false);
243                 evt.WaitOne ();
244         }
245
246         public static int Main (String[] args) {
247                 tls_i = 42;
248
249                 if (args.Length > 0 && args [0] == "suspend-test")
250                         /* This contains an infinite loop, so execute it conditionally */
251                         suspend ();
252                 if (args.Length >0 && args [0] == "unhandled-exception") {
253                         unhandled_exception ();
254                         return 0;
255                 }
256                 if (args.Length >0 && args [0] == "unhandled-exception-endinvoke") {
257                         unhandled_exception_endinvoke ();
258                         return 0;
259                 }
260                 if (args.Length >0 && args [0] == "unhandled-exception-user") {
261                         unhandled_exception_user ();
262                         return 0;
263                 }
264                 if (args.Length >0 && args [0] == "wait-one") {
265                         wait_one ();
266                         return 0;
267                 }
268                 breakpoints ();
269                 single_stepping ();
270                 arguments ();
271                 objects ();
272                 objrefs ();
273                 vtypes ();
274                 locals ();
275                 line_numbers ();
276                 type_info ();
277                 assembly_load ();
278                 invoke ();
279                 exceptions ();
280                 exception_filter ();
281                 threads ();
282                 dynamic_methods ();
283                 user ();
284                 type_load ();
285                 regress ();
286                 gc_suspend ();
287                 if (args.Length > 0 && args [0] == "domain-test")
288                         /* This takes a lot of time, so execute it conditionally */
289                         domains ();
290                 if (args.Length > 0 && args [0] == "ref-emit-test")
291                         ref_emit ();
292                 if (args.Length > 0 && args [0] == "frames-in-native")
293                         frames_in_native ();
294                 if (args.Length > 0 && args [0] == "invoke-single-threaded")
295                         new Tests ().invoke_single_threaded ();
296                 return 3;
297         }
298
299         public static void breakpoints () {
300                 /* Call these early so it is JITted by the time a breakpoint is placed on it */
301                 bp3 ();
302                 bp7<int> ();
303                 bp7<string> ();
304
305                 bp1 ();
306                 bp2 ();
307                 bp3 ();
308                 bp4 ();
309                 bp4 ();
310                 bp4 ();
311                 bp5 ();
312                 bp6<string> (new GClass <int> ());
313                 bp7<int> ();
314                 bp7<string> ();
315         }
316
317         [MethodImplAttribute (MethodImplOptions.NoInlining)]
318         public static void bp1 () {
319         }
320
321         [MethodImplAttribute (MethodImplOptions.NoInlining)]
322         public static void bp2 () {
323         }
324
325         [MethodImplAttribute (MethodImplOptions.NoInlining)]
326         public static void bp3 () {
327         }
328
329         [MethodImplAttribute (MethodImplOptions.NoInlining)]
330         public static void bp4 () {
331         }
332
333         [MethodImplAttribute (MethodImplOptions.NoInlining)]
334         public static void bp5 () {
335         }
336
337         [MethodImplAttribute (MethodImplOptions.NoInlining)]
338         public static void bp6<T> (GClass<int> gc) {
339                 gc.bp<int> ();
340         }
341
342         [MethodImplAttribute (MethodImplOptions.NoInlining)]
343         public static void bp7<T> () {
344         }
345
346         [MethodImplAttribute (MethodImplOptions.NoInlining)]
347         public static void single_stepping () {
348                 bool b = true;
349                 ss1 ();
350                 ss2 ();
351                 ss3 ();
352                 ss3_2 ();
353                 ss4 ();
354                 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
355                 try {
356                         ss6 (b);
357                 } catch {
358                 }
359                 ss7 ();
360                 ss_nested ();
361                 ss_regress_654694 ();
362                 ss_step_through ();
363         }
364
365         [MethodImplAttribute (MethodImplOptions.NoInlining)]
366         public static void ss1 () {
367         }
368
369         [MethodImplAttribute (MethodImplOptions.NoInlining)]
370         public static void ss2 () {
371         }
372
373         [MethodImplAttribute (MethodImplOptions.NoInlining)]
374         public static int ss3 () {
375                 int sum = 0;
376
377                 for (int i = 0; i < 10; ++i)
378                         sum += i;
379
380                 return sum;
381         }
382
383         [MethodImplAttribute (MethodImplOptions.NoInlining)]
384         public static void ss3_2 () {
385                 ss3_2_2 ();
386         }
387
388         [MethodImplAttribute (MethodImplOptions.NoInlining)]
389         public static void ss3_2_2 () {
390         }
391
392         [MethodImplAttribute (MethodImplOptions.NoInlining)]
393         public static int ss4 () {
394                 ss1 (); ss1 ();
395                 ss2 ();
396                 return 0;
397         }
398
399         [MethodImplAttribute (MethodImplOptions.NoInlining)]
400         public static void ss5 (int[] arr, Func<int, bool> selector) {
401                 // Call into linq which calls back into this assembly
402                 arr.Count (selector);
403         }
404
405         [MethodImplAttribute (MethodImplOptions.NoInlining)]
406         public static void ss6 (bool b) {
407                 if (b) {
408                         ss6_2 ();
409                         throw new Exception ();
410                 }
411         }
412
413         [MethodImplAttribute (MethodImplOptions.NoInlining)]
414         public static void ss6_2 () {
415         }
416
417         [MethodImplAttribute (MethodImplOptions.NoInlining)]
418         public static void ss7 () {
419                 try {
420                         ss7_2 ();
421                         ss7_3 ();
422                 } catch {
423                 }
424                 ss7_2 ();
425         }
426
427         [MethodImplAttribute (MethodImplOptions.NoInlining)]
428         public static void ss7_2 () {
429         }
430
431         [MethodImplAttribute (MethodImplOptions.NoInlining)]
432         public static void ss7_3 () {
433                 throw new Exception ();
434         }
435
436         [MethodImplAttribute (MethodImplOptions.NoInlining)]
437         public static void ss_nested () {
438                 ss_nested_1 (ss_nested_2 ());
439                 ss_nested_1 (ss_nested_2 ());
440                 ss_nested_3 ();
441         }
442
443         [MethodImplAttribute (MethodImplOptions.NoInlining)]
444         public static void ss_nested_1 (int i) {
445         }
446
447         [MethodImplAttribute (MethodImplOptions.NoInlining)]
448         public static int ss_nested_2 () {
449                 return 0;
450         }
451
452         [MethodImplAttribute (MethodImplOptions.NoInlining)]
453         public static void ss_nested_3 () {
454         }
455
456         [MethodImplAttribute (MethodImplOptions.NoInlining)]
457         public static void ss_step_through () {
458                 step_through_1 ();
459                 StepThroughClass.step_through_2 ();
460                 step_through_3 ();
461         }
462
463         [DebuggerStepThrough]
464         [MethodImplAttribute (MethodImplOptions.NoInlining)]
465         public static void step_through_1 () {
466         }
467
468         [DebuggerStepThrough]
469         class StepThroughClass {
470                 [MethodImplAttribute (MethodImplOptions.NoInlining)]
471                 public static void step_through_2 () {
472                 }
473         }
474
475         [DebuggerStepThrough]
476         [MethodImplAttribute (MethodImplOptions.NoInlining)]
477         public static void step_through_3 () {
478         }
479
480         [MethodImplAttribute (MethodImplOptions.NoInlining)]
481         public static bool is_even (int i) {
482                 return i % 2 == 0;
483         }
484
485         /*
486                 lock (static_s) {
487                         Console.WriteLine ("HIT!");
488                 }
489                 return 0;
490         }
491         */
492
493         [MethodImplAttribute (MethodImplOptions.NoInlining)]
494         public static void arguments () {
495                 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));
496                 int i = 42;
497                 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object ());
498                 Tests t = new Tests () { field_i = 42, field_s = "S" };
499                 t.arg3 ("BLA");
500         }
501
502         [MethodImplAttribute (MethodImplOptions.NoInlining)]
503         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) {
504                 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
505         }
506
507         [MethodImplAttribute (MethodImplOptions.NoInlining)]
508         public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2) {
509                 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
510         }
511
512         [MethodImplAttribute (MethodImplOptions.NoInlining)]
513         public object arg3 (string s) {
514                 return s + s + s + s + this;
515         }
516
517         [MethodImplAttribute (MethodImplOptions.NoInlining)]
518         public static void objects () {
519                 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 };
520                 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
521                 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 });
522         }
523
524         [MethodImplAttribute (MethodImplOptions.NoInlining)]
525         public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
526                 if (t == null || gc1 == null || gc2 == null)
527                         return null;
528                 else
529                         return this;
530         }
531
532         [MethodImplAttribute (MethodImplOptions.NoInlining)]
533         public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
534                 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
535         }
536
537         [MethodImplAttribute (MethodImplOptions.NoInlining)]
538         public static void objrefs () {
539                 Tests t = new Tests () {};
540                 set_child (t);
541                 t.objrefs1 ();
542                 t.child = null;
543                 GC.Collect ();
544                 objrefs2 ();
545         }
546
547         [MethodImplAttribute (MethodImplOptions.NoInlining)]
548         public static void set_child (Tests t) {
549                 t.child = new Tests ();
550         }
551
552         [MethodImplAttribute (MethodImplOptions.NoInlining)]
553         public void objrefs1 () {
554         }
555
556         [MethodImplAttribute (MethodImplOptions.NoInlining)]
557         public static void objrefs2 () {
558         }
559
560         public static void vtypes () {
561                 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 ) };
562                 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
563                 AStruct[] arr = new AStruct[] { 
564                         new AStruct () { i = 1, s = "S1" },
565                         new AStruct () { i = 2, s = "S2" } };
566                 t.vtypes1 (s, arr);
567                 vtypes2 (s);
568                 vtypes3 (s);
569         }
570
571         [MethodImplAttribute (MethodImplOptions.NoInlining)]
572         public object vtypes1 (AStruct s, AStruct[] arr) {
573                 if (arr != null)
574                         return this;
575                 else
576                         return null;
577         }
578
579         [MethodImplAttribute (MethodImplOptions.NoInlining)]
580         public static void vtypes2 (AStruct s) {
581                 s.foo (5);
582         }
583
584         [MethodImplAttribute (MethodImplOptions.NoInlining)]
585         public static void vtypes3 (AStruct s) {
586                 AStruct.static_foo (5);
587         }
588
589         [MethodImplAttribute (MethodImplOptions.NoInlining)]
590         public static void locals () {
591                 string s = null;
592                 locals1 (null);
593                 locals2<string> (null, 5, "ABC", ref s);
594                 locals3 ();
595                 locals6 ();
596                 locals7<int> (22);
597         }
598
599         [MethodImplAttribute (MethodImplOptions.NoInlining)]
600         static void locals11 (double a, ref double b) {
601         }
602
603         [MethodImplAttribute (MethodImplOptions.NoInlining)]
604         public static void locals1 (string[] args) {
605                 long foo = 42;
606
607                 double ri = 1;
608                 locals11 (b: ref ri, a: ri);
609
610                 for (int j = 0; j < 10; ++j) {
611                         foo ++;
612                 }
613         }
614
615         [MethodImplAttribute (MethodImplOptions.NoInlining)]
616 #if NET_4_5
617         [StateMachine (typeof (int))]
618 #endif
619         public static void locals2<T> (string[] args, int arg, T t, ref string rs) {
620                 long i = 42;
621                 string s = "AB";
622
623                 for (int j = 0; j < 10; ++j) {
624                         if (s != null)
625                                 i ++;
626                         if (t != null)
627                                 i ++;
628                 }
629                 rs = "A";
630         }
631
632
633         [MethodImplAttribute (MethodImplOptions.NoInlining)]
634         public static void locals3 () {
635                 string s = "B";
636                 s.ToString ();
637
638                 {
639                         long i = 42;
640                         i ++;
641                         locals4 ();
642                 }
643                 {
644                         string i = "A";
645                         i.ToString ();
646                         locals5 ();
647                 }
648                 {
649                         long j = 42;
650                         j ++;
651                 }
652         }
653
654         [MethodImplAttribute (MethodImplOptions.NoInlining)]
655         public static void locals4 () {
656         }
657
658         [MethodImplAttribute (MethodImplOptions.NoInlining)]
659         public static void locals5 () {
660         }
661
662         [MethodImplAttribute (MethodImplOptions.NoInlining)]
663         public static void locals6 () {
664                 int i = 0;
665                 int j = 0;
666                 for (i = 0; i < 10; ++i)
667                         j ++;
668                 sbyte sb = 0;
669                 for (i = 0; i < 10; ++i)
670                         sb ++;
671                 locals6_1 ();
672                 locals6_2 (j);
673                 locals6_3 ();
674                 locals6_4 (j);
675                 locals6_5 ();
676                 locals6_6 (sb);
677         }
678
679         [MethodImplAttribute (MethodImplOptions.NoInlining)]
680         public static void locals6_1 () {
681         }
682
683         [MethodImplAttribute (MethodImplOptions.NoInlining)]
684         public static void locals6_2 (int arg) {
685         }
686
687         [MethodImplAttribute (MethodImplOptions.NoInlining)]
688         public static void locals6_3 () {
689                 // Clobber all registers
690                 int sum = 0, i, j, k, l, m;
691                 for (i = 0; i < 100; ++i)
692                         sum ++;
693                 for (j = 0; j < 100; ++j)
694                         sum ++;
695                 for (k = 0; k < 100; ++k)
696                         sum ++;
697                 for (l = 0; l < 100; ++l)
698                         sum ++;
699                 for (m = 0; m < 100; ++m)
700                         sum ++;
701         }
702
703         [MethodImplAttribute (MethodImplOptions.NoInlining)]
704         public static void locals6_4 (int arg) {
705         }
706
707         [MethodImplAttribute (MethodImplOptions.NoInlining)]
708         public static void locals6_5 () {
709         }
710
711         [MethodImplAttribute (MethodImplOptions.NoInlining)]
712         public static void locals6_6 (int arg) {
713         }
714
715         [MethodImplAttribute (MethodImplOptions.NoInlining)]
716         public static void locals7<T> (T arg) {
717                 T t = arg;
718                 T t2 = t;
719         }
720
721         [MethodImplAttribute (MethodImplOptions.NoInlining)]
722         public static void line_numbers () {
723                 LineNumbers.ln1 ();
724         }
725
726         [MethodImplAttribute (MethodImplOptions.NoInlining)]
727         public static void suspend () {
728                 long i = 5;
729
730                 while (true) {
731                         i ++;
732                 }
733         }
734
735         [MethodImplAttribute (MethodImplOptions.NoInlining)]
736         public static void type_info () {
737                 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
738                 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
739                 int val = 0;
740                 unsafe {
741                         AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
742
743                         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);
744                 }
745         }
746
747         [MethodImplAttribute (MethodImplOptions.NoInlining)]
748         public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
749                 if (t == null || gc1 == null || gc2 == null)
750                         return null;
751                 else
752                         return this;
753         }
754
755         [MethodImplAttribute (MethodImplOptions.NoInlining)]
756         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) {
757                 return s2 [0] + s3 [0] + s4 [0, 0];
758         }
759
760         [MethodImplAttribute (MethodImplOptions.NoInlining)]
761         public static void assembly_load () {
762                 assembly_load_2 ();
763         }
764
765         [MethodImplAttribute (MethodImplOptions.NoInlining)]
766         public static void assembly_load_2 () {
767                 // This will load System.dll while holding the loader lock
768                 new Foo ();
769         }
770
771         [MethodImplAttribute (MethodImplOptions.NoInlining)]
772         public static void invoke () {
773                 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }, new GStruct<int> { j = 42 });
774                 new Tests ().invoke_ex ();
775         }
776
777         [MethodImplAttribute (MethodImplOptions.NoInlining)]
778         public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
779                 invoke2 ();
780         }
781
782         [MethodImplAttribute (MethodImplOptions.NoInlining)]
783         public void invoke2 () {
784         }
785
786         [MethodImplAttribute (MethodImplOptions.NoInlining)]
787         public void invoke_ex () {
788                 invoke_ex_inner ();
789         }
790
791         [MethodImplAttribute (MethodImplOptions.NoInlining)]
792         public void invoke_ex_inner () {
793                 try {
794                         throw new Exception ();
795                 } catch {
796                 }
797         }
798
799         int counter;
800
801         [MethodImplAttribute (MethodImplOptions.NoInlining)]
802         public void invoke_single_threaded () {
803                 // Spawn a thread incrementing a counter
804                 bool finished = false;
805
806                 new Thread (delegate () {
807                                 while (!finished)
808                                         counter ++;
809                 }).Start ();
810
811                 Thread.Sleep (100);
812
813                 invoke_single_threaded_2 ();
814
815                 finished = true;
816         }
817
818         [MethodImplAttribute (MethodImplOptions.NoInlining)]
819         public void invoke_single_threaded_2 () {
820         }
821
822         public void invoke_return_void () {
823         }
824
825         public string invoke_return_ref () {
826                 return "ABC";
827         }
828
829         public object invoke_return_null () {
830                 return null;
831         }
832
833         public int invoke_return_primitive () {
834                 return 42;
835         }
836
837         public int? invoke_return_nullable () {
838                 return 42;
839         }
840
841         public int? invoke_return_nullable_null () {
842                 return null;
843         }
844
845         public void invoke_type_load () {
846                 new Class3 ();
847         }
848
849         class Class3 {
850         }
851
852         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) {
853                 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
854         }
855
856         public int invoke_pass_primitive2 (bool b) {
857                 return b ? 1 : 0;
858         }
859
860         public string invoke_pass_ref (string s) {
861                 return s;
862         }
863
864         public static string invoke_static_pass_ref (string s) {
865                 return s;
866         }
867
868         public static void invoke_static_return_void () {
869         }
870
871         public static void invoke_throws () {
872                 throw new Exception ();
873         }
874
875         public int invoke_iface () {
876                 return 42;
877         }
878
879         [MethodImplAttribute (MethodImplOptions.NoInlining)]
880         public static void exceptions () {
881                 try {
882                         throw new OverflowException ();
883                 } catch (Exception) {
884                 }
885                 try {
886                         throw new OverflowException ();
887                 } catch (Exception) {
888                 }
889                 try {
890                         throw new ArgumentException ();
891                 } catch (Exception) {
892                 }
893                 try {
894                         throw new OverflowException ();
895                 } catch (Exception) {
896                 }
897                 // no subclasses
898                 try {
899                         throw new OverflowException ();
900                 } catch (Exception) {
901                 }
902                 try {
903                         throw new Exception ();
904                 } catch (Exception) {
905                 }
906
907                 object o = null;
908                 try {
909                         o.GetType ();
910                 } catch (Exception) {
911                 }
912
913                 try {
914                         exceptions2 ();
915                 } catch (Exception) {
916                 }
917         }
918
919         [MethodImplAttribute (MethodImplOptions.NoInlining)]
920         public static void unhandled_exception () {
921                 ThreadPool.QueueUserWorkItem (delegate {
922                                 throw new InvalidOperationException ();
923                         });
924                 Thread.Sleep (10000);
925         }
926
927         [MethodImplAttribute (MethodImplOptions.NoInlining)]
928         public static void unhandled_exception_endinvoke_2 () {
929         }
930
931         [MethodImplAttribute (MethodImplOptions.NoInlining)]
932         public static void unhandled_exception_endinvoke () {
933                         Action action = new Action (() => 
934                         {
935                                 throw new Exception ("thrown");
936                         });
937                         action.BeginInvoke ((ar) => {
938                                 try {
939                                         action.EndInvoke (ar);
940                                 } catch (Exception ex) {
941                                         //Console.WriteLine (ex);
942                                 }
943                         }, null);
944                 Thread.Sleep (1000);
945                 unhandled_exception_endinvoke_2 ();
946         }
947
948         [MethodImplAttribute (MethodImplOptions.NoInlining)]
949         public static void unhandled_exception_user () {
950 #if NET_4_5
951                 System.Threading.Tasks.Task.Factory.StartNew (() => {
952                                 Throw ();
953                         });
954                 Thread.Sleep (10000);
955 #endif
956         }
957
958         [MethodImplAttribute (MethodImplOptions.NoInlining)]
959         public static void Throw () {
960                 throw new Exception ();
961         }
962
963         internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
964         {
965                 if (dlg == null)
966                         throw new ArgumentNullException ();
967                 if (dlg.Target != null)
968                         throw new ArgumentException ();
969                 if (dlg.Method == null)
970                         throw new ArgumentException ();
971
972                 var ret_type = dlg.Method.ReturnType;
973                 var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();
974
975                 var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
976                 var ig = dynamic.GetILGenerator ();
977
978                 LocalBuilder retval = null;
979                 if (ret_type != typeof (void))
980                         retval = ig.DeclareLocal (ret_type);
981
982                 var label = ig.BeginExceptionBlock ();
983
984                 for (int i = 0; i < param_types.Length; i++)
985                         ig.Emit (OpCodes.Ldarg, i);
986                 ig.Emit (OpCodes.Call, dlg.Method);
987
988                 if (retval != null)
989                         ig.Emit (OpCodes.Stloc, retval);
990
991                 ig.Emit (OpCodes.Leave, label);
992
993                 ig.BeginExceptFilterBlock ();
994
995                 ig.Emit (OpCodes.Call, filter_method);
996
997                 ig.BeginCatchBlock (null);
998
999                 ig.Emit (OpCodes.Pop);
1000
1001                 ig.EndExceptionBlock ();
1002
1003                 if (retval != null)
1004                         ig.Emit (OpCodes.Ldloc, retval);
1005
1006                 ig.Emit (OpCodes.Ret);
1007
1008                 return dynamic.CreateDelegate (dlg.GetType ());
1009         }
1010
1011         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1012         static void exception_filter_method () {
1013                 throw new InvalidOperationException ();
1014         }
1015
1016         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1017         static int exception_filter_filter (Exception exc) {
1018                 return 1;
1019         }
1020
1021         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1022         public static void exception_filter () {
1023                 var method = typeof (Tests).GetMethod (
1024                         "exception_filter_method", BindingFlags.NonPublic | BindingFlags.Static);
1025                 var filter_method = typeof (Tests).GetMethod (
1026                         "exception_filter_filter", BindingFlags.NonPublic | BindingFlags.Static);
1027
1028                 var dlg = Delegate.CreateDelegate (typeof (Action), method);
1029
1030                 var wrapper = (Action) create_filter_delegate (dlg, filter_method);
1031
1032                 wrapper ();
1033         }
1034
1035         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1036         public static bool return_true () {
1037                 return true;
1038         }
1039
1040         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1041         public static void exceptions2 () {
1042                 if (return_true ())
1043                         throw new Exception ();
1044                 Console.WriteLine ();
1045         }
1046
1047         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1048         public static void threads () {
1049                 Thread t = new Thread (delegate () {});
1050
1051                 t.Start ();
1052                 t.Join ();
1053         }
1054
1055         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1056         public static void domains () {
1057                 AppDomain domain = AppDomain.CreateDomain ("domain");
1058
1059                 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
1060                                    typeof (CrossDomain).Assembly.FullName, "CrossDomain");
1061
1062                 domains_2 (o, new CrossDomain ());
1063
1064                 o.invoke_2 ();
1065
1066                 o.invoke ();
1067
1068                 o.invoke_2 ();
1069
1070                 AppDomain.Unload (domain);
1071
1072                 domains_3 ();
1073         }
1074
1075         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1076         public static void domains_2 (object o, object o2) {
1077         }
1078
1079         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1080         public static void domains_3 () {
1081         }
1082
1083         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1084         public static void invoke_in_domain () {
1085         }
1086
1087         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1088         public static void invoke_in_domain_2 () {
1089         }
1090
1091         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1092         public static void dynamic_methods () {
1093                 var m = new DynamicMethod ("dyn_method", typeof (void), new Type []  { typeof (int) }, typeof (object).Module);
1094                 var ig = m.GetILGenerator ();
1095
1096                 ig.Emit (OpCodes.Ldstr, "FOO");
1097                 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
1098                 ig.Emit (OpCodes.Ret);
1099
1100                 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
1101
1102                 del (0);
1103         }
1104
1105         public static void dyn_call (string s) {
1106         }
1107
1108         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1109         public static void ref_emit () {
1110                 AssemblyName assemblyName = new AssemblyName ();
1111                 assemblyName.Name = "foo";
1112
1113                 AssemblyBuilder assembly =
1114                         Thread.GetDomain ().DefineDynamicAssembly (
1115                                                                                                            assemblyName, AssemblyBuilderAccess.RunAndSave);
1116
1117                 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
1118
1119                 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
1120                 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
1121                 ILGenerator ig = mb.GetILGenerator ();
1122                 ig.Emit (OpCodes.Ldstr, "FOO");
1123                 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
1124                 ig.Emit (OpCodes.Ret);
1125
1126                 Type t = tb.CreateType ();
1127
1128                 t.GetMethod ("ref_emit_method").Invoke (null, null);
1129         }
1130
1131         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1132         public static void ref_emit_call (string s) {
1133         }
1134
1135         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1136         public static void frames_in_native () {
1137                 Thread.Sleep (500);
1138                 var evt = new ManualResetEvent (false);
1139                 
1140                 object mon = new object ();
1141                 ThreadPool.QueueUserWorkItem (delegate {
1142                                 frames_in_native_2 ();
1143                                 evt.Set ();
1144                         });
1145                 evt.WaitOne ();
1146         }
1147
1148         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1149         static void frames_in_native_2 () {
1150                 frames_in_native_3 ();
1151         }
1152
1153         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1154         static void frames_in_native_3 () {
1155         }
1156
1157         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1158         public static void string_call (string s) {
1159         }
1160
1161         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1162         public static void ss_regress_654694 () {
1163                 if (true) {
1164                         string h = "hi";
1165                         string_call (h);
1166                 }
1167         }
1168
1169         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1170         public static void user () {
1171                 Debugger.Break ();
1172
1173                 Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
1174         }
1175
1176         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1177         public static void type_load () {
1178                 type_load_2 ();
1179         }
1180
1181         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1182         static void type_load_2 () {
1183                 var c1 = new Dictionary<int, int> ();
1184                 c1.ToString ();
1185                 var c = new TypeLoadClass ();
1186                 c.ToString ();
1187                 var c2 = new TypeLoadClass2 ();
1188                 c2.ToString ();
1189         }
1190
1191         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1192         public static void regress () {
1193                 regress_2755 (DateTime.Now);
1194         }
1195
1196         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1197         public static unsafe void regress_2755 (DateTime d) {
1198                 int* buffer = stackalloc int [128];
1199
1200                 regress_2755_2 ();
1201
1202                 int sum = 0;
1203                 for (int i = 0; i < 128; ++i)
1204                         sum += buffer [i];
1205
1206                 regress_2755_3 (sum);
1207         }
1208
1209         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1210         public static void regress_2755_2 () {
1211         }
1212
1213         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1214         public static void regress_2755_3 (int sum) {
1215         }
1216
1217         static object gc_suspend_field;
1218
1219         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1220         static unsafe void set_gc_suspend_field () {
1221                 set_gc_suspend_field_2 ();
1222                 // Clear stack
1223                 int* buffer = stackalloc int [4096];
1224         }
1225
1226         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1227         static void set_gc_suspend_field_2 () {
1228                 gc_suspend_field = new object ();
1229         }
1230
1231         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1232         static void gc_suspend_1 () {
1233         }
1234
1235         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1236         public static void gc_suspend_invoke () {
1237                 gc_suspend_field = null;
1238                 GC.Collect ();
1239                 GC.WaitForPendingFinalizers ();
1240         }
1241
1242         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1243         public static void gc_suspend () {
1244                 set_gc_suspend_field ();
1245                 gc_suspend_1 ();
1246         }
1247
1248         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1249         public static void generic_method<T> () where T : class {
1250         }
1251 }
1252
1253 class TypeLoadClass {
1254 }
1255
1256 class TypeLoadClass2 {
1257 }
1258
1259 public class CrossDomain : MarshalByRefObject
1260 {
1261         public void invoke () {
1262                 Tests.invoke_in_domain ();
1263         }
1264
1265         public void invoke_2 () {
1266                 Tests.invoke_in_domain_2 ();
1267         }
1268
1269         public int invoke_3 () {
1270                 return 42;
1271         }
1272 }       
1273
1274 public class Foo
1275 {
1276         public ProcessStartInfo info;
1277 }
1278
1279 // Class used for line number info testing, don't change its layout
1280 public class LineNumbers
1281 {
1282         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1283         public static void ln1 () {
1284                 // Column 3
1285                 ln2 ();
1286                 ln3 ();
1287         }
1288
1289         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1290         public static void ln2 () {
1291         }
1292
1293         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1294         public static void ln3 () {
1295 #pragma warning disable 0219
1296                 int i = 5;
1297 #pragma warning restore 0219
1298                 #line 55 "FOO"
1299         }
1300 }