From a878333ecdfae5b09e87abcf082b3f398d3e5668 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Tue, 7 Feb 2017 18:35:20 -0500 Subject: [PATCH] [sdb] Add an attach test, not yet enabled. --- .../Mono.Debugger.Soft/Test/dtest-app.cs | 30 +++++- mcs/class/Mono.Debugger.Soft/Test/dtest.cs | 100 +++++++++++++++--- 2 files changed, 113 insertions(+), 17 deletions(-) diff --git a/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs b/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs index 6cfa088437f..400b43ce34f 100644 --- a/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs +++ b/mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs @@ -13,7 +13,6 @@ using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; using System.Net.Sockets; -using System.Threading.Tasks; using MonoTests.Helpers; public class TestsBase @@ -319,6 +318,10 @@ public class Tests : TestsBase, ITest2 threadpool_io (); return 0; } + if (args.Length > 0 && args [0] == "attach") { + new Tests ().attach (); + return 0; + } assembly_load (); breakpoints (); single_stepping (); @@ -1688,6 +1691,26 @@ public class Tests : TestsBase, ITest2 streamOut.Close (); var bsIn = t.Result; } + + [MethodImplAttribute (MethodImplOptions.NoInlining)] + public void attach_break () { + } + + [MethodImplAttribute (MethodImplOptions.NoInlining)] + public void attach () { + AppDomain domain = AppDomain.CreateDomain ("domain"); + + CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap ( + typeof (CrossDomain).Assembly.FullName, "CrossDomain"); + o.assembly_load (); + o.type_load (); + + // Wait for the client to attach + while (true) { + Thread.Sleep (200); + attach_break (); + } + } } public class SentinelClass : MarshalByRefObject { @@ -1712,6 +1735,11 @@ public class CrossDomain : MarshalByRefObject public void assembly_load () { Tests.assembly_load_in_domain (); } + + public void type_load () { + //Activator.CreateInstance (typeof (int).Assembly.GetType ("Microsoft.Win32.RegistryOptions")); + var is_server = System.Runtime.GCSettings.IsServerGC; + } } public class Foo diff --git a/mcs/class/Mono.Debugger.Soft/Test/dtest.cs b/mcs/class/Mono.Debugger.Soft/Test/dtest.cs index 61b3e310881..631b5985db1 100644 --- a/mcs/class/Mono.Debugger.Soft/Test/dtest.cs +++ b/mcs/class/Mono.Debugger.Soft/Test/dtest.cs @@ -63,25 +63,30 @@ public class DebuggerTests Start (false, args); } + Diag.ProcessStartInfo CreateStartInfo (string[] args) { + var pi = new Diag.ProcessStartInfo (); + + if (runtime != null) { + pi.FileName = runtime; + } else if (Path.DirectorySeparatorChar == '\\') { + string processExe = Diag.Process.GetCurrentProcess ().MainModule.FileName; + if (processExe != null) { + string fileName = Path.GetFileName (processExe); + if (fileName.StartsWith ("mono") && fileName.EndsWith (".exe")) + pi.FileName = processExe; + } + } + if (string.IsNullOrEmpty (pi.FileName)) + pi.FileName = "mono"; + pi.Arguments = String.Join (" ", args); + return pi; + } + void Start (bool forceExit, params string[] args) { this.forceExit = forceExit; if (!listening) { - var pi = new Diag.ProcessStartInfo (); - - if (runtime != null) { - pi.FileName = runtime; - } else if (Path.DirectorySeparatorChar == '\\') { - string processExe = Diag.Process.GetCurrentProcess ().MainModule.FileName; - if (processExe != null) { - string fileName = Path.GetFileName (processExe); - if (fileName.StartsWith ("mono") && fileName.EndsWith (".exe")) - pi.FileName = processExe; - } - } - if (string.IsNullOrEmpty (pi.FileName)) - pi.FileName = "mono"; - pi.Arguments = String.Join (" ", args); + var pi = CreateStartInfo (args); vm = VirtualMachineManager.Launch (pi, new LaunchOptions { AgentArgs = agent_args }); } else { var ep = new IPEndPoint (IPAddress.Any, 10000); @@ -4251,7 +4256,7 @@ public class DebuggerTests vm.SetBreakpoint (cctor, 0); vm.Resume (); - var e = vm.GetNextEvent (); + var e = GetNextEvent (); Assert.IsTrue (e is BreakpointEvent); var req = create_step (e); @@ -4276,6 +4281,69 @@ public class DebuggerTests e = step_out (); // leave threadpool_bp e = step_out (); // leave threadpool_io } + + [Test] + // Uses a fixed port + [Category("NotWorking")] + public void Attach () { + vm.Exit (0); + + // Launch the app using server=y,suspend=n + var pi = CreateStartInfo (new string[] { "--debugger-agent=transport=dt_socket,address=127.0.0.1:10000,server=y,suspend=n", "dtest-app.exe", "attach" }); + var process = Diag.Process.Start (pi); + + // Wait for the app to reach the Sleep () in attach (). + Thread.Sleep (1000); + var ep = new IPEndPoint (IPAddress.Loopback, 10000); + vm = VirtualMachineManager.Connect (ep); + + var load_req = vm.CreateAssemblyLoadRequest (); + load_req.Enable (); + vm.EnableEvents (EventType.TypeLoad); + + Event vmstart = GetNextEvent (); + Assert.AreEqual (EventType.VMStart, vmstart.EventType); + + // Get collected events + bool assembly_load_found = false; + bool type_load_found = false; + while (true) { + Event e = GetNextEvent (); + + // AssemblyLoad + if (e is AssemblyLoadEvent) { + var assemblyload = e as AssemblyLoadEvent; + + var amirror = assemblyload.Assembly; + + if (amirror.GetName ().Name == "System.Transactions") { + assembly_load_found = true; + Assert.AreEqual ("domain", amirror.Domain.FriendlyName); + } + + if (amirror.GetName ().Name == "dtest-app") + // Set a bp so we can break the event loop + vm.SetBreakpoint (amirror.EntryPoint.DeclaringType.GetMethod ("attach_break"), 0); + } + if (e is TypeLoadEvent) { + var typeload = e as TypeLoadEvent; + + if (typeload.Type.Name == "GCSettings") { + type_load_found = true; + Assert.AreEqual ("domain", typeload.Type.Assembly.Domain.FriendlyName); + } + } + + if (e is BreakpointEvent) + break; + } + Assert.IsTrue (assembly_load_found); + Assert.IsTrue (type_load_found); + + vm.Exit (0); + vm = null; + } + } } -- 2.25.1