public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [gdbserver] move a bit of code from the linux backend to common code
@ 2010-08-09 15:04 Pedro Alves
  2010-08-25 16:26 ` [gdbserver 2/N] " Pedro Alves
  0 siblings, 1 reply; 2+ messages in thread
From: Pedro Alves @ 2010-08-09 15:04 UTC (permalink / raw)
  To: gdb-patches

This moves a bit of code from the linux backend to gdbserver's common code,
since #1, this is state that all backends would need for non-stop support;
#2, it should be possible to move the transparent step-over-breakpoints
support to common code (and that's what I was considering, though
I ended up giving up on that for now).

Tested on x86_64-linux and checked in.

-- 
Pedro Alves

2010-08-09  Pedro Alves  <pedro@codesourcery.com>

	gdbserver/
	* linux-low.c (gdb_wants_lwp_stopped): Delete.
	(gdb_wants_all_stopped): Delete.
	(linux_wait_1): Don't call them.
	* server.c (handle_v_cont): Tag all threads as want-stopped.
	(gdb_wants_thread_stopped): Fix comments.  Tag the thread that
	stopped as "client-wants-stopped".

---
 gdb/gdbserver/linux-low.c |   48 +---------------------------------------------
 gdb/gdbserver/server.c    |   20 +++++++++++++++++--
 2 files changed, 20 insertions(+), 48 deletions(-)

Index: src/gdb/gdbserver/linux-low.c
===================================================================
--- src.orig/gdb/gdbserver/linux-low.c	2010-08-06 13:18:46.000000000 +0100
+++ src/gdb/gdbserver/linux-low.c	2010-08-06 18:41:48.000000000 +0100
@@ -1809,24 +1809,6 @@ select_event_lwp (struct lwp_info **orig
     }
 }
 
-/* Set this inferior LWP's state as "want-stopped".  We won't resume
-   this LWP until the client gives us another action for it.  */
-
-static void
-gdb_wants_lwp_stopped (struct inferior_list_entry *entry)
-{
-  struct lwp_info *lwp = (struct lwp_info *) entry;
-  struct thread_info *thread = get_lwp_thread (lwp);
-
-  /* Most threads are stopped implicitly (all-stop); tag that with
-     signal 0.  The thread being explicitly reported stopped to the
-     client, gets it's status fixed up afterwards.  */
-  thread->last_status.kind = TARGET_WAITKIND_STOPPED;
-  thread->last_status.value.sig = TARGET_SIGNAL_0;
-
-  thread->last_resume_kind = resume_stop;
-}
-
 /* Decrement the suspend count of an LWP.  */
 
 static int
@@ -1853,14 +1835,6 @@ unsuspend_all_lwps (struct lwp_info *exc
   find_inferior (&all_lwps, unsuspend_one_lwp, except);
 }
 
-/* Set all LWP's states as "want-stopped".  */
-
-static void
-gdb_wants_all_stopped (void)
-{
-  for_each_inferior (&all_lwps, gdb_wants_lwp_stopped);
-}
-
 static void move_out_of_jump_pad_callback (struct inferior_list_entry *entry);
 static int stuck_in_jump_pad_callback (struct inferior_list_entry *entry,
 				       void *data);
@@ -2389,8 +2363,6 @@ Check if we're already there.\n",
 
   ourstatus->kind = TARGET_WAITKIND_STOPPED;
 
-  /* Do this before the gdb_wants_all_stopped calls below, since they
-     always set last_resume_kind to resume_stop.  */
   if (current_inferior->last_resume_kind == resume_stop
       && WSTOPSIG (w) == SIGSTOP)
     {
@@ -2413,30 +2385,14 @@ Check if we're already there.\n",
 
   gdb_assert (ptid_equal (step_over_bkpt, null_ptid));
 
-  if (stabilizing_threads)
-    return ptid_of (event_child);
-
-  if (!non_stop)
-    {
-      /* From GDB's perspective, all-stop mode always stops all
-	 threads implicitly.  Tag all threads as "want-stopped".  */
-      gdb_wants_all_stopped ();
-    }
-  else
-    {
-      /* We're reporting this LWP as stopped.  Update it's
-      	 "want-stopped" state to what the client wants, until it gets
-      	 a new resume action.  */
-      gdb_wants_lwp_stopped (&event_child->head);
-    }
-
   if (debug_threads)
     fprintf (stderr, "linux_wait ret = %s, %d, %d\n",
 	     target_pid_to_str (ptid_of (event_child)),
 	     ourstatus->kind,
 	     ourstatus->value.sig);
 
-  current_inferior->last_status = *ourstatus;
+  if (!stabilizing_threads)
+    current_inferior->last_status = *ourstatus;
 
   return ptid_of (event_child);
 }
Index: src/gdb/gdbserver/server.c
===================================================================
--- src.orig/gdb/gdbserver/server.c	2010-07-27 15:06:05.000000000 +0100
+++ src/gdb/gdbserver/server.c	2010-08-06 18:38:14.000000000 +0100
@@ -1674,6 +1674,8 @@ handle_query (char *own_buf, int packet_
   own_buf[0] = 0;
 }
 
+static void gdb_wants_all_threads_stopped (void);
+
 /* Parse vCont packets.  */
 void
 handle_v_cont (char *own_buf)
@@ -1777,6 +1779,12 @@ handle_v_cont (char *own_buf)
   else
     {
       last_ptid = mywait (minus_one_ptid, &last_status, 0, 1);
+
+      /* From the client's perspective, all-stop mode always stops all
+	 threads implicitly (and the target backend has already done
+	 so by now).  Tag all threads as "want-stopped", so we don't
+	 resume them implicitly without the client telling us to.  */
+      gdb_wants_all_threads_stopped ();
       prepare_resume_reply (own_buf, last_ptid, &last_status);
       disable_async_io ();
 
@@ -2129,8 +2137,9 @@ queue_stop_reply_callback (struct inferi
   return 0;
 }
 
-/* Set this inferior LWP's state as "want-stopped".  We won't resume
-   this LWP until the client gives us another action for it.  */
+/* Set this inferior threads's state as "want-stopped".  We won't
+   resume this thread until the client gives us another action for
+   it.  */
 
 static void
 gdb_wants_thread_stopped (struct inferior_list_entry *entry)
@@ -2141,6 +2150,8 @@ gdb_wants_thread_stopped (struct inferio
 
   if (thread->last_status.kind == TARGET_WAITKIND_IGNORE)
     {
+      /* Most threads are stopped implicitly (all-stop); tag that with
+	 signal 0.  */
       thread->last_status.kind = TARGET_WAITKIND_STOPPED;
       thread->last_status.value.sig = TARGET_SIGNAL_0;
     }
@@ -3123,6 +3134,11 @@ handle_target_event (int err, gdb_client
 	  mark_breakpoints_out (process);
 	  mourn_inferior (process);
 	}
+      else
+	/* We're reporting this thread as stopped.  Update it's
+	   "want-stopped" state to what the client wants, until it gets
+	   a new resume action.  */
+	gdb_wants_thread_stopped (&current_inferior->entry);
 
       if (forward_event)
 	{

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gdbserver 2/N] move a bit of code from the linux backend to common code
  2010-08-09 15:04 [gdbserver] move a bit of code from the linux backend to common code Pedro Alves
@ 2010-08-25 16:26 ` Pedro Alves
  0 siblings, 0 replies; 2+ messages in thread
From: Pedro Alves @ 2010-08-25 16:26 UTC (permalink / raw)
  To: gdb-patches

On Monday 09 August 2010 16:04:36, Pedro Alves wrote:
> This moves a bit of code from the linux backend to gdbserver's common code,
> since #1, this is state that all backends would need for non-stop support;
> #2, it should be possible to move the transparent step-over-breakpoints
> support to common code 

And here's a follow up, continuing the trend.

The main bit here is having linux_wait not need to know about the
stabilizing_threads global.

Tested on x86_64-linux, and applied.

-- 
Pedro Alves

2010-08-25  Pedro Alves  <pedro@codesourcery.com>

	* linux-low.c (linux_wait_1): Don't set last_status here.
	* server.c (push_event, queue_stop_reply_callback): Assert we're
	not pushing a TARGET_WAITKIND_IGNORE event.
	(start_inferior, start_inferior, attach_inferior, handle_v_cont)
	(myresume, handle_target_event): Set the thread's last_resume_kind
	and last_status from the target returned status.

---
 gdb/gdbserver/linux-low.c |    3 ---
 gdb/gdbserver/server.c    |   42 ++++++++++++++++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 7 deletions(-)

Index: src/gdb/gdbserver/linux-low.c
===================================================================
--- src.orig/gdb/gdbserver/linux-low.c	2010-08-25 15:20:55.000000000 +0100
+++ src/gdb/gdbserver/linux-low.c	2010-08-25 17:04:42.000000000 +0100
@@ -2391,9 +2391,6 @@ Check if we're already there.\n",
 	     ourstatus->kind,
 	     ourstatus->value.sig);
 
-  if (!stabilizing_threads)
-    current_inferior->last_status = *ourstatus;
-
   return ptid_of (event_child);
 }
 
Index: src/gdb/gdbserver/server.c
===================================================================
--- src.orig/gdb/gdbserver/server.c	2010-08-24 20:51:14.000000000 +0100
+++ src/gdb/gdbserver/server.c	2010-08-25 17:04:42.000000000 +0100
@@ -158,6 +158,8 @@ queue_stop_reply (ptid_t ptid, struct ta
 void
 push_event (ptid_t ptid, struct target_waitstatus *status)
 {
+  gdb_assert (status->kind != TARGET_WAITKIND_IGNORE);
+
   queue_stop_reply (ptid, status);
 
   /* If this is the first stop reply in the queue, then inform GDB
@@ -292,9 +294,14 @@ start_inferior (char **argv)
  	  mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
 	  if (last_status.kind != TARGET_WAITKIND_STOPPED)
 	    return signal_pid;
+
+	  current_inferior->last_resume_kind = resume_stop;
+	  current_inferior->last_status = last_status;
 	}
       while (last_status.value.sig != TARGET_SIGNAL_TRAP);
 
+      current_inferior->last_resume_kind = resume_stop;
+      current_inferior->last_status = last_status;
       return signal_pid;
     }
 
@@ -302,6 +309,13 @@ start_inferior (char **argv)
      (assuming success).  */
   last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
 
+  if (last_status.kind != TARGET_WAITKIND_EXITED
+      && last_status.kind != TARGET_WAITKIND_SIGNALLED)
+    {
+      current_inferior->last_resume_kind = resume_stop;
+      current_inferior->last_status = last_status;
+    }
+
   return signal_pid;
 }
 
@@ -332,6 +346,9 @@ attach_inferior (int pid)
       if (last_status.kind == TARGET_WAITKIND_STOPPED
 	  && last_status.value.sig == TARGET_SIGNAL_STOP)
 	last_status.value.sig = TARGET_SIGNAL_TRAP;
+
+      current_inferior->last_resume_kind = resume_stop;
+      current_inferior->last_status = last_status;
     }
 
   return 0;
@@ -1780,6 +1797,10 @@ handle_v_cont (char *own_buf)
     {
       last_ptid = mywait (minus_one_ptid, &last_status, 0, 1);
 
+      if (last_status.kind != TARGET_WAITKIND_EXITED
+          && last_status.kind != TARGET_WAITKIND_SIGNALLED)
+	current_inferior->last_status = last_status;
+
       /* From the client's perspective, all-stop mode always stops all
 	 threads implicitly (and the target backend has already done
 	 so by now).  Tag all threads as "want-stopped", so we don't
@@ -2089,6 +2110,14 @@ myresume (char *own_buf, int step, int s
   else
     {
       last_ptid = mywait (minus_one_ptid, &last_status, 0, 1);
+
+      if (last_status.kind != TARGET_WAITKIND_EXITED
+          && last_status.kind != TARGET_WAITKIND_SIGNALLED)
+	{
+	  current_inferior->last_resume_kind = resume_stop;
+	  current_inferior->last_status = last_status;
+	}
+
       prepare_resume_reply (own_buf, last_ptid, &last_status);
       disable_async_io ();
 
@@ -2128,6 +2157,8 @@ queue_stop_reply_callback (struct inferi
 		     target_pid_to_str (entry->id),
 		     target_waitstatus_to_string (&thread->last_status));
 
+	  gdb_assert (thread->last_status.kind != TARGET_WAITKIND_IGNORE);
+
 	  /* Pass the last stop reply back to GDB, but don't notify
 	     yet.  */
 	  queue_stop_reply (entry->id, &thread->last_status);
@@ -3135,10 +3166,13 @@ handle_target_event (int err, gdb_client
 	  mourn_inferior (process);
 	}
       else
-	/* We're reporting this thread as stopped.  Update it's
-	   "want-stopped" state to what the client wants, until it gets
-	   a new resume action.  */
-	gdb_wants_thread_stopped (&current_inferior->entry);
+	{
+	  /* We're reporting this thread as stopped.  Update its
+	     "want-stopped" state to what the client wants, until it
+	     gets a new resume action.  */
+	  current_inferior->last_resume_kind = resume_stop;
+	  current_inferior->last_status = last_status;
+	}
 
       if (forward_event)
 	{

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-25 16:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-09 15:04 [gdbserver] move a bit of code from the linux backend to common code Pedro Alves
2010-08-25 16:26 ` [gdbserver 2/N] " Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).