gdb_proc_service.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* <proc_service.h> replacement for systems that don't have it.
  2. Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef COMMON_GDB_PROC_SERVICE_H
  15. #define COMMON_GDB_PROC_SERVICE_H
  16. #include <sys/types.h>
  17. #ifdef HAVE_PROC_SERVICE_H
  18. /* glibc's proc_service.h doesn't wrap itself with extern "C". Need
  19. to do it ourselves. */
  20. EXTERN_C_PUSH
  21. #include <proc_service.h>
  22. EXTERN_C_POP
  23. #else /* HAVE_PROC_SERVICE_H */
  24. /* The following fallback definitions have been imported and adjusted
  25. from glibc's proc_service.h */
  26. /* Callback interface for libthread_db, functions users must define.
  27. Copyright (C) 1999,2002,2003 Free Software Foundation, Inc.
  28. This file is part of the GNU C Library.
  29. The GNU C Library is free software; you can redistribute it and/or
  30. modify it under the terms of the GNU Lesser General Public
  31. License as published by the Free Software Foundation; either
  32. version 2.1 of the License, or (at your option) any later version.
  33. The GNU C Library is distributed in the hope that it will be useful,
  34. but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  36. Lesser General Public License for more details.
  37. You should have received a copy of the GNU Lesser General Public
  38. License along with the GNU C Library; if not, see
  39. <http://www.gnu.org/licenses/>. */
  40. /* The definitions in this file must correspond to those in the debugger. */
  41. #ifdef HAVE_SYS_PROCFS_H
  42. #include <sys/procfs.h>
  43. #endif
  44. /* Not all platforms bring in <linux/elf.h> via <sys/procfs.h>. If
  45. <sys/procfs.h> wasn't enough to find elf_fpregset_t, try the kernel
  46. headers also (but don't if we don't need to). */
  47. #ifndef HAVE_ELF_FPREGSET_T
  48. # ifdef HAVE_LINUX_ELF_H
  49. # include <linux/elf.h>
  50. # endif
  51. #endif
  52. EXTERN_C_PUSH
  53. /* Functions in this interface return one of these status codes. */
  54. typedef enum
  55. {
  56. PS_OK, /* Generic "call succeeded". */
  57. PS_ERR, /* Generic error. */
  58. PS_BADPID, /* Bad process handle. */
  59. PS_BADLID, /* Bad LWP identifier. */
  60. PS_BADADDR, /* Bad address. */
  61. PS_NOSYM, /* Could not find given symbol. */
  62. PS_NOFREGS /* FPU register set not available for given LWP. */
  63. } ps_err_e;
  64. #ifndef HAVE_LWPID_T
  65. typedef unsigned int lwpid_t;
  66. #endif
  67. #ifndef HAVE_PSADDR_T
  68. typedef void *psaddr_t;
  69. #endif
  70. #ifndef HAVE_PRGREGSET_T
  71. typedef elf_gregset_t prgregset_t;
  72. #endif
  73. #ifndef HAVE_PRFPREGSET_T
  74. typedef elf_fpregset_t prfpregset_t;
  75. #endif
  76. /* This type is opaque in this interface. It's defined by the user of
  77. libthread_db. GDB's version is defined below. */
  78. struct ps_prochandle;
  79. /* Read or write process memory at the given address. */
  80. extern ps_err_e ps_pdread (struct ps_prochandle *,
  81. psaddr_t, void *, size_t);
  82. extern ps_err_e ps_pdwrite (struct ps_prochandle *,
  83. psaddr_t, const void *, size_t);
  84. extern ps_err_e ps_ptread (struct ps_prochandle *,
  85. psaddr_t, void *, size_t);
  86. extern ps_err_e ps_ptwrite (struct ps_prochandle *,
  87. psaddr_t, const void *, size_t);
  88. /* Get and set the given LWP's general or FPU register set. */
  89. extern ps_err_e ps_lgetregs (struct ps_prochandle *,
  90. lwpid_t, prgregset_t);
  91. extern ps_err_e ps_lsetregs (struct ps_prochandle *,
  92. lwpid_t, const prgregset_t);
  93. extern ps_err_e ps_lgetfpregs (struct ps_prochandle *,
  94. lwpid_t, prfpregset_t *);
  95. extern ps_err_e ps_lsetfpregs (struct ps_prochandle *,
  96. lwpid_t, const prfpregset_t *);
  97. /* Return the PID of the process. */
  98. extern pid_t ps_getpid (struct ps_prochandle *);
  99. /* Fetch the special per-thread address associated with the given LWP.
  100. This call is only used on a few platforms (most use a normal register).
  101. The meaning of the `int' parameter is machine-dependent. */
  102. extern ps_err_e ps_get_thread_area (struct ps_prochandle *,
  103. lwpid_t, int, psaddr_t *);
  104. /* Look up the named symbol in the named DSO in the symbol tables
  105. associated with the process being debugged, filling in *SYM_ADDR
  106. with the corresponding run-time address. */
  107. extern ps_err_e ps_pglobal_lookup (struct ps_prochandle *,
  108. const char *object_name,
  109. const char *sym_name,
  110. psaddr_t *sym_addr);
  111. /* Stop or continue the entire process. */
  112. extern ps_err_e ps_pstop (struct ps_prochandle *);
  113. extern ps_err_e ps_pcontinue (struct ps_prochandle *);
  114. /* Stop or continue the given LWP alone. */
  115. extern ps_err_e ps_lstop (struct ps_prochandle *, lwpid_t);
  116. extern ps_err_e ps_lcontinue (struct ps_prochandle *, lwpid_t);
  117. /* The following are only defined in/called by Solaris. */
  118. /* Get size of extra register set. */
  119. extern ps_err_e ps_lgetxregsize (struct ps_prochandle *ph,
  120. lwpid_t lwpid, int *xregsize);
  121. /* Get extra register set. */
  122. extern ps_err_e ps_lgetxregs (struct ps_prochandle *ph, lwpid_t lwpid,
  123. caddr_t xregset);
  124. extern ps_err_e ps_lsetxregs (struct ps_prochandle *ph, lwpid_t lwpid,
  125. caddr_t xregset);
  126. /* Log a message (sends to gdb_stderr). */
  127. extern void ps_plog (const char *fmt, ...);
  128. EXTERN_C_POP
  129. #endif /* HAVE_PROC_SERVICE_H */
  130. /* Make sure we export the needed symbols, in case GDB is built with
  131. -fvisibility=hidden. */
  132. #define PS_EXPORT(SYM) \
  133. __attribute__((visibility ("default"))) decltype (SYM) SYM
  134. PS_EXPORT (ps_get_thread_area);
  135. PS_EXPORT (ps_getpid);
  136. PS_EXPORT (ps_lcontinue);
  137. PS_EXPORT (ps_lgetfpregs);
  138. PS_EXPORT (ps_lgetregs);
  139. PS_EXPORT (ps_lsetfpregs);
  140. PS_EXPORT (ps_lsetregs);
  141. PS_EXPORT (ps_lstop);
  142. PS_EXPORT (ps_pcontinue);
  143. PS_EXPORT (ps_pdread);
  144. PS_EXPORT (ps_pdwrite);
  145. PS_EXPORT (ps_pglobal_lookup);
  146. PS_EXPORT (ps_pstop);
  147. PS_EXPORT (ps_ptread);
  148. PS_EXPORT (ps_ptwrite);
  149. #ifdef __sun__
  150. PS_EXPORT (ps_lgetxregs);
  151. PS_EXPORT (ps_lgetxregsize);
  152. PS_EXPORT (ps_lsetxregs);
  153. PS_EXPORT (ps_plog);
  154. #endif
  155. #endif /* COMMON_GDB_PROC_SERVICE_H */