gdb: fix vfork with multiple threads
[deliverable/binutils-gdb.git] / gdb / remote-sim.c
index 347dfd70131b03888bc9dd4faa6092063645d47e..5bedc04011d4831f5ec075156cb4055b24378dac 100644 (file)
@@ -1,6 +1,6 @@
 /* Generic remote debugging interface for simulators.
 
-   Copyright (C) 1993-2020 Free Software Foundation, Inc.
+   Copyright (C) 1993-2021 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
    Steve Chamberlain (sac@cygnus.com).
@@ -33,8 +33,8 @@
 #include "target.h"
 #include "process-stratum-target.h"
 #include "gdbcore.h"
-#include "gdb/callback.h"
-#include "gdb/remote-sim.h"
+#include "sim/callback.h"
+#include "sim/sim.h"
 #include "command.h"
 #include "regcache.h"
 #include "sim-regno.h"
@@ -42,6 +42,8 @@
 #include "readline/readline.h"
 #include "gdbthread.h"
 #include "gdbsupport/byte-vector.h"
+#include "memory-map.h"
+#include "remote.h"
 
 /* Prototypes */
 
@@ -131,7 +133,7 @@ struct gdbsim_target final
   void detach (inferior *inf, int) override;
 
   void resume (ptid_t, int, enum gdb_signal) override;
-  ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+  ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
 
   void fetch_registers (struct regcache *, int) override;
   void store_registers (struct regcache *, int) override;
@@ -164,6 +166,7 @@ struct gdbsim_target final
 
   bool has_all_memory ()  override;
   bool has_memory ()  override;
+  std::vector<mem_region> memory_map () override;
 
 private:
   sim_inferior_data *get_inferior_data_by_ptid (ptid_t ptid,
@@ -211,7 +214,8 @@ get_sim_inferior_data (struct inferior *inf, int sim_instance_needed)
   if (sim_instance_needed == SIM_INSTANCE_NEEDED
       && (sim_data == NULL || sim_data->gdbsim_desc == NULL))
     {
-      sim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback, exec_bfd, sim_argv);
+      sim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback,
+                          current_program_space->exec_bfd (), sim_argv);
       if (sim_desc == NULL)
        error (_("Unable to create simulator instance for inferior %d."),
               inf->num);
@@ -620,7 +624,7 @@ gdbsim_target::create_inferior (const char *exec_file,
   char *arg_buf;
   const char *args = allargs.c_str ();
 
-  if (exec_file == 0 || exec_bfd == 0)
+  if (exec_file == 0 || current_program_space->exec_bfd () == 0)
     warning (_("No executable file specified."));
   if (!sim_data->program_loaded)
     warning (_("No program loaded."));
@@ -648,14 +652,16 @@ gdbsim_target::create_inferior (const char *exec_file,
       built_argv.reset (arg_buf);
     }
 
-  if (sim_create_inferior (sim_data->gdbsim_desc, exec_bfd,
+  if (sim_create_inferior (sim_data->gdbsim_desc,
+                          current_program_space->exec_bfd (),
                           built_argv.get (), env)
       != SIM_RC_OK)
     error (_("Unable to create sim inferior."));
 
-  inferior_ptid = sim_data->remote_sim_ptid;
-  inferior_appeared (current_inferior (), inferior_ptid.pid ());
-  add_thread_silent (this, inferior_ptid);
+  inferior_appeared (current_inferior (),
+                    sim_data->remote_sim_ptid.pid ());
+  thread_info *thr = add_thread_silent (this, sim_data->remote_sim_ptid);
+  switch_to_thread (thr);
 
   insert_breakpoints ();       /* Needed to get correct instruction
                                   in cache.  */
@@ -693,7 +699,7 @@ gdbsim_target_open (const char *args, int from_tty)
      operation until after we complete those operations which could
      error out.  */
   if (gdbsim_is_open)
-    unpush_target (&gdbsim_ops);
+    current_inferior ()->unpush_target (&gdbsim_ops);
 
   len = (7 + 1                 /* gdbsim */
         + strlen (" -E little")
@@ -737,7 +743,8 @@ gdbsim_target_open (const char *args, int from_tty)
   sim_argv = argv.release ();
 
   init_callbacks ();
-  gdbsim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback, exec_bfd, sim_argv);
+  gdbsim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback,
+                         current_program_space->exec_bfd (), sim_argv);
 
   if (gdbsim_desc == 0)
     {
@@ -756,12 +763,12 @@ gdbsim_target_open (const char *args, int from_tty)
 
   sim_data->gdbsim_desc = gdbsim_desc;
 
-  push_target (&gdbsim_ops);
+  current_inferior ()->push_target (&gdbsim_ops);
   printf_filtered ("Connected to the simulator.\n");
 
   /* There's nothing running after "target sim" or "load"; not until
      "run".  */
-  inferior_ptid = null_ptid;
+  switch_to_no_thread ();
 
   gdbsim_is_open = 1;
 }
@@ -827,9 +834,9 @@ gdbsim_target::detach (inferior *inf, int from_tty)
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "gdbsim_detach\n");
 
-  unpush_target (this);                /* calls gdbsim_close to do the real work */
+  inf->unpush_target (this);           /* calls gdbsim_close to do the real work */
   if (from_tty)
-    printf_filtered ("Ending simulator %s debugging\n", target_shortname);
+    printf_filtered ("Ending simulator %s debugging\n", target_shortname ());
 }
 
 /* Resume execution of the target process.  STEP says whether to single-step
@@ -926,7 +933,8 @@ gdbsim_cntrl_c (int signo)
 }
 
 ptid_t
-gdbsim_target::wait (ptid_t ptid, struct target_waitstatus *status, int options)
+gdbsim_target::wait (ptid_t ptid, struct target_waitstatus *status,
+                    target_wait_flags options)
 {
   struct sim_inferior_data *sim_data;
   static sighandler_t prev_sigint;
@@ -945,7 +953,6 @@ gdbsim_target::wait (ptid_t ptid, struct target_waitstatus *status, int options)
       if (sim_data == NULL)
        error (_("Unable to wait for pid %d.  Inferior not found."),
               ptid.pid ());
-      inferior_ptid = ptid;
     }
 
   if (remote_debug)
@@ -1103,16 +1110,16 @@ gdbsim_target::files_info ()
     = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
   const char *file = "nothing";
 
-  if (exec_bfd)
-    file = bfd_get_filename (exec_bfd);
+  if (current_program_space->exec_bfd ())
+    file = bfd_get_filename (current_program_space->exec_bfd ());
 
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "gdbsim_files_info: file \"%s\"\n", file);
 
-  if (exec_bfd)
+  if (current_program_space->exec_bfd ())
     {
       fprintf_unfiltered (gdb_stdlog, "\tAttached to %s running program %s\n",
-                         target_shortname, file);
+                         target_shortname (), file);
       sim_info (sim_data->gdbsim_desc, 0);
     }
 }
@@ -1266,6 +1273,22 @@ gdbsim_target::has_memory ()
   return true;
 }
 
+/* Get memory map from the simulator.  */
+
+std::vector<mem_region>
+gdbsim_target::memory_map ()
+{
+  struct sim_inferior_data *sim_data
+    = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED);
+  std::vector<mem_region> result;
+  gdb::unique_xmalloc_ptr<char> text (sim_memory_map (sim_data->gdbsim_desc));
+
+  if (text != nullptr)
+    result = parse_memory_map (text.get ());
+
+  return result;
+}
+
 void _initialize_remote_sim ();
 void
 _initialize_remote_sim ()
This page took 0.025835 seconds and 4 git commands to generate.