[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to inspect and debug STL containers?
From: |
foxx |
Subject: |
Re: How to inspect and debug STL containers? |
Date: |
19 Apr 2007 01:16:36 -0700 |
User-agent: |
G2/1.0 |
For future reference -- here is an email I received from Tom Malnar
about this topic:
>>I noticed your post about this issue. If you don't like writing your own
>>dump functions all the time, I've created some macros in gdb to do this.
>>Simply copy and paste this into some file and bring the file into gdb via:
>>source someFile
>>Feel free to add my macros to your post. It very hard to find any
>>information on GDB and STL so I created this myself from some old ones on the
>>net that no longer worked with the current STL. Hopefully it helps you and
>>others you are searching for this info on the net.
# GDB helper macros
# Tom Malnar
# April 18, 2007
# This file contains GDB helper functions for cleaning up print output
and debugging STL classes
#
# Set this variable to your samba mapped rootfs drive, double slash on
backslashs are required
set solib-absolute-prefix z:\\rootfs
# Print settings
set print pretty on
set print object on
set print static-members on
set print vtbl on
set print demangle on
set demangle-style gnu-v3
# STL macro's
#
# Tree
# -----
# p_tree <variable> <tree type> <tree data type> -- Prints whole tree
# p_tree_node <variable> <tree type> <tree data type> <value> --
Prints one node
# p_tree_size <variable> -- Prints number of nodes
#
# List
# -----
# p_list <variable> <list type> -- Prints whole tree
# p_list_node <variable> <list type> <value> -- Prints one node
# p_list_size <variable> -- Prints number of nodes
#
# Vector
# -----
# p_vect <variable> -- Prints whole tree
# p_vect_node <variable> <value> -- Prints one node
# p_vect_size <variable>
define p_tree
set $tree = ($arg0)
set $i = 0
set $node = $tree->_M_t->_M_impl->_M_header->_M_left
set $end = $tree->_M_t->_M_impl->_M_header
set $tree_size = $tree->_M_t->_M_impl->_M_node_count
while ($i < $tree_size)
set $i++
printf "NODE %d: ", $i
set $value = (void *)($node + 1)
p *($arg1 *)$value
set $value = $value + 4
p *($arg2 *)$value
if ($node->_M_right != 0)
set $node = $node->_M_right
while ($node->_M_left != 0)
set $node = $node->_M_left
end
else
set $tmp_node = $node->_M_parent
while ($node == $tmp_node->_M_right)
set $node = $tmp_node
set $tmp_node = $tmp_node->_M_parent
end
if ($node->_M_right != $tmp_node)
set $node = $tmp_node
end
end
end
end
define p_tree_node
set $tree = ($arg0)
set $i = 0
set $node = $tree->_M_t->_M_impl->_M_header->_M_left
set $end = $tree->_M_t->_M_impl->_M_header
set $tree_size = $tree->_M_t->_M_impl->_M_node_count
while ($i < $tree_size)
set $i++
set $value = (void *)($node + 1)
if ( *($arg1 *)$value == $arg3 )
p *($arg1 *)$value
printf "NODE %d: ", $i
set $value = $value + 4
p *($arg2 *)$value
end
if ($node->_M_right != 0)
set $node = $node->_M_right
while ($node->_M_left != 0)
set $node = $node->_M_left
end
else
set $tmp_node = $node->_M_parent
while ($node == $tmp_node->_M_right)
set $node = $tmp_node
set $tmp_node = $tmp_node->_M_parent
end
if ($node->_M_right != $tmp_node)
set $node = $tmp_node
end
end
end
end
define p_tree_size
set $tree = ($arg0)
set $tree_size = $tree->_M_t->_M_impl->_M_node_count
printf "Tree Size: %d\n", $tree_size
end
define p_vect_size
set $vec = ($arg0)
set $vec_size = $vec->_M_impl->_M_finish - $vec->_M_impl->_M_start
printf "Vector Size: %d\n", $vec_size
end
define p_vect
set $vec = ($arg0)
set $vec_size = $vec->_M_impl->_M_finish - $vec->_M_impl->_M_start
if ($vec_size != 0)
set $i = 0
while ($i < $vec_size)
printf "Vector Element %d: ", $i
p *($vec->_M_impl->_M_start+$i)
set $i++
end
end
end
define p_vect_node
set $vec = ($arg0)
set $vec_size = $vec->_M_impl->_M_finish - $vec->_M_impl->_M_start
if ($vec_size != 0)
set $i = 0
while ($i < $vec_size)
if ($i == $arg1)
printf "Vector Element %d: ", $i
p *($vec->_M_impl->_M_start+$i)
end
set $i++
end
end
end
define p_list_size
set $list = ($arg0)
set $list_size = 0
set $firstNode = &$arg0._M_impl._M_node
set $curNode = $list->_M_impl->_M_node->_M_next
while ($curNode != $firstNode)
set $curNode = $curNode->_M_next
set $list_size++
end
printf "List Size: %d\n", $list_size
end
define p_list
set $list = ($arg0)
set $firstNode = &$arg0._M_impl._M_node
set $curNode = $list->_M_impl->_M_node->_M_next
while ($curNode != $firstNode)
p *($arg1 *)($curNode+1)
set $curNode = $curNode->_M_next
end
end
define p_list_node
set $list = ($arg0)
set $firstNode = &$arg0._M_impl._M_node
set $curNode = $list->_M_impl->_M_node->_M_next
set $list_size = 0
while ($curNode != $firstNode)
if ( $list_size == $arg2 )
p *($arg1 *)($curNode+1)
end
set $curNode = $curNode->_M_next
set $list_size++
end
end
Tom Malnar
Product Developer, Software
CHRISTIE
- Re: How to inspect and debug STL containers?,
foxx <=