OSDN Git Service

Updated copyright notices for most files.
[pf3gnuchains/pf3gnuchains4x.git] / gdb / gdbserver / linux-low.c
index 9876491..e5cb528 100644 (file)
@@ -1,6 +1,6 @@
 /* Low level interface to ptrace, for the remote server for GDB.
    Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-   2006, 2007 Free Software Foundation, Inc.
+   2006, 2007, 2008 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <sys/syscall.h>
+#include <sched.h>
 
 #ifndef PTRACE_GETSIGINFO
 # define PTRACE_GETSIGINFO 0x4202
@@ -622,6 +623,7 @@ linux_wait_for_event (struct thread_info *child)
   CORE_ADDR stop_pc;
   struct process_info *event_child;
   int wstat;
+  int bp_status;
 
   /* Check for a process with a pending status.  */
   /* It is possible that the user changed the pending task's registers since
@@ -785,18 +787,20 @@ linux_wait_for_event (struct thread_info *child)
          continue;
        }
 
-      if (debug_threads)
-       fprintf (stderr, "Hit a (non-reinsert) breakpoint.\n");
+      bp_status = check_breakpoints (stop_pc);
 
-      if (check_breakpoints (stop_pc) != 0)
+      if (bp_status != 0)
        {
+         if (debug_threads)
+           fprintf (stderr, "Hit a gdbserver breakpoint.\n");
+
          /* We hit one of our own breakpoints.  We mark it as a pending
             breakpoint, so that check_removed_breakpoint () will do the PC
             adjustment for us at the appropriate time.  */
          event_child->pending_is_breakpoint = 1;
          event_child->pending_stop_pc = stop_pc;
 
-         /* Now we need to put the breakpoint back.  We continue in the event
+         /* We may need to put the breakpoint back.  We continue in the event
             loop instead of simply replacing the breakpoint right away,
             in order to not lose signals sent to the thread that hit the
             breakpoint.  Unfortunately this increases the window where another
@@ -814,7 +818,10 @@ linux_wait_for_event (struct thread_info *child)
             Otherwise, call the target function to figure out where we need
             our temporary breakpoint, create it, and continue executing this
             process.  */
-         if (the_low_target.breakpoint_reinsert_addr == NULL)
+         if (bp_status == 2)
+           /* No need to reinsert.  */
+           linux_resume_one_process (&event_child->head, 0, 0, NULL);
+         else if (the_low_target.breakpoint_reinsert_addr == NULL)
            {
              event_child->bp_reinsert = stop_pc;
              uninsert_breakpoint (stop_pc);
@@ -830,6 +837,9 @@ linux_wait_for_event (struct thread_info *child)
          continue;
        }
 
+      if (debug_threads)
+       fprintf (stderr, "Hit a non-gdbserver breakpoint.\n");
+
       /* If we were single-stepping, we definitely want to report the
         SIGTRAP.  The single-step operation has completed, so also
          clear the stepping flag; in general this does not matter,
@@ -896,11 +906,8 @@ retry:
        }
     }
 
-  enable_async_io ();
-  unblock_async_io ();
   w = linux_wait_for_event (child);
   stop_all_processes ();
-  disable_async_io ();
 
   if (must_set_ptrace_flags)
     {
@@ -1312,11 +1319,7 @@ linux_resume (struct thread_resume *resume_info)
   if (pending_flag)
     for_each_inferior (&all_threads, linux_queue_one_thread);
   else
-    {
-      block_async_io ();
-      enable_async_io ();
-      for_each_inferior (&all_threads, linux_continue_one_thread);
-    }
+    for_each_inferior (&all_threads, linux_continue_one_thread);
 }
 
 #ifdef HAVE_LINUX_USRREGS
@@ -1740,12 +1743,20 @@ linux_tracefork_grandchild (void *arg)
   _exit (0);
 }
 
+#define STACK_SIZE 4096
+
 static int
 linux_tracefork_child (void *arg)
 {
   ptrace (PTRACE_TRACEME, 0, 0, 0);
   kill (getpid (), SIGSTOP);
-  clone (linux_tracefork_grandchild, arg, CLONE_VM | SIGCHLD, NULL);
+#ifdef __ia64__
+  __clone2 (linux_tracefork_grandchild, arg, STACK_SIZE,
+           CLONE_VM | SIGCHLD, NULL);
+#else
+  clone (linux_tracefork_grandchild, arg + STACK_SIZE,
+        CLONE_VM | SIGCHLD, NULL);
+#endif
   _exit (0);
 }
 
@@ -1773,13 +1784,18 @@ linux_test_for_tracefork (void)
 {
   int child_pid, ret, status;
   long second_pid;
-  char *stack = malloc (8192);
+  char *stack = malloc (STACK_SIZE * 4);
 
   linux_supports_tracefork_flag = 0;
 
   /* Use CLONE_VM instead of fork, to support uClinux (no MMU).  */
-  child_pid = clone (linux_tracefork_child, stack + 2048,
-                    CLONE_VM | SIGCHLD, stack + 6144);
+#ifdef __ia64__
+  child_pid = __clone2 (linux_tracefork_child, stack, STACK_SIZE,
+                       CLONE_VM | SIGCHLD, stack + STACK_SIZE * 2);
+#else
+  child_pid = clone (linux_tracefork_child, stack + STACK_SIZE,
+                    CLONE_VM | SIGCHLD, stack + STACK_SIZE * 2);
+#endif
   if (child_pid == -1)
     perror_with_name ("clone");