Athena
Athena

Reputation: 213

How to clarify namespaces in .natvis visualiser?

I am trying to write a custom visualizer for a kind of loader/smart pointer that internally stores the data as a void* and casts it to the correct (templated) type. But the visualizer is getting confused regarding namespaces/types when casting it in the visualizer, and I'm not sure how to resolve it.

The relevant classes are defined as follows:

namespace Resource
{
    class ResourceBase
    {
        std::string filename;
        void* data;
    };

    template<typename Data>
    class Resource : public ResourceBase
    {
        const Data* GetData() const { return (const Data*)this->data; }
    };

    template<typename Data>
    class Loader
    {
        Resource<Data>* resource;
    };
}

namespace Foo
{
   class Bar;
}

Resource::Loader<Foo::Bar> foobar;

But when I try to inspect foobar in the debugger, it fails and in the Output window I see this natvis error: "Error: identifier "Resource::Foo" is undefined".

My simple natvis file is like so:

<?xml version="1.0" encoding="utf-8"?> 
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <Type Name="Resource::Loader&lt;*&gt;">
    <DisplayString Condition="resource==0">null</DisplayString>
    <DisplayString Condition="resource!=0">{resource->filename}</DisplayString>
    <Expand>
      <ExpandedItem Condition="resource!=0&amp;&amp;resource->data!=0">*($T1*)resource->data</ExpandedItem>
    </Expand>
  </Type>
</AutoVisualizer>

I tried adding a :: (global namespace) before the $T1 and it changed the error to "Error: name followed by '::' must be a class or namespace name", but not sure if that helps.

Any help or suggestions appreciated. This is not something that can fixed through refactoring the actual code.

A more fleshed out example here: https://godbolt.org/z/zv5dP345n

Upvotes: 0

Views: 403

Answers (0)

Related Questions