diff options
author | Andrew Au <andrewau@microsoft.com> | 2017-05-20 01:19:36 +0300 |
---|---|---|
committer | Andrew Au <andrewau@microsoft.com> | 2017-05-20 01:19:36 +0300 |
commit | 374a3c743cbbf4f43097ffb5569924ef02b05ce9 (patch) | |
tree | b10ad677b17a11f4343d8731d529a554ea64f1c4 /src | |
parent | fc82237c820e10baf1c6687cf7c9e03b207a4af4 (diff) |
Debugger Support
[tfs-changeset: 1658968]
Diffstat (limited to 'src')
5 files changed, 50 insertions, 1 deletions
diff --git a/src/Native/Runtime/DebuggerHook.cpp b/src/Native/Runtime/DebuggerHook.cpp index 26ca90497..08da25213 100644 --- a/src/Native/Runtime/DebuggerHook.cpp +++ b/src/Native/Runtime/DebuggerHook.cpp @@ -4,6 +4,7 @@ #include "common.h" #include "CommonTypes.h" +#include "CommonMacros.h" #include "DebuggerHook.h" #include "DebugEventSource.h" #include "Debug.h" @@ -14,6 +15,10 @@ GVAL_IMPL_INIT(UInt32, g_numGcProtectionRequests, 0); /* static */ DebuggerProtectedBufferList* DebuggerHook::s_debuggerProtectedBuffers = nullptr; +/* static */ DebuggerOwnedHandleList* DebuggerHook::s_debuggerOwnedHandleList = nullptr; + +/* static */ UInt32 DebuggerHook::s_debuggeeInitiatedHandleIdentifier = 2; + /* static */ void DebuggerHook::OnBeforeGcCollection() { if (g_numGcProtectionRequests > 0) @@ -109,4 +114,27 @@ GVAL_IMPL_INIT(UInt32, g_numGcProtectionRequests, 0); } } +/* static */ UInt32 DebuggerHook::RecordDebuggeeInitiatedHandle(void* objectHandle) +{ + DebuggerOwnedHandleList* head = new (nothrow) DebuggerOwnedHandleList(); + if (head == nullptr) + { + return 0; + } + + head->handle = objectHandle; + head->identifier = DebuggerHook::s_debuggeeInitiatedHandleIdentifier; + head->next = s_debuggerOwnedHandleList; + s_debuggerOwnedHandleList = head; + + s_debuggeeInitiatedHandleIdentifier += 2; + + return head->identifier; +} + +EXTERN_C REDHAWK_API UInt32 __cdecl RhpRecordDebuggeeInitiatedHandle(void* objectHandle) +{ + return DebuggerHook::RecordDebuggeeInitiatedHandle(objectHandle); +} + #endif // !DACCESS_COMPILE
\ No newline at end of file diff --git a/src/Native/Runtime/DebuggerHook.h b/src/Native/Runtime/DebuggerHook.h index feb1d3e24..bc6c87ded 100644 --- a/src/Native/Runtime/DebuggerHook.h +++ b/src/Native/Runtime/DebuggerHook.h @@ -25,11 +25,21 @@ struct DebuggerProtectedBufferList struct DebuggerProtectedBufferList* next; }; +struct DebuggerOwnedHandleList +{ + void* handle; + UInt32 identifier; + struct DebuggerOwnedHandleList* next; +}; + class DebuggerHook { public: static void OnBeforeGcCollection(); + static UInt32 RecordDebuggeeInitiatedHandle(void* handle); static DebuggerProtectedBufferList* s_debuggerProtectedBuffers; + static DebuggerOwnedHandleList* s_debuggerOwnedHandleList; + static UInt32 s_debuggeeInitiatedHandleIdentifier; }; #endif //!DACCESS_COMPILE diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs index 49da77fd1..63f21775c 100644 --- a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs +++ b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs @@ -1076,6 +1076,12 @@ namespace Internal.Runtime.Augments return RuntimeImports.RhpGetFuncEvalParameterBufferSize(); } + [CLSCompliant(false)] + public static unsafe uint RhpRecordDebuggeeInitiatedHandle(IntPtr objectHandle) + { + return RuntimeImports.RhpRecordDebuggeeInitiatedHandle((void*)objectHandle); + } + public static unsafe object RhBoxAny(IntPtr pData, IntPtr pEEType) { return RuntimeImports.RhBoxAny((void*)pData, new EETypePtr(pEEType)); diff --git a/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index bf7bc1b99..4a9c71d98 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -43,6 +43,9 @@ namespace System.Runtime [DllImport(RuntimeLibrary, ExactSpelling = true)] internal static extern uint RhpGetFuncEvalParameterBufferSize(); + [DllImport(RuntimeLibrary, ExactSpelling = true)] + internal static extern unsafe uint RhpRecordDebuggeeInitiatedHandle(void* objectHandle); + // // calls to GC // These methods are needed to implement System.GC like functionality (optional) diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/DebugFuncEval.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/DebugFuncEval.cs index e3089de06..d3d1162be 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/DebugFuncEval.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/DebugFuncEval.cs @@ -52,11 +52,13 @@ namespace Internal.Runtime.TypeLoader IntPtr input = arguments.GetAddressOfVarData(0); object returnValue = RuntimeAugments.RhBoxAny(input, (IntPtr)param.types[0].ToEETypePtr()); GCHandle returnValueHandle = GCHandle.Alloc(returnValue); + IntPtr returnValueHandlePointer = GCHandle.ToIntPtr(returnValueHandle); + uint identifier = RuntimeAugments.RhpRecordDebuggeeInitiatedHandle(returnValueHandlePointer); // Signal to the debugger the func eval completes FuncEvalCompleteCommand* funcEvalCompleteCommand = stackalloc FuncEvalCompleteCommand[1]; funcEvalCompleteCommand->commandCode = 0; - funcEvalCompleteCommand->returnAddress = (long)GCHandle.ToIntPtr(returnValueHandle); + funcEvalCompleteCommand->returnAddress = (long)returnValueHandlePointer; IntPtr funcEvalCompleteCommandPointer = new IntPtr(funcEvalCompleteCommand); RuntimeAugments.RhpSendCustomEventToDebugger(funcEvalCompleteCommandPointer, Unsafe.SizeOf<FuncEvalCompleteCommand>()); } |