From 687942aee99bca1dbbd5d592b49e0419857a6726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Fri, 2 Dec 2005 20:47:47 +0000 Subject: [PATCH] Rewritten Debugger.ManagedCallbackProxy git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@821 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Debugger/Internal/MTA2STA.cs | 7 +- .../Debugger/Internal/ManagedCallbackProxy.cs | 343 ++++++++++++++---- 2 files changed, 279 insertions(+), 71 deletions(-) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/MTA2STA.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/MTA2STA.cs index bd7db8cddc..99564bac9e 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/MTA2STA.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/MTA2STA.cs @@ -45,7 +45,7 @@ namespace Debugger public object CallInSTA(MethodInvokerWithReturnValue callDelegate) { - return CallInSTA(callDelegate, true); // TODO: Make it false once it is safe + return CallInSTA(callDelegate, false); } object CallInSTA(MethodInvokerWithReturnValue callDelegate, bool mayAbandon) @@ -79,6 +79,11 @@ namespace Debugger } } + public static T MarshalIntPtrTo(IntPtr param) + { + return (T)MarshalIntPtrTo(param, typeof(T)); + } + public static object MarshalIntPtrTo(IntPtr param, Type outputType) { // IntPtr requested as output (must be before the null check so that we pass IntPtr.Zero) 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 d68cbd31d4..09e9a0a9d7 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 @@ -14,11 +14,12 @@ using System.Windows.Forms; using Debugger.Interop.CorDebug; // Regular expresion: -// ^{\t*}{(:Ll| )*{:i} *\(((.# {:i}, |\))|())^6\)*}\n\t*\{(.|\n)@\} +// ^{\t*}{(:Ll| )*{:i} *\(((.# {:i}, |\))|())^6\)*}\n\t*\{(.|\n)@\t\} // Output: \1 - intention \2 - declaration \3 - function name \4-9 parameters // Replace with: // \1\2\n\1{\n\1\tCallbackReceived("\3", new object[] {\4, \5, \6, \7, \8, \9});\n\1} +// \1\2\n\1{\n\1\tCall(delegate {\n\1\t \trealCallback.\3(\n\1\t \t\tMTA2STA.MarshalIntPtrTo(\4),\n\1\t \t\tMTA2STA.MarshalIntPtrTo(\5),\n\1\t \t\tMTA2STA.MarshalIntPtrTo(\6),\n\1\t \t\tMTA2STA.MarshalIntPtrTo(\7),\n\1\t \t\tMTA2STA.MarshalIntPtrTo(\8),\n\1\t \t\tMTA2STA.MarshalIntPtrTo(\9),\n\1\t \t);\n\1\t });\n\1} namespace Debugger { @@ -50,136 +51,285 @@ namespace Debugger } } - - + void Call(MethodInvoker d) + { + mta2sta.CallInSTA(d); + } + public void StepComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pStepper, Debugger.Interop.CorDebug.CorDebugStepReason reason) { - CallbackReceived("StepComplete", new object[] {pAppDomain, pThread, pStepper, reason}); + Call(delegate { + realCallback.StepComplete( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + MTA2STA.MarshalIntPtrTo(pStepper), + reason + ); + }); } - + public void Break(System.IntPtr pAppDomain, System.IntPtr pThread) { - CallbackReceived("Break", new object[] {pAppDomain, pThread}); + Call(delegate { + realCallback.Break( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread) + ); + }); } - + public void ControlCTrap(System.IntPtr pProcess) { - CallbackReceived("ControlCTrap", new object[] {pProcess}); + Call(delegate { + realCallback.ControlCTrap( + MTA2STA.MarshalIntPtrTo(pProcess) + ); + }); } - + public void Exception(System.IntPtr pAppDomain, System.IntPtr pThread, int unhandled) { - CallbackReceived("Exception", new object[] {pAppDomain, pThread, unhandled}); + Call(delegate { + realCallback.Exception( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + unhandled + ); + }); } - + public void Breakpoint(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pBreakpoint) { - CallbackReceived("Breakpoint", new object[] {pAppDomain, pThread, pBreakpoint}); + Call(delegate { + realCallback.Breakpoint( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + pBreakpoint + ); + }); } - + public void CreateProcess(System.IntPtr pProcess) { - CallbackReceived("CreateProcess", new object[] {pProcess}); + Call(delegate { + realCallback.CreateProcess( + MTA2STA.MarshalIntPtrTo(pProcess) + ); + }); } - + public void CreateAppDomain(System.IntPtr pProcess, System.IntPtr pAppDomain) { - CallbackReceived("CreateAppDomain", new object[] {pProcess, pAppDomain}); + Call(delegate { + realCallback.CreateAppDomain( + MTA2STA.MarshalIntPtrTo(pProcess), + MTA2STA.MarshalIntPtrTo(pAppDomain) + ); + }); } - + public void CreateThread(System.IntPtr pAppDomain, System.IntPtr pThread) { - CallbackReceived("CreateThread", new object[] {pAppDomain, pThread}); + Call(delegate { + realCallback.CreateThread( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread) + ); + }); } - + public void LoadAssembly(System.IntPtr pAppDomain, System.IntPtr pAssembly) { - CallbackReceived("LoadAssembly", new object[] {pAppDomain, pAssembly}); + Call(delegate { + realCallback.LoadAssembly( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pAssembly) + ); + }); } - + public void LoadModule(System.IntPtr pAppDomain, System.IntPtr pModule) { - CallbackReceived("LoadModule", new object[] {pAppDomain, pModule}); + Call(delegate { + realCallback.LoadModule( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pModule) + ); + }); } - + public void NameChange(System.IntPtr pAppDomain, System.IntPtr pThread) { - CallbackReceived("NameChange", new object[] {pAppDomain, pThread}); + Call(delegate { + realCallback.NameChange( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread) + ); + }); } - + public void LoadClass(System.IntPtr pAppDomain, System.IntPtr c) { - CallbackReceived("LoadClass", new object[] {pAppDomain, c}); + Call(delegate { + realCallback.LoadClass( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(c) + ); + }); } - + public void UnloadClass(System.IntPtr pAppDomain, System.IntPtr c) { - CallbackReceived("UnloadClass", new object[] {pAppDomain, c}); + Call(delegate { + realCallback.UnloadClass( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(c) + ); + }); } - + public void ExitThread(System.IntPtr pAppDomain, System.IntPtr pThread) { - CallbackReceived("ExitThread", new object[] {pAppDomain, pThread}); + Call(delegate { + realCallback.ExitThread( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread) + ); + }); } - + public void UnloadModule(System.IntPtr pAppDomain, System.IntPtr pModule) { - CallbackReceived("UnloadModule", new object[] {pAppDomain, pModule}); + Call(delegate { + realCallback.UnloadModule( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pModule) + ); + }); } - + public void UnloadAssembly(System.IntPtr pAppDomain, System.IntPtr pAssembly) { - CallbackReceived("UnloadAssembly", new object[] {pAppDomain, pAssembly}); + Call(delegate { + realCallback.UnloadAssembly( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pAssembly) + ); + }); } - + public void ExitAppDomain(System.IntPtr pProcess, System.IntPtr pAppDomain) { - CallbackReceived("ExitAppDomain", new object[] {pProcess, pAppDomain}); + Call(delegate { + realCallback.ExitAppDomain( + MTA2STA.MarshalIntPtrTo(pProcess), + MTA2STA.MarshalIntPtrTo(pAppDomain) + ); + }); } - + public void ExitProcess(System.IntPtr pProcess) { - CallbackReceived("ExitProcess", new object[] {pProcess}); + Call(delegate { + realCallback.ExitProcess( + MTA2STA.MarshalIntPtrTo(pProcess) + ); + }); } - + public void BreakpointSetError(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pBreakpoint, uint dwError) { - CallbackReceived("BreakpointSetError", new object[] {pAppDomain, pThread, pBreakpoint, dwError}); + Call(delegate { + realCallback.BreakpointSetError( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + MTA2STA.MarshalIntPtrTo(pBreakpoint), + dwError + ); + }); } - + public void LogSwitch(System.IntPtr pAppDomain, System.IntPtr pThread, int lLevel, uint ulReason, System.IntPtr pLogSwitchName, System.IntPtr pParentName) { - CallbackReceived("LogSwitch", new object[] {pAppDomain, pThread, lLevel, ulReason, pLogSwitchName}); + Call(delegate { + realCallback.LogSwitch( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + lLevel, + ulReason, + MTA2STA.MarshalIntPtrTo(pLogSwitchName), + MTA2STA.MarshalIntPtrTo(pParentName) + ); + }); } - + public void EvalException(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pEval) { - CallbackReceived("EvalException", new object[] {pAppDomain, pThread, pEval}); + Call(delegate { + realCallback.EvalException( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + MTA2STA.MarshalIntPtrTo(pEval) + ); + }); } - + public void LogMessage(System.IntPtr pAppDomain, System.IntPtr pThread, int lLevel, System.IntPtr pLogSwitchName, System.IntPtr pMessage) { - CallbackReceived("LogMessage", new object[] {pAppDomain, pThread, lLevel, pLogSwitchName, pMessage}); + Call(delegate { + realCallback.LogMessage( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + lLevel, + MTA2STA.MarshalIntPtrTo(pLogSwitchName), + MTA2STA.MarshalIntPtrTo(pMessage) + ); + }); } - + public void EditAndContinueRemap(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pFunction, int fAccurate) { - CallbackReceived("EditAndContinueRemap", new object[] {pAppDomain, pThread, pFunction, fAccurate}); + Call(delegate { + realCallback.EditAndContinueRemap( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + MTA2STA.MarshalIntPtrTo(pFunction), + fAccurate + ); + }); } - + public void EvalComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pEval) { - CallbackReceived("EvalComplete", new object[] {pAppDomain, pThread, pEval}); + Call(delegate { + realCallback.EvalComplete( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + MTA2STA.MarshalIntPtrTo(pEval) + ); + }); } - + public void DebuggerError(System.IntPtr pProcess, int errorHR, uint errorCode) { - CallbackReceived("DebuggerError", new object[] {pProcess, errorHR, errorCode}); + Call(delegate { + realCallback.DebuggerError( + MTA2STA.MarshalIntPtrTo(pProcess), + errorHR, + errorCode + ); + }); } - + public void UpdateModuleSymbols(System.IntPtr pAppDomain, System.IntPtr pModule, System.IntPtr pSymbolStream) { - CallbackReceived("UpdateModuleSymbols", new object[] {pAppDomain, pModule, pSymbolStream}); + Call(delegate { + realCallback.UpdateModuleSymbols( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pModule), + MTA2STA.MarshalIntPtrTo(pSymbolStream) + ); + }); } @@ -188,44 +338,97 @@ namespace Debugger public void ChangeConnection(IntPtr pProcess, uint dwConnectionId) { - CallbackReceived("ChangeConnection", new object[] {pProcess, dwConnectionId}); + Call(delegate { + realCallback.ChangeConnection( + MTA2STA.MarshalIntPtrTo(pProcess), + dwConnectionId + ); + }); } - + public void CreateConnection(IntPtr pProcess, uint dwConnectionId, ref ushort pConnName) { - CallbackReceived("CreateConnection", new object[] {pProcess, dwConnectionId, pConnName}); + ushort pName = pConnName; + Call(delegate { + realCallback.CreateConnection( + MTA2STA.MarshalIntPtrTo(pProcess), + dwConnectionId, + ref pName + ); + }); } - + public void DestroyConnection(IntPtr pProcess, uint dwConnectionId) { - CallbackReceived("DestroyConnection", new object[] {pProcess, dwConnectionId}); + Call(delegate { + realCallback.DestroyConnection( + MTA2STA.MarshalIntPtrTo(pProcess), + dwConnectionId + ); + }); } - + public void Exception(IntPtr pAppDomain, IntPtr pThread, IntPtr pFrame, uint nOffset, CorDebugExceptionCallbackType dwEventType, uint dwFlags) { - CallbackReceived("Exception2", new object[] {pAppDomain, pThread, pFrame, nOffset, dwEventType, dwFlags}); + Call(delegate { + realCallback.Exception2( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + MTA2STA.MarshalIntPtrTo(pFrame), + nOffset, + dwEventType, + dwFlags + ); + }); } - + public void ExceptionUnwind(IntPtr pAppDomain, IntPtr pThread, CorDebugExceptionUnwindCallbackType dwEventType, uint dwFlags) { - CallbackReceived("ExceptionUnwind", new object[] {pAppDomain, pThread, dwEventType, dwFlags}); + Call(delegate { + realCallback.ExceptionUnwind( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + dwEventType, + dwFlags + ); + }); } - + public void FunctionRemapComplete(IntPtr pAppDomain, IntPtr pThread, IntPtr pFunction) { - CallbackReceived("FunctionRemapComplete", new object[] {pAppDomain, pThread, pFunction}); + Call(delegate { + realCallback.FunctionRemapComplete( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + MTA2STA.MarshalIntPtrTo(pFunction) + ); + }); } - + public void FunctionRemapOpportunity(IntPtr pAppDomain, IntPtr pThread, IntPtr pOldFunction, IntPtr pNewFunction, uint oldILOffset) { - CallbackReceived("FunctionRemapOpportunity", new object[] {pAppDomain, pThread, pOldFunction, pNewFunction, oldILOffset}); + Call(delegate { + realCallback.FunctionRemapOpportunity( + MTA2STA.MarshalIntPtrTo(pAppDomain), + MTA2STA.MarshalIntPtrTo(pThread), + MTA2STA.MarshalIntPtrTo(pOldFunction), + MTA2STA.MarshalIntPtrTo(pNewFunction), + oldILOffset + ); + }); } - + public void MDANotification(IntPtr pController, IntPtr pThread, IntPtr pMDA) { - CallbackReceived("MDANotification", new object[] {pController, pThread, pMDA}); + Call(delegate { + realCallback.MDANotification( + MTA2STA.MarshalIntPtrTo(pController), + MTA2STA.MarshalIntPtrTo(pThread), + MTA2STA.MarshalIntPtrTo(pMDA) + ); + }); } - + #endregion }