Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic natvis visualizations for some VM types #52853

Merged
merged 6 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of PRIVATE?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PRIVATE makes sure to keep the natvis linked only to the jit dlls and not to dlls that link to the jit dlls in the CMake build. See here in the CMake docs: https://cmake.org/cmake/help/latest/command/target_link_libraries.html#id3

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>
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
<Expand>
<ExpandedItem>m_value</ExpandedItem>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need ExpandedItem for this? May be a screenshot will help. You can also consider adding StringView for better copy paste experience.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since HolderBase doesn't usually hold a string, I think StringView would be the wrong element to add here. I think DisplayString handles that case. I'll change it to m_value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok..And then what is the purpose of ExpandedItem? Isn't DisplayString sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpandedItem basically removes a level of indirection in the expanded tree when looking in the locals/auto/watch view, so when the holder object is expanded, we get directly to the held value.

</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()