From: Mike McLaughlin Date: Fri, 27 Mar 2015 23:34:05 +0000 (-0700) Subject: Get the dbgshim module to build and enabled all the public APIs with simple/dummy... X-Git-Tag: accepted/tizen/base/20180629.140029~6882^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9d16c5deced95f0d4b1cf1432eb8da8f3702282e;p=platform%2Fupstream%2Fcoreclr.git Get the dbgshim module to build and enabled all the public APIs with simple/dummy implementation for Linux. Rename CMakeLists.txt file. --- diff --git a/src/ToolBox/SOS/Strike/sos.def b/src/ToolBox/SOS/Strike/sos.def index 7452e3c..1f0354c 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 856c577..b20b786 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 b4e7dad..b362065 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 0000000..fb5017f --- /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}/$/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 14bf983..0000000 --- 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}/$/dbgshim.pdb DESTINATION PDB) diff --git a/src/dlls/dbgshim/dbgshim.cpp b/src/dlls/dbgshim/dbgshim.cpp index 65fe6c3..5519234 100644 --- a/src/dlls/dbgshim/dbgshim.cpp +++ b/src/dlls/dbgshim/dbgshim.cpp @@ -16,7 +16,9 @@ #include #include #include +#ifndef FEATURE_PAL #include +#endif #include #include // 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 ae3f2d7..a4c5d3e 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 d01a2d8..68dcd70 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 f64c976..371f3d6 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