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