Browse Source

Moving functionality from NDebugger to Process - added ManagedCallbackSwitch

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1688 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 20 years ago
parent
commit
ac04c154eb
  1. 1
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj
  2. 14
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs
  3. 85
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackProxy.cs
  4. 254
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackSwitch.cs
  5. 12
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs
  6. 5
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs
  7. 17
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs

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

@ -383,6 +383,7 @@
<Compile Include="Src\Variables\Evals\NewObjectEval.cs" /> <Compile Include="Src\Variables\Evals\NewObjectEval.cs" />
<Compile Include="Src\Debugger\IMutable.cs" /> <Compile Include="Src\Debugger\IMutable.cs" />
<Compile Include="Src\Debugger\ExceptionEventArgs.cs" /> <Compile Include="Src\Debugger\ExceptionEventArgs.cs" />
<Compile Include="Src\Debugger\Internal\ManagedCallbackSwitch.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="README.TXT" /> <Content Include="README.TXT" />

14
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs

@ -20,6 +20,9 @@ using Debugger.Wrappers.CorDebug;
namespace Debugger namespace Debugger
{ {
/// <summary>
/// Handles all callbacks of a given process
/// </summary>
class ManagedCallback class ManagedCallback
{ {
Process process; Process process;
@ -39,6 +42,7 @@ namespace Debugger
void EnterCallback(PausedReason pausedReason, string name, ICorDebugProcess pProcess) void EnterCallback(PausedReason pausedReason, string name, ICorDebugProcess pProcess)
{ {
process.TraceMessage("Callback: " + name); process.TraceMessage("Callback: " + name);
System.Diagnostics.Debug.Assert(process.CorProcess == pProcess);
// Check state // Check state
if (process.IsRunning || if (process.IsRunning ||
// After break is pressed we may receive some messages that were already queued // After break is pressed we may receive some messages that were already queued
@ -46,7 +50,6 @@ namespace Debugger
// ExitProcess may be called at any time when debuggee is killed // ExitProcess may be called at any time when debuggee is killed
name == "ExitProcess") { name == "ExitProcess") {
process = process.GetProcess(pProcess);
if (process.IsPaused && process.PauseSession.PausedReason == PausedReason.ForcedBreak) { if (process.IsPaused && process.PauseSession.PausedReason == PausedReason.ForcedBreak) {
process.TraceMessage("Processing post-break callback"); process.TraceMessage("Processing post-break callback");
// Continue the break, process is still breaked because of the callback // Continue the break, process is still breaked because of the callback
@ -394,14 +397,7 @@ namespace Debugger
{ {
EnterCallback(PausedReason.Other, "ExitProcess", pProcess); EnterCallback(PausedReason.Other, "ExitProcess", pProcess);
Process process = process.GetProcess(pProcess); process.NotifyHasExpired();
process.RemoveProcess(process);
if (process.Processes.Count == 0) {
// Exit callback and then terminate the debugger
process.MTA2STA.AsyncCall( delegate { process.TerminateDebugger(); } );
}
} }
#endregion #endregion

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

@ -23,21 +23,24 @@ using Debugger.Wrappers.CorDebug;
namespace Debugger namespace Debugger
{ {
/// <summary>
/// This proxy marshals the callback to the appropriate thread
/// </summary>
class ManagedCallbackProxy : ICorDebugManagedCallbacks class ManagedCallbackProxy : ICorDebugManagedCallbacks
{ {
Process process; NDebugger debugger;
ManagedCallback realCallback; ManagedCallbackSwitch callbackSwitch;
public Process Process { public NDebugger Debugger {
get { get {
return process; return debugger;
} }
} }
public ManagedCallbackProxy(ManagedCallback realCallback) public ManagedCallbackProxy(NDebugger debugger, ManagedCallbackSwitch callbackSwitch)
{ {
this.debugger = realCallback.Process; this.debugger = debugger;
this.realCallback = realCallback; this.callbackSwitch = callbackSwitch;
} }
void Call(MethodInvoker callback) void Call(MethodInvoker callback)
@ -48,7 +51,7 @@ namespace Debugger
public void StepComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pStepper, CorDebugStepReason reason) public void StepComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pStepper, CorDebugStepReason reason)
{ {
Call(delegate { Call(delegate {
realCallback.StepComplete( callbackSwitch.StepComplete(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
MTA2STA.MarshalIntPtrTo<ICorDebugStepper>(pStepper), MTA2STA.MarshalIntPtrTo<ICorDebugStepper>(pStepper),
@ -60,7 +63,7 @@ namespace Debugger
public void Break(System.IntPtr pAppDomain, System.IntPtr pThread) public void Break(System.IntPtr pAppDomain, System.IntPtr pThread)
{ {
Call(delegate { Call(delegate {
realCallback.Break( callbackSwitch.Break(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread) MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread)
); );
@ -70,7 +73,7 @@ namespace Debugger
public void ControlCTrap(System.IntPtr pProcess) public void ControlCTrap(System.IntPtr pProcess)
{ {
Call(delegate { Call(delegate {
realCallback.ControlCTrap( callbackSwitch.ControlCTrap(
MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess) MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess)
); );
}); });
@ -79,7 +82,7 @@ namespace Debugger
public void Exception(System.IntPtr pAppDomain, System.IntPtr pThread, int unhandled) public void Exception(System.IntPtr pAppDomain, System.IntPtr pThread, int unhandled)
{ {
Call(delegate { Call(delegate {
realCallback.Exception( callbackSwitch.Exception(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
unhandled unhandled
@ -90,7 +93,7 @@ namespace Debugger
public void Breakpoint(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pBreakpoint) public void Breakpoint(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pBreakpoint)
{ {
Call(delegate { Call(delegate {
realCallback.Breakpoint( callbackSwitch.Breakpoint(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
pBreakpoint // Do not marshal this one - it fails in .NET 1.1 pBreakpoint // Do not marshal this one - it fails in .NET 1.1
@ -101,7 +104,7 @@ namespace Debugger
public void CreateProcess(System.IntPtr pProcess) public void CreateProcess(System.IntPtr pProcess)
{ {
Call(delegate { Call(delegate {
realCallback.CreateProcess( callbackSwitch.CreateProcess(
MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess) MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess)
); );
}); });
@ -110,7 +113,7 @@ namespace Debugger
public void CreateAppDomain(System.IntPtr pProcess, System.IntPtr pAppDomain) public void CreateAppDomain(System.IntPtr pProcess, System.IntPtr pAppDomain)
{ {
Call(delegate { Call(delegate {
realCallback.CreateAppDomain( callbackSwitch.CreateAppDomain(
MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess), MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain) MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain)
); );
@ -120,7 +123,7 @@ namespace Debugger
public void CreateThread(System.IntPtr pAppDomain, System.IntPtr pThread) public void CreateThread(System.IntPtr pAppDomain, System.IntPtr pThread)
{ {
Call(delegate { Call(delegate {
realCallback.CreateThread( callbackSwitch.CreateThread(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread) MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread)
); );
@ -130,7 +133,7 @@ namespace Debugger
public void LoadAssembly(System.IntPtr pAppDomain, System.IntPtr pAssembly) public void LoadAssembly(System.IntPtr pAppDomain, System.IntPtr pAssembly)
{ {
Call(delegate { Call(delegate {
realCallback.LoadAssembly( callbackSwitch.LoadAssembly(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugAssembly>(pAssembly) MTA2STA.MarshalIntPtrTo<ICorDebugAssembly>(pAssembly)
); );
@ -140,7 +143,7 @@ namespace Debugger
public void LoadModule(System.IntPtr pAppDomain, System.IntPtr pModule) public void LoadModule(System.IntPtr pAppDomain, System.IntPtr pModule)
{ {
Call(delegate { Call(delegate {
realCallback.LoadModule( callbackSwitch.LoadModule(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugModule>(pModule) MTA2STA.MarshalIntPtrTo<ICorDebugModule>(pModule)
); );
@ -150,7 +153,7 @@ namespace Debugger
public void NameChange(System.IntPtr pAppDomain, System.IntPtr pThread) public void NameChange(System.IntPtr pAppDomain, System.IntPtr pThread)
{ {
Call(delegate { Call(delegate {
realCallback.NameChange( callbackSwitch.NameChange(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread) MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread)
); );
@ -160,7 +163,7 @@ namespace Debugger
public void LoadClass(System.IntPtr pAppDomain, System.IntPtr c) public void LoadClass(System.IntPtr pAppDomain, System.IntPtr c)
{ {
Call(delegate { Call(delegate {
realCallback.LoadClass( callbackSwitch.LoadClass(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugClass>(c) MTA2STA.MarshalIntPtrTo<ICorDebugClass>(c)
); );
@ -170,7 +173,7 @@ namespace Debugger
public void UnloadClass(System.IntPtr pAppDomain, System.IntPtr c) public void UnloadClass(System.IntPtr pAppDomain, System.IntPtr c)
{ {
Call(delegate { Call(delegate {
realCallback.UnloadClass( callbackSwitch.UnloadClass(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugClass>(c) MTA2STA.MarshalIntPtrTo<ICorDebugClass>(c)
); );
@ -180,7 +183,7 @@ namespace Debugger
public void ExitThread(System.IntPtr pAppDomain, System.IntPtr pThread) public void ExitThread(System.IntPtr pAppDomain, System.IntPtr pThread)
{ {
Call(delegate { Call(delegate {
realCallback.ExitThread( callbackSwitch.ExitThread(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread) MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread)
); );
@ -190,7 +193,7 @@ namespace Debugger
public void UnloadModule(System.IntPtr pAppDomain, System.IntPtr pModule) public void UnloadModule(System.IntPtr pAppDomain, System.IntPtr pModule)
{ {
Call(delegate { Call(delegate {
realCallback.UnloadModule( callbackSwitch.UnloadModule(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugModule>(pModule) MTA2STA.MarshalIntPtrTo<ICorDebugModule>(pModule)
); );
@ -200,7 +203,7 @@ namespace Debugger
public void UnloadAssembly(System.IntPtr pAppDomain, System.IntPtr pAssembly) public void UnloadAssembly(System.IntPtr pAppDomain, System.IntPtr pAssembly)
{ {
Call(delegate { Call(delegate {
realCallback.UnloadAssembly( callbackSwitch.UnloadAssembly(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugAssembly>(pAssembly) MTA2STA.MarshalIntPtrTo<ICorDebugAssembly>(pAssembly)
); );
@ -210,7 +213,7 @@ namespace Debugger
public void ExitAppDomain(System.IntPtr pProcess, System.IntPtr pAppDomain) public void ExitAppDomain(System.IntPtr pProcess, System.IntPtr pAppDomain)
{ {
Call(delegate { Call(delegate {
realCallback.ExitAppDomain( callbackSwitch.ExitAppDomain(
MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess), MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain) MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain)
); );
@ -220,7 +223,7 @@ namespace Debugger
public void ExitProcess(System.IntPtr pProcess) public void ExitProcess(System.IntPtr pProcess)
{ {
Call(delegate { Call(delegate {
realCallback.ExitProcess( callbackSwitch.ExitProcess(
MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess) MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess)
); );
}); });
@ -229,7 +232,7 @@ namespace Debugger
public void BreakpointSetError(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pBreakpoint, uint dwError) public void BreakpointSetError(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pBreakpoint, uint dwError)
{ {
Call(delegate { Call(delegate {
realCallback.BreakpointSetError( callbackSwitch.BreakpointSetError(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
MTA2STA.MarshalIntPtrTo<ICorDebugBreakpoint>(pBreakpoint), MTA2STA.MarshalIntPtrTo<ICorDebugBreakpoint>(pBreakpoint),
@ -241,7 +244,7 @@ namespace Debugger
public void LogSwitch(System.IntPtr pAppDomain, System.IntPtr pThread, int lLevel, uint ulReason, System.IntPtr pLogSwitchName, System.IntPtr pParentName) public void LogSwitch(System.IntPtr pAppDomain, System.IntPtr pThread, int lLevel, uint ulReason, System.IntPtr pLogSwitchName, System.IntPtr pParentName)
{ {
Call(delegate { Call(delegate {
realCallback.LogSwitch( callbackSwitch.LogSwitch(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
lLevel, lLevel,
@ -255,7 +258,7 @@ namespace Debugger
public void EvalException(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pEval) public void EvalException(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pEval)
{ {
Call(delegate { Call(delegate {
realCallback.EvalException( callbackSwitch.EvalException(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
MTA2STA.MarshalIntPtrTo<ICorDebugEval>(pEval) MTA2STA.MarshalIntPtrTo<ICorDebugEval>(pEval)
@ -266,7 +269,7 @@ namespace Debugger
public void LogMessage(System.IntPtr pAppDomain, System.IntPtr pThread, int lLevel, System.IntPtr pLogSwitchName, System.IntPtr pMessage) public void LogMessage(System.IntPtr pAppDomain, System.IntPtr pThread, int lLevel, System.IntPtr pLogSwitchName, System.IntPtr pMessage)
{ {
Call(delegate { Call(delegate {
realCallback.LogMessage( callbackSwitch.LogMessage(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
lLevel, lLevel,
@ -279,7 +282,7 @@ namespace Debugger
public void EditAndContinueRemap(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pFunction, int fAccurate) public void EditAndContinueRemap(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pFunction, int fAccurate)
{ {
Call(delegate { Call(delegate {
realCallback.EditAndContinueRemap( callbackSwitch.EditAndContinueRemap(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
MTA2STA.MarshalIntPtrTo<ICorDebugFunction>(pFunction), MTA2STA.MarshalIntPtrTo<ICorDebugFunction>(pFunction),
@ -291,7 +294,7 @@ namespace Debugger
public void EvalComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pEval) public void EvalComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pEval)
{ {
Call(delegate { Call(delegate {
realCallback.EvalComplete( callbackSwitch.EvalComplete(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
MTA2STA.MarshalIntPtrTo<ICorDebugEval>(pEval) MTA2STA.MarshalIntPtrTo<ICorDebugEval>(pEval)
@ -302,7 +305,7 @@ namespace Debugger
public void DebuggerError(System.IntPtr pProcess, int errorHR, uint errorCode) public void DebuggerError(System.IntPtr pProcess, int errorHR, uint errorCode)
{ {
Call(delegate { Call(delegate {
realCallback.DebuggerError( callbackSwitch.DebuggerError(
MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess), MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
errorHR, errorHR,
errorCode errorCode
@ -313,7 +316,7 @@ namespace Debugger
public void UpdateModuleSymbols(System.IntPtr pAppDomain, System.IntPtr pModule, System.IntPtr pSymbolStream) public void UpdateModuleSymbols(System.IntPtr pAppDomain, System.IntPtr pModule, System.IntPtr pSymbolStream)
{ {
Call(delegate { Call(delegate {
realCallback.UpdateModuleSymbols( callbackSwitch.UpdateModuleSymbols(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugModule>(pModule), MTA2STA.MarshalIntPtrTo<ICorDebugModule>(pModule),
MTA2STA.MarshalIntPtrTo<IStream>(pSymbolStream) MTA2STA.MarshalIntPtrTo<IStream>(pSymbolStream)
@ -328,7 +331,7 @@ namespace Debugger
public void ChangeConnection(IntPtr pProcess, uint dwConnectionId) public void ChangeConnection(IntPtr pProcess, uint dwConnectionId)
{ {
Call(delegate { Call(delegate {
realCallback.ChangeConnection( callbackSwitch.ChangeConnection(
MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess), MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
dwConnectionId dwConnectionId
); );
@ -338,7 +341,7 @@ namespace Debugger
public void CreateConnection(IntPtr pProcess, uint dwConnectionId, IntPtr pConnName) public void CreateConnection(IntPtr pProcess, uint dwConnectionId, IntPtr pConnName)
{ {
Call(delegate { Call(delegate {
realCallback.CreateConnection( callbackSwitch.CreateConnection(
MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess), MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
dwConnectionId, dwConnectionId,
pConnName pConnName
@ -349,7 +352,7 @@ namespace Debugger
public void DestroyConnection(IntPtr pProcess, uint dwConnectionId) public void DestroyConnection(IntPtr pProcess, uint dwConnectionId)
{ {
Call(delegate { Call(delegate {
realCallback.DestroyConnection( callbackSwitch.DestroyConnection(
MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess), MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
dwConnectionId dwConnectionId
); );
@ -359,7 +362,7 @@ namespace Debugger
public void Exception(IntPtr pAppDomain, IntPtr pThread, IntPtr pFrame, uint nOffset, CorDebugExceptionCallbackType dwEventType, uint dwFlags) public void Exception(IntPtr pAppDomain, IntPtr pThread, IntPtr pFrame, uint nOffset, CorDebugExceptionCallbackType dwEventType, uint dwFlags)
{ {
Call(delegate { Call(delegate {
realCallback.Exception2( callbackSwitch.Exception2(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
MTA2STA.MarshalIntPtrTo<ICorDebugFrame>(pFrame), MTA2STA.MarshalIntPtrTo<ICorDebugFrame>(pFrame),
@ -373,7 +376,7 @@ namespace Debugger
public void ExceptionUnwind(IntPtr pAppDomain, IntPtr pThread, CorDebugExceptionUnwindCallbackType dwEventType, uint dwFlags) public void ExceptionUnwind(IntPtr pAppDomain, IntPtr pThread, CorDebugExceptionUnwindCallbackType dwEventType, uint dwFlags)
{ {
Call(delegate { Call(delegate {
realCallback.ExceptionUnwind( callbackSwitch.ExceptionUnwind(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
dwEventType, dwEventType,
@ -385,7 +388,7 @@ namespace Debugger
public void FunctionRemapComplete(IntPtr pAppDomain, IntPtr pThread, IntPtr pFunction) public void FunctionRemapComplete(IntPtr pAppDomain, IntPtr pThread, IntPtr pFunction)
{ {
Call(delegate { Call(delegate {
realCallback.FunctionRemapComplete( callbackSwitch.FunctionRemapComplete(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
MTA2STA.MarshalIntPtrTo<ICorDebugFunction>(pFunction) MTA2STA.MarshalIntPtrTo<ICorDebugFunction>(pFunction)
@ -396,7 +399,7 @@ namespace Debugger
public void FunctionRemapOpportunity(IntPtr pAppDomain, IntPtr pThread, IntPtr pOldFunction, IntPtr pNewFunction, uint oldILOffset) public void FunctionRemapOpportunity(IntPtr pAppDomain, IntPtr pThread, IntPtr pOldFunction, IntPtr pNewFunction, uint oldILOffset)
{ {
Call(delegate { Call(delegate {
realCallback.FunctionRemapOpportunity( callbackSwitch.FunctionRemapOpportunity(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
MTA2STA.MarshalIntPtrTo<ICorDebugFunction>(pOldFunction), MTA2STA.MarshalIntPtrTo<ICorDebugFunction>(pOldFunction),
@ -409,7 +412,7 @@ namespace Debugger
public void MDANotification(IntPtr pController, IntPtr pThread, IntPtr pMDA) public void MDANotification(IntPtr pController, IntPtr pThread, IntPtr pMDA)
{ {
Call(delegate { Call(delegate {
realCallback.MDANotification( callbackSwitch.MDANotification(
MTA2STA.MarshalIntPtrTo<ICorDebugController>(pController), MTA2STA.MarshalIntPtrTo<ICorDebugController>(pController),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
MTA2STA.MarshalIntPtrTo<ICorDebugMDA>(pMDA) MTA2STA.MarshalIntPtrTo<ICorDebugMDA>(pMDA)

254
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackSwitch.cs

@ -0,0 +1,254 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision$</version>
// </file>
// Regular expresion:
// ^{\t*}{(:Ll| )*{:i} *\(((.# {:i}, |\))|())^6\)*}\n\t*\{(.|\n)@^\1\}
// Output: \1 - intention \2 - declaration \3 - function name \4-9 parameters
// Replace with:
// \1\2\n\1{\n\1\tGetProcessCallbackInterface(\4).\3(\4, \5, \6, \7, \8, \9);\n\1}
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Debugger.Wrappers.CorDebug;
namespace Debugger
{
/// <summary>
/// This class forwards the callback the the approprite process
/// </summary>
class ManagedCallbackSwitch
{
NDebugger debugger;
public NDebugger Debugger {
get {
return debugger;
}
}
public ManagedCallbackSwitch(NDebugger debugger)
{
this.debugger = debugger;
}
public ManagedCallback GetProcessCallbackInterface(ICorDebugController c)
{
if (c.Is<ICorDebugAppDomain>()) {
return GetProcessCallbackInterface(c.CastTo<ICorDebugAppDomain>());
} else if (c.Is<ICorDebugProcess>()){
return GetProcessCallbackInterface(c.CastTo<ICorDebugProcess>());
} else {
throw new System.Exception("Unknown callback argument");
}
}
public ManagedCallback GetProcessCallbackInterface(ICorDebugAppDomain pAppDomain)
{
return GetProcessCallbackInterface(pAppDomain.Process);
}
public ManagedCallback GetProcessCallbackInterface(ICorDebugProcess pProcess)
{
Process process = debugger.GetProcess(pProcess);
return process.CallbackInterface;
}
#region Program folow control
public void StepComplete(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugStepper pStepper, CorDebugStepReason reason)
{
GetProcessCallbackInterface(pAppDomain).StepComplete(pAppDomain, pThread, pStepper, reason);
}
// Do not pass the pBreakpoint parameter as ICorDebugBreakpoint - marshaling of it fails in .NET 1.1
public void Breakpoint(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, IntPtr pBreakpoint)
{
GetProcessCallbackInterface(pAppDomain).Breakpoint(pAppDomain, pThread, pBreakpoint);
}
public void BreakpointSetError(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugBreakpoint pBreakpoint, uint dwError)
{
GetProcessCallbackInterface(pAppDomain).BreakpointSetError(pAppDomain, pThread, pBreakpoint, dwError);
}
public unsafe void Break(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread)
{
GetProcessCallbackInterface(pAppDomain).Break(pAppDomain, pThread);
}
public void ControlCTrap(ICorDebugProcess pProcess)
{
GetProcessCallbackInterface(pProcess).ControlCTrap(pProcess);
}
public unsafe void Exception(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, int unhandled)
{
GetProcessCallbackInterface(pAppDomain).Exception(pAppDomain, pThread, unhandled);
}
#endregion
#region Various
public void LogSwitch(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, int lLevel, uint ulReason, string pLogSwitchName, string pParentName)
{
GetProcessCallbackInterface(pAppDomain).LogSwitch(pAppDomain, pThread, lLevel, ulReason, pLogSwitchName, pParentName);
}
public void LogMessage(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, int lLevel, string pLogSwitchName, string pMessage)
{
GetProcessCallbackInterface(pAppDomain).LogMessage(pAppDomain, pThread, lLevel, pLogSwitchName, pMessage);
}
public void EditAndContinueRemap(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugFunction pFunction, int fAccurate)
{
GetProcessCallbackInterface(pAppDomain).EditAndContinueRemap(pAppDomain, pThread, pFunction, fAccurate);
}
public void EvalException(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugEval corEval)
{
GetProcessCallbackInterface(pAppDomain).EvalException(pAppDomain, pThread, corEval);
}
public void EvalComplete(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugEval corEval)
{
GetProcessCallbackInterface(pAppDomain).EvalComplete(pAppDomain, pThread, corEval);
}
public void DebuggerError(ICorDebugProcess pProcess, int errorHR, uint errorCode)
{
GetProcessCallbackInterface(pProcess).DebuggerError(pProcess, errorHR, errorCode);
}
public void UpdateModuleSymbols(ICorDebugAppDomain pAppDomain, ICorDebugModule pModule, IStream pSymbolStream)
{
GetProcessCallbackInterface(pAppDomain).UpdateModuleSymbols(pAppDomain, pModule, pSymbolStream);
}
#endregion
#region Start of Application
public void CreateProcess(ICorDebugProcess pProcess)
{
GetProcessCallbackInterface(pProcess).CreateProcess(pProcess);
}
public void CreateAppDomain(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain)
{
GetProcessCallbackInterface(pProcess).CreateAppDomain(pProcess, pAppDomain);
}
public void LoadAssembly(ICorDebugAppDomain pAppDomain, ICorDebugAssembly pAssembly)
{
GetProcessCallbackInterface(pAppDomain).LoadAssembly(pAppDomain, pAssembly);
}
public unsafe void LoadModule(ICorDebugAppDomain pAppDomain, ICorDebugModule pModule)
{
GetProcessCallbackInterface(pAppDomain).LoadModule(pAppDomain, pModule);
}
public void NameChange(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread)
{
GetProcessCallbackInterface(pAppDomain).NameChange(pAppDomain, pThread);
}
public void CreateThread(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread)
{
GetProcessCallbackInterface(pAppDomain).CreateThread(pAppDomain, pThread);
}
public void LoadClass(ICorDebugAppDomain pAppDomain, ICorDebugClass c)
{
GetProcessCallbackInterface(pAppDomain).LoadClass(pAppDomain, c);
}
#endregion
#region Exit of Application
public void UnloadClass(ICorDebugAppDomain pAppDomain, ICorDebugClass c)
{
GetProcessCallbackInterface(pAppDomain).UnloadClass(pAppDomain, c);
}
public void UnloadModule(ICorDebugAppDomain pAppDomain, ICorDebugModule pModule)
{
GetProcessCallbackInterface(pAppDomain).UnloadModule(pAppDomain, pModule);
}
public void UnloadAssembly(ICorDebugAppDomain pAppDomain, ICorDebugAssembly pAssembly)
{
GetProcessCallbackInterface(pAppDomain).UnloadAssembly(pAppDomain, pAssembly);
}
public void ExitThread(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread)
{
GetProcessCallbackInterface(pAppDomain).ExitThread(pAppDomain, pThread);
}
public void ExitAppDomain(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain)
{
GetProcessCallbackInterface(pProcess).ExitAppDomain(pProcess, pAppDomain);
}
public void ExitProcess(ICorDebugProcess pProcess)
{
GetProcessCallbackInterface(pProcess).ExitProcess(pProcess);
}
#endregion
#region ICorDebugManagedCallback2 Members
public void ChangeConnection(ICorDebugProcess pProcess, uint dwConnectionId)
{
GetProcessCallbackInterface(pProcess).ChangeConnection(pProcess, dwConnectionId);
}
public void CreateConnection(ICorDebugProcess pProcess, uint dwConnectionId, IntPtr pConnName)
{
GetProcessCallbackInterface(pProcess).CreateConnection(pProcess, dwConnectionId, pConnName);
}
public void DestroyConnection(ICorDebugProcess pProcess, uint dwConnectionId)
{
GetProcessCallbackInterface(pProcess).DestroyConnection(pProcess, dwConnectionId);
}
public void Exception2(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugFrame pFrame, uint nOffset, CorDebugExceptionCallbackType exceptionType, uint dwFlags)
{
GetProcessCallbackInterface(pAppDomain).Exception2(pAppDomain, pThread, pFrame, nOffset, exceptionType, dwFlags);
}
public void ExceptionUnwind(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, CorDebugExceptionUnwindCallbackType dwEventType, uint dwFlags)
{
GetProcessCallbackInterface(pAppDomain).ExceptionUnwind(pAppDomain, pThread, dwEventType, dwFlags);
}
public void FunctionRemapComplete(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugFunction pFunction)
{
GetProcessCallbackInterface(pAppDomain).FunctionRemapComplete(pAppDomain, pThread, pFunction);
}
public void FunctionRemapOpportunity(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugFunction pOldFunction, ICorDebugFunction pNewFunction, uint oldILOffset)
{
GetProcessCallbackInterface(pAppDomain).FunctionRemapOpportunity(pAppDomain, pThread, pOldFunction, pNewFunction, oldILOffset);
}
public void MDANotification(ICorDebugController c, ICorDebugThread t, ICorDebugMDA mda)
{
GetProcessCallbackInterface(c).MDANotification(c, t, mda);
}
#endregion
}
}

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

@ -19,7 +19,7 @@ namespace Debugger
public partial class NDebugger: RemotingObjectBase public partial class NDebugger: RemotingObjectBase
{ {
ICorDebug corDebug; ICorDebug corDebug;
ManagedCallback managedCallback; ManagedCallbackSwitch managedCallbackSwitch;
ManagedCallbackProxy managedCallbackProxy; ManagedCallbackProxy managedCallbackProxy;
MTA2STA mta2sta = new MTA2STA(); MTA2STA mta2sta = new MTA2STA();
@ -44,12 +44,6 @@ namespace Debugger
} }
} }
internal ManagedCallback ManagedCallback {
get {
return managedCallback;
}
}
public NDebugger() public NDebugger()
{ {
if (ApartmentState.STA == System.Threading.Thread.CurrentThread.GetApartmentState()) { if (ApartmentState.STA == System.Threading.Thread.CurrentThread.GetApartmentState()) {
@ -105,8 +99,8 @@ namespace Debugger
corDebug = new ICorDebug(NativeMethods.CreateDebuggingInterfaceFromVersion(3, this.debuggeeVersion)); corDebug = new ICorDebug(NativeMethods.CreateDebuggingInterfaceFromVersion(3, this.debuggeeVersion));
managedCallback = new ManagedCallback(this); managedCallbackSwitch = new ManagedCallbackSwitch(this);
managedCallbackProxy = new ManagedCallbackProxy(managedCallback); managedCallbackProxy = new ManagedCallbackProxy(this, managedCallbackSwitch);
corDebug.Initialize(); corDebug.Initialize();
corDebug.SetManagedHandler(new ICorDebugManagedCallback(managedCallbackProxy)); corDebug.SetManagedHandler(new ICorDebugManagedCallback(managedCallbackProxy));

5
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs

@ -49,9 +49,12 @@ namespace Debugger
internal void RemoveProcess(Process process) internal void RemoveProcess(Process process)
{ {
processCollection.Remove(process); processCollection.Remove(process);
process.NotifyHasExpired();
OnProcessExited(process); OnProcessExited(process);
// noProcessesHandle is set in NDebugger.TerminateDebugger // noProcessesHandle is set in NDebugger.TerminateDebugger
if (processCollection.Count == 0) {
// Exit callback and then terminate the debugger
this.MTA2STA.AsyncCall( delegate { this.TerminateDebugger(); } );
}
} }
protected virtual void OnProcessStarted(Process process) protected virtual void OnProcessStarted(Process process)

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

@ -19,6 +19,7 @@ namespace Debugger
NDebugger debugger; NDebugger debugger;
ICorDebugProcess corProcess; ICorDebugProcess corProcess;
ManagedCallback callbackInterface;
Thread selectedThread; Thread selectedThread;
PauseSession pauseSession; PauseSession pauseSession;
@ -40,6 +41,7 @@ namespace Debugger
if (Expired != null) { if (Expired != null) {
Expired(this, new ProcessEventArgs(this)); Expired(this, new ProcessEventArgs(this));
} }
debugger.RemoveProcess(this);
} }
} }
@ -63,10 +65,18 @@ namespace Debugger
} }
} }
internal ManagedCallback CallbackInterface {
get {
return callbackInterface;
}
}
internal Process(NDebugger debugger, ICorDebugProcess corProcess) internal Process(NDebugger debugger, ICorDebugProcess corProcess)
{ {
this.debugger = debugger; this.debugger = debugger;
this.corProcess = corProcess; this.corProcess = corProcess;
this.callbackInterface = new ManagedCallback(this);
} }
internal ICorDebugProcess CorProcess { internal ICorDebugProcess CorProcess {
@ -187,6 +197,13 @@ namespace Debugger
} }
string debuggeeVersion;
public string DebuggeeVersion {
get {
return debuggeeVersion;
}
}
/// <summary> /// <summary>
/// Fired when System.Diagnostics.Trace.WriteLine() is called in debuged process /// Fired when System.Diagnostics.Trace.WriteLine() is called in debuged process

Loading…
Cancel
Save