Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug in VS Code using lldb?

I'm trying to debug a simple C++ program, but nothing happens, and breakpoints are also not working. Build task runs fine, and I can run the application.

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++.exe build active file",
            "command": "F:\\Programs\\LLVM\\bin\\clang++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "clang++.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "miDebuggerPath": "F:\\Programs\\LLVM\\bin\\lldb-vscode.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: clang++.exe build active file"
        }
    ]
}

When I press F5, I have this in terminal:

PS F:\Projects\Console Apps\testbuild>  & 'c:\Users\daniil\.vscode\extensions\ms-vscode.cpptools-1.7.1\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-4pf1un21.l04' '--stdout=Microsoft-MIEngine-Out-tpjfi4ip.jse' '--stderr=Microsoft-MIEngine-Error-2nkku53m.1iw' '--pid=Microsoft-MIEngine-Pid-xscepzdp.k00' '--dbgExe=F:\Programs\LLVM\bin\lldb-vscode.exe' '--interpreter=mi'

But I don't have any output of my program, step over/into/out buttons is greyed out and breakpoints are not working.

like image 355
Daniil Andreev Avatar asked May 09 '26 18:05

Daniil Andreev


2 Answers

In launch.json I had to write "lldb", not "cppdbg". Now it works.

like image 117
Daniil Andreev Avatar answered May 12 '26 09:05

Daniil Andreev


Just to complete Daniil's answer, I installed CodeLLDB extension and used the following launcher :

{
    "name": "debug-launcher",
    "type": "lldb",
    "request": "launch",
    "program": "${workspaceFolder}/build/debug/bin/foo_exe",
    "cwd": "${workspaceFolder}/build/debug/bin",
    "env": {
        "MY_VERSION":"2.4.0",
        "GDAL_DATA": "/home/myuser/binaries/gdal-2.4.4/share/gdal",
        "LD_LIBRARY_PATH": "/home/myuser/[...]/lib",
        "DISPLAY": "host.docker.internal:0"
    },
    "args": [],
    "preRunCommands": ["breakpoint name configure --disable cpp_exception"]
}

Note the last line, used to avoid breaking on exceptions (caught/uncaught)

like image 23
georges abitbol Avatar answered May 12 '26 09:05

georges abitbol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!