-3

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}"
    }
]

}

Garry
  • 1
  • 1
  • 2
    This is not a site for tutorials. You should search for guides like https://code.visualstudio.com/docs/cpp/cpp-debug and then come back with more specific questions. – Lex Li Jul 13 '23 at 05:46
  • 2
    If you're just getting started, consider using something else. VS Code takea fair amount of wrangling to get working. If you have to wonder if you have the tool set up correctly at the same time you have to learn the language, you're putting yourself at a disadvantage. – user4581301 Jul 13 '23 at 06:10

1 Answers1

0

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

  • i used codelldb but it didnt stop at the breakpoint it just ran through the codesimply this is my launch.json: "version": "0.2.0", "configurations": [ { "type": "lldb", "request": "launch", "name": "Debug", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "cwd": "${fileDirname}" } ] PS: i am on windows – Garry Jul 13 '23 at 06:27
  • Did you add MiMode? also it's nicer to edit your original question for this as including the config in the comments is very hard to read. – Amelia Haghighi Jul 13 '23 at 06:30
  • @Garry *'As a programmer I believe it's very important to be able to read documentation well.'* I 100% agree with this statement, it's much better to be able to research a problem for yourself than to rely on others to tell you the answer. – john Jul 13 '23 at 06:32
  • @john i have read many documentation but it just confused me more . the debugger just wont stop at the breakpoints (in codelldb extension) .could i connect with any of you on telegram if possible please? – Garry Jul 13 '23 at 07:21
  • @Garry I'm not on telegram. If you are on Windows then why are you trying to use lldb? What compiler are you using? – john Jul 13 '23 at 07:25
  • @john mingw64 (g++) im following a course on c++,the instructor said to use codelldb – Garry Jul 13 '23 at 07:32
  • @Garry Then you have picked the wrong debugger, and it's no surprise you cannot get it to work. The debugger for g++ is called gdb. You should uninstall the codelldb extension, and you should start again trying to setup your debugging environment. AFAIK no extension is required to use gdb. – john Jul 13 '23 at 07:34
  • 1
    @Garry Honestly the best advice I can give is to forget about VSCode, VSCode is a complex product and there are alternatives for Windows that are simpler and (IMHO) better. Visual Studio being the obvious choice. – john Jul 13 '23 at 07:36
  • oh okk, thanx can u tell me how to configure the launch.json for that. i one did ran the debugger with gdb, but it didnt step into a function that i had in the program,(it went into somth like main.h ,i think) – Garry Jul 13 '23 at 07:37
  • 1
    @Garry I'm sorry but this is not a tutorial site. How to set up the debugger for g++ is well documented on the official VSCode site. Or you could switch to Visual Studio where the debugger just works, no setup is required at all. – john Jul 13 '23 at 07:40
  • @Garry Also got to wonder what your course instructor was thinking. Maybe there was some miscommunication there. – john Jul 13 '23 at 07:43
  • @Garry If you are sticking with VSCode then give setting up the debugger your best shot. If it still does not work then ask a new question. Make sure that in that question you post tasks.json, launch.json and that you describe precisely what steps you take to attempt to build and debug your code. – john Jul 13 '23 at 07:47
  • @john ohkk thanks – Garry Jul 13 '23 at 16:52