1 /* Common definitions for remote server for GDB.
2 Copyright (C) 1993-2013 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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/>. */
23 #include "build-gnulib-gdbserver/config.h"
26 #include "wincecompat.h"
29 #include "libiberty.h"
41 /* For gnulib's PATH_MAX. */
51 /* On some systems such as MinGW, alloca is declared in malloc.h
52 (there is no alloca.h). */
57 #if !HAVE_DECL_STRERROR
59 extern char *strerror (int); /* X3.159-1989 4.11.6.2 */
65 extern void perror (const char *);
69 #if !HAVE_DECL_VASPRINTF
70 extern int vasprintf(char **strp
, const char *fmt
, va_list ap
);
72 #if !HAVE_DECL_VSNPRINTF
73 int vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
);
76 #ifdef IN_PROCESS_AGENT
79 # define PROG "gdbserver"
82 /* A type used for binary buffers. */
83 typedef unsigned char gdb_byte
;
87 #include "xml-utils.h"
88 #include "gdb_locale.h"
90 /* FIXME: This should probably be autoconf'd for. It's an integer type at
91 least the size of a (void *). */
92 typedef long long CORE_ADDR
;
94 typedef long long LONGEST
;
95 typedef unsigned long long ULONGEST
;
97 /* Generic information for tracking a list of ``inferiors'' - threads,
101 struct inferior_list_entry
*head
;
102 struct inferior_list_entry
*tail
;
104 struct inferior_list_entry
107 struct inferior_list_entry
*next
;
115 #include "regcache.h"
116 #include "gdb/signals.h"
117 #include "gdb_signals.h"
119 #include "mem-break.h"
120 #include "gdbthread.h"
124 struct inferior_list_entry entry
;
131 struct raw_breakpoint
;
132 struct fast_tracepoint_jump
;
133 struct process_info_private
;
137 struct inferior_list_entry head
;
139 /* Nonzero if this child process was attached rather than
143 /* True if GDB asked us to detach from this process, but we remained
147 /* The symbol cache. */
148 struct sym_cache
*symbol_cache
;
150 /* The list of memory breakpoints. */
151 struct breakpoint
*breakpoints
;
153 /* The list of raw memory breakpoints. */
154 struct raw_breakpoint
*raw_breakpoints
;
156 /* The list of installed fast tracepoints. */
157 struct fast_tracepoint_jump
*fast_tracepoint_jumps
;
159 const struct target_desc
*tdesc
;
161 /* Private target data. */
162 struct process_info_private
*private;
165 /* Return a pointer to the process that corresponds to the current
166 thread (current_inferior). It is an error to call this if there is
167 no current thread selected. */
169 struct process_info
*current_process (void);
170 struct process_info
*get_thread_process (struct thread_info
*);
172 /* Target-specific functions */
174 void initialize_low ();
176 /* From inferiors.c. */
178 extern struct inferior_list all_processes
;
179 extern struct inferior_list all_dlls
;
180 extern int dlls_changed
;
181 extern void clear_dlls (void);
183 void add_inferior_to_list (struct inferior_list
*list
,
184 struct inferior_list_entry
*new_inferior
);
185 void for_each_inferior (struct inferior_list
*list
,
186 void (*action
) (struct inferior_list_entry
*));
188 extern struct thread_info
*current_inferior
;
189 void remove_inferior (struct inferior_list
*list
,
190 struct inferior_list_entry
*entry
);
192 struct process_info
*add_process (int pid
, int attached
);
193 void remove_process (struct process_info
*process
);
194 struct process_info
*find_process_pid (int pid
);
195 int have_started_inferiors_p (void);
196 int have_attached_inferiors_p (void);
198 ptid_t
thread_id_to_gdb_id (ptid_t
);
199 ptid_t
thread_to_gdb_id (struct thread_info
*);
200 ptid_t
gdb_id_to_thread_id (ptid_t
);
202 void clear_inferiors (void);
203 struct inferior_list_entry
*find_inferior
204 (struct inferior_list
*,
205 int (*func
) (struct inferior_list_entry
*,
208 struct inferior_list_entry
*find_inferior_id (struct inferior_list
*list
,
210 void *inferior_target_data (struct thread_info
*);
211 void set_inferior_target_data (struct thread_info
*, void *);
212 void *inferior_regcache_data (struct thread_info
*);
213 void set_inferior_regcache_data (struct thread_info
*, void *);
215 void loaded_dll (const char *name
, CORE_ADDR base_addr
);
216 void unloaded_dll (const char *name
, CORE_ADDR base_addr
);
218 /* Public variables in server.c */
220 extern ptid_t cont_thread
;
221 extern ptid_t general_thread
;
223 extern int server_waiting
;
224 extern int debug_threads
;
225 extern int debug_hw_points
;
226 extern int pass_signals
[];
227 extern int program_signals
[];
228 extern int program_signals_p
;
230 extern jmp_buf toplevel
;
232 extern int disable_packet_vCont
;
233 extern int disable_packet_Tthread
;
234 extern int disable_packet_qC
;
235 extern int disable_packet_qfThreadInfo
;
238 extern int multi_process
;
241 extern int disable_randomization
;
244 #include <winsock2.h>
245 typedef SOCKET gdb_fildes_t
;
247 typedef int gdb_fildes_t
;
250 /* Functions from event-loop.c. */
251 typedef void *gdb_client_data
;
252 typedef int (handler_func
) (int, gdb_client_data
);
253 typedef int (callback_handler_func
) (gdb_client_data
);
255 extern void delete_file_handler (gdb_fildes_t fd
);
256 extern void add_file_handler (gdb_fildes_t fd
, handler_func
*proc
,
257 gdb_client_data client_data
);
258 extern int append_callback_event (callback_handler_func
*proc
,
259 gdb_client_data client_data
);
260 extern void delete_callback_event (int id
);
262 extern void start_event_loop (void);
263 extern void initialize_event_loop (void);
265 /* Functions from server.c. */
266 extern int handle_serial_event (int err
, gdb_client_data client_data
);
267 extern int handle_target_event (int err
, gdb_client_data client_data
);
269 /* Functions from hostio.c. */
270 extern int handle_vFile (char *, int, int *);
272 /* Functions from hostio-errno.c. */
273 extern void hostio_last_error_from_errno (char *own_buf
);
275 #include "remote-utils.h"
277 #include "common-utils.h"
280 #include "gdb_assert.h"
282 /* Maximum number of bytes to read/write at once. The value here
283 is chosen to fill up a packet (the headers account for the 32). */
284 #define MAXBUFBYTES(N) (((N)-32)/2)
286 /* Buffer sizes for transferring memory, registers, etc. Set to a constant
287 value to accomodate multiple register formats. This value must be at least
288 as large as the largest register set supported by gdbserver. */
289 #define PBUFSIZ 16384
291 /* Bytecode compilation function vector. */
295 void (*emit_prologue
) (void);
296 void (*emit_epilogue
) (void);
297 void (*emit_add
) (void);
298 void (*emit_sub
) (void);
299 void (*emit_mul
) (void);
300 void (*emit_lsh
) (void);
301 void (*emit_rsh_signed
) (void);
302 void (*emit_rsh_unsigned
) (void);
303 void (*emit_ext
) (int arg
);
304 void (*emit_log_not
) (void);
305 void (*emit_bit_and
) (void);
306 void (*emit_bit_or
) (void);
307 void (*emit_bit_xor
) (void);
308 void (*emit_bit_not
) (void);
309 void (*emit_equal
) (void);
310 void (*emit_less_signed
) (void);
311 void (*emit_less_unsigned
) (void);
312 void (*emit_ref
) (int size
);
313 void (*emit_if_goto
) (int *offset_p
, int *size_p
);
314 void (*emit_goto
) (int *offset_p
, int *size_p
);
315 void (*write_goto_address
) (CORE_ADDR from
, CORE_ADDR to
, int size
);
316 void (*emit_const
) (LONGEST num
);
317 void (*emit_call
) (CORE_ADDR fn
);
318 void (*emit_reg
) (int reg
);
319 void (*emit_pop
) (void);
320 void (*emit_stack_flush
) (void);
321 void (*emit_zero_ext
) (int arg
);
322 void (*emit_swap
) (void);
323 void (*emit_stack_adjust
) (int n
);
325 /* Emit code for a generic function that takes one fixed integer
326 argument and returns a 64-bit int (for instance, tsv getter). */
327 void (*emit_int_call_1
) (CORE_ADDR fn
, int arg1
);
329 /* Emit code for a generic function that takes one fixed integer
330 argument and a 64-bit int from the top of the stack, and returns
331 nothing (for instance, tsv setter). */
332 void (*emit_void_call_2
) (CORE_ADDR fn
, int arg1
);
334 /* Emit code specialized for common combinations of compare followed
336 void (*emit_eq_goto
) (int *offset_p
, int *size_p
);
337 void (*emit_ne_goto
) (int *offset_p
, int *size_p
);
338 void (*emit_lt_goto
) (int *offset_p
, int *size_p
);
339 void (*emit_le_goto
) (int *offset_p
, int *size_p
);
340 void (*emit_gt_goto
) (int *offset_p
, int *size_p
);
341 void (*emit_ge_goto
) (int *offset_p
, int *size_p
);
344 extern CORE_ADDR current_insn_ptr
;
345 extern int emit_error
;
347 #endif /* SERVER_H */