18dffb485Schristos /* <proc_service.h> replacement for systems that don't have it. 2*5ba1f45fSchristos Copyright (C) 2000-2024 Free Software Foundation, Inc. 38dffb485Schristos 48dffb485Schristos This file is part of GDB. 58dffb485Schristos 68dffb485Schristos This program is free software; you can redistribute it and/or modify 78dffb485Schristos it under the terms of the GNU General Public License as published by 88dffb485Schristos the Free Software Foundation; either version 3 of the License, or 98dffb485Schristos (at your option) any later version. 108dffb485Schristos 118dffb485Schristos This program is distributed in the hope that it will be useful, 128dffb485Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 138dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 148dffb485Schristos GNU General Public License for more details. 158dffb485Schristos 168dffb485Schristos You should have received a copy of the GNU General Public License 178dffb485Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 188dffb485Schristos 198dffb485Schristos #ifndef COMMON_GDB_PROC_SERVICE_H 208dffb485Schristos #define COMMON_GDB_PROC_SERVICE_H 218dffb485Schristos 228dffb485Schristos #include <sys/types.h> 238dffb485Schristos 248dffb485Schristos #ifdef HAVE_PROC_SERVICE_H 258dffb485Schristos 268dffb485Schristos /* glibc's proc_service.h doesn't wrap itself with extern "C". Need 278dffb485Schristos to do it ourselves. */ 28*5ba1f45fSchristos extern "C" { 298dffb485Schristos 308dffb485Schristos #include <proc_service.h> 318dffb485Schristos 32*5ba1f45fSchristos } 338dffb485Schristos 348dffb485Schristos #else /* HAVE_PROC_SERVICE_H */ 358dffb485Schristos 368dffb485Schristos /* The following fallback definitions have been imported and adjusted 378dffb485Schristos from glibc's proc_service.h */ 388dffb485Schristos 398dffb485Schristos /* Callback interface for libthread_db, functions users must define. 408dffb485Schristos Copyright (C) 1999,2002,2003 Free Software Foundation, Inc. 418dffb485Schristos This file is part of the GNU C Library. 428dffb485Schristos 438dffb485Schristos The GNU C Library is free software; you can redistribute it and/or 448dffb485Schristos modify it under the terms of the GNU Lesser General Public 458dffb485Schristos License as published by the Free Software Foundation; either 468dffb485Schristos version 2.1 of the License, or (at your option) any later version. 478dffb485Schristos 488dffb485Schristos The GNU C Library is distributed in the hope that it will be useful, 498dffb485Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 508dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 518dffb485Schristos Lesser General Public License for more details. 528dffb485Schristos 538dffb485Schristos You should have received a copy of the GNU Lesser General Public 548dffb485Schristos License along with the GNU C Library; if not, see 558dffb485Schristos <http://www.gnu.org/licenses/>. */ 568dffb485Schristos 578dffb485Schristos /* The definitions in this file must correspond to those in the debugger. */ 588dffb485Schristos 598dffb485Schristos #ifdef HAVE_SYS_PROCFS_H 608dffb485Schristos #include <sys/procfs.h> 618dffb485Schristos #endif 628dffb485Schristos 638dffb485Schristos /* Not all platforms bring in <linux/elf.h> via <sys/procfs.h>. If 648dffb485Schristos <sys/procfs.h> wasn't enough to find elf_fpregset_t, try the kernel 658dffb485Schristos headers also (but don't if we don't need to). */ 668dffb485Schristos #ifndef HAVE_ELF_FPREGSET_T 678dffb485Schristos # ifdef HAVE_LINUX_ELF_H 688dffb485Schristos # include <linux/elf.h> 698dffb485Schristos # endif 708dffb485Schristos #endif 718dffb485Schristos 72*5ba1f45fSchristos extern "C" { 738dffb485Schristos 748dffb485Schristos /* Functions in this interface return one of these status codes. */ 758dffb485Schristos typedef enum 768dffb485Schristos { 778dffb485Schristos PS_OK, /* Generic "call succeeded". */ 788dffb485Schristos PS_ERR, /* Generic error. */ 798dffb485Schristos PS_BADPID, /* Bad process handle. */ 808dffb485Schristos PS_BADLID, /* Bad LWP identifier. */ 818dffb485Schristos PS_BADADDR, /* Bad address. */ 828dffb485Schristos PS_NOSYM, /* Could not find given symbol. */ 838dffb485Schristos PS_NOFREGS /* FPU register set not available for given LWP. */ 848dffb485Schristos } ps_err_e; 858dffb485Schristos 868dffb485Schristos #ifndef HAVE_LWPID_T 878dffb485Schristos typedef unsigned int lwpid_t; 888dffb485Schristos #endif 898dffb485Schristos 908dffb485Schristos #ifndef HAVE_PSADDR_T 918dffb485Schristos typedef void *psaddr_t; 928dffb485Schristos #endif 938dffb485Schristos 948dffb485Schristos #ifndef HAVE_PRGREGSET_T 958dffb485Schristos typedef elf_gregset_t prgregset_t; 968dffb485Schristos #endif 978dffb485Schristos 988dffb485Schristos #ifndef HAVE_PRFPREGSET_T 998dffb485Schristos typedef elf_fpregset_t prfpregset_t; 1008dffb485Schristos #endif 1018dffb485Schristos 1028dffb485Schristos /* This type is opaque in this interface. It's defined by the user of 1038dffb485Schristos libthread_db. GDB's version is defined below. */ 1048dffb485Schristos struct ps_prochandle; 1058dffb485Schristos 1068dffb485Schristos 1078dffb485Schristos /* Read or write process memory at the given address. */ 1088dffb485Schristos extern ps_err_e ps_pdread (struct ps_prochandle *, 1098dffb485Schristos psaddr_t, void *, size_t); 1108dffb485Schristos extern ps_err_e ps_pdwrite (struct ps_prochandle *, 1118dffb485Schristos psaddr_t, const void *, size_t); 1128dffb485Schristos extern ps_err_e ps_ptread (struct ps_prochandle *, 1138dffb485Schristos psaddr_t, void *, size_t); 1148dffb485Schristos extern ps_err_e ps_ptwrite (struct ps_prochandle *, 1158dffb485Schristos psaddr_t, const void *, size_t); 1168dffb485Schristos 1178dffb485Schristos 1188dffb485Schristos /* Get and set the given LWP's general or FPU register set. */ 1198dffb485Schristos extern ps_err_e ps_lgetregs (struct ps_prochandle *, 1208dffb485Schristos lwpid_t, prgregset_t); 1218dffb485Schristos extern ps_err_e ps_lsetregs (struct ps_prochandle *, 1228dffb485Schristos lwpid_t, const prgregset_t); 1238dffb485Schristos extern ps_err_e ps_lgetfpregs (struct ps_prochandle *, 1248dffb485Schristos lwpid_t, prfpregset_t *); 1258dffb485Schristos extern ps_err_e ps_lsetfpregs (struct ps_prochandle *, 1268dffb485Schristos lwpid_t, const prfpregset_t *); 1278dffb485Schristos 1288dffb485Schristos /* Return the PID of the process. */ 1298dffb485Schristos extern pid_t ps_getpid (struct ps_prochandle *); 1308dffb485Schristos 1318dffb485Schristos /* Fetch the special per-thread address associated with the given LWP. 1328dffb485Schristos This call is only used on a few platforms (most use a normal register). 1338dffb485Schristos The meaning of the `int' parameter is machine-dependent. */ 1348dffb485Schristos extern ps_err_e ps_get_thread_area (struct ps_prochandle *, 1358dffb485Schristos lwpid_t, int, psaddr_t *); 1368dffb485Schristos 1378dffb485Schristos 1388dffb485Schristos /* Look up the named symbol in the named DSO in the symbol tables 1398dffb485Schristos associated with the process being debugged, filling in *SYM_ADDR 1408dffb485Schristos with the corresponding run-time address. */ 1418dffb485Schristos extern ps_err_e ps_pglobal_lookup (struct ps_prochandle *, 1428dffb485Schristos const char *object_name, 1438dffb485Schristos const char *sym_name, 1448dffb485Schristos psaddr_t *sym_addr); 1458dffb485Schristos 1468dffb485Schristos 1478dffb485Schristos /* Stop or continue the entire process. */ 1488dffb485Schristos extern ps_err_e ps_pstop (struct ps_prochandle *); 1498dffb485Schristos extern ps_err_e ps_pcontinue (struct ps_prochandle *); 1508dffb485Schristos 1518dffb485Schristos /* Stop or continue the given LWP alone. */ 1528dffb485Schristos extern ps_err_e ps_lstop (struct ps_prochandle *, lwpid_t); 1538dffb485Schristos extern ps_err_e ps_lcontinue (struct ps_prochandle *, lwpid_t); 1548dffb485Schristos 1558dffb485Schristos /* The following are only defined in/called by Solaris. */ 1568dffb485Schristos 1578dffb485Schristos /* Get size of extra register set. */ 1588dffb485Schristos extern ps_err_e ps_lgetxregsize (struct ps_prochandle *ph, 1598dffb485Schristos lwpid_t lwpid, int *xregsize); 1608dffb485Schristos /* Get extra register set. */ 1618dffb485Schristos extern ps_err_e ps_lgetxregs (struct ps_prochandle *ph, lwpid_t lwpid, 1628dffb485Schristos caddr_t xregset); 1638dffb485Schristos extern ps_err_e ps_lsetxregs (struct ps_prochandle *ph, lwpid_t lwpid, 1648dffb485Schristos caddr_t xregset); 1658dffb485Schristos 1668dffb485Schristos /* Log a message (sends to gdb_stderr). */ 1678dffb485Schristos extern void ps_plog (const char *fmt, ...); 1688dffb485Schristos 169*5ba1f45fSchristos } 1708dffb485Schristos 1718dffb485Schristos #endif /* HAVE_PROC_SERVICE_H */ 1728dffb485Schristos 1738dffb485Schristos /* Make sure we export the needed symbols, in case GDB is built with 1748dffb485Schristos -fvisibility=hidden. */ 1758dffb485Schristos 1768dffb485Schristos #define PS_EXPORT(SYM) \ 1774b169a6bSchristos __attribute__((visibility ("default"))) decltype (SYM) SYM 1788dffb485Schristos 1798dffb485Schristos PS_EXPORT (ps_get_thread_area); 1808dffb485Schristos PS_EXPORT (ps_getpid); 1818dffb485Schristos PS_EXPORT (ps_lcontinue); 1828dffb485Schristos PS_EXPORT (ps_lgetfpregs); 1838dffb485Schristos PS_EXPORT (ps_lgetregs); 1848dffb485Schristos PS_EXPORT (ps_lsetfpregs); 1858dffb485Schristos PS_EXPORT (ps_lsetregs); 1868dffb485Schristos PS_EXPORT (ps_lstop); 1878dffb485Schristos PS_EXPORT (ps_pcontinue); 1888dffb485Schristos PS_EXPORT (ps_pdread); 1898dffb485Schristos PS_EXPORT (ps_pdwrite); 1908dffb485Schristos PS_EXPORT (ps_pglobal_lookup); 1918dffb485Schristos PS_EXPORT (ps_pstop); 1928dffb485Schristos PS_EXPORT (ps_ptread); 1938dffb485Schristos PS_EXPORT (ps_ptwrite); 1948dffb485Schristos 1958dffb485Schristos #ifdef __sun__ 1968dffb485Schristos PS_EXPORT (ps_lgetxregs); 1978dffb485Schristos PS_EXPORT (ps_lgetxregsize); 1988dffb485Schristos PS_EXPORT (ps_lsetxregs); 1998dffb485Schristos PS_EXPORT (ps_plog); 2008dffb485Schristos #endif 2018dffb485Schristos 2028dffb485Schristos #endif /* COMMON_GDB_PROC_SERVICE_H */ 203