natvis in vscode with gdb gives "Explicit refresh required for visualized expressions"

1.2k Views Asked by At

vscode is meant to be able to pretty print custom objects if given a natvis file. I'm running linux and debugging with gdb.

The docs say:

For gdb/lldb debugging ("type": "cppdbg"), a subset of the Natvis framework has been ported to the Visual Studio Code C/C++ extension and the code resides in the MIEngine shared component. If additional features that are not implemented are requested, please file an issue on the MIEngine GitHub page with details of what is missing.

I've created a simple natvis file based on the natvis page here:

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <Type Name="MyArray">
    <DisplayString>{{size={size}}}</DisplayString>
    <Expand>
        <Item Name="[size]">size</Item>
        <ArrayItems>
            <Size>size</Size>
            <ValuePointer>ptr</ValuePointer>
        </ArrayItems>
    </Expand>
  </Type>
</AutoVisualizer>

I've included a reference to this file in my launch.json:

"visualizerFile": "${workspaceFolder}/file.natvis",

After launching the debugger and hovering over a variable I see "Explicit refresh required for visualized expressions". This was promising because it shows vscode has found the file, but it still isn't able to apply it for some reason. There are no natvis logs/errors in any of the vscode OUTPUT/DEBUG CONSOLE tabs.

enter image description here

Is there something I'm missing? How can I get vscode+gdb to use my .natvis file?

1

There are 1 best solutions below

1
jozxyqk On

The solution for me came from here:

can you make sure you have the property "showDisplayString": true set in your launch.json?

Adding the following line in addition to visualizerFile suddenly made the .natvis definitions work.

"visualizerFile": "${workspaceFolder}/file.natvis",
"showDisplayString": true, // <-- add this

FYI, I also noticed that vscode passes --interpreter=mi to gdb, so there is some explicit gdb support for interacting with the MIEngine referenced by the docs.