struct ui_out;
struct terminal_info;
struct target_desc_info;
-struct gdb_environ;
struct continuation;
+struct inferior;
/* For bpstat. */
#include "breakpoint.h"
/* For struct frame_id. */
#include "frame.h"
+/* For gdb_environ. */
+#include "environ.h"
+
#include "progspace.h"
#include "registry.h"
#include "symfile-add-flags.h"
+#include "common/refcounted-object.h"
+
+#include "common-inferior.h"
struct infcall_suspend_state;
struct infcall_control_state;
extern struct regcache *
get_infcall_suspend_state_regcache (struct infcall_suspend_state *);
-/* Save value of inferior_ptid so that it may be restored by
- a later call to do_cleanups(). Returns the struct cleanup
- pointer needed for later doing the cleanup. */
-extern struct cleanup * save_inferior_ptid (void);
-
extern void set_sigint_trap (void);
extern void clear_sigint_trap (void);
extern void child_terminal_info (struct target_ops *self, const char *, int);
-extern void term_info (char *, int);
+extern void info_terminal_command (char *, int);
extern void child_terminal_ours (struct target_ops *self);
/* From fork-child.c */
-/* Report an error that happened when starting to trace the inferior
- (i.e., when the "traceme_fun" callback is called on fork_inferior)
- and bail out. This function does not return. */
-
-extern void trace_start_error (const char *fmt, ...)
- ATTRIBUTE_NORETURN;
-
-/* Like "trace_start_error", but the error message is constructed by
- combining STRING with the system error message for errno. This
- function does not return. */
-
-extern void trace_start_error_with_name (const char *string)
- ATTRIBUTE_NORETURN;
-
-extern int fork_inferior (const char *, const std::string &, char **,
- void (*)(void),
- void (*)(int), void (*)(void), char *,
- void (*)(const char *,
- char * const *, char * const *));
-
-
-extern void startup_inferior (int);
+/* Helper function to call STARTUP_INFERIOR with PID and NUM_TRAPS.
+ This function already calls set_executing. Return the ptid_t from
+ STARTUP_INFERIOR. */
+extern ptid_t gdb_startup_inferior (pid_t pid, int num_traps);
extern char *construct_inferior_arguments (int, char **);
#define ON_STACK 1
#define AT_ENTRY_POINT 4
-/* Number of traps that happen between exec'ing the shell to run an
- inferior and when we finally get to the inferior code, not counting
- the exec for the shell. This is 1 on all supported
- implementations. */
-#define START_INFERIOR_TRAPS_EXPECTED 1
-
struct private_inferior;
/* Inferior process specific part of `struct infcall_control_state'.
enum stop_kind stop_soon;
};
+/* Return a pointer to the current inferior. */
+extern inferior *current_inferior ();
+
+extern void set_current_inferior (inferior *);
+
/* GDB represents the state of each program execution with an object
called an inferior. An inferior typically corresponds to a process
but is more general and applies also to targets that do not have a
inferior, as does each attachment to an existing process.
Inferiors have unique internal identifiers that are different from
target process ids. Each inferior may in turn have multiple
- threads running in it. */
-
-class inferior
+ threads running in it.
+
+ Inferiors are intrusively refcounted objects. Unlike thread
+ objects, being the user-selected inferior is considered a strong
+ reference and is thus accounted for in the inferior object's
+ refcount (see set_current_inferior). When GDB needs to remember
+ the selected inferior to later restore it, GDB temporarily bumps
+ the inferior object's refcount, to prevent something deleting the
+ inferior object before reverting back (e.g., due to a
+ "remove-inferiors" command (see
+ make_cleanup_restore_current_thread). All other inferior
+ references are considered weak references. Inferiors are always
+ listed exactly once in the inferior list, so placing an inferior in
+ the inferior list is an implicit, not counted strong reference. */
+
+class inferior : public refcounted_object
{
public:
explicit inferior (int pid);
~inferior ();
+ /* Returns true if we can delete this inferior. */
+ bool deletable () const { return refcount () == 0; }
+
/* Pointer to next inferior in singly-linked list of inferiors. */
struct inferior *next = NULL;
should never be freed. */
char **argv = NULL;
+ /* The current working directory that will be used when starting
+ this inferior. */
+ gdb::unique_xmalloc_ptr<char> cwd;
+
/* The name of terminal device to use for I/O. */
char *terminal = NULL;
/* Environment to use for running inferior,
in format described in environ.h. */
- gdb_environ *environment = NULL;
+ gdb_environ environment;
/* True if this child process was attached rather than forked. */
bool attach_flag = false;
bool waiting_for_vfork_done = false;
/* True if we're in the process of detaching from this inferior. */
- int detaching = 0;
+ bool detaching = false;
/* What is left to do for an execution command after any thread of
this inferior stops. For continuations associated with a
(not cores, not executables, real live processes). */
extern int have_live_inferiors (void);
-/* Return a pointer to the current inferior. It is an error to call
- this if there is no current inferior. */
-extern struct inferior *current_inferior (void);
+/* Save/restore the current inferior. */
+
+class scoped_restore_current_inferior
+{
+public:
+ scoped_restore_current_inferior ()
+ : m_saved_inf (current_inferior ())
+ {}
+
+ ~scoped_restore_current_inferior ()
+ { set_current_inferior (m_saved_inf); }
-extern void set_current_inferior (struct inferior *);
+ DISABLE_COPY_AND_ASSIGN (scoped_restore_current_inferior);
+
+private:
+ inferior *m_saved_inf;
+};
-extern struct cleanup *save_current_inferior (void);
/* Traverse all inferiors. */