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

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorMichael Hutchinson <m.j.hutchinson@gmail.com>2011-11-22 06:12:47 +0400
committerMichael Hutchinson <m.j.hutchinson@gmail.com>2011-11-22 22:00:47 +0400
commit3129bd5ef65b8082ceb6f9bf29a342f47d14c15d (patch)
tree10d123c0fa3af6af256b35418d004d88f18386de /main/src
parentfdd1aa076d51841c1331f2468258b59fb90244a4 (diff)
[Debugger] Allow custom soft debugger transports
Diffstat (limited to 'main/src')
-rw-r--r--main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerSession.cs68
-rw-r--r--main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerStartInfo.cs46
2 files changed, 91 insertions, 23 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerSession.cs b/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerSession.cs
index e405b71a3d..e127942b86 100644
--- a/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerSession.cs
+++ b/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerSession.cs
@@ -71,6 +71,7 @@ namespace Mono.Debugging.Soft
Thread errorReader;
IAsyncResult connectionHandle;
+ SoftDebuggerStartArgs startArgs;
LinkedList<List<Event>> queuedEventSets = new LinkedList<List<Event>> ();
@@ -107,11 +108,58 @@ namespace Mono.Debugging.Soft
StartConnecting (dsi);
} else if (dsi.StartArgs is SoftDebuggerListenArgs) {
StartListening (dsi);
+ } else if (dsi.StartArgs.ConnectionProvider != null) {
+ StartConnection (dsi);
} else {
- throw new Exception (string.Format ("Unknown args: {0}", dsi.StartArgs));
+ throw new ArgumentException ("StartArgs has no ConnectionProvider");
}
}
+ void StartConnection (SoftDebuggerStartInfo dsi)
+ {
+ this.startArgs = dsi.StartArgs;
+
+ RegisterUserAssemblies (dsi.UserAssemblyNames);
+
+ if (!String.IsNullOrEmpty (dsi.LogMessage))
+ LogWriter (false, dsi.LogMessage + "\n");
+
+
+ AsyncCallback callback = null;
+ int attemptNumber = 0;
+ int maxAttempts = startArgs.MaxConnectionAttempts;
+ int timeBetweenAttempts = startArgs.TimeBetweenConnectionAttempts;
+ callback = delegate (IAsyncResult ar) {
+ try {
+ string appName;
+ VirtualMachine vm;
+ startArgs.ConnectionProvider.EndConnect (ar, LogWriter, out vm, out appName);
+ this.remoteProcessName = appName;
+ ConnectionStarted (vm);
+ return;
+ } catch (Exception ex) {
+ attemptNumber++;
+ if (!ShouldRetryConnection (ex, attemptNumber)
+ || !startArgs.ConnectionProvider.ShouldRetryConnection (ex)
+ || attemptNumber == maxAttempts
+ || Exited)
+ {
+ OnConnectionError (ex);
+ return;
+ }
+ }
+ try {
+ if (timeBetweenAttempts > 0)
+ System.Threading.Thread.Sleep (timeBetweenAttempts);
+ ConnectionStarting (startArgs.ConnectionProvider.BeginConnect (callback, LogWriter), dsi, false, 0);
+ } catch (Exception ex2) {
+ OnConnectionError (ex2);
+ }
+ };
+ //the "listening" value is never used, pass a dummy value
+ ConnectionStarting (startArgs.ConnectionProvider.BeginConnect (callback, LogWriter), dsi, false, 0);
+ }
+
void StartLaunching (SoftDebuggerStartInfo dsi)
{
var args = (SoftDebuggerLaunchArgs) dsi.StartArgs;
@@ -198,8 +246,7 @@ namespace Mono.Debugging.Soft
protected void StartConnecting (SoftDebuggerStartInfo dsi)
{
- var args = (SoftDebuggerConnectArgs) dsi.StartArgs;
- StartConnecting (dsi, args.MaxConnectionAttempts, args.TimeBetweenConnectionAttempts);
+ StartConnecting (dsi, dsi.StartArgs.MaxConnectionAttempts, dsi.StartArgs.TimeBetweenConnectionAttempts);
}
/// <summary>Starts the debugger connecting to a remote IP</summary>
@@ -246,8 +293,6 @@ namespace Mono.Debugging.Soft
var args = (SoftDebuggerRemoteArgs) dsi.StartArgs;
remoteProcessName = args.AppName;
- if (string.IsNullOrEmpty (remoteProcessName))
- remoteProcessName = "mono";
RegisterUserAssemblies (dsi.UserAssemblyNames);
@@ -277,7 +322,7 @@ namespace Mono.Debugging.Soft
protected virtual void OnConnectionError (Exception ex)
{
//if the exception was caused by cancelling the session
- if (Exited && ex is SocketException)
+ if (Exited)
return;
if (!HandleException (ex)) {
@@ -312,7 +357,12 @@ namespace Mono.Debugging.Soft
{
HideConnectionDialog ();
if (connectionHandle != null) {
- VirtualMachineManager.CancelConnection (connectionHandle);
+ if (startArgs != null && startArgs.ConnectionProvider != null) {
+ startArgs.ConnectionProvider.CancelConnect (connectionHandle);
+ startArgs = null;
+ } else {
+ VirtualMachineManager.CancelConnection (connectionHandle);
+ }
connectionHandle = null;
}
}
@@ -596,8 +646,8 @@ namespace Mono.Debugging.Soft
protected override ProcessInfo[] OnGetProcesses ()
{
if (procs == null) {
- if (remoteProcessName != null) {
- procs = new ProcessInfo[] { new ProcessInfo (0, remoteProcessName) };
+ if (remoteProcessName != null || vm.TargetProcess == null) {
+ procs = new ProcessInfo[] { new ProcessInfo (0, remoteProcessName ?? "mono") };
} else {
try {
procs = new ProcessInfo[] { new ProcessInfo (vm.TargetProcess.Id, vm.TargetProcess.ProcessName) };
diff --git a/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerStartInfo.cs b/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerStartInfo.cs
index 8bbc895b25..049d069994 100644
--- a/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerStartInfo.cs
+++ b/main/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/SoftDebuggerStartInfo.cs
@@ -29,6 +29,7 @@ using System.Collections.Generic;
using System.Reflection;
using System.IO;
using System.Net;
+using Mono.Debugger.Soft;
namespace Mono.Debugging.Soft
{
@@ -63,8 +64,33 @@ namespace Mono.Debugging.Soft
public SoftDebuggerStartArgs StartArgs { get; set; }
}
+ public interface ISoftDebuggerConnectionProvider
+ {
+ IAsyncResult BeginConnect (AsyncCallback callback, OutputWriterDelegate log);
+ void EndConnect (IAsyncResult result, OutputWriterDelegate log, out VirtualMachine vm, out string appName);
+ void CancelConnect (IAsyncResult result);
+ bool ShouldRetryConnection (Exception ex);
+ }
+
public abstract class SoftDebuggerStartArgs
{
+ public SoftDebuggerStartArgs ()
+ {
+ MaxConnectionAttempts = 1;
+ TimeBetweenConnectionAttempts = 500;
+ }
+
+ public abstract ISoftDebuggerConnectionProvider ConnectionProvider { get; }
+
+ /// <summary>
+ /// Maximum number of connection attempts. Zero or less means infinite attempts. Default is 1.
+ /// </summary>
+ public int MaxConnectionAttempts { get; set; }
+
+ /// <summary>
+ /// The time between connection attempts, in milliseconds. Default is 500.
+ /// </summary>
+ public int TimeBetweenConnectionAttempts { get; set; }
}
public abstract class SoftDebuggerRemoteArgs : SoftDebuggerStartArgs
@@ -117,6 +143,8 @@ namespace Mono.Debugging.Soft
: base (appName, address, debugPort, outputPort)
{
}
+
+ public override ISoftDebuggerConnectionProvider ConnectionProvider { get { return null; } }
}
/// <summary>
@@ -134,20 +162,9 @@ namespace Mono.Debugging.Soft
throw new ArgumentException ("Debug port cannot be zero when connecting", "debugPort");
if (outputPort == 0)
throw new ArgumentException ("Output port cannot be zero when connecting", "outputPort");
-
- MaxConnectionAttempts = 1;
- TimeBetweenConnectionAttempts = 500;
}
- /// <summary>
- /// Maximum number of connection attempts. Zero or less means infinite attempts.
- /// </summary>
- public int MaxConnectionAttempts { get; set; }
-
- /// <summary>
- /// Tthe time between connection attempts, in milliseconds.
- /// </summary>
- public int TimeBetweenConnectionAttempts { get; set; }
+ public override ISoftDebuggerConnectionProvider ConnectionProvider { get { return null; } }
}
/// <summary>
@@ -178,6 +195,7 @@ namespace Mono.Debugging.Soft
/// Launcher for the external console. May be null if the app does not run on an external console.
/// </summary>
public Mono.Debugger.Soft.LaunchOptions.TargetProcessLauncher ExternalConsoleLauncher { get; set; }
+
+ public override ISoftDebuggerConnectionProvider ConnectionProvider { get { return null; } }
}
-}
-
+} \ No newline at end of file