gdb routines for some stl containers

Ravi Menon jravimenon@gmail.com
Fri Aug 4 18:13:00 GMT 2006


Hi,

I am fairly new to this discussion list.  I have attached some gdb
routines for the following stl containers:

* hash_map - dumphmap

* hash_set - dumphset

* map - dumpmap

* set - dumpset

* vector - dumpvec

* string - dumpstr

I have attached three versions of these rouitnes for each compiler
version respectively - g++2x, g++3x, and g++4x.

I found them useful in debugging various problems where stl was used
heavily - the bugs were largely in user code due to some mistaken
assumptions.

The map/set routines above only works for a particular version of g++
3.4.x - I had raised this question earlier:

http://gcc.gnu.org/ml/libstdc++/2006-06/msg00001.html

If time permits, I will add more to this list.

Regards,
Ravi
-------------- next part --------------
define dumpstlht
  set $s = $arg0._M_ht._M_buckets._M_start
  set $e = $arg0._M_ht._M_buckets._M_finish
  set $b = 0
  while $s < $e 
    printf "bucket %d\n", $b
    set $x = *$s
    while $x != 0
      p $x->_M_val
      set $x = $x->_M_next
    end
    set $b = $b + 1
    set $s = $s + 1
    printf "\n"
  end
end

define dumpvec
  set $s = $arg0._M_start
  set $e = $arg0._M_finish
  set $i = 0
  while $s < $e
    printf "%d:", $i
    p *$s
    set $i = $i + 1
    set $s = $s + 1
    printf "\n"
  end
end

define dumpstlrbt
  set $h = $arg0._M_t._M_header
  set $i = $h->_M_left
  while $i != $h
    p ((_Rb_tree_node*) $i)->_M_value_field
    if $i->_M_right != 0
      set $i = $i->_M_right
      while $i->_M_left != 0
        set $i = $i->_M_left
      end
    else
      set $p = $i->_M_parent
      while $i == $p->_M_right
        set $i = $p
        set $p = $p->_M_parent
      end
      if $i->_M_right != $p
        set $i = $p
      end
    end
  end
end

define dumpmap
  dumpstlrbt $arg0
end

define dumpset
  dumpstlrbt $arg0
end

define dumphmap
  dumpstlht $arg0
end


define dumphset
  dumpstlht $arg0
end

define dumpstr
  set $rep = ((Rep*) $arg0.dat) - 1
  printf "[Reserve = %u, Length = %u, References = %u, Selfish=%d]\n\"%s\"\n", $rep->res, $rep->len, $rep->ref, $rep->selfish, $arg0.dat
end

-------------- next part --------------
define dumpstlht
  set $s = $arg0._M_ht._M_buckets._M_start
  set $e = $arg0._M_ht._M_buckets._M_finish
  set $b = 0
  while $s < $e 
    printf "bucket %d\n", $b
    set $x = *$s
    while $x != 0
      p $x->_M_val
      set $x = $x->_M_next
    end
    set $b = $b + 1
    set $s = $s + 1
    printf "\n"
  end
end

define dumpvec
  set $s = $arg0._M_start
  set $e = $arg0._M_finish
  set $i = 0
  while $s < $e
    printf "%d:", $i
    p *$s
    set $i = $i + 1
    set $s = $s + 1
    printf "\n"
  end
end

define dumpstlrbt
  set $h = $arg0._M_t._M_header
  set $i = $h->_M_left
  while $i != $h
    p ((_Rb_tree_node*) $i)->_M_value_field
    if $i->_M_right != 0
      set $i = $i->_M_right
      while $i->_M_left != 0
        set $i = $i->_M_left
      end
    else
      set $p = $i->_M_parent
      while $i == $p->_M_right
        set $i = $p
        set $p = $p->_M_parent
      end
      if $i->_M_right != $p
        set $i = $p
      end
    end
  end
end

define dumpmap
  dumpstlrbt $arg0
end

define dumpset
  dumpstlrbt $arg0
end

define dumphmap
  dumpstlht $arg0
end


define dumphset
  dumpstlht $arg0
end

define dumpstr
  printf "[Capacity = %u, Length = %u, References = %d]\n\"%s\"\n", $arg0._M_rep()->_M_capacity, $arg0._M_rep()->_M_length, $arg0._M_rep()->_M_references, $arg0._M_data()
end

-------------- next part --------------
define dumpstlht
  set $s = $arg0._M_ht._M_buckets._M_impl._M_start
  set $e = $arg0._M_ht._M_buckets._M_impl._M_finish
  set $b = 0
  while $s < $e 
    printf "bucket %d\n", $b
    set $x = *$s
    while $x != 0
      p $x->_M_val
      set $x = $x->_M_next
    end
    set $b = $b + 1
    set $s = $s + 1
    printf "\n"
  end
end

define dumpvec
  set $s = $arg0._M_impl._M_start
  set $e = $arg0._M_impl._M_finish
  set $i = 0
  while $s < $e
    printf "%d:", $i
    p *$s
    set $i = $i + 1
    set $s = $s + 1
    printf "\n"
  end
end

define dumpstlrbt
  set $h = $arg0._M_t._M_impl._M_header
  set $i = $h->_M_left
  while $i != $h
    p ((_Rb_tree_node*) $i)->_M_value_field
    if $i->_M_right != 0
      set $i = $i->_M_right
      while $i->_M_left != 0
        set $i = $i->_M_left
      end
    else
      set $p = $i->_M_parent
      while $i == $p->_M_right
        set $i = $p
        set $p = $p->_M_parent
      end
      if $i->_M_right != $p
        set $i = $p
      end
    end
  end
end

define dumpmap
  dumpstlrbt $arg0
end

define dumpset
  dumpstlrbt $arg0
end

define dumphmap
  dumpstlht $arg0
end


define dumphset
  dumpstlht $arg0
end

define dumpstr
  printf "[Capacity = %u, Length = %u, References = %d]\n\"%s\"\n", $arg0._M_rep()->_M_capacity, $arg0._M_rep()->_M_length, $arg0._M_rep()->_M_refcount, $arg0._M_data()
end




More information about the Libstdc++ mailing list