Using debugger in VS code

223 Views Asked by At

how do i use a debugger in vs code for a c++ program. i watched some videos and tutorials but didn't quite get anything.

do i need the codelldb extension for that. is a launch.json file needed for using the debugger .i once ran the debugger without the launch.json file but it didn't stepped into a function that i had created . it went into some weird location (something like main.h , i think) what configuration do i need in the launch.json file . what are "launch" and "attach" in there. what is "c++ : catch" and "c++: throw" in the breakpoints window.

this is my launch.json for codelldb : { "version": "0.2.0", "configurations": [

    {
        "type": "lldb",
        "request": "launch",
        "name": "Debug",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "args": [],
        "cwd": "${fileDirname}"
    }
]

}

1

There are 1 best solutions below

12
Amelia Haghighi On

I recommend you to give this link a read. As a programmer I believe it's very important to be able to read documentation well.

To answer the your question, it depends on what debugger you need, on MacOS, as far as I'm aware, your only option is for C/C++ debugging is LLDB. You'll indeed need the CodeLLDB extension installed in VSCode.

to give you an idea here is my launch.json for LLDB on MacOS, this is a CMake project. Make sure you compile your code as Debug. For CMake, you'll have to use the -DCMAKE_BUILD_TYPE=Debug argument when generating the makefile

my launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "lldb",
            "request": "launch",
            "targetArchitecture": "arm64",
            "program": "${workspaceFolder}/build/Bunget",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            
        }
    ]
  }

Pay extra attention to the MiMode, targetArchitecture, program and type arguments.

If you own an Apple Silicone MacBook, this article might also be useful