Browse Source

Added MyProxy, preparing NDebugger for MTA

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@178 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 21 years ago
parent
commit
563d57b57d
  1. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj
  2. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/Breakpoint.cs
  3. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/MTA2STA.cs
  4. 10
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackProxy.cs
  5. 11
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/RemotingObjectBase.cs
  6. 15
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs
  7. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/Module.cs
  8. 55
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/RemotingSinks/PrivateEventHandlersSink/MyProxy.cs
  9. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs
  10. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs
  11. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs
  12. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/SourcecodeSegment.cs
  13. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs
  14. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj

@ -62,6 +62,8 @@ @@ -62,6 +62,8 @@
<Compile Include="Src\Modules\ModuleEventHandler.cs" />
<Compile Include="Src\Modules\NDebugger-Modules.cs" />
<Compile Include="Src\RemotingSinks\PrivateEventHandlersSink\AsyncMessageResponseSink.cs" />
<Compile Include="Src\RemotingSinks\PrivateEventHandlersSink\MyProxy.cs" />
<Compile Include="Src\Debugger\Internal\RemotingObjectBase.cs" />
<Compile Include="Src\Threads\Exception.cs" />
<Compile Include="Src\Threads\ExceptionType.cs" />
<Compile Include="Src\Threads\Function.cs" />

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/Breakpoint.cs

@ -11,7 +11,7 @@ using DebuggerInterop.Core; @@ -11,7 +11,7 @@ using DebuggerInterop.Core;
namespace DebuggerLibrary
{
public class Breakpoint: MarshalByRefObject
public class Breakpoint: RemotingObjectBase
{
NDebugger debugger;

8
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/MTA2STA.cs

@ -68,6 +68,11 @@ namespace DebuggerInterop.Core @@ -68,6 +68,11 @@ namespace DebuggerInterop.Core
}
void PerformCall(object sender, EventArgs e)
{
returnValue = Call(targetObject, functionName, functionParameters);
}
public object Call (object targetObject, string functionName, object[] functionParameters)
{
MethodInfo method;
object[] outputParams;
@ -107,7 +112,7 @@ namespace DebuggerInterop.Core @@ -107,7 +112,7 @@ namespace DebuggerInterop.Core
}
}
TraceMsg ("Invoke " + functionName + "{");
returnValue = null;
object returnValue = null;
try {
if (targetObject is Type) {
returnValue = method.Invoke(null, outputParams);
@ -118,6 +123,7 @@ namespace DebuggerInterop.Core @@ -118,6 +123,7 @@ namespace DebuggerInterop.Core
System.Diagnostics.Debug.Fail("Invoke of " + functionName + " failed.", exception.ToString());
}
TraceMsg ("} \\\\ Invoke");
return returnValue;
}
}
}

10
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackProxy.cs

@ -21,18 +21,24 @@ namespace DebuggerLibrary @@ -21,18 +21,24 @@ namespace DebuggerLibrary
{
class ManagedCallbackProxy :ICorDebugManagedCallback, ICorDebugManagedCallback2
{
MTA2STA mta2sta;
NDebugger debugger;
ManagedCallback realCallback;
MTA2STA mta2sta;
public ManagedCallbackProxy(ManagedCallback realCallback)
public ManagedCallbackProxy(NDebugger debugger, ManagedCallback realCallback)
{
this.debugger = debugger;
this.realCallback = realCallback;
mta2sta = new MTA2STA();
}
private void CallbackReceived (string function, object[] parameters)
{
if (debugger.RequiredApartmentState == ApartmentState.STA) {
mta2sta.CallInSTA(realCallback, function, parameters);
} else {
mta2sta.Call(realCallback, function, parameters);
}
}

11
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/RemotingObjectBase.cs

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using CustomSinks;
namespace DebuggerLibrary
{
public class RemotingObjectBase: MarshalByRefObject
{
}
}

15
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs

@ -7,13 +7,14 @@ using System.Diagnostics; @@ -7,13 +7,14 @@ using System.Diagnostics;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using DebuggerInterop.Core;
using DebuggerInterop.MetaData;
namespace DebuggerLibrary
{
public partial class NDebugger: MarshalByRefObject
public partial class NDebugger: RemotingObjectBase
{
ICorDebug corDebug;
ManagedCallback managedCallback;
@ -23,6 +24,14 @@ namespace DebuggerLibrary @@ -23,6 +24,14 @@ namespace DebuggerLibrary
public bool CatchHandledExceptions = false;
ApartmentState requiredApartmentState;
public ApartmentState RequiredApartmentState {
get {
return requiredApartmentState;
}
}
internal ICorDebug CorDebug {
get {
return corDebug;
@ -60,6 +69,8 @@ namespace DebuggerLibrary @@ -60,6 +69,8 @@ namespace DebuggerLibrary
public NDebugger()
{
requiredApartmentState = System.Threading.Thread.CurrentThread.GetApartmentState();
InitDebugger();
ResetEnvironment();
@ -82,7 +93,7 @@ namespace DebuggerLibrary @@ -82,7 +93,7 @@ namespace DebuggerLibrary
//corDebug = new CorDebugClass();
managedCallback = new ManagedCallback(this);
managedCallbackProxy = new ManagedCallbackProxy(managedCallback);
managedCallbackProxy = new ManagedCallbackProxy(this, managedCallback);
corDebug.Initialize();
corDebug.SetManagedHandler(managedCallbackProxy);

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/Module.cs

@ -11,7 +11,7 @@ using DebuggerInterop.MetaData; @@ -11,7 +11,7 @@ using DebuggerInterop.MetaData;
namespace DebuggerLibrary
{
public class Module: MarshalByRefObject
public class Module: RemotingObjectBase
{
string fullPath;
ulong baseAdress;

55
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/RemotingSinks/PrivateEventHandlersSink/MyProxy.cs

@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Services;
namespace CustomSinks
{
[AttributeUsage(AttributeTargets.Class)]
public class MyProxyAttribute: ProxyAttribute
{
public override MarshalByRefObject CreateInstance(Type type)
{
Console.WriteLine("Creating proxy of type " + type.ToString());
MarshalByRefObject instance = base.CreateInstance(type);
MyProxy proxy = new MyProxy(type, instance);
return (MarshalByRefObject)proxy.GetTransparentProxy();
}
}
public class MyProxy: RealProxy
{
private MarshalByRefObject realObject;
public MyProxy(Type type, MarshalByRefObject realObject):base(type)
{
this.realObject = realObject;
}
public override IMessage Invoke(IMessage msg)
{
Console.WriteLine("Proxy called: " + msg.Properties["__MethodName"]);
if (msg is IConstructionCallMessage) {
IConstructionCallMessage ctorMsg = (IConstructionCallMessage)msg;
try {
RemotingServices.GetRealProxy(realObject).InitializeServerObject(ctorMsg);
} catch (Exception e) {
}
ObjRef objRef = RemotingServices.Marshal(realObject);
RemotingServices.Unmarshal(objRef);
MarshalByRefObject transpProxy = (MarshalByRefObject)this.GetTransparentProxy();
return EnterpriseServicesHelper.CreateConstructionReturnMessage(ctorMsg, transpProxy);
} else {
return RemotingServices.ExecuteMessage(realObject, (IMethodCallMessage)msg);
}
}
}
}

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs

@ -11,7 +11,7 @@ using DebuggerInterop.MetaData; @@ -11,7 +11,7 @@ using DebuggerInterop.MetaData;
namespace DebuggerLibrary
{
public class Exception: MarshalByRefObject
public class Exception: RemotingObjectBase
{
NDebugger debugger;
Thread thread;

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs

@ -14,7 +14,7 @@ using System.Collections.Generic; @@ -14,7 +14,7 @@ using System.Collections.Generic;
namespace DebuggerLibrary
{
public class Function: MarshalByRefObject
public class Function: RemotingObjectBase
{
NDebugger debugger;

8
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs

@ -12,7 +12,7 @@ using DebuggerInterop.MetaData; @@ -12,7 +12,7 @@ using DebuggerInterop.MetaData;
namespace DebuggerLibrary
{
public class Process: MarshalByRefObject
public class Process: RemotingObjectBase
{
NDebugger debugger;
@ -88,9 +88,13 @@ namespace DebuggerLibrary @@ -88,9 +88,13 @@ namespace DebuggerLibrary
static public Process CreateProcess(NDebugger debugger, string filename, string workingDirectory, string arguments)
{
MTA2STA m2s = new MTA2STA();
Process createdProcess = null;
if (debugger.RequiredApartmentState == ApartmentState.STA) {
MTA2STA m2s = new MTA2STA();
createdProcess = (Process)m2s.CallInSTA(typeof(Process), "StartInternal", new Object[] {debugger, filename, workingDirectory, arguments});
} else {
createdProcess = StartInternal(debugger, filename, workingDirectory, arguments);
}
return createdProcess;
}

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/SourcecodeSegment.cs

@ -7,7 +7,7 @@ using System.Diagnostics.SymbolStore; @@ -7,7 +7,7 @@ using System.Diagnostics.SymbolStore;
namespace DebuggerLibrary
{
public class SourcecodeSegment: MarshalByRefObject
public class SourcecodeSegment: RemotingObjectBase
{
string moduleFilename;
string sourceFullFilename;

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs

@ -12,7 +12,7 @@ using DebuggerInterop.MetaData; @@ -12,7 +12,7 @@ using DebuggerInterop.MetaData;
namespace DebuggerLibrary
{
public partial class Thread: MarshalByRefObject
public partial class Thread: RemotingObjectBase
{
NDebugger debugger;

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs

@ -10,7 +10,7 @@ using DebuggerInterop.Core; @@ -10,7 +10,7 @@ using DebuggerInterop.Core;
namespace DebuggerLibrary
{
public abstract class Variable: MarshalByRefObject
public abstract class Variable: RemotingObjectBase
{
protected NDebugger debugger;

Loading…
Cancel
Save