vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

LLDB debugger hangs (using 100% cpu) at launch if std::map is uninitialised

Open zwangz opened this issue 6 years ago • 27 comments

Type: Debugger

Describe the bug

  • OS and Version: macOS 10.14.6 (Darwin x64 18.7.0)
  • VS Code Version: 1.47.2
  • C/C++ Extension Version: 0.29.0
  • Issue:

Similar log to #860 When using include <map>and std::map/std::multimap without initialisation the debugger hangs at launch and is stuck at -var-create - - "map_variable_name" --thread 1 --frame 0; seems like no garbage value can be created See example A below

However this does not happen, if before the (one) std::map declaration there is another container such as std::vector or std::unordered_map declared, even uninitialised.
See example B below

And the problem re-surfaces if more than two <map> contrainers are used. See example C below

Therefore this seems to strangely happen only to std::map containers; a few other stl containers and std::vector alone uninitialised can launch fine and be seen in the local variables window

Please could you investigate? many thanks in advance

To Reproduce

Steps to reproduce the behavior:

  1. tasks.json
{
    "version": "2.0.0",
    "tasks": [
             {
            "type": "shell",
            "label": "clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-std=c++17", 			
                "-stdlib=libc++",
                "-Wall",
                "-g",
                "${fileDirname}/**.cpp",
                "-o",
		"${fileBasenameNoExtension}",
            ],
	    "options": {"cwd": "${fileDirname}"},
            "problemMatcher": ["$gcc"],
	    "group": "build",
		},
     ]
}
  1. launch.json
    "version": "0.2.0",
    "configurations": [
        {
            "name": "vscpp - Build and Debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "lldb",
            "preLaunchTask": "clang++ build active file",
            "logging": {"engineLogging": true},
            "miDebuggerPath": "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi"
        },
    ]
  1. main.cpp using examples below:

EXAMPLE A

#include <iostream>
#include <string>
#include <map> 
#include <unordered_map>
#include <vector>

int main() {
    std::cout << "ISSUE" << std::endl;

    // std::unordered_map<int, int> unord_map;
    // std::vector<int> my_v;             // Same effect as using unordered_map

    std::map<int,int> my_map;
    // std::multimap<int, int> multi_map; // Same issue as my_map
    // std::map<int,int> my_map2;

    std::cout << "ISSUE" << std::endl;
    return 0;
}

image

EXAMPLE B

int main() {
    std::cout << "ISSUE" << std::endl;

    std::unordered_map<int, int> unord_map;
    // std::vector<int> my_v;             // Same effect as using unordered_map

    std::map<int,int> my_map;
    // std::multimap<int, int> multi_map; // Same issue as my_map
    // std::map<int,int> my_map2;

    std::cout << "ISSUE" << std::endl;
    return 0;
}

image

EXAMPLE C - stuck at multi_map

int main() {
    std::cout << "ISSUE" << std::endl;

    std::unordered_map<int, int> unord_map;
    // std::vector<int> my_v;             // Same effect as using unordered_map

    std::map<int,int> my_map;
    std::multimap<int, int> multi_map; // Same issue as my_map
    // std::map<int,int> my_map2;

    std::cout << "ISSUE" << std::endl;
    return 0;
}

image

  1. launch debugger Full log for example A log.txt cpu usage when hanging image

zwangz avatar Jul 19 '20 21:07 zwangz

@zeeepw Thanks for the very detailed issue.

I will need to validate if this occurs in lldb with the non-MI commands.

WardenGnaw avatar Jul 20 '20 17:07 WardenGnaw

@zeeepw Thanks for the very detailed issue.

I will need to validate if this occurs in lldb with the non-MI commands.

Hello, has there been any progress pls?

zwangz avatar Jul 26 '20 16:07 zwangz

I'm having what looks like the same problem, on a big codebase (Apache Arrow). As soon as I get to a stack frame that contains more complex objects (that use STL collections in their implementation, the debugger freezes and does not respond to commands. Looking at things under the hood, VSCode is waiting forever on a reply to the following: 1: (18328) <-1041-var-create - - "parser" --thread 1 --frame 0 (parser is a variable that uses STL collections).

This is making C++ debugging completely unusable for me.

chrish42 avatar Sep 03 '20 16:09 chrish42

I've been experiencing this issue when debugging C++ program in macOS. When this happens, I have to turn to Xcode which works perfectly. So I would have to guess lldb works fine and it is a lldb-mi specific issue.

@zeeepw Thanks for the very detailed issue.

I will need to validate if this occurs in lldb with the non-MI commands.

bubbercn avatar Nov 14 '20 00:11 bubbercn

Can confirm this is still happening on: OS and Version: macOS 10.15.7 VS Code Version: 1.53.2 C/C++ Extension Version: 1.2.0

DominicCabral avatar Feb 15 '21 14:02 DominicCabral

HI

Is there any update on this ? I am writing a simple C++ program for maps and not able to debug at all!!

arvindx101 avatar Jul 27 '21 22:07 arvindx101

I just can not believe this issue still hasn't been addressed. I've been running into this for more than one year. And my workaround is to not use lldb-mi at all.

bubbercn avatar Aug 21 '21 04:08 bubbercn

just ran into it. Cannot believe it is still unresolved

Wdong04 avatar Aug 30 '21 20:08 Wdong04

I've got this same issue.

n-hass avatar Oct 10 '21 10:10 n-hass

It happens to me a lot. I restart my MacBook and sometimes it fixes it. Other times it does not help at all.

josueaanyosa avatar Oct 16 '21 01:10 josueaanyosa

Happens to me with unordered_map, sometimes even if it's initialized.

I just need an IDE with a debugger and a CMake extension for OSX. Any workarounds or recommendations?

blanerhoads avatar Oct 16 '21 17:10 blanerhoads

Can confirm this is still happening on: OS and Version: macOS 11.6 VS Code Version: 1.62.0 C/C++ Extension Version: 1.7.1

When I uncomment the declaration of multi_map (example C) and set a breakpoint on the first line of main() or have "stopAtEntry": true then lldb-mi goes to high CPU and I have to kill it and the debugged process manually.

I could also reproduce the high cpu hang without a breakpoint on the first line of main() if I attached to the process and put the code in a function called after a sleep with a breakpoint at the start of the function.

remyers avatar Nov 06 '21 11:11 remyers

I also ran into a similar issue.

ScherbakovAl avatar Feb 23 '22 11:02 ScherbakovAl

Same here

TwentyPast4 avatar Mar 01 '22 16:03 TwentyPast4

I have a similar problem and I noticed the local section in the variables window in the Visual Code debugger has a spinner during the hang. I hid the variables window and the debugger no longer hangs. Hopefully this works for someone else because this was driving me insane.

csloan-gmail avatar Apr 19 '22 16:04 csloan-gmail

I have a similar problem and I noticed the local section in the variables window in the Visual Code debugger has a spinner during the hang. I hid the variables window and the debugger no longer hangs. Hopefully this works for someone else because this was driving me insane.

@csloan-gmail It works, thanks. Not a solution but this allows to actually debug stuff, at least.

nazavode avatar Apr 30 '22 09:04 nazavode

@csloan-gmail Thanks! That works for me if in addition I'm also super careful with my mouse to not accidentally hover over a map.

sebrockm avatar May 02 '22 09:05 sebrockm

Thanks @csloan-gmail same problem here. Workaround (not looking at variables) at least allows me to move forward.

filipecustodio avatar Oct 17 '22 21:10 filipecustodio

I have a similar problem and I noticed the local section in the variables window in the Visual Code debugger has a spinner during the hang. I hid the variables window and the debugger no longer hangs. Hopefully this works for someone else because this was driving me insane.

Thanks, it solved the issues. I hope it will be fixed soon.

eliyaoo32 avatar Jan 07 '23 09:01 eliyaoo32

Have the same problem on MacOS, hiding variable window is a partial workaround for now.

basdp avatar Jan 13 '23 12:01 basdp