When investigating bug 383275, the host stacktrace was containing
only one IP. This is because the tid corresponding to the lwpid
is dead, and so no valid thread state was returned.
This then gave a rubbish stacktop of 0, which means unwinding
stops at first frame.
So, try harder to find a valid thread state when reporting the
host stacktrace.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16470
Addr ips[BACKTRACE_DEPTH];
Int n_ips;
ThreadState *tst
- = VG_(get_ThreadState)( VG_(lwpid_to_vgtid)( VG_(gettid)() ) );
+ = VG_(get_ThreadState)( VG_(lwpid_to_vgtid_dead_ok)(VG_(gettid)()));
// If necessary, fake up an ExeContext which is of our actual real CPU
// state. Could cause problems if we got the panic/exception within the
return VG_INVALID_THREADID;
}
+ThreadId VG_(lwpid_to_vgtid_dead_ok)(Int lwp)
+{
+ ThreadId tid = VG_(lwpid_to_vgtid)(lwp);
+
+ if (tid != VG_INVALID_THREADID)
+ return tid;
+
+ for(tid = 1; tid < VG_N_THREADS; tid++)
+ if (VG_(threads)[tid].os_state.lwpid == lwp)
+ return tid;
+
+ return VG_INVALID_THREADID;
+}
+
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
ThreadId */
extern ThreadId VG_(lwpid_to_vgtid)(Int lwpid);
+
+/* Same as VG_(lwpid_to_vgtid), but if no corresponding living thread is found,
+ searches also in dead threads.
+ This can be used when the tid is exiting, but the corresponding
+ lwpid is still running. */
+extern ThreadId VG_(lwpid_to_vgtid_dead_ok)(Int lwpid);
+
#endif // __PUB_CORE_THREADSTATE_H
/*--------------------------------------------------------------------*/