summaryrefslogtreecommitdiffstats
path: root/gdb/thread.c
diff options
context:
space:
mode:
authorMichael Snyder <msnyder@vmware.com>1997-05-01 20:39:06 +0000
committerMichael Snyder <msnyder@vmware.com>1997-05-01 20:39:06 +0000
commit2847920ae997ce7240f6d51979a8fc004b2abc9e (patch)
tree839aa13e6050ef818e94a9bf640429bbdf498b68 /gdb/thread.c
parent6475b23404300349a3de07afeb8724ab47d5daca (diff)
downloadppe42-binutils-2847920ae997ce7240f6d51979a8fc004b2abc9e.tar.gz
ppe42-binutils-2847920ae997ce7240f6d51979a8fc004b2abc9e.zip
Thu May 1 11:44:46 1997 Michael Snyder <msnyder@cleaver.cygnus.com>
* Finalize merge from Hurd folk. Mon Oct 30 16:41:04 1995 Miles Bader <miles@gnu.ai.mit.edu> * thread.c (thread_apply_command, thread_apply_all_command, thread_command): Make sure TP is alive. (thread_alive): New function. Tue Nov 14 14:31:03 1995 Miles Bader <miles@gnu.ai.mit.edu> * infrun.c (sig_print_info): Deal better with long signal names. Wed Nov 22 15:23:35 1995 Miles Bader <miles@gnu.ai.mit.edu> * thread.c (thread_id_to_pid): New function. Fri Dec 1 13:25:25 1995 Miles Bader <miles@gnu.ai.mit.edu> * gnu-nat.c: (set_thread_cmd_list, show_thread_cmd_list, set_thread_default_cmd_list, show_thread_default_cmd_list): New variables. (set_thread_cmd, show_thread_cmd, set_thread_default_cmd, show_thread_default_cmd): New functions. Fri Apr 18 15:20:16 1997 Miles Bader <miles@gnu.ai.mit.edu> * gnu-nat.c (inf_startup): remove TASK parameter. (inf_set_task): replace with new function (inf_set_pid). * gdbthread.h: Add extern decl for thread_cmd_list.
Diffstat (limited to 'gdb/thread.c')
-rw-r--r--gdb/thread.c83
1 files changed, 49 insertions, 34 deletions
diff --git a/gdb/thread.c b/gdb/thread.c
index cd7fb02235..7ffc65af81 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -270,25 +270,41 @@ void save_infrun_state (pid, prev_pc, prev_func_start, prev_func_name,
tp->another_trap = another_trap;
}
+/* Return true if TP is an active thread. */
+static int
+thread_alive (tp)
+ struct thread_info *tp;
+{
+ if (tp->pid == -1)
+ return 0;
+ if (! target_thread_alive (tp->pid))
+ {
+ tp->pid = -1; /* Mark it as dead */
+ return 0;
+ }
+ return 1;
+}
+
static void
prune_threads ()
{
- struct thread_info *tp, *tpprev;
+ struct thread_info *tp, *tpprev, *next;
tpprev = 0;
-
- for (tp = thread_list; tp; tp = tp->next)
- if (tp->pid == -1)
- {
- if (tpprev)
- tpprev->next = tp->next;
- else
- thread_list = NULL;
-
- free (tp);
- }
- else
- tpprev = tp;
+ for (tp = thread_list; tp; tp = next)
+ {
+ next = tp->next;
+ if (!thread_alive (tp))
+ {
+ if (tpprev)
+ tpprev->next = next;
+ else
+ thread_list = next;
+ free (tp);
+ }
+ else
+ tpprev = tp;
+ }
}
/* Print information about currently known threads */
@@ -305,14 +321,9 @@ info_threads_command (arg, from_tty)
selected_frame. */
if (!target_has_stack) error ("No stack.");
+ prune_threads ();
for (tp = thread_list; tp; tp = tp->next)
{
- if (! target_thread_alive (tp->pid))
- {
- tp->pid = -1; /* Mark it as dead */
- continue;
- }
-
if (tp->pid == current_pid)
printf_filtered ("* ");
else
@@ -325,7 +336,6 @@ info_threads_command (arg, from_tty)
}
switch_to_thread (current_pid);
- prune_threads ();
}
/* Switch from one thread to another. */
@@ -375,12 +385,13 @@ thread_apply_all_command (cmd, from_tty)
old_chain = make_cleanup (restore_current_thread, inferior_pid);
for (tp = thread_list; tp; tp = tp->next)
- {
- switch_to_thread (tp->pid);
- printf_filtered ("\nThread %d (%s):\n", tp->num,
- target_pid_to_str (inferior_pid));
- execute_command (cmd, from_tty);
- }
+ if (thread_alive (tp))
+ {
+ switch_to_thread (tp->pid);
+ printf_filtered ("\nThread %d (%s):\n", tp->num,
+ target_pid_to_str (inferior_pid));
+ execute_command (cmd, from_tty);
+ }
}
static void
@@ -434,15 +445,16 @@ thread_apply_command (tidlist, from_tty)
tp = find_thread_id (start);
if (!tp)
+ warning ("Unknown thread %d.", start);
+ else if (!thread_alive (tp))
+ warning ("Thread %d has terminated.", start);
+ else
{
- warning ("Unknown thread %d.", start);
- continue;
+ switch_to_thread (tp->pid);
+ printf_filtered ("\nThread %d (%s):\n", tp->num,
+ target_pid_to_str (inferior_pid));
+ execute_command (cmd, from_tty);
}
-
- switch_to_thread (tp->pid);
- printf_filtered ("\nThread %d (%s):\n", tp->num,
- target_pid_to_str (inferior_pid));
- execute_command (cmd, from_tty);
}
}
}
@@ -470,6 +482,9 @@ see the IDs of currently known threads.");
error ("Thread ID %d not known. Use the \"info threads\" command to\n\
see the IDs of currently known threads.", num);
+ if (!thread_alive (tp))
+ error ("Thread ID %d has terminated.\n", num);
+
switch_to_thread (tp->pid);
printf_filtered ("[Switching to %s]\n", target_pid_to_str (inferior_pid));
OpenPOWER on IntegriCloud