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