For example with std::vector<std::vector> v(10,vector<int>(5,-1)). When I run the debug with GDB, i can only see the address of the first and last element. When i expand the _M_start_ or _M_finish_, it still show the address, not the value i need to see. How can i see the value of elements in STL or arrays in debug:
You need to set up python pretty printers for C++ in the .gdbinit file.
Have a look here:
https://sourceware.org/gdb/wiki/STLSupport
@philong6297 Also make sure you have the following block in your launch.json to enable pretty printing:
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
For the record, you need both of those, and they can both be wrapped in the setupCommands
Modern OSes like Fedora and Ubuntu include the svn submodule, and you don't need to download them separately. For example, in Ubuntu 18.04
"setupCommands": [
{
"description": "Test",
"text": "python import sys;sys.path.insert(0, '/usr/share/gcc-8/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
}
]
not sure why
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld.out",
"args": ["-arg1", "-arg2"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"customLaunchSetupCommands": [
{
"description": "Test",
"text": "python import sys;sys.path.insert(0, '/Users/mingyeyang/gcc/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
}
],
"logging": {
"trace": true,
"traceResponse": true,
"engineLogging": true
}
}
]
}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (476) STDERR: error: 'logout' is not a valid command.\n"},"seq":44}
1: (476) STDERR: error: 'logout' is not a valid command.
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (477) STDERR: error: Unrecognized command 'logout'.\n"},"seq":46}
1: (477) STDERR: error: Unrecognized command 'logout'.
--> E (output): {"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/Launch","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"14.0.61023.1","VS.Diagnostics.Debugger.HostVersion":"14.0.61023.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Launch.ErrorCode":1005,"VS.Diagnostics.Debugger.Launch.IsError":true}},"seq":48}
--> R (launch-2): {"type":"response","request_seq":2,"success":false,"command":"launch","message":"Unable to start debugging. Specified argument was out of the range of valid values.\nParameter name: options.TargetArchitecture","body":{"error":{"id":1005,"format":"Unable to start debugging. Specified argument was out of the range of valid values.\nParameter name: options.TargetArchitecture"}},"seq":50}
How do I do the same for Windows?
For the record, you need both of those, and they can both be wrapped in the
setupCommandsModern OSes like Fedora and Ubuntu include the svn submodule, and you don't need to download them separately. For example, in Ubuntu 18.04
"setupCommands": [ { "description": "Test", "text": "python import sys;sys.path.insert(0, '/usr/share/gcc-8/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 } ]
Any idea why @andyneff 's suggestion can't be rolled into vscode-cpptools so that it works out of the box? I've been struggling with debugging STL in vscode for a while now, and this suggestion is going to make it a lot easier.
@WardenGnaw can we see if we can get a test matrix with @andyneff's suggestion above and wee where it works and where it doesn't? we would need to at the bare minimum set up Arch, Ubuntu, Centos and WSL1/2
Most helpful comment
For the record, you need both of those, and they can both be wrapped in the
setupCommandsModern OSes like Fedora and Ubuntu include the svn submodule, and you don't need to download them separately. For example, in Ubuntu 18.04