c++ - 使用 C++(windows) 在 VS 代码中调试 C++ 时出错

标签 c++ debugging visual-studio-code

<分区>

有人在Windows 10 平台上使用GCC 编译器使用VS code 调试C++ 吗?我收到一些 PDB 文件丢失或无法从 System32 目录打开之类的错误。当我开始调试时,程序正在执行而没有命中断点。那么我应该如何处理这些 PDB 错误,因为我无法对这些错误使用调试功能。

最佳答案

下面是我的 launch.json 和 task.json。 确保在您的项目文件夹中有一个 build 文件夹 启动.json

{
   "version": "0.2.0",
   "configurations": [
       {
           "name": "C++ Launch (GDB)",                
           "type": "cppdbg",                         
           "request": "launch",                        
           "targetArchitecture": "x86",                
           "program": "${workspaceRoot}\\build\\${fileBasename}.exe",                 
           "miDebuggerPath":"C:\\mingw-w64\\bin\\gdb.exe", 
           "args": [],     
           "stopAtEntry": false,                  
           "cwd": "${workspaceRoot}",                  
           "externalConsole": true,                  
           "preLaunchTask": "g++"                    
           }
   ]
}

任务.json

{
   "version": "0.1.0",
   "command": "g++",
   "args": ["-g","-std=c++11","${file}","-o","${workspaceRoot}\\build\\${fileBasename}.exe"],
   "problemMatcher": {
       "owner": "cpp",
       "fileLocation": ["relative", "${workspaceRoot}"],
       "pattern": {
           "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
           "file": 1,
           "line": 2,
           "column": 3,
           "severity": 4,
           "message": 5
       }
   }
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/usr/include"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "/usr/include",
                    "${workspaceRoot}"
                ]
            },
            "intelliSenseMode": "clang-x64"
        },
        {
            "name": "Linux",
            "includePath": [
                "/usr/include"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "/usr/include",
                    "${workspaceRoot}"
                ]
            },
            "intelliSenseMode": "clang-x64"
        },
        {
            "name": "Win32",
            "includePath": [
                "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/include"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/include",
                    "${workspaceRoot}"
                ]
            },
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 2
}

文件夹

enter image description here

关于c++ - 使用 C++(windows) 在 VS 代码中调试 C++ 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46089042/

相关文章:

c++ - Cygwin Make bash 命令未找到

jquery - 当 jQuery 处理程序中抛出异常时,调用堆栈会丢失

c - gdb运行程序问题

debugging - 使用 vscode 调试 electron。运行时可执行文件

android - 安装 build/app/outputs/flutter-apk/app.apk... 在 flutter 运行后丢失/没有发生。设备上未保存任何应用

visual-studio-code - 删除 VS Code 编辑器 View 中心的垂直线

c++ - 如何在WinAPI应用程序中集成OpenGL和GLU?

C++。 Child 继承自 Parent 并作为 Parent 属性包含在内

c++ - fgets() 似乎没有正确移动文件指针

angular - 在停止调试时终止 vs 代码中的 ng serve 任务