gdbserver: Use std::list for all_processes
[deliverable/binutils-gdb.git] / gdb / gdbserver / inferiors.h
CommitLineData
270c6aea 1/* Inferior process information for the remote server for GDB.
61baf725 2 Copyright (C) 1993-2017 Free Software Foundation, Inc.
270c6aea
PA
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef INFERIORS_H
20#define INFERIORS_H
21
82075af2 22#include "gdb_vecs.h"
9179355e 23#include <list>
82075af2 24
270c6aea
PA
25/* Generic information for tracking a list of ``inferiors'' - threads,
26 processes, etc. */
27struct inferior_list
28{
29 struct inferior_list_entry *head;
30 struct inferior_list_entry *tail;
31};
32struct inferior_list_entry
33{
34 ptid_t id;
35 struct inferior_list_entry *next;
36};
37
38struct thread_info;
a44892be 39struct regcache;
270c6aea
PA
40struct target_desc;
41struct sym_cache;
42struct breakpoint;
43struct raw_breakpoint;
44struct fast_tracepoint_jump;
45struct process_info_private;
46
47struct process_info
48{
9179355e
SM
49 /* This process' pid. */
50 int pid;
270c6aea
PA
51
52 /* Nonzero if this child process was attached rather than
53 spawned. */
54 int attached;
55
56 /* True if GDB asked us to detach from this process, but we remained
57 attached anyway. */
58 int gdb_detached;
59
60 /* The symbol cache. */
61 struct sym_cache *symbol_cache;
62
63 /* The list of memory breakpoints. */
64 struct breakpoint *breakpoints;
65
66 /* The list of raw memory breakpoints. */
67 struct raw_breakpoint *raw_breakpoints;
68
69 /* The list of installed fast tracepoints. */
70 struct fast_tracepoint_jump *fast_tracepoint_jumps;
71
82075af2
JS
72 /* The list of syscalls to report, or just a single element, ANY_SYSCALL,
73 for unfiltered syscall reporting. */
74 VEC (int) *syscalls_to_catch;
75
270c6aea
PA
76 const struct target_desc *tdesc;
77
78 /* Private target data. */
fe978cb0 79 struct process_info_private *priv;
270c6aea
PA
80};
81
9179355e
SM
82/* Get the pid of PROC. */
83
84static inline int
85pid_of (const process_info *proc)
86{
87 return proc->pid;
88}
d86d4aaf 89
270c6aea 90/* Return a pointer to the process that corresponds to the current
0bfdf32f 91 thread (current_thread). It is an error to call this if there is
270c6aea
PA
92 no current thread selected. */
93
94struct process_info *current_process (void);
63c40ec7 95struct process_info *get_thread_process (const struct thread_info *);
270c6aea 96
9179355e 97extern std::list<process_info *> all_processes;
270c6aea
PA
98
99void add_inferior_to_list (struct inferior_list *list,
100 struct inferior_list_entry *new_inferior);
101void for_each_inferior (struct inferior_list *list,
102 void (*action) (struct inferior_list_entry *));
103
649ebbca
DE
104void for_each_inferior_with_data
105 (struct inferior_list *list,
106 void (*action) (struct inferior_list_entry *, void *),
107 void *data);
108
109void clear_inferior_list (struct inferior_list *list);
110
111int one_inferior_p (struct inferior_list *list);
112
fa96cb38
PA
113/* Helper for ALL_INFERIORS_TYPE. Gets the next element starting at
114 CUR, if CUR is not NULL. */
115#define A_I_NEXT(type, list, cur) \
116 ((cur) != NULL \
117 ? (type *) ((struct inferior_list_entry *) cur)->next \
118 : NULL)
119
120/* Iterate over all inferiors of type TYPE in LIST, open loop
121 style. */
122#define ALL_INFERIORS_TYPE(type, list, cur, tmp) \
123 for ((cur) = (type *) (list)->head, (tmp) = A_I_NEXT (type, list, cur); \
124 (cur) != NULL; \
125 (cur) = (tmp), (tmp) = A_I_NEXT (type, list, cur))
126
127/* Iterate over all inferiors in LIST, open loop style. */
128#define ALL_INFERIORS(list, cur, tmp) \
129 ALL_INFERIORS_TYPE (struct inferior_list_entry, list, cur, tmp)
130
9179355e
SM
131/* Invoke FUNC for each process. */
132
133template <typename Func>
134static void
135for_each_process (Func func)
136{
137 std::list<process_info *>::iterator next, cur = all_processes.begin ();
138
139 while (cur != all_processes.end ())
140 {
141 next = cur;
142 next++;
143 func (*cur);
144 cur = next;
145 }
146}
147
148/* Find the first process for which FUNC returns true. Return NULL if no
149 process satisfying FUNC is found. */
150
151template <typename Func>
152static process_info *
153find_process (Func func)
154{
155 std::list<process_info *>::iterator next, cur = all_processes.begin ();
156
157 while (cur != all_processes.end ())
158 {
159 next = cur;
160 next++;
161
162 if (func (*cur))
163 return *cur;
164
165 cur = next;
166 }
167
168 return NULL;
169}
fa96cb38 170
0bfdf32f 171extern struct thread_info *current_thread;
270c6aea
PA
172void remove_inferior (struct inferior_list *list,
173 struct inferior_list_entry *entry);
174
649ebbca
DE
175struct inferior_list_entry *get_first_inferior (struct inferior_list *list);
176
3d40fbb5
PA
177/* Return the first process in the processes list. */
178struct process_info *get_first_process (void);
179
270c6aea
PA
180struct process_info *add_process (int pid, int attached);
181void remove_process (struct process_info *process);
182struct process_info *find_process_pid (int pid);
183int have_started_inferiors_p (void);
184int have_attached_inferiors_p (void);
185
270c6aea
PA
186void clear_inferiors (void);
187struct inferior_list_entry *find_inferior
188 (struct inferior_list *,
189 int (*func) (struct inferior_list_entry *,
190 void *),
191 void *arg);
192struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
193 ptid_t id);
89342618
YQ
194struct inferior_list_entry *
195 find_inferior_in_random (struct inferior_list *,
196 int (*func) (struct inferior_list_entry *,
197 void *),
198 void *arg);
80894984 199
6afd337d
SM
200void *thread_target_data (struct thread_info *);
201struct regcache *thread_regcache_data (struct thread_info *);
202void set_thread_regcache_data (struct thread_info *, struct regcache *);
270c6aea
PA
203
204#endif /* INFERIORS_H */
This page took 0.33527 seconds and 4 git commands to generate.