I note that debugging C++ in Visual Studio Code (VSCode) is quite uncomfortable, especially respect to other IDE, like Visual Studio. Consider the following example: to access to the content of a std::vector. On Visual Studio, the content is easily accessible. On the other hand, on VSCode it is possible to see exactly all the information related to that std::vector, like the address of the internal pointer. However, to see the content of the std::vector is cumbersome. For this reason, I am looking for something that can improve the visualization using this IDE, like an extension or an add-on. Note: consider std::vector myVec = {1, 2, 3}; . With content I mean: 1, 2, 3. Note: I am using VSCode latest version, both on Win and Linux with GCC compiler. Version 13.1. Note: I am using GDB 14.2 on both environment. Note: Assume C++17. Note: Extension installed the C/C++ Extension Pack from Microsoft.
Assistant
Debugging C++ can indeed be challenging in VSCode compared to fully-fledged IDEs like Visual Studio. The issue you're encountering with viewing std::vector content in the debugger can be quite common. Here are some steps and potential solutions to improve your debugging experience in VSCode:
Install the Microsoft C++ Extension Pack
You've already done this, but for completeness:
Install the C++ Extension Pack from Microsoft, which includes the C/C++ plugin for IntelliSense, debugging, and code browsing.
Configure GDB Pretty Printers
GDB pretty printers can format the output of complex stl types like std::vector, std::map, etc., making them more readable in the debugger. You need to set up pretty printers to improve visual representation.
Clone the Pretty Printer Repository: If it's not already bundled with GDB, you can get it from here.
sh
git clone https://github.com/gcc-mirror/gcc.git
Set Up GDB to Use Pretty Printers: Add the following lines to your launch.json configuration in your VSCode workspace to force GDB to locate the pretty-printers.
Make sure to replace /path_to_your_repo with the actual path to the directory where you cloned the repository.
Debug Adapter Protocol (DAP) Enhancements
The VSCode C/C++ extension integrates with the Debug Adapter Protocol (DAP) for more robust debugging features. Always ensure you have the latest version of the C/C++ extension as it receives frequent updates:
Open the Extensions view by clicking on the Extensions icon in the Activity Bar.
Update the installed C/C++ extension from Microsoft to the latest version.
Updating Configuration Files
Ensure launch.json and other configuration files in your .vscode directory have optimal settings. Adding pretty-printing and proper GDB settings can help:
If the visual debugging experience does not improve with GDB, you might consider using lldb (LLVM debugger) as an alternative to GDB. LLDB generally provides good pretty-printing support for STL containers. Follow similar steps to configure it in launch.json and ensure pretty-printers are enabled:
By enabling GDB's or LLDB's pretty printers and ensuring your launch.json is correctly set up, you should experience improved visualization of STL containers like std::vector when debugging in VSCode. Keep your extensions updated and explore additional customization options within launch.json to tailor the debugging experience to your needs.