|
From: <sv...@va...> - 2007-10-30 23:56:40
|
Author: sewardj
Date: 2007-10-30 23:56:42 +0000 (Tue, 30 Oct 2007)
New Revision: 7059
Log:
Add a last-ditch heuristic-hack to the amd64-linux stack unwinder,
which is used when all other methods fail. Seems like GDB has
something similar.
Modified:
branches/THRCHECK/coregrind/m_stacktrace.c
Modified: branches/THRCHECK/coregrind/m_stacktrace.c
===================================================================
--- branches/THRCHECK/coregrind/m_stacktrace.c 2007-10-30 21:37:49 UTC (rev 7058)
+++ branches/THRCHECK/coregrind/m_stacktrace.c 2007-10-30 23:56:42 UTC (rev 7059)
@@ -240,7 +240,29 @@
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;
}
|