GDB supports C + + STL debugging

Source: Internet
Author: User
Tags bitset print object

Http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt

Save the text of a Web page to ~/.gdbinit

You can then use the P command to view the contents of the STL container.

# # STL GDB Evalu ators/views/utilities-1.03## the new GDB commands: # is E  ntirely Non Instrumental # Do no depend on any "inline" (s)-e.g. size (),                                                                                 [], etc# is extremely tolerant to debugger settings# # This file should is "included" in. Gdbinit as following:# source stl-views.gdb or just paste it I Nto your gdbinit file## The following STL containers is currently supported:## std::vector<t>-via Pvect or command# std::list<t>--via plist or Plist_member command# std::map<t,t>-via Pmap or pmap_m Ember command# std::multimap<t,t>-via pmap or Pmap_member command# std::set<t>-via PSet comm and# Std::multiset<T>-Via PSet command# std::d eque<t>-Via Pdequeue command# std::stack<t>-Via Pstack       command# std::queue<t>-Via Pqueue command# std::p riority_queue<t>-Via Ppqueue command# Std::bitset<n>-Via Pbitset command# std::string-via pstring command# std::widestring-Via Pwstr ing command## the end of this file contains (optional) C + + beautifiers# Make sure your debugger supports $ARGC # # Sim ple GDB Macros writen by Dan Marinescu (H-PHD)-License gpl# Inspired by intial work of Tom Malnar, # Tony Novac (P HD)/cornell/stanford,# Gilad Mishne (PhD) and many many others.# contact: [email protected] (SUBJECT:STL) # # Modified to work with g++ 4.3 by Anders elton# Also added _member functions, that instead of printing the entire CLA SS in map, prints a member.## std::vector<> #define PVECTORIF $ARGC = = 0help Pvectorelseset $size = $arg 0._m_impl._m_ finish-$arg 0._m_impl._M_startset $capacity = $arg 0._m_impl._m_end_of_storage-$arg 0._m_impl._m_startset $size _max = $size -1endif $ARGC = = 1se T $i = 0while $i < $sizeprintf "elem[%u]:", $ip * ($arg 0._m_impl._m_start + $i) set $i ++endendif $ARGC = = 2set $idx = $a Rg1if $idx < 0 | | $idx > $size _maxprintf "idx1, IDX2 is not in acceptable range: [0..%u].\n], $size _maxelseprintf" elem[%u]: ", $IDXP * ( $arg 0._m_impl._m_start + $idx) endendif $ARGC = = 3 Set $start _idx = $arg 1 set $stop _idx = $arg 2 if $start _idx > $stop  _idx set $tmp _idx = $start _idx set $start _idx = $stop _idx set $stop _idx = $tmp _idx End If $start _idx < 0 | | $stop _idx < 0 | | $start _idx > $size _max | | $stop _idx > $size _max printf "idx1, idx2 is not in acceptable range: [0..%u].\n", $size _max Else set $i = $star T_idxwhile $i <= $stop _idxprintf "elem[%u]:", $ip * ($arg 0._m_impl._m_start + $i) set $i ++end endendif $argc > 0prin tf "Vector size =%u\n", $sizeprintf "vector capacity =%u\n", $capacityprinTF "Element" Whatis $arg 0._m_impl._m_startendenddocument pvectorprints std::vector<t> information. Syntax:pvector <vector> <idx1> <idx2>note:idx, idx1 and idx2 must is in acceptable range [0..<vecto R>.size ()-1]. Examples:pvector v-prints vector content, size, capacity and T Typedefpvector v 0-prints element[idx] from Vectorpvect or V 1 2-prints elements in range [idx1.  IDX2] from Vectorend # # std::list<> #define PLISTIF $ARGC = = 0help Plistelseset $head = & $arg 0._m_impl._m_nodeset $current = $arg 0._m_impl._m_node._m_nextset $size = 0while $current! = $headif $ARGC = = 2printf "elem[%u]:", $sizep * ($a rg1*) ($current + 1) endif $ARGC = = 3if $size = = $arg 2printf "elem[%u]:", $sizep * ($arg 1*) ($current + 1) endendset $current = $current. _m_nextset $size ++endprintf "list size =%u \ n", $sizeif $ARGC = = 1printf "List" Whatis $arg 0printf "Use plist <variable_name> <element_type> to see the elements in the list.\n "Endendenddocument PlistprinTS std::list<t> information. Syntax:plist <list> <T> <idx>: Prints list size, if T defined all elements or just element at Idxexampl Es:plist l-prints list size and definitionplist l int-prints all elements and list sizeplist L int 2-prints the Thir d element in the list (if exists) and list sizeenddefine Plist_memberif $ARGC = = 0help Plist_memberelseset $head = & $a Rg0._m_impl._m_nodeset $current = $arg 0._m_impl._m_node._m_nextset $size = 0while $current! = $headif $ARGC = = 3printf "El Em[%u]: ", $sizep (* ($arg 1*) ($current + 1)). $arg 2endif $ARGC = = 4if $size = = $arg 3printf" elem[%u]: ", $sizep (* ($arg 1*) ($  Current + 1). $arg 2endendset $current = $current. _m_nextset $size ++endprintf "List size =%u \ n", $sizeif $argc = = 1printf  "List" Whatis $arg 0printf "use Plist_member <variable_name> <element_type> <member> to see the elements In the list.\n "Endendenddocument plist_memberprints std::list<t> information. Syntax:plist <list> &Lt T> <idx>: Prints list size, if T defined all elements or just element at Idxexamples:plist_member L INT member- Prints all elements and list sizeplist_member L INT member 2-prints The third element in the list (if exists) and list s izeend## Std::map and std::multimap#define pmapif $ARGC = = 0help Pmapelseset $tree = $arg 0set $i = 0set $node = $tree. _m_t . _m_impl._m_header._m_leftset $end = $tree. _m_t._m_impl._m_headerset $tree _size = $tree. _m_t._m_impl._m_node_countif $ARGC = = 1printf "Map" Whatis $treeprintf "use Pmap <variable_name> <left_element_type> <right_element_ Type> to see the elements in the map.\n "endif $ARGC = = 3while $i < $tree _sizeset $value = (void *) ($node + 1) printf "Elem[%u].left:", $ip * ($arg 1*) $valueset $value = $value + sizeof ($arg 1) printf "elem[%u].right:", $ip * ($arg) $valueif $node. _m_right! = 0set $node = $node. _m_rightwhile $node. _m_left! = 0set $node = $node. _m_leftendelseset $tmp _node = $node . _m_parentwhile $node = = $tmp _Node._m_rightset $node = $tmp _nodeset $tmp _node = $tmp _node._m_parentendif $node. _m_right! = $tmp _nodeset $node = $tmp _nod Eendendset $i ++endendif $ARGC = = 4set $idx = $arg 3set $ElementsFound = 0while $i < $tree _sizeset $value = (void *) ($nod E + 1) if * ($arg 1*) $value = = $idxprintf "Elem[%u].left:", $ip * ($arg 1*) $valueset $value = $value + sizeof ($arg 1) printf "El Em[%u].right: ", $ip * ($arg) $valueset $ElementsFound ++endif $node. _m_right! = 0set $node = $node. _m_rightwhile $node. _m _left! = 0set $node = $node. _m_leftendelseset $tmp _node = $node. _m_parentwhile $node = = $tmp _node._m_rightset $node = $tmp _nodeset $tmp _node = $tmp _node._m_parentendif $node. _m_right! = $tmp _nodeset $node = $tmp _nodeendendset $i ++endprintf "Nu Mber of elements found =%u\n ", $ElementsFoundendif $argc = = 5set $idx 1 = $arg 3set $idx 2 = $arg 4set $ElementsFound = 0whil E $i < $tree _sizeset $value = (void *) ($node + 1) Set $valueLeft = * ($arg 1*) $valueset $valueRight = * ($arg) ($value + s) Izeof ($arg 1)) if $valueLeft = = $idx 1 && $valueRight = = $idx 2printf "elem[%u].left:", $ip $valueLeftprintf "Elem[%u].right:", $ip $valueRigh Tset $ElementsFound ++endif $node. _m_right! = 0set $node = $node. _m_rightwhile $node. _m_left! = 0set $node = $node. _m_lefte Ndelseset $tmp _node = $node. _m_parentwhile $node = = $tmp _node._m_rightset $node = $tmp _nodeset $tmp _node = $tmp _node._m_pa Rentendif $node. _m_right! = $tmp _nodeset $node = $tmp _nodeendendset $i ++endprintf "number of elements found =%u\n", $Elem entsfoundendprintf "Map size =%u\n", $tree _sizeendenddocument pmapprints std::map<tleft and tright> or Std::multim Ap<tleft and tright> information. Works for Std::multimap as well. Syntax:pmap <map> <TtypeLeft> <TypeRight> <valLeft> <valright>: Prints map size, if T defin Ed all elements or just element (s) with Val (s) examples:pmap m-prints map size and definitionpmap m int int-prints all Elements and map sizepmap m int int 20-prints the element (s) with Left-vaLue = (if any) and map sizepmap m int int. 200-prints the element (s) with left-value = + Right-value = Any) and map sizeenddefine pmap_memberif $ARGC = = 0help Pmap_memberelseset $tree = $arg 0set $i = 0set $node = $tree. _m_t. _m_impl._m_header._m_leftset $end = $tree. _m_t._m_impl._m_headerset $tree _size = $tree. _m_t._m_impl._m_node_countif $ ARGC = = 1printf "Map" Whatis $treeprintf "use Pmap <variable_name> <left_element_type> <right_element_ Type> to see the elements in the map.\n "endif $ARGC = = 5while $i < $tree _sizeset $value = (void *) ($node + 1) printf "Elem[%u].left:", $ip (* ($arg 1*) $value). $arg 2set $value = $value + sizeof ($arg 1) printf "elem[%u].right:", $ip (* ($arg) $value). $arg 4if $node. _m_right! = 0set $node = $node. _m_rightwhile $node. _m_left! = 0set $node = $node. _m_leftendelseset $ Tmp_node = $node. _m_parentwhile $node = = $tmp _node._m_rightset $node = $tmp _nodeset $tmp _node = $tmp _node._m_parentendif $ Node._m_right! = $tmp _nodeset $nodE = $tmp _nodeendendset $i ++endendif $argc = = 6set $idx = $arg 5set $ElementsFound = 0while $i < $tree _sizeset $value = ( void *) ($node + 1) if * ($arg 1*) $value = = $idxprintf "Elem[%u].left:", $ip (* ($arg 1*) $value). $arg 2set $value = $value + siz EOF ($arg 1) printf "elem[%u].right:", $ip (* ($arg) $value). $arg 4set $ElementsFound ++endif $node. _m_right! = 0set $node = $node. _m_rightwhile $node. _m_left = 0set $node = $node. _m_leftendelseset $tmp _node = $node. _m_parentwhile $node = = $tmp _n Ode._m_rightset $node = $tmp _nodeset $tmp _node = $tmp _node._m_parentendif $node. _m_right! = $tmp _nodeset $node = $tmp _node Endendset $i ++endprintf "number of elements found =%u\n", $ElementsFoundendprintf "Map size =%u\n", $tree _SIZEENDENDDOCU ment pmap_memberprints std::map<tleft and tright> or Std::multimap<tleft and tright> information. Works for Std::multimap as well. Syntax:pmap <map> <TtypeLeft> <TypeRight> <valLeft> <valright>: Prints map size, if T defin Ed AlL elements or just element (s) with Val (s) examples:pmap_member m Class1 member1 class2 member2-prints class1.member1:cl Ass2.member2pmap_member m Class1 member1 class2 member2 lvalue-prints class1.member1:class2.member2 where Class1 = = LV alueend## Std::set and std::multiset#define psetif $ARGC = = 0help Psetelseset $tree = $arg 0set $i = 0set $node = $tree. _m_ T._m_impl._m_header._m_leftset $end = $tree. _m_t._m_impl._m_headerset $tree _size = $tree. _m_t._m_impl._m_node_  Countif $ARGC = = 1printf "Set" Whatis $treeprintf "use PSet <variable_name> <element_type> to see the elements In the set.\n "endif $ARGC = = 2while $i < $tree _sizeset $value = (void *) ($node + 1) printf" elem[%u]: ", $ip * ($arg 1*) $  Valueif $node. _m_right! = 0set $node = $node. _m_rightwhile $node. _m_left! = 0set $node = $node. _m_leftendelseset $tmp _node = $node. _m_parentwhile $node = = $tmp _node._m_rightset $node = $tmp _nodeset $tmp _node = $tmp _node._m_parentendif $node. _m_ Right! = $tmp _nodeset $node = $tmp _nOdeendendset $i ++endendif $ARGC = = 3set $idx = $arg 2set $ElementsFound = 0while $i < $tree _sizeset $value = (void *) ($n  Ode + 1) If * ($arg 1*) $value = = $idxprintf "elem[%u]:", $ip * ($arg 1*) $valueset $ElementsFound ++endif $node. _m_right! = 0set $node = $node. _m_rightwhile $node. _m_left! = 0set $node = $node. _m_leftendelseset $tmp _node = $node. _m_parentwhile $node = = $tmp _node._m_rightset $node = $tmp _nodeset $tmp _node = $tmp _node._m_parentendif $node. _m_right! = $tmp _nodeset $node = $tmp _nodeendendset $i ++endprintf "number of elements found =%u\n", $ElementsFoundendprintf "Set size =%u\n", $tree _sizee Ndenddocument psetprints std::set<t> or std::multiset<t> information. Works for Std::multiset as well. Syntax:pset <set> <T> <val>: Prints set size, if T defined all elements or just element (s) has Valex  Amples:pset s-prints set size and Definitionpset s int-prints all elements and the size of spset s int 20-prints the Element (s) with value = (ifAny) and the size of send## std::d equeue#define pdequeueif $ARGC = = 0help Pdequeueelseset $size = 0set $start _cur = $arg 0. _m_impl._m_start._m_curset $start _last = $arg 0._m_impl._m_start._m_lastset $start _stop = $start _lastwhile $start _cur! = $start _stopp * $start _curset $start _cur++set $size ++endset $finish _first = $arg 0._m_impl._m_finish._m_firstset $ Finish_cur = $arg 0._m_impl._m_finish._m_curset $finish _last = $arg 0._m_impl._m_finish._m_lastif $finish _cur < $ Finish_lastset $finish _stop = $finish _curelseset $finish _stop = $finish _lastendwhile $finish _first! = $finish _stopp *$ Finish_firstset $finish _first++set $size ++endprintf "Dequeue size =%u\n", $sizeendenddocument pdequeueprints std:: dequeue<t> information. Syntax:pdequeue <dequeue>: Prints dequeue size, if T defined all Elementsdeque elements is listed "left to right" (Left-most stands for front and right-most stands for back) Example:pdequeue d-prints all elements and size of dend## std::stack#define pstackif $arGC = = 0help Pstackelseset $start _cur = $arg 0.c._m_impl._m_start._m_curset $finish _cur = $arg 0.c._m_impl._m_finish._m_            Curset $size = $finish _cur-$start _cur Set $i = $size-1 while $i >= 0 p * ($start _cur + $i) Set $i--endprintf "Stack size =%u\n", $sizeendenddocument pstackprints std::stack<t> Information .  Syntax:pstack <stack>: Prints all elements and size of the Stackstack elements is listed "top to Buttom" (top-most Element is the first to come on pop) Example:pstack s-prints all elements and the size of send## std::queue#define Pqueu EIF $ARGC = = 0help Pqueueelseset $start _cur = $arg 0.c._m_impl._m_start._m_curset $finish _cur = $arg 0.c._m_impl._m_finish            . _m_curset $size = $finish _cur-$start _cur Set $i = 0 while $i < $size p * ($start _cur + $i) Set $i + + endprintf "Queue size =%u\n", $sizeendenddocument pqueueprints std::queue<t> information. Syntax:pqueue <queue>:Prints all elements and the size of the QUEUEQUEUE elements be listed "top to Bottom" (top-most element was the first to C ome on Pop) Example:pqueue q-prints all elements and the size of qend## std::p riority_queue#define ppqueueif $ARGC = = 0he LP Ppqueueelseset $size = $arg 0.c._m_impl._m_finish-$arg 0.c._m_impl._m_startset $capacity = $arg 0.c._m_impl._m_end_of _storage-$arg 0.c._m_impl._m_startset $i = $size -1while $i >= 0p * ($arg 0.c._m_impl._m_start + $i) set $i--endprintf " Priority Queue size =%u\n ", $sizeprintf" priority queue capacity =%u\n ", $capacityendenddocument ppqueueprints std::p Rio rity_queue<t> information. Syntax:ppqueue <priority_queue>: Prints all elements, size and capacity of the priority_queuepriority_queue element S is listed ' top to Buttom ' (top-most element is the first and come on POPs) Example:ppqueue pq-prints all elements, size and capacity of pqend## std::bitset#define pbitsetif $ARGC = = 0help Pbitsetelse p/t $arg 0._m_wendenddocumentPbitsetprints std::bitset<n> information. Syntax:pbitset <bitset>: Prints all bits in Bitsetexample:pbitset b-prints all bits in bend## std::string#define  Pstringif $ARGC = = 0help pstringelseprintf "string \t\t\t= \"%s\ "\ n", $arg 0._m_data () printf "string size/length \t=%u\n", $arg 0._m_rep (). _m_lengthprintf "String capacity \t=%u\n", $arg 0._m_rep (). _m_capacityprintf "string Ref-count \t=%d\n" , $arg 0._m_rep (). _m_refcountendenddocument pstringprints std::string information. Syntax:pstring <string>example:pstring s-prints Content, size/length, capacity and Ref-count of string Send # # St D::wstring#define pwstringif $ARGC = = 0help Pwstringelsecall printf ("Wstring \t\t= \"%ls\ "\ n", $arg 0._m_data ()) printf " WString size/length \t=%u\n ", $arg 0._m_rep (). _m_lengthprintf" WString capacity \t=%u\n ", $arg 0._m_rep (). _m_ capacityprintf "WString ref-count \t=%d\n", $arg 0._m_rep (). _m_refcountendenddocument pwstringprints std::wstring Information. Syntax:pwstring <wstring>Example:pwstring s-prints content, size/length, capacity and ref-count of wstring in C + + related beautifiers (optio NAL) #set Print pretty onset Print object onset print static-members onset print vtbl onset print demangle onset demangle-s Tyle gnu-v3set Print sevenbit-strings off
View Code

GDB supports C + + STL debugging

Related Article

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.