How GDB prints the STL variables in the program

Source: Internet
Author: User

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 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.