Kamal
Kamal

Reputation: 13

Why does my VSCode debugger not stop at breakpoints when debugging C files with GCC and GDB? (Windows)

I have configured launch.json and tasks.json in VSCode to compile and debug C files using GCC and GDB on Windows. The code compiles and executes successfully, but the debugger does not stop at the breakpoints I set in the code.

Here are the contents of my tasks.json and launch.json:

launch.json

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

tasks.json

{
"version": "2.0.0",
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: gcc.exe build active file",
        "command": "C:\\cygwin64\\bin\\gcc.exe",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: C:\\cygwin64\\bin\\gcc.exe"
    }
]
}

Here is the test C file I'm trying to debug (test.c):

#include <stdio.h>

int main() {
  int a = 5;
  int b = a + 3;
  printf("%d %d", a, b);
  return 0;
}

Expected Behavior:

The debugger should stop at the breakpoints I set in the code.

Observed Behavior:

The code compiles and runs, but the debugger does not stop at the breakpoints. Instead, the program completes execution, and the output is displayed in the terminal.

enter image description here

Environment:

Attempts to Solve:

What might be causing the debugger to skip the breakpoints? How can I resolve this issue?

Upvotes: 0

Views: 37

Answers (0)

Related Questions