Skip to content

Commit d49bcbe

Browse files
authored
Add basic natvis visualizations for some VM types (#52853)
1 parent aad916c commit d49bcbe

File tree

6 files changed

+87
-27
lines changed

6 files changed

+87
-27
lines changed

eng/native/functions.cmake

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,38 @@ if (CMAKE_VERSION VERSION_LESS "3.16")
467467
endfunction()
468468
endif()
469469

470-
function(add_executable_clr)
470+
# add_linker_flag(Flag [Config1 Config2 ...])
471+
function(add_linker_flag Flag)
472+
if (ARGN STREQUAL "")
473+
set("CMAKE_EXE_LINKER_FLAGS" "${CMAKE_EXE_LINKER_FLAGS} ${Flag}" PARENT_SCOPE)
474+
set("CMAKE_SHARED_LINKER_FLAGS" "${CMAKE_SHARED_LINKER_FLAGS} ${Flag}" PARENT_SCOPE)
475+
else()
476+
foreach(Config ${ARGN})
477+
set("CMAKE_EXE_LINKER_FLAGS_${Config}" "${CMAKE_EXE_LINKER_FLAGS_${Config}} ${Flag}" PARENT_SCOPE)
478+
set("CMAKE_SHARED_LINKER_FLAGS_${Config}" "${CMAKE_SHARED_LINKER_FLAGS_${Config}} ${Flag}" PARENT_SCOPE)
479+
endforeach()
480+
endif()
481+
endfunction()
482+
483+
function(link_natvis_sources_for_target targetName linkKind)
484+
if (NOT CLR_CMAKE_HOST_WIN32)
485+
return()
486+
endif()
487+
foreach(source ${ARGN})
488+
if (NOT IS_ABSOLUTE "${source}")
489+
convert_to_absolute_path(source ${source})
490+
endif()
491+
get_filename_component(extension "${source}" EXT)
492+
if ("${extension}" STREQUAL ".natvis")
493+
message("Embedding natvis ${source}")
494+
# Since natvis embedding is only supported on Windows
495+
# we can use target_link_options since our minimum version is high enough
496+
target_link_options(${targetName} "${linkKind}" "-NATVIS:${source}")
497+
endif()
498+
endforeach()
499+
endfunction()
500+
501+
function(add_executable_clr targetName)
471502
if(NOT WIN32)
472503
add_executable(${ARGV} ${VERSION_FILE_PATH})
473504
disable_pax_mprotect(${ARGV})
@@ -479,26 +510,13 @@ function(add_executable_clr)
479510
endif()
480511
endfunction()
481512

482-
function(add_library_clr)
483-
if(NOT WIN32 AND "${ARGV1}" STREQUAL "SHARED")
513+
function(add_library_clr targetName kind)
514+
if(NOT WIN32 AND "${kind}" STREQUAL "SHARED")
484515
add_library(${ARGV} ${VERSION_FILE_PATH})
485516
else()
486517
add_library(${ARGV})
487-
endif(NOT WIN32 AND "${ARGV1}" STREQUAL "SHARED")
488-
if("${ARGV1}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
518+
endif()
519+
if("${kind}" STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
489520
strip_symbols(${ARGV0} symbolFile)
490521
endif()
491522
endfunction()
492-
493-
# add_linker_flag(Flag [Config1 Config2 ...])
494-
function(add_linker_flag Flag)
495-
if (ARGN STREQUAL "")
496-
set("CMAKE_EXE_LINKER_FLAGS" "${CMAKE_EXE_LINKER_FLAGS} ${Flag}" PARENT_SCOPE)
497-
set("CMAKE_SHARED_LINKER_FLAGS" "${CMAKE_SHARED_LINKER_FLAGS} ${Flag}" PARENT_SCOPE)
498-
else()
499-
foreach(Config ${ARGN})
500-
set("CMAKE_EXE_LINKER_FLAGS_${Config}" "${CMAKE_EXE_LINKER_FLAGS_${Config}} ${Flag}" PARENT_SCOPE)
501-
set("CMAKE_SHARED_LINKER_FLAGS_${Config}" "${CMAKE_SHARED_LINKER_FLAGS_${Config}} ${Flag}" PARENT_SCOPE)
502-
endforeach()
503-
endif()
504-
endfunction()

src/coreclr/jit/CMakeLists.txt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,6 @@ convert_to_absolute_path(JIT_ARM_SOURCES ${JIT_ARM_SOURCES})
372372
convert_to_absolute_path(JIT_I386_SOURCES ${JIT_I386_SOURCES})
373373
convert_to_absolute_path(JIT_ARM64_SOURCES ${JIT_ARM64_SOURCES})
374374

375-
# Include natvis file for Windows
376-
if (CLR_CMAKE_HOST_WIN32)
377-
set(JIT_NATVIS_SOURCE
378-
clrjit.natvis
379-
)
380-
convert_to_absolute_path(JIT_NATVIS_SOURCE ${JIT_NATVIS_SOURCE})
381-
add_linker_flag("/NATVIS:${JIT_NATVIS_SOURCE}")
382-
endif(CLR_CMAKE_HOST_WIN32)
383-
384375
set(JIT_DLL_MAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/dllmain.cpp)
385376

386377
if(CLR_CMAKE_TARGET_WIN32)
@@ -471,6 +462,10 @@ function(add_jit jitName)
471462
${JIT_ARCH_LINK_LIBRARIES}
472463
)
473464

465+
if (CLR_CMAKE_HOST_WIN32)
466+
link_natvis_sources_for_target(${jitName} PRIVATE clrjit.natvis)
467+
endif()
468+
474469
# add the install targets
475470
install_clr(TARGETS ${jitName} ${ARGN} COMPONENT alljits)
476471
endfunction()

src/coreclr/utilcode/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ endif(CLR_CMAKE_HOST_UNIX)
112112

113113
if(CLR_CMAKE_HOST_WIN32)
114114
target_compile_definitions(utilcodestaticnohost PRIVATE _CRTIMP=) # use static version of crt
115+
116+
link_natvis_sources_for_target(utilcodestaticnohost INTERFACE utilcode.natvis)
117+
link_natvis_sources_for_target(utilcode_crossgen INTERFACE utilcode.natvis)
118+
link_natvis_sources_for_target(utilcode_dac INTERFACE utilcode.natvis)
119+
link_natvis_sources_for_target(utilcode INTERFACE utilcode.natvis)
115120
endif(CLR_CMAKE_HOST_WIN32)
116121

117122
set_target_properties(utilcode_dac PROPERTIES DAC_COMPONENT TRUE)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!--
4+
Licensed to the .NET Foundation under one or more agreements.
5+
The .NET Foundation licenses this file to you under the MIT license.
6+
-->
7+
8+
9+
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
10+
<Type Name="SString">
11+
<DisplayString Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_EMPTY">[Empty]</DisplayString>
12+
<DisplayString Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_UNICODE">[Unicode] {m_buffer,su}</DisplayString>
13+
<DisplayString Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_ASCII">[ASCII] {m_buffer,s}</DisplayString>
14+
<DisplayString Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_UTF8">[UTF8] {m_buffer,s8}</DisplayString>
15+
<DisplayString Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_ANSI">[ANSI] {m_buffer,s}</DisplayString>
16+
<StringView Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_UNICODE">m_buffer,su</StringView>
17+
<StringView Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_ASCII">m_buffer,s</StringView>
18+
<StringView Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_UTF8">m_buffer,s8</StringView>
19+
<StringView Condition="(m_flags &amp; REPRESENTATION_MASK) == REPRESENTATION_ANSI">m_buffer,s</StringView>
20+
</Type>
21+
</AutoVisualizer>

src/coreclr/vm/vm.natvis

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!--
4+
Licensed to the .NET Foundation under one or more agreements.
5+
The .NET Foundation licenses this file to you under the MIT license.
6+
-->
7+
8+
9+
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
10+
<Type Name="HolderBase&lt;*&gt;">
11+
<DisplayString>{m_value}</DisplayString>
12+
<Expand>
13+
<ExpandedItem>m_value</ExpandedItem>
14+
</Expand>
15+
</Type>
16+
</AutoVisualizer>

src/coreclr/vm/wks/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,8 @@ add_library(cee_wks INTERFACE)
7676
target_sources(cee_wks INTERFACE $<TARGET_OBJECTS:cee_wks_obj> $<TARGET_OBJECTS:cee_wks_core> ${VM_WKS_ARCH_ASM_OBJECTS})
7777
add_library(cee_wks_mergeable INTERFACE)
7878
target_sources(cee_wks_mergeable INTERFACE $<TARGET_OBJECTS:cee_wks_mergeable_obj> $<TARGET_OBJECTS:cee_wks_core> ${VM_WKS_ARCH_ASM_OBJECTS})
79+
80+
if (CLR_CMAKE_HOST_WIN32)
81+
link_natvis_sources_for_target(cee_wks INTERFACE ../vm.natvis)
82+
link_natvis_sources_for_target(cee_wks_mergeable INTERFACE ../vm.natvis)
83+
endif()

0 commit comments

Comments
 (0)