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;
102 static int static_i = 55;
103 static string static_s = "A";
104 public const int literal_i = 56;
105 public const string literal_s = "B";
107 public AStruct field_struct;
108 public object field_boxed_struct;
109 public GStruct<int> generic_field_struct;
111 public static int tls_i;
112 public static bool is_attached = Debugger.IsAttached;
114 #pragma warning restore 0414
116 public class NestedClass {
119 public int IntProperty {
128 public int ReadOnlyProperty {
134 public int this [int index] {
140 public static int Main (String[] args) {
141 if (args.Length > 0 && args [0] == "suspend-test")
142 /* This contains an infinite loop, so execute it conditionally */
158 if (args.Length > 0 && args [0] == "domain-test")
159 /* This takes a lot of time, so execute it conditionally */
161 if (args.Length > 0 && args [0] == "ref-emit-test")
163 if (args.Length > 0 && args [0] == "frames-in-native")
165 if (args.Length >0 && args [0] == "invoke-single-threaded")
166 new Tests ().invoke_single_threaded ();
170 public static void breakpoints () {
171 /* Call these early so it is JITted by the time a breakpoint is placed on it */
188 [MethodImplAttribute (MethodImplOptions.NoInlining)]
189 public static void bp1 () {
192 [MethodImplAttribute (MethodImplOptions.NoInlining)]
193 public static void bp2 () {
196 [MethodImplAttribute (MethodImplOptions.NoInlining)]
197 public static void bp3 () {
200 [MethodImplAttribute (MethodImplOptions.NoInlining)]
201 public static void bp4 () {
204 [MethodImplAttribute (MethodImplOptions.NoInlining)]
205 public static void bp5 () {
208 [MethodImplAttribute (MethodImplOptions.NoInlining)]
209 public static void bp6<T> () {
212 [MethodImplAttribute (MethodImplOptions.NoInlining)]
213 public static void bp7<T> () {
216 [MethodImplAttribute (MethodImplOptions.NoInlining)]
217 public static void single_stepping () {
222 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
225 [MethodImplAttribute (MethodImplOptions.NoInlining)]
226 public static void ss1 () {
229 [MethodImplAttribute (MethodImplOptions.NoInlining)]
230 public static void ss2 () {
233 [MethodImplAttribute (MethodImplOptions.NoInlining)]
234 public static int ss3 () {
237 for (int i = 0; i < 10; ++i)
243 [MethodImplAttribute (MethodImplOptions.NoInlining)]
244 public static int ss4 () {
250 [MethodImplAttribute (MethodImplOptions.NoInlining)]
251 public static void ss5 (int[] arr, Func<int, bool> selector) {
252 // Call into linq which calls back into this assembly
253 arr.Count (selector);
256 [MethodImplAttribute (MethodImplOptions.NoInlining)]
257 public static bool is_even (int i) {
263 Console.WriteLine ("HIT!");
269 [MethodImplAttribute (MethodImplOptions.NoInlining)]
270 public static void arguments () {
271 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));
273 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object ());
274 Tests t = new Tests () { field_i = 42, field_s = "S" };
278 [MethodImplAttribute (MethodImplOptions.NoInlining)]
279 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) {
280 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
283 [MethodImplAttribute (MethodImplOptions.NoInlining)]
284 public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2) {
285 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
288 [MethodImplAttribute (MethodImplOptions.NoInlining)]
289 public object arg3 (string s) {
290 return s + s + s + s + this;
293 [MethodImplAttribute (MethodImplOptions.NoInlining)]
294 public static void objects () {
295 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) };
296 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
297 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 });
300 [MethodImplAttribute (MethodImplOptions.NoInlining)]
301 public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
302 if (t == null || gc1 == null || gc2 == null)
308 [MethodImplAttribute (MethodImplOptions.NoInlining)]
309 public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
310 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
313 [MethodImplAttribute (MethodImplOptions.NoInlining)]
314 public static void objrefs () {
315 Tests t = new Tests () {};
323 [MethodImplAttribute (MethodImplOptions.NoInlining)]
324 public static void set_child (Tests t) {
325 t.child = new Tests ();
328 [MethodImplAttribute (MethodImplOptions.NoInlining)]
329 public void objrefs1 () {
332 [MethodImplAttribute (MethodImplOptions.NoInlining)]
333 public static void objrefs2 () {
336 public static void vtypes () {
337 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 }};
338 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
339 AStruct[] arr = new AStruct[] {
340 new AStruct () { i = 1, s = "S1" },
341 new AStruct () { i = 2, s = "S2" } };
347 [MethodImplAttribute (MethodImplOptions.NoInlining)]
348 public object vtypes1 (AStruct s, AStruct[] arr) {
355 [MethodImplAttribute (MethodImplOptions.NoInlining)]
356 public static void vtypes2 (AStruct s) {
360 [MethodImplAttribute (MethodImplOptions.NoInlining)]
361 public static void vtypes3 (AStruct s) {
362 AStruct.static_foo (5);
365 [MethodImplAttribute (MethodImplOptions.NoInlining)]
366 public static void locals () {
371 [MethodImplAttribute (MethodImplOptions.NoInlining)]
372 public static void locals1 (string[] args) {
375 for (int j = 0; j < 10; ++j) {
380 [MethodImplAttribute (MethodImplOptions.NoInlining)]
381 public static void locals2 (string[] args, int arg) {
385 for (int j = 0; j < 10; ++j) {
391 [MethodImplAttribute (MethodImplOptions.NoInlining)]
392 public static void line_numbers () {
396 [MethodImplAttribute (MethodImplOptions.NoInlining)]
397 public static void suspend () {
405 [MethodImplAttribute (MethodImplOptions.NoInlining)]
406 public static void type_info () {
407 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
408 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
411 AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
413 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> ());
417 [MethodImplAttribute (MethodImplOptions.NoInlining)]
418 public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
419 if (t == null || gc1 == null || gc2 == null)
425 [MethodImplAttribute (MethodImplOptions.NoInlining)]
426 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) {
427 return s2 [0] + s3 [0] + s4 [0, 0];
430 [MethodImplAttribute (MethodImplOptions.NoInlining)]
431 public static void assembly_load () {
435 [MethodImplAttribute (MethodImplOptions.NoInlining)]
436 public static void assembly_load_2 () {
437 // This will load System.dll while holding the loader lock
441 [MethodImplAttribute (MethodImplOptions.NoInlining)]
442 public static void invoke () {
443 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42 });
446 [MethodImplAttribute (MethodImplOptions.NoInlining)]
447 public void invoke1 (Tests2 t, AStruct s) {
451 [MethodImplAttribute (MethodImplOptions.NoInlining)]
452 public void invoke2 () {
457 [MethodImplAttribute (MethodImplOptions.NoInlining)]
458 public void invoke_single_threaded () {
459 // Spawn a thread incrementing a counter
460 bool finished = false;
462 new Thread (delegate () {
469 invoke_single_threaded_2 ();
474 [MethodImplAttribute (MethodImplOptions.NoInlining)]
475 public void invoke_single_threaded_2 () {
478 public void invoke_return_void () {
481 public string invoke_return_ref () {
485 public object invoke_return_null () {
489 public int invoke_return_primitive () {
493 public void invoke_type_load () {
500 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) {
501 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
504 public int invoke_pass_primitive2 (bool b) {
508 public string invoke_pass_ref (string s) {
512 public static string invoke_static_pass_ref (string s) {
516 public static void invoke_static_return_void () {
519 public static void invoke_throws () {
520 throw new Exception ();
523 [MethodImplAttribute (MethodImplOptions.NoInlining)]
524 public static void exceptions () {
526 throw new OverflowException ();
527 } catch (Exception) {
530 throw new OverflowException ();
531 } catch (Exception) {
534 throw new ArgumentException ();
535 } catch (Exception) {
541 } catch (Exception) {
545 [MethodImplAttribute (MethodImplOptions.NoInlining)]
546 public static void threads () {
547 Thread t = new Thread (delegate () {});
553 [MethodImplAttribute (MethodImplOptions.NoInlining)]
554 public static void domains () {
555 AppDomain domain = AppDomain.CreateDomain ("domain");
557 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
558 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
562 AppDomain.Unload (domain);
567 [MethodImplAttribute (MethodImplOptions.NoInlining)]
568 public static void domains_2 () {
571 [MethodImplAttribute (MethodImplOptions.NoInlining)]
572 public static void invoke_in_domain () {
575 [MethodImplAttribute (MethodImplOptions.NoInlining)]
576 public static void dynamic_methods () {
577 var m = new DynamicMethod ("dyn_method", typeof (void), new Type [] { typeof (int) }, typeof (object).Module);
578 var ig = m.GetILGenerator ();
580 ig.Emit (OpCodes.Ldstr, "FOO");
581 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
582 ig.Emit (OpCodes.Ret);
584 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
589 public static void dyn_call (string s) {
592 [MethodImplAttribute (MethodImplOptions.NoInlining)]
593 public static void ref_emit () {
594 AssemblyName assemblyName = new AssemblyName ();
595 assemblyName.Name = "foo";
597 AssemblyBuilder assembly =
598 Thread.GetDomain ().DefineDynamicAssembly (
599 assemblyName, AssemblyBuilderAccess.RunAndSave);
601 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
603 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
604 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
605 ILGenerator ig = mb.GetILGenerator ();
606 ig.Emit (OpCodes.Ldstr, "FOO");
607 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
608 ig.Emit (OpCodes.Ret);
610 Type t = tb.CreateType ();
612 t.GetMethod ("ref_emit_method").Invoke (null, null);
615 [MethodImplAttribute (MethodImplOptions.NoInlining)]
616 public static void ref_emit_call (string s) {
619 [MethodImplAttribute (MethodImplOptions.NoInlining)]
620 public static void frames_in_native () {
625 public class CrossDomain : MarshalByRefObject
627 public void invoke () {
628 Tests.invoke_in_domain ();
634 public ProcessStartInfo info;
637 // Class used for line number info testing, don't change its layout
638 public class LineNumbers
640 [MethodImplAttribute (MethodImplOptions.NoInlining)]
641 public static void ln1 () {
646 [MethodImplAttribute (MethodImplOptions.NoInlining)]
647 public static void ln2 () {
650 [MethodImplAttribute (MethodImplOptions.NoInlining)]
651 public static void ln3 () {