Add basic natvis visualizations for some VM types (#52853)
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Wed, 19 May 2021 23:43:37 +0000 (16:43 -0700)
committerGitHub <noreply@github.com>
Wed, 19 May 2021 23:43:37 +0000 (16:43 -0700)
eng/native/functions.cmake
src/coreclr/jit/CMakeLists.txt
src/coreclr/utilcode/CMakeLists.txt
src/coreclr/utilcode/utilcode.natvis [new file with mode: 0644]
src/coreclr/vm/vm.natvis [new file with mode: 0644]
src/coreclr/vm/wks/CMakeLists.txt

index f5b4a44619130ed7257b2d18cc1daf4a433288f9..1ca230c3e534d76681154f869c34ac8d1836b338 100644 (file)
@@ -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()
index 53cfd5e096e0fe285ade70230d15c17947237459..586598cc7ae05e51ab6f040385e849f4f7eddf6a 100644 (file)
@@ -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)
@@ -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()
index af1187a59b2aad4ed833ba01e6745c5586028bcb..fec22cf9dce38a3697887e8fe5da95fba097b73c 100644 (file)
@@ -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 (file)
index 0000000..7756270
--- /dev/null
@@ -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>
diff --git a/src/coreclr/vm/vm.natvis b/src/coreclr/vm/vm.natvis
new file mode 100644 (file)
index 0000000..f7bdbb1
--- /dev/null
@@ -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>
index 626037f0b34f39a488b7f6898a918149e82d75e0..cb7ba8ca2cc997a8d3ca4d6723661d666ec342d4 100644 (file)
@@ -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()