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