4 * Application program used by the debugger tests.
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;
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
32 [DebuggerDisplay ("Tests", Name="FOO", Target=typeof (int))]
33 [DebuggerTypeProxy (typeof (Tests))]
35 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
37 public static int static_field_j;
39 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
40 public int AProperty {
46 public void invoke () {
50 public struct AStruct {
56 [MethodImplAttribute (MethodImplOptions.NoInlining)]
57 public int foo (int val) {
61 [MethodImplAttribute (MethodImplOptions.NoInlining)]
62 public static int static_foo (int val) {
66 [MethodImplAttribute (MethodImplOptions.NoInlining)]
67 public int invoke_return_int () {
71 [MethodImplAttribute (MethodImplOptions.NoInlining)]
72 public static int invoke_static () {
76 [MethodImplAttribute (MethodImplOptions.NoInlining)]
77 public IntPtr invoke_return_intptr () {
82 public class GClass<T> {
84 public static T static_field;
86 [MethodImplAttribute (MethodImplOptions.NoInlining)]
91 public struct GStruct<T> {
96 [MethodImplAttribute (MethodImplOptions.NoInlining)]
97 public int invoke_return_int () {
102 public class Tests : TestsBase
104 #pragma warning disable 0414
108 bool field_bool1, field_bool2;
120 static int static_i = 55;
121 static string static_s = "A";
122 public const int literal_i = 56;
123 public const string literal_s = "B";
125 public AStruct field_struct;
126 public object field_boxed_struct;
127 public GStruct<int> generic_field_struct;
129 public static int tls_i;
130 public static bool is_attached = Debugger.IsAttached;
132 #pragma warning restore 0414
134 public class NestedClass {
137 public int IntProperty {
146 public int ReadOnlyProperty {
152 public int this [int index] {
158 public static int Main (String[] args) {
159 if (args.Length > 0 && args [0] == "suspend-test")
160 /* This contains an infinite loop, so execute it conditionally */
176 if (args.Length > 0 && args [0] == "domain-test")
177 /* This takes a lot of time, so execute it conditionally */
179 if (args.Length > 0 && args [0] == "ref-emit-test")
181 if (args.Length > 0 && args [0] == "frames-in-native")
183 if (args.Length >0 && args [0] == "invoke-single-threaded")
184 new Tests ().invoke_single_threaded ();
188 public static void breakpoints () {
189 /* Call these early so it is JITted by the time a breakpoint is placed on it */
206 [MethodImplAttribute (MethodImplOptions.NoInlining)]
207 public static void bp1 () {
210 [MethodImplAttribute (MethodImplOptions.NoInlining)]
211 public static void bp2 () {
214 [MethodImplAttribute (MethodImplOptions.NoInlining)]
215 public static void bp3 () {
218 [MethodImplAttribute (MethodImplOptions.NoInlining)]
219 public static void bp4 () {
222 [MethodImplAttribute (MethodImplOptions.NoInlining)]
223 public static void bp5 () {
226 [MethodImplAttribute (MethodImplOptions.NoInlining)]
227 public static void bp6<T> () {
230 [MethodImplAttribute (MethodImplOptions.NoInlining)]
231 public static void bp7<T> () {
234 [MethodImplAttribute (MethodImplOptions.NoInlining)]
235 public static void single_stepping () {
241 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
248 [MethodImplAttribute (MethodImplOptions.NoInlining)]
249 public static void ss1 () {
252 [MethodImplAttribute (MethodImplOptions.NoInlining)]
253 public static void ss2 () {
256 [MethodImplAttribute (MethodImplOptions.NoInlining)]
257 public static int ss3 () {
260 for (int i = 0; i < 10; ++i)
266 [MethodImplAttribute (MethodImplOptions.NoInlining)]
267 public static void ss3_2 () {
271 [MethodImplAttribute (MethodImplOptions.NoInlining)]
272 public static void ss3_2_2 () {
275 [MethodImplAttribute (MethodImplOptions.NoInlining)]
276 public static int ss4 () {
282 [MethodImplAttribute (MethodImplOptions.NoInlining)]
283 public static void ss5 (int[] arr, Func<int, bool> selector) {
284 // Call into linq which calls back into this assembly
285 arr.Count (selector);
288 [MethodImplAttribute (MethodImplOptions.NoInlining)]
289 public static void ss6 (bool b) {
292 throw new Exception ();
296 [MethodImplAttribute (MethodImplOptions.NoInlining)]
297 public static void ss7 () {
300 [MethodImplAttribute (MethodImplOptions.NoInlining)]
301 public static bool is_even (int i) {
307 Console.WriteLine ("HIT!");
313 [MethodImplAttribute (MethodImplOptions.NoInlining)]
314 public static void arguments () {
315 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));
317 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object ());
318 Tests t = new Tests () { field_i = 42, field_s = "S" };
322 [MethodImplAttribute (MethodImplOptions.NoInlining)]
323 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) {
324 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
327 [MethodImplAttribute (MethodImplOptions.NoInlining)]
328 public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2) {
329 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
332 [MethodImplAttribute (MethodImplOptions.NoInlining)]
333 public object arg3 (string s) {
334 return s + s + s + s + this;
337 [MethodImplAttribute (MethodImplOptions.NoInlining)]
338 public static void objects () {
339 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) };
340 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
341 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 });
344 [MethodImplAttribute (MethodImplOptions.NoInlining)]
345 public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
346 if (t == null || gc1 == null || gc2 == null)
352 [MethodImplAttribute (MethodImplOptions.NoInlining)]
353 public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
354 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
357 [MethodImplAttribute (MethodImplOptions.NoInlining)]
358 public static void objrefs () {
359 Tests t = new Tests () {};
367 [MethodImplAttribute (MethodImplOptions.NoInlining)]
368 public static void set_child (Tests t) {
369 t.child = new Tests ();
372 [MethodImplAttribute (MethodImplOptions.NoInlining)]
373 public void objrefs1 () {
376 [MethodImplAttribute (MethodImplOptions.NoInlining)]
377 public static void objrefs2 () {
380 public static void vtypes () {
381 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 }};
382 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
383 AStruct[] arr = new AStruct[] {
384 new AStruct () { i = 1, s = "S1" },
385 new AStruct () { i = 2, s = "S2" } };
391 [MethodImplAttribute (MethodImplOptions.NoInlining)]
392 public object vtypes1 (AStruct s, AStruct[] arr) {
399 [MethodImplAttribute (MethodImplOptions.NoInlining)]
400 public static void vtypes2 (AStruct s) {
404 [MethodImplAttribute (MethodImplOptions.NoInlining)]
405 public static void vtypes3 (AStruct s) {
406 AStruct.static_foo (5);
409 [MethodImplAttribute (MethodImplOptions.NoInlining)]
410 public static void locals () {
416 [MethodImplAttribute (MethodImplOptions.NoInlining)]
417 public static void locals1 (string[] args) {
420 for (int j = 0; j < 10; ++j) {
425 [MethodImplAttribute (MethodImplOptions.NoInlining)]
426 public static void locals2 (string[] args, int arg) {
430 for (int j = 0; j < 10; ++j) {
436 [MethodImplAttribute (MethodImplOptions.NoInlining)]
437 public static void locals3 () {
457 [MethodImplAttribute (MethodImplOptions.NoInlining)]
458 public static void locals4 () {
461 [MethodImplAttribute (MethodImplOptions.NoInlining)]
462 public static void locals5 () {
465 [MethodImplAttribute (MethodImplOptions.NoInlining)]
466 public static void line_numbers () {
470 [MethodImplAttribute (MethodImplOptions.NoInlining)]
471 public static void suspend () {
479 [MethodImplAttribute (MethodImplOptions.NoInlining)]
480 public static void type_info () {
481 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
482 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
485 AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
487 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);
491 [MethodImplAttribute (MethodImplOptions.NoInlining)]
492 public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
493 if (t == null || gc1 == null || gc2 == null)
499 [MethodImplAttribute (MethodImplOptions.NoInlining)]
500 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) {
501 return s2 [0] + s3 [0] + s4 [0, 0];
504 [MethodImplAttribute (MethodImplOptions.NoInlining)]
505 public static void assembly_load () {
509 [MethodImplAttribute (MethodImplOptions.NoInlining)]
510 public static void assembly_load_2 () {
511 // This will load System.dll while holding the loader lock
515 [MethodImplAttribute (MethodImplOptions.NoInlining)]
516 public static void invoke () {
517 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }, new GStruct<int> { j = 42 });
518 new Tests ().invoke_ex ();
521 [MethodImplAttribute (MethodImplOptions.NoInlining)]
522 public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
526 [MethodImplAttribute (MethodImplOptions.NoInlining)]
527 public void invoke2 () {
530 [MethodImplAttribute (MethodImplOptions.NoInlining)]
531 public void invoke_ex () {
535 [MethodImplAttribute (MethodImplOptions.NoInlining)]
536 public void invoke_ex_inner () {
538 throw new Exception ();
545 [MethodImplAttribute (MethodImplOptions.NoInlining)]
546 public void invoke_single_threaded () {
547 // Spawn a thread incrementing a counter
548 bool finished = false;
550 new Thread (delegate () {
557 invoke_single_threaded_2 ();
562 [MethodImplAttribute (MethodImplOptions.NoInlining)]
563 public void invoke_single_threaded_2 () {
566 public void invoke_return_void () {
569 public string invoke_return_ref () {
573 public object invoke_return_null () {
577 public int invoke_return_primitive () {
581 public void invoke_type_load () {
588 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) {
589 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
592 public int invoke_pass_primitive2 (bool b) {
596 public string invoke_pass_ref (string s) {
600 public static string invoke_static_pass_ref (string s) {
604 public static void invoke_static_return_void () {
607 public static void invoke_throws () {
608 throw new Exception ();
611 [MethodImplAttribute (MethodImplOptions.NoInlining)]
612 public static void exceptions () {
614 throw new OverflowException ();
615 } catch (Exception) {
618 throw new OverflowException ();
619 } catch (Exception) {
622 throw new ArgumentException ();
623 } catch (Exception) {
626 throw new OverflowException ();
627 } catch (Exception) {
633 } catch (Exception) {
637 [MethodImplAttribute (MethodImplOptions.NoInlining)]
638 public static void threads () {
639 Thread t = new Thread (delegate () {});
645 [MethodImplAttribute (MethodImplOptions.NoInlining)]
646 public static void domains () {
647 AppDomain domain = AppDomain.CreateDomain ("domain");
649 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
650 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
658 AppDomain.Unload (domain);
663 [MethodImplAttribute (MethodImplOptions.NoInlining)]
664 public static void domains_2 () {
667 [MethodImplAttribute (MethodImplOptions.NoInlining)]
668 public static void invoke_in_domain () {
671 [MethodImplAttribute (MethodImplOptions.NoInlining)]
672 public static void invoke_in_domain_2 () {
675 [MethodImplAttribute (MethodImplOptions.NoInlining)]
676 public static void dynamic_methods () {
677 var m = new DynamicMethod ("dyn_method", typeof (void), new Type [] { typeof (int) }, typeof (object).Module);
678 var ig = m.GetILGenerator ();
680 ig.Emit (OpCodes.Ldstr, "FOO");
681 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
682 ig.Emit (OpCodes.Ret);
684 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
689 public static void dyn_call (string s) {
692 [MethodImplAttribute (MethodImplOptions.NoInlining)]
693 public static void ref_emit () {
694 AssemblyName assemblyName = new AssemblyName ();
695 assemblyName.Name = "foo";
697 AssemblyBuilder assembly =
698 Thread.GetDomain ().DefineDynamicAssembly (
699 assemblyName, AssemblyBuilderAccess.RunAndSave);
701 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
703 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
704 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
705 ILGenerator ig = mb.GetILGenerator ();
706 ig.Emit (OpCodes.Ldstr, "FOO");
707 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
708 ig.Emit (OpCodes.Ret);
710 Type t = tb.CreateType ();
712 t.GetMethod ("ref_emit_method").Invoke (null, null);
715 [MethodImplAttribute (MethodImplOptions.NoInlining)]
716 public static void ref_emit_call (string s) {
719 [MethodImplAttribute (MethodImplOptions.NoInlining)]
720 public static void frames_in_native () {
725 public class CrossDomain : MarshalByRefObject
727 public void invoke () {
728 Tests.invoke_in_domain ();
731 public void invoke_2 () {
732 Tests.invoke_in_domain_2 ();
738 public ProcessStartInfo info;
741 // Class used for line number info testing, don't change its layout
742 public class LineNumbers
744 [MethodImplAttribute (MethodImplOptions.NoInlining)]
745 public static void ln1 () {
750 [MethodImplAttribute (MethodImplOptions.NoInlining)]
751 public static void ln2 () {
754 [MethodImplAttribute (MethodImplOptions.NoInlining)]
755 public static void ln3 () {