首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在VSCode上使用F5调试失败,并显示"Unable to establish a connection to GDB“

在VSCode上使用F5调试失败,并显示"Unable to establish a connection to GDB“
EN

Stack Overflow用户
提问于 2021-02-25 17:31:56
回答 2查看 921关注 0票数 0

当我按F5键在Visual Studio Code上运行C++程序时,我得到消息

"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information."

我使用g++.exe和MinGW进行编译。直到一个小时前,使用F5键的调试才正常完成,而且我从来没有接触过launch.json。你能告诉我出了什么问题吗?

下面是launch.json

代码语言:javascript
运行
复制
{
    // 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": "g++.exe - アクティブ ファイルのビルドとデバッグ",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "console": "externalTerminal",
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "gdb の再フォーマットを有効にする",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe アクティブなファイルのビルド"
        }
    ]
}

下面是tasks.json

代码语言:javascript
运行
复制
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe アクティブなファイルのビルド",
            "command": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "コンパイラ: C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe アクティブなファイルのビルド ver(1)",
            "command": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "デバッガーによって生成されたタスク。"
        }
    ]
}

下面是c_cpp_properties.json

代码语言:javascript
运行
复制
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "${vcpkgRoot}/x86-windows-static/include",
                "C:\\Users\\SonicTheHedgehog\\Desktop\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "C:\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

附加:我在launch.json上发现了一条错误消息

Property console is not allowed

console用波浪线标记。

EN

回答 2

Stack Overflow用户

发布于 2021-02-25 17:38:55

我建议使用不同的基于编译器的扩展,例如代码运行器等,有时,扩展是visual studio代码中的兼容性问题。当我开始使用visual studio代码时,我也遇到了同样的问题。

票数 0
EN

Stack Overflow用户

发布于 2021-11-10 06:16:25

请查看此链接:https://github.com/microsoft/vscode-cpptools/issues/2889

在内部控制台中运行(在VSCode中运行)时,PowerShell会出现一些问题。

我在launch.json中做了以下更改:

之前:

代码语言:javascript
运行
复制
        "environment": [],
        "externalConsole": **false**,
        "MIMode": "gdb",

之后:

代码语言:javascript
运行
复制
        "environment": [],
        "externalConsole": **true**,
        "MIMode": "gdb",

现在,我在VSCode之外的cmd.exe中看到了程序的输出。但是,调试器在VSCode中运行得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66365840

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档