如何在VSCode上使用MSYS2(MSYS64)gdb.exe调试C ++? [英] How to debug C++ with MSYS2 (MSYS64) gdb.exe on VSCode?

查看:112
本文介绍了如何在VSCode上使用MSYS2(MSYS64)gdb.exe调试C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使C ++(GDB)调试器正常工作.到目前为止,我已经安装了扩展程序:

I can't get the C++ (GDB) debugger to work. So far, I'd instaled the extensions:

MSYS2已经在Windows PATH中,我可以使用以下命令从PowerShell中调用gdb.exe:

MSYS2 is already in Windows PATH, and I can call gdb.exe from PowerShell with:

Start("gdb.exe")

第一次尝试时,我收到一条消息,提示 crtexe.c 不存在.我选择创建它的选项.文件路径在 C:\ repo \ mingw-w64-crt-git \ src \ mingw-w64 \ mingw-w64-crt \ crt \ crtexe.c 上,我已经从此

By the first time I tried, I got a message that the crtexe.c didn't exists. I choose the option to create it. The file path is on C:\repo\mingw-w64-crt-git\src\mingw-w64\mingw-w64-crt\crt\crtexe.c and I've copied its contents from this source.

程序可以正常编译.并且,当按 F5 时,调试器跳到 crtexe.c 并在几个 F11 步骤后停止.我真的被困在这一点上,任何帮助的确会超过您的赞赏!

The programs is compiling fine. And, when pressing F5, the debugger jumps to crtexe.c and stops after few F11 steps. I'm really stuck at this point and any help will be, indeed, more than appreciated !

这是我的 c_cpp_properties.json :

{
    "configurations": [{
            "name": "Mac",
            "includePath": [
                "/usr/include",
                "/usr/local/include",
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "Linux",
            "includePath": [
                "/usr/include",
                "/usr/local/include",
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "Win32",
            "includePath": [
                "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include",
                "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include-fixed",
                "C:/msys64/mingw64/include/c++/7.1.0/x86_64-w64-mingw32",
                "C:/msys64/mingw64/x86_64-w64-mingw32/include",
                "C:/msys64/mingw64/x86_64-w64-mingw32/include/wrl",
                "C:/msys64/mingw64/include/c++/7.1.0/tr1",
                "C:/msys64/mingw64/include/c++/7.1.0/backward",
                "C:/msys64/mingw64/include/c++/7.1.0",
                "C:/msys64/mingw64/include",
                "${workspaceRoot}"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=7.1.0",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include",
                    "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include-fixed",
                    "C:/msys64/mingw64/include/c++/7.1.0/x86_64-w64-mingw32",
                    "C:/msys64/mingw64/x86_64-w64-mingw32/include",
                    "C:/msys64/mingw64/x86_64-w64-mingw32/include/wrl",
                    "C:/msys64/mingw64/include/c++/7.1.0/tr1",
                    "C:/msys64/mingw64/include/c++/7.1.0/backward",
                    "C:/msys64/mingw64/include/c++/7.1.0",
                    "C:/msys64/mingw64/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 2
}

而且,我的 launch.json 是这样的:

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

推荐答案

仅仅是编辑工作区 settings.json 的问题,如下所示.这样,通过 -g 选项,编译器会在程序上插入调试符号,并且调试器可以正常工作.

Was just a question of edit the workspace settings.json like follows. That way, with the -goption, the compiler inserts debug symbols on the program and the debugger works fine.

{
    "code-runner.executorMap": {
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -g && $dir$fileNameWithoutExt"
    }
}

问题显然已经解决!

这篇关于如何在VSCode上使用MSYS2(MSYS64)gdb.exe调试C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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