microsoft / microsoft/vscode-cpptools

Natvis: Size specifier for array-like structures is not working

Open
#11,995 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

debugger help wanted
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Environment
  • OS and version: Linux
  • VS Code: 1.85.2
  • C/C++ extension: 1.18.5
  • OS and version of remote machine (if applicable): RHEL 7.6
  • GDB / LLDB version: 10.2
Bug Summary and Steps to Reproduce

Bug Summary:

In my natvis file, I am trying to create a visualizer for GCC's std::string_view, and I am using a method similar to how MSVC displays their std::string_view. It looks like so:

<Type Name="std::string_view">
    <AlternativeType Name="std::basic_string_view&lt;*,*&gt;" />
    <DisplayString>{_M_str,[_M_len]na}</DisplayString>
    <StringView>_M_str,[_M_len]na</StringView>
    <Expand>
        <Item Name="[size]" ExcludeView="simple">_M_len</Item>
        <ArrayItems ExcludeView="simple">
            <Size>_M_len</Size>
            <ValuePointer>_M_str</ValuePointer>
        </ArrayItems>
    </Expand>
</Type>

During debugging, the DisplayString just reports "-var-create: unable to create variable object".
image

If I remove the size specifier, it works, but this isn't correct because a std::string_view doesn't necessarily need to be a null-terminated string.

Steps to reproduce:

  1. Start a remote debugging session to a linux server (haven't tried this with running directly on my linux machine)
  2. Use a custom natvis file with the above std::string_view visualizer
  3. Create a c++ program that uses std::string_view
  4. Start a debugging session of a c++ application
  5. Try to visualize the std::string_view and see the "-var-create" option
Debugger Configurations
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach MyProgram",
            "type": "cppdbg",
            "request": "attach",
            "program": "/path/to/my/program",
            "visualizerFile": "${workspaceFolder}/stl.natvis",
            "showDisplayString": true,
            "miDebuggerPath": "/usr/local/bin/gdb",
            "MIMode": "gdb"
        }
    ]
}
Debugger Logs
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (31423) <-2235-var-create  - * \"((lPattern)._M_str),[((lPattern)._M_len)]na\"\n"},"seq":10547}
1: (31423) <-2235-var-create  - * "((lPattern)._M_str),[((lPattern)._M_len)]na"
--> R (variables-33): {"type":"response","request_seq":33,"success":true,"command":"variables","body":{"variables":[{"name":"lPattern","value":"-var-create: unable to create variable object","type":"std::string_view","evaluateName":"lPattern","variablesReference":1002},{"name":"lTagName","value":"0x7fffffff8130 \"\"","type":"std::string","evaluateName":"lTagName","variablesReference":1003},{"name":"lStatus","value":"0","type":"int","evaluateName":"lStatus","variablesReference":0,"memoryReference":"0x0000000000000000"},{"name":"lWaveAll","value":"false","type":"bool","evaluateName":"lWaveAll","variablesReference":0},{"name":"lTagFound","value":"false","type":"bool","evaluateName":"lTagFound","variablesReference":0},{"name":"lInsertPoint","value":"false","type":"bool","evaluateName":"lInsertPoint","variablesReference":0},{"name":"lTagCount","value":"1","type":"int","evaluateName":"lTagCount","variablesReference":0,"memoryReference":"0x0000000000000001"},{"name":"lRecursive","value":"0","type":"int","evaluateName":"lRecursive","variablesReference":0,"memoryReference":"0x0000000000000000"},{"name":"lDepth","value":"-1","type":"int","evaluateName":"lDepth","variablesReference":0},{"name":"lLimit","value":"5000","type":"int","evaluateName":"lLimit","variablesReference":0,"memoryReference":"0x0000000000001388"},{"name":"lCount","value":"false","type":"bool","evaluateName":"lCount","variablesReference":0},{"name":"lIsExtId","value":"false","type":"bool","evaluateName":"lIsExtId","variablesReference":0},{"name":"xPattern","value":"-var-create: unable to create variable object","type":"std::string_view","evaluateName":"xPattern","variablesReference":1004},{"name":"xOptions","value":"-var-create: unable to create variable object","type":"std::string_view","evaluateName":"xOptions","variablesReference":1005},{"name":"xFlush","value":"0","type":"int","evaluateName":"xFlush","variablesReference":0,"memoryReference":"0x0000000000000000"},{"name":"xRequest","value":"{...}","type":"const wave::AddWaveReq &","evaluateName":"xRequest","variablesReference":1006}]},"seq":10587}
Other Extensions

No response

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the custom natvis file and the ArrayItems Size expression shown in the report, then reproduce the failure using the provided remote GDB configuration and debugger log. Trace how the C++ extension handles the natvis size specifier for the string_view display; done means the visualizer creates successfully and displays the bounded characters without the var-create error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.