1 /* for separate threads within the inferior process, for GDB.
2 Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
4 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5 WARRANTY. No author or distributor accepts responsibility to anyone
6 for the consequences of using it or for whether it serves any
7 particular purpose or works at all, unless he says so in writing.
8 Refer to the GDB General Public License for full details.
10 Everyone is granted permission to copy, modify and redistribute GDB,
11 but only under the conditions described in the GDB General Public
12 License. A copy of this license is supposed to have been given to you
13 along with GDB so you can know your rights and responsibilities. It
14 should be in a file named COPYING. Among other things, the copyright
15 notice and this notice must be preserved on all copies.
17 In other words, go ahead and share GDB, but don't try to stop
18 anyone else from sharing it farther. Help stamp out software hoarding!
30 #include <sys/types.h>
33 /*#include "lynxos-core.h"*/
37 struct thread_info *next;
38 int pid; /* Actual process id */
39 int num; /* Convenient handle */
42 static struct thread_info *thread_list = NULL;
43 static int highest_thread_num;
45 static void thread_info PARAMS ((void));
47 static void thread_command PARAMS ((char * tidstr, int from_tty));
49 static void prune_threads PARAMS ((void));
51 static void thread_switch PARAMS ((int pid));
56 struct thread_info *tp, *tpnext;
61 for (tp = thread_list; tp; tp = tpnext)
68 highest_thread_num = 0;
75 struct thread_info *tp;
77 tp = xmalloc (sizeof (struct thread_info));
80 tp->num = ++highest_thread_num;
81 tp->next = thread_list;
85 static struct thread_info *
89 struct thread_info *tp;
91 for (tp = thread_list; tp; tp = tp->next)
102 struct thread_info *tp;
104 for (tp = thread_list; tp; tp = tp->next)
108 return 0; /* Never heard of 'im */
113 bfd_get_core_threads (abfd)
118 inferior_pid = BUILDPID (inferior_pid, core_thread (abfd)->pid);
119 for (i = 0; i < core_pss (abfd).threadcnt; i++)
120 add_thread (core_thread (abfd)[i].pid);
127 struct thread_info *tp, *tpprev;
131 for (tp = thread_list; tp; tp = tp->next)
135 tpprev->next = tp->next;
145 /* Print information about currently known threads */
148 info_threads_command (arg, from_tty)
152 struct thread_info *tp;
153 int current_pid = inferior_pid;
155 for (tp = thread_list; tp; tp = tp->next)
157 if (target_has_execution
158 && kill (tp->pid, 0) == -1)
160 tp->pid == -1; /* Mark it as dead */
164 if (tp->pid == current_pid)
165 printf_filtered ("* ");
167 printf_filtered (" ");
169 printf_filtered ("%d %s ", tp->num, target_pid_to_str (tp->pid));
171 thread_switch (tp->pid);
172 print_stack_frame (selected_frame, -1, 0);
175 thread_switch (current_pid);
179 /* Switch from one thread to another. */
185 if (pid == inferior_pid)
190 flush_cached_frames ();
191 registers_changed ();
193 set_current_frame (create_new_frame (read_fp (), stop_pc));
194 stop_frame_address = FRAME_FP (get_current_frame ());
195 select_frame (get_current_frame (), 0);
199 thread_command (tidstr, from_tty)
204 struct thread_info *tp;
207 error ("Please specify a thread ID. Use the \"info threads\" command to\n\
208 see the IDs of currently known threads.");
213 tp = find_thread_id (num);
216 error ("Thread ID %d not known. Use the \"info threads\" command to\n\
217 see the IDs of currently known threads.", num);
219 thread_switch (tp->pid);
221 printf_filtered ("[Switching to %s]\n", target_pid_to_str (inferior_pid));
222 print_stack_frame (selected_frame, selected_frame_level, 1);
226 _initialize_thread ()
228 add_info ("threads", info_threads_command,
229 "IDs of currently known threads.");
230 add_com ("thread", class_info, thread_command,
231 "Use this command to switch between threads.\n\
232 The new thread ID must be currently known.");