ec_htab_size_idx++;
}
-ExeContext* VG_(record_ExeContext) ( ThreadId tid )
+ExeContext* VG_(record_ExeContext) ( ThreadId tid, Word first_ip_delta )
{
Int i;
Addr ips[VG_DEEPEST_BACKTRACE];
vg_assert(VG_(clo_backtrace_size) >= 1 &&
VG_(clo_backtrace_size) <= VG_DEEPEST_BACKTRACE);
- n_ips = VG_(get_StackTrace)( tid, ips, VG_(clo_backtrace_size) );
+ n_ips = VG_(get_StackTrace)( tid, ips, VG_(clo_backtrace_size),
+ first_ip_delta );
tl_assert(n_ips >= 1 && n_ips <= VG_(clo_backtrace_size));
/* Now figure out if we've seen this one before. First hash it so
continue;
}
- /* No luck there. We have to give up. */
+ /* Last-ditch hack (evidently GDB does something similar). We
+ are in the middle of nowhere and we have a nonsense value for
+ the frame pointer. If the stack pointer is still valid,
+ assume that what it points at is a return address. Yes,
+ desperate measures. Could do better here:
+ - check that the supposed return address is in
+ an executable page
+ - check that the supposed return address is just after a call insn
+ - given those two checks, don't just consider *sp as the return
+ address; instead scan a likely section of stack (eg sp .. sp+256)
+ and use suitable values found there.
+ */
+ if (fp_min <= sp && sp < fp_max) {
+ ip = ((UWord*)sp)[0];
+ ips[i++] = ip;
+ if (debug)
+ VG_(printf)(" ipsH[%d]=%08p\n", i-1, ips[i-1]);
+ ip = ip - 1;
+ sp += 8;
+ continue;
+ }
+
+ /* No luck at all. We have to give up. */
break;
}
return n_found;
}
-UInt VG_(get_StackTrace) ( ThreadId tid, StackTrace ips, UInt n_ips )
+UInt VG_(get_StackTrace) ( ThreadId tid, StackTrace ips, UInt n_ips,
+ Word first_ip_delta )
{
/* thread in thread table */
Addr ip = VG_(get_IP)(tid);
}
# endif
+ /* Take into account the first_ip_delta. */
+ vg_assert( sizeof(Addr) == sizeof(Word) );
+ ip += first_ip_delta;
+
if (0)
VG_(printf)("tid %d: stack_highest=0x%08lx ip=0x%08lx sp=0x%08lx fp=0x%08lx\n",
tid, stack_highest_word, ip, sp, fp);
void VG_(get_and_pp_StackTrace) ( ThreadId tid, UInt n_ips )
{
Addr ips[n_ips];
- UInt n_ips_obtained = VG_(get_StackTrace)(tid, ips, n_ips);
+ UInt n_ips_obtained = VG_(get_StackTrace)(tid, ips, n_ips,
+ 0/*first_ip_delta*/);
VG_(pp_StackTrace)(ips, n_ips_obtained);
}
providing moral support.)
Partly based upon other Valgrind tools
- Copyright (C) 2000-2006 Julian Seward, Nicholas Nethercote et al.
+ Copyright (C) 2000-2007 Julian Seward, Nicholas Nethercote et al.
jseward@acm.org
njn@valgrind.org
{
O_MDEBUG("creating new context maybeLast=0");
// Get the current stacktrace
- mb->leaked = VG_(record_ExeContext)(VG_(get_running_tid)());
+ mb->leaked = VG_(record_ExeContext)(VG_(get_running_tid)(),
+ 0/*first_ip_delta*/);
}
doReport = o_addLeakedBlock(mb->where, mb->leaked, mb->length);
*/
mb->hdr.key = start;
mb->length = size;
- mb->where = VG_(record_ExeContext)(tid);
+ mb->where = VG_(record_ExeContext)(tid, 0/*first_ip_delta*/);
/*
O_DEBUG("Creating new MemBlock (%p) key = %p, length %d",
if(!tp->memBlock->maybeLast)
{
tp->memBlock->maybeLast = tp;
- tp->memBlock->funcEnd = VG_(record_ExeContext)(VG_(get_running_tid)());
+ tp->memBlock->funcEnd = VG_(record_ExeContext)(VG_(get_running_tid)(),
+ 0/*first_ip_delta*/);
O_MDEBUG("setting maybeLast to %p in block at %p",
FROM_TRACKED_KEY(tp->hdr.key), tp->block);
}
//
// If called from generated code, use VG_(get_running_tid)() to get the
// current ThreadId. If called from non-generated code, the current
-// ThreadId should be passed in by the core.
-extern ExeContext* VG_(record_ExeContext) ( ThreadId tid );
+// ThreadId should be passed in by the core. The initial IP value to
+// use is adjusted by first_ip_delta before the stack is unwound.
+// A safe value to pass is zero.
+extern
+ExeContext* VG_(record_ExeContext) ( ThreadId tid, Word first_ip_delta );
// Apply a function to every element in the ExeContext. The parameter 'n'
// gives the index of the passed ip. Doesn't go below main() unless
VG_(tool_panic)("get_IPs: ips[] too small, inc. MAX_OVERESTIMATE?");
// Ask for more IPs than clo_depth suggests we need.
- n_ips = VG_(get_StackTrace)( tid, ips, clo_depth + overestimate );
+ n_ips = VG_(get_StackTrace)( tid, ips, clo_depth + overestimate,
+ 0/*first_ip_delta*/ );
tl_assert(n_ips > 0);
// If the original stack trace is smaller than asked-for, redo=False.
cgbs[i].start = arg[1];
cgbs[i].size = arg[2];
cgbs[i].desc = VG_(strdup)((Char *)arg[3]);
- cgbs[i].where = VG_(record_ExeContext) ( tid );
+ cgbs[i].where = VG_(record_ExeContext) ( tid, 0/*first_ip_delta*/ );
*ret = i;
} else
VG_(needs_core_errors) ();
VG_(needs_tool_errors) (mc_eq_Error,
mc_pp_Error,
+ True,/*show TIDs for errors*/
mc_update_extra,
mc_recognised_suppression,
mc_read_extra_suppression_info,
mc->data = p;
mc->szB = szB;
mc->allockind = kind;
- mc->where = VG_(record_ExeContext)(tid);
+ mc->where = VG_(record_ExeContext)(tid, 0/*first_ip_delta*/);
/* Paranoia ... ensure the MC_Chunk is off-limits to the client, so
the mc->data field isn't visible to the leak checker. If memory
/* Put it out of harm's way for a while, if not from a client request */
if (MC_AllocCustom != mc->allockind) {
/* Record where freed */
- mc->where = VG_(record_ExeContext) ( tid );
+ mc->where = VG_(record_ExeContext) ( tid, 0/*first_ip_delta*/ );
add_to_freed_queue ( mc );
} else {
VG_(free) ( mc );
if (old_szB == new_szB) {
/* size unchanged */
- mc->where = VG_(record_ExeContext)(tid);
+ mc->where = VG_(record_ExeContext)(tid, 0/*first_ip_delta*/);
p_new = p_old;
} else if (old_szB > new_szB) {
/* new size is smaller */
MC_(make_mem_noaccess)( mc->data+new_szB, mc->szB-new_szB );
mc->szB = new_szB;
- mc->where = VG_(record_ExeContext)(tid);
+ mc->where = VG_(record_ExeContext)(tid, 0/*first_ip_delta*/);
p_new = p_old;
} else {