|
From: Jeremy F. <je...@go...> - 2005-01-24 01:24:30
|
CVS commit by fitzhardinge:
Fix stack backtraces in threads. do_clone() was not initializing
stack_highest_word, so a lot of stack-related things were going wrong.
M +13 -2 vg_execontext.c 1.24
M +4 -3 x86-linux/syscalls.c 1.18
--- valgrind/coregrind/vg_execontext.c #1.23:1.24
@@ -160,4 +160,5 @@ static UInt stack_snapshot2 ( Addr* ips,
Addr fp_min, Addr fp_max_orig )
{
+ static const Bool debug = False;
Int i;
Addr fp_max;
@@ -182,4 +183,8 @@ static UInt stack_snapshot2 ( Addr* ips,
fp_max -= sizeof(Addr);
+ if (debug)
+ VG_(printf)("n_ips=%d fp_min=%p fp_max_orig=%p, fp_max=%p ip=%p fp=%p\n",
+ n_ips, fp_min, fp_max_orig, fp_max, ip, fp);
+
/* Assertion broken before main() is reached in pthreaded programs; the
* offending stack traces only have one item. --njn, 2002-aug-16 */
@@ -198,5 +203,6 @@ static UInt stack_snapshot2 ( Addr* ips,
for (i = 1; i < n_ips; i++) {
if (!(fp_min <= fp && fp <= fp_max)) {
- //VG_(printf)("... out of range %p\n", fp);
+ if (debug)
+ VG_(printf)("... out of range %p\n", fp);
break; /* fp gone baaaad */
}
@@ -208,5 +214,6 @@ static UInt stack_snapshot2 ( Addr* ips,
ips[i] = STACK_FRAME_RET(fp); /* ret addr */
fp = STACK_FRAME_NEXT(fp); /* old fp */
- //VG_(printf)(" %p\n", ips[i]);
+ if (debug)
+ VG_(printf)(" ips[%d]=%08p\n", i, ips[i]);
}
}
@@ -334,4 +341,8 @@ void get_needed_regs(ThreadId tid, Addr*
*sp += sizeof(Addr);
}
+
+ if (0)
+ VG_(printf)("tid %d: stack_highest=%p ip=%p sp=%p fp=%p\n",
+ tid, *stack_highest_word, *ip, *sp, *fp);
}
--- valgrind/coregrind/x86-linux/syscalls.c #1.17:1.18
@@ -326,9 +326,10 @@ static Int do_clone(ThreadId ptid,
if (seg) {
ctst->stack_base = seg->addr;
- ctst->stack_size = (Addr)PGROUNDUP(esp) - seg->addr;
+ ctst->stack_highest_word = (Addr)PGROUNDUP(esp);
+ ctst->stack_size = ctst->stack_highest_word - ctst->stack_base;
if (debug)
- VG_(printf)("guessed client stack range %p-%p\n",
- seg->addr, PGROUNDUP(esp));
+ VG_(printf)("tid %d: guessed client stack range %p-%p\n",
+ ctid, seg->addr, PGROUNDUP(esp));
} else {
VG_(message)(Vg_UserMsg, "!? New thread %d starts with ESP(%p) unmapped\n",
|