VS Code 上的简单 GDB C++调试失败,并显示 NullReferenceException

Simple GDB C++ debugging on VS Code fails with a NullReferenceException

本文关键字:失败 显示 NullReferenceException 调试 C++ Code 简单 GDB VS      更新时间:2023-10-16

我的源代码file.cpp

#include <iostream>
using namespace std;
int main()
{
    int x = 1;
    int y = 2;
    cout << x + y << endl;
    return 0;
}

我使用 g++ -g file.cpp 编译它,然后我的launch.json文件是这样的:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

我的目录结构是:

- workspaceFolder
  - .vscode
    - launch.json
  - a.out
  - file.cpp
当我单击"调试"

选项卡中的绿色"开始调试"箭头时,我在调试控制台中收到此错误:

Stopping due to fatal error: NullReferenceException: Object reference not set to an instance of an object

我做错了什么? 我已经查看了每个教程和调试C++似乎适用于所有教程和调试,除了我的情况。我还安装了C/C++(Microsoft)扩展,并且正在运行Ubuntu 64位。

我遇到了同样的问题,不知道为什么,但是在launch.json中设置"externalConsole"false对我来说是有好处的。

此问题已在 15 天前在 Microsoft/vscode-cpptools 上报告,自 v1.30.0 以来一直存在,并且应该在最新的内部版本中修复。