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 {
55 [MethodImplAttribute (MethodImplOptions.NoInlining)]
56 public int foo (int val) {
60 [MethodImplAttribute (MethodImplOptions.NoInlining)]
61 public static int static_foo (int val) {
65 [MethodImplAttribute (MethodImplOptions.NoInlining)]
66 public int invoke_return_int () {
71 public class GClass<T> {
73 public static T static_field;
75 [MethodImplAttribute (MethodImplOptions.NoInlining)]
80 public struct GStruct<T> {
84 public class Tests : TestsBase
86 #pragma warning disable 0414
90 bool field_bool1, field_bool2;
101 static int static_i = 55;
102 static string static_s = "A";
103 public const int literal_i = 56;
104 public const string literal_s = "B";
106 public AStruct field_struct;
107 public object field_boxed_struct;
108 public GStruct<int> generic_field_struct;
110 public static int tls_i;
111 public static bool is_attached = Debugger.IsAttached;
113 #pragma warning restore 0414
115 public class NestedClass {
118 public int IntProperty {
127 public int ReadOnlyProperty {
133 public int this [int index] {
139 public static int Main (String[] args) {
140 if (args.Length > 0 && args [0] == "suspend-test")
141 /* This contains an infinite loop, so execute it conditionally */
157 if (args.Length > 0 && args [0] == "domain-test")
158 /* This takes a lot of time, so execute it conditionally */
160 if (args.Length > 0 && args [0] == "ref-emit-test")
162 if (args.Length > 0 && args [0] == "frames-in-native")
164 if (args.Length >0 && args [0] == "invoke-single-threaded")
165 new Tests ().invoke_single_threaded ();
169 public static void breakpoints () {
170 /* Call these early so it is JITted by the time a breakpoint is placed on it */
187 [MethodImplAttribute (MethodImplOptions.NoInlining)]
188 public static void bp1 () {
191 [MethodImplAttribute (MethodImplOptions.NoInlining)]
192 public static void bp2 () {
195 [MethodImplAttribute (MethodImplOptions.NoInlining)]
196 public static void bp3 () {
199 [MethodImplAttribute (MethodImplOptions.NoInlining)]
200 public static void bp4 () {
203 [MethodImplAttribute (MethodImplOptions.NoInlining)]
204 public static void bp5 () {
207 [MethodImplAttribute (MethodImplOptions.NoInlining)]
208 public static void bp6<T> () {
211 [MethodImplAttribute (MethodImplOptions.NoInlining)]
212 public static void bp7<T> () {
215 [MethodImplAttribute (MethodImplOptions.NoInlining)]
216 public static void single_stepping () {
221 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
224 [MethodImplAttribute (MethodImplOptions.NoInlining)]
225 public static void ss1 () {
228 [MethodImplAttribute (MethodImplOptions.NoInlining)]
229 public static void ss2 () {
232 [MethodImplAttribute (MethodImplOptions.NoInlining)]
233 public static int ss3 () {
236 for (int i = 0; i < 10; ++i)
242 [MethodImplAttribute (MethodImplOptions.NoInlining)]
243 public static int ss4 () {
249 [MethodImplAttribute (MethodImplOptions.NoInlining)]
250 public static void ss5 (int[] arr, Func<int, bool> selector) {
251 // Call into linq which calls back into this assembly
252 arr.Count (selector);
255 [MethodImplAttribute (MethodImplOptions.NoInlining)]
256 public static bool is_even (int i) {
262 Console.WriteLine ("HIT!");
268 [MethodImplAttribute (MethodImplOptions.NoInlining)]
269 public static void arguments () {
270 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));
272 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object ());
273 Tests t = new Tests () { field_i = 42, field_s = "S" };
277 [MethodImplAttribute (MethodImplOptions.NoInlining)]
278 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) {
279 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
282 [MethodImplAttribute (MethodImplOptions.NoInlining)]
283 public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2) {
284 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
287 [MethodImplAttribute (MethodImplOptions.NoInlining)]
288 public object arg3 (string s) {
289 return s + s + s + s + this;
292 [MethodImplAttribute (MethodImplOptions.NoInlining)]
293 public static void objects () {
294 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 };
295 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
296 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 });
299 [MethodImplAttribute (MethodImplOptions.NoInlining)]
300 public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
301 if (t == null || gc1 == null || gc2 == null)
307 [MethodImplAttribute (MethodImplOptions.NoInlining)]
308 public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
309 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
312 [MethodImplAttribute (MethodImplOptions.NoInlining)]
313 public static void objrefs () {
314 Tests t = new Tests () {};
322 [MethodImplAttribute (MethodImplOptions.NoInlining)]
323 public static void set_child (Tests t) {
324 t.child = new Tests ();
327 [MethodImplAttribute (MethodImplOptions.NoInlining)]
328 public void objrefs1 () {
331 [MethodImplAttribute (MethodImplOptions.NoInlining)]
332 public static void objrefs2 () {
335 public static void vtypes () {
336 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 }};
337 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
338 AStruct[] arr = new AStruct[] {
339 new AStruct () { i = 1, s = "S1" },
340 new AStruct () { i = 2, s = "S2" } };
346 [MethodImplAttribute (MethodImplOptions.NoInlining)]
347 public object vtypes1 (AStruct s, AStruct[] arr) {
354 [MethodImplAttribute (MethodImplOptions.NoInlining)]
355 public static void vtypes2 (AStruct s) {
359 [MethodImplAttribute (MethodImplOptions.NoInlining)]
360 public static void vtypes3 (AStruct s) {
361 AStruct.static_foo (5);
364 [MethodImplAttribute (MethodImplOptions.NoInlining)]
365 public static void locals () {
370 [MethodImplAttribute (MethodImplOptions.NoInlining)]
371 public static void locals1 (string[] args) {
374 for (int j = 0; j < 10; ++j) {
379 [MethodImplAttribute (MethodImplOptions.NoInlining)]
380 public static void locals2 (string[] args, int arg) {
384 for (int j = 0; j < 10; ++j) {
390 [MethodImplAttribute (MethodImplOptions.NoInlining)]
391 public static void line_numbers () {
395 [MethodImplAttribute (MethodImplOptions.NoInlining)]
396 public static void suspend () {
404 [MethodImplAttribute (MethodImplOptions.NoInlining)]
405 public static void type_info () {
406 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
407 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
410 AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
412 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> ());
416 [MethodImplAttribute (MethodImplOptions.NoInlining)]
417 public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
418 if (t == null || gc1 == null || gc2 == null)
424 [MethodImplAttribute (MethodImplOptions.NoInlining)]
425 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) {
426 return s2 [0] + s3 [0] + s4 [0, 0];
429 [MethodImplAttribute (MethodImplOptions.NoInlining)]
430 public static void assembly_load () {
434 [MethodImplAttribute (MethodImplOptions.NoInlining)]
435 public static void assembly_load_2 () {
436 // This will load System.dll while holding the loader lock
440 [MethodImplAttribute (MethodImplOptions.NoInlining)]
441 public static void invoke () {
442 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42 });
445 [MethodImplAttribute (MethodImplOptions.NoInlining)]
446 public void invoke1 (Tests2 t, AStruct s) {
450 [MethodImplAttribute (MethodImplOptions.NoInlining)]
451 public void invoke2 () {
456 [MethodImplAttribute (MethodImplOptions.NoInlining)]
457 public void invoke_single_threaded () {
458 // Spawn a thread incrementing a counter
459 bool finished = false;
461 new Thread (delegate () {
468 invoke_single_threaded_2 ();
473 [MethodImplAttribute (MethodImplOptions.NoInlining)]
474 public void invoke_single_threaded_2 () {
477 public void invoke_return_void () {
480 public string invoke_return_ref () {
484 public object invoke_return_null () {
488 public int invoke_return_primitive () {
492 public void invoke_type_load () {
499 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) {
500 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
503 public int invoke_pass_primitive2 (bool b) {
507 public string invoke_pass_ref (string s) {
511 public static string invoke_static_pass_ref (string s) {
515 public static void invoke_static_return_void () {
518 public static void invoke_throws () {
519 throw new Exception ();
522 [MethodImplAttribute (MethodImplOptions.NoInlining)]
523 public static void exceptions () {
525 throw new OverflowException ();
526 } catch (Exception) {
529 throw new OverflowException ();
530 } catch (Exception) {
533 throw new ArgumentException ();
534 } catch (Exception) {
540 } catch (Exception) {
544 [MethodImplAttribute (MethodImplOptions.NoInlining)]
545 public static void threads () {
546 Thread t = new Thread (delegate () {});
552 [MethodImplAttribute (MethodImplOptions.NoInlining)]
553 public static void domains () {
554 AppDomain domain = AppDomain.CreateDomain ("domain");
556 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
557 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
561 AppDomain.Unload (domain);
566 [MethodImplAttribute (MethodImplOptions.NoInlining)]
567 public static void domains_2 () {
570 [MethodImplAttribute (MethodImplOptions.NoInlining)]
571 public static void invoke_in_domain () {
574 [MethodImplAttribute (MethodImplOptions.NoInlining)]
575 public static void dynamic_methods () {
576 var m = new DynamicMethod ("dyn_method", typeof (void), new Type [] { typeof (int) }, typeof (object).Module);
577 var ig = m.GetILGenerator ();
579 ig.Emit (OpCodes.Ldstr, "FOO");
580 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
581 ig.Emit (OpCodes.Ret);
583 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
588 public static void dyn_call (string s) {
591 [MethodImplAttribute (MethodImplOptions.NoInlining)]
592 public static void ref_emit () {
593 AssemblyName assemblyName = new AssemblyName ();
594 assemblyName.Name = "foo";
596 AssemblyBuilder assembly =
597 Thread.GetDomain ().DefineDynamicAssembly (
598 assemblyName, AssemblyBuilderAccess.RunAndSave);
600 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
602 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
603 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
604 ILGenerator ig = mb.GetILGenerator ();
605 ig.Emit (OpCodes.Ldstr, "FOO");
606 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
607 ig.Emit (OpCodes.Ret);
609 Type t = tb.CreateType ();
611 t.GetMethod ("ref_emit_method").Invoke (null, null);
614 [MethodImplAttribute (MethodImplOptions.NoInlining)]
615 public static void ref_emit_call (string s) {
618 [MethodImplAttribute (MethodImplOptions.NoInlining)]
619 public static void frames_in_native () {
624 public class CrossDomain : MarshalByRefObject
626 public void invoke () {
627 Tests.invoke_in_domain ();
633 public ProcessStartInfo info;
636 // Class used for line number info testing, don't change its layout
637 public class LineNumbers
639 [MethodImplAttribute (MethodImplOptions.NoInlining)]
640 public static void ln1 () {
645 [MethodImplAttribute (MethodImplOptions.NoInlining)]
646 public static void ln2 () {
649 [MethodImplAttribute (MethodImplOptions.NoInlining)]
650 public static void ln3 () {