diff options
author | Eugene Zemtsov <Eugene.Zemtsov@microsoft.com> | 2015-06-15 17:03:23 -0700 |
---|---|---|
committer | Eugene Zemtsov <Eugene.Zemtsov@microsoft.com> | 2015-06-15 17:03:23 -0700 |
commit | e869a08e0bc1cc848b92da51c67fdb7ce4c98de6 (patch) | |
tree | 05657ca8b818614ce8d01743ef0031b8134f4982 /src/dlls/dbgshim | |
parent | 11b9438b15629b7d60816de07bf1139f521cf3be (diff) | |
download | coreclr-e869a08e0bc1cc848b92da51c67fdb7ce4c98de6.tar.gz coreclr-e869a08e0bc1cc848b92da51c67fdb7ce4c98de6.tar.bz2 coreclr-e869a08e0bc1cc848b92da51c67fdb7ce4c98de6.zip |
Make sure dbgshim can attach to processes from other sessions
[tfs-changeset: 1488695]
Diffstat (limited to 'src/dlls/dbgshim')
-rw-r--r-- | src/dlls/dbgshim/dbgshim.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/dlls/dbgshim/dbgshim.cpp b/src/dlls/dbgshim/dbgshim.cpp index aa972d8d2f..79a33cdcb7 100644 --- a/src/dlls/dbgshim/dbgshim.cpp +++ b/src/dlls/dbgshim/dbgshim.cpp @@ -81,7 +81,14 @@ Notes: // //----------------------------------------------------------------------------- #define StartupNotifyEventNamePrefix W("TelestoStartupEvent_") -const int cchEventNameBufferSize = sizeof(StartupNotifyEventNamePrefix)/sizeof(WCHAR) + 8; // + hex DWORD (8). NULL terminator is included in sizeof(StartupNotifyEventNamePrefix) +#define SessionIdPrefix W("Session\\") + +// NULL terminator is included in sizeof(StartupNotifyEventNamePrefix) +const int cchEventNameBufferSize = (sizeof(StartupNotifyEventNamePrefix) + sizeof(SessionIdPrefix)) / sizeof(WCHAR) + + 8 // + hex process id DWORD + + 10 // + decimal session id DWORD + + 1; // '\' after session id + HRESULT GetStartupNotificationEvent(DWORD debuggeePID, __out HANDLE* phStartupEvent) @@ -93,10 +100,30 @@ HRESULT GetStartupNotificationEvent(DWORD debuggeePID, #ifndef FEATURE_PAL HRESULT hr; + DWORD currentSessionId = 0, debuggeeSessionId = 0; + if (!ProcessIdToSessionId(GetCurrentProcessId(), ¤tSessionId)) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (!ProcessIdToSessionId(debuggeePID, &debuggeeSessionId)) + { + return HRESULT_FROM_WIN32(GetLastError()); + } - // Note this event name doesn't have a Global prefix, and so debugging across sessions will not work. + // Here we could just add "Global\" to the event name and this would solve cross-session debugging scenario, but that would require event name change + // in CoreCLR, and break backward compatibility. Instead if we see that debugee is in a different session, we explicitly create startup event + // in that session (by adding "Session\#\"). We could do it even for our own session, but that's vaguely documented behavior and we'd + // like to use it as little as possible. WCHAR szEventName[cchEventNameBufferSize]; - swprintf_s(szEventName, cchEventNameBufferSize, StartupNotifyEventNamePrefix W("%08x"), debuggeePID); + if (currentSessionId == debuggeeSessionId) + { + swprintf_s(szEventName, cchEventNameBufferSize, StartupNotifyEventNamePrefix W("%08x"), debuggeePID); + } + else + { + swprintf_s(szEventName, cchEventNameBufferSize, SessionIdPrefix W("%u\\") StartupNotifyEventNamePrefix W("%08x"), debuggeeSessionId, debuggeePID); + } // Determine an appropriate ACL and SECURITY_ATTRIBUTES to apply to this event. We use the same logic // here as the debugger uses for other events (like the setup-sync-event). Specifically, this does |