/* Variables that describe the inferior process running under GDB:
Where it is, why it stopped, and how to step it.
- Copyright (C) 1986-2020 Free Software Foundation, Inc.
+ Copyright (C) 1986-2021 Free Software Foundation, Inc.
This file is part of GDB.
#if !defined (INFERIOR_H)
#define INFERIOR_H 1
+#include <exception>
+#include <list>
+
struct target_waitstatus;
struct frame_info;
struct ui_file;
struct ui_out;
struct terminal_info;
struct target_desc_info;
-struct continuation;
struct inferior;
struct thread_info;
#include "symfile-add-flags.h"
#include "gdbsupport/refcounted-object.h"
#include "gdbsupport/forward-scope-exit.h"
+#include "gdbsupport/gdb_unique_ptr.h"
#include "gdbsupport/common-inferior.h"
#include "gdbthread.h"
#include "process-stratum-target.h"
+#include "displaced-stepping.h"
struct infcall_suspend_state;
struct infcall_control_state;
/* If we are restoring the inferior state due to an exception,
some error message will be printed. So, only warn the user
when we cannot restore during normal execution. */
- if (!std::uncaught_exception ())
+ bool unwinding;
+#if __cpp_lib_uncaught_exceptions
+ unwinding = std::uncaught_exceptions () > 0;
+#else
+ unwinding = std::uncaught_exception ();
+#endif
+ if (!unwinding)
warning (_("Failed to restore inferior state: %s"), e.what ());
}
}
extern void clear_sigint_trap (void);
-/* Set/get file name for default use for standard in/out in the inferior. */
-
-extern void set_inferior_io_terminal (const char *terminal_name);
-extern const char *get_inferior_io_terminal (void);
-
/* Collected pid, tid, etc. of the debugged inferior. When there's
no inferior, inferior_ptid.pid () will be 0. */
extern void setup_inferior (int from_tty);
-extern void post_create_inferior (struct target_ops *, int);
+extern void post_create_inferior (int from_tty);
extern void attach_command (const char *, int);
extern void detach_command (const char *, int);
-extern void notice_new_inferior (struct thread_info *, int, int);
+extern void notice_new_inferior (struct thread_info *, bool, int);
extern struct value *get_return_value (struct value *function,
struct type *value_type);
void push_target (struct target_ops *t)
{ m_target_stack.push (t); }
+ /* An overload that deletes the target on failure. */
+ void push_target (target_ops_up &&t)
+ {
+ m_target_stack.push (t.get ());
+ t.release ();
+ }
+
/* Unpush T from this inferior's target stack. */
int unpush_target (struct target_ops *t)
{ return m_target_stack.unpush (t); }
{ return m_target_stack.at (stratum); }
bool has_execution ()
- { return target_has_execution_1 (this); }
+ { return target_has_execution (this); }
/* Pointer to next inferior in singly-linked list of inferiors. */
struct inferior *next = NULL;
inline safe_inf_threads_range threads_safe ()
{ return safe_inf_threads_range (this->thread_list); }
+ /* Continuations-related methods. A continuation is an std::function
+ to be called to finish the execution of a command when running
+ GDB asynchronously. A continuation is executed after any thread
+ of this inferior stops. Continuations are used by the attach
+ command and the remote target when a new inferior is detected. */
+ void add_continuation (std::function<void ()> &&cont);
+ void do_all_continuations ();
+
+ /* Set/get file name for default use for standard in/out in the
+ inferior. On Unix systems, we try to make TERMINAL_NAME the
+ inferior's controlling terminal. If TERMINAL_NAME is nullptr or
+ the empty string, then the inferior inherits GDB's terminal (or
+ GDBserver's if spawning a remote process). */
+ void set_tty (const char *terminal_name);
+ const char *tty ();
+
/* Convenient handle (GDB inferior id). Unique across all
inferiors. */
int num = 0;
struct program_space *pspace = NULL;
/* The arguments string to use when running. */
- char *args = NULL;
+ gdb::unique_xmalloc_ptr<char> args;
/* The size of elements in argv. */
int argc = 0;
this inferior. */
gdb::unique_xmalloc_ptr<char> cwd;
- /* The name of terminal device to use for I/O. */
- char *terminal = NULL;
-
/* The terminal state as set by the last target_terminal::terminal_*
call. */
target_terminal_state terminal_state = target_terminal_state::is_ours;
/* True if we're in the process of detaching from this inferior. */
bool detaching = false;
- /* What is left to do for an execution command after any thread of
- this inferior stops. For continuations associated with a
- specific thread, see `struct thread_info'. */
- continuation *continuations = NULL;
-
/* True if setup_inferior wasn't called for this inferior yet.
Until that is done, we must not access inferior memory or
registers, as we haven't determined the target
private:
/* The inferior's target stack. */
target_stack m_target_stack;
+
+ /* The name of terminal device to use for I/O. */
+ gdb::unique_xmalloc_ptr<char> m_terminal;
+
+ /* The list of continuations. */
+ std::list<std::function<void ()>> m_continuations;
};
/* Keep a registry of per-inferior data-pointers required by other GDB