diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index c2e6b6d2bd6..e891f510e08 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -830,8 +830,10 @@ sync_threadlists (pid_t pid)
 		private_thread_info_up (priv));
 	}
 
-      /* The thread is terminated. Remove it.  */
-      if (state == PST_TERM)
+      /* If the thread is terminated remove it, but only if it is a binary
+	 and has execution.  If it is a core file, keep terminated threads
+	 so we can analyse them.  */
+      if (target_has_execution () && state == PST_TERM)
 	{
 	  thread_info *thr = proc_target->find_thread (ptid);
 	  gdb_assert (thr != nullptr);
@@ -847,16 +849,20 @@ sync_threadlists (pid_t pid)
        where in the end after the threadfunc breakpoint is hit, the
        thread exits and gets into a PST_UNKNOWN state.  So this thread
        will not run in the above for loop.  Therefore the below for loop
-       is to manually delete such threads.  */
-    for (thread_info &it : all_threads_safe ())
+       will manually delete such threads. We only do the for binaries in
+       execution.  For core files keep all threads for analysis.  */
+    if (target_has_execution ())
       {
-	aix_thread_info *priv = get_aix_thread_info (&it);
-	if (in_queue_threads.count (priv->pdtid) == 0
-		&& in_thread_list (proc_target, it.ptid)
-		&& pid == it.ptid.pid ())
+	for (thread_info &it : all_threads_safe ())
 	  {
-	    delete_thread (&it);
-	    data->exited_threads.insert (priv->pdtid);
+	    aix_thread_info *priv = get_aix_thread_info (&it);
+	    if (in_queue_threads.count (priv->pdtid) == 0
+		    && in_thread_list (proc_target, it.ptid)
+		    && pid == it.ptid.pid ())
+	      {
+		delete_thread (&it);
+		data->exited_threads.insert (priv->pdtid);
+	      }
 	  }
       }
 }
