Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Variables that describe the inferior process running under GDB: |
2 | Where it is, why it stopped, and how to step it. | |
1bac305b | 3 | |
e2882c85 | 4 | Copyright (C) 1986-2018 Free Software Foundation, Inc. |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 11 | (at your option) any later version. |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b | 18 | You should have received a copy of the GNU General Public License |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
20 | |
21 | #if !defined (INFERIOR_H) | |
22 | #define INFERIOR_H 1 | |
23 | ||
da3331ec AC |
24 | struct target_waitstatus; |
25 | struct frame_info; | |
26 | struct ui_file; | |
27 | struct type; | |
67a2b77e | 28 | struct gdbarch; |
72cec141 | 29 | struct regcache; |
b77209e0 | 30 | struct ui_out; |
7e1789f5 | 31 | struct terminal_info; |
6ecd4729 | 32 | struct target_desc_info; |
0550c955 | 33 | struct continuation; |
3a3fd0fd | 34 | struct inferior; |
00431a78 | 35 | struct thread_info; |
67a2b77e | 36 | |
c906108c SS |
37 | /* For bpstat. */ |
38 | #include "breakpoint.h" | |
39 | ||
2ea28649 | 40 | /* For enum gdb_signal. */ |
c906108c SS |
41 | #include "target.h" |
42 | ||
aa0cd9c1 AC |
43 | /* For struct frame_id. */ |
44 | #include "frame.h" | |
45 | ||
9a6c7d9c SDJ |
46 | /* For gdb_environ. */ |
47 | #include "environ.h" | |
48 | ||
6c95b8df | 49 | #include "progspace.h" |
8e260fc0 | 50 | #include "registry.h" |
6c95b8df | 51 | |
b15cc25c | 52 | #include "symfile-add-flags.h" |
3a3fd0fd | 53 | #include "common/refcounted-object.h" |
b15cc25c | 54 | |
2090129c | 55 | #include "common-inferior.h" |
08036331 | 56 | #include "gdbthread.h" |
2090129c | 57 | |
16c381f0 JK |
58 | struct infcall_suspend_state; |
59 | struct infcall_control_state; | |
7a292a7a | 60 | |
16c381f0 JK |
61 | extern void restore_infcall_suspend_state (struct infcall_suspend_state *); |
62 | extern void restore_infcall_control_state (struct infcall_control_state *); | |
b89667eb | 63 | |
c7c4d3fa TT |
64 | /* A deleter for infcall_suspend_state that calls |
65 | restore_infcall_suspend_state. */ | |
66 | struct infcall_suspend_state_deleter | |
67 | { | |
68 | void operator() (struct infcall_suspend_state *state) const | |
69 | { | |
70 | restore_infcall_suspend_state (state); | |
71 | } | |
72 | }; | |
73 | ||
74 | /* A unique_ptr specialization for infcall_suspend_state. */ | |
75 | typedef std::unique_ptr<infcall_suspend_state, infcall_suspend_state_deleter> | |
76 | infcall_suspend_state_up; | |
77 | ||
cb524840 TT |
78 | extern infcall_suspend_state_up save_infcall_suspend_state (); |
79 | ||
c7c4d3fa TT |
80 | /* A deleter for infcall_control_state that calls |
81 | restore_infcall_control_state. */ | |
82 | struct infcall_control_state_deleter | |
83 | { | |
84 | void operator() (struct infcall_control_state *state) const | |
85 | { | |
86 | restore_infcall_control_state (state); | |
87 | } | |
88 | }; | |
89 | ||
90 | /* A unique_ptr specialization for infcall_control_state. */ | |
91 | typedef std::unique_ptr<infcall_control_state, infcall_control_state_deleter> | |
92 | infcall_control_state_up; | |
b89667eb | 93 | |
cb524840 TT |
94 | extern infcall_control_state_up save_infcall_control_state (); |
95 | ||
16c381f0 JK |
96 | extern void discard_infcall_suspend_state (struct infcall_suspend_state *); |
97 | extern void discard_infcall_control_state (struct infcall_control_state *); | |
7a292a7a | 98 | |
daf6667d | 99 | extern readonly_detached_regcache * |
16c381f0 | 100 | get_infcall_suspend_state_regcache (struct infcall_suspend_state *); |
b89667eb | 101 | |
a14ed312 | 102 | extern void set_sigint_trap (void); |
c906108c | 103 | |
a14ed312 | 104 | extern void clear_sigint_trap (void); |
c906108c | 105 | |
3cb3b8df | 106 | /* Set/get file name for default use for standard in/out in the inferior. */ |
c906108c | 107 | |
3cb3b8df BR |
108 | extern void set_inferior_io_terminal (const char *terminal_name); |
109 | extern const char *get_inferior_io_terminal (void); | |
c906108c | 110 | |
39f77062 | 111 | /* Collected pid, tid, etc. of the debugged inferior. When there's |
e99b03dc | 112 | no inferior, inferior_ptid.pid () will be 0. */ |
c906108c | 113 | |
39f77062 | 114 | extern ptid_t inferior_ptid; |
c906108c | 115 | |
a14ed312 | 116 | extern void generic_mourn_inferior (void); |
c906108c | 117 | |
9898f801 UW |
118 | extern CORE_ADDR unsigned_pointer_to_address (struct gdbarch *gdbarch, |
119 | struct type *type, | |
b60c417a | 120 | const gdb_byte *buf); |
9898f801 UW |
121 | extern void unsigned_address_to_pointer (struct gdbarch *gdbarch, |
122 | struct type *type, gdb_byte *buf, | |
ac2e2ef7 | 123 | CORE_ADDR addr); |
9898f801 UW |
124 | extern CORE_ADDR signed_pointer_to_address (struct gdbarch *gdbarch, |
125 | struct type *type, | |
b60c417a | 126 | const gdb_byte *buf); |
9898f801 UW |
127 | extern void address_to_signed_pointer (struct gdbarch *gdbarch, |
128 | struct type *type, gdb_byte *buf, | |
ac2e2ef7 | 129 | CORE_ADDR addr); |
4478b372 | 130 | |
a14ed312 | 131 | extern void reopen_exec_file (void); |
c906108c | 132 | |
c906108c SS |
133 | /* From misc files */ |
134 | ||
0ab7a791 AC |
135 | extern void default_print_registers_info (struct gdbarch *gdbarch, |
136 | struct ui_file *file, | |
137 | struct frame_info *frame, | |
138 | int regnum, int all); | |
666e11c5 | 139 | |
cc86d1cb YQ |
140 | /* Default implementation of gdbarch_print_float_info. Print |
141 | the values of all floating point registers. */ | |
142 | ||
143 | extern void default_print_float_info (struct gdbarch *gdbarch, | |
144 | struct ui_file *file, | |
145 | struct frame_info *frame, | |
146 | const char *args); | |
147 | ||
0a4f40a2 | 148 | extern void child_terminal_info (struct target_ops *self, const char *, int); |
c906108c | 149 | |
11db9430 | 150 | extern void info_terminal_command (char *, int); |
c906108c | 151 | |
d6b64346 PA |
152 | extern void child_terminal_ours (struct target_ops *self); |
153 | ||
154 | extern void child_terminal_ours_for_output (struct target_ops *self); | |
c906108c | 155 | |
d6b64346 | 156 | extern void child_terminal_inferior (struct target_ops *self); |
c906108c | 157 | |
e671cd59 PA |
158 | extern void child_terminal_save_inferior (struct target_ops *self); |
159 | ||
d6b64346 | 160 | extern void child_terminal_init (struct target_ops *self); |
c906108c | 161 | |
d6b64346 | 162 | extern void child_terminal_init_with_pgrp (int pgrp); |
c906108c | 163 | |
e671cd59 PA |
164 | extern void child_pass_ctrlc (struct target_ops *self); |
165 | ||
166 | extern void child_interrupt (struct target_ops *self); | |
167 | ||
c906108c SS |
168 | /* From fork-child.c */ |
169 | ||
2090129c SDJ |
170 | /* Helper function to call STARTUP_INFERIOR with PID and NUM_TRAPS. |
171 | This function already calls set_executing. Return the ptid_t from | |
172 | STARTUP_INFERIOR. */ | |
173 | extern ptid_t gdb_startup_inferior (pid_t pid, int num_traps); | |
c906108c | 174 | |
bd57a748 | 175 | extern char *construct_inferior_arguments (int, char **); |
552c04a7 | 176 | |
c906108c SS |
177 | /* From infcmd.c */ |
178 | ||
6efcd9a8 PA |
179 | /* Initial inferior setup. Determines the exec file is not yet known, |
180 | takes any necessary post-attaching actions, fetches the target | |
181 | description and syncs the shared library list. */ | |
182 | ||
183 | extern void setup_inferior (int from_tty); | |
184 | ||
281b533b DJ |
185 | extern void post_create_inferior (struct target_ops *, int); |
186 | ||
0b39b52e | 187 | extern void attach_command (const char *, int); |
c906108c | 188 | |
cbaaa0ca | 189 | extern const char *get_inferior_args (void); |
07091751 | 190 | |
0b39b52e | 191 | extern void set_inferior_args (const char *); |
07091751 | 192 | |
552c04a7 TT |
193 | extern void set_inferior_args_vector (int, char **); |
194 | ||
1d12d88f | 195 | extern void registers_info (const char *, int); |
36dc181b | 196 | |
77ebaa5a VP |
197 | extern void continue_1 (int all_threads); |
198 | ||
77ebaa5a VP |
199 | extern void interrupt_target_1 (int all_threads); |
200 | ||
186c406b TT |
201 | extern void delete_longjmp_breakpoint_cleanup (void *arg); |
202 | ||
981a3fb3 | 203 | extern void detach_command (const char *, int); |
6418d433 | 204 | |
75cbc781 | 205 | extern void notice_new_inferior (struct thread_info *, int, int); |
1941c569 | 206 | |
0700e23e PA |
207 | extern struct value *get_return_value (struct value *function, |
208 | struct type *value_type); | |
cc72b2a2 | 209 | |
329ea579 PA |
210 | /* Prepare for execution command. TARGET is the target that will run |
211 | the command. BACKGROUND determines whether this is a foreground | |
212 | (synchronous) or background (asynchronous) command. */ | |
213 | ||
214 | extern void prepare_execution_command (struct target_ops *target, | |
215 | int background); | |
216 | ||
98882a26 PA |
217 | /* Whether to start up the debuggee under a shell. |
218 | ||
219 | If startup-with-shell is set, GDB's "run" will attempt to start up | |
220 | the debuggee under a shell. | |
221 | ||
222 | This is in order for argument-expansion to occur. E.g., | |
223 | ||
224 | (gdb) run * | |
225 | ||
226 | The "*" gets expanded by the shell into a list of files. | |
227 | ||
228 | While this is a nice feature, it may be handy to bypass the shell | |
229 | in some cases. To disable this feature, do "set startup-with-shell | |
230 | false". | |
231 | ||
232 | The catch-exec traps expected during start-up will be one more if | |
233 | the target is started up with a shell. */ | |
234 | extern int startup_with_shell; | |
235 | ||
c906108c SS |
236 | /* Nonzero if stopped due to completion of a stack dummy routine. */ |
237 | ||
aa7d318d | 238 | extern enum stop_stack_kind stop_stack_dummy; |
c906108c SS |
239 | |
240 | /* Nonzero if program stopped due to a random (unexpected) signal in | |
241 | inferior process. */ | |
242 | ||
243 | extern int stopped_by_random_signal; | |
244 | ||
f67c0c91 SDJ |
245 | /* Print notices on inferior events (attach, detach, etc.), set with |
246 | `set print inferior-events'. */ | |
247 | extern int print_inferior_events; | |
248 | ||
b0f4b84b DJ |
249 | /* Anything but NO_STOP_QUIETLY means we expect a trap and the caller |
250 | will handle it themselves. STOP_QUIETLY is used when running in | |
251 | the shell before the child program has been exec'd and when running | |
252 | through shared library loading. STOP_QUIETLY_REMOTE is used when | |
253 | setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP | |
254 | except that there is no need to hide a signal. */ | |
c54cfec8 | 255 | |
7c0bc051 DE |
256 | /* STOP_QUIETLY_NO_SIGSTOP is used to handle a tricky situation with attach. |
257 | When doing an attach, the kernel stops the debuggee with a SIGSTOP. | |
258 | On newer GNU/Linux kernels (>= 2.5.61) the handling of SIGSTOP for | |
259 | a ptraced process has changed. Earlier versions of the kernel | |
260 | would ignore these SIGSTOPs, while now SIGSTOP is treated like any | |
261 | other signal, i.e. it is not muffled. | |
262 | ||
c54cfec8 EZ |
263 | If the gdb user does a 'continue' after the 'attach', gdb passes |
264 | the global variable stop_signal (which stores the signal from the | |
265 | attach, SIGSTOP) to the ptrace(PTRACE_CONT,...) call. This is | |
266 | problematic, because the kernel doesn't ignore such SIGSTOP | |
1777feb0 | 267 | now. I.e. it is reported back to gdb, which in turn presents it |
c54cfec8 | 268 | back to the user. |
7c0bc051 | 269 | |
c54cfec8 EZ |
270 | To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows |
271 | gdb to clear the value of stop_signal after the attach, so that it | |
272 | is not passed back down to the kernel. */ | |
273 | ||
274 | enum stop_kind | |
275 | { | |
276 | NO_STOP_QUIETLY = 0, | |
277 | STOP_QUIETLY, | |
b0f4b84b | 278 | STOP_QUIETLY_REMOTE, |
c54cfec8 EZ |
279 | STOP_QUIETLY_NO_SIGSTOP |
280 | }; | |
c906108c | 281 | |
c906108c | 282 | \f |
faaf634c | 283 | /* Possible values for gdbarch_call_dummy_location. */ |
c906108c | 284 | #define ON_STACK 1 |
c906108c SS |
285 | #define AT_ENTRY_POINT 4 |
286 | ||
089354bb SM |
287 | /* Base class for target-specific inferior data. */ |
288 | ||
289 | struct private_inferior | |
290 | { | |
291 | virtual ~private_inferior () = 0; | |
292 | }; | |
b77209e0 | 293 | |
16c381f0 JK |
294 | /* Inferior process specific part of `struct infcall_control_state'. |
295 | ||
296 | Inferior thread counterpart is `struct thread_control_state'. */ | |
297 | ||
298 | struct inferior_control_state | |
299 | { | |
ee841dd8 TT |
300 | inferior_control_state () |
301 | : stop_soon (NO_STOP_QUIETLY) | |
302 | { | |
303 | } | |
304 | ||
305 | explicit inferior_control_state (enum stop_kind when) | |
306 | : stop_soon (when) | |
307 | { | |
308 | } | |
309 | ||
16c381f0 JK |
310 | /* See the definition of stop_kind above. */ |
311 | enum stop_kind stop_soon; | |
312 | }; | |
313 | ||
3a3fd0fd PA |
314 | /* Return a pointer to the current inferior. */ |
315 | extern inferior *current_inferior (); | |
316 | ||
317 | extern void set_current_inferior (inferior *); | |
318 | ||
b77209e0 PA |
319 | /* GDB represents the state of each program execution with an object |
320 | called an inferior. An inferior typically corresponds to a process | |
321 | but is more general and applies also to targets that do not have a | |
322 | notion of processes. Each run of an executable creates a new | |
323 | inferior, as does each attachment to an existing process. | |
324 | Inferiors have unique internal identifiers that are different from | |
325 | target process ids. Each inferior may in turn have multiple | |
3a3fd0fd PA |
326 | threads running in it. |
327 | ||
328 | Inferiors are intrusively refcounted objects. Unlike thread | |
329 | objects, being the user-selected inferior is considered a strong | |
330 | reference and is thus accounted for in the inferior object's | |
331 | refcount (see set_current_inferior). When GDB needs to remember | |
332 | the selected inferior to later restore it, GDB temporarily bumps | |
333 | the inferior object's refcount, to prevent something deleting the | |
334 | inferior object before reverting back (e.g., due to a | |
335 | "remove-inferiors" command (see | |
336 | make_cleanup_restore_current_thread). All other inferior | |
337 | references are considered weak references. Inferiors are always | |
338 | listed exactly once in the inferior list, so placing an inferior in | |
339 | the inferior list is an implicit, not counted strong reference. */ | |
340 | ||
341 | class inferior : public refcounted_object | |
b77209e0 | 342 | { |
0550c955 PA |
343 | public: |
344 | explicit inferior (int pid); | |
345 | ~inferior (); | |
346 | ||
3a3fd0fd PA |
347 | /* Returns true if we can delete this inferior. */ |
348 | bool deletable () const { return refcount () == 0; } | |
349 | ||
b77209e0 | 350 | /* Pointer to next inferior in singly-linked list of inferiors. */ |
0550c955 | 351 | struct inferior *next = NULL; |
b77209e0 | 352 | |
08036331 PA |
353 | /* This inferior's thread list. */ |
354 | thread_info *thread_list = nullptr; | |
355 | ||
356 | /* Returns a range adapter covering the inferior's threads, | |
357 | including exited threads. Used like this: | |
358 | ||
359 | for (thread_info *thr : inf->threads ()) | |
360 | { .... } | |
361 | */ | |
362 | inf_threads_range threads () | |
363 | { return inf_threads_range (this->thread_list); } | |
364 | ||
365 | /* Returns a range adapter covering the inferior's non-exited | |
366 | threads. Used like this: | |
367 | ||
368 | for (thread_info *thr : inf->non_exited_threads ()) | |
369 | { .... } | |
370 | */ | |
371 | inf_non_exited_threads_range non_exited_threads () | |
372 | { return inf_non_exited_threads_range (this->thread_list); } | |
373 | ||
374 | /* Like inferior::threads(), but returns a range adapter that can be | |
375 | used with range-for, safely. I.e., it is safe to delete the | |
376 | currently-iterated thread, like this: | |
377 | ||
378 | for (thread_info *t : inf->threads_safe ()) | |
379 | if (some_condition ()) | |
380 | delete f; | |
381 | */ | |
382 | inline safe_inf_threads_range threads_safe () | |
383 | { return safe_inf_threads_range (this->thread_list); } | |
384 | ||
b77209e0 PA |
385 | /* Convenient handle (GDB inferior id). Unique across all |
386 | inferiors. */ | |
0550c955 | 387 | int num = 0; |
b77209e0 PA |
388 | |
389 | /* Actual target inferior id, usually, a process id. This matches | |
390 | the ptid_t.pid member of threads of this inferior. */ | |
0550c955 | 391 | int pid = 0; |
e714e1bf | 392 | /* True if the PID was actually faked by GDB. */ |
0550c955 | 393 | bool fake_pid_p = false; |
b77209e0 | 394 | |
5d5658a1 | 395 | /* The highest thread number this inferior ever had. */ |
0550c955 | 396 | int highest_thread_num = 0; |
5d5658a1 | 397 | |
16c381f0 JK |
398 | /* State of GDB control of inferior process execution. |
399 | See `struct inferior_control_state'. */ | |
ee841dd8 | 400 | inferior_control_state control; |
16c381f0 | 401 | |
6c95b8df PA |
402 | /* True if this was an auto-created inferior, e.g. created from |
403 | following a fork; false, if this inferior was manually added by | |
404 | the user, and we should not attempt to prune it | |
405 | automatically. */ | |
0550c955 | 406 | bool removable = false; |
6c95b8df PA |
407 | |
408 | /* The address space bound to this inferior. */ | |
0550c955 | 409 | struct address_space *aspace = NULL; |
6c95b8df PA |
410 | |
411 | /* The program space bound to this inferior. */ | |
0550c955 | 412 | struct program_space *pspace = NULL; |
6c95b8df | 413 | |
3f81c18a | 414 | /* The arguments string to use when running. */ |
0550c955 | 415 | char *args = NULL; |
3f81c18a VP |
416 | |
417 | /* The size of elements in argv. */ | |
0550c955 | 418 | int argc = 0; |
3f81c18a VP |
419 | |
420 | /* The vector version of arguments. If ARGC is nonzero, | |
421 | then we must compute ARGS from this (via the target). | |
422 | This is always coming from main's argv and therefore | |
423 | should never be freed. */ | |
0550c955 | 424 | char **argv = NULL; |
3f81c18a | 425 | |
d092c5a2 SDJ |
426 | /* The current working directory that will be used when starting |
427 | this inferior. */ | |
428 | gdb::unique_xmalloc_ptr<char> cwd; | |
429 | ||
3f81c18a | 430 | /* The name of terminal device to use for I/O. */ |
0550c955 | 431 | char *terminal = NULL; |
3f81c18a | 432 | |
e671cd59 PA |
433 | /* The terminal state as set by the last target_terminal::terminal_* |
434 | call. */ | |
435 | target_terminal_state terminal_state = target_terminal_state::is_ours; | |
436 | ||
3f81c18a VP |
437 | /* Environment to use for running inferior, |
438 | in format described in environ.h. */ | |
9a6c7d9c | 439 | gdb_environ environment; |
3f81c18a | 440 | |
0550c955 PA |
441 | /* True if this child process was attached rather than forked. */ |
442 | bool attach_flag = false; | |
181e7f93 | 443 | |
6c95b8df PA |
444 | /* If this inferior is a vfork child, then this is the pointer to |
445 | its vfork parent, if GDB is still attached to it. */ | |
0550c955 | 446 | inferior *vfork_parent = NULL; |
6c95b8df PA |
447 | |
448 | /* If this process is a vfork parent, this is the pointer to the | |
449 | child. Since a vfork parent is left frozen by the kernel until | |
450 | the child execs or exits, a process can only have one vfork child | |
451 | at a given time. */ | |
0550c955 | 452 | inferior *vfork_child = NULL; |
6c95b8df PA |
453 | |
454 | /* True if this inferior should be detached when it's vfork sibling | |
455 | exits or execs. */ | |
0550c955 | 456 | bool pending_detach = false; |
6c95b8df PA |
457 | |
458 | /* True if this inferior is a vfork parent waiting for a vfork child | |
459 | not under our control to be done with the shared memory region, | |
460 | either by exiting or execing. */ | |
0550c955 | 461 | bool waiting_for_vfork_done = false; |
6c95b8df | 462 | |
24291992 | 463 | /* True if we're in the process of detaching from this inferior. */ |
9bcb1f16 | 464 | bool detaching = false; |
24291992 | 465 | |
e0ba6746 PA |
466 | /* What is left to do for an execution command after any thread of |
467 | this inferior stops. For continuations associated with a | |
468 | specific thread, see `struct thread_info'. */ | |
0550c955 | 469 | continuation *continuations = NULL; |
e0ba6746 | 470 | |
6efcd9a8 PA |
471 | /* True if setup_inferior wasn't called for this inferior yet. |
472 | Until that is done, we must not access inferior memory or | |
473 | registers, as we haven't determined the target | |
474 | architecture/description. */ | |
0550c955 | 475 | bool needs_setup = false; |
6efcd9a8 | 476 | |
b77209e0 | 477 | /* Private data used by the target vector implementation. */ |
089354bb | 478 | std::unique_ptr<private_inferior> priv; |
a96d9b2e | 479 | |
8cf64490 TT |
480 | /* HAS_EXIT_CODE is true if the inferior exited with an exit code. |
481 | In this case, the EXIT_CODE field is also valid. */ | |
0550c955 PA |
482 | bool has_exit_code = false; |
483 | LONGEST exit_code = 0; | |
8cf64490 | 484 | |
7dcd53a0 | 485 | /* Default flags to pass to the symbol reading functions. These are |
b15cc25c | 486 | used whenever a new objfile is created. */ |
0550c955 | 487 | symfile_add_flags symfile_flags = 0; |
7dcd53a0 | 488 | |
6ecd4729 PA |
489 | /* Info about an inferior's target description (if it's fetched; the |
490 | user supplied description's filename, if any; etc.). */ | |
0550c955 | 491 | target_desc_info *tdesc_info = NULL; |
6ecd4729 PA |
492 | |
493 | /* The architecture associated with the inferior through the | |
494 | connection to the target. | |
495 | ||
496 | The architecture vector provides some information that is really | |
497 | a property of the inferior, accessed through a particular target: | |
498 | ptrace operations; the layout of certain RSP packets; the | |
499 | solib_ops vector; etc. To differentiate architecture accesses to | |
500 | per-inferior/target properties from | |
501 | per-thread/per-frame/per-objfile properties, accesses to | |
502 | per-inferior/target properties should be made through | |
503 | this gdbarch. */ | |
0550c955 | 504 | struct gdbarch *gdbarch = NULL; |
6ecd4729 | 505 | |
6c95b8df | 506 | /* Per inferior data-pointers required by other GDB modules. */ |
8e260fc0 | 507 | REGISTRY_FIELDS; |
b77209e0 PA |
508 | }; |
509 | ||
6c95b8df PA |
510 | /* Keep a registry of per-inferior data-pointers required by other GDB |
511 | modules. */ | |
512 | ||
8e260fc0 | 513 | DECLARE_REGISTRY (inferior); |
6c95b8df | 514 | |
b77209e0 PA |
515 | /* Add an inferior to the inferior list, print a message that a new |
516 | inferior is found, and return the pointer to the new inferior. | |
517 | Caller may use this pointer to initialize the private inferior | |
518 | data. */ | |
519 | extern struct inferior *add_inferior (int pid); | |
520 | ||
521 | /* Same as add_inferior, but don't print new inferior notifications to | |
522 | the CLI. */ | |
523 | extern struct inferior *add_inferior_silent (int pid); | |
524 | ||
7a41607e | 525 | extern void delete_inferior (struct inferior *todel); |
b77209e0 PA |
526 | |
527 | /* Delete an existing inferior list entry, due to inferior detaching. */ | |
bc09b0c1 SM |
528 | extern void detach_inferior (inferior *inf); |
529 | ||
00431a78 | 530 | extern void exit_inferior (inferior *inf); |
b77209e0 | 531 | |
00431a78 | 532 | extern void exit_inferior_silent (inferior *inf); |
6c95b8df PA |
533 | |
534 | extern void exit_inferior_num_silent (int num); | |
535 | ||
536 | extern void inferior_appeared (struct inferior *inf, int pid); | |
537 | ||
82f73884 PA |
538 | /* Get rid of all inferiors. */ |
539 | extern void discard_all_inferiors (void); | |
540 | ||
6c95b8df | 541 | /* Search function to lookup an inferior by target 'pid'. */ |
b77209e0 PA |
542 | extern struct inferior *find_inferior_pid (int pid); |
543 | ||
c9657e70 SM |
544 | /* Search function to lookup an inferior whose pid is equal to 'ptid.pid'. */ |
545 | extern struct inferior *find_inferior_ptid (ptid_t ptid); | |
546 | ||
6c95b8df PA |
547 | /* Search function to lookup an inferior by GDB 'num'. */ |
548 | extern struct inferior *find_inferior_id (int num); | |
549 | ||
32990ada PA |
550 | /* Find an inferior bound to PSPACE, giving preference to the current |
551 | inferior. */ | |
6c95b8df PA |
552 | extern struct inferior * |
553 | find_inferior_for_program_space (struct program_space *pspace); | |
554 | ||
b77209e0 PA |
555 | /* Inferior iterator function. |
556 | ||
557 | Calls a callback function once for each inferior, so long as the | |
558 | callback function returns false. If the callback function returns | |
559 | true, the iteration will end and the current inferior will be | |
560 | returned. This can be useful for implementing a search for a | |
561 | inferior with arbitrary attributes, or for applying some operation | |
562 | to every inferior. | |
563 | ||
564 | It is safe to delete the iterated inferior from the callback. */ | |
565 | extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *, | |
566 | void *), | |
567 | void *); | |
568 | ||
b77209e0 PA |
569 | /* Returns true if the inferior list is not empty. */ |
570 | extern int have_inferiors (void); | |
571 | ||
8020350c DB |
572 | /* Returns the number of live inferiors (real live processes). */ |
573 | extern int number_of_live_inferiors (void); | |
574 | ||
c35b1492 PA |
575 | /* Returns true if there are any live inferiors in the inferior list |
576 | (not cores, not executables, real live processes). */ | |
577 | extern int have_live_inferiors (void); | |
578 | ||
5ed8105e PA |
579 | /* Save/restore the current inferior. */ |
580 | ||
581 | class scoped_restore_current_inferior | |
582 | { | |
583 | public: | |
584 | scoped_restore_current_inferior () | |
585 | : m_saved_inf (current_inferior ()) | |
586 | {} | |
587 | ||
588 | ~scoped_restore_current_inferior () | |
589 | { set_current_inferior (m_saved_inf); } | |
590 | ||
d6541620 | 591 | DISABLE_COPY_AND_ASSIGN (scoped_restore_current_inferior); |
5ed8105e PA |
592 | |
593 | private: | |
594 | inferior *m_saved_inf; | |
595 | }; | |
596 | ||
6c95b8df | 597 | |
c65b3e0d PA |
598 | /* Traverse all inferiors. */ |
599 | ||
08036331 | 600 | extern struct inferior *inferior_list; |
c65b3e0d | 601 | |
08036331 PA |
602 | /* Pull in the internals of the inferiors ranges and iterators. Must |
603 | be done after struct inferior is defined. */ | |
604 | #include "inferior-iter.h" | |
85ad3aaf | 605 | |
08036331 PA |
606 | /* Return a range that can be used to walk over all inferiors |
607 | inferiors, with range-for, safely. I.e., it is safe to delete the | |
608 | currently-iterated inferior. When combined with range-for, this | |
609 | allow convenient patterns like this: | |
85ad3aaf | 610 | |
08036331 PA |
611 | for (inferior *inf : all_inferiors_safe ()) |
612 | if (some_condition ()) | |
613 | delete inf; | |
614 | */ | |
615 | ||
616 | inline all_inferiors_safe_range | |
617 | all_inferiors_safe () | |
618 | { | |
619 | return {}; | |
620 | } | |
621 | ||
622 | /* Returns a range representing all inferiors, suitable to use with | |
623 | range-for, like this: | |
624 | ||
625 | for (inferior *inf : all_inferiors ()) | |
626 | [...] | |
627 | */ | |
628 | ||
629 | inline all_inferiors_range | |
630 | all_inferiors () | |
631 | { | |
632 | return {}; | |
633 | } | |
634 | ||
635 | /* Return a range that can be used to walk over all inferiors with PID | |
636 | not zero, with range-for. */ | |
637 | ||
638 | inline all_non_exited_inferiors_range | |
639 | all_non_exited_inferiors () | |
640 | { | |
641 | return {}; | |
642 | } | |
6c95b8df PA |
643 | |
644 | /* Prune away automatically added inferiors that aren't required | |
645 | anymore. */ | |
646 | extern void prune_inferiors (void); | |
647 | ||
648 | extern int number_of_inferiors (void); | |
649 | ||
a79b8f6e VP |
650 | extern struct inferior *add_inferior_with_spaces (void); |
651 | ||
4034d0ff AT |
652 | /* Print the current selected inferior. */ |
653 | extern void print_selected_inferior (struct ui_out *uiout); | |
654 | ||
c906108c | 655 | #endif /* !defined (INFERIOR_H) */ |