GDB's custom commands are very useful, by customizing the commands to directly manipulate the data in the container, you can easily view the data in the STL container.
This link dbinit_stl_views is a custom command written by Dan C Marinescu to view the STL container (if it is not for your STL version, you can modify it yourself). Add it to your. Gdbinit, you can easily view the STL container. It provides a way to view objects such as vector,list,map,multimap,set,multiset,deque,stack,queue,priority_queue,bitset,string,widestring, Very easy to use.
1. Download Http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt 2. #cat dbinit_stl_views-1.03.txt >> ~/.gdbinit 3. If you are in GDB, run the command: (GDB) source ~/.gdbinit 4. For example, the following code: Bugging.cpp
[CPP] View plain copy #include <vector> using namespace std; int main () {vector<int> VEC; Vec.push_back (2); Vec.push_back (3); Vec.push_back (4); return 0; }
Compile:
[CPP] View plain copy #g + +-o bugging-g bugging.cpp gdb debugging:.
[cpp] View Plain copy # gdb bugging gnu gdb 6.8 Copyright (C) 2008 Free Software Foundation, Inc. license gplv3+: gnu gpl version 3 or later