gdb/gdbserver/proc-service.c - gdb

Data types defined

Functions defined

Macros defined

Source code

  1. /* libthread_db helper functions for the remote server for GDB.
  2.    Copyright (C) 2002-2015 Free Software Foundation, Inc.

  3.    Contributed by MontaVista Software.

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #include "server.h"

  16. /* This file is currently tied to GNU/Linux.  It should scale well to
  17.    another libthread_db implementation, with the approriate gdbserver
  18.    hooks, but for now this means we can use GNU/Linux's target data.  */

  19. #include "linux-low.h"

  20. #include "gdb_proc_service.h"

  21. typedef struct ps_prochandle *gdb_ps_prochandle_t;
  22. typedef void *gdb_ps_read_buf_t;
  23. typedef const void *gdb_ps_write_buf_t;
  24. typedef size_t gdb_ps_size_t;

  25. #ifdef HAVE_LINUX_REGSETS
  26. #define HAVE_REGSETS
  27. #endif

  28. #ifdef HAVE_REGSETS
  29. static struct regset_info *
  30. gregset_info (void)
  31. {
  32.   int i = 0;
  33.   const struct regs_info *regs_info = (*the_low_target.regs_info) ();
  34.   struct regsets_info *regsets_info = regs_info->regsets_info;

  35.   while (regsets_info->regsets[i].size != -1)
  36.     {
  37.       if (regsets_info->regsets[i].type == GENERAL_REGS)
  38.         break;
  39.       i++;
  40.     }

  41.   return &regsets_info->regsets[i];
  42. }
  43. #endif

  44. /* Search for the symbol named NAME within the object named OBJ within
  45.    the target process PH.  If the symbol is found the address of the
  46.    symbol is stored in SYM_ADDR.  */

  47. ps_err_e
  48. ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj,
  49.                    const char *name, psaddr_t *sym_addr)
  50. {
  51.   CORE_ADDR addr;

  52.   if (thread_db_look_up_one_symbol (name, &addr) == 0)
  53.     return PS_NOSYM;

  54.   *sym_addr = (psaddr_t) (unsigned long) addr;
  55.   return PS_OK;
  56. }

  57. /* Read SIZE bytes from the target process PH at address ADDR and copy
  58.    them into BUF.  */

  59. ps_err_e
  60. ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr,
  61.            gdb_ps_read_buf_t buf, gdb_ps_size_t size)
  62. {
  63.   read_inferior_memory ((unsigned long) addr, buf, size);
  64.   return PS_OK;
  65. }

  66. /* Write SIZE bytes from BUF into the target process PH at address ADDR.  */

  67. ps_err_e
  68. ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr,
  69.             gdb_ps_write_buf_t buf, gdb_ps_size_t size)
  70. {
  71.   return write_inferior_memory ((unsigned long) addr, buf, size);
  72. }

  73. /* Get the general registers of LWP LWPID within the target process PH
  74.    and store them in GREGSET.  */

  75. ps_err_e
  76. ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
  77. {
  78. #ifdef HAVE_REGSETS
  79.   struct lwp_info *lwp;
  80.   struct thread_info *reg_thread, *saved_thread;
  81.   struct regcache *regcache;

  82.   lwp = find_lwp_pid (pid_to_ptid (lwpid));
  83.   if (lwp == NULL)
  84.     return PS_ERR;

  85.   reg_thread = get_lwp_thread (lwp);
  86.   saved_thread = current_thread;
  87.   current_thread = reg_thread;
  88.   regcache = get_thread_regcache (current_thread, 1);
  89.   gregset_info ()->fill_function (regcache, gregset);

  90.   current_thread = saved_thread;
  91.   return PS_OK;
  92. #else
  93.   return PS_ERR;
  94. #endif
  95. }

  96. /* Set the general registers of LWP LWPID within the target process PH
  97.    from GREGSET.  */

  98. ps_err_e
  99. ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
  100. {
  101.   /* Unneeded.  */
  102.   return PS_ERR;
  103. }

  104. /* Get the floating-point registers of LWP LWPID within the target
  105.    process PH and store them in FPREGSET.  */

  106. ps_err_e
  107. ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, void *fpregset)
  108. {
  109.   /* Unneeded.  */
  110.   return PS_ERR;
  111. }

  112. /* Set the floating-point registers of LWP LWPID within the target
  113.    process PH from FPREGSET.  */

  114. ps_err_e
  115. ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, void *fpregset)
  116. {
  117.   /* Unneeded.  */
  118.   return PS_ERR;
  119. }

  120. /* Return overall process id of the target PH.  Special for GNU/Linux
  121.    -- not used on Solaris.  */

  122. pid_t
  123. ps_getpid (gdb_ps_prochandle_t ph)
  124. {
  125.   return pid_of (current_thread);
  126. }