vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.43k stars 237 forks source link

Unable to show correct size of unordered_map after inserting elements while debugging CPP program #912

Open hengyuekang opened 1 year ago

hengyuekang commented 1 year ago

OS: Ubuntu 22.04.2 LTS VSCode version: Version: 1.77.3 (Universal) CodeLLDB version: v1.9.0 Compiler: Ubuntu clang version 14.0.6 Debuggee: x86-64-UNIX-System V

I'm remotely developing a program in Virtual Machine on my server with my laptop(macOS Monterey Version 12.0.1). While debugging with lldb, I found that the size and contents of std::vector in the sidebar are correct but for std::unordered_map, it keeps showing size=0 even after inserting elements.

This is the code for the test:

#include<unordered_map>
#include<vector>
#include<cstdio>
#include <cstdlib>
int main()
{
    std::unordered_map<int, int> m;
    std::vector<int> v;
    for(int i=0;i<20;i++)
    {
        v.push_back(rand()%10);
    }
    for(auto num:v)
    {
        if(m.count(num)!=0)
        {
            m[num]++;
        }
        else
        {
            m[num]=1;
        }
    }
    for(auto it:m)
    {
        printf("num: %d, count: %d\n", it.first, it.second);
    }
    return 0;
}

the configuration file launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "lldb-debug-test",
            "type": "lldb", 
            "request": "launch",
            "preLaunchTask": "lldb-debug-test",
            "cwd": "${workspaceFolder}",
            "program": "${workspaceFolder}/test/codelldb_test",
            "args": [],
            "terminal": "integrated",
        }
    ]
}

and compiled it with: clang++-14 -g codelldb_test.cc -std=c++14 -O0 -o codelldb_test

This is a capture of the screen while debugging:

Screen Shot 2023-04-23 at 11 37 23

Obviously, it didn't show the right size of m(an unordered_map) after counting(inserting elements).

(BTW: could you give me more detailed instructions about how to capture the verbose log? I tried to add "lldb.verboseLogging":true to the launch.json file, but it shows "Property lldb.verboseLogging is not allowed." and nothing happened when reproducing the problem)

vadimcn commented 1 year ago

All C++ type visualizations are inherited from the upstream LLDB. I'd recommend trying to reproduce the bug with CLI LLDB then filing a bug with them, if confirmed.

chanmaoganda commented 3 months ago

Screenshot 2024-04-17 100157 now the set should be with size of 4. In raw pointer, the element count is 4, while it shows 0 in codelldb

chanmaoganda commented 3 months ago

Screenshot 2024-04-17 100554 also, if i try using vertex.size() to assign variable size, it also does well. the size of this set in codelldb always gonna show 0