#include "common/refcounted-object.h"
#include "common-inferior.h"
+#include "gdbthread.h"
struct infcall_suspend_state;
struct infcall_control_state;
-extern struct infcall_suspend_state *save_infcall_suspend_state (void);
-extern struct infcall_control_state *save_infcall_control_state (void);
-
extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
extern void restore_infcall_control_state (struct infcall_control_state *);
-extern struct cleanup *make_cleanup_restore_infcall_suspend_state
- (struct infcall_suspend_state *);
-extern struct cleanup *make_cleanup_restore_infcall_control_state
- (struct infcall_control_state *);
+/* A deleter for infcall_suspend_state that calls
+ restore_infcall_suspend_state. */
+struct infcall_suspend_state_deleter
+{
+ void operator() (struct infcall_suspend_state *state) const
+ {
+ restore_infcall_suspend_state (state);
+ }
+};
+
+/* A unique_ptr specialization for infcall_suspend_state. */
+typedef std::unique_ptr<infcall_suspend_state, infcall_suspend_state_deleter>
+ infcall_suspend_state_up;
+
+extern infcall_suspend_state_up save_infcall_suspend_state ();
+
+/* A deleter for infcall_control_state that calls
+ restore_infcall_control_state. */
+struct infcall_control_state_deleter
+{
+ void operator() (struct infcall_control_state *state) const
+ {
+ restore_infcall_control_state (state);
+ }
+};
+
+/* A unique_ptr specialization for infcall_control_state. */
+typedef std::unique_ptr<infcall_control_state, infcall_control_state_deleter>
+ infcall_control_state_up;
+
+extern infcall_control_state_up save_infcall_control_state ();
extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
extern void discard_infcall_control_state (struct infcall_control_state *);
extern void attach_command (const char *, int);
-extern char *get_inferior_args (void);
+extern const char *get_inferior_args (void);
extern void set_inferior_args (const char *);
`set print inferior-events'. */
extern int print_inferior_events;
-/* STEP_OVER_ALL means step over all subroutine calls.
- STEP_OVER_UNDEBUGGABLE means step over calls to undebuggable functions.
- STEP_OVER_NONE means don't step over any subroutine calls. */
-
-enum step_over_calls_kind
- {
- STEP_OVER_NONE,
- STEP_OVER_ALL,
- STEP_OVER_UNDEBUGGABLE
- };
-
/* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
will handle it themselves. STOP_QUIETLY is used when running in
the shell before the child program has been exec'd and when running
struct inferior_control_state
{
+ inferior_control_state ()
+ : stop_soon (NO_STOP_QUIETLY)
+ {
+ }
+
+ explicit inferior_control_state (enum stop_kind when)
+ : stop_soon (when)
+ {
+ }
+
/* See the definition of stop_kind above. */
enum stop_kind stop_soon;
};
/* Pointer to next inferior in singly-linked list of inferiors. */
struct inferior *next = NULL;
+ /* This inferior's thread list. */
+ thread_info *thread_list = nullptr;
+
+ /* Returns a range adapter covering the inferior's threads,
+ including exited threads. Used like this:
+
+ for (thread_info *thr : inf->threads ())
+ { .... }
+ */
+ inf_threads_range threads ()
+ { return inf_threads_range (this->thread_list); }
+
+ /* Returns a range adapter covering the inferior's non-exited
+ threads. Used like this:
+
+ for (thread_info *thr : inf->non_exited_threads ())
+ { .... }
+ */
+ inf_non_exited_threads_range non_exited_threads ()
+ { return inf_non_exited_threads_range (this->thread_list); }
+
+ /* Like inferior::threads(), but returns a range adapter that can be
+ used with range-for, safely. I.e., it is safe to delete the
+ currently-iterated thread, like this:
+
+ for (thread_info *t : inf->threads_safe ())
+ if (some_condition ())
+ delete f;
+ */
+ inline safe_inf_threads_range threads_safe ()
+ { return safe_inf_threads_range (this->thread_list); }
+
/* Convenient handle (GDB inferior id). Unique across all
inferiors. */
int num = 0;
/* State of GDB control of inferior process execution.
See `struct inferior_control_state'. */
- inferior_control_state control {NO_STOP_QUIETLY};
+ inferior_control_state control;
/* True if this was an auto-created inferior, e.g. created from
following a fork; false, if this inferior was manually added by
/* Traverse all inferiors. */
-#define ALL_INFERIORS(I) \
- for ((I) = inferior_list; (I); (I) = (I)->next)
+extern struct inferior *inferior_list;
-/* Traverse all non-exited inferiors. */
+/* Pull in the internals of the inferiors ranges and iterators. Must
+ be done after struct inferior is defined. */
+#include "inferior-iter.h"
-#define ALL_NON_EXITED_INFERIORS(I) \
- ALL_INFERIORS (I) \
- if ((I)->pid != 0)
+/* Return a range that can be used to walk over all inferiors
+ inferiors, with range-for, safely. I.e., it is safe to delete the
+ currently-iterated inferior. When combined with range-for, this
+ allow convenient patterns like this:
-extern struct inferior *inferior_list;
+ for (inferior *inf : all_inferiors_safe ())
+ if (some_condition ())
+ delete inf;
+*/
+
+inline all_inferiors_safe_range
+all_inferiors_safe ()
+{
+ return {};
+}
+
+/* Returns a range representing all inferiors, suitable to use with
+ range-for, like this:
+
+ for (inferior *inf : all_inferiors ())
+ [...]
+*/
+
+inline all_inferiors_range
+all_inferiors ()
+{
+ return {};
+}
+
+/* Return a range that can be used to walk over all inferiors with PID
+ not zero, with range-for. */
+
+inline all_non_exited_inferiors_range
+all_non_exited_inferiors ()
+{
+ return {};
+}
/* Prune away automatically added inferiors that aren't required
anymore. */