I'm currently using VS Code to learn C++ because it was easy to setup and is much lighter than VS Studio. However, one thing that I'm unable to do is to see the elements of an array (or string, etc), in debug mode.
I've searched for solutions here, and it seems that enabling pretty printing would solve the issue, but unfortunetly it did not (i have Python 3.6 installed). I've also tried using VS Studio compiler and debugger, but was unable to get it to work the way i wanted (basically clicking F5 to compile single cpp files without needing to change any options, just a single click).
Can you guys help me out on this? I'm currently using MinGW compiler on windows 10, with the following tasks file:
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "g++",
"args": [
"-g", "${relativeFile}", "-o", "example"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
and launch:
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/example.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"preLaunchTask": "echo",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
Thank in advance!
Install Visual Studio Code. Install the C/C++ extension for VS Code. You can install the C/C++ extension by searching for 'c++' in the Extensions view (Ctrl+Shift+X). Get the latest version of Mingw-w64 via MSYS2, which provides up-to-date native builds of GCC, Mingw-w64, and other helpful C++ tools and libraries.
For me this works, but check first if you have 'c:\msys64\mingw64\share\gcc-8.3.0\python'
or 'c:\usr\share\gcc-8.3.0\python'
folder and adjust the snippet
launch.json
...
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "python import sys;sys.path.insert(0, 'c:\\msys64\\mingw64\\share\\gcc-8.3.0\\python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)",
"ignoreFailures": false
},
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
...
I used the method just like Georgy described above.
*((int(*)[10])array._M_impl._M_start)
Debug console output:
-exec p array
$7 = {<std::_Vector_base<int, std::allocator<int> >> = {_M_impl = {<std::allocator<int>> = {<__gnu_cxx::new_allocator<int>> = {<No data fields>}, <No data fields>}, _M_start = 0x2924cb0, _M_finish = 0x2924cd8, _M_end_of_storage = 0x2924cf0}}, <No data fields>}
-exec p *((int(*)[10])array._M_impl._M_start)
$8 = {41, 18467, 6334, 26500, 19169, 15724, 11478, 29358, 26962, 24464}
I also faced a similar problem using MinGW
for Windows.
Problem was resolved for me when I removed MINGW
and installed mingw-w64 instead.
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