Repository navigation
lldb-mi freezes on MacOS when breaking near uninitialised variables #7240
Description
Type: Debugger
Describe the bug
- OS and Version: MacOS 11.2.3 (Big Sur)
- VS Code Version: 1.5.4.3
- C/C++ Extension Version: 1.2.2
- I have recreated on both Intel and Apple Silicon (Rosetta) MacBook Pros.
During debugging, if stopping on (or stepping in to) a frame containing certain types of uninitialised variables, lldb-mi gets stuck at 100% cpu and starts to consume multiple GBs of memory.
I've encountered this a a few times in different code, I've condensed the latest example in to a tiny snippet (below), using a std::initialiser_list<int>.
I couldn't reproduce using the lldb command line. Xcode is fine too, but I notice it uses lldb-rpc-server to communicate with debugserver instead of lldb-mi.
I also tried using the CodeLLDB extension (https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) which doesn't suffer with the same problem (and doesn't use lldb-mi) - but interestingly, it does try to inspect the values of the initializer_list but times out after a short time.
If debugging is stopped while this is going on, the lldb-mi process continue to spin with high cpu usage in the background.
This may be related to the following:
- LLDB debugger hangs (using 100% cpu) at launch if std::map is uninitialised #5805
- c++ lldb debugger seems hangs #860
- lldb-mi becomes unresponsive, uses lots of memory #1899
The issue may not be directly related to cpptools (could be an lldb-mi bug?), but the extension suffers as a result - in that case, maybe there is something between the interaction with lldb-mi and cpptools that could avoid triggering the bug.
To Reproduce
(I've also prepared a tiny repo for easily reproducing the problem here: https://github.com/andrewfindon/lldbmi-freeze)
To trigger the problem, step in to the freeze_up() function in the example below. The lldb-mi process should spike in cpu/memory usage and vscode will appear to freeze waiting for local variables to resolve.
main.cpp
#include <initializer_list>
void freeze_up()
{
auto bad_var = {1, 2, 3}; // A breakpoint here will trigger the issue.
} // A breakpoint here is fine (bad_var is initialised).
int main() {
freeze_up();
return 0;
}launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/freeze",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "clang++ build",
"logging": {
"engineLogging": true,
"trace": true,
"traceResponse": true
}
}
]
}tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build",
"command": "/usr/bin/clang++",
"args": [
"main.cpp",
"-arch",
"x86_64",
"-std=c++17",
"-Wall",
"-g",
"-o",
"freeze",
],
"problemMatcher": [
"$gcc"
],
"group": "build",
}
]
}The tail of my engine logging output at the point where the debugger has frozen on a breakpoint, looks like:
--> E (stopped): {"type":"event","event":"stopped","body":{"reason":"step","threadId":1,"allThreadsStopped":true,"source":{"name":"main.cpp","path":"/Users/andrewfindon/Documents/lldbmi-crash/main.cpp","sources":[],"checksums":[]},"line":6,"column":1},"seq":641}
<-- C (threads-12): {"command":"threads","type":"request","seq":12}
--> R (threads-12): {"type":"response","request_seq":12,"success":true,"command":"threads","body":{"threads":[{"id":1,"name":"Thread #1"}]},"seq":644}
<-- C (stackTrace-13): {"command":"stackTrace","arguments":{"threadId":1,"startFrame":0,"levels":20},"type":"request","seq":13}
--> R (stackTrace-13): {"type":"response","request_seq":13,"success":true,"command":"stackTrace","body":{"stackFrames":[{"id":1000,"name":"freeze!freeze_up()","source":{"name":"main.cpp","path":"/Users/andrewfindon/Documents/lldbmi-crash/main.cpp","sources":[],"checksums":[]},"line":6,"column":1,"moduleId":1},{"id":1001,"name":"freeze!main","source":{"name":"main.cpp","path":"/Users/andrewfindon/Documents/lldbmi-crash/main.cpp","sources":[],"checksums":[]},"line":12,"column":1,"moduleId":1},{"id":1002,"name":"libdyld.dylib!start","line":0,"column":0,"moduleId":12},{"id":1003,"name":"libdyld.dylib!start","line":0,"column":0,"moduleId":12}],"totalFrames":4},"seq":647}
<-- C (scopes-14): {"command":"scopes","arguments":{"frameId":1000},"type":"request","seq":14}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (33618) <-1018-stack-list-variables 0 --thread 1 --frame 0\n"},"seq":650}
1: (33618) <-1018-stack-list-variables 0 --thread 1 --frame 0
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (33631) ->1018^done,variables=[{name=\"bad_var\"}]\n"},"seq":652}
1: (33631) ->1018^done,variables=[{name="bad_var"}]
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (33631) ->(gdb)\n"},"seq":654}
1: (33631) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (33632) 1018: elapsed time 13\n"},"seq":656}
1: (33632) 1018: elapsed time 13
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (33657) <-1019-var-create - - \"bad_var\" --thread 1 --frame 0\n"},"seq":658}
1: (33657) <-1019-var-create - - "bad_var" --thread 1 --frame 0
Here's a trace of lldb-mi in Instruments - it's clear on the timeline when I stepped in to the freeze_up function:

Example debugging session:

Activity
WardenGnaw commentedon Mar 29, 2021
lldb-mi seems to already have some issues being slow debugging as per #1899 (comment).
For Apple Silicon, it will be slow since both the Debug Adapter (MIEngine) and lldb-mi will both be running in emulation.
To fix the latter, it is dependent on #7035
andrewfindon commentedon Mar 29, 2021
Please note, this issue applies equally to Intel machines (I mention Apple Silicon only to be thorough).
Also, I have left It in this high cpu, high memory state for "some time" (multiple minutes) - it doesn't seem to recover (so less about it being slow, and more about it getting stuck).
cpptools no longer responds, except for cancelling debugging (but this leaves lldb-mi running in the background eating cpu and rapidly draining battery).
This ~6 line sample is enough to break the debugging experience entirely, but personally I've encountered these symptoms a couple of times in actual code, although then I think it was an uninitialised std::vector that was the trigger.
Anecdotally it seems like the debugger is reaching in to the uninitiated memory forever to resolve values for the local variables view.
ni4 commentedon Jun 19, 2021
+1 for this issue, macOS Catalina 10.15.7, Intel CPU.
However:
-fsanitize=address,undefined. Removing this doesn't change the behaviour.Wdong04 commentedon Aug 30, 2021
Same problem here. Would like to know how to address it.
shiretu commentedon Dec 20, 2021
I have recompiled my lldb-mi with this patch:
Ayasra commentedon Mar 19, 2022
Same problem here
PenceGL commentedon Apr 7, 2022
I just experienced this a few minutes ago. I am on MacOS Monterey, v12.3.1, Intel CPU.
I was able to hit breakpoints, but then realized my debugger controls (Continue, Step Over, Step In) were completely unresponsive. I was able to press stop to quit debugging as andrewfindon mentioned. But then my laptop tried to enter orbit... fans on full blast, CPU utilization pegged at 100%. Activity Monitor showed several instances (I guess because I had hit stop and rerun the debugger a few times) of lldb-mi using lots of memory and 100% CPU. Stopping them manually through Activity Monitor resolved the issue and the fan/utilization went back to normal levels.
A few quick Google searches led me here. I'm glad to see that it's an issue that's still getting attention.
AgraVator commentedon Apr 24, 2022
This helped me to avoid the problem for now.
Looking forward for a permanent fix though.
lp35 commentedon Aug 10, 2022
Hey guys, do you have a solution for Linux users?
Cheers!
vlebourl commentedon Sep 13, 2022
Hey, any news on this?
shiretu commentedon Oct 5, 2022
I do not think this is a VSCode issue. This is truly a problem with the lldb. See my patch above. lldb is out-of-bounds-ing on walking uninitialized variables with garbage values on things like internal counters and sizes. My quick yet brutal fix is to limit these things to 64.
Unfortunately, VSCode tries to render all local variables in the current scope. And when it reaches one of those not-yet-initialized vars, it behaves like that.
jpcofr commentedon Mar 12, 2023
As a workaround, I installed CodeLLDB. It fixed the issue. Still, vscode's own debugger got lldb to use all the memory in my machine, which in turn made it unresponsive and I had to restart it.
garfieldnate commentedon Aug 25, 2023
I ran into this today. Since Gavriloaie Eugen-Andrei (@shiretu) says this is an lldb-mi issue, I guess the place to track it is here?
6 remaining items
sunshaoce commentedon Nov 29, 2023
Gavriloaie Eugen-Andrei (@shiretu) Would you consider improving it and then submit it to lldb-mi?
robUx4 commentedon Feb 17, 2024
This is still happening with cpptools v1.18.5. I disabled the "Variables" view of the debugger so I can get some work done. Mouse hover on a variable still shows the variables when needed.
wbf22 commentedon May 16, 2024
I actually had it freeze again after removing the file James Juett (@jamesjuett)
But hiding the variables section in the debug window does work (rerunning after hiding)
ddavlet commentedon Jul 23, 2024
This issue still persists
clayborg commentedon Aug 6, 2024
This is an issue with synthetic child providers. For STL classes you often don't want to see the actual children of a
std::list<T>orstd::vector<T>, you want to see the children as an array. When we have uninitialized variables, the synthetic child provider has to be very careful to check for invalid values and not do too much work when calculating the number of children. So this can most likely be fixed by checking out the typename of the type that is causing this delay, and then finding out which synthetic child provider it is using and adding a fix to this formatter if upstream LLDB doesn't already have it fixed. To see which synthetic formatters are enabled, type this command at the prompt:And then with the variable that causes the problem run:
The --raw option will disable the synthetic child plug-in. These synthetic plugins can either be natively compiled into lldb, or they can be python modules that add the support. If they are python then it is usually easy to fix right away. If the synthetic child provider is compiled into LLDB, then a new version of LLDB will need to be distributed. This formatter does seem to have issues. I just compiled your example and ran this in the command line:
As you can see we stopped asking for children when we reached the
target.max-children-countsetting. The MI plug-in will want to do the same thing. We can see the raw variable values here:So we think there are 4299233552 children to show. This value is way to easy to mess up because there isn't much we can do to know when the values are bad. We can check that
__begin_is aligned on aintboundary, but in this case, it works.clayborg commentedon Aug 6, 2024
In this case the provider is built in:
clayborg commentedon Aug 6, 2024
So the question is: is the MI plug-in asking and producing that many children for this variable and that is what is taking the time and blowing up memory? If so, it should stop creating children for a variable when it hits the
target.max-children-countlldb setting value.sunshaoce commentedon Aug 7, 2024
lldb-mihas attempted to fix this problem in lldb-tools/lldb-mi#115, but it seems thatcpptoolsis not using the latest version oflldb-mi.KevinEady commentedon Aug 17, 2024
Thanks for the info Shaoce SUN (@sunshaoce) . I was able to work around the issue by building
lldb-mifrom scratch (from commit a6c8c66), and replacing the executable inside~/.vscode/extensions/ms-vscode.cpptools-1.21.6-darwin-arm64/debugAdapters/lldb-mi/bin/lldb-miObviously any update to the extension would cause the file to be overwritten. Not sure how to update it inside the cpptools extension directly. This whole "downloading" section seems outdated https://github.com/microsoft/vscode-cpptools/blob/main/CONTRIBUTING.md#about-the-code -- there is no
packageManager.tsjjaine commentedon Oct 9, 2024
OS and Version: MacOS 14.6.1 (Sonoma)
VS Code Version: 1.93.1
C/C++ Extension Version: 1.21.6
LLDB Version: lldb-1600.0.36.3
Apple M2 Max Chip
Similar issue, but for me the debugger crashes
Tried building
lldb-miwith the instructions from lldb-tools/lldb-mi#100 using the commit a6c8c66, which made no difference. Also tried the fix from the lldb-tools/lldb-mi#118 forlldb-mi, also no difference.The workaround of hiding the Variables view from #7240 (comment) works.
Downgrading Xcode to 15.4 (and thus to
lldb-1500.0.404.7) also returns the issue to the current state (which for me was still working in most cases).icppWorld commentedon Jan 22, 2025
Thank you for this tip. Is a great workaround.
Ritil-Ranjan commentedon Jul 8, 2025
Yes I faced the exact same issues with my Mac M2 Sequoia 15.5, but with one more problem. The temperature spiked from low to very high really quickly. I have used VSCode for so much time before and nothing like this ever happened. Only when I tried to do debugging, this happened; and this happened always when I tried to do debugging.
tangobravo commentedon Oct 13, 2025
Here's another really small reproducer with a breakpoint on the first line of the main function.
Right now on an M1 Pro macbook with clang/lldb from the latest Xcode the default build / debug action in vscode on this incredibly simple test case (after also modifying tasks.json to add
-lstdc++to avoid linker errors) causes the spinner on loading the locals list. On stopping debugging it leaves the lldb-mi process around, consuming 100% of a CPU core and gobbling memory at a rate of around 1GB every 10 seconds. The first time it happened I needed to hard reset my laptop as I hadn't noticed that runaway process before the system became unresponsive. This feels like a pretty serious issue that I'd argue makes C++ debugging in vscode on vanilla Mac configurations actively harmful.To summarise what I've learnt of the background, it seems there are two possible ways that vscode can communicate with LLDB - lldb-mi, and lldb-dap.
LLVM themselves do publish a lldb-dap extension for vscode which does not suffer from this issue, so installing that from the marketplace is a simple workaround.
The issue with the version of lldb-mi shipped with this extension is that it recurses into children when evaluating variables. lldb implements synthetic children for things like std::vector and if the memory is corrupt or uninitialised that can lead to an incredibly large number of children (the lldb-dap debugger doesn't do the recursion and reports the size of the vector as 5166693 before stepping over the initialization line where it is initialized to 0).
Even though it's not very actively maintained, the lldb-mi repo does appear to have a fix for this:
lldb-tools/lldb-mi@2340ff2
It looks like the binary shipped with vscode is built from the scripts in the Build/lldb-mi folder which reference a specific older lldb-mi commit from before the fix listed above.
So therefore if there are valid reasons for not switching to lldb-dab just yet, then at least updating lldb-mi (or just applying a patch based on the commit above) should resolve this issue and the many others referencing debugging hangs on lldb/Mac.
I tried just updating the reference above in a fork but it looks like that workflow doesn't run on GitHub but rather on some separate azure infrastructure? Would it be possible for someone on the vscode team just to try bumping that to a newer commit for testing?