18dffb485Schristos /* Common definitions for remote server for GDB. 2*2be465b0Schristos Copyright (C) 1993-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 GDBSERVER_SERVER_H 208dffb485Schristos #define GDBSERVER_SERVER_H 218dffb485Schristos 228dffb485Schristos #include "gdbsupport/common-defs.h" 238dffb485Schristos 248dffb485Schristos #undef PACKAGE 258dffb485Schristos #undef PACKAGE_NAME 268dffb485Schristos #undef PACKAGE_VERSION 278dffb485Schristos #undef PACKAGE_STRING 288dffb485Schristos #undef PACKAGE_TARNAME 298dffb485Schristos 308dffb485Schristos #include <config.h> 318dffb485Schristos 32*2be465b0Schristos static_assert (sizeof (CORE_ADDR) >= sizeof (void *)); 338dffb485Schristos 348dffb485Schristos #include "gdbsupport/version.h" 358dffb485Schristos 368dffb485Schristos #if !HAVE_DECL_PERROR 378dffb485Schristos #ifndef perror 388dffb485Schristos extern void perror (const char *); 398dffb485Schristos #endif 408dffb485Schristos #endif 418dffb485Schristos 428dffb485Schristos #if !HAVE_DECL_VASPRINTF 438dffb485Schristos extern int vasprintf(char **strp, const char *fmt, va_list ap); 448dffb485Schristos #endif 458dffb485Schristos #if !HAVE_DECL_VSNPRINTF 468dffb485Schristos int vsnprintf(char *str, size_t size, const char *format, va_list ap); 478dffb485Schristos #endif 488dffb485Schristos 498dffb485Schristos #ifdef IN_PROCESS_AGENT 508dffb485Schristos # define PROG "ipa" 518dffb485Schristos #else 528dffb485Schristos # define PROG "gdbserver" 538dffb485Schristos #endif 548dffb485Schristos 558dffb485Schristos #include "gdbsupport/xml-utils.h" 568dffb485Schristos #include "regcache.h" 578dffb485Schristos #include "gdbsupport/gdb_signals.h" 588dffb485Schristos #include "target.h" 598dffb485Schristos #include "mem-break.h" 608dffb485Schristos #include "gdbsupport/environ.h" 618dffb485Schristos 628dffb485Schristos /* Target-specific functions */ 638dffb485Schristos 648dffb485Schristos void initialize_low (); 658dffb485Schristos 668dffb485Schristos /* Public variables in server.c */ 678dffb485Schristos 688dffb485Schristos extern bool server_waiting; 698dffb485Schristos 708dffb485Schristos extern bool disable_packet_vCont; 718dffb485Schristos extern bool disable_packet_Tthread; 728dffb485Schristos extern bool disable_packet_qC; 738dffb485Schristos extern bool disable_packet_qfThreadInfo; 748dffb485Schristos extern bool disable_packet_T; 758dffb485Schristos 768dffb485Schristos extern bool run_once; 778dffb485Schristos extern bool non_stop; 788dffb485Schristos 798dffb485Schristos #include "gdbsupport/event-loop.h" 808dffb485Schristos 818dffb485Schristos /* Functions from server.c. */ 828dffb485Schristos extern void handle_v_requests (char *own_buf, int packet_len, 838dffb485Schristos int *new_packet_len); 848dffb485Schristos extern void handle_serial_event (int err, gdb_client_data client_data); 858dffb485Schristos extern void handle_target_event (int err, gdb_client_data client_data); 868dffb485Schristos 878dffb485Schristos /* Get rid of the currently pending stop replies that match PTID. */ 888dffb485Schristos extern void discard_queued_stop_replies (ptid_t ptid); 898dffb485Schristos 908dffb485Schristos /* Returns true if there's a pending stop reply that matches PTID in 918dffb485Schristos the vStopped notifications queue. */ 928dffb485Schristos extern int in_queued_stop_replies (ptid_t ptid); 938dffb485Schristos 948dffb485Schristos #include "remote-utils.h" 958dffb485Schristos 968dffb485Schristos #include "utils.h" 978dffb485Schristos #include "debug.h" 988dffb485Schristos #include "gdbsupport/gdb_vecs.h" 998dffb485Schristos 1008dffb485Schristos /* Maximum number of bytes to read/write at once. The value here 1018dffb485Schristos is chosen to fill up a packet (the headers account for the 32). */ 1028dffb485Schristos #define MAXBUFBYTES(N) (((N)-32)/2) 1038dffb485Schristos 1048dffb485Schristos /* Buffer sizes for transferring memory, registers, etc. Set to a constant 105*2be465b0Schristos value to accommodate multiple register formats. This value must be at least 1068dffb485Schristos as large as the largest register set supported by gdbserver. */ 107*2be465b0Schristos #define PBUFSIZ 131104 1088dffb485Schristos 1098dffb485Schristos /* Definition for an unknown syscall, used basically in error-cases. */ 1108dffb485Schristos #define UNKNOWN_SYSCALL (-1) 1118dffb485Schristos 1128dffb485Schristos /* Definition for any syscall, used for unfiltered syscall reporting. */ 1138dffb485Schristos #define ANY_SYSCALL (-2) 1148dffb485Schristos 1158dffb485Schristos /* After fork_inferior has been called, we need to adjust a few 1168dffb485Schristos signals and call startup_inferior to start the inferior and consume 1178dffb485Schristos its first events. This is done here. PID is the pid of the new 1188dffb485Schristos inferior and PROGRAM is its name. */ 1198dffb485Schristos extern void post_fork_inferior (int pid, const char *program); 1208dffb485Schristos 1218dffb485Schristos /* Get the gdb_environ being used in the current session. */ 1228dffb485Schristos extern gdb_environ *get_environ (); 1238dffb485Schristos 1248dffb485Schristos extern unsigned long signal_pid; 1258dffb485Schristos 1268dffb485Schristos 1278dffb485Schristos /* Description of the client remote protocol state for the currently 1288dffb485Schristos connected client. */ 1298dffb485Schristos 1308dffb485Schristos struct client_state 1318dffb485Schristos { 1328dffb485Schristos client_state (): 1338dffb485Schristos own_buf ((char *) xmalloc (PBUFSIZ + 1)) 1348dffb485Schristos {} 1358dffb485Schristos 1368dffb485Schristos /* The thread set with an `Hc' packet. `Hc' is deprecated in favor of 1378dffb485Schristos `vCont'. Note the multi-process extensions made `vCont' a 1388dffb485Schristos requirement, so `Hc pPID.TID' is pretty much undefined. So 1398dffb485Schristos CONT_THREAD can be null_ptid for no `Hc' thread, minus_one_ptid for 1408dffb485Schristos resuming all threads of the process (again, `Hc' isn't used for 1418dffb485Schristos multi-process), or a specific thread ptid_t. */ 1428dffb485Schristos ptid_t cont_thread; 1438dffb485Schristos 1448dffb485Schristos /* The thread set with an `Hg' packet. */ 1458dffb485Schristos ptid_t general_thread; 1468dffb485Schristos 1478dffb485Schristos int multi_process = 0; 1488dffb485Schristos int report_fork_events = 0; 1498dffb485Schristos int report_vfork_events = 0; 1508dffb485Schristos int report_exec_events = 0; 1518dffb485Schristos int report_thread_events = 0; 1528dffb485Schristos 1538dffb485Schristos /* True if the "swbreak+" feature is active. In that case, GDB wants 1548dffb485Schristos us to report whether a trap is explained by a software breakpoint 1558dffb485Schristos and for the server to handle PC adjustment if necessary on this 1568dffb485Schristos target. Only enabled if the target supports it. */ 1578dffb485Schristos int swbreak_feature = 0; 1588dffb485Schristos /* True if the "hwbreak+" feature is active. In that case, GDB wants 1598dffb485Schristos us to report whether a trap is explained by a hardware breakpoint. 1608dffb485Schristos Only enabled if the target supports it. */ 1618dffb485Schristos int hwbreak_feature = 0; 1628dffb485Schristos 1638dffb485Schristos /* True if the "vContSupported" feature is active. In that case, GDB 1648dffb485Schristos wants us to report whether single step is supported in the reply to 1658dffb485Schristos "vCont?" packet. */ 1668dffb485Schristos int vCont_supported = 0; 1678dffb485Schristos 1688dffb485Schristos /* Whether we should attempt to disable the operating system's address 1698dffb485Schristos space randomization feature before starting an inferior. */ 1708dffb485Schristos int disable_randomization = 1; 1718dffb485Schristos 1728dffb485Schristos int pass_signals[GDB_SIGNAL_LAST]; 1738dffb485Schristos int program_signals[GDB_SIGNAL_LAST]; 1748dffb485Schristos int program_signals_p = 0; 1758dffb485Schristos 1768dffb485Schristos /* Last status reported to GDB. */ 1778dffb485Schristos struct target_waitstatus last_status; 1788dffb485Schristos ptid_t last_ptid; 1798dffb485Schristos 1808dffb485Schristos char *own_buf; 1818dffb485Schristos 1828dffb485Schristos /* If true, then GDB has requested noack mode. */ 1838dffb485Schristos int noack_mode = 0; 1848dffb485Schristos /* If true, then we tell GDB to use noack mode by default. */ 1858dffb485Schristos int transport_is_reliable = 0; 1868dffb485Schristos 1878dffb485Schristos /* The traceframe to be used as the source of data to send back to 1888dffb485Schristos GDB. A value of -1 means to get data from the live program. */ 1898dffb485Schristos 1908dffb485Schristos int current_traceframe = -1; 1918dffb485Schristos 1924b169a6bSchristos /* If true, memory tagging features are supported. */ 1934b169a6bSchristos bool memory_tagging_feature = false; 1944b169a6bSchristos 1958dffb485Schristos }; 1968dffb485Schristos 1978dffb485Schristos client_state &get_client_state (); 1988dffb485Schristos 1998dffb485Schristos #include "gdbthread.h" 2008dffb485Schristos #include "inferiors.h" 2018dffb485Schristos 2028dffb485Schristos #endif /* GDBSERVER_SERVER_H */ 203