Type: Debugger
Describe the bug
launch.json
{
"version": "0.2.0",
"configurations":
[
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "C++ Launch (GDB)",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x86",
"program": "${workspaceRoot}\\C++\\${fileBasenameNoExtension}.exe",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"externalConsole": true,
"preLaunchTask": "MyBuild",
"setupCommands":
[
{
"text": "-enable-pretty-printing",
"description": "enable pretty printing",
"ignoreFailures": true
}
]
},
{
"name": "Build and debug",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true, //set to true to see output in cmd instead
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands":
[
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file",
"logging": { "engineLogging": true, "trace": true, "traceResponse": true }
},
{
"name": "Build and run",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true, //set to true to see output in cmd instead
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands":
[
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build & run active file"
}
]
}
Steps to reproduce the behavior:
expand the variable names in the "locals" window
Note, pretty printing doesn't work with any of the above debug configurations for C++
this is what I'm seeing while debugging
Does the GDB you are using have python installed?
You can check by running -exec python print sys.version in the debug console.
It told me Python scripting is not supported for this copy of GDB, but I'm confused, why do I need python to debug c++ code? The guide I followed didn't mention anything about python. Can you elaborate please? and can you provide me with a python supported GDB?
GDB utilizes python in order to pretty print variables.
You will need to use a GDB with python enabled.
Did you obtain MinGW from this documentation?
Hello, I have the same problem but my GDB has python enabled and yes I installed MinGW from this tutorial.
I had the exact same problem. After hours of searching for answer I re-downloaded _mingw-w64_ from sourceforge, and IT FINALLY WORKED...
I installed mingw from the online installer via sourceforge and I can get a version response now:
-exec python print sys.version
2.7.9 (default, May 12 2018, 10:00:46)
[GCC 8.1.0]
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
GNU gdb (GDB) 8.1
But C++ objects are still displayed as {...}
DataPacket d;
In the debugger, I tried to print 'd':
-exec print d
$1 = {Id = 192 '�'Python Exception <type 'exceptions.ValueError'> Cannot find type std::__cxx11::list<unsigned char, std::allocator<unsigned char> >::_Node:
, PacketData = empty std::__cxx11::list, Index = 0 '\000', Length = 0, segment = pHeader0, VoltageData = {voltage = 0, {byte1 = 0 '\000', byte0 = 0 '\000'}}}
std::__cxx11::list -- listed in the installed gdb printers.
Today, a class will show up once, starting debug a second time -- the class is no longer available. Restarting the IDE it reacts the same way.
Version: 1.49.0-insider (user setup)
Commit: 8c9b4015feb0297d99c8051c35e85d208ffe83e3
Date: 2020-09-03T06:00:27.719Z
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Windows_NT x64 10.0.19041
As @RashimNarayanTiku said, change MinGW to MinGW-w64 (from online installer) and now it's working.
Looks like old school MinGW (32 bits) is not good for VSCode and 64 bits environments.
Most helpful comment
Hello, I have the same problem but my GDB has python enabled and yes I installed MinGW from this tutorial.