[PATCH] D18261: Show members of DeclContexts (i.e., class members) in Visual Studio native visualizers

Mike Spertus via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 17 18:59:02 PDT 2016


mspertus created this revision.
mspertus added reviewers: aaron.ballman, zturner.
mspertus added a subscriber: cfe-commits.

This change shows members of `DeclContext` objects in the Visual Studio debugger. It will also cast a `TagType` like a class or a struct to a `DeclContext`, so its methods and fields are visualized. For example, suppose we have a class

```
struct A {
  int foo();
};
```

With this change, the `CXXRecordDecl *` representing `A` will be displayed in the Visual Studio debugger as

```
D                 0x0067ab48 struct A
|- DeclKind       CXXRecord
|- [0]            struct A
|- [1]            Method {foo}
|- [Raw View]     //Remaining fields//
```

http://reviews.llvm.org/D18261

Files:
  clang.natvis

Index: clang.natvis
===================================================================
--- clang.natvis
+++ clang.natvis
@@ -73,6 +73,31 @@
   <Type Name="clang::AttributedType">
     <DisplayString>{ModifiedType} Attribute={(clang::AttributedType::Kind)AttributedTypeBits.AttrKind}</DisplayString>
   </Type>
+  
+  <!-- Unfortunately, Visual Studio has trouble seeing the PointerBitMask member PointerIntUnion, so I hardwire it to 2 bits-->
+  <Type Name="clang::DeclContext">
+    <DisplayString>{(clang::Decl::Kind)DeclKind,en}Decl</DisplayString>
+    <Expand>
+      <Item Name="DeclKind">(clang::Decl::Kind)DeclKind,en</Item>
+      <LinkedListItems>
+        <HeadPointer>FirstDecl</HeadPointer>
+        <NextPointer>(clang::Decl *)(NextInContextAndBits.Value & ~3)</NextPointer>
+        <ValueNode>*this</ValueNode>
+      </LinkedListItems>
+    </Expand>
+  </Type>
+  <Type Name="clang::FieldDecl">
+    <DisplayString>Field {{{*(clang::NamedDecl *)this,view(cpp)nd}}}</DisplayString>
+  </Type>
+  <Type Name="clang::CXXMethodDecl">
+    <DisplayString>Method {{{*(clang::NamedDecl *)this,view(cpp)nd}}}</DisplayString>
+  </Type>
+  <Type Name="clang::CXXConstructorDecl">
+    <DisplayString>Constructor {{{*(clang::NamedDecl *)this,view(cpp)nd}}}</DisplayString>
+  </Type>
+  <Type Name="clang::CXXDestructorDecl">
+    <DisplayString>Destructor {{{*(clang::NamedDecl *)this,view(cpp)nd}}}</DisplayString>
+  </Type>
   <Type Name="clang::NamedDecl" >
     <DisplayString IncludeView="cpp">{Name,view(cpp)}</DisplayString>
     <DisplayString>{Name}</DisplayString>
@@ -83,6 +108,9 @@
     <DisplayString Condition="TagDeclKind==clang::TagTypeKind::TTK_Union">union {Name,view(cpp)}</DisplayString>
     <DisplayString Condition="TagDeclKind==clang::TagTypeKind::TTK_Class">class {Name,view(cpp)}</DisplayString>
     <DisplayString Condition="TagDeclKind==clang::TagTypeKind::TTK_Enum">enum {Name,view(cpp)}</DisplayString>
+    <Expand>
+      <ExpandedItem>(clang::DeclContext *)this</ExpandedItem>
+    </Expand>
   </Type>
   <Type Name="clang::TagType">
     <DisplayString>{*decl}</DisplayString>
@@ -97,7 +125,6 @@
       <Item Name="TagType">*(clang::TagType *)this</Item>
     </Expand>
   </Type>
-
   <Type Name="clang::SubstTemplateTypeParmType">
     <DisplayString>{*Replaced,view(cpp)} <= {CanonicalType,view(cpp)}</DisplayString>
     <Expand>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18261.51009.patch
Type: text/x-patch
Size: 2388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160318/ed426535/attachment.bin>


More information about the cfe-commits mailing list