proc-service.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* libthread_db helper functions for the remote server for GDB.
  2. Copyright (C) 2002-2022 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 appropriate 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 regs_info *regs_info = the_linux_target->get_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. if (read_inferior_memory ((uintptr_t) addr, (gdb_byte *) buf, size) != 0)
  64. return PS_ERR;
  65. return PS_OK;
  66. }
  67. /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
  68. ps_err_e
  69. ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr,
  70. gdb_ps_write_buf_t buf, gdb_ps_size_t size)
  71. {
  72. if (target_write_memory ((uintptr_t) addr, (const gdb_byte *) buf, size)
  73. != 0)
  74. return PS_ERR;
  75. return PS_OK;
  76. }
  77. /* Get the general registers of LWP LWPID within the target process PH
  78. and store them in GREGSET. */
  79. ps_err_e
  80. ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
  81. {
  82. #ifdef HAVE_REGSETS
  83. struct lwp_info *lwp;
  84. struct regcache *regcache;
  85. lwp = find_lwp_pid (ptid_t (lwpid));
  86. if (lwp == NULL)
  87. return PS_ERR;
  88. scoped_restore_current_thread restore_thread;
  89. switch_to_thread (get_lwp_thread (lwp));
  90. regcache = get_thread_regcache (current_thread, 1);
  91. gregset_info ()->fill_function (regcache, gregset);
  92. return PS_OK;
  93. #else
  94. return PS_ERR;
  95. #endif
  96. }
  97. /* Set the general registers of LWP LWPID within the target process PH
  98. from GREGSET. */
  99. ps_err_e
  100. ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
  101. {
  102. /* Unneeded. */
  103. return PS_ERR;
  104. }
  105. /* Get the floating-point registers of LWP LWPID within the target
  106. process PH and store them in FPREGSET. */
  107. ps_err_e
  108. ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prfpregset_t *fpregset)
  109. {
  110. /* Unneeded. */
  111. return PS_ERR;
  112. }
  113. /* Set the floating-point registers of LWP LWPID within the target
  114. process PH from FPREGSET. */
  115. ps_err_e
  116. ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregset)
  117. {
  118. /* Unneeded. */
  119. return PS_ERR;
  120. }
  121. /* Return overall process id of the target PH. Special for GNU/Linux
  122. -- not used on Solaris. */
  123. pid_t
  124. ps_getpid (gdb_ps_prochandle_t ph)
  125. {
  126. return pid_of (current_thread);
  127. }