Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS code is ignoring the breakpoint in c++ debugging

I am debugging a c++ code in VS Code but it doesn't stop on breakpoint and visualize the variables, watch and call stack, which it was supposed to do. Instead of this, it prints this in debug console:

Breakpoint 1, 0x000000000040074a in main ()
[Inferior 1 (process 9445) exited normally]
The program '/home/hashir/x/a.out' has exited with code 0 (0x00000000)

here is launch.json file:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/hashir/x/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "/home/hashir/x/",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
like image 520
Hashir Sarwar Avatar asked Jan 15 '18 17:01

Hashir Sarwar


People also ask

Why is my breakpoint not working VSCode?

If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.

How do you Debug a breakpoint in Visual Studio code?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

Why C is not working in VSCode?

Go to the menu Code > Preferences > Settings. In the User tab on the left panel, expand the Extensions section. Find and select Run Code Configuration. Find and check the box Run in Terminal.

Can you Debug C in VSCode?

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)


2 Answers

Comiple the program using -g tag alongwith g++/clang++

like image 115
Hashir Sarwar Avatar answered Oct 20 '22 19:10

Hashir Sarwar


This problem literally ruined my day. It turned out that all I had to do is just Terminal > Run Build Task or Ctrl+Shift + B and then start debugging.

like image 26
temmmy Avatar answered Oct 20 '22 21:10

temmmy