1 /* Inferior process information for the remote server for GDB.
3 Free Software Foundation, Inc.
5 Contributed by MontaVista Software.
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., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
30 struct inferior_list_entry entry;
35 struct inferior_list all_threads;
37 struct thread_info *current_inferior;
39 #define get_thread(inf) ((struct thread_info *)(inf))
42 add_inferior_to_list (struct inferior_list *list,
43 struct inferior_list_entry *new_inferior)
45 new_inferior->next = NULL;
46 if (list->tail != NULL)
47 list->tail->next = new_inferior;
49 list->head = new_inferior;
50 list->tail = new_inferior;
54 for_each_inferior (struct inferior_list *list,
55 void (*action) (struct inferior_list_entry *))
57 struct inferior_list_entry *cur = list->head, *next;
68 change_inferior_id (struct inferior_list *list,
71 if (list->head != list->tail)
72 error ("tried to change thread ID after multiple threads are created");
74 list->head->id = new_id;
78 remove_inferior (struct inferior_list *list,
79 struct inferior_list_entry *entry)
81 struct inferior_list_entry **cur;
83 if (list->head == entry)
85 list->head = entry->next;
86 if (list->tail == entry)
87 list->tail = list->head;
92 while (*cur && (*cur)->next != entry)
98 (*cur)->next = entry->next;
100 if (list->tail == entry)
105 add_thread (int thread_id, void *target_data)
107 struct thread_info *new_thread
108 = (struct thread_info *) malloc (sizeof (*new_thread));
110 memset (new_thread, 0, sizeof (*new_thread));
112 new_thread->entry.id = thread_id;
114 add_inferior_to_list (&all_threads, & new_thread->entry);
116 if (current_inferior == NULL)
117 current_inferior = new_thread;
119 new_thread->target_data = target_data;
120 set_inferior_regcache_data (new_thread, new_register_cache ());
124 free_one_thread (struct inferior_list_entry *inf)
126 struct thread_info *thread = get_thread (inf);
127 free_register_cache (inferior_regcache_data (thread));
132 remove_thread (struct thread_info *thread)
134 remove_inferior (&all_threads, (struct inferior_list_entry *) thread);
135 free_one_thread (&thread->entry);
139 clear_inferiors (void)
141 for_each_inferior (&all_threads, free_one_thread);
143 all_threads.head = all_threads.tail = NULL;
146 struct inferior_list_entry *
147 find_inferior (struct inferior_list *list,
148 int (*func) (struct inferior_list_entry *, void *), void *arg)
150 struct inferior_list_entry *inf = list->head;
154 if ((*func) (inf, arg))
162 struct inferior_list_entry *
163 find_inferior_id (struct inferior_list *list, int id)
165 struct inferior_list_entry *inf = list->head;
178 inferior_target_data (struct thread_info *inferior)
180 return inferior->target_data;
184 set_inferior_target_data (struct thread_info *inferior, void *data)
186 inferior->target_data = data;
190 inferior_regcache_data (struct thread_info *inferior)
192 return inferior->regcache_data;
196 set_inferior_regcache_data (struct thread_info *inferior, void *data)
198 inferior->regcache_data = data;