如何在 Visual Studio Code 中为 C++ 启用漂亮打印?

2024-02-25

我正在尝试使用 MinGW GDB python 调试器在 Visual Studio Code 中启用 C++ 的漂亮打印。

我按照描述的步骤操作here https://stackoverflow.com/questions/4985414/how-to-enable-gdb-pretty-printing-for-c-stl-objects-in-eclipse-cdt在下面“这是针对使用 Eclipse CDT 的 MinGW 用户”标题,但是当我尝试启动调试器时"externalConsole": true我在调试控制台中得到以下日志输出:

1: (189) LaunchOptions{"name":"g++.exe - Build and debug active file","type":"cppdbg","request":"launch","program":"c:\\Users\\Ben Wilson\\Documents\\Scripts\\CodingChallenges\\movie.exe","args":[],"stopAtEntry":false,"cwd":"C:\\Users\\Ben Wilson\\Documents\\Scripts\\CodingChallenges","environment":[],"externalConsole":true,"MIMode":"gdb","miDebuggerPath":"C:\\MinGW\\bin\\gdb-python27.exe","setupCommands":[{"description":"Enable pretty-printing for gdb","text":"-enable-pretty-printing","ignoreFailures":true}],"preLaunchTask":"C/C++: g++.exe build active file","logging":{"engineLogging":true},"__configurationTarget":5,"__sessionId":"c62bc9d3-8c55-4dfb-b413-c91d22f3232e"}
1: (315) Starting: "C:\MinGW\bin\gdb-python27.exe" --interpreter=mi -x "C:\Users\Ben Wilson\Documents\Scripts\CodingChallenges\.gdbinit"
1: (328) DebuggerPid=11376
1: (391) "C:\MinGW\bin\gdb-python27.exe" exited with code -1073741515 (0xC0000135).
Starting: "C:\MinGW\bin\gdb-python27.exe" --interpreter=mi -x "C:\Users\Ben Wilson\Documents\Scripts\CodingChallenges\.gdbinit"
"C:\MinGW\bin\gdb-python27.exe" exited with code -1073741515 (0xC0000135).

1: (407) Send Event AD7MessageEvent
1: (408) <-logout

我尝试设置"externalConsole": false,我将以下输出发送到调试控制台:

1: (123) LaunchOptions{"name":"g++.exe - Build and debug active file","type":"cppdbg","request":"launch","program":"c:\\Users\\Ben Wilson\\Documents\\Scripts\\CodingChallenges\\movie.exe","args":[],"stopAtEntry":false,"cwd":"C:\\Users\\Ben Wilson\\Documents\\Scripts\\CodingChallenges","environment":[],"externalConsole":false,"MIMode":"gdb","miDebuggerPath":"C:\\MinGW\\bin\\gdb-python27.exe","setupCommands":[{"description":"Enable pretty-printing for gdb","text":"-enable-pretty-printing","ignoreFailures":true}],"preLaunchTask":"C/C++: g++.exe build active file","logging":{"engineLogging":true},"__configurationTarget":5,"__sessionId":"cfbd8955-0807-495d-8bfa-e06052797523"}
1: (225) Wait for connection completion.

启动.json

{
    // 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 - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb-python27.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file",
            "logging": { "engineLogging": true }
        }
    ]
}

任务.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:\\MinGW\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

另外,单独运行 gdb-python27 可执行文件似乎没有做任何事情(不确定这是否是预期的行为)

C:\Users\Ben Wilson\Documents\Scripts\CodingChallenges>C:\MinGW\bin\gdb-python27.exe

C:\Users\Ben Wilson\Documents\Scripts\CodingChallenges>

有人以前经历过这种情况或者知道在这里该怎么做吗?


Solution

已修复问题:

  1. 从此卸载 mingw 并安装 mingw64link https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download
  2. 修改miDebuggerPath in launch.json and command and cwd in tasks.json匹配新文件位置
  3. 将新的 mingw64 bin 位置添加到 PATH
  4. 修改includePath and compilerPath in c_cpp_properties.json匹配新文件位置
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Visual Studio Code 中为 C++ 启用漂亮打印? 的相关文章

随机推荐