[PATCH] D19339: Add natvis visualizers for endian packed types

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 21 11:47:37 PDT 2016


zturner updated this revision to Diff 54554.
zturner added a comment.

Apparently you can line break inside of the `<DisplayString>` tag without messing anything up, so this should be easier to read.


http://reviews.llvm.org/D19339

Files:
  utils/LLVMVisualizers/llvm.natvis

Index: utils/LLVMVisualizers/llvm.natvis
===================================================================
--- utils/LLVMVisualizers/llvm.natvis
+++ utils/LLVMVisualizers/llvm.natvis
@@ -168,4 +168,45 @@
       <Item Name="[underlying]" Condition="hasVal">*(($T1 *)(unsigned char *)storage.buffer)</Item>
     </Expand>
   </Type>
+
+  <!-- Since we're in MSVC, we can assume that the system is little endian.  Therefore
+       the little and native cases just require a cast.  Handle this easy case first. Use
+       a wildcard for the second template argument (the endianness), but we will use a
+       specific value of 0 later on for the big endian to give it priority for being a
+       better match.  -->
+  <Type Name="llvm::support::detail::packed_endian_specific_integral<*,*,1>">
+    <DisplayString>{{little endian value = {*(($T1*)(unsigned char *)Value.buffer)} }}</DisplayString>
+    <Expand>
+      <Item Name="[Raw Bytes]" Condition="sizeof($T1)==1">(unsigned char *)Value.buffer,1</Item>
+      <Item Name="[Raw Bytes]" Condition="sizeof($T1)==2">(unsigned char *)Value.buffer,2</Item>
+      <Item Name="[Raw Bytes]" Condition="sizeof($T1)==4">(unsigned char *)Value.buffer,4</Item>
+      <Item Name="[Raw Bytes]" Condition="sizeof($T1)==8">(unsigned char *)Value.buffer,8</Item>
+    </Expand>
+  </Type>
+  
+  <!-- Now handle the hard case of big endian.  We need to do the swizzling here, but
+       we need to specialize it based on the size of the value type. -->
+  <Type Name="llvm::support::detail::packed_endian_specific_integral<*,0,1>">
+    <DisplayString Condition="sizeof($T1)==1">{{ big endian value = {*(unsigned char *)Value.buffer} }}</DisplayString>
+    <DisplayString Condition="sizeof($T1)==2">{{ big endian value = {(($T1)(*(unsigned char *)Value.buffer) << 8) 
+                                                                    | ($T1)(*((unsigned char *)Value.buffer+1))} }}</DisplayString>
+    <DisplayString Condition="sizeof($T1)==4">{{ big endian value = {(($T1)(*(unsigned char *)Value.buffer) << 24) 
+                                                                    | (($T1)(*((unsigned char *)Value.buffer+1)) << 16) 
+                                                                    | (($T1)(*((unsigned char *)Value.buffer+2)) << 8) 
+                                                                    |  ($T1)(*((unsigned char *)Value.buffer+3))} }}</DisplayString>
+    <DisplayString Condition="sizeof($T1)==8">{{ big endian value = {(($T1)(*(unsigned char *)Value.buffer) << 56) 
+                                                                    | (($T1)(*((unsigned char *)Value.buffer+1)) << 48) 
+                                                                    | (($T1)(*((unsigned char *)Value.buffer+2)) << 40) 
+                                                                    | (($T1)(*((unsigned char *)Value.buffer+3)) << 32) 
+                                                                    | (($T1)(*((unsigned char *)Value.buffer+4)) << 24) 
+                                                                    | (($T1)(*((unsigned char *)Value.buffer+5)) << 16) 
+                                                                    | (($T1)(*((unsigned char *)Value.buffer+6)) << 8) 
+                                                                    |  ($T1)(*((unsigned char *)Value.buffer+7))} }}</DisplayString>
+    <Expand>
+      <Item Name="[Raw Bytes]" Condition="sizeof($T1)==1">(unsigned char *)Value.buffer,1</Item>
+      <Item Name="[Raw Bytes]" Condition="sizeof($T1)==2">(unsigned char *)Value.buffer,2</Item>
+      <Item Name="[Raw Bytes]" Condition="sizeof($T1)==4">(unsigned char *)Value.buffer,4</Item>
+      <Item Name="[Raw Bytes]" Condition="sizeof($T1)==8">(unsigned char *)Value.buffer,8</Item>
+    </Expand>
+  </Type>
 </AutoVisualizer>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19339.54554.patch
Type: text/x-patch
Size: 3996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160421/b55a4ba5/attachment.bin>


More information about the llvm-commits mailing list