gdbserver: finish turning the target ops vector into a class
[deliverable/binutils-gdb.git] / gdbserver / linux-low.cc
index 19d84c2d042d853b951f5baa709d97aa5eec8beb..2872bc78da95111dac4f7ad661658110941fd371 100644 (file)
@@ -711,7 +711,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.  */
-      the_target->pt->mourn (proc);
+      the_target->mourn (proc);
       current_thread = NULL;
 
       /* Create a new process/lwp/thread.  */
@@ -1628,7 +1628,7 @@ linux_process_target::detach (process_info *process)
 #endif
 
   /* Stabilize threads (move out of jump pads).  */
-  stabilize_threads ();
+  target_stabilize_threads ();
 
   /* Detach from the clone lwps first.  If the thread group exits just
      while we're detaching, we must reap the clone lwps before we're
@@ -2934,8 +2934,8 @@ static ptid_t linux_wait_1 (ptid_t ptid,
    since for something else in the new run, the thread would now
    execute the wrong / random instructions.  */
 
-static void
-linux_stabilize_threads (void)
+void
+linux_process_target::stabilize_threads ()
 {
   thread_info *thread_stuck = find_thread (stuck_in_jump_pad_callback);
 
@@ -3721,7 +3721,7 @@ linux_wait_1 (ptid_t ptid,
 
       /* Stabilize threads (move out of jump pads).  */
       if (!non_stop)
-       stabilize_threads ();
+       target_stabilize_threads ();
     }
   else
     {
@@ -5720,7 +5720,7 @@ linux_process_target::store_registers (regcache *regcache, int regno)
 static int
 linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
 {
-  return the_target->pt->read_memory (memaddr, myaddr, len);
+  return the_target->read_memory (memaddr, myaddr, len);
 }
 
 /* Copy LEN bytes from inferior's memory starting at MEMADDR
@@ -6044,8 +6044,8 @@ linux_process_target::supports_hardware_single_step ()
   return can_hardware_single_step ();
 }
 
-static int
-linux_supports_software_single_step (void)
+bool
+linux_process_target::supports_software_single_step ()
 {
   return can_software_single_step ();
 }
@@ -6408,33 +6408,77 @@ linux_process_target::handle_monitor_command (char *mon)
 #endif
 }
 
-static int
-linux_supports_disable_randomization (void)
+int
+linux_process_target::core_of_thread (ptid_t ptid)
+{
+  return linux_common_core_of_thread (ptid);
+}
+
+bool
+linux_process_target::supports_disable_randomization ()
 {
 #ifdef HAVE_PERSONALITY
-  return 1;
+  return true;
 #else
-  return 0;
+  return false;
 #endif
 }
 
-static int
-linux_supports_agent (void)
+bool
+linux_process_target::supports_agent ()
 {
-  return 1;
+  return true;
 }
 
-static int
-linux_supports_range_stepping (void)
+bool
+linux_process_target::supports_range_stepping ()
 {
   if (can_software_single_step ())
-    return 1;
+    return true;
   if (*the_low_target.supports_range_stepping == NULL)
-    return 0;
+    return false;
 
   return (*the_low_target.supports_range_stepping) ();
 }
 
+bool
+linux_process_target::supports_pid_to_exec_file ()
+{
+  return true;
+}
+
+char *
+linux_process_target::pid_to_exec_file (int pid)
+{
+  return linux_proc_pid_to_exec_file (pid);
+}
+
+bool
+linux_process_target::supports_multifs ()
+{
+  return true;
+}
+
+int
+linux_process_target::multifs_open (int pid, const char *filename,
+                                   int flags, mode_t mode)
+{
+  return linux_mntns_open_cloexec (pid, filename, flags, mode);
+}
+
+int
+linux_process_target::multifs_unlink (int pid, const char *filename)
+{
+  return linux_mntns_unlink (pid, filename);
+}
+
+ssize_t
+linux_process_target::multifs_readlink (int pid, const char *filename,
+                                       char *buf, size_t bufsiz)
+{
+  return linux_mntns_readlink (pid, filename, buf, bufsiz);
+}
+
 #if defined PT_GETDSBT || defined PTRACE_GETFDPIC
 struct target_loadseg
 {
@@ -6477,9 +6521,15 @@ struct target_loadmap
 #  define LINUX_LOADMAP_INTERP PTRACE_GETFDPIC_INTERP
 # endif
 
-static int
-linux_read_loadmap (const char *annex, CORE_ADDR offset,
-                   unsigned char *myaddr, unsigned int len)
+bool
+linux_process_target::supports_read_loadmap ()
+{
+  return true;
+}
+
+int
+linux_process_target::read_loadmap (const char *annex, CORE_ADDR offset,
+                                   unsigned char *myaddr, unsigned int len)
 {
   int pid = lwpid_of (current_thread);
   int addr = -1;
@@ -6509,26 +6559,24 @@ linux_read_loadmap (const char *annex, CORE_ADDR offset,
   memcpy (myaddr, (char *) data + offset, copy_length);
   return copy_length;
 }
-#else
-# define linux_read_loadmap NULL
 #endif /* defined PT_GETDSBT || defined PTRACE_GETFDPIC */
 
-static void
-linux_process_qsupported (char **features, int count)
+void
+linux_process_target::process_qsupported (char **features, int count)
 {
   if (the_low_target.process_qsupported != NULL)
     the_low_target.process_qsupported (features, count);
 }
 
-static int
-linux_supports_catch_syscall (void)
+bool
+linux_process_target::supports_catch_syscall ()
 {
   return (the_low_target.get_syscall_trapinfo != NULL
          && linux_supports_tracesysgood ());
 }
 
-static int
-linux_get_ipa_tdesc_idx (void)
+int
+linux_process_target::get_ipa_tdesc_idx ()
 {
   if (the_low_target.get_ipa_tdesc_idx == NULL)
     return 0;
@@ -6536,17 +6584,17 @@ linux_get_ipa_tdesc_idx (void)
   return (*the_low_target.get_ipa_tdesc_idx) ();
 }
 
-static int
-linux_supports_tracepoints (void)
+bool
+linux_process_target::supports_tracepoints ()
 {
   if (*the_low_target.supports_tracepoints == NULL)
-    return 0;
+    return false;
 
   return (*the_low_target.supports_tracepoints) ();
 }
 
-static CORE_ADDR
-linux_read_pc (struct regcache *regcache)
+CORE_ADDR
+linux_process_target::read_pc (regcache *regcache)
 {
   if (the_low_target.get_pc == NULL)
     return 0;
@@ -6554,24 +6602,30 @@ linux_read_pc (struct regcache *regcache)
   return (*the_low_target.get_pc) (regcache);
 }
 
-static void
-linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
+void
+linux_process_target::write_pc (regcache *regcache, CORE_ADDR pc)
 {
   gdb_assert (the_low_target.set_pc != NULL);
 
   (*the_low_target.set_pc) (regcache, pc);
 }
 
-static int
-linux_thread_stopped (struct thread_info *thread)
+bool
+linux_process_target::supports_thread_stopped ()
+{
+  return true;
+}
+
+bool
+linux_process_target::thread_stopped (thread_info *thread)
 {
   return get_thread_lwp (thread)->stopped;
 }
 
 /* This exposes stop-all-threads functionality to other modules.  */
 
-static void
-linux_pause_all (int freeze)
+void
+linux_process_target::pause_all (bool freeze)
 {
   stop_all_lwps (freeze, NULL);
 }
@@ -6579,8 +6633,8 @@ linux_pause_all (int freeze)
 /* This exposes unstop-all-threads functionality to other gdbserver
    modules.  */
 
-static void
-linux_unpause_all (int unfreeze)
+void
+linux_process_target::unpause_all (bool unfreeze)
 {
   unstop_all_lwps (unfreeze, NULL);
 }
@@ -6591,7 +6645,7 @@ linux_process_target::prepare_to_access_memory ()
   /* Neither ptrace nor /proc/PID/mem allow accessing memory through a
      running LWP.  */
   if (non_stop)
-    linux_pause_all (1);
+    target_pause_all (true);
   return 0;
 }
 
@@ -6601,22 +6655,23 @@ linux_process_target::done_accessing_memory ()
   /* Neither ptrace nor /proc/PID/mem allow accessing memory through a
      running LWP.  */
   if (non_stop)
-    linux_unpause_all (1);
+    target_unpause_all (true);
 }
 
-static int
-linux_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, CORE_ADDR tpaddr,
-                                       CORE_ADDR collector,
-                                       CORE_ADDR lockaddr,
-                                       ULONGEST orig_size,
-                                       CORE_ADDR *jump_entry,
-                                       CORE_ADDR *trampoline,
-                                       ULONGEST *trampoline_size,
-                                       unsigned char *jjump_pad_insn,
-                                       ULONGEST *jjump_pad_insn_size,
-                                       CORE_ADDR *adjusted_insn_addr,
-                                       CORE_ADDR *adjusted_insn_addr_end,
-                                       char *err)
+bool
+linux_process_target::supports_fast_tracepoints ()
+{
+  return the_low_target.install_fast_tracepoint_jump_pad != nullptr;
+}
+
+int
+linux_process_target::install_fast_tracepoint_jump_pad
+  (CORE_ADDR tpoint, CORE_ADDR tpaddr, CORE_ADDR collector,
+   CORE_ADDR lockaddr, ULONGEST orig_size, CORE_ADDR *jump_entry,
+   CORE_ADDR *trampoline, ULONGEST *trampoline_size,
+   unsigned char *jjump_pad_insn, ULONGEST *jjump_pad_insn_size,
+   CORE_ADDR *adjusted_insn_addr, CORE_ADDR *adjusted_insn_addr_end,
+   char *err)
 {
   return (*the_low_target.install_fast_tracepoint_jump_pad)
     (tpoint, tpaddr, collector, lockaddr, orig_size,
@@ -6626,8 +6681,8 @@ linux_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, CORE_ADDR tpaddr,
      err);
 }
 
-static struct emit_ops *
-linux_emit_ops (void)
+emit_ops *
+linux_process_target::emit_ops ()
 {
   if (the_low_target.emit_ops != NULL)
     return (*the_low_target.emit_ops) ();
@@ -6635,8 +6690,8 @@ linux_emit_ops (void)
     return NULL;
 }
 
-static int
-linux_get_min_fast_tracepoint_insn_len (void)
+int
+linux_process_target::get_min_fast_tracepoint_insn_len ()
 {
   return (*the_low_target.get_min_fast_tracepoint_insn_len) ();
 }
@@ -6914,6 +6969,12 @@ read_one_ptr (CORE_ADDR memaddr, CORE_ADDR *ptr, int ptr_size)
   return ret;
 }
 
+bool
+linux_process_target::supports_qxfer_libraries_svr4 ()
+{
+  return true;
+}
+
 struct link_map_offsets
   {
     /* Offset and size of r_debug.r_version.  */
@@ -6940,10 +7001,11 @@ struct link_map_offsets
 
 /* Construct qXfer:libraries-svr4:read reply.  */
 
-static int
-linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
-                           unsigned const char *writebuf,
-                           CORE_ADDR offset, int len)
+int
+linux_process_target::qxfer_libraries_svr4 (const char *annex,
+                                           unsigned char *readbuf,
+                                           unsigned const char *writebuf,
+                                           CORE_ADDR offset, int len)
 {
   struct process_info_private *const priv = current_process ()->priv;
   char filename[PATH_MAX];
@@ -7129,10 +7191,17 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
 
 #ifdef HAVE_LINUX_BTRACE
 
+btrace_target_info *
+linux_process_target::enable_btrace (ptid_t ptid,
+                                    const btrace_config *conf)
+{
+  return linux_enable_btrace (ptid, conf);
+}
+
 /* See to_disable_btrace target method.  */
 
-static int
-linux_low_disable_btrace (struct btrace_target_info *tinfo)
+int
+linux_process_target::disable_btrace (btrace_target_info *tinfo)
 {
   enum btrace_error err;
 
@@ -7191,9 +7260,10 @@ linux_low_encode_raw (struct buffer *buffer, const gdb_byte *data,
 
 /* See to_read_btrace target method.  */
 
-static int
-linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
-                      enum btrace_read_type type)
+int
+linux_process_target::read_btrace (btrace_target_info *tinfo,
+                                  buffer *buffer,
+                                  enum btrace_read_type type)
 {
   struct btrace_data btrace;
   enum btrace_error err;
@@ -7250,9 +7320,9 @@ linux_low_read_btrace (struct btrace_target_info *tinfo, struct buffer *buffer,
 
 /* See to_btrace_conf target method.  */
 
-static int
-linux_low_btrace_conf (const struct btrace_target_info *tinfo,
-                      struct buffer *buffer)
+int
+linux_process_target::read_btrace_conf (const btrace_target_info *tinfo,
+                                       buffer *buffer)
 {
   const struct btrace_config *conf;
 
@@ -7296,19 +7366,19 @@ current_lwp_ptid (void)
 
 /* Implementation of the target_ops method "breakpoint_kind_from_pc".  */
 
-static int
-linux_breakpoint_kind_from_pc (CORE_ADDR *pcptr)
+int
+linux_process_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr)
 {
   if (the_low_target.breakpoint_kind_from_pc != NULL)
     return (*the_low_target.breakpoint_kind_from_pc) (pcptr);
   else
-    return default_breakpoint_kind_from_pc (pcptr);
+    return process_stratum_target::breakpoint_kind_from_pc (pcptr);
 }
 
 /* Implementation of the target_ops method "sw_breakpoint_from_kind".  */
 
-static const gdb_byte *
-linux_sw_breakpoint_from_kind (int kind, int *size)
+const gdb_byte *
+linux_process_target::sw_breakpoint_from_kind (int kind, int *size)
 {
   gdb_assert (the_low_target.sw_breakpoint_from_kind != NULL);
 
@@ -7318,15 +7388,30 @@ linux_sw_breakpoint_from_kind (int kind, int *size)
 /* Implementation of the target_ops method
    "breakpoint_kind_from_current_state".  */
 
-static int
-linux_breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
+int
+linux_process_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
 {
   if (the_low_target.breakpoint_kind_from_current_state != NULL)
     return (*the_low_target.breakpoint_kind_from_current_state) (pcptr);
   else
-    return linux_breakpoint_kind_from_pc (pcptr);
+    return breakpoint_kind_from_pc (pcptr);
 }
 
+const char *
+linux_process_target::thread_name (ptid_t thread)
+{
+  return linux_proc_tid_get_name (thread);
+}
+
+#if USE_THREAD_DB
+bool
+linux_process_target::thread_handle (ptid_t ptid, gdb_byte **handle,
+                                    int *handle_len)
+{
+  return thread_db_thread_handle (ptid, handle, handle_len);
+}
+#endif
+
 /* Default implementation of linux_target_ops method "set_pc" for
    32-bit pc register which is literally named "pc".  */
 
@@ -7387,7 +7472,7 @@ linux_get_auxv (int wordsize, CORE_ADDR match, CORE_ADDR *valp)
 
   gdb_assert (wordsize == 4 || wordsize == 8);
 
-  while (the_target->pt->read_auxv (offset, data, 2 * wordsize) == 2 * wordsize)
+  while (the_target->read_auxv (offset, data, 2 * wordsize) == 2 * wordsize)
     {
       if (wordsize == 4)
        {
@@ -7438,55 +7523,6 @@ linux_get_hwcap2 (int wordsize)
 
 static linux_process_target the_linux_target;
 
-static process_stratum_target linux_target_ops = {
-  linux_common_core_of_thread,
-  linux_read_loadmap,
-  linux_process_qsupported,
-  linux_supports_tracepoints,
-  linux_read_pc,
-  linux_write_pc,
-  linux_thread_stopped,
-  NULL,
-  linux_pause_all,
-  linux_unpause_all,
-  linux_stabilize_threads,
-  linux_install_fast_tracepoint_jump_pad,
-  linux_emit_ops,
-  linux_supports_disable_randomization,
-  linux_get_min_fast_tracepoint_insn_len,
-  linux_qxfer_libraries_svr4,
-  linux_supports_agent,
-#ifdef HAVE_LINUX_BTRACE
-  linux_enable_btrace,
-  linux_low_disable_btrace,
-  linux_low_read_btrace,
-  linux_low_btrace_conf,
-#else
-  NULL,
-  NULL,
-  NULL,
-  NULL,
-#endif
-  linux_supports_range_stepping,
-  linux_proc_pid_to_exec_file,
-  linux_mntns_open_cloexec,
-  linux_mntns_unlink,
-  linux_mntns_readlink,
-  linux_breakpoint_kind_from_pc,
-  linux_sw_breakpoint_from_kind,
-  linux_proc_tid_get_name,
-  linux_breakpoint_kind_from_current_state,
-  linux_supports_software_single_step,
-  linux_supports_catch_syscall,
-  linux_get_ipa_tdesc_idx,
-#if USE_THREAD_DB
-  thread_db_thread_handle,
-#else
-  NULL,
-#endif
-  &the_linux_target,
-};
-
 #ifdef HAVE_LINUX_REGSETS
 void
 initialize_regsets_info (struct regsets_info *info)
@@ -7504,7 +7540,7 @@ initialize_low (void)
   struct sigaction sigchld_action;
 
   memset (&sigchld_action, 0, sizeof (sigchld_action));
-  set_target_ops (&linux_target_ops);
+  set_target_ops (&the_linux_target);
 
   linux_ptrace_init_warnings ();
   linux_proc_init_warnings ();
This page took 0.032184 seconds and 4 git commands to generate.