[sdb] Fix race condition on test program that would cause a hang when running on...
[mono-project.git] / mcs / class / Mono.Debugger.Soft / Test / dtest-app.cs
blob7d475e7dd0bb49d8db51b02508d14996699ffe16
1 /*
2 * dtest-app.cs:
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;
15 public class TestsBase
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
27 public enum AnEnum {
28 A = 0,
29 B= 1
32 public sealed class Tests3 {
33 public static void M1 () {
36 static void M2 () {
39 public void M3 () {
42 void M4 () {
47 public static class Tests4 {
48 static Tests4 () {
52 public class AAttribute : Attribute {
53 public int afield;
56 public class BAttribute : AAttribute {
57 public int bfield;
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;
68 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
69 public int AProperty {
70 get {
71 return 0;
75 public void invoke () {
79 public struct AStruct {
80 public int i;
81 public string s;
82 public byte k;
83 public IntPtr j;
85 [MethodImplAttribute (MethodImplOptions.NoInlining)]
86 public int foo (int val) {
87 return val;
90 [MethodImplAttribute (MethodImplOptions.NoInlining)]
91 public static int static_foo (int val) {
92 return val;
95 [MethodImplAttribute (MethodImplOptions.NoInlining)]
96 public int invoke_return_int () {
97 return i;
100 [MethodImplAttribute (MethodImplOptions.NoInlining)]
101 public static int invoke_static () {
102 return 5;
105 [MethodImplAttribute (MethodImplOptions.NoInlining)]
106 public IntPtr invoke_return_intptr () {
107 return j;
111 public class GClass<T> {
112 public T field;
113 public static T static_field;
115 [MethodImplAttribute (MethodImplOptions.NoInlining)]
116 public GClass () {
119 [MethodImplAttribute (MethodImplOptions.NoInlining)]
120 public void bp<T2> () {
124 public struct GStruct<T> {
125 public T i;
127 public int j;
129 [MethodImplAttribute (MethodImplOptions.NoInlining)]
130 public int invoke_return_int () {
131 return j;
135 interface ITest
137 void Foo ();
138 void Bar ();
141 interface ITest<T>
143 void Foo ();
144 void Bar ();
147 class TestIfaces : ITest
149 void ITest.Foo () {
152 void ITest.Bar () {
155 TestIfaces<int> Baz () {
156 return null;
160 class TestIfaces<T> : ITest<T>
162 void ITest<T>.Foo () {
165 void ITest<T>.Bar () {
169 public class Tests : TestsBase
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 [ThreadStatic]
197 public static int tls_i;
198 public static bool is_attached = Debugger.IsAttached;
200 #pragma warning restore 0414
202 public class NestedClass {
205 public int IntProperty {
206 get {
207 return field_i;
209 set {
210 field_i = value;
214 public int ReadOnlyProperty {
215 get {
216 return field_i;
220 public int this [int index] {
221 get {
222 return field_i;
226 public static int Main (String[] args) {
227 tls_i = 42;
229 if (args.Length > 0 && args [0] == "suspend-test")
230 /* This contains an infinite loop, so execute it conditionally */
231 suspend ();
232 if (args.Length >0 && args [0] == "unhandled-exception") {
233 unhandled_exception ();
234 return 0;
236 if (args.Length >0 && args [0] == "unhandled-exception-endinvoke") {
237 unhandled_exception_endinvoke ();
238 return 0;
240 if (args.Length >0 && args [0] == "unhandled-exception-user") {
241 unhandled_exception_user ();
242 return 0;
244 breakpoints ();
245 single_stepping ();
246 arguments ();
247 objects ();
248 objrefs ();
249 vtypes ();
250 locals ();
251 line_numbers ();
252 type_info ();
253 assembly_load ();
254 invoke ();
255 exceptions ();
256 exception_filter ();
257 threads ();
258 dynamic_methods ();
259 user ();
260 type_load ();
261 regress ();
262 gc_suspend ();
263 if (args.Length > 0 && args [0] == "domain-test")
264 /* This takes a lot of time, so execute it conditionally */
265 domains ();
266 if (args.Length > 0 && args [0] == "ref-emit-test")
267 ref_emit ();
268 if (args.Length > 0 && args [0] == "frames-in-native")
269 frames_in_native ();
270 if (args.Length > 0 && args [0] == "invoke-single-threaded")
271 new Tests ().invoke_single_threaded ();
272 return 3;
275 public static void breakpoints () {
276 /* Call these early so it is JITted by the time a breakpoint is placed on it */
277 bp3 ();
278 bp7<int> ();
279 bp7<string> ();
281 bp1 ();
282 bp2 ();
283 bp3 ();
284 bp4 ();
285 bp4 ();
286 bp4 ();
287 bp5 ();
288 bp6<string> (new GClass <int> ());
289 bp7<int> ();
290 bp7<string> ();
293 [MethodImplAttribute (MethodImplOptions.NoInlining)]
294 public static void bp1 () {
297 [MethodImplAttribute (MethodImplOptions.NoInlining)]
298 public static void bp2 () {
301 [MethodImplAttribute (MethodImplOptions.NoInlining)]
302 public static void bp3 () {
305 [MethodImplAttribute (MethodImplOptions.NoInlining)]
306 public static void bp4 () {
309 [MethodImplAttribute (MethodImplOptions.NoInlining)]
310 public static void bp5 () {
313 [MethodImplAttribute (MethodImplOptions.NoInlining)]
314 public static void bp6<T> (GClass<int> gc) {
315 gc.bp<int> ();
318 [MethodImplAttribute (MethodImplOptions.NoInlining)]
319 public static void bp7<T> () {
322 [MethodImplAttribute (MethodImplOptions.NoInlining)]
323 public static void single_stepping () {
324 bool b = true;
325 ss1 ();
326 ss2 ();
327 ss3 ();
328 ss3_2 ();
329 ss4 ();
330 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
331 try {
332 ss6 (b);
333 } catch {
335 ss7 ();
336 ss_regress_654694 ();
339 [MethodImplAttribute (MethodImplOptions.NoInlining)]
340 public static void ss1 () {
343 [MethodImplAttribute (MethodImplOptions.NoInlining)]
344 public static void ss2 () {
347 [MethodImplAttribute (MethodImplOptions.NoInlining)]
348 public static int ss3 () {
349 int sum = 0;
351 for (int i = 0; i < 10; ++i)
352 sum += i;
354 return sum;
357 [MethodImplAttribute (MethodImplOptions.NoInlining)]
358 public static void ss3_2 () {
359 ss3_2_2 ();
362 [MethodImplAttribute (MethodImplOptions.NoInlining)]
363 public static void ss3_2_2 () {
366 [MethodImplAttribute (MethodImplOptions.NoInlining)]
367 public static int ss4 () {
368 ss1 (); ss1 ();
369 ss2 ();
370 return 0;
373 [MethodImplAttribute (MethodImplOptions.NoInlining)]
374 public static void ss5 (int[] arr, Func<int, bool> selector) {
375 // Call into linq which calls back into this assembly
376 arr.Count (selector);
379 [MethodImplAttribute (MethodImplOptions.NoInlining)]
380 public static void ss6 (bool b) {
381 if (b) {
382 ss6_2 ();
383 throw new Exception ();
387 [MethodImplAttribute (MethodImplOptions.NoInlining)]
388 public static void ss6_2 () {
391 [MethodImplAttribute (MethodImplOptions.NoInlining)]
392 public static void ss7 () {
393 try {
394 ss7_2 ();
395 ss7_3 ();
396 } catch {
398 ss7_2 ();
401 [MethodImplAttribute (MethodImplOptions.NoInlining)]
402 public static void ss7_2 () {
405 [MethodImplAttribute (MethodImplOptions.NoInlining)]
406 public static void ss7_3 () {
407 throw new Exception ();
410 [MethodImplAttribute (MethodImplOptions.NoInlining)]
411 public static bool is_even (int i) {
412 return i % 2 == 0;
416 lock (static_s) {
417 Console.WriteLine ("HIT!");
419 return 0;
423 [MethodImplAttribute (MethodImplOptions.NoInlining)]
424 public static void arguments () {
425 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));
426 int i = 42;
427 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object ());
428 Tests t = new Tests () { field_i = 42, field_s = "S" };
429 t.arg3 ("BLA");
432 [MethodImplAttribute (MethodImplOptions.NoInlining)]
433 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) {
434 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
437 [MethodImplAttribute (MethodImplOptions.NoInlining)]
438 public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2) {
439 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
442 [MethodImplAttribute (MethodImplOptions.NoInlining)]
443 public object arg3 (string s) {
444 return s + s + s + s + this;
447 [MethodImplAttribute (MethodImplOptions.NoInlining)]
448 public static void objects () {
449 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 };
450 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
451 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 });
454 [MethodImplAttribute (MethodImplOptions.NoInlining)]
455 public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
456 if (t == null || gc1 == null || gc2 == null)
457 return null;
458 else
459 return this;
462 [MethodImplAttribute (MethodImplOptions.NoInlining)]
463 public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
464 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
467 [MethodImplAttribute (MethodImplOptions.NoInlining)]
468 public static void objrefs () {
469 Tests t = new Tests () {};
470 set_child (t);
471 t.objrefs1 ();
472 t.child = null;
473 GC.Collect ();
474 objrefs2 ();
477 [MethodImplAttribute (MethodImplOptions.NoInlining)]
478 public static void set_child (Tests t) {
479 t.child = new Tests ();
482 [MethodImplAttribute (MethodImplOptions.NoInlining)]
483 public void objrefs1 () {
486 [MethodImplAttribute (MethodImplOptions.NoInlining)]
487 public static void objrefs2 () {
490 public static void vtypes () {
491 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 }};
492 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
493 AStruct[] arr = new AStruct[] {
494 new AStruct () { i = 1, s = "S1" },
495 new AStruct () { i = 2, s = "S2" } };
496 t.vtypes1 (s, arr);
497 vtypes2 (s);
498 vtypes3 (s);
501 [MethodImplAttribute (MethodImplOptions.NoInlining)]
502 public object vtypes1 (AStruct s, AStruct[] arr) {
503 if (arr != null)
504 return this;
505 else
506 return null;
509 [MethodImplAttribute (MethodImplOptions.NoInlining)]
510 public static void vtypes2 (AStruct s) {
511 s.foo (5);
514 [MethodImplAttribute (MethodImplOptions.NoInlining)]
515 public static void vtypes3 (AStruct s) {
516 AStruct.static_foo (5);
519 [MethodImplAttribute (MethodImplOptions.NoInlining)]
520 public static void locals () {
521 string s = null;
522 locals1 (null);
523 locals2<string> (null, 5, "ABC", ref s);
524 locals3 ();
525 locals6 ();
528 [MethodImplAttribute (MethodImplOptions.NoInlining)]
529 static void locals11 (double a, ref double b) {
532 [MethodImplAttribute (MethodImplOptions.NoInlining)]
533 public static void locals1 (string[] args) {
534 long foo = 42;
536 double ri = 1;
537 locals11 (b: ref ri, a: ri);
539 for (int j = 0; j < 10; ++j) {
540 foo ++;
544 [MethodImplAttribute (MethodImplOptions.NoInlining)]
545 [StateMachine (typeof (int))]
546 public static void locals2<T> (string[] args, int arg, T t, ref string rs) {
547 long i = 42;
548 string s = "AB";
550 for (int j = 0; j < 10; ++j) {
551 if (s != null)
552 i ++;
553 if (t != null)
554 i ++;
556 rs = "A";
559 [MethodImplAttribute (MethodImplOptions.NoInlining)]
560 public static void locals3 () {
561 string s = "B";
562 s.ToString ();
565 long i = 42;
566 i ++;
567 locals4 ();
570 string i = "A";
571 i.ToString ();
572 locals5 ();
575 long j = 42;
576 j ++;
580 [MethodImplAttribute (MethodImplOptions.NoInlining)]
581 public static void locals4 () {
584 [MethodImplAttribute (MethodImplOptions.NoInlining)]
585 public static void locals5 () {
588 [MethodImplAttribute (MethodImplOptions.NoInlining)]
589 public static void locals6 () {
590 int i = 0;
591 int j = 0;
592 for (i = 0; i < 10; ++i)
593 j ++;
594 sbyte sb = 0;
595 for (i = 0; i < 10; ++i)
596 sb ++;
597 locals6_1 ();
598 locals6_2 (j);
599 locals6_3 ();
600 locals6_4 (j);
601 locals6_5 ();
602 locals6_6 (sb);
605 [MethodImplAttribute (MethodImplOptions.NoInlining)]
606 public static void locals6_1 () {
609 [MethodImplAttribute (MethodImplOptions.NoInlining)]
610 public static void locals6_2 (int arg) {
613 [MethodImplAttribute (MethodImplOptions.NoInlining)]
614 public static void locals6_3 () {
615 // Clobber all registers
616 int sum = 0, i, j, k, l, m;
617 for (i = 0; i < 100; ++i)
618 sum ++;
619 for (j = 0; j < 100; ++j)
620 sum ++;
621 for (k = 0; k < 100; ++k)
622 sum ++;
623 for (l = 0; l < 100; ++l)
624 sum ++;
625 for (m = 0; m < 100; ++m)
626 sum ++;
629 [MethodImplAttribute (MethodImplOptions.NoInlining)]
630 public static void locals6_4 (int arg) {
633 [MethodImplAttribute (MethodImplOptions.NoInlining)]
634 public static void locals6_5 () {
637 [MethodImplAttribute (MethodImplOptions.NoInlining)]
638 public static void locals6_6 (int arg) {
641 [MethodImplAttribute (MethodImplOptions.NoInlining)]
642 public static void line_numbers () {
643 LineNumbers.ln1 ();
646 [MethodImplAttribute (MethodImplOptions.NoInlining)]
647 public static void suspend () {
648 long i = 5;
650 while (true) {
651 i ++;
655 [MethodImplAttribute (MethodImplOptions.NoInlining)]
656 public static void type_info () {
657 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
658 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
659 int val = 0;
660 unsafe {
661 AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
663 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);
667 [MethodImplAttribute (MethodImplOptions.NoInlining)]
668 public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
669 if (t == null || gc1 == null || gc2 == null)
670 return null;
671 else
672 return this;
675 [MethodImplAttribute (MethodImplOptions.NoInlining)]
676 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) {
677 return s2 [0] + s3 [0] + s4 [0, 0];
680 [MethodImplAttribute (MethodImplOptions.NoInlining)]
681 public static void assembly_load () {
682 assembly_load_2 ();
685 [MethodImplAttribute (MethodImplOptions.NoInlining)]
686 public static void assembly_load_2 () {
687 // This will load System.dll while holding the loader lock
688 new Foo ();
691 [MethodImplAttribute (MethodImplOptions.NoInlining)]
692 public static void invoke () {
693 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }, new GStruct<int> { j = 42 });
694 new Tests ().invoke_ex ();
697 [MethodImplAttribute (MethodImplOptions.NoInlining)]
698 public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
699 invoke2 ();
702 [MethodImplAttribute (MethodImplOptions.NoInlining)]
703 public void invoke2 () {
706 [MethodImplAttribute (MethodImplOptions.NoInlining)]
707 public void invoke_ex () {
708 invoke_ex_inner ();
711 [MethodImplAttribute (MethodImplOptions.NoInlining)]
712 public void invoke_ex_inner () {
713 try {
714 throw new Exception ();
715 } catch {
719 int counter;
721 [MethodImplAttribute (MethodImplOptions.NoInlining)]
722 public void invoke_single_threaded () {
723 // Spawn a thread incrementing a counter
724 bool finished = false;
726 new Thread (delegate () {
727 while (!finished)
728 counter ++;
729 }).Start ();
731 Thread.Sleep (100);
733 invoke_single_threaded_2 ();
735 finished = true;
738 [MethodImplAttribute (MethodImplOptions.NoInlining)]
739 public void invoke_single_threaded_2 () {
742 public void invoke_return_void () {
745 public string invoke_return_ref () {
746 return "ABC";
749 public object invoke_return_null () {
750 return null;
753 public int invoke_return_primitive () {
754 return 42;
757 public int? invoke_return_nullable () {
758 return 42;
761 public int? invoke_return_nullable_null () {
762 return null;
765 public void invoke_type_load () {
766 new Class3 ();
769 class Class3 {
772 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) {
773 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
776 public int invoke_pass_primitive2 (bool b) {
777 return b ? 1 : 0;
780 public string invoke_pass_ref (string s) {
781 return s;
784 public static string invoke_static_pass_ref (string s) {
785 return s;
788 public static void invoke_static_return_void () {
791 public static void invoke_throws () {
792 throw new Exception ();
795 [MethodImplAttribute (MethodImplOptions.NoInlining)]
796 public static void exceptions () {
797 try {
798 throw new OverflowException ();
799 } catch (Exception) {
801 try {
802 throw new OverflowException ();
803 } catch (Exception) {
805 try {
806 throw new ArgumentException ();
807 } catch (Exception) {
809 try {
810 throw new OverflowException ();
811 } catch (Exception) {
814 object o = null;
815 try {
816 o.GetType ();
817 } catch (Exception) {
820 try {
821 exceptions2 ();
822 } catch (Exception) {
826 [MethodImplAttribute (MethodImplOptions.NoInlining)]
827 public static void unhandled_exception () {
828 ThreadPool.QueueUserWorkItem (delegate {
829 throw new InvalidOperationException ();
831 Thread.Sleep (10000);
834 [MethodImplAttribute (MethodImplOptions.NoInlining)]
835 public static void unhandled_exception_endinvoke_2 () {
838 [MethodImplAttribute (MethodImplOptions.NoInlining)]
839 public static void unhandled_exception_endinvoke () {
840 Action action = new Action (() =>
842 throw new Exception ("thrown");
844 action.BeginInvoke ((ar) => {
845 try {
846 action.EndInvoke (ar);
847 } catch (Exception ex) {
848 //Console.WriteLine (ex);
850 }, null);
851 Thread.Sleep (1000);
852 unhandled_exception_endinvoke_2 ();
855 [MethodImplAttribute (MethodImplOptions.NoInlining)]
856 public static void unhandled_exception_user () {
857 #if NET_4_5
858 System.Threading.Tasks.Task.Factory.StartNew (() => {
859 Throw ();
861 Thread.Sleep (10000);
862 #endif
865 [MethodImplAttribute (MethodImplOptions.NoInlining)]
866 public static void Throw () {
867 throw new Exception ();
870 internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
872 if (dlg == null)
873 throw new ArgumentNullException ();
874 if (dlg.Target != null)
875 throw new ArgumentException ();
876 if (dlg.Method == null)
877 throw new ArgumentException ();
879 var ret_type = dlg.Method.ReturnType;
880 var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();
882 var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
883 var ig = dynamic.GetILGenerator ();
885 LocalBuilder retval = null;
886 if (ret_type != typeof (void))
887 retval = ig.DeclareLocal (ret_type);
889 var label = ig.BeginExceptionBlock ();
891 for (int i = 0; i < param_types.Length; i++)
892 ig.Emit (OpCodes.Ldarg, i);
893 ig.Emit (OpCodes.Call, dlg.Method);
895 if (retval != null)
896 ig.Emit (OpCodes.Stloc, retval);
898 ig.Emit (OpCodes.Leave, label);
900 ig.BeginExceptFilterBlock ();
902 ig.Emit (OpCodes.Call, filter_method);
904 ig.BeginCatchBlock (null);
906 ig.Emit (OpCodes.Pop);
908 ig.EndExceptionBlock ();
910 if (retval != null)
911 ig.Emit (OpCodes.Ldloc, retval);
913 ig.Emit (OpCodes.Ret);
915 return dynamic.CreateDelegate (dlg.GetType ());
918 [MethodImplAttribute (MethodImplOptions.NoInlining)]
919 static void exception_filter_method () {
920 throw new InvalidOperationException ();
923 [MethodImplAttribute (MethodImplOptions.NoInlining)]
924 static int exception_filter_filter (Exception exc) {
925 return 1;
928 [MethodImplAttribute (MethodImplOptions.NoInlining)]
929 public static void exception_filter () {
930 var method = typeof (Tests).GetMethod (
931 "exception_filter_method", BindingFlags.NonPublic | BindingFlags.Static);
932 var filter_method = typeof (Tests).GetMethod (
933 "exception_filter_filter", BindingFlags.NonPublic | BindingFlags.Static);
935 var dlg = Delegate.CreateDelegate (typeof (Action), method);
937 var wrapper = (Action) create_filter_delegate (dlg, filter_method);
939 wrapper ();
942 [MethodImplAttribute (MethodImplOptions.NoInlining)]
943 public static bool return_true () {
944 return true;
947 [MethodImplAttribute (MethodImplOptions.NoInlining)]
948 public static void exceptions2 () {
949 if (return_true ())
950 throw new Exception ();
951 Console.WriteLine ();
954 [MethodImplAttribute (MethodImplOptions.NoInlining)]
955 public static void threads () {
956 Thread t = new Thread (delegate () {});
958 t.Start ();
959 t.Join ();
962 [MethodImplAttribute (MethodImplOptions.NoInlining)]
963 public static void domains () {
964 AppDomain domain = AppDomain.CreateDomain ("domain");
966 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
967 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
969 domains_2 (o, new CrossDomain ());
971 o.invoke_2 ();
973 o.invoke ();
975 o.invoke_2 ();
977 AppDomain.Unload (domain);
979 domains_3 ();
982 [MethodImplAttribute (MethodImplOptions.NoInlining)]
983 public static void domains_2 (object o, object o2) {
986 [MethodImplAttribute (MethodImplOptions.NoInlining)]
987 public static void domains_3 () {
990 [MethodImplAttribute (MethodImplOptions.NoInlining)]
991 public static void invoke_in_domain () {
994 [MethodImplAttribute (MethodImplOptions.NoInlining)]
995 public static void invoke_in_domain_2 () {
998 [MethodImplAttribute (MethodImplOptions.NoInlining)]
999 public static void dynamic_methods () {
1000 var m = new DynamicMethod ("dyn_method", typeof (void), new Type [] { typeof (int) }, typeof (object).Module);
1001 var ig = m.GetILGenerator ();
1003 ig.Emit (OpCodes.Ldstr, "FOO");
1004 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
1005 ig.Emit (OpCodes.Ret);
1007 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
1009 del (0);
1012 public static void dyn_call (string s) {
1015 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1016 public static void ref_emit () {
1017 AssemblyName assemblyName = new AssemblyName ();
1018 assemblyName.Name = "foo";
1020 AssemblyBuilder assembly =
1021 Thread.GetDomain ().DefineDynamicAssembly (
1022 assemblyName, AssemblyBuilderAccess.RunAndSave);
1024 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
1026 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
1027 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
1028 ILGenerator ig = mb.GetILGenerator ();
1029 ig.Emit (OpCodes.Ldstr, "FOO");
1030 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
1031 ig.Emit (OpCodes.Ret);
1033 Type t = tb.CreateType ();
1035 t.GetMethod ("ref_emit_method").Invoke (null, null);
1038 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1039 public static void ref_emit_call (string s) {
1042 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1043 public static void frames_in_native () {
1044 Thread.Sleep (500);
1045 var evt = new ManualResetEvent (false);
1047 object mon = new object ();
1048 ThreadPool.QueueUserWorkItem (delegate {
1049 frames_in_native_2 ();
1050 evt.Set ();
1052 evt.WaitOne ();
1055 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1056 static void frames_in_native_2 () {
1057 frames_in_native_3 ();
1060 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1061 static void frames_in_native_3 () {
1064 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1065 public static void string_call (string s) {
1068 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1069 public static void ss_regress_654694 () {
1070 if (true) {
1071 string h = "hi";
1072 string_call (h);
1076 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1077 public static void user () {
1078 Debugger.Break ();
1080 Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
1083 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1084 public static void type_load () {
1085 type_load_2 ();
1088 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1089 static void type_load_2 () {
1090 var c1 = new Dictionary<int, int> ();
1091 c1.ToString ();
1092 var c = new TypeLoadClass ();
1093 c.ToString ();
1094 var c2 = new TypeLoadClass2 ();
1095 c2.ToString ();
1098 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1099 public static void regress () {
1100 regress_2755 (DateTime.Now);
1103 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1104 public static unsafe void regress_2755 (DateTime d) {
1105 int* buffer = stackalloc int [128];
1107 regress_2755_2 ();
1109 int sum = 0;
1110 for (int i = 0; i < 128; ++i)
1111 sum += buffer [i];
1113 regress_2755_3 (sum);
1116 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1117 public static void regress_2755_2 () {
1120 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1121 public static void regress_2755_3 (int sum) {
1124 static object gc_suspend_field;
1126 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1127 static unsafe void set_gc_suspend_field () {
1128 set_gc_suspend_field_2 ();
1129 // Clear stack
1130 int* buffer = stackalloc int [4096];
1133 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1134 static void set_gc_suspend_field_2 () {
1135 gc_suspend_field = new object ();
1138 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1139 static void gc_suspend_1 () {
1142 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1143 public static void gc_suspend_invoke () {
1144 gc_suspend_field = null;
1145 GC.Collect ();
1146 GC.WaitForPendingFinalizers ();
1149 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1150 public static void gc_suspend () {
1151 set_gc_suspend_field ();
1152 gc_suspend_1 ();
1156 class TypeLoadClass {
1159 class TypeLoadClass2 {
1162 public class CrossDomain : MarshalByRefObject
1164 public void invoke () {
1165 Tests.invoke_in_domain ();
1168 public void invoke_2 () {
1169 Tests.invoke_in_domain_2 ();
1172 public int invoke_3 () {
1173 return 42;
1177 public class Foo
1179 public ProcessStartInfo info;
1182 // Class used for line number info testing, don't change its layout
1183 public class LineNumbers
1185 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1186 public static void ln1 () {
1187 // Column 3
1188 ln2 ();
1189 ln3 ();
1192 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1193 public static void ln2 () {
1196 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1197 public static void ln3 () {
1198 #pragma warning disable 0219
1199 int i = 5;
1200 #pragma warning restore 0219
1201 #line 55 "FOO"