Running VS Code in Windows and configured it to compile/debug with clang and lldb-mi when I debug and set breakpoints going step by step I cannot see the output in debug terminal or terminal.
This is the code I use for testing:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", // change this to your executable path
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
// "MIMode": "lldb-mi",
// change this to your lldb-mi path
// you can install lldb-mi using chocolatey: choco install llvm
// then find it under C:\ProgramData\chocolatey\lib\llvm\tools\lldb\bin
// or use any other method of installing lldb-mi
// make sure to escape backslashes with another backslash
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\lldb-mi.exe"
}
]
}
Tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\ucrt64\\bin\\clang++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"-std=c++20",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
If I just debug without any breakpoint the output terminal shows:
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=thread-selected,id="1"
=library-unloaded,id="C:\\msys64\\mingw64\\bin\\libwinpthread-1.dll",target-name="C:\\msys64\\mingw64\\bin\\libwinpthread-1.dll",host-name="C:\\msys64\\mingw64\\bin\\libwinpthread-1.dll"
Hello C++ World from VS Code and the C++ extension!
=library-unloaded,id="D:\\dev\\projects\\helloworld\\helloworld.exe",target-name="D:\\dev\\projects\\helloworld\\helloworld.exe",host-name="D:\\dev\\projects\\helloworld\\helloworld.exe"
The program 'D:\dev\projects\helloworld/helloworld.exe' has exited with code 0 (0x00000000).
but with a breakpoint I can only see the printed text if I let it run until the end, while doing F10 it does not print on cout
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=thread-selected,id="2"
=library-unloaded,id="C:\\msys64\\mingw64\\bin\\libwinpthread-1.dll",target-name="C:\\msys64\\mingw64\\bin\\libwinpthread-1.dll",host-name="C:\\msys64\\mingw64\\bin\\libwinpthread-1.dll"
=thread-selected,id="1"
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)
Hello C++ World from VS Code and the C++ extension!
=library-unloaded,id="D:\\dev\\projects\\helloworld\\helloworld.exe",target-name="D:\\dev\\projects\\helloworld\\helloworld.exe",host-name="D:\\dev\\projects\\helloworld\\helloworld.exe"
The program 'D:\dev\projects\helloworld/helloworld.exe' has exited with code 0 (0x00000000).
UPDATE
I followed the instructions here std::cout won't print but sorry, it didn't work. No matter if I add std::endl or std::flush for every cout, it won't print to debugger/terminal if I'm debugging with breakpoints. There seems to be a problem with the lldb-mi debugger because I can debug and see the output happening if I use gdb