Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Filippov <mikhail@filippov.me>2019-02-28 21:29:30 +0300
committerAlexander Köplinger <alex.koeplinger@outlook.com>2019-02-28 21:29:30 +0300
commitf512a68edca1dbf2997e3c6b9f738c74bc634639 (patch)
tree1b3007dae956f6dc2638bb64f5c90fd86c451f58 /mcs/class/Mono.Debugger.Soft
parenta4eee021952f965c2fd789868be5f6887db1f696 (diff)
[Mono.Debugger.Soft] Add new debugger tests and fix the Attach() test (#9091)
* Fixed the Attach() test which required a free port to attach. * Added test for incorrect events behavior when VM is started with suspend * Bump API snapshot submodule
Diffstat (limited to 'mcs/class/Mono.Debugger.Soft')
-rw-r--r--mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs15
-rw-r--r--mcs/class/Mono.Debugger.Soft/Test/dtest.cs130
2 files changed, 138 insertions, 7 deletions
diff --git a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs
index caa732000ab..f3819c2c50b 100644
--- a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs
+++ b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs
@@ -109,6 +109,21 @@ namespace Mono.Debugger.Soft
}
}
+ public EventSet GetNextEventSet (int timeoutInMilliseconds) {
+ lock (queue_monitor) {
+ if (queue.Count == 0) {
+ if (!Monitor.Wait (queue_monitor, timeoutInMilliseconds)) {
+ return null;
+ }
+ }
+
+ current_es = null;
+ current_es_index = 0;
+
+ return (EventSet)queue.Dequeue ();
+ }
+ }
+
[Obsolete ("Use GetNextEventSet () instead")]
public T GetNextEvent<T> () where T : Event {
return GetNextEvent () as T;
diff --git a/mcs/class/Mono.Debugger.Soft/Test/dtest.cs b/mcs/class/Mono.Debugger.Soft/Test/dtest.cs
index b0c0de5c832..411677cec4d 100644
--- a/mcs/class/Mono.Debugger.Soft/Test/dtest.cs
+++ b/mcs/class/Mono.Debugger.Soft/Test/dtest.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Threading;
using System.Net;
+using System.Net.Sockets;
using System.Reflection;
using System.Text;
using Mono.Cecil.Cil;
@@ -4602,6 +4603,21 @@ public class DebuggerTests
assert_location(e, "ss_nested_arg");
}
+ static int GetFreePort () {
+ var s = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ s.Bind (new IPEndPoint (IPAddress.Loopback, 0));
+ var port = ((IPEndPoint)s.LocalEndPoint).Port;
+ s.Close ();
+ return port;
+ }
+
+ static VirtualMachine ConnectToPort (int port) {
+ var ep = new IPEndPoint (IPAddress.Loopback, port);
+ // Wait for the app to reach the Sleep () in attach ().
+ Thread.Sleep (1000);
+ return VirtualMachineManager.Connect (ep);
+ }
+
[Test]
public void InspectEnumeratorInGenericStruct() {
//files.myBucket.GetEnumerator().get_Current().Key watching this generates an exception in Debugger
@@ -4639,19 +4655,16 @@ public class DebuggerTests
}
[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_path, "attach" });
+ var port = GetFreePort ();
+ var pi = CreateStartInfo (new string[] { $"--debugger-agent=transport=dt_socket,address=127.0.0.1:{port},server=y,suspend=n", dtest_app_path, "attach" });
+ pi.UseShellExecute = false;
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);
+ vm = ConnectToPort (port);
var load_req = vm.CreateAssemblyLoadRequest ();
load_req.Enable ();
@@ -4846,5 +4859,108 @@ public class DebuggerTests
e = step_into ();
Assert.IsTrue ((e as StepEvent).Method.Name == "op_Equality" || (e as StepEvent).Method.Name == "if_property_stepping");
}
+
+ void HandleEvents () {
+ string failMessage = null;
+ var alreadyStopped = false;
+ while (true) {
+ var nextEventSet = vm.GetNextEventSet (5000);
+ if (nextEventSet == null)
+ break;
+
+ foreach (var e in nextEventSet.Events) {
+ if (e.EventType == EventType.AssemblyLoad) {
+ var assemblyload = e as AssemblyLoadEvent;
+ var amirror = assemblyload.Assembly;
+ if (amirror.GetName ().Name.Contains ("dtest-app")) {
+ var methodMirror = amirror.EntryPoint.DeclaringType.GetMethod ("attach_break");
+ vm.SetBreakpoint (methodMirror, 0);
+ }
+ }
+
+ if (e.EventType == EventType.TypeLoad) {
+ Assert.Fail ("Unexpected TypeLoadEvent");
+ }
+
+ if (e.EventType == EventType.Breakpoint) {
+ var typeLoadRequest = vm.CreateTypeLoadRequest ();
+ typeLoadRequest.SourceFileFilter = new[] {"dtest-app.cs"};
+ typeLoadRequest.Enable ();
+
+ if (alreadyStopped) {
+ Assert.Fail ("Unexpected BreakpointEvent");
+ }
+
+ alreadyStopped = true;
+ continue;
+ }
+
+ try {
+ vm.Resume ();
+ }
+ catch (VMNotSuspendedException ex) {
+ failMessage = ex.Message;
+ }
+ }
+ }
+
+ if (failMessage != null)
+ Assert.Fail (failMessage);
+ }
+
+ void ShouldNotSendUnexpectedTypeLoadEventsAndInvalidSuspendPolicyAfterAttach (int port) {
+ string failMessage = null;
+ try {
+ vm = ConnectToPort (port);
+
+ vm.EnableEvents (EventType.AssemblyLoad, EventType.ThreadStart);
+ var vmstart = GetNextEvent ();
+ Assert.AreEqual (EventType.VMStart, vmstart.EventType);
+ try {
+ vm.Resume ();
+ }
+ catch (VMNotSuspendedException e)
+ {
+ failMessage = e.Message;
+ }
+ HandleEvents ();
+ }
+ catch (Exception ex) {
+ failMessage = ex.Message;
+ }
+ finally {
+ vm.Exit (0);
+ vm = null;
+ }
+ if (failMessage != null)
+ Assert.Fail (failMessage);
+ }
+
+ [Test]
+ public void ShouldNotSendUnexpectedTypeLoadEventsAndInvalidSuspendPolicyAfterAttachIfSuspendIsTrue() {
+ vm.Exit (0);
+ var port = GetFreePort ();
+
+ // Launch the app using server=y,suspend=y
+ var pi = CreateStartInfo (new string[] { $"--debugger-agent=transport=dt_socket,address=127.0.0.1:{port},server=y,suspend=y", dtest_app_path, "attach" });
+ pi.UseShellExecute = false;
+ var process = Diag.Process.Start (pi);
+
+ ShouldNotSendUnexpectedTypeLoadEventsAndInvalidSuspendPolicyAfterAttach (port);
+ }
+
+ [Test]
+ [Category("NotWorking")]
+ public void ShouldNotSendUnexpectedTypeLoadEventsAndInvalidSuspendPolicyAfterAttachIfSuspendIsFalse() {
+ vm.Exit (0);
+ var port = GetFreePort ();
+
+ // Launch the app using server=y,suspend=n
+ var pi = CreateStartInfo (new string[] { $"--debugger-agent=transport=dt_socket,address=127.0.0.1:{port},server=y,suspend=n", dtest_app_path, "attach" });
+ pi.UseShellExecute = false;
+ var process = Diag.Process.Start (pi);
+
+ ShouldNotSendUnexpectedTypeLoadEventsAndInvalidSuspendPolicyAfterAttach (port);
+ }
} // class DebuggerTests
} // namespace