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 IntPtr invoke_return_intptr () {
77 public class GClass<T> {
79 public static T static_field;
81 [MethodImplAttribute (MethodImplOptions.NoInlining)]
86 public struct GStruct<T> {
90 public class Tests : TestsBase
92 #pragma warning disable 0414
96 bool field_bool1, field_bool2;
108 static int static_i = 55;
109 static string static_s = "A";
110 public const int literal_i = 56;
111 public const string literal_s = "B";
113 public AStruct field_struct;
114 public object field_boxed_struct;
115 public GStruct<int> generic_field_struct;
117 public static int tls_i;
118 public static bool is_attached = Debugger.IsAttached;
120 #pragma warning restore 0414
122 public class NestedClass {
125 public int IntProperty {
134 public int ReadOnlyProperty {
140 public int this [int index] {
146 public static int Main (String[] args) {
147 if (args.Length > 0 && args [0] == "suspend-test")
148 /* This contains an infinite loop, so execute it conditionally */
164 if (args.Length > 0 && args [0] == "domain-test")
165 /* This takes a lot of time, so execute it conditionally */
167 if (args.Length > 0 && args [0] == "ref-emit-test")
169 if (args.Length > 0 && args [0] == "frames-in-native")
171 if (args.Length >0 && args [0] == "invoke-single-threaded")
172 new Tests ().invoke_single_threaded ();
176 public static void breakpoints () {
177 /* Call these early so it is JITted by the time a breakpoint is placed on it */
194 [MethodImplAttribute (MethodImplOptions.NoInlining)]
195 public static void bp1 () {
198 [MethodImplAttribute (MethodImplOptions.NoInlining)]
199 public static void bp2 () {
202 [MethodImplAttribute (MethodImplOptions.NoInlining)]
203 public static void bp3 () {
206 [MethodImplAttribute (MethodImplOptions.NoInlining)]
207 public static void bp4 () {
210 [MethodImplAttribute (MethodImplOptions.NoInlining)]
211 public static void bp5 () {
214 [MethodImplAttribute (MethodImplOptions.NoInlining)]
215 public static void bp6<T> () {
218 [MethodImplAttribute (MethodImplOptions.NoInlining)]
219 public static void bp7<T> () {
222 [MethodImplAttribute (MethodImplOptions.NoInlining)]
223 public static void single_stepping () {
229 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
236 [MethodImplAttribute (MethodImplOptions.NoInlining)]
237 public static void ss1 () {
240 [MethodImplAttribute (MethodImplOptions.NoInlining)]
241 public static void ss2 () {
244 [MethodImplAttribute (MethodImplOptions.NoInlining)]
245 public static int ss3 () {
248 for (int i = 0; i < 10; ++i)
254 [MethodImplAttribute (MethodImplOptions.NoInlining)]
255 public static void ss3_2 () {
259 [MethodImplAttribute (MethodImplOptions.NoInlining)]
260 public static void ss3_2_2 () {
263 [MethodImplAttribute (MethodImplOptions.NoInlining)]
264 public static int ss4 () {
270 [MethodImplAttribute (MethodImplOptions.NoInlining)]
271 public static void ss5 (int[] arr, Func<int, bool> selector) {
272 // Call into linq which calls back into this assembly
273 arr.Count (selector);
276 [MethodImplAttribute (MethodImplOptions.NoInlining)]
277 public static void ss6 (bool b) {
280 throw new Exception ();
284 [MethodImplAttribute (MethodImplOptions.NoInlining)]
285 public static void ss7 () {
288 [MethodImplAttribute (MethodImplOptions.NoInlining)]
289 public static bool is_even (int i) {
295 Console.WriteLine ("HIT!");
301 [MethodImplAttribute (MethodImplOptions.NoInlining)]
302 public static void arguments () {
303 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));
305 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object ());
306 Tests t = new Tests () { field_i = 42, field_s = "S" };
310 [MethodImplAttribute (MethodImplOptions.NoInlining)]
311 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) {
312 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
315 [MethodImplAttribute (MethodImplOptions.NoInlining)]
316 public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2) {
317 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
320 [MethodImplAttribute (MethodImplOptions.NoInlining)]
321 public object arg3 (string s) {
322 return s + s + s + s + this;
325 [MethodImplAttribute (MethodImplOptions.NoInlining)]
326 public static void objects () {
327 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) };
328 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
329 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 });
332 [MethodImplAttribute (MethodImplOptions.NoInlining)]
333 public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
334 if (t == null || gc1 == null || gc2 == null)
340 [MethodImplAttribute (MethodImplOptions.NoInlining)]
341 public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
342 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
345 [MethodImplAttribute (MethodImplOptions.NoInlining)]
346 public static void objrefs () {
347 Tests t = new Tests () {};
355 [MethodImplAttribute (MethodImplOptions.NoInlining)]
356 public static void set_child (Tests t) {
357 t.child = new Tests ();
360 [MethodImplAttribute (MethodImplOptions.NoInlining)]
361 public void objrefs1 () {
364 [MethodImplAttribute (MethodImplOptions.NoInlining)]
365 public static void objrefs2 () {
368 public static void vtypes () {
369 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 }};
370 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
371 AStruct[] arr = new AStruct[] {
372 new AStruct () { i = 1, s = "S1" },
373 new AStruct () { i = 2, s = "S2" } };
379 [MethodImplAttribute (MethodImplOptions.NoInlining)]
380 public object vtypes1 (AStruct s, AStruct[] arr) {
387 [MethodImplAttribute (MethodImplOptions.NoInlining)]
388 public static void vtypes2 (AStruct s) {
392 [MethodImplAttribute (MethodImplOptions.NoInlining)]
393 public static void vtypes3 (AStruct s) {
394 AStruct.static_foo (5);
397 [MethodImplAttribute (MethodImplOptions.NoInlining)]
398 public static void locals () {
403 [MethodImplAttribute (MethodImplOptions.NoInlining)]
404 public static void locals1 (string[] args) {
407 for (int j = 0; j < 10; ++j) {
412 [MethodImplAttribute (MethodImplOptions.NoInlining)]
413 public static void locals2 (string[] args, int arg) {
417 for (int j = 0; j < 10; ++j) {
423 [MethodImplAttribute (MethodImplOptions.NoInlining)]
424 public static void line_numbers () {
428 [MethodImplAttribute (MethodImplOptions.NoInlining)]
429 public static void suspend () {
437 [MethodImplAttribute (MethodImplOptions.NoInlining)]
438 public static void type_info () {
439 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
440 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
443 AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
445 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);
449 [MethodImplAttribute (MethodImplOptions.NoInlining)]
450 public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
451 if (t == null || gc1 == null || gc2 == null)
457 [MethodImplAttribute (MethodImplOptions.NoInlining)]
458 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) {
459 return s2 [0] + s3 [0] + s4 [0, 0];
462 [MethodImplAttribute (MethodImplOptions.NoInlining)]
463 public static void assembly_load () {
467 [MethodImplAttribute (MethodImplOptions.NoInlining)]
468 public static void assembly_load_2 () {
469 // This will load System.dll while holding the loader lock
473 [MethodImplAttribute (MethodImplOptions.NoInlining)]
474 public static void invoke () {
475 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 });
478 [MethodImplAttribute (MethodImplOptions.NoInlining)]
479 public void invoke1 (Tests2 t, AStruct s) {
483 [MethodImplAttribute (MethodImplOptions.NoInlining)]
484 public void invoke2 () {
489 [MethodImplAttribute (MethodImplOptions.NoInlining)]
490 public void invoke_single_threaded () {
491 // Spawn a thread incrementing a counter
492 bool finished = false;
494 new Thread (delegate () {
501 invoke_single_threaded_2 ();
506 [MethodImplAttribute (MethodImplOptions.NoInlining)]
507 public void invoke_single_threaded_2 () {
510 public void invoke_return_void () {
513 public string invoke_return_ref () {
517 public object invoke_return_null () {
521 public int invoke_return_primitive () {
525 public void invoke_type_load () {
532 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) {
533 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
536 public int invoke_pass_primitive2 (bool b) {
540 public string invoke_pass_ref (string s) {
544 public static string invoke_static_pass_ref (string s) {
548 public static void invoke_static_return_void () {
551 public static void invoke_throws () {
552 throw new Exception ();
555 [MethodImplAttribute (MethodImplOptions.NoInlining)]
556 public static void exceptions () {
558 throw new OverflowException ();
559 } catch (Exception) {
562 throw new OverflowException ();
563 } catch (Exception) {
566 throw new ArgumentException ();
567 } catch (Exception) {
570 throw new OverflowException ();
571 } catch (Exception) {
577 } catch (Exception) {
581 [MethodImplAttribute (MethodImplOptions.NoInlining)]
582 public static void threads () {
583 Thread t = new Thread (delegate () {});
589 [MethodImplAttribute (MethodImplOptions.NoInlining)]
590 public static void domains () {
591 AppDomain domain = AppDomain.CreateDomain ("domain");
593 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
594 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
598 AppDomain.Unload (domain);
603 [MethodImplAttribute (MethodImplOptions.NoInlining)]
604 public static void domains_2 () {
607 [MethodImplAttribute (MethodImplOptions.NoInlining)]
608 public static void invoke_in_domain () {
611 [MethodImplAttribute (MethodImplOptions.NoInlining)]
612 public static void dynamic_methods () {
613 var m = new DynamicMethod ("dyn_method", typeof (void), new Type [] { typeof (int) }, typeof (object).Module);
614 var ig = m.GetILGenerator ();
616 ig.Emit (OpCodes.Ldstr, "FOO");
617 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
618 ig.Emit (OpCodes.Ret);
620 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
625 public static void dyn_call (string s) {
628 [MethodImplAttribute (MethodImplOptions.NoInlining)]
629 public static void ref_emit () {
630 AssemblyName assemblyName = new AssemblyName ();
631 assemblyName.Name = "foo";
633 AssemblyBuilder assembly =
634 Thread.GetDomain ().DefineDynamicAssembly (
635 assemblyName, AssemblyBuilderAccess.RunAndSave);
637 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
639 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
640 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
641 ILGenerator ig = mb.GetILGenerator ();
642 ig.Emit (OpCodes.Ldstr, "FOO");
643 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
644 ig.Emit (OpCodes.Ret);
646 Type t = tb.CreateType ();
648 t.GetMethod ("ref_emit_method").Invoke (null, null);
651 [MethodImplAttribute (MethodImplOptions.NoInlining)]
652 public static void ref_emit_call (string s) {
655 [MethodImplAttribute (MethodImplOptions.NoInlining)]
656 public static void frames_in_native () {
661 public class CrossDomain : MarshalByRefObject
663 public void invoke () {
664 Tests.invoke_in_domain ();
670 public ProcessStartInfo info;
673 // Class used for line number info testing, don't change its layout
674 public class LineNumbers
676 [MethodImplAttribute (MethodImplOptions.NoInlining)]
677 public static void ln1 () {
682 [MethodImplAttribute (MethodImplOptions.NoInlining)]
683 public static void ln2 () {
686 [MethodImplAttribute (MethodImplOptions.NoInlining)]
687 public static void ln3 () {