]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Callgrind: Fix failed assertion at toggling instrumentation mode
authorJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Sun, 10 Sep 2006 22:34:20 +0000 (22:34 +0000)
committerJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Sun, 10 Sep 2006 22:34:20 +0000 (22:34 +0000)
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

callgrind/bb.c
callgrind/context.c
callgrind/main.c

index 6f1dd6a3a5884dbfbd703fc1c871a811f4718482..32b1dfebf878ea7abaed53395ec3997237a5c30d 100644 (file)
@@ -306,7 +306,10 @@ void CLG_(delete_bb)(Addr addr)
        CLG_DEBUG(3, "  delete_bb (Obj %s, off %p): NOT FOUND\n",
                  obj->name, offset);
 
-       /* we didn't find it.  That's strange. */
+       /* we didn't find it.
+        * this happens when callgrinds instrumentation mode
+        * was off at BB translation time, ie. no BB was created.
+        */
        return;
     }
 
@@ -334,6 +337,7 @@ void CLG_(delete_bb)(Addr addr)
            + (bb->cjmp_count+1) * sizeof(CJmpInfo);
        VG_(memset)( bb, 0xAA, size );
        CLG_FREE(bb);
+       return;
     }
     CLG_DEBUG(3, "  delete_bb: BB in use, can not free!\n");
 }
index f174888a1c7ab360bc2b7115071b3785dfa894e0..04740354fcf79e8b4fbb19c39943d4ca17fd8a4c 100644 (file)
@@ -279,6 +279,11 @@ void CLG_(push_cxt)(fn_node* fn)
   call_stack* cs = &CLG_(current_call_stack);
   Int fn_entries;
 
+  CLG_DEBUG(5, "+ push_cxt(fn '%s'): old ctx %d\n", 
+           fn ? fn->name : (Char*)"0x0",
+           CLG_(current_state).cxt ?
+           CLG_(current_state).cxt->base_number : -1);
+
   /* save old context on stack (even if not changed at all!) */
   CLG_ASSERT(cs->sp < cs->size);
   CLG_ASSERT(cs->entry[cs->sp].cxt == 0);
@@ -321,8 +326,10 @@ void CLG_(push_cxt)(fn_node* fn)
   *(CLG_(current_fn_stack).top) = fn;
   CLG_(current_state).cxt = CLG_(get_cxt)(CLG_(current_fn_stack).top);
 
-  CLG_DEBUG(5, "  push_cxt(fn '%s'): %d\n", 
-          fn ? fn->name : (Char*)"0x0",
-          CLG_(current_fn_stack).top - CLG_(current_fn_stack).bottom);
+  CLG_DEBUG(5, "- push_cxt(fn '%s'): new cxt %d, fn_sp %d\n", 
+           fn ? fn->name : (Char*)"0x0",
+           CLG_(current_state).cxt ?
+             CLG_(current_state).cxt->base_number : -1,
+           CLG_(current_fn_stack).top - CLG_(current_fn_stack).bottom);
 }
                               
index 2a21a9c53c86aa978a4070bdd5e207d042db2e56..aa88a9df3c2347a27c11eaff649eeda05d46863e 100644 (file)
@@ -771,6 +771,10 @@ void unwind_thread(thread_info* t)
   /* 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 @@ void CLG_(set_instrument_state)(Char* reason, Bool state)
   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");
 }