Replace clear_hook_in_cleanup with scoped_restore_hook_in
[deliverable/binutils-gdb.git] / gdb / inf-ptrace.c
index 32794ec132f72c261debd329196c73a4e3cff75b..af181f084cb72a0ac5c29199dccff34814a787b6 100644 (file)
@@ -31,6 +31,8 @@
 #include "inf-ptrace.h"
 #include "inf-child.h"
 #include "gdbthread.h"
+#include "nat/fork-inferior.h"
+#include "utils.h"
 
 \f
 
@@ -90,10 +92,11 @@ inf_ptrace_me (void)
 
 static void
 inf_ptrace_create_inferior (struct target_ops *ops,
-                           char *exec_file, char *allargs, char **env,
-                           int from_tty)
+                           const char *exec_file, const std::string &allargs,
+                           char **env, int from_tty)
 {
-  int pid;
+  pid_t pid;
+  ptid_t ptid;
 
   /* Do not change either targets above or the same target if already present.
      The reason is the target stack is shared across multiple inferiors.  */
@@ -110,13 +113,19 @@ inf_ptrace_create_inferior (struct target_ops *ops,
   pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL,
                       NULL, NULL, NULL);
 
+  ptid = pid_to_ptid (pid);
+  /* We have something that executes now.  We'll be running through
+     the shell at this point (if startup-with-shell is true), but the
+     pid shouldn't change.  */
+  add_thread_silent (ptid);
+
   discard_cleanups (back_to);
 
-  startup_inferior (START_INFERIOR_TRAPS_EXPECTED);
+  gdb_startup_inferior (pid, START_INFERIOR_TRAPS_EXPECTED);
 
   /* On some targets, there must be some explicit actions taken after
      the inferior has been started up.  */
-  target_post_startup_inferior (pid_to_ptid (pid));
+  target_post_startup_inferior (ptid);
 }
 
 #ifdef PT_GET_PROCESS_STATE
@@ -462,7 +471,7 @@ inf_ptrace_peek_poke (pid_t pid, gdb_byte *readbuf,
   /* We transfer aligned words.  Thus align ADDR down to a word
      boundary and determine how many bytes to skip at the
      beginning.  */
-  unsigned int skip = addr & (sizeof (PTRACE_TYPE_RET) - 1);
+  ULONGEST skip = addr & (sizeof (PTRACE_TYPE_RET) - 1);
   addr -= skip;
 
   for (n = 0;
@@ -520,7 +529,7 @@ inf_ptrace_xfer_partial (struct target_ops *ops, enum target_object object,
                         const gdb_byte *writebuf,
                         ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
 {
-  pid_t pid = ptid_get_pid (inferior_ptid);
+  pid_t pid = get_ptrace_pid (inferior_ptid);
 
   switch (object)
     {
@@ -619,7 +628,7 @@ inf_ptrace_files_info (struct target_ops *ignore)
                   target_pid_to_str (inferior_ptid));
 }
 
-static char *
+static const char *
 inf_ptrace_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   return normal_pid_to_str (ptid);
@@ -708,7 +717,8 @@ inf_ptrace_fetch_register (struct regcache *regcache, int regnum)
   CORE_ADDR addr;
   size_t size;
   PTRACE_TYPE_RET *buf;
-  int pid, i;
+  pid_t pid;
+  int i;
 
   /* This isn't really an address, but ptrace thinks of it as one.  */
   addr = inf_ptrace_register_u_offset (gdbarch, regnum, 0);
@@ -719,11 +729,7 @@ inf_ptrace_fetch_register (struct regcache *regcache, int regnum)
       return;
     }
 
-  /* Cater for systems like GNU/Linux, that implement threads as
-     separate processes.  */
-  pid = ptid_get_lwp (inferior_ptid);
-  if (pid == 0)
-    pid = ptid_get_pid (inferior_ptid);
+  pid = get_ptrace_pid (regcache_get_ptid (regcache));
 
   size = register_size (gdbarch, regnum);
   gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0);
@@ -769,7 +775,8 @@ inf_ptrace_store_register (const struct regcache *regcache, int regnum)
   CORE_ADDR addr;
   size_t size;
   PTRACE_TYPE_RET *buf;
-  int pid, i;
+  pid_t pid;
+  int i;
 
   /* This isn't really an address, but ptrace thinks of it as one.  */
   addr = inf_ptrace_register_u_offset (gdbarch, regnum, 1);
@@ -777,11 +784,7 @@ inf_ptrace_store_register (const struct regcache *regcache, int regnum)
       || gdbarch_cannot_store_register (gdbarch, regnum))
     return;
 
-  /* Cater for systems like GNU/Linux, that implement threads as
-     separate processes.  */
-  pid = ptid_get_lwp (inferior_ptid);
-  if (pid == 0)
-    pid = ptid_get_pid (inferior_ptid);
+  pid = get_ptrace_pid (regcache_get_ptid (regcache));
 
   size = register_size (gdbarch, regnum);
   gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0);
This page took 0.024731 seconds and 4 git commands to generate.