microsoft / MIEngine

The Visual Studio MI Debug Engine ("MIEngine") provides an open-source Visual Studio Debugger extension that works with MI-enabled debuggers such as gdb and lldb.
MIT License
818 stars 218 forks source link

TreeItems' LeftPointer and RightPointer are not evaluated #1426

Open ahfakt opened 1 year ago

ahfakt commented 1 year ago

Based on this issue I assume VSCode C/C++ extension uses this implementation. I tried to define a simple TreeItems. When debugging on Linux with GDB, even though natvis.xsd says so, LeftPointer and RightPointer is not evaluated. And I think the problem is the implementation of the GetTraverse function. It's also used by LinkedListItems's NextPointer, I haven't tried it but it may affect that too.

Example C++ code

template <typename T>
struct Tree {
    struct Node {
        Node* left = nullptr;
        Node* right = nullptr;
        T val;
    } n1, n2, n3;
    Node* head;
    int size = 3;
};

int main()
{

    Tree<int> tree;
    tree.n1.val = 11;
    tree.n2.val = 22;
    tree.n3.val = 33;
    tree.head = &tree.n2;
    tree.n2.left = &tree.n1;
    tree.n2.right = &tree.n3;

    return 0;
}

.natvis definition

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
    <Type Name="Tree&lt;*&gt;">
        <DisplayString>{size}</DisplayString>
        <Expand HideRawView="1">
            <TreeItems>
                <!-- "size+0" OK-->
                <Size>size</Size>

                <!-- "head+0" OK-->
                <HeadPointer>head</HeadPointer>

                <!-- "left+0" ERR-->
                <LeftPointer>left</LeftPointer>

                <!-- "right+0" ERR-->
                <RightPointer>right</RightPointer>

                <!-- "*($T1*)(&amp;val+0)" OK-->
                <ValueNode>val</ValueNode>
            </TreeItems>
        </Expand>
    </Type>
</AutoVisualizer>

and related launch configuration

    "launch": {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch",
                "type": "cppdbg",
                "MIMode": "gdb",
                "request": "launch",
                "cwd": "${command:cmake.launchTargetDirectory}",
                "program": "${command:cmake.launchTargetPath}",
                "args": [],
                "externalConsole": false,
                "stopAtEntry": true,
                "visualizerFile": [
                    "${workspaceFolder}/.natvis"
                ],
                "showDisplayString": true
            }
        ]
    }