]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Ensure host stack trace has better chance to work when valgrind is exiting
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Tue, 8 Aug 2017 21:15:45 +0000 (21:15 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Tue, 8 Aug 2017 21:15:45 +0000 (21:15 +0000)
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

coregrind/m_libcassert.c
coregrind/m_threadstate.c
coregrind/pub_core_threadstate.h

index a6f306968135c5bef16d54f174ec766b2a307cd5..63fb64b2401f3905573aee71753f65f75cbbacc0 100644 (file)
@@ -343,7 +343,7 @@ static void show_sched_status_wrk ( Bool host_stacktrace,
       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
index 6edf2260fc22942c59ef5dd2c96bbfd04cb66ad9..cba4ef8695b5f9bea221ed50760f8ce856d7215b 100644 (file)
@@ -177,6 +177,20 @@ ThreadId VG_(lwpid_to_vgtid)(Int lwp)
    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                                                          ---*/
 /*--------------------------------------------------------------------*/
index 19a998246c2c933c21ec3887189016021d2dbc24..c62429e36ab335c01a284ddc75f3f786a9926199 100644 (file)
@@ -466,6 +466,13 @@ extern Int VG_(count_runnable_threads)(void);
    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
 
 /*--------------------------------------------------------------------*/