From 6b8aece23942c602ac7789ca824e94a650b018f8 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 14 May 2021 17:05:37 -0700 Subject: [PATCH 1/5] Add function to link natvis files and stub out a natvis file for the vm. --- eng/native/functions.cmake | 54 ++++++++++++++++++++----------- src/coreclr/jit/CMakeLists.txt | 13 +++----- src/coreclr/vm/vm.natvis | 11 +++++++ src/coreclr/vm/wks/CMakeLists.txt | 5 +++ 4 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 src/coreclr/vm/vm.natvis diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index f5b4a44619130..1ca230c3e534d 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -467,7 +467,38 @@ if (CMAKE_VERSION VERSION_LESS "3.16") endfunction() endif() -function(add_executable_clr) +# add_linker_flag(Flag [Config1 Config2 ...]) +function(add_linker_flag Flag) + if (ARGN STREQUAL "") + set("CMAKE_EXE_LINKER_FLAGS" "${CMAKE_EXE_LINKER_FLAGS} ${Flag}" PARENT_SCOPE) + set("CMAKE_SHARED_LINKER_FLAGS" "${CMAKE_SHARED_LINKER_FLAGS} ${Flag}" PARENT_SCOPE) + else() + foreach(Config ${ARGN}) + set("CMAKE_EXE_LINKER_FLAGS_${Config}" "${CMAKE_EXE_LINKER_FLAGS_${Config}} ${Flag}" PARENT_SCOPE) + set("CMAKE_SHARED_LINKER_FLAGS_${Config}" "${CMAKE_SHARED_LINKER_FLAGS_${Config}} ${Flag}" PARENT_SCOPE) + endforeach() + endif() +endfunction() + +function(link_natvis_sources_for_target targetName linkKind) + if (NOT CLR_CMAKE_HOST_WIN32) + return() + endif() + foreach(source ${ARGN}) + if (NOT IS_ABSOLUTE "${source}") + convert_to_absolute_path(source ${source}) + endif() + get_filename_component(extension "${source}" EXT) + if ("${extension}" STREQUAL ".natvis") + message("Embedding natvis ${source}") + # Since natvis embedding is only supported on Windows + # we can use target_link_options since our minimum version is high enough + target_link_options(${targetName} "${linkKind}" "-NATVIS:${source}") + endif() + endforeach() +endfunction() + +function(add_executable_clr targetName) if(NOT WIN32) add_executable(${ARGV} ${VERSION_FILE_PATH}) disable_pax_mprotect(${ARGV}) @@ -479,26 +510,13 @@ function(add_executable_clr) endif() endfunction() -function(add_library_clr) - if(NOT WIN32 AND "${ARGV1}" STREQUAL "SHARED") +function(add_library_clr targetName kind) + if(NOT WIN32 AND "${kind}" STREQUAL "SHARED") add_library(${ARGV} ${VERSION_FILE_PATH}) else() add_library(${ARGV}) - endif(NOT WIN32 AND "${ARGV1}" STREQUAL "SHARED") - if("${ARGV1}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) + endif() + if("${kind}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) strip_symbols(${ARGV0} symbolFile) endif() endfunction() - -# add_linker_flag(Flag [Config1 Config2 ...]) -function(add_linker_flag Flag) - if (ARGN STREQUAL "") - set("CMAKE_EXE_LINKER_FLAGS" "${CMAKE_EXE_LINKER_FLAGS} ${Flag}" PARENT_SCOPE) - set("CMAKE_SHARED_LINKER_FLAGS" "${CMAKE_SHARED_LINKER_FLAGS} ${Flag}" PARENT_SCOPE) - else() - foreach(Config ${ARGN}) - set("CMAKE_EXE_LINKER_FLAGS_${Config}" "${CMAKE_EXE_LINKER_FLAGS_${Config}} ${Flag}" PARENT_SCOPE) - set("CMAKE_SHARED_LINKER_FLAGS_${Config}" "${CMAKE_SHARED_LINKER_FLAGS_${Config}} ${Flag}" PARENT_SCOPE) - endforeach() - endif() -endfunction() diff --git a/src/coreclr/jit/CMakeLists.txt b/src/coreclr/jit/CMakeLists.txt index 1d8e8645f5046..680ed8b0f18f2 100644 --- a/src/coreclr/jit/CMakeLists.txt +++ b/src/coreclr/jit/CMakeLists.txt @@ -366,15 +366,6 @@ convert_to_absolute_path(JIT_ARM_SOURCES ${JIT_ARM_SOURCES}) convert_to_absolute_path(JIT_I386_SOURCES ${JIT_I386_SOURCES}) convert_to_absolute_path(JIT_ARM64_SOURCES ${JIT_ARM64_SOURCES}) -# Include natvis file for Windows -if (CLR_CMAKE_HOST_WIN32) - set(JIT_NATVIS_SOURCE - clrjit.natvis - ) - convert_to_absolute_path(JIT_NATVIS_SOURCE ${JIT_NATVIS_SOURCE}) - add_linker_flag("/NATVIS:${JIT_NATVIS_SOURCE}") -endif(CLR_CMAKE_HOST_WIN32) - set(JIT_DLL_MAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/dllmain.cpp) if(CLR_CMAKE_TARGET_WIN32) @@ -465,6 +456,10 @@ function(add_jit jitName) ${JIT_ARCH_LINK_LIBRARIES} ) + if (CLR_CMAKE_HOST_WIN32) + link_natvis_sources_for_target(${jitName} PRIVATE clrjit.natvis) + endif() + # add the install targets install_clr(TARGETS ${jitName} ${ARGN} COMPONENT alljits) endfunction() diff --git a/src/coreclr/vm/vm.natvis b/src/coreclr/vm/vm.natvis new file mode 100644 index 0000000000000..106d181cef605 --- /dev/null +++ b/src/coreclr/vm/vm.natvis @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/src/coreclr/vm/wks/CMakeLists.txt b/src/coreclr/vm/wks/CMakeLists.txt index 626037f0b34f3..cb7ba8ca2cc99 100644 --- a/src/coreclr/vm/wks/CMakeLists.txt +++ b/src/coreclr/vm/wks/CMakeLists.txt @@ -76,3 +76,8 @@ add_library(cee_wks INTERFACE) target_sources(cee_wks INTERFACE $ $ ${VM_WKS_ARCH_ASM_OBJECTS}) add_library(cee_wks_mergeable INTERFACE) target_sources(cee_wks_mergeable INTERFACE $ $ ${VM_WKS_ARCH_ASM_OBJECTS}) + +if (CLR_CMAKE_HOST_WIN32) + link_natvis_sources_for_target(cee_wks INTERFACE ../vm.natvis) + link_natvis_sources_for_target(cee_wks_mergeable INTERFACE ../vm.natvis) +endif() From cdeedfa1a5460c774b9d4782d4ef7ae8b703e8e8 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 14 May 2021 17:20:35 -0700 Subject: [PATCH 2/5] Add SString view. --- src/coreclr/utilcode/CMakeLists.txt | 5 +++++ src/coreclr/utilcode/utilcode.natvis | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/coreclr/utilcode/utilcode.natvis diff --git a/src/coreclr/utilcode/CMakeLists.txt b/src/coreclr/utilcode/CMakeLists.txt index af1187a59b2aa..fec22cf9dce38 100644 --- a/src/coreclr/utilcode/CMakeLists.txt +++ b/src/coreclr/utilcode/CMakeLists.txt @@ -112,6 +112,11 @@ endif(CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_HOST_WIN32) target_compile_definitions(utilcodestaticnohost PRIVATE _CRTIMP=) # use static version of crt + + link_natvis_sources_for_target(utilcodestaticnohost INTERFACE utilcode.natvis) + link_natvis_sources_for_target(utilcode_crossgen INTERFACE utilcode.natvis) + link_natvis_sources_for_target(utilcode_dac INTERFACE utilcode.natvis) + link_natvis_sources_for_target(utilcode INTERFACE utilcode.natvis) endif(CLR_CMAKE_HOST_WIN32) set_target_properties(utilcode_dac PROPERTIES DAC_COMPONENT TRUE) diff --git a/src/coreclr/utilcode/utilcode.natvis b/src/coreclr/utilcode/utilcode.natvis new file mode 100644 index 0000000000000..54f0a90a1bcc6 --- /dev/null +++ b/src/coreclr/utilcode/utilcode.natvis @@ -0,0 +1,17 @@ + + + + + + + + [Empty] + [Unicode] {m_buffer,su} + [ASCII] {m_buffer,s} + [UTF8] {m_buffer,s8} + [ANSI] {m_buffer,s} + + From 753415014a2d9c557abbebeb579d2c728147794d Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 17 May 2021 10:43:27 -0700 Subject: [PATCH 3/5] Implement natvis for SString type --- src/coreclr/utilcode/utilcode.natvis | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreclr/utilcode/utilcode.natvis b/src/coreclr/utilcode/utilcode.natvis index 54f0a90a1bcc6..7756270b164cd 100644 --- a/src/coreclr/utilcode/utilcode.natvis +++ b/src/coreclr/utilcode/utilcode.natvis @@ -13,5 +13,9 @@ The .NET Foundation licenses this file to you under the MIT license. [ASCII] {m_buffer,s} [UTF8] {m_buffer,s8} [ANSI] {m_buffer,s} + m_buffer,su + m_buffer,s + m_buffer,s8 + m_buffer,s From a248c45d643a0393bc361ed71b5680991852e2bd Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 17 May 2021 10:53:59 -0700 Subject: [PATCH 4/5] Add natvis visualization for the CoreCLR holder types. --- src/coreclr/vm/vm.natvis | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/vm.natvis b/src/coreclr/vm/vm.natvis index 106d181cef605..a044270d8b2f8 100644 --- a/src/coreclr/vm/vm.natvis +++ b/src/coreclr/vm/vm.natvis @@ -7,5 +7,10 @@ The .NET Foundation licenses this file to you under the MIT license. - + + {*m_value} + + m_value + + From 8a0ceb30fdf253b783e06c71ac50947007c77f85 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 17 May 2021 11:48:56 -0700 Subject: [PATCH 5/5] Update src/coreclr/vm/vm.natvis --- src/coreclr/vm/vm.natvis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/vm.natvis b/src/coreclr/vm/vm.natvis index a044270d8b2f8..f7bdbb1c30ca0 100644 --- a/src/coreclr/vm/vm.natvis +++ b/src/coreclr/vm/vm.natvis @@ -8,7 +8,7 @@ The .NET Foundation licenses this file to you under the MIT license. - {*m_value} + {m_value} m_value