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