【问题标题】:Breakpoints are ignored in VS-Code debugging C with gdb在使用 gdb 的 VS-Code 调试 C 中忽略断点
【发布时间】:2019-09-10 07:45:44
【问题描述】:

我尝试调试我的 C 代码,但我的断点被忽略。 我的系统是 Windows 10。VS-Code 版本是 1.38。

这是我的 launch.json 条目:

    {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "C:/Users/NCH-Lap10/Desktop/aaa.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerPath": "C:/TDM-GCC-64/bin/gdb.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
    },

我会很感激任何提示。 我可以提供更多信息吗?

【问题讨论】:

    标签: c visual-studio-code gdb vscode-debugger


    【解决方案1】:

    我在这里分享我的配置文件,只需将它们添加到.vscode 文件夹下,并将文件命名如下。

    c_cpp_propreties.json

    {
       "configurations":[
          {
             "name":"Win32",
             "includePath":[
                "${workspaceFolder}/**",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/trl"
             ],
             "defines":[
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
             ],
             "compilerPath":"C:\\MinGW\\bin\\gcc.exe",
             "cStandard":"c11",
             "cppStandard":"c++17",
             "intelliSenseMode":"clang-x64"
          }
       ],
       "version":4
    }
    

    launch.json

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "(gdb) Launch",
                "type": "cppdbg",
                "request": "launch",
                "program": "${workspaceFolder}/a.exe",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",
                "environment": [],
                "externalConsole": false,
                "MIMode": "gdb",
                "miDebuggerPath": "C:/MinGW/bin/gdb.exe",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ],
                "preLaunchTask": "Compile C File"
            }
        ]
    }
    

    tasks.json

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "Compile C File",
                "command": "gcc",
                "type": "shell",
                "args": [
                    "-g",
                    "${file}",
                    "-o",
                    "${workspaceRoot}\\a.exe"
                ],
                "problemMatcher": [
                    "$tsc"
                ],
                "presentation": {
                    "reveal": "always"
                },
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
    

    为了在以上配置中工作,您至少需要拥有launch.jsontasks.json

    【讨论】:

    • @kame 另外,您正在使用 gdb 进行 c 代码调试,但您需要为 c 提供 gcc,为 cpp 提供 gdb。
    猜你喜欢
    • 2017-07-20
    • 2020-11-28
    • 2018-02-20
    • 2018-06-24
    • 2022-11-17
    • 2018-03-08
    • 2014-01-15
    • 1970-01-01
    • 2018-07-22
    相关资源
    最近更新 更多