diff options
-rw-r--r-- | src/ToolBox/SOS/Strike/sos.def | 4 | ||||
-rw-r--r-- | src/ToolBox/SOS/Strike/util.cpp | 29 | ||||
-rw-r--r-- | src/dlls/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/dlls/dbgshim/CMakeLists.txt | 65 | ||||
-rw-r--r-- | src/dlls/dbgshim/CmakeLists.txt | 39 | ||||
-rw-r--r-- | src/dlls/dbgshim/dbgshim.cpp | 157 | ||||
-rw-r--r-- | src/dlls/dbgshim/dbgshim.h | 5 | ||||
-rw-r--r-- | src/inc/getproductversionnumber.h | 5 | ||||
-rw-r--r-- | src/pal/inc/pal.h | 22 |
9 files changed, 207 insertions, 121 deletions
diff --git a/src/ToolBox/SOS/Strike/sos.def b/src/ToolBox/SOS/Strike/sos.def index 7452e3c833..1f0354c9ca 100644 --- a/src/ToolBox/SOS/Strike/sos.def +++ b/src/ToolBox/SOS/Strike/sos.def @@ -169,10 +169,6 @@ EXPORTS filthint #endif -#ifdef FEATURE_PAL - SetClrDebugDll - UnloadClrDebugDll -#else _EFN_GetManagedExcepStack _EFN_GetManagedExcepStackW _EFN_GetManagedObjectFieldInfo diff --git a/src/ToolBox/SOS/Strike/util.cpp b/src/ToolBox/SOS/Strike/util.cpp index 856c577846..b20b78667f 100644 --- a/src/ToolBox/SOS/Strike/util.cpp +++ b/src/ToolBox/SOS/Strike/util.cpp @@ -4720,7 +4720,7 @@ HRESULT InitCorDebugInterface() return hr; } - + // SOS now has a statically linked version of the loader code that is normally found in mscoree/mscoreei.dll @@ -4778,33 +4778,6 @@ HRESULT InitCorDebugInterface() } - - -#ifdef FEATURE_PAL -// On the Mac, we expect our hosting program to give us the IXCLRDataProcess interface by -// calling this function. -extern "C" HRESULT CALLBACK SetClrDebugDll(IXCLRDataProcess *data) -{ - UnloadClrDebugDll(); - g_clrData = data; - return g_clrData ? S_OK : E_FAIL; -} - -#endif // FEATURE_PAL - -extern "C" void CALLBACK -UnloadClrDebugDll(void) -{ - // On Windows, the Debugger manages the Dac, but on unix we have to do this ourselves. -#ifdef FEATURE_PAL - if (g_clrData) - { - g_clrData->Release(); - g_clrData = NULL; - } -#endif -} - typedef enum { GC_HEAP_INVALID = 0, diff --git a/src/dlls/CMakeLists.txt b/src/dlls/CMakeLists.txt index b4e7dada44..b3620655ce 100644 --- a/src/dlls/CMakeLists.txt +++ b/src/dlls/CMakeLists.txt @@ -1,8 +1,8 @@ if(WIN32) add_subdirectory(clretwrc) - add_subdirectory(dbgshim) endif(WIN32) if(NOT CLR_CMAKE_PLATFORM_DARWIN) + add_subdirectory(dbgshim) add_subdirectory(mscorrc) add_subdirectory(mscordbi) endif(NOT CLR_CMAKE_PLATFORM_DARWIN) diff --git a/src/dlls/dbgshim/CMakeLists.txt b/src/dlls/dbgshim/CMakeLists.txt new file mode 100644 index 0000000000..fb5017ff03 --- /dev/null +++ b/src/dlls/dbgshim/CMakeLists.txt @@ -0,0 +1,65 @@ +add_definitions(-DFEATURE_NO_HOST) +add_definitions(-DSELF_NO_HOST) + +set(DBGSHIM_SOURCES + dbgshim.cpp +) + +if(WIN32) + # Use static crt + add_definitions(-MT) + add_definitions(-DFX_VER_INTERNALNAME_STR=dbgshim.dll) + + list(APPEND DBGSHIM_SOURCES + dbgshim.rc + ) + + preprocess_def_file(${CMAKE_CURRENT_SOURCE_DIR}/dbgshim.ntdef ${CMAKE_CURRENT_BINARY_DIR}/dbgshim.def) + list(APPEND DBGSHIM_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dbgshim.def) +endif(WIN32) + +if(CLR_CMAKE_PLATFORM_UNIX) + add_compile_options(-fPIC) +endif(CLR_CMAKE_PLATFORM_UNIX) + +if(CLR_CMAKE_PLATFORM_LINUX) + # This option is necessary to ensure that the overloaded delete operator defined inside + # of the utilcode will be used instead of the standard library delete operator. + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -Bsymbolic-functions") +endif(CLR_CMAKE_PLATFORM_LINUX) + +add_library(dbgshim SHARED ${DBGSHIM_SOURCES}) + +set(DBGSHIM_LIBRARIES + debugshim + corguids + dbgutil + utilcodestaticnohost +) + +if(WIN32) + list(APPEND DBGSHIM_LIBRARIES + kernel32.lib + ${STATIC_MT_CRT_LIB} + uuid.lib + user32.lib + advapi32.lib + oleaut32.lib + WtsApi32.lib + version.lib + psapi.lib + ) +else() + list(APPEND DBGSHIM_LIBRARIES + CoreClrPal + palrt + ) +endif(WIN32) + +target_link_libraries(dbgshim ${DBGSHIM_LIBRARIES}) + +# add the install targets +install (TARGETS dbgshim DESTINATION .) +if(WIN32) + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/dbgshim.pdb DESTINATION PDB) +endif(WIN32) diff --git a/src/dlls/dbgshim/CmakeLists.txt b/src/dlls/dbgshim/CmakeLists.txt deleted file mode 100644 index 14bf9831aa..0000000000 --- a/src/dlls/dbgshim/CmakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -add_definitions(-DFEATURE_NO_HOST) -add_definitions(-DSELF_NO_HOST) -# Use static crt -add_definitions(-MT) - -set(DBGSHIM_SOURCES - dbgshim.cpp - dbgshim.rc -) - -add_definitions(-DFX_VER_INTERNALNAME_STR=dbgshim.dll) - -preprocess_def_file(${CMAKE_CURRENT_SOURCE_DIR}/dbgshim.ntdef ${CMAKE_CURRENT_BINARY_DIR}/dbgshim.def) - -list(APPEND DBGSHIM_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dbgshim.def) - -add_library(dbgshim SHARED ${DBGSHIM_SOURCES}) - -set(DBGSHIM_LIBRARIES - debugshim - corguids - dbgutil - utilcodestaticnohost - kernel32.lib - ${STATIC_MT_CRT_LIB} - uuid.lib - user32.lib - advapi32.lib - oleaut32.lib - WtsApi32.lib - version.lib - psapi.lib -) - -target_link_libraries(dbgshim ${DBGSHIM_LIBRARIES}) - -# add the install targets -install (TARGETS dbgshim DESTINATION .) -install (FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/dbgshim.pdb DESTINATION PDB) diff --git a/src/dlls/dbgshim/dbgshim.cpp b/src/dlls/dbgshim/dbgshim.cpp index 65fe6c3621..5519234bd7 100644 --- a/src/dlls/dbgshim/dbgshim.cpp +++ b/src/dlls/dbgshim/dbgshim.cpp @@ -16,7 +16,9 @@ #include <tlhelp32.h> #include <cor.h> #include <sstring.h> +#ifndef FEATURE_PAL #include <securityutil.h> +#endif #include <ex.h> #include <cordebug.h> // for Version nunmbers @@ -76,15 +78,18 @@ Notes: //----------------------------------------------------------------------------- #define StartupNotifyEventNamePrefix W("TelestoStartupEvent_") const int cchEventNameBufferSize = sizeof(StartupNotifyEventNamePrefix)/sizeof(WCHAR) + 8; // + hex DWORD (8). NULL terminator is included in sizeof(StartupNotifyEventNamePrefix) + HRESULT GetStartupNotificationEvent(DWORD debuggeePID, __out HANDLE* phStartupEvent) { PUBLIC_CONTRACT; - HRESULT hr; if (phStartupEvent == NULL) return E_INVALIDARG; +#ifndef FEATURE_PAL + HRESULT hr; + // Note this event name doesn't have a Global prefix, and so debugging across sessions will not work. WCHAR szEventName[cchEventNameBufferSize]; swprintf_s(szEventName, cchEventNameBufferSize, StartupNotifyEventNamePrefix W("%08x"), debuggeePID); @@ -126,14 +131,13 @@ HRESULT GetStartupNotificationEvent(DWORD debuggeePID, } *phStartupEvent = startupEvent; +#else + *phStartupEvent = NULL; +#endif // FEATURE_PAL return S_OK; } -HRESULT GetContinueStartupEvent(DWORD debuggeePID, - LPCWSTR szTelestoFullPath, - __out HANDLE* phContinueStartupEvent); - //----------------------------------------------------------------------------- // Public API. // @@ -157,6 +161,7 @@ HRESULT CloseCLREnumeration(HANDLE* pHandleArray, LPWSTR* pStringArray, DWORD dw if (pHandleArray == NULL) return S_OK; +#ifndef FEATURE_PAL for (DWORD i = 0; i < dwArrayLength; i++) { HANDLE hTemp = pHandleArray[i]; @@ -166,11 +171,18 @@ HRESULT CloseCLREnumeration(HANDLE* pHandleArray, LPWSTR* pStringArray, DWORD dw CloseHandle(hTemp); } } +#endif // FEATURE_PAL delete[] pHandleArray; return S_OK; } +#ifndef FEATURE_PAL + +HRESULT GetContinueStartupEvent(DWORD debuggeePID, + LPCWSTR szTelestoFullPath, + __out HANDLE* phContinueStartupEvent); + // Refer to clr\src\mscoree\mscorwks_ntdef.src. const WORD kOrdinalForMetrics = 2; @@ -390,6 +402,8 @@ bool IsCoreClrWithGoodHeader(HANDLE hProcess, HMODULE hModule) return false; } +#endif // !FEATURE_PAL + //----------------------------------------------------------------------------- // Public API. // @@ -421,6 +435,7 @@ HRESULT EnumerateCLRs(DWORD debuggeePID, if ((ppHandleArrayOut == NULL) || (ppStringArrayOut == NULL) || (pdwArrayLengthOut == NULL)) return E_INVALIDARG; +#ifndef FEATURE_PAL HandleHolder hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, debuggeePID); if (NULL == hProcess) ThrowHR(E_FAIL); @@ -446,7 +461,6 @@ HRESULT EnumerateCLRs(DWORD debuggeePID, } } - // If we didn't find anything, no point in continuing. if (count == 0) { @@ -454,8 +468,11 @@ HRESULT EnumerateCLRs(DWORD debuggeePID, *ppStringArrayOut = NULL; *pdwArrayLengthOut = 0; - return S_OK; + return S_OK; } +#else + DWORD count = 1; +#endif // FEATURE_PAL size_t cbEventArrayData = sizeof(HANDLE) * count; // event array data size_t cbStringArrayData = sizeof(LPWSTR) * count; // string array data @@ -471,20 +488,20 @@ HRESULT EnumerateCLRs(DWORD debuggeePID, HANDLE* pEventArray = (HANDLE*) &pOutBuffer[0]; LPWSTR* pStringArray = (LPWSTR*) &pOutBuffer[cbEventArrayData]; WCHAR* pStringData = (WCHAR*) &pOutBuffer[cbEventArrayData + cbStringArrayData]; + DWORD idx = 0; +#ifndef FEATURE_PAL + // There's no guarantee that another coreclr hasn't loaded already anyhow, + // so if we get the corner case that the second time through we enumerate + // more coreclrs, just ignore the extras. + // This mismatch could happen when + // a) take module shapshot + // b) underlying file is opened for exclusive access/deleted/moved/ACL'd etc so we can't open it + // c) count is determined + // d) file is closed/copied/moved/ACL'd etc so we can find/open it again + // e) this loop runs + // Thus the loop checks idx < count - // There's no guarantee that another coreclr hasn't loaded already anyhow, - // so if we get the corner case that the second time through we enumerate - // more coreclrs, just ignore the extras. - // This mismatch could happen when - // a) take module shapshot - // b) underlying file is opened for exclusive access/deleted/moved/ACL'd etc so we can't open it - // c) count is determined - // d) file is closed/copied/moved/ACL'd etc so we can find/open it again - // e) this loop runs - // Thus the loop checks idx < count - - DWORD idx = 0; for(DWORD i = 0; i < countModules && idx < count; i++) { if (IsCoreClrWithGoodHeader(hProcess, modules[i])) @@ -527,6 +544,11 @@ HRESULT EnumerateCLRs(DWORD debuggeePID, // Strings themselves don't need moved. } +#else + pStringArray[idx] = &pStringData[idx * MAX_PATH]; + wcscpy_s(pStringArray[idx], MAX_PATH, MAKEDLLNAME_W(W("coreclr"))); + idx++; +#endif // FEATURE_PAL *ppHandleArrayOut = pEventArray; *ppStringArrayOut = pStringArray; @@ -535,6 +557,8 @@ HRESULT EnumerateCLRs(DWORD debuggeePID, return S_OK; } +#ifndef FEATURE_PAL + //----------------------------------------------------------------------------- // Get the base address of a module from the remote process. // @@ -586,6 +610,8 @@ BYTE* GetRemoteModuleBaseAddress(DWORD dwPID, LPCWSTR szFullModulePath) return NULL; } +#endif // FEATURE_PAL + // DBI version: max 8 hex chars // SEMICOLON: 1 // PID: max 8 hex chars @@ -654,6 +680,7 @@ HRESULT CreateVersionStringFromModule(DWORD pidDebuggee, } else if (pBuffer != NULL) { +#ifndef FEATURE_PAL HRESULT hr = S_OK; EX_TRY { @@ -671,11 +698,16 @@ HRESULT CreateVersionStringFromModule(DWORD pidDebuggee, } EX_CATCH_HRESULT(hr); return hr; +#else + swprintf_s(pBuffer, cchBuffer, W("%08x"), pidDebuggee); +#endif // FEATURE_PAL } return S_OK; } +#ifndef FEATURE_PAL + // Functions that we'll look for in the loaded Mscordbi module. typedef HRESULT (STDAPICALLTYPE *FPCoreCLRCreateCordbObject)( int iDebuggerVersion, @@ -822,6 +854,15 @@ bool CheckDbiAndRuntimeVersion(SString & szFullDbiPath, SString & szFullCoreClrP } } +#else + +// Functions that we'll look for in the loaded Mscordbi module. +typedef HRESULT (STDAPICALLTYPE *FPCreateCordbObject)( + int iDebuggerVersion, + IUnknown ** ppCordb); + +#endif // FEATURE_PAL + //----------------------------------------------------------------------------- // Public API. // Given a version string, create the matching mscordbi.dll for it. @@ -840,20 +881,16 @@ bool CheckDbiAndRuntimeVersion(SString & szFullDbiPath, SString & szFullCoreClrP //----------------------------------------------------------------------------- HRESULT CreateDebuggingInterfaceFromVersionEx( int iDebuggerVersion, - LPCWSTR szDebuggeeVersion, + LPCWSTR szDebuggeeVersion, IUnknown ** ppCordb -) + ) { PUBLIC_CONTRACT; - HRESULT hrIgnore; // ignored HResult + HRESULT hrIgnore = S_OK; // ignored HResult HRESULT hr = S_OK; HMODULE hMod = NULL; IUnknown * pCordb = NULL; - - SString szFullDbiPath; - SString szFullCoreClrPath; - LOG((LF_CORDB, LL_EVERYTHING, "Calling CreateDebuggerInterfaceFromVersion, ver=%S\n", szDebuggeeVersion)); if ((szDebuggeeVersion == NULL) || (ppCordb == NULL)) @@ -864,10 +901,11 @@ HRESULT CreateDebuggingInterfaceFromVersionEx( *ppCordb = NULL; +#ifndef FEATURE_PAL // // Step 1: Parse version information into internal data structures // - + CorDebugInterfaceVersion iTargetVersion; // the CorDebugInterfaceVersion (CorDebugVersion_2_0) DWORD pidDebuggee; // OS process ID of the debuggee HMODULE hmodTargetCLR; // module of Telesto in target (the clrInstanceId) @@ -876,7 +914,6 @@ HRESULT CreateDebuggingInterfaceFromVersionEx( if (FAILED(hr)) goto Exit; - // // Step 2: Find the proper Dbi module (mscordbi.dll) and load it. // @@ -885,6 +922,9 @@ HRESULT CreateDebuggingInterfaceFromVersionEx( // This will be very common for internal developer setups, but not common in end-user setups. EX_TRY { + SString szFullDbiPath; + SString szFullCoreClrPath; + GetDbiFilenameNextToRuntime(pidDebuggee, hmodTargetCLR, szFullDbiPath, szFullCoreClrPath); if (!CheckDbiAndRuntimeVersion(szFullDbiPath, szFullCoreClrPath)) @@ -896,10 +936,10 @@ HRESULT CreateDebuggingInterfaceFromVersionEx( // We calculated where dbi would be, but haven't yet verified if it's there. // Try to load it. We're using this to check for file existence. - // Issue:951525: coreclr mscordbi load fails on downlevel OS since LoadLibraryEx can't find - // dependent forwarder DLLs. Force LoadLibrary to look for dependencies in szFullDbiPath plus the default - // search paths. - hMod = WszLoadLibraryEx(szFullDbiPath, NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + // Issue:951525: coreclr mscordbi load fails on downlevel OS since LoadLibraryEx can't find + // dependent forwarder DLLs. Force LoadLibrary to look for dependencies in szFullDbiPath plus the default + // search paths. + hMod = WszLoadLibraryEx(szFullDbiPath, NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); } EX_CATCH_HRESULT(hrIgnore); // failure leaves hMod null @@ -922,21 +962,34 @@ HRESULT CreateDebuggingInterfaceFromVersionEx( // // Step 3: Now that module is loaded, instantiate an ICorDebug. // - - FPCoreCLRCreateCordbObject fpCreate2 = (FPCoreCLRCreateCordbObject) GetProcAddress(hMod, "CoreCLRCreateCordbObject"); + FPCoreCLRCreateCordbObject fpCreate2 = (FPCoreCLRCreateCordbObject)GetProcAddress(hMod, "CoreCLRCreateCordbObject"); if (fpCreate2 == NULL) { // New-style creation API didn't exist - this DBI must be the wrong version, for the Mix07 protocol hr = CORDBG_E_INCOMPATIBLE_PROTOCOL; goto Exit; } - + // Invoke to instantiate an ICorDebug. This export was introduced after the Mix'07 release. hr = fpCreate2(iDebuggerVersion, pidDebuggee, hmodTargetCLR, &pCordb); +#else + { + hMod = LoadLibraryExW(MAKEDLLNAME_W(W("mscordbi")), NULL, 0); + if (NULL == hMod) + { + hr = CORDBG_E_DEBUG_COMPONENT_MISSING; + goto Exit; + } + FPCreateCordbObject fpCreate = (FPCreateCordbObject)GetProcAddress(hMod, "CreateCordbObject"); + if (fpCreate == NULL) + { + hr = CORDBG_E_INCOMPATIBLE_PROTOCOL; + goto Exit; + } + hr = fpCreate(iDebuggerVersion, &pCordb); + } +#endif // FEATURE_PAL _ASSERTE((pCordb == NULL) == FAILED(hr)); - - - Exit: if (FAILED(hr)) @@ -996,6 +1049,7 @@ HRESULT CreateDebuggingInterfaceFromVersion( ppCordb); } +#ifndef FEATURE_PAL //------------------------------------------------------------------------------ // Manually retrieves the "continue startup" event from the correct CLR instance @@ -1058,6 +1112,7 @@ HRESULT GetContinueStartupEvent(DWORD debuggeePID, return hr; } +#endif // !FEATURE_PAL #if defined(FEATURE_CORESYSTEM) && defined(_TARGET_X86_) #include "debugshim.h" @@ -1088,6 +1143,32 @@ HRESULT CLRCreateInstance(REFCLSID clsid, REFIID riid, LPVOID *ppInterface) #endif } +#ifdef FEATURE_PAL +EXTERN_C BOOL WINAPI +DllMain(HANDLE instance, DWORD reason, LPVOID reserved) +{ + int err = 0; + switch (reason) + { + case DLL_PROCESS_ATTACH: + { + err = PAL_InitializeDLL(); + break; + } + + case DLL_THREAD_ATTACH: + err = PAL_EnterTop(); + break; + } + + if (err != 0) + { + return FALSE; + } + + return TRUE; +} +#endif // FEATURE_PAL diff --git a/src/dlls/dbgshim/dbgshim.h b/src/dlls/dbgshim/dbgshim.h index ae3f2d70f3..a4c5d3ee5c 100644 --- a/src/dlls/dbgshim/dbgshim.h +++ b/src/dlls/dbgshim/dbgshim.h @@ -25,6 +25,11 @@ HRESULT CreateVersionStringFromModule(DWORD pidDebuggee, DWORD cchBuffer, __out DWORD* pdwLength); +HRESULT CreateDebuggingInterfaceFromVersionEx( + int iDebuggerVersion, + LPCWSTR szDebuggeeVersion, + IUnknown ** ppCordb); + HRESULT CreateDebuggingInterfaceFromVersion( LPCWSTR szDebuggeeVersion, IUnknown ** ppCordb); diff --git a/src/inc/getproductversionnumber.h b/src/inc/getproductversionnumber.h index d01a2d8403..68dcd702ab 100644 --- a/src/inc/getproductversionnumber.h +++ b/src/inc/getproductversionnumber.h @@ -36,6 +36,7 @@ void inline GetProductVersionNumber(SString &szFullPath, DWORD * pdwVersionMS, DWORD * pdwVersionLS) { WRAPPER_NO_CONTRACT; +#ifndef FEATURE_PAL DWORD dwDummy = 0; DWORD dwFileInfoSize = 0; @@ -68,6 +69,10 @@ void inline GetProductVersionNumber(SString &szFullPath, DWORD * pdwVersionMS, D *pdwVersionMS = pVersionInfo->dwProductVersionMS; *pdwVersionLS = pVersionInfo->dwProductVersionLS; +#else + *pdwVersionMS = 0; + *pdwVersionLS = 0; +#endif // FEATURE_PAL } #endif // __GetProductVersionNumber_h__ diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index f64c976f22..371f3d60a2 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -3295,22 +3295,22 @@ PALIMPORT FARPROC PALAPI GetProcAddress( - IN HMODULE hModule, - IN LPCSTR lpProcName); + IN HMODULE hModule, + IN LPCSTR lpProcName); PALIMPORT BOOL PALAPI FreeLibrary( - IN OUT HMODULE hLibModule); + IN OUT HMODULE hLibModule); PALIMPORT PAL_NORETURN VOID PALAPI FreeLibraryAndExitThread( - IN HMODULE hLibModule, - IN DWORD dwExitCode); + IN HMODULE hLibModule, + IN DWORD dwExitCode); PALIMPORT BOOL @@ -3322,17 +3322,17 @@ PALIMPORT DWORD PALAPI GetModuleFileNameA( - IN HMODULE hModule, - OUT LPSTR lpFileName, - IN DWORD nSize); + IN HMODULE hModule, + OUT LPSTR lpFileName, + IN DWORD nSize); PALIMPORT DWORD PALAPI GetModuleFileNameW( - IN HMODULE hModule, - OUT LPWSTR lpFileName, - IN DWORD nSize); + IN HMODULE hModule, + OUT LPWSTR lpFileName, + IN DWORD nSize); #ifdef UNICODE #define GetModuleFileName GetModuleFileNameW |