My Blog List

How to debug the STL containers



Because the STL Containers are not basic data types such as int or array thus sometimes hard to directly display the value of a container such as vector in debug.

Here is a simple way rather then  using static debug. We can add the display statement in source code rather then invoking them in the program, we can call the at gdb when debug. Write an auxiliary that can display the property of variable what you want, and call that function in runtime of gdb. Note that the output stream should be cerr.

This is the source code in which you can see the function gdb_display is used to show the vector data when debug. Here is how to call it in gdb


According to the different vector passed into gdb_display, different vector shows.


No comments:

Post a Comment

Enter you comment