Index: valgrind-quilt/coregrind/vg_execontext.c =================================================================== --- valgrind-quilt.orig/coregrind/vg_execontext.c 2005-05-06 08:35:08.598115176 -0400 +++ valgrind-quilt/coregrind/vg_execontext.c 2005-05-06 08:43:11.816003304 -0400 @@ -197,6 +197,25 @@ ips[0] = ip; i = 1; } else { +#ifdef __PPC__ + // If lr doesn't point to an address in the function at the top of the + // stack, it must still contain the return address for this frame. If + // this is the case, this is a better return address to use, because + // when the topmost stack frame is a leaf (makes no function calls), it + // won't store the return address in the stack. + + ThreadId tid = VG_(get_lwp_tid)(VG_(gettid)()); + ThreadState *tst = &VG_(threads)[tid]; + UInt lr = ARCH_RETADDR(tst->arch); + UChar buf_lr[M_VG_ERRTXT], buf_ip[M_VG_ERRTXT]; + Addr lr_return_addr = 0; + + if (VG_(get_fnname) (lr, buf_lr, M_VG_ERRTXT)) + if (VG_(get_fnname) (ip, buf_ip, M_VG_ERRTXT)) + if (VG_(strncmp)(buf_lr, buf_ip, M_VG_ERRTXT)) + lr_return_addr = lr; +#endif + /* Get whatever we safely can ... */ ips[0] = ip; fp = FIRST_STACK_FRAME(fp); @@ -211,7 +230,13 @@ // VG_(printf)("nonmonotonic\n"); // break; /* fp gone nonmonotonic */ // } - ips[i] = STACK_FRAME_RET(fp); /* ret addr */ +#ifdef __PPC__ + if (lr_return_addr) { + ips[i] = lr_return_addr; + lr_return_addr = 0; + } else +#endif + ips[i] = STACK_FRAME_RET(fp); /* ret addr */ fp = STACK_FRAME_NEXT(fp); /* old fp */ if (debug) VG_(printf)(" ips[%d]=%08p\n", i, ips[i]);