【问题标题】:Simple GDB C++ debugging on VS Code fails with a NullReferenceExceptionVS Code 上的简单 GDB C++ 调试失败并出现 NullReferenceException
【发布时间】:2018-12-25 10:20:07
【问题描述】:

我的来源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 位。

【问题讨论】:

    标签: c++ visual-studio-code vscode-debugger


    【解决方案1】:

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

    这个问题是 15 天前的 reported on Microsoft/vscode-cpptools,从 v1.30.0 开始出现,应该在最新的 Insiders 版本中修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-04
      • 1970-01-01
      • 2019-07-17
      • 2016-12-29
      • 2020-08-25
      • 2018-07-22
      • 2011-01-14
      • 1970-01-01
      相关资源
      最近更新 更多