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