【问题标题】:Can't debug C++ in VS code with gdb无法使用 gdb 在 VS 代码中调试 C++
【发布时间】:2018-11-20 09:25:39
【问题描述】:

我正在尝试在 Visual Studio Code 中调试 C++,但这里出了点问题。 调试状态不断滚动,但没有控制台显示。如果我停止调试(shift+ F5),我将无法再次调试。无论是单击绿色三角形还是 F5,都没有任何反应。 Debug screenshot

建筑没问题。这只是调试问题。
MinGW 已添加到 PATH。我可以在 CMD 中使用 g++ 或 gdb。

我的环境:

  • 操作系统:Windows10 1803
  • Visual Studio 代码:1.24.0
  • C/C++ 扩展:0.17.4
  • MinGW_w64: x86_64-8.1.0-release-posix-seh-rt_v6-rev0

这是我的配置:

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "C:/MinGW/include",
                "C:/MinGW/x86_64-w64-mingw32/include",
                "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
                "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                "${workspaceFolder}"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "compilerPath": "C:/MinGW/bin/gcc.exe",
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "C:/MinGW/include",
                    "C:/MinGW/x86_64-w64-mingw32/include",
                    "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                    "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                    "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                    "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1",
                    "C:/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                    "${workspaceFolder}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

launch.json:

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

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "windows": {
                "command": "g++",
                "args": [
                    "-g",
                    "\"${file}\"",
                    "--std=c++11",
                    "-o",
                    "\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
                ]
            }
        }
    ]
}

settings.json

{
    "files.associations": {
        "iostream": "cpp",
        "ostream": "cpp",
        "cmath": "cpp",
        "array": "cpp",
        "chrono": "cpp",
        "functional": "cpp",
        "ratio": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "future": "cpp",
        "streambuf": "cpp",
        "sstream": "cpp",
        "initializer_list": "cpp",
        "valarray": "cpp"
    }
}

【问题讨论】:

  • c_cpp_properties.json 中的编译器路径应该是"compilerPath": "C:/MinGW/bin/g++.exe"
  • @HeheBoi 谢谢。但还是不行。
  • 我在这个问题上停留了大约 2 天,这个问题对我有用。感谢分享这个

标签: c++ debugging visual-studio-code gdb mingw


【解决方案1】:

我发现这是一个编码问题,我自己解决了。

首先,尝试 gdb 日志记录,看看您是否遇到了同样的问题。
启用"logging": { "engineLogging": true },如果你看到类似的东西

1: (1992) ->&"\357\273\2771001-gdb-set target-async on\n"
1: (1993) ->&"Undefined command: "\357". Try "help".\n"
1: (1993) ->^error,msg="Undefined command: "\357". Try "help"."

那你也有同样的问题。

要修复它,您需要禁用 Unicode UTF-8 以获得全球语言支持,这是自 Windows10 1803 以来的测试版功能,默认情况下已禁用。
它位于 控制面板 - 时钟和区域 - 区域 - 管理 - 更改系统位置 strong>(需要管理员授权)- 测试版:使用 Unicode UTF-8 获得全球语言支持(需要重新启动系统)。

更多详情请访问 GitHub 上的why vscode just hang in there when start debugging with gdb.exe?

【讨论】:

  • 嗨,你在哪里启用"logging": { "engineLogging": true }?我得到未知的配置设置
猜你喜欢
  • 2013-01-07
  • 2013-09-29
  • 1970-01-01
  • 1970-01-01
  • 2022-01-05
  • 2019-05-14
  • 2014-04-24
  • 2023-02-04
相关资源
最近更新 更多