public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  scox/dyninst: Move global state to client_state and change callers
@ 2015-02-03 17:28 scox
  0 siblings, 0 replies; only message in thread
From: scox @ 2015-02-03 17:28 UTC (permalink / raw)
  To: archer-commits

The branch, scox/dyninst has been updated
       via  9bd9119042646a9f974898ae4ef7a92b074268fd (commit)
      from  aa94c518bc927f2214532a512d9c7399f9ec32d2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 9bd9119042646a9f974898ae4ef7a92b074268fd
Author: Stan Cox <scox@redhat.com>
Date:   Tue Feb 3 12:25:09 2015 -0500

    Move global state to client_state and change callers
    
    * server.h
    ** Add struct client_state.  All global variables are moved here.
    ** Change 'global_var' to 'cs = ...; cs->global_var...;'
    * server.c
    ** new_client_state creates a client_state for a new connection.
    ** set_client_state contains a static first_client_state which links to sibling client_state
    *** if there is no client_state for this fd create it, otherwise return it
    *** save the fd, if we are called with an fd of 0, return the client_state for the saved fd
    ** get_remote_desc is called wherever a global variable is accessed
    ** handle_query adds a parameter for the client_state pointer
    ** handle_v_requests adds a parameter for the client_state pointer
    ** captured_main sets up first_client_state
    ** process_serial_event adds a parameter for the client_state pointer
    * event-loop.c
    ** wait_for_event now adds a select in case another client tries to connect
    *** add a new client if so
    * remote-utils.c
    ** get_remote_desc and get_listen_desc are added so these fds can be accessed outside remote-utils.c
    ** handle_accept_event turns noack mode off as a subsequent connection seems to assume that
    *** set the default client_state to the new fd and don't close the listen_desc
    ** remote_open adds a parameter for client_state
    ** write_prim, read_prim, readchar, and getpkt add a parameter for fd

-----------------------------------------------------------------------

Summary of changes:
 gdb/gdbserver/dyninst-low.cc      |   37 ++++--
 gdb/gdbserver/event-loop.c        |   58 ++++++++-
 gdb/gdbserver/gdbthread.h         |    4 +-
 gdb/gdbserver/inferiors.c         |   57 +++++---
 gdb/gdbserver/inferiors.h         |    6 +-
 gdb/gdbserver/linux-aarch64-low.c |   11 +-
 gdb/gdbserver/linux-arm-low.c     |   30 +++--
 gdb/gdbserver/linux-cris-low.c    |    4 +-
 gdb/gdbserver/linux-crisv32-low.c |   15 ++-
 gdb/gdbserver/linux-low.c         |  279 +++++++++++++++++++++----------------
 gdb/gdbserver/linux-mips-low.c    |   21 ++-
 gdb/gdbserver/linux-nios2-low.c   |    3 +-
 gdb/gdbserver/linux-s390-low.c    |    3 +-
 gdb/gdbserver/linux-sparc-low.c   |    3 +-
 gdb/gdbserver/linux-tile-low.c    |    3 +-
 gdb/gdbserver/linux-x86-low.c     |   40 ++++--
 gdb/gdbserver/lynx-low.c          |   21 ++-
 gdb/gdbserver/mem-break.c         |   56 +++++---
 gdb/gdbserver/nto-low.c           |   20 ++-
 gdb/gdbserver/proc-service.c      |   13 +-
 gdb/gdbserver/regcache.c          |   23 ++--
 gdb/gdbserver/remote-utils.c      |  126 +++++++++++------
 gdb/gdbserver/remote-utils.h      |    2 +-
 gdb/gdbserver/server.c            |  168 +++++++++++++++--------
 gdb/gdbserver/server.h            |   28 ++--
 gdb/gdbserver/target.c            |    4 +-
 gdb/gdbserver/tdesc.c             |    4 +-
 gdb/gdbserver/thread-db.c         |   30 +++--
 gdb/gdbserver/tracepoint.c        |   13 +-
 gdb/gdbserver/win32-i386-low.c    |   17 ++-
 gdb/gdbserver/win32-low.c         |   37 ++++--
 31 files changed, 729 insertions(+), 407 deletions(-)

First 500 lines of diff:
diff --git a/gdb/gdbserver/dyninst-low.cc b/gdb/gdbserver/dyninst-low.cc
index fec8825..be4d6ef 100644
--- a/gdb/gdbserver/dyninst-low.cc
+++ b/gdb/gdbserver/dyninst-low.cc
@@ -359,16 +359,18 @@ void
 dyninst_add_thread(int pid, Thread::const_ptr thread)
 {
   Dyninst::LWP lwp;
+  client_state *cs = get_client_state ();
+
   if (thread != NULL)
     {
       struct thread_info_private *tip = new struct thread_info_private;
       tip->thread = thread;
       lwp = thread->getLWP();
-     current_thread =  add_thread (ptid_build (pid, lwp, 0), tip);
+      cs->current_thread =  add_thread (ptid_build (pid, lwp, 0), tip);
     }
   else
     {
-      current_thread = add_thread (ptid_build (pid, pid, 0), NULL);
+      cs->current_thread = add_thread (ptid_build (pid, pid, 0), NULL);
     }
 }
 
@@ -378,9 +380,11 @@ dyninst_add_thread(int pid, Thread::const_ptr thread)
 static Thread::const_ptr
 dyninst_get_inferior_thread()
 {
-  DEBUG("current_thread=" << current_thread);
-  struct thread_info_private *tip = (struct thread_info_private*)(current_thread->target_data);
-  DEBUG("", pid_to_string (current_thread->entry.id));
+  client_state *cs = get_client_state ();
+
+  DEBUG("current_thread=" << cs->current_thread);
+  struct thread_info_private *tip = (struct thread_info_private*)(cs->current_thread->target_data);
+  DEBUG("", pid_to_string (cs->current_thread->entry.id));
   if (!tip)
     error ("No inferior thread");
   return tip->thread;
@@ -564,13 +568,16 @@ dyninst_attach (unsigned long pid)
 static void
 dyninst_resume (struct thread_resume *resume_info, size_t n)
 {
+  client_state *cs = get_client_state ();
+
+
   for (int i = 0; i < (int)n; i++)
     {
       DEBUG("",pid_to_string(resume_info[i].thread));
       ptid_t ptid = resume_info[i].thread;
 
       if (ptid_equal (ptid, minus_one_ptid))
-	ptid = thread_to_gdb_id (current_thread);
+	ptid = thread_to_gdb_id (cs->current_thread);
 
       Dyninst::PID pid = ptid_get_pid (ptid);
       ProcessSet::iterator procset_it = dyninst_procset->find(pid);
@@ -657,8 +664,10 @@ dyninst_continue (ptid_t ptid)
 bool
 in_step_range ()
 {
-  struct thread_info_private *tip = (struct thread_info_private*)(current_thread->target_data);
-  struct regcache *regcache = get_thread_regcache (current_thread, 1);
+  client_state *cs = get_client_state ();
+
+  struct thread_info_private *tip = (struct thread_info_private*)(cs->current_thread->target_data);
+  struct regcache *regcache = get_thread_regcache (cs->current_thread, 1);
   CORE_ADDR pc = (*the_low_target.get_pc) (regcache);
 
   return (pc >= tip->step_range_start && pc < tip->step_range_end);
@@ -673,6 +682,7 @@ dyninst_wait_1 (ptid_t ptid, struct target_waitstatus *status, int options)
   ptid_t new_ptid = ptid;
   Dyninst::PID pid = ptid.pid;
   bool thread_created = false;
+  client_state *cs = get_client_state ();
 
   DEBUG("", pid_to_string (ptid));
 
@@ -768,8 +778,8 @@ dyninst_wait_1 (ptid_t ptid, struct target_waitstatus *status, int options)
       break;
     }
 
-  DEBUG("returning", pid_to_string (ptid_of(current_thread)));
-  return ptid_of (current_thread);
+  DEBUG("returning", pid_to_string (ptid_of(cs->current_thread)));
+  return ptid_of (cs->current_thread);
 //  return new_ptid;
 }
 
@@ -1028,7 +1038,9 @@ dyninst_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
 static void
 dyninst_request_interrupt (void)
 {
-  Dyninst::PID pid = ptid_get_pid (thread_to_gdb_id (current_thread));
+  client_state *cs = get_client_state ();
+
+  Dyninst::PID pid = ptid_get_pid (thread_to_gdb_id (cs->current_thread));
   ProcessSet::iterator procset_it = dyninst_procset->find(pid);
   Process::ptr dyninst_process = *procset_it;
 
@@ -1045,7 +1057,8 @@ dyninst_read_auxv (CORE_ADDR offset, unsigned char *myaddr, unsigned int len)
 {
   char filename[PATH_MAX];
   int fd, n;
-  int pid = lwpid_of (current_thread);
+  client_state *cs = get_client_state ();
+  int pid = lwpid_of (cs->current_thread);
 
   xsnprintf (filename, sizeof filename, "/proc/%d/auxv", pid);
 
diff --git a/gdb/gdbserver/event-loop.c b/gdb/gdbserver/event-loop.c
index 92c8db0..7185c02 100644
--- a/gdb/gdbserver/event-loop.c
+++ b/gdb/gdbserver/event-loop.c
@@ -23,6 +23,9 @@
 
 #include <sys/types.h>
 #include <sys/time.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
 
 #ifdef USE_WIN32API
 #include <windows.h>
@@ -160,6 +163,7 @@ initialize_event_loop (void)
   event_queue = QUEUE_alloc (gdb_event_p, gdb_event_xfree);
 }
 
+
 /* Process one event.  If an event was processed, 1 is returned
    otherwise 0 is returned.  Scan the queue from head to tail,
    processing therefore the high priority events first, by invoking
@@ -277,6 +281,8 @@ create_file_handler (gdb_fildes_t fd, int mask, handler_func *proc,
 {
   file_handler *file_ptr;
 
+  if (debug_threads)
+    fprintf (stderr,"%s matched fd %d\n",__FUNCTION__,fd);
   /* Do we already have a file handler for this file? (We may be
      changing its associated procedure).  */
   for (file_ptr = gdb_notifier.first_file_handler;
@@ -337,6 +343,8 @@ delete_file_handler (gdb_fildes_t fd)
   file_handler *file_ptr, *prev_ptr = NULL;
   int i;
 
+  if (debug_threads)
+    fprintf (stderr,"%s matched fd %d\n",__FUNCTION__,fd);
   /* Find the entry for the given file. */
 
   for (file_ptr = gdb_notifier.first_file_handler;
@@ -426,6 +434,7 @@ handle_file_event (gdb_fildes_t event_file_desc)
 	  /* If there was a match, then call the handler.  */
 	  if (mask != 0)
 	    {
+	      set_client_state (file_ptr->fd);
 	      if ((*file_ptr->proc) (file_ptr->error,
 				     file_ptr->client_data) < 0)
 		return -1;
@@ -459,12 +468,46 @@ create_file_event (gdb_fildes_t fd)
    select.  Return -1 if there are no files descriptors to monitor,
    otherwise return 0.  */
 
+int get_remote_desc();
+int get_listen_desc();
+
 static int
 wait_for_event (void)
 {
   file_handler *file_ptr;
   int num_found = 0;
 
+  //
+  fd_set conn_fd_set;
+  struct timeval timeout;
+  FD_ZERO(&conn_fd_set);
+  FD_SET(get_listen_desc(),&conn_fd_set);
+  timeout.tv_sec = 0;
+  timeout.tv_usec = 10;
+  num_found = select (FD_SETSIZE, &conn_fd_set, NULL, NULL, &timeout);
+  fprintf (stderr,"%s select fd=%d found=%d\n",__FUNCTION__,get_listen_desc(),num_found);
+  if (num_found > 0)
+    {
+    int i;
+      for (i = 1; i < FD_SETSIZE; ++i)
+	if (FD_ISSET (i, &conn_fd_set))
+	  {
+	    if (i == get_listen_desc())
+	      {
+		int handle_accept_event (int, gdb_client_data);
+		if (debug_threads)
+		  fprintf (stderr,"%s in select idx %d\n",__FUNCTION__,i);
+		// instead of using gdb_event just setup the connection "by hand"
+		handle_accept_event (0, NULL);
+		add_file_handler (get_remote_desc(), handle_serial_event, get_client_state());
+	      }
+	    else
+	      if (debug_threads)
+		fprintf (stderr,"%s data arrived on existing connection %d fd=%d\n", __FUNCTION__, 	i,get_listen_desc());
+	  }
+    }
+  //
+
   /* Make sure all output is done before getting another event.  */
   fflush (stdout);
   fflush (stderr);
@@ -481,6 +524,10 @@ wait_for_event (void)
 		      &gdb_notifier.ready_masks[2],
 		      NULL);
 
+  if (debug_threads)
+    fprintf(stderr,"select num_fds %d returned %d\n",gdb_notifier.num_fds,num_found);
+  if (num_found < 0)
+    perror(__FUNCTION__);
   /* Clear the masks after an error from select.  */
   if (num_found == -1)
     {
@@ -496,7 +543,7 @@ wait_for_event (void)
     }
 
   /* Enqueue all detected file events.  */
-
+  fprintf (stderr,"%s 1 #fds=%d\n",__FUNCTION__,gdb_notifier.num_fds);
   for (file_ptr = gdb_notifier.first_file_handler;
        file_ptr != NULL && num_found > 0;
        file_ptr = file_ptr->next_file)
@@ -520,8 +567,11 @@ wait_for_event (void)
 
       if (file_ptr->ready_mask == 0)
 	{
+	  int handle_accept_event (int err, gdb_client_data client_data);
 	  gdb_event *file_event_ptr = create_file_event (file_ptr->fd);
-
+	  fprintf (stderr,"%s 2 #fds=%d\n",__FUNCTION__,gdb_notifier.num_fds);
+	  if (debug_threads)
+	    fprintf(stderr,"%s create_file_event for %d %#lx %#lx %#lx %#lx\n",__FUNCTION__,file_event_ptr->fd,(long unsigned int)file_ptr->proc,(long unsigned int)handle_file_event,(long unsigned int)handle_serial_event,(long unsigned int)handle_accept_event);
 	  QUEUE_enque (gdb_event_p, event_queue, file_event_ptr);
 	}
       file_ptr->ready_mask = mask;
@@ -545,6 +595,8 @@ start_event_loop (void)
     {
       /* Any events already waiting in the queue?  */
       int res = process_event ();
+      if (debug_threads)
+	fprintf (stderr, "COX  After process_event\n");
 
       /* Did the event handler want the event loop to stop?  */
       if (res == -1)
@@ -568,6 +620,8 @@ start_event_loop (void)
 	 sources left.  This will make the event loop stop, and the
 	 application exit.  */
 
+      if (debug_threads)
+	fprintf (stderr, "COX Before start_event_loop return\n");
       if (wait_for_event () < 0)
 	return;
     }
diff --git a/gdb/gdbserver/gdbthread.h b/gdb/gdbserver/gdbthread.h
index 8290ec1..7ae481b 100644
--- a/gdb/gdbserver/gdbthread.h
+++ b/gdb/gdbserver/gdbthread.h
@@ -70,7 +70,7 @@ struct thread_info
   struct btrace_target_info *btrace;
 };
 
-extern struct inferior_list all_threads;
+// extern struct inferior_list cs->all_threads;
 
 void remove_thread (struct thread_info *thread);
 struct thread_info *add_thread (ptid_t ptid, void *target_data);
@@ -80,6 +80,6 @@ struct thread_info *get_first_thread (void);
 struct thread_info *find_thread_ptid (ptid_t ptid);
 
 /* Get current thread ID (Linux task ID).  */
-#define current_ptid (current_thread->entry.id)
+#define current_ptid ({client_state *cs = get_client_state (); cs->current_thread->entry.id;})
 
 #endif /* GDB_THREAD_H */
diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index 379c51d..3b150ac 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -22,10 +22,10 @@
 #include "gdbthread.h"
 #include "dll.h"
 
-struct inferior_list all_processes;
-struct inferior_list all_threads;
+// struct inferior_list all_processes;
+// struct inferior_list all_threads;
 
-struct thread_info *current_thread;
+// struct thread_info *cs->current_thread;
 
 #define get_thread(inf) ((struct thread_info *)(inf))
 
@@ -106,6 +106,7 @@ struct thread_info *
 add_thread (ptid_t thread_id, void *target_data)
 {
   struct thread_info *new_thread = xmalloc (sizeof (*new_thread));
+  client_state *cs = get_client_state ();
 
   memset (new_thread, 0, sizeof (*new_thread));
 
@@ -113,10 +114,10 @@ add_thread (ptid_t thread_id, void *target_data)
   new_thread->last_resume_kind = resume_continue;
   new_thread->last_status.kind = TARGET_WAITKIND_IGNORE;
 
-  add_inferior_to_list (&all_threads, &new_thread->entry);
+  add_inferior_to_list (&cs->all_threads, &new_thread->entry);
 
-  if (current_thread == NULL)
-    current_thread = new_thread;
+  if (cs->current_thread == NULL)
+    cs->current_thread = new_thread;
 
   new_thread->target_data = target_data;
 
@@ -134,13 +135,17 @@ thread_to_gdb_id (struct thread_info *thread)
 struct thread_info *
 get_first_thread (void)
 {
-  return (struct thread_info *) get_first_inferior (&all_threads);
+  client_state *cs = get_client_state ();
+
+  return (struct thread_info *) get_first_inferior (&cs->all_threads);
 }
 
 struct thread_info *
 find_thread_ptid (ptid_t ptid)
 {
-  return (struct thread_info *) find_inferior_id (&all_threads, ptid);
+  client_state *cs = get_client_state ();
+
+  return (struct thread_info *) find_inferior_id (&cs->all_threads, ptid);
 }
 
 ptid_t
@@ -162,10 +167,12 @@ free_one_thread (struct inferior_list_entry *inf)
 void
 remove_thread (struct thread_info *thread)
 {
+  client_state *cs = get_client_state ();
+
   if (thread->btrace != NULL)
     target_disable_btrace (thread->btrace);
 
-  remove_inferior (&all_threads, (struct inferior_list_entry *) thread);
+  remove_inferior (&cs->all_threads, (struct inferior_list_entry *) thread);
   free_one_thread (&thread->entry);
 }
 
@@ -262,25 +269,28 @@ clear_inferior_list (struct inferior_list *list)
 void
 clear_inferiors (void)
 {
-  for_each_inferior (&all_threads, free_one_thread);
-  clear_inferior_list (&all_threads);
+  client_state *cs = get_client_state ();
+
+  for_each_inferior (&cs->all_threads, free_one_thread);
+  clear_inferior_list (&cs->all_threads);
 
   clear_dlls ();
 
-  current_thread = NULL;
+  cs->current_thread = NULL;
 }
 
 struct process_info *
 add_process (int pid, int attached)
 {
   struct process_info *process;
+  client_state *cs = get_client_state ();
 
   process = xcalloc (1, sizeof (*process));
 
   process->entry.id = pid_to_ptid (pid);
   process->attached = attached;
 
-  add_inferior_to_list (&all_processes, &process->entry);
+  add_inferior_to_list (&cs->all_processes, &process->entry);
 
   return process;
 }
@@ -292,17 +302,21 @@ add_process (int pid, int attached)
 void
 remove_process (struct process_info *process)
 {
+  client_state *cs = get_client_state ();
+
   clear_symbol_cache (&process->symbol_cache);
   free_all_breakpoints (process);
-  remove_inferior (&all_processes, &process->entry);
+  remove_inferior (&cs->all_processes, &process->entry);
   free (process);
 }
 
 struct process_info *
 find_process_pid (int pid)
 {
+  client_state *cs = get_client_state ();
+
   return (struct process_info *)
-    find_inferior_id (&all_processes, pid_to_ptid (pid));
+    find_inferior_id (&cs->all_processes, pid_to_ptid (pid));
 }
 
 /* Return non-zero if INF, a struct process_info, was started by us,
@@ -322,7 +336,9 @@ started_inferior_callback (struct inferior_list_entry *entry, void *args)
 int
 have_started_inferiors_p (void)
 {
-  return (find_inferior (&all_processes, started_inferior_callback, NULL)
+  client_state *cs = get_client_state ();
+
+  return (find_inferior (&cs->all_processes, started_inferior_callback, NULL)
 	  != NULL);
 }
 
@@ -341,7 +357,9 @@ attached_inferior_callback (struct inferior_list_entry *entry, void *args)
 int
 have_attached_inferiors_p (void)
 {
-  return (find_inferior (&all_processes, attached_inferior_callback, NULL)
+  client_state *cs = get_client_state ();
+
+  return (find_inferior (&cs->all_processes, attached_inferior_callback, NULL)
 	  != NULL);
 }
 
@@ -355,6 +373,7 @@ get_thread_process (struct thread_info *thread)
 struct process_info *
 current_process (void)
 {
-  gdb_assert (current_thread != NULL);
-  return get_thread_process (current_thread);
+  client_state *cs = get_client_state ();
+  gdb_assert (cs->current_thread != NULL);
+  return get_thread_process (cs->current_thread);
 }
diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h
index f99947b..e244b9a 100644
--- a/gdb/gdbserver/inferiors.h
+++ b/gdb/gdbserver/inferiors.h
@@ -83,7 +83,7 @@ struct process_info
 struct process_info *current_process (void);
 struct process_info *get_thread_process (struct thread_info *);
 
-extern struct inferior_list all_processes;
+// extern struct inferior_list cs->all_processes;
 
 void add_inferior_to_list (struct inferior_list *list,
 			   struct inferior_list_entry *new_inferior);
@@ -119,9 +119,9 @@ int one_inferior_p (struct inferior_list *list);
 
 /* Iterate over all processes, open loop style.  */
 #define ALL_PROCESSES(cur, tmp)					\
-  ALL_INFERIORS_TYPE (struct process_info, &all_processes, cur, tmp)
+  ALL_INFERIORS_TYPE (struct process_info, &cs->all_processes, cur, tmp)
 
-extern struct thread_info *current_thread;
+// extern struct thread_info *current_thread;
 void remove_inferior (struct inferior_list *list,
 		      struct inferior_list_entry *entry);
 
diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index 01dff7f..93eb4f5 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -695,14 +695,15 @@ aarch64_notify_debug_reg_change (const struct aarch64_debug_reg_state *state,
 				 int is_watchpoint, unsigned int idx)
 {
   struct aarch64_dr_update_callback_param param;
+  client_state *cs = get_client_state ();
 
   /* Only update the threads of this process.  */
-  param.pid = pid_of (current_thread);
+  param.pid = pid_of (cs->current_thread);
 
   param.is_watchpoint = is_watchpoint;
   param.idx = idx;
 
-  find_inferior (&all_threads, debug_reg_change_callback, (void *) &param);
+  find_inferior (&cs->all_threads, debug_reg_change_callback, (void *) &param);
 }
 
 
@@ -1037,8 +1038,9 @@ aarch64_stopped_data_address (void)
   siginfo_t siginfo;
   int pid, i;
   struct aarch64_debug_reg_state *state;
+  client_state *cs = get_client_state ();
 
-  pid = lwpid_of (current_thread);
+  pid = lwpid_of (cs->current_thread);
 
   /* Get the siginfo.  */
   if (ptrace (PTRACE_GETSIGINFO, pid, NULL, &siginfo) != 0)
@@ -1183,10 +1185,11 @@ aarch64_arch_setup (void)


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-02-03 17:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-03 17:28 [SCM] scox/dyninst: Move global state to client_state and change callers scox

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).