]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdbserver/linux-low.cc
gdbserver: turn target op 'supports_z_point_type' into a method
[thirdparty/binutils-gdb.git] / gdbserver / linux-low.cc
index 676dea26c637afbd0a146f78810f20ccbda0b830..37e46a8ca22e21ec25f0189f2e99818c46fc4adf 100644 (file)
@@ -262,7 +262,6 @@ static int stabilizing_threads;
 
 static void linux_resume_one_lwp (struct lwp_info *lwp,
                                  int step, int signal, siginfo_t *info);
-static void linux_resume (struct thread_resume *resume_info, size_t n);
 static void stop_all_lwps (int suspend, struct lwp_info *except);
 static void unstop_all_lwps (int unsuspend, struct lwp_info *except);
 static void unsuspend_all_lwps (struct lwp_info *except);
@@ -270,7 +269,6 @@ static int linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
                                          int *wstat, int options);
 static int linux_wait_for_event (ptid_t ptid, int *wstat, int options);
 static struct lwp_info *add_lwp (ptid_t ptid);
-static void linux_mourn (struct process_info *process);
 static int linux_stopped_by_watchpoint (void);
 static void mark_lwp_dead (struct lwp_info *lwp, int wstat);
 static int lwp_is_marked_dead (struct lwp_info *lwp);
@@ -707,7 +705,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat)
       syscalls_to_catch = std::move (proc->syscalls_to_catch);
 
       /* Delete the execing process and all its threads.  */
-      linux_mourn (proc);
+      the_target->pt->mourn (proc);
       current_thread = NULL;
 
       /* Create a new process/lwp/thread.  */
@@ -996,9 +994,9 @@ linux_ptrace_fun ()
    PROGRAM is the name of the program to be started, and PROGRAM_ARGS
    are its arguments.  */
 
-static int
-linux_create_inferior (const char *program,
-                      const std::vector<char *> &program_args)
+int
+linux_process_target::create_inferior (const char *program,
+                                      const std::vector<char *> &program_args)
 {
   client_state &cs = get_client_state ();
   struct lwp_info *new_lwp;
@@ -1029,8 +1027,8 @@ linux_create_inferior (const char *program,
 
 /* Implement the post_create_inferior target_ops method.  */
 
-static void
-linux_post_create_inferior (void)
+void
+linux_process_target::post_create_inferior ()
 {
   struct lwp_info *lwp = get_thread_lwp (current_thread);
 
@@ -1181,8 +1179,8 @@ static void async_file_mark (void);
 /* Attach to PID.  If PID is the tgid, attach to it and all
    of its threads.  */
 
-static int
-linux_attach (unsigned long pid)
+int
+linux_process_target::attach (unsigned long pid)
 {
   struct process_info *proc;
   struct thread_info *initial_thread;
@@ -1386,8 +1384,8 @@ kill_one_lwp_callback (thread_info *thread, int pid)
   kill_wait_lwp (lwp);
 }
 
-static int
-linux_kill (process_info *process)
+int
+linux_process_target::kill (process_info *process)
 {
   int pid = process->pid;
 
@@ -1413,7 +1411,7 @@ linux_kill (process_info *process)
   else
     kill_wait_lwp (lwp);
 
-  the_target->mourn (process);
+  mourn (process);
 
   /* Since we presently can only stop all lwps of all processes, we
      need to unstop lwps of other processes.  */
@@ -1603,8 +1601,8 @@ linux_detach_lwp_callback (thread_info *thread)
   linux_detach_one_lwp (lwp);
 }
 
-static int
-linux_detach (process_info *process)
+int
+linux_process_target::detach (process_info *process)
 {
   struct lwp_info *main_lwp;
 
@@ -1634,7 +1632,7 @@ linux_detach (process_info *process)
   main_lwp = find_lwp_pid (ptid_t (process->pid));
   linux_detach_one_lwp (main_lwp);
 
-  the_target->mourn (process);
+  mourn (process);
 
   /* Since we presently can only stop all lwps of all processes, we
      need to unstop lwps of other processes.  */
@@ -1644,8 +1642,8 @@ linux_detach (process_info *process)
 
 /* Remove all LWPs that belong to process PROC from the lwp list.  */
 
-static void
-linux_mourn (struct process_info *process)
+void
+linux_process_target::mourn (process_info *process)
 {
   struct process_info_private *priv;
 
@@ -1670,8 +1668,8 @@ linux_mourn (struct process_info *process)
   remove_process (process);
 }
 
-static void
-linux_join (int pid)
+void
+linux_process_target::join (int pid)
 {
   int status, ret;
 
@@ -1682,9 +1680,10 @@ linux_join (int pid)
   } while (ret != -1 || errno != ECHILD);
 }
 
-/* Return nonzero if the given thread is still alive.  */
-static int
-linux_thread_alive (ptid_t ptid)
+/* Return true if the given thread is still alive.  */
+
+bool
+linux_process_target::thread_alive (ptid_t ptid)
 {
   struct lwp_info *lwp = find_lwp_pid (ptid);
 
@@ -3834,9 +3833,10 @@ async_file_mark (void)
      be awakened anyway.  */
 }
 
-static ptid_t
-linux_wait (ptid_t ptid,
-           struct target_waitstatus *ourstatus, int target_options)
+ptid_t
+linux_process_target::wait (ptid_t ptid,
+                           target_waitstatus *ourstatus,
+                           int target_options)
 {
   ptid_t event_ptid;
 
@@ -4005,7 +4005,7 @@ wait_for_sigstop (void)
                                       &wstat, __WALL);
   gdb_assert (ret == -1);
 
-  if (saved_thread == NULL || linux_thread_alive (saved_tid))
+  if (saved_thread == NULL || mythread_alive (saved_tid))
     current_thread = saved_thread;
   else
     {
@@ -5002,8 +5002,8 @@ linux_resume_one_thread (thread_info *thread, bool leave_all_stopped)
   lwp->resume = NULL;
 }
 
-static void
-linux_resume (struct thread_resume *resume_info, size_t n)
+void
+linux_process_target::resume (thread_resume *resume_info, size_t n)
 {
   struct thread_info *need_step_over = NULL;
 
@@ -5650,8 +5650,8 @@ usr_store_inferior_registers (const struct regs_info *regs_info,
 #endif
 
 
-static void
-linux_fetch_registers (struct regcache *regcache, int regno)
+void
+linux_process_target::fetch_registers (regcache *regcache, int regno)
 {
   int use_regsets;
   int all = 0;
@@ -5683,8 +5683,8 @@ linux_fetch_registers (struct regcache *regcache, int regno)
     }
 }
 
-static void
-linux_store_registers (struct regcache *regcache, int regno)
+void
+linux_process_target::store_registers (regcache *regcache, int regno)
 {
   int use_regsets;
   int all = 0;
@@ -5709,11 +5709,20 @@ linux_store_registers (struct regcache *regcache, int regno)
 }
 
 
-/* Copy LEN bytes from inferior's memory starting at MEMADDR
-   to debugger memory starting at MYADDR.  */
+/* A wrapper for the read_memory target op.  */
 
 static int
 linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
+{
+  return the_target->pt->read_memory (memaddr, myaddr, len);
+}
+
+/* Copy LEN bytes from inferior's memory starting at MEMADDR
+   to debugger memory starting at MYADDR.  */
+
+int
+linux_process_target::read_memory (CORE_ADDR memaddr,
+                                  unsigned char *myaddr, int len)
 {
   int pid = lwpid_of (current_thread);
   PTRACE_XFER_TYPE *buffer;
@@ -5801,8 +5810,9 @@ linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
    memory at MEMADDR.  On failure (cannot write to the inferior)
    returns the value of errno.  Always succeeds if LEN is zero.  */
 
-static int
-linux_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
+int
+linux_process_target::write_memory (CORE_ADDR memaddr,
+                                   const unsigned char *myaddr, int len)
 {
   int i;
   /* Round starting address down to longword boundary.  */
@@ -5888,8 +5898,8 @@ linux_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
   return 0;
 }
 
-static void
-linux_look_up_symbols (void)
+void
+linux_process_target::look_up_symbols ()
 {
 #ifdef USE_THREAD_DB
   struct process_info *proc = current_process ();
@@ -5901,19 +5911,26 @@ linux_look_up_symbols (void)
 #endif
 }
 
-static void
-linux_request_interrupt (void)
+void
+linux_process_target::request_interrupt ()
 {
   /* Send a SIGINT to the process group.  This acts just like the user
      typed a ^C on the controlling terminal.  */
-  kill (-signal_pid, SIGINT);
+  ::kill (-signal_pid, SIGINT);
+}
+
+bool
+linux_process_target::supports_read_auxv ()
+{
+  return true;
 }
 
 /* Copy LEN bytes from inferior's auxiliary vector starting at OFFSET
    to debugger memory starting at MYADDR.  */
 
-static int
-linux_read_auxv (CORE_ADDR offset, unsigned char *myaddr, unsigned int len)
+int
+linux_process_target::read_auxv (CORE_ADDR offset, unsigned char *myaddr,
+                                unsigned int len)
 {
   char filename[PATH_MAX];
   int fd, n;
@@ -5940,8 +5957,8 @@ linux_read_auxv (CORE_ADDR offset, unsigned char *myaddr, unsigned int len)
    pass on the function call if the target has registered a
    corresponding function.  */
 
-static int
-linux_supports_z_point_type (char z_type)
+bool
+linux_process_target::supports_z_point_type (char z_type)
 {
   return (the_low_target.supports_z_point_type != NULL
          && the_low_target.supports_z_point_type (z_type));
@@ -6505,8 +6522,8 @@ linux_unpause_all (int unfreeze)
   unstop_all_lwps (unfreeze, NULL);
 }
 
-static int
-linux_prepare_to_access_memory (void)
+int
+linux_process_target::prepare_to_access_memory ()
 {
   /* Neither ptrace nor /proc/PID/mem allow accessing memory through a
      running LWP.  */
@@ -6515,8 +6532,8 @@ linux_prepare_to_access_memory (void)
   return 0;
 }
 
-static void
-linux_done_accessing_memory (void)
+void
+linux_process_target::done_accessing_memory ()
 {
   /* Neither ptrace nor /proc/PID/mem allow accessing memory through a
      running LWP.  */
@@ -7307,7 +7324,7 @@ linux_get_auxv (int wordsize, CORE_ADDR match, CORE_ADDR *valp)
 
   gdb_assert (wordsize == 4 || wordsize == 8);
 
-  while ((*the_target->read_auxv) (offset, data, 2 * wordsize) == 2 * wordsize)
+  while (the_target->pt->read_auxv (offset, data, 2 * wordsize) == 2 * wordsize)
     {
       if (wordsize == 4)
        {
@@ -7354,27 +7371,11 @@ linux_get_hwcap2 (int wordsize)
   return hwcap2;
 }
 
+/* The linux target ops object.  */
+
+static linux_process_target the_linux_target;
+
 static process_stratum_target linux_target_ops = {
-  linux_create_inferior,
-  linux_post_create_inferior,
-  linux_attach,
-  linux_kill,
-  linux_detach,
-  linux_mourn,
-  linux_join,
-  linux_thread_alive,
-  linux_resume,
-  linux_wait,
-  linux_fetch_registers,
-  linux_store_registers,
-  linux_prepare_to_access_memory,
-  linux_done_accessing_memory,
-  linux_read_memory,
-  linux_write_memory,
-  linux_look_up_symbols,
-  linux_request_interrupt,
-  linux_read_auxv,
-  linux_supports_z_point_type,
   linux_insert_point,
   linux_remove_point,
   linux_stopped_by_sw_breakpoint,
@@ -7457,6 +7458,7 @@ static process_stratum_target linux_target_ops = {
 #else
   NULL,
 #endif
+  &the_linux_target,
 };
 
 #ifdef HAVE_LINUX_REGSETS