Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug C++ code on VSCode? MacOS

Tags:

I have downloaded the C++ extension and this is my launch.json file. enter image description here

What should I need to do to debug it? I keep having this error. enter image description here

Is it possible to debug C++ code on MacOS? Anything I should add/download/create first?

Update : Here is what I did base on answers below and I get this enter image description here

like image 785
Student Avatar asked Oct 20 '16 18:10

Student


People also ask

Can you Debug C in VS Code?

Visual Studio Code supports the following debuggers for C/C++ depending on the operating system you are using: Linux: GDB. macOS: LLDB or GDB. Windows: the Visual Studio Windows Debugger or GDB (using Cygwin or MinGW)

How do you run and Debug C code in VS?

VSCode can create and auto-configure these files if we try to debug for the first time. To do that, open C++ file in VSCode and either hit F5 or go to Debug -> Start Debugging and select C++ (GDB/LLDB) then select g++.exe build and debug active file .

How do you Debug a MAC code?

Setting a breakpoint is easy. Just open the source file you want to debug in Xcode, and click in the margin to the left of the line of code where you want to break. During the debugging session, each time that line is executed, the debugger will break there, and you will be able to debug it.


1 Answers

You cannot use cppvsdbg as the debugger, unless you are using the Visual Studio Windows debugger. For Mac OS X you should be using cppdbg as the debugger type.

Besides that, your program entry points to a directory, not an executable image. Change that to something like "program": "${workspaceRoot}/a.out". As documented, this entry "[s]pecifies the full path to executable the debugger will launch or attach to."

More information available at Configuring launch.json for C/C++ debugging.

like image 92
IInspectable Avatar answered Sep 26 '22 16:09

IInspectable