diff --git a/CMakeLists.txt b/CMakeLists.txt index 149ae1b17a37..f7872e00ee3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ endif() set(CLR_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(VM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/vm) +set(GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/inc) if(CMAKE_SYSTEM_NAME STREQUAL Linux) set(CLR_CMAKE_PLATFORM_UNIX 1) diff --git a/src/debug/daccess/CMakeLists.txt b/src/debug/daccess/CMakeLists.txt index ba5ae147126d..c84fe625b996 100644 --- a/src/debug/daccess/CMakeLists.txt +++ b/src/debug/daccess/CMakeLists.txt @@ -16,7 +16,8 @@ include_directories(${CLR_DIR}/src/gc) include_directories(${CLR_DIR}/src/gcdump) if(CLR_CMAKE_PLATFORM_UNIX) - add_compile_options(-fPIC) + include_directories(${GENERATED_INCLUDE_DIR}) + add_compile_options(-fPIC) endif(CLR_CMAKE_PLATFORM_UNIX) set(DACCESS_SOURCES @@ -54,3 +55,7 @@ convert_to_absolute_path(DACCESS_SOURCES ${DACCESS_SOURCES}) add_precompiled_header(stdafx.h stdafx.cpp DACCESS_SOURCES) add_library(daccess ${DACCESS_SOURCES}) + +if(CLR_CMAKE_PLATFORM_UNIX) + add_dependencies(daccess coreclr) +endif(CLR_CMAKE_PLATFORM_UNIX) diff --git a/src/debug/daccess/daccess.cpp b/src/debug/daccess/daccess.cpp index ded8ff9272e5..9d21dcad2c22 100644 --- a/src/debug/daccess/daccess.cpp +++ b/src/debug/daccess/daccess.cpp @@ -25,6 +25,9 @@ #include "dwreport.h" #include "primitives.h" #include "dbgutil.h" +#ifdef FEATURE_PAL +#include +#endif #include "dwbucketmanager.hpp" @@ -7196,20 +7199,14 @@ HRESULT ClrDataAccess::GetDacGlobals() { #ifdef FEATURE_PAL - PVOID dacTableAddress = nullptr; - ULONG dacTableSize = 0; - DWORD err = PAL_GetDacTableAddress((PVOID)m_globalBase, &dacTableAddress, &dacTableSize); - if (err != ERROR_SUCCESS) - { - return CORDBG_E_MISSING_DEBUGGER_EXPORTS; - } - - if (dacTableSize != sizeof(g_dacGlobals)) +#ifdef DAC_TABLE_SIZE + if (DAC_TABLE_SIZE != sizeof(g_dacGlobals)) { return E_INVALIDARG; } - - if (FAILED(ReadFromDataTarget(m_pTarget, (ULONG64)dacTableAddress, (BYTE*)&g_dacGlobals, dacTableSize))) +#endif + ULONG64 dacTableAddress = m_globalBase + DAC_TABLE_RVA; + if (FAILED(ReadFromDataTarget(m_pTarget, dacTableAddress, (BYTE*)&g_dacGlobals, sizeof(g_dacGlobals)))) { return CORDBG_E_MISSING_DEBUGGER_EXPORTS; } diff --git a/src/debug/ee/dactable.cpp b/src/debug/ee/dactable.cpp index c7cf64e18680..b1925830b692 100644 --- a/src/debug/ee/dactable.cpp +++ b/src/debug/ee/dactable.cpp @@ -58,7 +58,6 @@ void DacGlobals::Initialize() #ifdef FEATURE_SVR_GC g_dacTable.InitializeSVREntries(baseAddress); #endif - PAL_PublishDacTableAddress((PVOID)baseAddress, &g_dacTable, sizeof(g_dacTable)); } // Initializes the non-SVR table entries diff --git a/src/dlls/mscoree/coreclr/CMakeLists.txt b/src/dlls/mscoree/coreclr/CMakeLists.txt index 9337fc54b456..d6653a03e344 100644 --- a/src/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/dlls/mscoree/coreclr/CMakeLists.txt @@ -117,7 +117,6 @@ endif(WIN32) target_link_libraries(coreclr ${CORECLR_LIBRARIES}) if(WIN32) - add_dependencies(coreclr dactablegen) # Add dac table & debug resource to coreclr @@ -134,6 +133,14 @@ if(WIN32) COMMAND $ /bin:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin /dll:$ /name:CLRDEBUGINFO COMMENT Add dactable & debug resources to coreclr ) +else() + add_custom_command( + TARGET coreclr + POST_BUILD + VERBATIM + COMMAND sh ${CLR_DIR}/src/pal/tools/gen-dactable-rva.sh $ ${GENERATED_INCLUDE_DIR}/dactablerva.h + COMMENT Generating ${GENERATED_INCLUDE_DIR}/dactablerva.h + ) endif(WIN32) # add the install targets diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index b9d537f65434..2148b119a33a 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -599,32 +599,6 @@ PAL_DeleteExecWatchpoint( #endif -PALIMPORT -DWORD -PALAPI -PAL_PublishDacTableAddress( - IN PVOID baseAddress, - IN PVOID tableAddress, - IN ULONG tableSize - ); - -PALIMPORT -DWORD -PALAPI -PAL_GetDacTableAddress( - IN PVOID baseAddress, - OUT PVOID *tableAddress, - OUT PULONG tableSize - ); - -PALIMPORT -VOID -PALAPI -PAL_CleanupDacTableAddress( - IN PVOID baseAddress - ); - - /******************* winuser.h Entrypoints *******************************/ PALIMPORT diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt index bc966c1ce58a..890fc4c46c63 100644 --- a/src/pal/src/CMakeLists.txt +++ b/src/pal/src/CMakeLists.txt @@ -104,7 +104,6 @@ set(SOURCES misc/interlock.cpp misc/miscpalapi.cpp misc/msgbox.cpp - misc/dactableaddress.cpp misc/strutil.cpp misc/sysinfo.cpp misc/time.cpp diff --git a/src/pal/src/misc/dactableaddress.cpp b/src/pal/src/misc/dactableaddress.cpp deleted file mode 100644 index ba635a0226da..000000000000 --- a/src/pal/src/misc/dactableaddress.cpp +++ /dev/null @@ -1,161 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -/*++ - - - -Module Name: - - dactableaddress.cpp - -Abstract: - - Functions to write and read DAC global pointer table address between the coreclr - and DAC/debugger processes. - -NOTE: - - These functions are temporary until a better way to plumb the DAC table - address from the debuggee to debugger processes is implemented. - -Revision History: - - ---*/ - -#include "pal/palinternal.h" -#include -#include -#include - -/*++ -Function - PAL_PublishDacTableAddress - -Parameters - - baseAddress - [in] base address of CLR module - tableAddress - [in] address of dac table - tableSize - [in] size of dac table - -Return Values - pal errors - ---*/ -PALIMPORT -DWORD -PALAPI -PAL_PublishDacTableAddress( - IN PVOID baseAddress, - IN PVOID tableAddress, - IN ULONG tableSize) -{ - DWORD ret = NO_ERROR; - - char fileName[100]; - snprintf(fileName, sizeof(fileName), "/tmp/%p_dacTable", baseAddress); - - FILE *file = fopen(fileName, "w+"); - if (file != nullptr) - { - char dacTableInfo[100]; - snprintf(dacTableInfo, sizeof(dacTableInfo), "%p %d\n", tableAddress, tableSize); - - if (fputs(dacTableInfo, file) < 0) - { - ret = ERROR_INVALID_DATA; - } - - fclose(file); - } - else - { - ret = ERROR_FILE_NOT_FOUND; - } - - return ret; -} - - -/*++ -Function - PAL_GetDacTableAddress - -Parameters - - baseAddress - [in] base address of CLR module - tableAddress - [out] pointer to put DAC table address - tableSize - [out] pointer to put DAC table size - -Return Values - pal errors - ---*/ -PALIMPORT -DWORD -PALAPI -PAL_GetDacTableAddress( - IN PVOID baseAddress, - OUT PVOID *tableAddress, - OUT PULONG tableSize) -{ - DWORD ret = NO_ERROR; - - char fileName[100]; - snprintf(fileName, sizeof(fileName), "/tmp/%p_dacTable", baseAddress); - - FILE *file = fopen(fileName, "r"); - if (file != nullptr) - { - char data[100]; - if (fgets(data, sizeof(data), file) != nullptr) - { - if (sscanf(data, "%p %d\n", tableAddress, tableSize) != 2) - { - ret = ERROR_INVALID_DATA; - } - } - else - { - ret = ERROR_INVALID_DATA; - } - - fclose(file); - } - else - { - ret = ERROR_FILE_NOT_FOUND; - } - return ret; -} - -/*++ -Function - PAL_CleanupDacTableAddress - -Parameters - None - -Return Values - None - ---*/ -PALIMPORT -VOID -PALAPI -PAL_CleanupDacTableAddress( - IN PVOID baseAddress) -{ - char fileName[100]; - snprintf(fileName, sizeof(fileName), "/tmp/%p_dacTable", baseAddress); - remove(fileName); -} diff --git a/src/pal/tools/gen-dactable-rva.sh b/src/pal/tools/gen-dactable-rva.sh new file mode 100644 index 000000000000..dd200068e5f3 --- /dev/null +++ b/src/pal/tools/gen-dactable-rva.sh @@ -0,0 +1 @@ +nm $1 | grep g_dacTable | cut -f 1 -d' ' | head -n 1 | awk '{ print "#define DAC_TABLE_RVA 0x" $1}' > $2