Skip to content

Commit

Permalink
Add basic natvis visualizations for some VM types (#52853)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky authored May 19, 2021
1 parent aad916c commit d49bcbe
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 27 deletions.
54 changes: 36 additions & 18 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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()
13 changes: 4 additions & 9 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,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)
Expand Down Expand Up @@ -471,6 +462,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()
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/utilcode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions src/coreclr/utilcode/utilcode.natvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Licensed to the .NET Foundation under one or more agreements.
The .NET Foundation licenses this file to you under the MIT license.
-->


<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="SString">
<DisplayString Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_EMPTY">[Empty]</DisplayString>
<DisplayString Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_UNICODE">[Unicode] {m_buffer,su}</DisplayString>
<DisplayString Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_ASCII">[ASCII] {m_buffer,s}</DisplayString>
<DisplayString Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_UTF8">[UTF8] {m_buffer,s8}</DisplayString>
<DisplayString Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_ANSI">[ANSI] {m_buffer,s}</DisplayString>
<StringView Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_UNICODE">m_buffer,su</StringView>
<StringView Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_ASCII">m_buffer,s</StringView>
<StringView Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_UTF8">m_buffer,s8</StringView>
<StringView Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_ANSI">m_buffer,s</StringView>
</Type>
</AutoVisualizer>
16 changes: 16 additions & 0 deletions src/coreclr/vm/vm.natvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Licensed to the .NET Foundation under one or more agreements.
The .NET Foundation licenses this file to you under the MIT license.
-->


<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="HolderBase&lt;*&gt;">
<DisplayString>{m_value}</DisplayString>
<Expand>
<ExpandedItem>m_value</ExpandedItem>
</Expand>
</Type>
</AutoVisualizer>
5 changes: 5 additions & 0 deletions src/coreclr/vm/wks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ add_library(cee_wks INTERFACE)
target_sources(cee_wks INTERFACE $<TARGET_OBJECTS:cee_wks_obj> $<TARGET_OBJECTS:cee_wks_core> ${VM_WKS_ARCH_ASM_OBJECTS})
add_library(cee_wks_mergeable INTERFACE)
target_sources(cee_wks_mergeable INTERFACE $<TARGET_OBJECTS:cee_wks_mergeable_obj> $<TARGET_OBJECTS:cee_wks_core> ${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()

0 comments on commit d49bcbe

Please sign in to comment.