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

Viewed 3540

My source file.cpp:

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

I compile it using g++ -g file.cpp, and then my launch.json file is like so:

{
    "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
                }
            ]
        }
    ]
}

My directory structure is:

- workspaceFolder
  - .vscode
    - launch.json
  - a.out
  - file.cpp

When I click the green "Start debugging" arrow in the Debug tab I get this error in the Debug Console:

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

What am I doing wrong? I have looked at every tutorial and debugging C++ seems to be working for all of them except in my case. I also have the C/C++ (Microsoft) extension installed, and am running Ubuntu 64-bit.

1 Answers

I had the same problem, not sure why, but setting "externalConsole" in launch.json to false did the trick for me.

This issue was reported on Microsoft/vscode-cpptools 15 days ago, has been occurring since v1.30.0, and is supposed to be fixed in the latest insiders build.

Related