无法使用 gdb 在 VS 代码中调试 C++ [英] Can't debug C++ in VS code with gdb

查看:48
本文介绍了无法使用 gdb 在 VS 代码中调试 C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying debugging C++ in Visual Studio Code, but here is something wrong. The debug status keeps scrolling, but no console shows. If I stop debug (shift+ F5), I won't be able to debug again. Whether click the green triangle or F5, nothing happens. Debug screenshot

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

Building is OK. It's just the debug problem.
MinGW has been added to PATH. I can use g++ or gdb in CMD.

我的环境:

  • 操作系统: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:

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:

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

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"
    }
}

推荐答案

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

I found out this is an encoding problem, and I solved it myself.

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

First, try gdb logging to find out whether you are having the same problem.
Enable "logging": { "engineLogging": true } and if you see something like

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

那你也有同样的问题.

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

To fix it, you need to disable Unicode UTF-8 for worldwide language support which is a beta feature since Windows10 1803 and is disabled by default.
It is at Control Panel - Clock and Region - Region - Administrative - Change system locate (administrator authorization required) - Beta: Use Unicode UTF-8 for worldwide language support (system reboot needed).

转到为什么vscode在开始使用gdb.exe调试时会卡在那里? 在 GitHub 上了解更多详细信息.

Go to why vscode just hang in there when start debugging with gdb.exe? at GitHub for more details.

这篇关于无法使用 gdb 在 VS 代码中调试 C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆