+ bool thread_alive (ptid_t ptid) override;
+
+ std::string pid_to_str (ptid_t) override;
+
+ bool has_all_memory () override;
+ bool has_memory () override;
+};
+
+static struct gdbsim_target gdbsim_ops;
+
+/* Value of the next pid to allocate for an inferior. As indicated
+ elsewhere, its initial value is somewhat arbitrary; it's critical
+ though that it's not zero or negative. */
+static int next_pid;
+#define INITIAL_PID 42000
+
+/* Simulator-specific, per-inferior state. */
+struct sim_inferior_data {
+ explicit sim_inferior_data (SIM_DESC desc)
+ : gdbsim_desc (desc),
+ remote_sim_ptid (next_pid, 0, next_pid)
+ {
+ ++next_pid;
+ }
+
+ ~sim_inferior_data ();
+
+ /* Flag which indicates whether or not the program has been loaded. */
+ int program_loaded = 0;
+
+ /* Simulator descriptor for this inferior. */
+ SIM_DESC gdbsim_desc;
+
+ /* This is the ptid we use for this particular simulator instance. Its
+ value is somewhat arbitrary, as the simulator target don't have a
+ notion of tasks or threads, but we need something non-null to place
+ in inferior_ptid. For simulators which permit multiple instances,
+ we also need a unique identifier to use for each inferior. */
+ ptid_t remote_sim_ptid;
+
+ /* Signal with which to resume. */
+ enum gdb_signal resume_siggnal = GDB_SIGNAL_0;
+
+ /* Flag which indicates whether resume should step or not. */
+ int resume_step = 0;
+};
+
+static inferior_key<sim_inferior_data> sim_inferior_data_key;
+
+/* Flag indicating the "open" status of this module. It's set to 1
+ in gdbsim_open() and 0 in gdbsim_close(). */
+static int gdbsim_is_open = 0;
+
+/* Argument list to pass to sim_open(). It is allocated in gdbsim_open()
+ and deallocated in gdbsim_close(). The lifetime needs to extend beyond
+ the call to gdbsim_open() due to the fact that other sim instances other
+ than the first will be allocated after the gdbsim_open() call. */
+static char **sim_argv = NULL;
+
+/* OS-level callback functions for write, flush, etc. */
+static host_callback gdb_callback;
+static int callbacks_initialized = 0;
+
+/* Callback for iterate_over_inferiors. It checks to see if the sim
+ descriptor passed via ARG is the same as that for the inferior
+ designated by INF. Return true if so; false otherwise. */
+
+static int
+check_for_duplicate_sim_descriptor (struct inferior *inf, void *arg)
+{
+ struct sim_inferior_data *sim_data;
+ SIM_DESC new_sim_desc = (SIM_DESC) arg;
+
+ sim_data = sim_inferior_data_key.get (inf);
+
+ return (sim_data != NULL && sim_data->gdbsim_desc == new_sim_desc);
+}
+
+/* Flags indicating whether or not a sim instance is needed. One of these
+ flags should be passed to get_sim_inferior_data(). */
+
+enum {SIM_INSTANCE_NOT_NEEDED = 0, SIM_INSTANCE_NEEDED = 1};
+
+/* Obtain pointer to per-inferior simulator data, allocating it if necessary.
+ Attempt to open the sim if SIM_INSTANCE_NEEDED is true. */
+
+static struct sim_inferior_data *
+get_sim_inferior_data (struct inferior *inf, int sim_instance_needed)