最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

Environment:

  • OS: Windows
  • Compiler: GCC (Cygwin)
  • Debugger: GDB
  • IDE: Visual Studio Code

Attempts to Solve:

  • Verified that -g is included in the compiler arguments to generate debug symbols.
  • Checked that the executable is being built in the same directory as specified in launch.json.
  • Confirmed that the correct miDebuggerPath is being used.

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论