Wednesday, May 17, 2006

Who vs What part 2

When I wrote the original posting, I talked about accountability. However, as I wrote it, I got it backwards. Accountability for the failures doesn't mean didly if you aren't also held accountable when it works properly. It is important to receive the credit!

So, who is still more important than what. However, it's not to know who to blame when it goes wrong, but who to reward when it goes right.

If you're being appreciated for the work you do, you'll make more of an effort on it. If you see it as a thankless task, you'll avoid it like a disease.

Essentially, I had the correct idea, but I was stuck in the blame side of the story. My bad.

Tuesday, May 16, 2006

Better STL Map Decoding

Way back when, I tried to decode an STL map in GDB. It didn't work very well. Well, a recent google trawl has turned up a better way!

It seems that GDB has a built-in scripting language! I Never knew that, but I should have guessed.

I've reproduced it here just in case the university takes it down. I don't want to lose it!


#
# GDB stl functions, a set of scripts to help debug STL containers
# Copyright (C) 2000 Gilad Mishne
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

add-symbol-file StlStdContainers.so

####################
# vector functions #
####################

define p_stl_vector_size
 set $vec = ($arg0)
 set $vec_size = $vec->_M_finish - $vec->_M_start
 printf "Vector Size: %d\n", $vec_size
end

define p_stl_vector
 set $vec = ($arg0)
 set $vec_size = $vec->_M_finish - $vec->_M_start
 if ($vec_size != 0)
   set $i = 0
   while ($i < $vec_size)       printf "Vector Element %d:  ", $i       p *($vec->_M_start+$i)
     set $i++
   end
 end
end


##########################################################################
# list functions                                                         #
# provides generic pointers that need to be cast back to the type        #
##########################################################################

define p_stl_list_size
 set $list = ($arg0)
 set $list_size = 0
 set $firstNode = $list->_M_node
 set $curNode = $list->_M_node->_M_next
 while ($curNode != $firstNode)
 set $curNode = ((_List_node *)$curNode)->_M_next
   set $list_size++
 end
 printf "List Size: %d\n", $list_size
end

define p_stl_list
 set $list = ($arg0)
 set $list_size = 0
 set $firstNode = $list->_M_node
 set $curNode = $list->_M_node->_M_next
 while ($curNode != $firstNode)
   printf "List Element %d: ", $list_size
   p (void *) (& ((_List_node *)$curNode)->_M_data)
 set $curNode = ((_List_node *)$curNode)->_M_next
   set $list_size++
 end
end


####################
# tree   functions #
####################

define p_stl_tree_size
 set $tree = ($arg0)
 set $tree_size = $tree->_M_t->_M_node_count
 printf "Tree Size: %d\n", $tree_size
end

define p_stl_tree
 set $tree = ($arg0)
 set $i = 0
 set $node = $tree->_M_t->_M_header->_M_left
 set $end = $tree->_M_t->_M_header
 while ($node != $end)
   set $i++
   printf "NODE %d: ", $i
   set $value = (void *)($node + 1)
   p $value
   if ($node->_M_right != 0)
     set $node = (_Rb_tree_node_base *)$node->_M_right
       while ($node->_M_left != 0)
         set $node = (_Rb_tree_node_base *)$node->_M_left
       end
   else
     set $tmp_node = (_Rb_tree_node_base *)$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

####################
# hash   functions #
####################

define p_stl_hash_size
 set $hash = ($arg0)
 set $table = $hash->_M_ht
 set $table_size = $table->_M_num_elements
 set $num_buckets = $table->_M_buckets->_M_finish - $table->_M_buckets->_M_start
 printf "Table Size: %d  (in %d buckets)\n", $table_size, $num_buckets
end

define p_stl_hash
 set $i = 0
 set $hash = ($arg0)
 set $table = $hash->_M_ht
 set $table_size = $table->_M_num_elements
 set $cur_bucket = 0

 set $num_buckets = $table->_M_buckets->_M_finish - $table->_M_buckets->_M_start
 while ($cur_bucket < $num_buckets && $i < $table_size)     if (*($table->_M_buckets->_M_start + $cur_bucket) != 0)
     printf "Bucket %d:\n--------\n", $cur_bucket
     set $cur_node = *($table->_M_buckets->_M_start + $cur_bucket)
     while ($cur_node != 0)
       set $cur_val = (void*)(&((_Hashtable_node *)$cur_node)->_M_val)
       set $cur_node = ((_Hashtable_node *)$cur_node)->_M_next
       p $cur_val
       set $i++
     end
     printf "\n"
   end
   set $cur_bucket++
 end
end


#####################################
# Documentation for online gdb help #
#####################################

document p_stl_list_size
p_stl_list_size : Print size of stl list
end
document p_stl_list
p_stl_list : Print contents of stl list as (void*) pointers. Cast back to actual template type to see the values.
end

document p_stl_vector_size
p_stl_vector_size : Print size of stl vector
end
document p_stl_vector
p_stl_vector : Print contents of stl vector as (void*) pointers. Cast back to actual template type to see the values.
end

document p_stl_tree_size
p_stl_tree_size : Print size of stl trees (sets and maps)
end
document p_stl_tree
p_stl_tree : Print contents of stl trees as (void*) pointers.
For sets, cast back to actual template type to see the values.
For maps, cast back to (pair*) to see the values.
end

document p_stl_hash_size
p_stl_hash_size : Print size of stl hashs (sets and maps)
end
document p_stl_hash
p_stl_hash : Print contents of stl hashs as (void*) pointers.
For sets, cast back to actual template type to see the values.
For maps, cast back to (pair*) to see the values.
end

Saturday, May 13, 2006

Who is more important than What or How

Do you have an organisation that talks the talk but doesn't actually walk the walk? Do you always sit around and discuss how "it would be better if we just". Do improvements die on the vine?

I've found that who is always more important than what. Once you answer who, everything else becomes easy. Who is responsible for ensuring that the change happens? Who is responsible for the outcome of the task? Who is held accountable when the code (or any work item) fails?

That's the hard part. Once you decide who wants to be (or is to be made to be) held accountable, then it becomes a matter of following through. It moves improvements from inidividual initiative and into the realm of employee performance management.

Otherwise, I've found that everyone sits around waiting for someone else to make the move. Even if someone steps forward and does the work, it will frequently require the agreement of others to use it. If they don't agree, the improvement will die from neglect (see my outsourcing discussion). This increases the frustration for everyone.

Of course, there could be other reasons for the behaviour. It could just be that even if management says they consider something important, they don't really mean it. It could be that people are afraid to accept responsability, perhaps there is a tendency to shoot the messenger. Perhaps your staff are like little dogs who have been beaten too many times and now flinch whenever someone waves.

It could be many things. Even if any of negative reasons are true, the key is still to make individuals accountable. Once they are accountable for both the good and bad things they do, you will quickly see them start to change how the job is done.

After all, people do like to take pride in their work.