From: Julian Seward Date: Tue, 12 Sep 2006 21:13:11 +0000 (+0000) Subject: Merge r6045 and r6053 (callgrind: fix failed assertion when toggling X-Git-Tag: svn/VALGRIND_3_2_1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=561cec9ad9d33cb103595b84d054a9eb2e99d6bf;p=thirdparty%2Fvalgrind.git Merge r6045 and r6053 (callgrind: fix failed assertion when toggling instrumentation mode) (JosefW) git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_2_BRANCH@6057 --- diff --git a/callgrind/bb.c b/callgrind/bb.c index 6f1dd6a3a5..32b1dfebf8 100644 --- a/callgrind/bb.c +++ b/callgrind/bb.c @@ -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"); } diff --git a/callgrind/context.c b/callgrind/context.c index f174888a1c..04740354fc 100644 --- a/callgrind/context.c +++ b/callgrind/context.c @@ -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); } diff --git a/callgrind/global.h b/callgrind/global.h index f6190a206c..0079b4d3a0 100644 --- a/callgrind/global.h +++ b/callgrind/global.h @@ -688,7 +688,8 @@ void CLG_(delete_bb)(Addr addr); static __inline__ Addr bb_addr(BB* bb) { return bb->offset + bb->obj->offset; } static __inline__ Addr bb_jmpaddr(BB* bb) - { return bb->instr[bb->instr_count-1].instr_offset + bb->offset + bb->obj->offset; } + { UInt off = (bb->instr_count > 0) ? bb->instr[bb->instr_count-1].instr_offset : 0; + return off + bb->offset + bb->obj->offset; } /* from fn.c */ void CLG_(init_fn_array)(fn_array*); diff --git a/callgrind/main.c b/callgrind/main.c index 2a21a9c53c..aa88a9df3c 100644 --- a/callgrind/main.c +++ b/callgrind/main.c @@ -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"); }