debugging 如何在Visual Studio代码中调试C++代码

6fe3ivhb  于 2022-11-30  发布在  其他
关注(0)|答案(2)|浏览(194)

任何人使用Visual Studio代码在C中编程吗?请告诉我,当我使用g编译器编译Visual Studio代码时,我如何管理在Visual Studio代码中调试我的代码。

yqlxgs2m

yqlxgs2m1#

C调试需要几个步骤来为它配置VSCode。一旦完成,C代码就可以很容易地用F5进行调试。
我写了一篇指导如何在VSCode中运行和调试C/C++文件的文章。
https://medium.com/@jerrygoyal/run-debug-intellisense-c-c-in-vscode-within-5-minutes-3ed956e059d6

fbcarpbf

fbcarpbf2#

用于调试项目目录中的多个cpp文件。
您的launch.json和task.json应该如下所示

tasks.json


{
        "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": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Task generated by Debugger."
    }

launch.json

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

相关问题