[sgen] Fix pointer access.
[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         public int l;
85
86         [MethodImplAttribute (MethodImplOptions.NoInlining)]
87         public int foo (int val) {
88                 return val;
89         }
90
91         [MethodImplAttribute (MethodImplOptions.NoInlining)]
92         public static int static_foo (int val) {
93                 return val;
94         }
95
96         [MethodImplAttribute (MethodImplOptions.NoInlining)]
97         public int invoke_return_int () {
98                 return i;
99         }
100
101         [MethodImplAttribute (MethodImplOptions.NoInlining)]
102         public static int invoke_static () {
103                 return 5;
104         }
105
106         [MethodImplAttribute (MethodImplOptions.NoInlining)]
107         public IntPtr invoke_return_intptr () {
108                 return j;
109         }
110
111         [MethodImplAttribute (MethodImplOptions.NoInlining)]
112         public void invoke_mutate () {
113                 l = 5;
114         }
115 }
116
117 public class GClass<T> {
118         public T field;
119         public static T static_field;
120
121         [MethodImplAttribute (MethodImplOptions.NoInlining)]
122         public GClass () {
123         }
124
125         [MethodImplAttribute (MethodImplOptions.NoInlining)]
126         public void bp<T2> () {
127         }
128 }
129
130 public struct GStruct<T> {
131         public T i;
132
133         public int j;
134
135         [MethodImplAttribute (MethodImplOptions.NoInlining)]
136         public int invoke_return_int () {
137                 return j;
138         }
139 }
140
141 public struct NestedStruct {
142         NestedInner nested1, nested2;
143 }
144
145 public struct NestedInner {
146 }
147
148 public interface IRecStruct {
149         void foo (object o);
150 }
151
152 struct RecStruct : IRecStruct {
153         public object o;
154
155         public void foo (object o) {
156                 this.o = o;
157         }
158 }
159
160 interface ITest
161 {
162         void Foo ();
163         void Bar ();
164 }
165
166 interface ITest<T>
167 {
168         void Foo ();
169         void Bar ();
170 }
171
172 class TestIfaces : ITest
173 {
174         void ITest.Foo () {
175         }
176
177         void ITest.Bar () {
178         }
179
180         TestIfaces<int> Baz () {
181                 return null;
182         }
183 }
184
185 class TestIfaces<T> : ITest<T>
186 {
187         void ITest<T>.Foo () {
188         }
189
190         void ITest<T>.Bar () {
191         }
192 }
193
194 public interface ITest2
195 {
196         int invoke_iface ();
197 }
198
199 public class Tests : TestsBase, ITest2
200 {
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;
231
232 #pragma warning restore 0414
233
234         public class NestedClass {
235         }
236
237         public int IntProperty {
238                 get {
239                         return field_i;
240                 }
241                 set {
242                         field_i = value;
243                 }
244         }
245
246         public int ReadOnlyProperty {
247                 get {
248                         return field_i;
249                 }
250         }
251
252         public int this [int index] {
253                 get {
254                         return field_i;
255                 }
256         }
257
258         public static void wait_one ()
259         {
260                 ManualResetEvent evt = new ManualResetEvent (false);
261                 evt.WaitOne ();
262         }
263
264         public static int Main (String[] args) {
265                 tls_i = 42;
266
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;
273                 }
274                 if (args.Length >0 && args [0] == "unhandled-exception-endinvoke") {
275                         unhandled_exception_endinvoke ();
276                         return 0;
277                 }
278                 if (args.Length >0 && args [0] == "unhandled-exception-user") {
279                         unhandled_exception_user ();
280                         return 0;
281                 }
282                 if (args.Length >0 && args [0] == "wait-one") {
283                         wait_one ();
284                         return 0;
285                 }
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;
317         }
318
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> ();
324
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> ();
335         }
336
337         [MethodImplAttribute (MethodImplOptions.NoInlining)]
338         public static void bp1 () {
339         }
340
341         [MethodImplAttribute (MethodImplOptions.NoInlining)]
342         public static void bp2 () {
343         }
344
345         [MethodImplAttribute (MethodImplOptions.NoInlining)]
346         public static void bp3 () {
347         }
348
349         [MethodImplAttribute (MethodImplOptions.NoInlining)]
350         public static void bp4 () {
351         }
352
353         [MethodImplAttribute (MethodImplOptions.NoInlining)]
354         public static void bp5 () {
355         }
356
357         [MethodImplAttribute (MethodImplOptions.NoInlining)]
358         public static void bp6<T> (GClass<int> gc) {
359                 gc.bp<int> ();
360         }
361
362         [MethodImplAttribute (MethodImplOptions.NoInlining)]
363         public static void bp7<T> () {
364         }
365
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 {
378                 }
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 ();
386         }
387
388         [MethodImplAttribute (MethodImplOptions.NoInlining)]
389         public static void ss1 () {
390         }
391
392         [MethodImplAttribute (MethodImplOptions.NoInlining)]
393         public static void ss2 () {
394         }
395
396         [MethodImplAttribute (MethodImplOptions.NoInlining)]
397         public static int ss3 () {
398                 int sum = 0;
399
400                 for (int i = 0; i < 10; ++i)
401                         sum += i;
402
403                 return sum;
404         }
405
406         [MethodImplAttribute (MethodImplOptions.NoInlining)]
407         public static void ss3_2 () {
408                 ss3_2_2 ();
409         }
410
411         [MethodImplAttribute (MethodImplOptions.NoInlining)]
412         public static void ss3_2_2 () {
413         }
414
415         [MethodImplAttribute (MethodImplOptions.NoInlining)]
416         public static int ss4 () {
417                 ss1 (); ss1 ();
418                 ss2 ();
419                 return 0;
420         }
421
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);
426         }
427
428         [MethodImplAttribute (MethodImplOptions.NoInlining)]
429         public static void ss6 (bool b) {
430                 if (b) {
431                         ss6_2 ();
432                         throw new Exception ();
433                 }
434         }
435
436         [MethodImplAttribute (MethodImplOptions.NoInlining)]
437         public static void ss6_2 () {
438         }
439
440         [MethodImplAttribute (MethodImplOptions.NoInlining)]
441         public static void ss7 () {
442                 try {
443                         ss7_2 ();
444                         ss7_3 ();
445                 } catch {
446                 }
447                 ss7_2 ();
448         }
449
450         [MethodImplAttribute (MethodImplOptions.NoInlining)]
451         public static void ss7_2 () {
452         }
453
454         [MethodImplAttribute (MethodImplOptions.NoInlining)]
455         public static void ss7_3 () {
456                 throw new Exception ();
457         }
458
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 ();
464         }
465
466         [MethodImplAttribute (MethodImplOptions.NoInlining)]
467         public static void ss_nested_1 (int i) {
468         }
469
470         [MethodImplAttribute (MethodImplOptions.NoInlining)]
471         public static int ss_nested_2 () {
472                 return 0;
473         }
474
475         [MethodImplAttribute (MethodImplOptions.NoInlining)]
476         public static void ss_nested_3 () {
477         }
478
479         [MethodImplAttribute (MethodImplOptions.NoInlining)]
480         public static void ss_step_through () {
481                 step_through_1 ();
482                 StepThroughClass.step_through_2 ();
483                 step_through_3 ();
484         }
485
486         [DebuggerStepThrough]
487         [MethodImplAttribute (MethodImplOptions.NoInlining)]
488         public static void step_through_1 () {
489         }
490
491         [DebuggerStepThrough]
492         class StepThroughClass {
493                 [MethodImplAttribute (MethodImplOptions.NoInlining)]
494                 public static void step_through_2 () {
495                 }
496         }
497
498         [DebuggerStepThrough]
499         [MethodImplAttribute (MethodImplOptions.NoInlining)]
500         public static void step_through_3 () {
501         }
502
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 ();
508         }
509
510         [DebuggerNonUserCode]
511         [MethodImplAttribute (MethodImplOptions.NoInlining)]
512         public static void non_user_code_1 () {
513         }
514
515         [DebuggerNonUserCode]
516         class StepNonUserCodeClass {
517                 [MethodImplAttribute (MethodImplOptions.NoInlining)]
518                 public static void non_user_code_2 () {
519                 }
520         }
521
522         [DebuggerNonUserCode]
523         [MethodImplAttribute (MethodImplOptions.NoInlining)]
524         public static void non_user_code_3 () {
525         }
526
527         [MethodImplAttribute (MethodImplOptions.NoInlining)]
528         public static void ss_recursive (int n) {
529                 if (n == 10)
530                         return;
531                 ss_recursive (n + 1);
532         }
533
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);
538         }
539
540         [MethodImplAttribute (MethodImplOptions.NoInlining)]
541         public static double ss_fp_clobber_1 (double d) {
542                 return d + 2.0;
543         }
544
545         [MethodImplAttribute (MethodImplOptions.NoInlining)]
546         public static void ss_fp_clobber_2 (double d) {
547         }
548
549         [MethodImplAttribute (MethodImplOptions.NoInlining)]
550         public static bool is_even (int i) {
551                 return i % 2 == 0;
552         }
553
554         /*
555                 lock (static_s) {
556                         Console.WriteLine ("HIT!");
557                 }
558                 return 0;
559         }
560         */
561
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");
569         }
570
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);
574         }
575
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;
579         }
580
581         [MethodImplAttribute (MethodImplOptions.NoInlining)]
582         public object arg3 (string s) {
583                 return s + s + s + s + this;
584         }
585
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 });
591         }
592
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;
599         }
600
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];
604         }
605
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 ();
614         }
615
616         [MethodImplAttribute (MethodImplOptions.NoInlining)]
617         public static void set_child (Tests t) {
618                 t.child = new Tests ();
619         }
620
621         [MethodImplAttribute (MethodImplOptions.NoInlining)]
622         public void objrefs1 () {
623         }
624
625         [MethodImplAttribute (MethodImplOptions.NoInlining)]
626         public static void objrefs2 () {
627         }
628
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 ();
639         }
640
641         [MethodImplAttribute (MethodImplOptions.NoInlining)]
642         public object vtypes1 (AStruct s, AStruct[] arr) {
643                 if (arr != null)
644                         return this;
645                 else
646                         return null;
647         }
648
649         [MethodImplAttribute (MethodImplOptions.NoInlining)]
650         public static void vtypes2 (AStruct s) {
651                 s.foo (5);
652         }
653
654         [MethodImplAttribute (MethodImplOptions.NoInlining)]
655         public static void vtypes3 (AStruct s) {
656                 AStruct.static_foo (5);
657         }
658
659         [MethodImplAttribute (MethodImplOptions.NoInlining)]
660         public static void vtypes4_2 (IRecStruct o) {
661         }
662
663         [MethodImplAttribute (MethodImplOptions.NoInlining)]
664         public static void vtypes4 () {
665                 IRecStruct s = new RecStruct ();
666                 s.foo (s);
667                 vtypes4_2 (s);
668         }
669
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);
679         }
680
681         [MethodImplAttribute (MethodImplOptions.NoInlining)]
682         static void locals11 (double a, ref double b) {
683         }
684
685         [MethodImplAttribute (MethodImplOptions.NoInlining)]
686         public static void locals1 (string[] args) {
687                 long foo = 42;
688
689                 double ri = 1;
690                 locals11 (b: ref ri, a: ri);
691
692                 for (int j = 0; j < 10; ++j) {
693                         foo ++;
694                 }
695         }
696
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";
704
705                 for (int j = 0; j < 10; ++j) {
706                         if (s != null)
707                                 i ++;
708                         if (t != null)
709                                 i ++;
710                         astruct = new AStruct ();
711                 }
712                 rs = "A";
713         }
714
715
716         [MethodImplAttribute (MethodImplOptions.NoInlining)]
717         public static void locals3 () {
718                 string s = "B";
719                 s.ToString ();
720
721                 {
722                         long i = 42;
723                         i ++;
724                         locals4 ();
725                 }
726                 {
727                         string i = "A";
728                         i.ToString ();
729                         locals5 ();
730                 }
731                 {
732                         long j = 42;
733                         j ++;
734                 }
735         }
736
737         [MethodImplAttribute (MethodImplOptions.NoInlining)]
738         public static void locals4 () {
739         }
740
741         [MethodImplAttribute (MethodImplOptions.NoInlining)]
742         public static void locals5 () {
743         }
744
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);
760         }
761
762         [MethodImplAttribute (MethodImplOptions.NoInlining)]
763         public static void locals6_1 () {
764         }
765
766         [MethodImplAttribute (MethodImplOptions.NoInlining)]
767         public static void locals6_2 (int arg) {
768         }
769
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 ++;
784         }
785
786         [MethodImplAttribute (MethodImplOptions.NoInlining)]
787         public static void locals6_4 (int arg) {
788         }
789
790         [MethodImplAttribute (MethodImplOptions.NoInlining)]
791         public static void locals6_5 () {
792         }
793
794         [MethodImplAttribute (MethodImplOptions.NoInlining)]
795         public static void locals6_6 (int arg) {
796         }
797
798         [MethodImplAttribute (MethodImplOptions.NoInlining)]
799         public static void locals7<T> (T arg) {
800                 T t = arg;
801                 T t2 = t;
802         }
803
804         [MethodImplAttribute (MethodImplOptions.NoInlining)]
805         public static void line_numbers () {
806                 LineNumbers.ln1 ();
807         }
808
809         [MethodImplAttribute (MethodImplOptions.NoInlining)]
810         public static void suspend () {
811                 long i = 5;
812
813                 while (true) {
814                         i ++;
815                 }
816         }
817
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 };
825
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);
827                 }
828         }
829
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;
836         }
837
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];
841         }
842
843         [MethodImplAttribute (MethodImplOptions.NoInlining)]
844         public static void assembly_load () {
845                 assembly_load_2 ();
846         }
847
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 ();
852         }
853
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 ();
858         }
859
860         [MethodImplAttribute (MethodImplOptions.NoInlining)]
861         public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
862                 invoke2 ();
863         }
864
865         [MethodImplAttribute (MethodImplOptions.NoInlining)]
866         public void invoke2 () {
867         }
868
869         [MethodImplAttribute (MethodImplOptions.NoInlining)]
870         public void invoke_ex () {
871                 invoke_ex_inner ();
872         }
873
874         [MethodImplAttribute (MethodImplOptions.NoInlining)]
875         public void invoke_ex_inner () {
876                 try {
877                         throw new Exception ();
878                 } catch {
879                 }
880         }
881
882         int counter;
883
884         [MethodImplAttribute (MethodImplOptions.NoInlining)]
885         public void invoke_single_threaded () {
886                 // Spawn a thread incrementing a counter
887                 bool finished = false;
888
889                 new Thread (delegate () {
890                                 while (!finished)
891                                         counter ++;
892                 }).Start ();
893
894                 Thread.Sleep (100);
895
896                 invoke_single_threaded_2 ();
897
898                 finished = true;
899         }
900
901         [MethodImplAttribute (MethodImplOptions.NoInlining)]
902         public void invoke_single_threaded_2 () {
903         }
904
905         public void invoke_return_void () {
906         }
907
908         public string invoke_return_ref () {
909                 return "ABC";
910         }
911
912         public object invoke_return_null () {
913                 return null;
914         }
915
916         public int invoke_return_primitive () {
917                 return 42;
918         }
919
920         public int? invoke_return_nullable () {
921                 return 42;
922         }
923
924         public int? invoke_return_nullable_null () {
925                 return null;
926         }
927
928         public void invoke_type_load () {
929                 new Class3 ();
930         }
931
932         class Class3 {
933         }
934
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;
937         }
938
939         public int invoke_pass_primitive2 (bool b) {
940                 return b ? 1 : 0;
941         }
942
943         public string invoke_pass_ref (string s) {
944                 return s;
945         }
946
947         public static string invoke_static_pass_ref (string s) {
948                 return s;
949         }
950
951         public static void invoke_static_return_void () {
952         }
953
954         public static void invoke_throws () {
955                 throw new Exception ();
956         }
957
958         public int invoke_iface () {
959                 return 42;
960         }
961
962         public void invoke_out (out int foo, out int[] arr) {
963                 foo = 5;
964                 arr = new int [10];
965         }
966
967         [MethodImplAttribute (MethodImplOptions.NoInlining)]
968         public static void exceptions () {
969                 try {
970                         throw new OverflowException ();
971                 } catch (Exception) {
972                 }
973                 try {
974                         throw new OverflowException ();
975                 } catch (Exception) {
976                 }
977                 try {
978                         throw new ArgumentException ();
979                 } catch (Exception) {
980                 }
981                 try {
982                         throw new OverflowException ();
983                 } catch (Exception) {
984                 }
985                 // no subclasses
986                 try {
987                         throw new OverflowException ();
988                 } catch (Exception) {
989                 }
990                 try {
991                         throw new Exception ();
992                 } catch (Exception) {
993                 }
994
995                 object o = null;
996                 try {
997                         o.GetType ();
998                 } catch (Exception) {
999                 }
1000
1001                 try {
1002                         exceptions2 ();
1003                 } catch (Exception) {
1004                 }
1005         }
1006
1007         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1008         public static void unhandled_exception () {
1009                 ThreadPool.QueueUserWorkItem (delegate {
1010                                 throw new InvalidOperationException ();
1011                         });
1012                 Thread.Sleep (10000);
1013         }
1014
1015         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1016         public static void unhandled_exception_endinvoke_2 () {
1017         }
1018
1019         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1020         public static void unhandled_exception_endinvoke () {
1021                         Action action = new Action (() => 
1022                         {
1023                                 throw new Exception ("thrown");
1024                         });
1025                         action.BeginInvoke ((ar) => {
1026                                 try {
1027                                         action.EndInvoke (ar);
1028                                 } catch (Exception ex) {
1029                                         //Console.WriteLine (ex);
1030                                 }
1031                         }, null);
1032                 Thread.Sleep (1000);
1033                 unhandled_exception_endinvoke_2 ();
1034         }
1035
1036         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1037         public static void unhandled_exception_user () {
1038 #if NET_4_5
1039                 System.Threading.Tasks.Task.Factory.StartNew (() => {
1040                                 Throw ();
1041                         });
1042                 Thread.Sleep (10000);
1043 #endif
1044         }
1045
1046         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1047         public static void Throw () {
1048                 throw new Exception ();
1049         }
1050
1051         internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
1052         {
1053                 if (dlg == null)
1054                         throw new ArgumentNullException ();
1055                 if (dlg.Target != null)
1056                         throw new ArgumentException ();
1057                 if (dlg.Method == null)
1058                         throw new ArgumentException ();
1059
1060                 var ret_type = dlg.Method.ReturnType;
1061                 var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();
1062
1063                 var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
1064                 var ig = dynamic.GetILGenerator ();
1065
1066                 LocalBuilder retval = null;
1067                 if (ret_type != typeof (void))
1068                         retval = ig.DeclareLocal (ret_type);
1069
1070                 var label = ig.BeginExceptionBlock ();
1071
1072                 for (int i = 0; i < param_types.Length; i++)
1073                         ig.Emit (OpCodes.Ldarg, i);
1074                 ig.Emit (OpCodes.Call, dlg.Method);
1075
1076                 if (retval != null)
1077                         ig.Emit (OpCodes.Stloc, retval);
1078
1079                 ig.Emit (OpCodes.Leave, label);
1080
1081                 ig.BeginExceptFilterBlock ();
1082
1083                 ig.Emit (OpCodes.Call, filter_method);
1084
1085                 ig.BeginCatchBlock (null);
1086
1087                 ig.Emit (OpCodes.Pop);
1088
1089                 ig.EndExceptionBlock ();
1090
1091                 if (retval != null)
1092                         ig.Emit (OpCodes.Ldloc, retval);
1093
1094                 ig.Emit (OpCodes.Ret);
1095
1096                 return dynamic.CreateDelegate (dlg.GetType ());
1097         }
1098
1099         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1100         static void exception_filter_method () {
1101                 throw new InvalidOperationException ();
1102         }
1103
1104         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1105         static int exception_filter_filter (Exception exc) {
1106                 return 1;
1107         }
1108
1109         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1110         public static void exception_filter () {
1111                 var method = typeof (Tests).GetMethod (
1112                         "exception_filter_method", BindingFlags.NonPublic | BindingFlags.Static);
1113                 var filter_method = typeof (Tests).GetMethod (
1114                         "exception_filter_filter", BindingFlags.NonPublic | BindingFlags.Static);
1115
1116                 var dlg = Delegate.CreateDelegate (typeof (Action), method);
1117
1118                 var wrapper = (Action) create_filter_delegate (dlg, filter_method);
1119
1120                 wrapper ();
1121         }
1122
1123         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1124         public static bool return_true () {
1125                 return true;
1126         }
1127
1128         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1129         public static void exceptions2 () {
1130                 if (return_true ())
1131                         throw new Exception ();
1132                 Console.WriteLine ();
1133         }
1134
1135         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1136         public static void threads () {
1137                 Thread t = new Thread (delegate () {});
1138
1139                 t.Start ();
1140                 t.Join ();
1141         }
1142
1143         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1144         public static void domains () {
1145                 AppDomain domain = AppDomain.CreateDomain ("domain");
1146
1147                 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
1148                                    typeof (CrossDomain).Assembly.FullName, "CrossDomain");
1149
1150                 domains_2 (o, new CrossDomain ());
1151
1152                 o.invoke_2 ();
1153
1154                 o.invoke ();
1155
1156                 o.invoke_2 ();
1157
1158                 AppDomain.Unload (domain);
1159
1160                 domains_3 ();
1161         }
1162
1163         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1164         public static void domains_2 (object o, object o2) {
1165         }
1166
1167         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1168         public static void domains_3 () {
1169         }
1170
1171         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1172         public static void invoke_in_domain () {
1173         }
1174
1175         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1176         public static void invoke_in_domain_2 () {
1177         }
1178
1179         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1180         public static void dynamic_methods () {
1181                 var m = new DynamicMethod ("dyn_method", typeof (void), new Type []  { typeof (int) }, typeof (object).Module);
1182                 var ig = m.GetILGenerator ();
1183
1184                 ig.Emit (OpCodes.Ldstr, "FOO");
1185                 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
1186                 ig.Emit (OpCodes.Ret);
1187
1188                 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
1189
1190                 del (0);
1191         }
1192
1193         public static void dyn_call (string s) {
1194         }
1195
1196         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1197         public static void ref_emit () {
1198                 AssemblyName assemblyName = new AssemblyName ();
1199                 assemblyName.Name = "foo";
1200
1201                 AssemblyBuilder assembly =
1202                         Thread.GetDomain ().DefineDynamicAssembly (
1203                                                                                                            assemblyName, AssemblyBuilderAccess.RunAndSave);
1204
1205                 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
1206
1207                 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
1208                 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
1209                 ILGenerator ig = mb.GetILGenerator ();
1210                 ig.Emit (OpCodes.Ldstr, "FOO");
1211                 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
1212                 ig.Emit (OpCodes.Ret);
1213
1214                 Type t = tb.CreateType ();
1215
1216                 t.GetMethod ("ref_emit_method").Invoke (null, null);
1217         }
1218
1219         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1220         public static void ref_emit_call (string s) {
1221         }
1222
1223         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1224         public static void frames_in_native () {
1225                 Thread.Sleep (500);
1226                 var evt = new ManualResetEvent (false);
1227                 
1228                 object mon = new object ();
1229                 ThreadPool.QueueUserWorkItem (delegate {
1230                                 frames_in_native_2 ();
1231                                 evt.Set ();
1232                         });
1233                 evt.WaitOne ();
1234         }
1235
1236         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1237         static void frames_in_native_2 () {
1238                 frames_in_native_3 ();
1239         }
1240
1241         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1242         static void frames_in_native_3 () {
1243         }
1244
1245         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1246         public static void string_call (string s) {
1247         }
1248
1249         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1250         public static void ss_regress_654694 () {
1251                 if (true) {
1252                         string h = "hi";
1253                         string_call (h);
1254                 }
1255         }
1256
1257         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1258         public static void user () {
1259                 Debugger.Break ();
1260
1261                 Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
1262         }
1263
1264         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1265         public static void type_load () {
1266                 type_load_2 ();
1267         }
1268
1269         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1270         static void type_load_2 () {
1271                 var c1 = new Dictionary<int, int> ();
1272                 c1.ToString ();
1273                 var c = new TypeLoadClass ();
1274                 c.ToString ();
1275                 var c2 = new TypeLoadClass2 ();
1276                 c2.ToString ();
1277         }
1278
1279         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1280         public static void regress () {
1281                 regress_2755 (DateTime.Now);
1282         }
1283
1284         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1285         public static unsafe void regress_2755 (DateTime d) {
1286                 int* buffer = stackalloc int [128];
1287
1288                 regress_2755_2 ();
1289
1290                 int sum = 0;
1291                 for (int i = 0; i < 128; ++i)
1292                         sum += buffer [i];
1293
1294                 regress_2755_3 (sum);
1295         }
1296
1297         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1298         public static void regress_2755_2 () {
1299         }
1300
1301         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1302         public static void regress_2755_3 (int sum) {
1303         }
1304
1305         static object gc_suspend_field;
1306
1307         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1308         static unsafe void set_gc_suspend_field () {
1309                 set_gc_suspend_field_2 ();
1310                 // Clear stack
1311                 int* buffer = stackalloc int [4096];
1312         }
1313
1314         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1315         static void set_gc_suspend_field_2 () {
1316                 gc_suspend_field = new object ();
1317         }
1318
1319         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1320         static void gc_suspend_1 () {
1321         }
1322
1323         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1324         public static void gc_suspend_invoke () {
1325                 gc_suspend_field = null;
1326                 GC.Collect ();
1327                 GC.WaitForPendingFinalizers ();
1328         }
1329
1330         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1331         public static void gc_suspend () {
1332                 set_gc_suspend_field ();
1333                 gc_suspend_1 ();
1334         }
1335
1336         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1337         public static void generic_method<T> () where T : class {
1338         }
1339
1340         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1341         public void evaluate_method_2 () {
1342         }
1343
1344         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1345         public void evaluate_method () {
1346                 field_i = 42;
1347                 evaluate_method_2 ();
1348         }
1349
1350         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1351         static void set_ip_1 () {
1352         }
1353
1354         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1355         static void set_ip_2 () {
1356         }
1357
1358         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1359         public static void set_ip () {
1360                 int i, j;
1361
1362                 i = 1;
1363                 set_ip_1 ();
1364                 i = 5;
1365                 j = 5;
1366                 set_ip_2 ();
1367         }
1368 }
1369
1370 class TypeLoadClass {
1371 }
1372
1373 class TypeLoadClass2 {
1374 }
1375
1376 public class CrossDomain : MarshalByRefObject
1377 {
1378         public void invoke () {
1379                 Tests.invoke_in_domain ();
1380         }
1381
1382         public void invoke_2 () {
1383                 Tests.invoke_in_domain_2 ();
1384         }
1385
1386         public int invoke_3 () {
1387                 return 42;
1388         }
1389 }       
1390
1391 public class Foo
1392 {
1393         public ProcessStartInfo info;
1394 }
1395
1396 // Class used for line number info testing, don't change its layout
1397 public class LineNumbers
1398 {
1399         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1400         public static void ln1 () {
1401                 // Column 3
1402                 ln2 ();
1403                 ln3 ();
1404         }
1405
1406         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1407         public static void ln2 () {
1408         }
1409
1410         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1411         public static void ln3 () {
1412 #pragma warning disable 0219
1413                 int i = 5;
1414 #pragma warning restore 0219
1415                 #line 55 "FOO"
1416         }
1417 }