Don't emit symbols seen only in dynamic object, don't read duplicate
[deliverable/binutils-gdb.git] / gdb / linux-nat.c
index 88e0d7d24d990ed2af5a356995460a423a7b98c2..b0b9cf32b9367fe52ddedb6485d819760a5761af 100644 (file)
@@ -36,6 +36,7 @@
 #include "gdbthread.h"
 #include "gdbcmd.h"
 #include "regcache.h"
+#include "regset.h"
 #include "inf-ptrace.h"
 #include "auxv.h"
 #include <sys/param.h>         /* for MAXPATHLEN */
@@ -275,6 +276,7 @@ linux_test_for_tracefork (int original_pid)
          ret = ptrace (PTRACE_KILL, second_pid, 0, 0);
          if (ret != 0)
            warning (_("linux_test_for_tracefork: failed to kill second child"));
+         my_waitpid (second_pid, &status, 0);
        }
     }
   else
@@ -334,12 +336,14 @@ void
 child_post_attach (int pid)
 {
   linux_enable_event_reporting (pid_to_ptid (pid));
+  check_for_thread_db ();
 }
 
 static void
 linux_child_post_startup_inferior (ptid_t ptid)
 {
   linux_enable_event_reporting (ptid);
+  check_for_thread_db ();
 }
 
 int
@@ -897,10 +901,13 @@ exit_lwp (struct lwp_info *lp)
       struct thread_info *thr;
 
       thr = iterate_over_threads (find_thread_from_lwp, &lp->ptid);
-      if (thr && !ptid_equal (thr->ptid, inferior_ptid))
-       delete_thread (thr->ptid);
-      else
-       record_dead_thread (thr->ptid);
+      if (thr)
+       {
+         if (!ptid_equal (thr->ptid, inferior_ptid))
+           delete_thread (thr->ptid);
+         else
+           record_dead_thread (thr->ptid);
+       }
     }
 
   delete_lwp (lp->ptid);
@@ -963,7 +970,7 @@ lin_lwp_attach_lwp (ptid_t ptid, int verbose)
       gdb_assert (pid == GET_LWP (ptid)
                  && WIFSTOPPED (status) && WSTOPSIG (status));
 
-      child_post_attach (pid);
+      target_post_attach (pid);
 
       lp->stopped = 1;
 
@@ -979,10 +986,10 @@ lin_lwp_attach_lwp (ptid_t ptid, int verbose)
     {
       /* We assume that the LWP representing the original process is
          already stopped.  Mark it as stopped in the data structure
-         that the linux ptrace layer uses to keep track of threads.
-         Note that this won't have already been done since the main
-         thread will have, we assume, been stopped by an attach from a
-         different layer.  */
+         that the GNU/linux ptrace layer uses to keep track of
+         threads.  Note that this won't have already been done since
+         the main thread will have, we assume, been stopped by an
+         attach from a different layer.  */
       lp->stopped = 1;
     }
 }
@@ -1276,10 +1283,11 @@ kill_lwp (int lwpid, int signo)
    just pass off to linux_handle_extended_wait, but if it reports a
    clone event we need to add the new LWP to our list (and not report
    the trap to higher layers).  This function returns non-zero if
-   the event should be ignored and we should wait again.  */
+   the event should be ignored and we should wait again.  If STOPPING
+   is true, the new LWP remains stopped, otherwise it is continued.  */
 
 static int
-linux_nat_handle_extended (struct lwp_info *lp, int status)
+linux_nat_handle_extended (struct lwp_info *lp, int status, int stopping)
 {
   linux_handle_extended_wait (GET_LWP (lp->ptid), status,
                              &lp->waitstatus);
@@ -1291,7 +1299,11 @@ linux_nat_handle_extended (struct lwp_info *lp, int status)
       new_lp = add_lwp (BUILD_LWP (lp->waitstatus.value.related_pid,
                                   GET_PID (inferior_ptid)));
       new_lp->cloned = 1;
-      new_lp->stopped = 1;
+
+      if (stopping)
+       new_lp->stopped = 1;
+      else
+       ptrace (PTRACE_CONT, lp->waitstatus.value.related_pid, 0, 0);
 
       lp->waitstatus.kind = TARGET_WAITKIND_IGNORE;
 
@@ -1375,7 +1387,7 @@ wait_lwp (struct lwp_info *lp)
        fprintf_unfiltered (gdb_stdlog,
                            "WL: Handling extended status 0x%06x\n",
                            status);
-      if (linux_nat_handle_extended (lp, status))
+      if (linux_nat_handle_extended (lp, status, 1))
        return wait_lwp (lp);
     }
 
@@ -2020,7 +2032,7 @@ retry:
                fprintf_unfiltered (gdb_stdlog,
                                    "LLW: Handling extended status 0x%06x\n",
                                    status);
-             if (linux_nat_handle_extended (lp, status))
+             if (linux_nat_handle_extended (lp, status, 0))
                {
                  status = 0;
                  continue;
@@ -2152,7 +2164,10 @@ retry:
     {
       int signo = target_signal_from_host (WSTOPSIG (status));
 
-      if (signal_stop_state (signo) == 0
+      /* If we get a signal while single-stepping, we may need special
+        care, e.g. to skip the signal handler.  Defer to common code.  */
+      if (!lp->step
+         && signal_stop_state (signo) == 0
          && signal_print_state (signo) == 0
          && signal_pass_state (signo) == 1)
        {
@@ -2380,7 +2395,13 @@ linux_nat_thread_alive (ptid_t ptid)
                        "LLTA: PTRACE_PEEKUSER %s, 0, 0 (%s)\n",
                        target_pid_to_str (ptid),
                        errno ? safe_strerror (errno) : "OK");
-  if (errno)
+
+  /* Not every Linux kernel implements PTRACE_PEEKUSER.  But we can
+     handle that case gracefully since ptrace will first do a lookup
+     for the process based upon the passed-in pid.  If that fails we
+     will get either -ESRCH or -EPERM, otherwise the child exists and
+     is alive.  */
+  if (errno == ESRCH || errno == EPERM)
     return 0;
 
   return 1;
@@ -2527,21 +2548,50 @@ linux_nat_do_thread_registers (bfd *obfd, ptid_t ptid,
   gdb_fpxregset_t fpxregs;
 #endif
   unsigned long lwp = ptid_get_lwp (ptid);
+  struct gdbarch *gdbarch = current_gdbarch;
+  const struct regset *regset;
+  int core_regset_p;
+
+  core_regset_p = gdbarch_regset_from_core_section_p (gdbarch);
+  if (core_regset_p
+      && (regset = gdbarch_regset_from_core_section (gdbarch, ".reg",
+                                                    sizeof (gregs))) != NULL
+      && regset->collect_regset != NULL)
+    regset->collect_regset (regset, current_regcache, -1,
+                           &gregs, sizeof (gregs));
+  else
+    fill_gregset (&gregs, -1);
 
-  fill_gregset (&gregs, -1);
   note_data = (char *) elfcore_write_prstatus (obfd,
                                               note_data,
                                               note_size,
                                               lwp,
                                               stop_signal, &gregs);
 
-  fill_fpregset (&fpregs, -1);
+  if (core_regset_p
+      && (regset = gdbarch_regset_from_core_section (gdbarch, ".reg2",
+                                                    sizeof (fpregs))) != NULL
+      && regset->collect_regset != NULL)
+    regset->collect_regset (regset, current_regcache, -1,
+                           &fpregs, sizeof (fpregs));
+  else
+    fill_fpregset (&fpregs, -1);
+
   note_data = (char *) elfcore_write_prfpreg (obfd,
                                              note_data,
                                              note_size,
                                              &fpregs, sizeof (fpregs));
+
 #ifdef FILL_FPXREGSET
-  fill_fpxregset (&fpxregs, -1);
+  if (core_regset_p
+      && (regset = gdbarch_regset_from_core_section (gdbarch, ".reg-xfp",
+                                                    sizeof (fpxregs))) != NULL
+      && regset->collect_regset != NULL)
+    regset->collect_regset (regset, current_regcache, -1,
+                           &fpxregs, sizeof (fpxregs));
+  else
+    fill_fpxregset (&fpxregs, -1);
+
   note_data = (char *) elfcore_write_prxfpreg (obfd,
                                               note_data,
                                               note_size,
@@ -2648,7 +2698,8 @@ linux_nat_make_corefile_notes (bfd *obfd, int *note_size)
       note_data = thread_args.note_data;
     }
 
-  auxv_len = target_auxv_read (&current_target, &auxv);
+  auxv_len = target_read_alloc (&current_target, TARGET_OBJECT_AUXV,
+                               NULL, &auxv);
   if (auxv_len > 0)
     {
       note_data = elfcore_write_note (obfd, note_data, note_size,
@@ -3130,8 +3181,6 @@ linux_target (void)
 void
 linux_nat_add_target (struct target_ops *t)
 {
-  extern void thread_db_init (struct target_ops *);
-
   /* Save the provided single-threaded target.  We save this in a separate
      variable because another target we've inherited from (e.g. inf-ptrace)
      may have saved a pointer to T; we want to use it for the final
This page took 0.027115 seconds and 4 git commands to generate.