This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Searching STL containers
- From: jimparker at mail dot utexas dot edu
- To: gdb at sources dot redhat dot com
- Cc: gilad at science dot uva dot nl
- Date: Wed, 21 Sep 2005 22:38:21 -0500
- Subject: Searching STL containers
I am looking for a method to examine the contents of STL containers using gdb.
and I hit upon a site hosted by Gilad Mishne
http://staff.science.uva.nl/~gilad/stl/stl_gdb.html
and found a related thread on this forum
http://sourceware.org/ml/gdb/2004-05/msg00179.html
Adapting from these two posts I generated the following definition
define plist
set $next = $arg0->_M_node._M_next
#This is stupid _prev._next... but I can't get it to find the
# end otherwise...
set $end = $arg0->_M_node._M_prev._M_next
set $listp = {&$arg0._M_node}
while ($next != $end)
# the assignment to ._M_prev is a hack that works...
# otherwise, I am one node off
set (void*)*$listp = $next._M_prev
p (*$listp)._M_data
set $next = $next->_M_next
end
end
that is a quick hack. I would appreciate if someone would explain/correct the
above pointer references to make it cleaner. But I present it as is, since it
works for my purposes, and perhaps will be useful to others. This is very
similar to the
C++ journal article mentioned, but I explicitly defined setbegin, setend,
and the pointer assignment.
Gilad,
On your site you type cast the $listp as (_List_node*) which doesn't seem to
work for me. In my STL library (g++) the typename _List_node is templated and
therefore requires the node class name and the std:: scope. i.e.
('std::_List_node<int>')
For reference, I'm using
gcc 3.3.1 -gdwarf-2
gdb 6.3.50
Cheers,
Jim