1 /* Common definitions for remote server for GDB. 2 Copyright (C) 1993-2024 Free Software Foundation, Inc. 3 4 This file is part of GDB. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 19 #ifndef GDBSERVER_SERVER_H 20 #define GDBSERVER_SERVER_H 21 22 #include "gdbsupport/common-defs.h" 23 24 #undef PACKAGE 25 #undef PACKAGE_NAME 26 #undef PACKAGE_VERSION 27 #undef PACKAGE_STRING 28 #undef PACKAGE_TARNAME 29 30 #include <config.h> 31 32 static_assert (sizeof (CORE_ADDR) >= sizeof (void *)); 33 34 #include "gdbsupport/version.h" 35 36 #if !HAVE_DECL_PERROR 37 #ifndef perror 38 extern void perror (const char *); 39 #endif 40 #endif 41 42 #if !HAVE_DECL_VASPRINTF 43 extern int vasprintf(char **strp, const char *fmt, va_list ap); 44 #endif 45 #if !HAVE_DECL_VSNPRINTF 46 int vsnprintf(char *str, size_t size, const char *format, va_list ap); 47 #endif 48 49 #ifdef IN_PROCESS_AGENT 50 # define PROG "ipa" 51 #else 52 # define PROG "gdbserver" 53 #endif 54 55 #include "gdbsupport/xml-utils.h" 56 #include "regcache.h" 57 #include "gdbsupport/gdb_signals.h" 58 #include "target.h" 59 #include "mem-break.h" 60 #include "gdbsupport/environ.h" 61 62 /* Target-specific functions */ 63 64 void initialize_low (); 65 66 /* Public variables in server.c */ 67 68 extern bool server_waiting; 69 70 extern bool disable_packet_vCont; 71 extern bool disable_packet_Tthread; 72 extern bool disable_packet_qC; 73 extern bool disable_packet_qfThreadInfo; 74 extern bool disable_packet_T; 75 76 extern bool run_once; 77 extern bool non_stop; 78 79 #include "gdbsupport/event-loop.h" 80 81 /* Functions from server.c. */ 82 extern void handle_v_requests (char *own_buf, int packet_len, 83 int *new_packet_len); 84 extern void handle_serial_event (int err, gdb_client_data client_data); 85 extern void handle_target_event (int err, gdb_client_data client_data); 86 87 /* Get rid of the currently pending stop replies that match PTID. */ 88 extern void discard_queued_stop_replies (ptid_t ptid); 89 90 /* Returns true if there's a pending stop reply that matches PTID in 91 the vStopped notifications queue. */ 92 extern int in_queued_stop_replies (ptid_t ptid); 93 94 #include "remote-utils.h" 95 96 #include "utils.h" 97 #include "debug.h" 98 #include "gdbsupport/gdb_vecs.h" 99 100 /* Maximum number of bytes to read/write at once. The value here 101 is chosen to fill up a packet (the headers account for the 32). */ 102 #define MAXBUFBYTES(N) (((N)-32)/2) 103 104 /* Buffer sizes for transferring memory, registers, etc. Set to a constant 105 value to accommodate multiple register formats. This value must be at least 106 as large as the largest register set supported by gdbserver. */ 107 #define PBUFSIZ 131104 108 109 /* Definition for an unknown syscall, used basically in error-cases. */ 110 #define UNKNOWN_SYSCALL (-1) 111 112 /* Definition for any syscall, used for unfiltered syscall reporting. */ 113 #define ANY_SYSCALL (-2) 114 115 /* After fork_inferior has been called, we need to adjust a few 116 signals and call startup_inferior to start the inferior and consume 117 its first events. This is done here. PID is the pid of the new 118 inferior and PROGRAM is its name. */ 119 extern void post_fork_inferior (int pid, const char *program); 120 121 /* Get the gdb_environ being used in the current session. */ 122 extern gdb_environ *get_environ (); 123 124 extern unsigned long signal_pid; 125 126 127 /* Description of the client remote protocol state for the currently 128 connected client. */ 129 130 struct client_state 131 { 132 client_state (): 133 own_buf ((char *) xmalloc (PBUFSIZ + 1)) 134 {} 135 136 /* The thread set with an `Hc' packet. `Hc' is deprecated in favor of 137 `vCont'. Note the multi-process extensions made `vCont' a 138 requirement, so `Hc pPID.TID' is pretty much undefined. So 139 CONT_THREAD can be null_ptid for no `Hc' thread, minus_one_ptid for 140 resuming all threads of the process (again, `Hc' isn't used for 141 multi-process), or a specific thread ptid_t. */ 142 ptid_t cont_thread; 143 144 /* The thread set with an `Hg' packet. */ 145 ptid_t general_thread; 146 147 int multi_process = 0; 148 int report_fork_events = 0; 149 int report_vfork_events = 0; 150 int report_exec_events = 0; 151 int report_thread_events = 0; 152 153 /* True if the "swbreak+" feature is active. In that case, GDB wants 154 us to report whether a trap is explained by a software breakpoint 155 and for the server to handle PC adjustment if necessary on this 156 target. Only enabled if the target supports it. */ 157 int swbreak_feature = 0; 158 /* True if the "hwbreak+" feature is active. In that case, GDB wants 159 us to report whether a trap is explained by a hardware breakpoint. 160 Only enabled if the target supports it. */ 161 int hwbreak_feature = 0; 162 163 /* True if the "vContSupported" feature is active. In that case, GDB 164 wants us to report whether single step is supported in the reply to 165 "vCont?" packet. */ 166 int vCont_supported = 0; 167 168 /* Whether we should attempt to disable the operating system's address 169 space randomization feature before starting an inferior. */ 170 int disable_randomization = 1; 171 172 int pass_signals[GDB_SIGNAL_LAST]; 173 int program_signals[GDB_SIGNAL_LAST]; 174 int program_signals_p = 0; 175 176 /* Last status reported to GDB. */ 177 struct target_waitstatus last_status; 178 ptid_t last_ptid; 179 180 char *own_buf; 181 182 /* If true, then GDB has requested noack mode. */ 183 int noack_mode = 0; 184 /* If true, then we tell GDB to use noack mode by default. */ 185 int transport_is_reliable = 0; 186 187 /* The traceframe to be used as the source of data to send back to 188 GDB. A value of -1 means to get data from the live program. */ 189 190 int current_traceframe = -1; 191 192 /* If true, memory tagging features are supported. */ 193 bool memory_tagging_feature = false; 194 195 }; 196 197 client_state &get_client_state (); 198 199 #include "gdbthread.h" 200 #include "inferiors.h" 201 202 #endif /* GDBSERVER_SERVER_H */ 203