1 /* Multi-process/thread control for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1988, 1993
4 Contributed by Lynx Real-Time Systems, Inc. Los Gatos, CA.
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
32 #include <sys/types.h>
35 /*#include "lynxos-core.h"*/
39 struct thread_info
*next
;
40 int pid
; /* Actual process id */
41 int num
; /* Convenient handle */
44 static struct thread_info
*thread_list
= NULL
;
45 static int highest_thread_num
;
47 static void thread_info
PARAMS ((void));
49 static void thread_command
PARAMS ((char * tidstr
, int from_tty
));
51 static void prune_threads
PARAMS ((void));
53 static void thread_switch
PARAMS ((int pid
));
58 struct thread_info
*tp
, *tpnext
;
63 for (tp
= thread_list
; tp
; tp
= tpnext
)
70 highest_thread_num
= 0;
77 struct thread_info
*tp
;
79 tp
= xmalloc (sizeof (struct thread_info
));
82 tp
->num
= ++highest_thread_num
;
83 tp
->next
= thread_list
;
87 static struct thread_info
*
91 struct thread_info
*tp
;
93 for (tp
= thread_list
; tp
; tp
= tp
->next
)
104 struct thread_info
*tp
;
106 for (tp
= thread_list
; tp
; tp
= tp
->next
)
110 return 0; /* Never heard of 'im */
115 bfd_get_core_threads (abfd
)
120 inferior_pid
= BUILDPID (inferior_pid
, core_thread (abfd
)->pid
);
121 for (i
= 0; i
< core_pss (abfd
).threadcnt
; i
++)
122 add_thread (core_thread (abfd
)[i
].pid
);
129 struct thread_info
*tp
, *tpprev
;
133 for (tp
= thread_list
; tp
; tp
= tp
->next
)
137 tpprev
->next
= tp
->next
;
147 /* Print information about currently known threads */
150 info_threads_command (arg
, from_tty
)
154 struct thread_info
*tp
;
155 int current_pid
= inferior_pid
;
157 for (tp
= thread_list
; tp
; tp
= tp
->next
)
159 if (target_has_execution
160 && kill (tp
->pid
, 0) == -1)
162 tp
->pid
== -1; /* Mark it as dead */
166 if (tp
->pid
== current_pid
)
167 printf_filtered ("* ");
169 printf_filtered (" ");
171 printf_filtered ("%d %s ", tp
->num
, target_pid_to_str (tp
->pid
));
173 thread_switch (tp
->pid
);
174 print_stack_frame (selected_frame
, -1, 0);
177 thread_switch (current_pid
);
181 /* Switch from one thread to another. */
187 if (pid
== inferior_pid
)
192 flush_cached_frames ();
193 registers_changed ();
195 set_current_frame (create_new_frame (read_fp (), stop_pc
));
196 stop_frame_address
= FRAME_FP (get_current_frame ());
197 select_frame (get_current_frame (), 0);
201 thread_command (tidstr
, from_tty
)
206 struct thread_info
*tp
;
209 error ("Please specify a thread ID. Use the \"info threads\" command to\n\
210 see the IDs of currently known threads.");
215 tp
= find_thread_id (num
);
218 error ("Thread ID %d not known. Use the \"info threads\" command to\n\
219 see the IDs of currently known threads.", num
);
221 thread_switch (tp
->pid
);
223 printf_filtered ("[Switching to %s]\n", target_pid_to_str (inferior_pid
));
224 print_stack_frame (selected_frame
, selected_frame_level
, 1);
228 _initialize_thread ()
230 add_info ("threads", info_threads_command
,
231 "IDs of currently known threads.");
232 add_com ("thread", class_info
, thread_command
,
233 "Use this command to switch between threads.\n\
234 The new thread ID must be currently known.");
This page took 0.034403 seconds and 4 git commands to generate.