Callgrind: Fix failed assertion at toggling instrumentation mode

When instrumentation mode is switched off, we want to fully
reset callgrinds internal execution state, which includes
the shadow call stack and function stack for context generation.
The latter was not completely reset before.

The bug showed up when switching the instrumentation mode on for
the second time, leading to
  Callgrind: callstack.c:211 (vgCallgrind_push_call_stack): 
  Assertion 'current_entry->cxt != 0' failed.

This commit also improves debug output a little bit.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6045 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/callgrind/main.c b/callgrind/main.c
index 2a21a9c..aa88a9d 100644
--- a/callgrind/main.c
+++ b/callgrind/main.c
@@ -771,6 +771,10 @@
   /* unwind regular call stack */
   while(CLG_(current_call_stack).sp>0)
     CLG_(pop_call_stack)();
+
+  /* reset context and function stack for context generation */
+  CLG_(init_exec_state)( &CLG_(current_state) );
+  CLG_(current_fn_stack).top = CLG_(current_fn_stack).bottom;
 }
 
 /* Ups, this can go wrong... */
@@ -795,11 +799,8 @@
   if (0)
     CLG_(forall_threads)(zero_thread_cost);
 
-  if (!state)
-    CLG_(init_exec_state)( &CLG_(current_state) );
-
   if (VG_(clo_verbosity) > 1)
-    VG_(message)(Vg_DebugMsg, "%s: instrumentation switched %s\n",
+    VG_(message)(Vg_DebugMsg, "%s: instrumentation switched %s",
 		 reason, state ? "ON" : "OFF");
 }