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