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.
Debugger not working Look at the debugger console for any error messages displayed. Look at the Debugger Tools console output for any errors. Remember to re-start VS Code once done (this won't be necessary in a future release). Solution: Clear all expressions from the debugger Watch window and start debugging again.
Example launch. Click and select C/C++ : (gdb) Attach option. To start debugging with VSCode, select the process name for your vehicle's binary : example arducopter . Before or after attaching you may put breakpoints in the code to start debugging.
Visual Studio Code supports the following debuggers for C/C++ depending on the operating system you are using: Linux: GDB. macOS: LLDB or GDB. Windows: the Visual Studio Windows Debugger or GDB (using Cygwin or MinGW)
Breakpoints. Breakpoints can be toggled by clicking on the editor margin or using F9 on the current line. Finer breakpoint control (enable/disable/reapply) can be done in the Run and Debug view's BREAKPOINTS section.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With