From ac04c154eb9acc73a2b87adfa8ae386a4e97107b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Thu, 10 Aug 2006 16:16:04 +0000 Subject: [PATCH] Moving functionality from NDebugger to Process - added ManagedCallbackSwitch git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1688 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Debugger.Core.csproj | 1 + .../Src/Debugger/Internal/ManagedCallback.cs | 14 +- .../Debugger/Internal/ManagedCallbackProxy.cs | 85 +++--- .../Internal/ManagedCallbackSwitch.cs | 254 ++++++++++++++++++ .../Project/Src/Debugger/NDebugger.cs | 12 +- .../Src/Threads/NDebugger-Processes.cs | 5 +- .../Project/Src/Threads/Process.cs | 23 +- 7 files changed, 331 insertions(+), 63 deletions(-) create mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackSwitch.cs diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj index 61ef9d7ce8..87ef542566 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj @@ -383,6 +383,7 @@ + diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs index ca4261794d..bef34d5893 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs @@ -20,6 +20,9 @@ using Debugger.Wrappers.CorDebug; namespace Debugger { + /// + /// Handles all callbacks of a given process + /// class ManagedCallback { Process process; @@ -39,6 +42,7 @@ namespace Debugger void EnterCallback(PausedReason pausedReason, string name, ICorDebugProcess pProcess) { process.TraceMessage("Callback: " + name); + System.Diagnostics.Debug.Assert(process.CorProcess == pProcess); // Check state if (process.IsRunning || // 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 name == "ExitProcess") { - process = process.GetProcess(pProcess); if (process.IsPaused && process.PauseSession.PausedReason == PausedReason.ForcedBreak) { process.TraceMessage("Processing post-break callback"); // Continue the break, process is still breaked because of the callback @@ -394,14 +397,7 @@ namespace Debugger { EnterCallback(PausedReason.Other, "ExitProcess", pProcess); - Process process = process.GetProcess(pProcess); - - process.RemoveProcess(process); - - if (process.Processes.Count == 0) { - // Exit callback and then terminate the debugger - process.MTA2STA.AsyncCall( delegate { process.TerminateDebugger(); } ); - } + process.NotifyHasExpired(); } #endregion diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackProxy.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackProxy.cs index 9794d19fbb..80ab25417f 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackProxy.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackProxy.cs @@ -23,21 +23,24 @@ using Debugger.Wrappers.CorDebug; namespace Debugger { + /// + /// This proxy marshals the callback to the appropriate thread + /// class ManagedCallbackProxy : ICorDebugManagedCallbacks { - Process process; - ManagedCallback realCallback; + NDebugger debugger; + ManagedCallbackSwitch callbackSwitch; - public Process Process { + public NDebugger Debugger { get { - return process; + return debugger; } } - public ManagedCallbackProxy(ManagedCallback realCallback) + public ManagedCallbackProxy(NDebugger debugger, ManagedCallbackSwitch callbackSwitch) { - this.debugger = realCallback.Process; - this.realCallback = realCallback; + this.debugger = debugger; + this.callbackSwitch = callbackSwitch; } void Call(MethodInvoker callback) @@ -48,7 +51,7 @@ namespace Debugger public void StepComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pStepper, CorDebugStepReason reason) { Call(delegate { - realCallback.StepComplete( + callbackSwitch.StepComplete( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), MTA2STA.MarshalIntPtrTo(pStepper), @@ -60,7 +63,7 @@ namespace Debugger public void Break(System.IntPtr pAppDomain, System.IntPtr pThread) { Call(delegate { - realCallback.Break( + callbackSwitch.Break( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread) ); @@ -70,7 +73,7 @@ namespace Debugger public void ControlCTrap(System.IntPtr pProcess) { Call(delegate { - realCallback.ControlCTrap( + callbackSwitch.ControlCTrap( MTA2STA.MarshalIntPtrTo(pProcess) ); }); @@ -79,7 +82,7 @@ namespace Debugger public void Exception(System.IntPtr pAppDomain, System.IntPtr pThread, int unhandled) { Call(delegate { - realCallback.Exception( + callbackSwitch.Exception( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), unhandled @@ -90,7 +93,7 @@ namespace Debugger public void Breakpoint(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pBreakpoint) { Call(delegate { - realCallback.Breakpoint( + callbackSwitch.Breakpoint( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), pBreakpoint // Do not marshal this one - it fails in .NET 1.1 @@ -101,7 +104,7 @@ namespace Debugger public void CreateProcess(System.IntPtr pProcess) { Call(delegate { - realCallback.CreateProcess( + callbackSwitch.CreateProcess( MTA2STA.MarshalIntPtrTo(pProcess) ); }); @@ -110,7 +113,7 @@ namespace Debugger public void CreateAppDomain(System.IntPtr pProcess, System.IntPtr pAppDomain) { Call(delegate { - realCallback.CreateAppDomain( + callbackSwitch.CreateAppDomain( MTA2STA.MarshalIntPtrTo(pProcess), MTA2STA.MarshalIntPtrTo(pAppDomain) ); @@ -120,7 +123,7 @@ namespace Debugger public void CreateThread(System.IntPtr pAppDomain, System.IntPtr pThread) { Call(delegate { - realCallback.CreateThread( + callbackSwitch.CreateThread( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread) ); @@ -130,7 +133,7 @@ namespace Debugger public void LoadAssembly(System.IntPtr pAppDomain, System.IntPtr pAssembly) { Call(delegate { - realCallback.LoadAssembly( + callbackSwitch.LoadAssembly( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pAssembly) ); @@ -140,7 +143,7 @@ namespace Debugger public void LoadModule(System.IntPtr pAppDomain, System.IntPtr pModule) { Call(delegate { - realCallback.LoadModule( + callbackSwitch.LoadModule( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pModule) ); @@ -150,7 +153,7 @@ namespace Debugger public void NameChange(System.IntPtr pAppDomain, System.IntPtr pThread) { Call(delegate { - realCallback.NameChange( + callbackSwitch.NameChange( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread) ); @@ -160,7 +163,7 @@ namespace Debugger public void LoadClass(System.IntPtr pAppDomain, System.IntPtr c) { Call(delegate { - realCallback.LoadClass( + callbackSwitch.LoadClass( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(c) ); @@ -170,7 +173,7 @@ namespace Debugger public void UnloadClass(System.IntPtr pAppDomain, System.IntPtr c) { Call(delegate { - realCallback.UnloadClass( + callbackSwitch.UnloadClass( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(c) ); @@ -180,7 +183,7 @@ namespace Debugger public void ExitThread(System.IntPtr pAppDomain, System.IntPtr pThread) { Call(delegate { - realCallback.ExitThread( + callbackSwitch.ExitThread( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread) ); @@ -190,7 +193,7 @@ namespace Debugger public void UnloadModule(System.IntPtr pAppDomain, System.IntPtr pModule) { Call(delegate { - realCallback.UnloadModule( + callbackSwitch.UnloadModule( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pModule) ); @@ -200,7 +203,7 @@ namespace Debugger public void UnloadAssembly(System.IntPtr pAppDomain, System.IntPtr pAssembly) { Call(delegate { - realCallback.UnloadAssembly( + callbackSwitch.UnloadAssembly( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pAssembly) ); @@ -210,7 +213,7 @@ namespace Debugger public void ExitAppDomain(System.IntPtr pProcess, System.IntPtr pAppDomain) { Call(delegate { - realCallback.ExitAppDomain( + callbackSwitch.ExitAppDomain( MTA2STA.MarshalIntPtrTo(pProcess), MTA2STA.MarshalIntPtrTo(pAppDomain) ); @@ -220,7 +223,7 @@ namespace Debugger public void ExitProcess(System.IntPtr pProcess) { Call(delegate { - realCallback.ExitProcess( + callbackSwitch.ExitProcess( MTA2STA.MarshalIntPtrTo(pProcess) ); }); @@ -229,7 +232,7 @@ namespace Debugger public void BreakpointSetError(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pBreakpoint, uint dwError) { Call(delegate { - realCallback.BreakpointSetError( + callbackSwitch.BreakpointSetError( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), MTA2STA.MarshalIntPtrTo(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) { Call(delegate { - realCallback.LogSwitch( + callbackSwitch.LogSwitch( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), lLevel, @@ -255,7 +258,7 @@ namespace Debugger public void EvalException(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pEval) { Call(delegate { - realCallback.EvalException( + callbackSwitch.EvalException( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), MTA2STA.MarshalIntPtrTo(pEval) @@ -266,7 +269,7 @@ namespace Debugger public void LogMessage(System.IntPtr pAppDomain, System.IntPtr pThread, int lLevel, System.IntPtr pLogSwitchName, System.IntPtr pMessage) { Call(delegate { - realCallback.LogMessage( + callbackSwitch.LogMessage( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), lLevel, @@ -279,7 +282,7 @@ namespace Debugger public void EditAndContinueRemap(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pFunction, int fAccurate) { Call(delegate { - realCallback.EditAndContinueRemap( + callbackSwitch.EditAndContinueRemap( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), MTA2STA.MarshalIntPtrTo(pFunction), @@ -291,7 +294,7 @@ namespace Debugger public void EvalComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pEval) { Call(delegate { - realCallback.EvalComplete( + callbackSwitch.EvalComplete( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), MTA2STA.MarshalIntPtrTo(pEval) @@ -302,7 +305,7 @@ namespace Debugger public void DebuggerError(System.IntPtr pProcess, int errorHR, uint errorCode) { Call(delegate { - realCallback.DebuggerError( + callbackSwitch.DebuggerError( MTA2STA.MarshalIntPtrTo(pProcess), errorHR, errorCode @@ -313,7 +316,7 @@ namespace Debugger public void UpdateModuleSymbols(System.IntPtr pAppDomain, System.IntPtr pModule, System.IntPtr pSymbolStream) { Call(delegate { - realCallback.UpdateModuleSymbols( + callbackSwitch.UpdateModuleSymbols( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pModule), MTA2STA.MarshalIntPtrTo(pSymbolStream) @@ -328,7 +331,7 @@ namespace Debugger public void ChangeConnection(IntPtr pProcess, uint dwConnectionId) { Call(delegate { - realCallback.ChangeConnection( + callbackSwitch.ChangeConnection( MTA2STA.MarshalIntPtrTo(pProcess), dwConnectionId ); @@ -338,7 +341,7 @@ namespace Debugger public void CreateConnection(IntPtr pProcess, uint dwConnectionId, IntPtr pConnName) { Call(delegate { - realCallback.CreateConnection( + callbackSwitch.CreateConnection( MTA2STA.MarshalIntPtrTo(pProcess), dwConnectionId, pConnName @@ -349,7 +352,7 @@ namespace Debugger public void DestroyConnection(IntPtr pProcess, uint dwConnectionId) { Call(delegate { - realCallback.DestroyConnection( + callbackSwitch.DestroyConnection( MTA2STA.MarshalIntPtrTo(pProcess), dwConnectionId ); @@ -359,7 +362,7 @@ namespace Debugger public void Exception(IntPtr pAppDomain, IntPtr pThread, IntPtr pFrame, uint nOffset, CorDebugExceptionCallbackType dwEventType, uint dwFlags) { Call(delegate { - realCallback.Exception2( + callbackSwitch.Exception2( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), MTA2STA.MarshalIntPtrTo(pFrame), @@ -373,7 +376,7 @@ namespace Debugger public void ExceptionUnwind(IntPtr pAppDomain, IntPtr pThread, CorDebugExceptionUnwindCallbackType dwEventType, uint dwFlags) { Call(delegate { - realCallback.ExceptionUnwind( + callbackSwitch.ExceptionUnwind( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), dwEventType, @@ -385,7 +388,7 @@ namespace Debugger public void FunctionRemapComplete(IntPtr pAppDomain, IntPtr pThread, IntPtr pFunction) { Call(delegate { - realCallback.FunctionRemapComplete( + callbackSwitch.FunctionRemapComplete( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), MTA2STA.MarshalIntPtrTo(pFunction) @@ -396,7 +399,7 @@ namespace Debugger public void FunctionRemapOpportunity(IntPtr pAppDomain, IntPtr pThread, IntPtr pOldFunction, IntPtr pNewFunction, uint oldILOffset) { Call(delegate { - realCallback.FunctionRemapOpportunity( + callbackSwitch.FunctionRemapOpportunity( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), MTA2STA.MarshalIntPtrTo(pOldFunction), @@ -409,7 +412,7 @@ namespace Debugger public void MDANotification(IntPtr pController, IntPtr pThread, IntPtr pMDA) { Call(delegate { - realCallback.MDANotification( + callbackSwitch.MDANotification( MTA2STA.MarshalIntPtrTo(pController), MTA2STA.MarshalIntPtrTo(pThread), MTA2STA.MarshalIntPtrTo(pMDA) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackSwitch.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackSwitch.cs new file mode 100644 index 0000000000..e213b673fb --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackSwitch.cs @@ -0,0 +1,254 @@ +// +// +// +// +// $Revision$ +// + +// 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 +{ + /// + /// This class forwards the callback the the approprite process + /// + 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()) { + return GetProcessCallbackInterface(c.CastTo()); + } else if (c.Is()){ + return GetProcessCallbackInterface(c.CastTo()); + } 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 + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs index 78fb5b9295..57f061bf79 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs @@ -19,7 +19,7 @@ namespace Debugger public partial class NDebugger: RemotingObjectBase { ICorDebug corDebug; - ManagedCallback managedCallback; + ManagedCallbackSwitch managedCallbackSwitch; ManagedCallbackProxy managedCallbackProxy; MTA2STA mta2sta = new MTA2STA(); @@ -44,12 +44,6 @@ namespace Debugger } } - internal ManagedCallback ManagedCallback { - get { - return managedCallback; - } - } - public NDebugger() { if (ApartmentState.STA == System.Threading.Thread.CurrentThread.GetApartmentState()) { @@ -105,8 +99,8 @@ namespace Debugger corDebug = new ICorDebug(NativeMethods.CreateDebuggingInterfaceFromVersion(3, this.debuggeeVersion)); - managedCallback = new ManagedCallback(this); - managedCallbackProxy = new ManagedCallbackProxy(managedCallback); + managedCallbackSwitch = new ManagedCallbackSwitch(this); + managedCallbackProxy = new ManagedCallbackProxy(this, managedCallbackSwitch); corDebug.Initialize(); corDebug.SetManagedHandler(new ICorDebugManagedCallback(managedCallbackProxy)); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs index 87608ff910..3b8ee88ea6 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs @@ -49,9 +49,12 @@ namespace Debugger internal void RemoveProcess(Process process) { processCollection.Remove(process); - process.NotifyHasExpired(); OnProcessExited(process); // 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) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs index 5a9c39120e..896eac1d6f 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs @@ -17,9 +17,10 @@ namespace Debugger public partial class Process: RemotingObjectBase, IExpirable { NDebugger debugger; - + ICorDebugProcess corProcess; - + ManagedCallback callbackInterface; + Thread selectedThread; PauseSession pauseSession; @@ -40,6 +41,7 @@ namespace Debugger if (Expired != null) { Expired(this, new ProcessEventArgs(this)); } + debugger.RemoveProcess(this); } } @@ -62,11 +64,19 @@ namespace Debugger return debugger; } } - + + internal ManagedCallback CallbackInterface { + get { + return callbackInterface; + } + } + internal Process(NDebugger debugger, ICorDebugProcess corProcess) { this.debugger = debugger; this.corProcess = corProcess; + + this.callbackInterface = new ManagedCallback(this); } internal ICorDebugProcess CorProcess { @@ -187,6 +197,13 @@ namespace Debugger } + string debuggeeVersion; + + public string DebuggeeVersion { + get { + return debuggeeVersion; + } + } /// /// Fired when System.Diagnostics.Trace.WriteLine() is called in debuged process