Add a new 'info proc files' subcommand of 'info proc'.
[deliverable/binutils-gdb.git] / gdb / linux-nat.c
index 5d693659f0f9f76a663beb62a5a00f31b404aa68..64015e75207939f29d3cf499e6f3c1463b8b83e6 100644 (file)
@@ -191,10 +191,6 @@ struct linux_nat_target *linux_target;
 /* Does the current host support PTRACE_GETREGSET?  */
 enum tribool have_ptrace_getregset = TRIBOOL_UNKNOWN;
 
-/* The saved to_close method, inherited from inf-ptrace.c.
-   Called by our to_close.  */
-static void (*super_close) (struct target_ops *);
-
 static unsigned int debug_linux_nat;
 static void
 show_debug_linux_nat (struct ui_file *file, int from_tty,
@@ -384,18 +380,19 @@ linux_nat_ptrace_options (int attached)
   return options;
 }
 
-/* Initialize ptrace warnings and check for supported ptrace
-   features given PID.
+/* Initialize ptrace and procfs warnings and check for supported
+   ptrace features given PID.
 
    ATTACHED should be nonzero iff we attached to the inferior.  */
 
 static void
-linux_init_ptrace (pid_t pid, int attached)
+linux_init_ptrace_procfs (pid_t pid, int attached)
 {
   int options = linux_nat_ptrace_options (attached);
 
   linux_enable_event_reporting (pid, options);
   linux_ptrace_init_warnings ();
+  linux_proc_init_warnings ();
 }
 
 linux_nat_target::~linux_nat_target ()
@@ -404,13 +401,13 @@ linux_nat_target::~linux_nat_target ()
 void
 linux_nat_target::post_attach (int pid)
 {
-  linux_init_ptrace (pid, 1);
+  linux_init_ptrace_procfs (pid, 1);
 }
 
 void
 linux_nat_target::post_startup_inferior (ptid_t ptid)
 {
-  linux_init_ptrace (ptid.pid (), 0);
+  linux_init_ptrace_procfs (ptid.pid (), 0);
 }
 
 /* Return the number of known LWPs in the tgid given by PID.  */
@@ -448,7 +445,6 @@ linux_nat_target::follow_fork (int follow_child, int detach_fork)
   if (!follow_child)
     {
       struct lwp_info *child_lp = NULL;
-      int status = W_STOPCODE (0);
       int has_vforked;
       ptid_t parent_ptid, child_ptid;
       int parent_pid, child_pid;
@@ -468,6 +464,8 @@ linux_nat_target::follow_fork (int follow_child, int detach_fork)
       /* Detach new forked process?  */
       if (detach_fork)
        {
+         int child_stop_signal = 0;
+         bool detach_child = true;
          struct cleanup *old_chain = make_cleanup (delete_lwp_cleanup,
                                                    child_lp);
 
@@ -487,18 +485,24 @@ linux_nat_target::follow_fork (int follow_child, int detach_fork)
          if (!gdbarch_software_single_step_p (target_thread_architecture
                                               (parent_ptid)))
            {
+             int status;
+
              linux_disable_event_reporting (child_pid);
              if (ptrace (PTRACE_SINGLESTEP, child_pid, 0, 0) < 0)
                perror_with_name (_("Couldn't do single step"));
              if (my_waitpid (child_pid, &status, 0) < 0)
                perror_with_name (_("Couldn't wait vfork process"));
+             else
+               {
+                 detach_child = WIFSTOPPED (status);
+                 child_stop_signal = WSTOPSIG (status);
+               }
            }
 
-         if (WIFSTOPPED (status))
+         if (detach_child)
            {
-             int signo;
+             int signo = child_stop_signal;
 
-             signo = WSTOPSIG (status);
              if (signo != 0
                  && !signal_pass_state (gdb_signal_from_host (signo)))
                signo = 0;
@@ -858,7 +862,7 @@ add_initial_lwp (ptid_t ptid)
 {
   struct lwp_info *lp;
 
-  gdb_assert (ptid_lwp_p (ptid));
+  gdb_assert (ptid.lwp_p ());
 
   lp = XNEW (struct lwp_info);
 
@@ -935,7 +939,7 @@ find_lwp_pid (ptid_t ptid)
   int lwp;
   struct lwp_info dummy;
 
-  if (ptid_lwp_p (ptid))
+  if (ptid.lwp_p ())
     lwp = ptid.lwp ();
   else
     lwp = ptid.pid ();
@@ -958,7 +962,7 @@ iterate_over_lwps (ptid_t filter,
     {
       lpnext = lp->next;
 
-      if (ptid_match (lp->ptid, filter))
+      if (lp->ptid.matches (filter))
        {
          if ((*callback) (lp, data) != 0)
            return lp;
@@ -1690,7 +1694,7 @@ linux_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
                        target_pid_to_str (inferior_ptid));
 
   /* A specific PTID means `step only this process id'.  */
-  resume_many = (ptid_equal (minus_one_ptid, ptid)
+  resume_many = (minus_one_ptid == ptid
                 || ptid.is_pid ());
 
   /* Mark the lwps we're resuming as resumed.  */
@@ -3389,7 +3393,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
   /* If we're not waiting for a specific LWP, choose an event LWP from
      among those that have had events.  Giving equal priority to all
      LWPs that have had events helps prevent starvation.  */
-  if (ptid_equal (ptid, minus_one_ptid) || ptid.is_pid ())
+  if (ptid == minus_one_ptid || ptid.is_pid ())
     select_event_lwp (ptid, &lp, &status);
 
   gdb_assert (lp != NULL);
@@ -3513,7 +3517,7 @@ resume_stopped_resumed_lwps (struct lwp_info *lp, void *data)
 
          /* Don't bother if there's a breakpoint at PC that we'd hit
             immediately, and we're not waiting for this LWP.  */
-         if (!ptid_match (lp->ptid, *wait_ptid_p))
+         if (!lp->ptid.matches (*wait_ptid_p))
            {
              if (breakpoint_inserted_here_p (regcache->aspace (), pc))
                leave_stopped = 1;
@@ -3551,14 +3555,11 @@ linux_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 
   if (debug_linux_nat)
     {
-      char *options_string;
-
-      options_string = target_options_to_string (target_options);
+      std::string options_string = target_options_to_string (target_options);
       fprintf_unfiltered (gdb_stdlog,
                          "linux_nat_wait: [%s], [%s]\n",
                          target_pid_to_str (ptid),
-                         options_string);
-      xfree (options_string);
+                         options_string.c_str ());
     }
 
   /* Flush the async file first.  */
@@ -3583,7 +3584,7 @@ linux_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
   if (target_is_async_p ()
       && ((ourstatus->kind != TARGET_WAITKIND_IGNORE
           && ourstatus->kind != TARGET_WAITKIND_NO_RESUMED)
-         || !ptid_equal (ptid, minus_one_ptid)))
+         || ptid != minus_one_ptid))
     async_file_mark ();
 
   return event_ptid;
@@ -3857,7 +3858,7 @@ linux_nat_target::xfer_partial (enum target_object object,
   /* The target is connected but no live inferior is selected.  Pass
      this request down to a lower stratum (e.g., the executable
      file).  */
-  if (object == TARGET_OBJECT_MEMORY && ptid_equal (inferior_ptid, null_ptid))
+  if (object == TARGET_OBJECT_MEMORY && inferior_ptid == null_ptid)
     return TARGET_XFER_EOF;
 
   if (object == TARGET_OBJECT_AUXV)
@@ -3933,7 +3934,7 @@ linux_nat_target::pid_to_str (ptid_t ptid)
 {
   static char buf[64];
 
-  if (ptid_lwp_p (ptid)
+  if (ptid.lwp_p ()
       && (ptid.pid () != ptid.lwp ()
          || num_lwps (ptid.pid ()) > 1))
     {
@@ -4663,7 +4664,7 @@ linux_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo)
 ptid_t
 current_lwp_ptid (void)
 {
-  gdb_assert (ptid_lwp_p (inferior_ptid));
+  gdb_assert (inferior_ptid.lwp_p ());
   return inferior_ptid;
 }
 
This page took 0.037067 seconds and 4 git commands to generate.