inferior.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /* Variables that describe the inferior process running under GDB:
  2. Where it is, why it stopped, and how to step it.
  3. Copyright (C) 1986-2022 Free Software Foundation, Inc.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #if !defined (INFERIOR_H)
  16. #define INFERIOR_H 1
  17. #include <exception>
  18. #include <list>
  19. struct target_waitstatus;
  20. struct frame_info;
  21. struct ui_file;
  22. struct type;
  23. struct gdbarch;
  24. struct regcache;
  25. struct ui_out;
  26. struct terminal_info;
  27. struct target_desc_info;
  28. struct inferior;
  29. struct thread_info;
  30. /* For bpstat. */
  31. #include "breakpoint.h"
  32. /* For enum gdb_signal. */
  33. #include "target.h"
  34. /* For struct frame_id. */
  35. #include "frame.h"
  36. /* For gdb_environ. */
  37. #include "gdbsupport/environ.h"
  38. #include "progspace.h"
  39. #include "registry.h"
  40. #include "symfile-add-flags.h"
  41. #include "gdbsupport/refcounted-object.h"
  42. #include "gdbsupport/forward-scope-exit.h"
  43. #include "gdbsupport/gdb_unique_ptr.h"
  44. #include "gdbsupport/intrusive_list.h"
  45. #include "gdbsupport/common-inferior.h"
  46. #include "gdbthread.h"
  47. #include "process-stratum-target.h"
  48. #include "displaced-stepping.h"
  49. #include <unordered_map>
  50. struct infcall_suspend_state;
  51. struct infcall_control_state;
  52. extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
  53. extern void restore_infcall_control_state (struct infcall_control_state *);
  54. /* A deleter for infcall_suspend_state that calls
  55. restore_infcall_suspend_state. */
  56. struct infcall_suspend_state_deleter
  57. {
  58. void operator() (struct infcall_suspend_state *state) const
  59. {
  60. try
  61. {
  62. restore_infcall_suspend_state (state);
  63. }
  64. catch (const gdb_exception_error &e)
  65. {
  66. /* If we are restoring the inferior state due to an exception,
  67. some error message will be printed. So, only warn the user
  68. when we cannot restore during normal execution. */
  69. bool unwinding;
  70. #if __cpp_lib_uncaught_exceptions
  71. unwinding = std::uncaught_exceptions () > 0;
  72. #else
  73. unwinding = std::uncaught_exception ();
  74. #endif
  75. if (!unwinding)
  76. warning (_("Failed to restore inferior state: %s"), e.what ());
  77. }
  78. }
  79. };
  80. /* A unique_ptr specialization for infcall_suspend_state. */
  81. typedef std::unique_ptr<infcall_suspend_state, infcall_suspend_state_deleter>
  82. infcall_suspend_state_up;
  83. extern infcall_suspend_state_up save_infcall_suspend_state ();
  84. /* A deleter for infcall_control_state that calls
  85. restore_infcall_control_state. */
  86. struct infcall_control_state_deleter
  87. {
  88. void operator() (struct infcall_control_state *state) const
  89. {
  90. restore_infcall_control_state (state);
  91. }
  92. };
  93. /* A unique_ptr specialization for infcall_control_state. */
  94. typedef std::unique_ptr<infcall_control_state, infcall_control_state_deleter>
  95. infcall_control_state_up;
  96. extern infcall_control_state_up save_infcall_control_state ();
  97. extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
  98. extern void discard_infcall_control_state (struct infcall_control_state *);
  99. extern readonly_detached_regcache *
  100. get_infcall_suspend_state_regcache (struct infcall_suspend_state *);
  101. extern void set_sigint_trap (void);
  102. extern void clear_sigint_trap (void);
  103. /* Collected pid, tid, etc. of the debugged inferior. When there's
  104. no inferior, inferior_ptid.pid () will be 0. */
  105. extern ptid_t inferior_ptid;
  106. extern void generic_mourn_inferior (void);
  107. extern CORE_ADDR unsigned_pointer_to_address (struct gdbarch *gdbarch,
  108. struct type *type,
  109. const gdb_byte *buf);
  110. extern void unsigned_address_to_pointer (struct gdbarch *gdbarch,
  111. struct type *type, gdb_byte *buf,
  112. CORE_ADDR addr);
  113. extern CORE_ADDR signed_pointer_to_address (struct gdbarch *gdbarch,
  114. struct type *type,
  115. const gdb_byte *buf);
  116. extern void address_to_signed_pointer (struct gdbarch *gdbarch,
  117. struct type *type, gdb_byte *buf,
  118. CORE_ADDR addr);
  119. extern void reopen_exec_file (void);
  120. /* From misc files */
  121. extern void default_print_registers_info (struct gdbarch *gdbarch,
  122. struct ui_file *file,
  123. struct frame_info *frame,
  124. int regnum, int all);
  125. /* Default implementation of gdbarch_print_float_info. Print
  126. the values of all floating point registers. */
  127. extern void default_print_float_info (struct gdbarch *gdbarch,
  128. struct ui_file *file,
  129. struct frame_info *frame,
  130. const char *args);
  131. extern void child_terminal_info (struct target_ops *self, const char *, int);
  132. extern void child_terminal_ours (struct target_ops *self);
  133. extern void child_terminal_ours_for_output (struct target_ops *self);
  134. extern void child_terminal_inferior (struct target_ops *self);
  135. extern void child_terminal_save_inferior (struct target_ops *self);
  136. extern void child_terminal_init (struct target_ops *self);
  137. extern void child_terminal_init_with_pgrp (int pgrp);
  138. extern void child_pass_ctrlc (struct target_ops *self);
  139. extern void child_interrupt (struct target_ops *self);
  140. /* From fork-child.c */
  141. /* Helper function to call STARTUP_INFERIOR with PID and NUM_TRAPS.
  142. This function already calls set_executing. Return the ptid_t from
  143. STARTUP_INFERIOR. */
  144. extern ptid_t gdb_startup_inferior (pid_t pid, int num_traps);
  145. /* From infcmd.c */
  146. /* Initial inferior setup. Determines the exec file is not yet known,
  147. takes any necessary post-attaching actions, fetches the target
  148. description and syncs the shared library list. */
  149. extern void setup_inferior (int from_tty);
  150. extern void post_create_inferior (int from_tty);
  151. extern void attach_command (const char *, int);
  152. extern void set_inferior_args_vector (int, char **);
  153. extern void registers_info (const char *, int);
  154. extern void continue_1 (int all_threads);
  155. extern void interrupt_target_1 (bool all_threads);
  156. using delete_longjmp_breakpoint_cleanup
  157. = FORWARD_SCOPE_EXIT (delete_longjmp_breakpoint);
  158. extern void detach_command (const char *, int);
  159. extern void notice_new_inferior (struct thread_info *, bool, int);
  160. /* Return the value of the result of a function at the end of a 'finish'
  161. command/BP. If the result's value cannot be retrieved, return NULL.
  162. FUNC_SYMBOL is the symbol of the function being returned from. FUNCTION is
  163. a value containing the address of the function. */
  164. extern struct value *get_return_value (struct symbol *func_symbol,
  165. struct value *function);
  166. /* Prepare for execution command. TARGET is the target that will run
  167. the command. BACKGROUND determines whether this is a foreground
  168. (synchronous) or background (asynchronous) command. */
  169. extern void prepare_execution_command (struct target_ops *target,
  170. int background);
  171. /* Nonzero if stopped due to completion of a stack dummy routine. */
  172. extern enum stop_stack_kind stop_stack_dummy;
  173. /* Nonzero if program stopped due to a random (unexpected) signal in
  174. inferior process. */
  175. extern int stopped_by_random_signal;
  176. /* Print notices on inferior events (attach, detach, etc.), set with
  177. `set print inferior-events'. */
  178. extern bool print_inferior_events;
  179. /* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
  180. will handle it themselves. STOP_QUIETLY is used when running in
  181. the shell before the child program has been exec'd and when running
  182. through shared library loading. STOP_QUIETLY_REMOTE is used when
  183. setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP
  184. except that there is no need to hide a signal. */
  185. /* STOP_QUIETLY_NO_SIGSTOP is used to handle a tricky situation with attach.
  186. When doing an attach, the kernel stops the debuggee with a SIGSTOP.
  187. On newer GNU/Linux kernels (>= 2.5.61) the handling of SIGSTOP for
  188. a ptraced process has changed. Earlier versions of the kernel
  189. would ignore these SIGSTOPs, while now SIGSTOP is treated like any
  190. other signal, i.e. it is not muffled.
  191. If the gdb user does a 'continue' after the 'attach', gdb passes
  192. the global variable stop_signal (which stores the signal from the
  193. attach, SIGSTOP) to the ptrace(PTRACE_CONT,...) call. This is
  194. problematic, because the kernel doesn't ignore such SIGSTOP
  195. now. I.e. it is reported back to gdb, which in turn presents it
  196. back to the user.
  197. To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows
  198. gdb to clear the value of stop_signal after the attach, so that it
  199. is not passed back down to the kernel. */
  200. enum stop_kind
  201. {
  202. NO_STOP_QUIETLY = 0,
  203. STOP_QUIETLY,
  204. STOP_QUIETLY_REMOTE,
  205. STOP_QUIETLY_NO_SIGSTOP
  206. };
  207. /* Possible values for gdbarch_call_dummy_location. */
  208. #define ON_STACK 1
  209. #define AT_ENTRY_POINT 4
  210. /* Base class for target-specific inferior data. */
  211. struct private_inferior
  212. {
  213. virtual ~private_inferior () = 0;
  214. };
  215. /* Inferior process specific part of `struct infcall_control_state'.
  216. Inferior thread counterpart is `struct thread_control_state'. */
  217. struct inferior_control_state
  218. {
  219. inferior_control_state ()
  220. : stop_soon (NO_STOP_QUIETLY)
  221. {
  222. }
  223. explicit inferior_control_state (enum stop_kind when)
  224. : stop_soon (when)
  225. {
  226. }
  227. /* See the definition of stop_kind above. */
  228. enum stop_kind stop_soon;
  229. };
  230. /* Return a pointer to the current inferior. */
  231. extern inferior *current_inferior ();
  232. extern void set_current_inferior (inferior *);
  233. /* Switch inferior (and program space) to INF, and switch to no thread
  234. selected. */
  235. extern void switch_to_inferior_no_thread (inferior *inf);
  236. /* GDB represents the state of each program execution with an object
  237. called an inferior. An inferior typically corresponds to a process
  238. but is more general and applies also to targets that do not have a
  239. notion of processes. Each run of an executable creates a new
  240. inferior, as does each attachment to an existing process.
  241. Inferiors have unique internal identifiers that are different from
  242. target process ids. Each inferior may in turn have multiple
  243. threads running in it.
  244. Inferiors are intrusively refcounted objects. Unlike thread
  245. objects, being the user-selected inferior is considered a strong
  246. reference and is thus accounted for in the inferior object's
  247. refcount (see set_current_inferior). When GDB needs to remember
  248. the selected inferior to later restore it, GDB temporarily bumps
  249. the inferior object's refcount, to prevent something deleting the
  250. inferior object before reverting back (e.g., due to a
  251. "remove-inferiors" command (see
  252. scoped_restore_current_inferior). All other inferior
  253. references are considered weak references. Inferiors are always
  254. listed exactly once in the inferior list, so placing an inferior in
  255. the inferior list is an implicit, not counted strong reference. */
  256. class inferior : public refcounted_object,
  257. public intrusive_list_node<inferior>
  258. {
  259. public:
  260. explicit inferior (int pid);
  261. ~inferior ();
  262. /* Returns true if we can delete this inferior. */
  263. bool deletable () const { return refcount () == 0; }
  264. /* Push T in this inferior's target stack. */
  265. void push_target (struct target_ops *t)
  266. { m_target_stack.push (t); }
  267. /* An overload that deletes the target on failure. */
  268. void push_target (target_ops_up &&t)
  269. {
  270. m_target_stack.push (t.get ());
  271. t.release ();
  272. }
  273. /* Unpush T from this inferior's target stack. */
  274. int unpush_target (struct target_ops *t);
  275. /* Returns true if T is pushed in this inferior's target stack. */
  276. bool target_is_pushed (target_ops *t)
  277. { return m_target_stack.is_pushed (t); }
  278. /* Find the target beneath T in this inferior's target stack. */
  279. target_ops *find_target_beneath (const target_ops *t)
  280. { return m_target_stack.find_beneath (t); }
  281. /* Return the target at the top of this inferior's target stack. */
  282. target_ops *top_target ()
  283. { return m_target_stack.top (); }
  284. /* Return the target at process_stratum level in this inferior's
  285. target stack. */
  286. struct process_stratum_target *process_target ()
  287. { return (process_stratum_target *) m_target_stack.at (process_stratum); }
  288. /* Return the target at STRATUM in this inferior's target stack. */
  289. target_ops *target_at (enum strata stratum)
  290. { return m_target_stack.at (stratum); }
  291. bool has_execution ()
  292. { return target_has_execution (this); }
  293. /* This inferior's thread list, sorted by creation order. */
  294. intrusive_list<thread_info> thread_list;
  295. /* A map of ptid_t to thread_info*, for average O(1) ptid_t lookup.
  296. Exited threads do not appear in the map. */
  297. std::unordered_map<ptid_t, thread_info *, hash_ptid> ptid_thread_map;
  298. /* Returns a range adapter covering the inferior's threads,
  299. including exited threads. Used like this:
  300. for (thread_info *thr : inf->threads ())
  301. { .... }
  302. */
  303. inf_threads_range threads ()
  304. { return inf_threads_range (this->thread_list.begin ()); }
  305. /* Returns a range adapter covering the inferior's non-exited
  306. threads. Used like this:
  307. for (thread_info *thr : inf->non_exited_threads ())
  308. { .... }
  309. */
  310. inf_non_exited_threads_range non_exited_threads ()
  311. { return inf_non_exited_threads_range (this->thread_list.begin ()); }
  312. /* Like inferior::threads(), but returns a range adapter that can be
  313. used with range-for, safely. I.e., it is safe to delete the
  314. currently-iterated thread, like this:
  315. for (thread_info *t : inf->threads_safe ())
  316. if (some_condition ())
  317. delete f;
  318. */
  319. inline safe_inf_threads_range threads_safe ()
  320. { return safe_inf_threads_range (this->thread_list.begin ()); }
  321. /* Delete all threads in the thread list. If SILENT, exit threads
  322. silently. */
  323. void clear_thread_list (bool silent);
  324. /* Continuations-related methods. A continuation is an std::function
  325. to be called to finish the execution of a command when running
  326. GDB asynchronously. A continuation is executed after any thread
  327. of this inferior stops. Continuations are used by the attach
  328. command and the remote target when a new inferior is detected. */
  329. void add_continuation (std::function<void ()> &&cont);
  330. void do_all_continuations ();
  331. /* Set/get file name for default use for standard in/out in the inferior.
  332. On Unix systems, we try to make TERMINAL_NAME the inferior's controlling
  333. terminal.
  334. If TERMINAL_NAME is the empty string, then the inferior inherits GDB's
  335. terminal (or GDBserver's if spawning a remote process). */
  336. void set_tty (std::string terminal_name);
  337. const std::string &tty ();
  338. /* Set the argument string to use when running this inferior.
  339. An empty string can be used to represent "no arguments". */
  340. void set_args (std::string args)
  341. {
  342. m_args = std::move (args);
  343. };
  344. /* Get the argument string to use when running this inferior.
  345. No arguments is represented by an empty string. */
  346. const std::string &args () const
  347. {
  348. return m_args;
  349. }
  350. /* Set the inferior current working directory.
  351. If CWD is empty, unset the directory. */
  352. void set_cwd (std::string cwd)
  353. {
  354. m_cwd = std::move (cwd);
  355. }
  356. /* Get the inferior current working directory.
  357. Return an empty string if the current working directory is not
  358. specified. */
  359. const std::string &cwd () const
  360. {
  361. return m_cwd;
  362. }
  363. /* Convenient handle (GDB inferior id). Unique across all
  364. inferiors. */
  365. int num = 0;
  366. /* Actual target inferior id, usually, a process id. This matches
  367. the ptid_t.pid member of threads of this inferior. */
  368. int pid = 0;
  369. /* True if the PID was actually faked by GDB. */
  370. bool fake_pid_p = false;
  371. /* The highest thread number this inferior ever had. */
  372. int highest_thread_num = 0;
  373. /* State of GDB control of inferior process execution.
  374. See `struct inferior_control_state'. */
  375. inferior_control_state control;
  376. /* True if this was an auto-created inferior, e.g. created from
  377. following a fork; false, if this inferior was manually added by
  378. the user, and we should not attempt to prune it
  379. automatically. */
  380. bool removable = false;
  381. /* The address space bound to this inferior. */
  382. struct address_space *aspace = NULL;
  383. /* The program space bound to this inferior. */
  384. struct program_space *pspace = NULL;
  385. /* The terminal state as set by the last target_terminal::terminal_*
  386. call. */
  387. target_terminal_state terminal_state = target_terminal_state::is_ours;
  388. /* Environment to use for running inferior,
  389. in format described in environ.h. */
  390. gdb_environ environment;
  391. /* True if this child process was attached rather than forked. */
  392. bool attach_flag = false;
  393. /* If this inferior is a vfork child, then this is the pointer to
  394. its vfork parent, if GDB is still attached to it. */
  395. inferior *vfork_parent = NULL;
  396. /* If this process is a vfork parent, this is the pointer to the
  397. child. Since a vfork parent is left frozen by the kernel until
  398. the child execs or exits, a process can only have one vfork child
  399. at a given time. */
  400. inferior *vfork_child = NULL;
  401. /* True if this inferior should be detached when it's vfork sibling
  402. exits or execs. */
  403. bool pending_detach = false;
  404. /* If non-nullptr, points to a thread that called vfork and is now waiting
  405. for a vfork child not under our control to be done with the shared memory
  406. region, either by exiting or execing. */
  407. thread_info *thread_waiting_for_vfork_done = nullptr;
  408. /* True if we're in the process of detaching from this inferior. */
  409. bool detaching = false;
  410. /* True if setup_inferior wasn't called for this inferior yet.
  411. Until that is done, we must not access inferior memory or
  412. registers, as we haven't determined the target
  413. architecture/description. */
  414. bool needs_setup = false;
  415. /* True when we are reading the library list of the inferior during an
  416. attach or handling a fork child. */
  417. bool in_initial_library_scan = false;
  418. /* Private data used by the target vector implementation. */
  419. std::unique_ptr<private_inferior> priv;
  420. /* HAS_EXIT_CODE is true if the inferior exited with an exit code.
  421. In this case, the EXIT_CODE field is also valid. */
  422. bool has_exit_code = false;
  423. LONGEST exit_code = 0;
  424. /* Default flags to pass to the symbol reading functions. These are
  425. used whenever a new objfile is created. */
  426. symfile_add_flags symfile_flags = 0;
  427. /* Info about an inferior's target description (if it's fetched; the
  428. user supplied description's filename, if any; etc.). */
  429. target_desc_info *tdesc_info = NULL;
  430. /* The architecture associated with the inferior through the
  431. connection to the target.
  432. The architecture vector provides some information that is really
  433. a property of the inferior, accessed through a particular target:
  434. ptrace operations; the layout of certain RSP packets; the
  435. solib_ops vector; etc. To differentiate architecture accesses to
  436. per-inferior/target properties from
  437. per-thread/per-frame/per-objfile properties, accesses to
  438. per-inferior/target properties should be made through
  439. this gdbarch. */
  440. struct gdbarch *gdbarch = NULL;
  441. /* Data related to displaced stepping. */
  442. displaced_step_inferior_state displaced_step_state;
  443. /* Per inferior data-pointers required by other GDB modules. */
  444. REGISTRY_FIELDS;
  445. private:
  446. /* The inferior's target stack. */
  447. target_stack m_target_stack;
  448. /* The name of terminal device to use for I/O. */
  449. std::string m_terminal;
  450. /* The list of continuations. */
  451. std::list<std::function<void ()>> m_continuations;
  452. /* The arguments string to use when running. */
  453. std::string m_args;
  454. /* The current working directory that will be used when starting
  455. this inferior. */
  456. std::string m_cwd;
  457. };
  458. /* Keep a registry of per-inferior data-pointers required by other GDB
  459. modules. */
  460. DECLARE_REGISTRY (inferior);
  461. /* Add an inferior to the inferior list, print a message that a new
  462. inferior is found, and return the pointer to the new inferior.
  463. Caller may use this pointer to initialize the private inferior
  464. data. */
  465. extern struct inferior *add_inferior (int pid);
  466. /* Same as add_inferior, but don't print new inferior notifications to
  467. the CLI. */
  468. extern struct inferior *add_inferior_silent (int pid);
  469. extern void delete_inferior (struct inferior *todel);
  470. /* Delete an existing inferior list entry, due to inferior detaching. */
  471. extern void detach_inferior (inferior *inf);
  472. extern void exit_inferior (inferior *inf);
  473. extern void exit_inferior_silent (inferior *inf);
  474. extern void exit_inferior_num_silent (int num);
  475. extern void inferior_appeared (struct inferior *inf, int pid);
  476. /* Search function to lookup an inferior of TARG by target 'pid'. */
  477. extern struct inferior *find_inferior_pid (process_stratum_target *targ,
  478. int pid);
  479. /* Search function to lookup an inferior of TARG whose pid is equal to
  480. 'ptid.pid'. */
  481. extern struct inferior *find_inferior_ptid (process_stratum_target *targ,
  482. ptid_t ptid);
  483. /* Search function to lookup an inferior by GDB 'num'. */
  484. extern struct inferior *find_inferior_id (int num);
  485. /* Find an inferior bound to PSPACE, giving preference to the current
  486. inferior. */
  487. extern struct inferior *
  488. find_inferior_for_program_space (struct program_space *pspace);
  489. /* Returns true if the inferior list is not empty. */
  490. extern int have_inferiors (void);
  491. /* Returns the number of live inferiors running on PROC_TARGET (real
  492. live processes with execution). */
  493. extern int number_of_live_inferiors (process_stratum_target *proc_target);
  494. /* Returns true if there are any live inferiors in the inferior list
  495. (not cores, not executables, real live processes). */
  496. extern int have_live_inferiors (void);
  497. /* Save/restore the current inferior. */
  498. class scoped_restore_current_inferior
  499. {
  500. public:
  501. scoped_restore_current_inferior ()
  502. : m_saved_inf (current_inferior ())
  503. {}
  504. ~scoped_restore_current_inferior ()
  505. { set_current_inferior (m_saved_inf); }
  506. DISABLE_COPY_AND_ASSIGN (scoped_restore_current_inferior);
  507. private:
  508. inferior *m_saved_inf;
  509. };
  510. /* Traverse all inferiors. */
  511. extern intrusive_list<inferior> inferior_list;
  512. /* Pull in the internals of the inferiors ranges and iterators. Must
  513. be done after struct inferior is defined. */
  514. #include "inferior-iter.h"
  515. /* Return a range that can be used to walk over all inferiors
  516. inferiors, with range-for, safely. I.e., it is safe to delete the
  517. currently-iterated inferior. When combined with range-for, this
  518. allow convenient patterns like this:
  519. for (inferior *inf : all_inferiors_safe ())
  520. if (some_condition ())
  521. delete inf;
  522. */
  523. inline all_inferiors_safe_range
  524. all_inferiors_safe ()
  525. {
  526. return all_inferiors_safe_range (nullptr, inferior_list);
  527. }
  528. /* Returns a range representing all inferiors, suitable to use with
  529. range-for, like this:
  530. for (inferior *inf : all_inferiors ())
  531. [...]
  532. */
  533. inline all_inferiors_range
  534. all_inferiors (process_stratum_target *proc_target = nullptr)
  535. {
  536. return all_inferiors_range (proc_target, inferior_list);
  537. }
  538. /* Return a range that can be used to walk over all inferiors with PID
  539. not zero, with range-for. */
  540. inline all_non_exited_inferiors_range
  541. all_non_exited_inferiors (process_stratum_target *proc_target = nullptr)
  542. {
  543. return all_non_exited_inferiors_range (proc_target, inferior_list);
  544. }
  545. /* Prune away automatically added inferiors that aren't required
  546. anymore. */
  547. extern void prune_inferiors (void);
  548. extern int number_of_inferiors (void);
  549. extern struct inferior *add_inferior_with_spaces (void);
  550. /* Print the current selected inferior. */
  551. extern void print_selected_inferior (struct ui_out *uiout);
  552. /* Switch to inferior NEW_INF, a new inferior, and unless
  553. NO_CONNECTION is true, push the process_stratum_target of ORG_INF
  554. to NEW_INF. */
  555. extern void switch_to_inferior_and_push_target
  556. (inferior *new_inf, bool no_connection, inferior *org_inf);
  557. #endif /* !defined (INFERIOR_H) */