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"
48 /* On some systems such as MinGW, alloca is declared in malloc.h
49 (there is no alloca.h). */
54 #if !HAVE_DECL_STRERROR
56 extern char *strerror (int); /* X3.159-1989 4.11.6.2 */
62 extern void perror (const char *);
66 #if !HAVE_DECL_VASPRINTF
67 extern int vasprintf(char **strp, const char *fmt, va_list ap);
69 #if !HAVE_DECL_VSNPRINTF
70 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
73 /* Define underscore macro, if not available, to be able to use it inside
74 code shared with gdb in common directory. */
76 #define _(String) (String)
79 #ifdef IN_PROCESS_AGENT
82 # define PROG "gdbserver"
85 /* A type used for binary buffers. */
86 typedef unsigned char gdb_byte;
90 #include "xml-utils.h"
91 #include "gdb_locale.h"
93 /* FIXME: This should probably be autoconf'd for. It's an integer type at
94 least the size of a (void *). */
95 typedef long long CORE_ADDR;
97 typedef long long LONGEST;
98 typedef unsigned long long ULONGEST;
100 /* Generic information for tracking a list of ``inferiors'' - threads,
104 struct inferior_list_entry *head;
105 struct inferior_list_entry *tail;
107 struct inferior_list_entry
110 struct inferior_list_entry *next;
118 #include "regcache.h"
119 #include "gdb/signals.h"
120 #include "gdb_signals.h"
122 #include "mem-break.h"
123 #include "gdbthread.h"
127 struct inferior_list_entry entry;
134 struct raw_breakpoint;
135 struct fast_tracepoint_jump;
136 struct process_info_private;
140 struct inferior_list_entry head;
142 /* Nonzero if this child process was attached rather than
146 /* True if GDB asked us to detach from this process, but we remained
150 /* The symbol cache. */
151 struct sym_cache *symbol_cache;
153 /* The list of memory breakpoints. */
154 struct breakpoint *breakpoints;
156 /* The list of raw memory breakpoints. */
157 struct raw_breakpoint *raw_breakpoints;
159 /* The list of installed fast tracepoints. */
160 struct fast_tracepoint_jump *fast_tracepoint_jumps;
162 const struct target_desc *tdesc;
164 /* Private target data. */
165 struct process_info_private *private;
168 /* Return a pointer to the process that corresponds to the current
169 thread (current_inferior). It is an error to call this if there is
170 no current thread selected. */
172 struct process_info *current_process (void);
173 struct process_info *get_thread_process (struct thread_info *);
175 /* Target-specific functions */
177 void initialize_low ();
179 /* From inferiors.c. */
181 extern struct inferior_list all_processes;
182 extern struct inferior_list all_dlls;
183 extern int dlls_changed;
184 extern void clear_dlls (void);
186 void add_inferior_to_list (struct inferior_list *list,
187 struct inferior_list_entry *new_inferior);
188 void for_each_inferior (struct inferior_list *list,
189 void (*action) (struct inferior_list_entry *));
191 extern struct thread_info *current_inferior;
192 void remove_inferior (struct inferior_list *list,
193 struct inferior_list_entry *entry);
195 struct process_info *add_process (int pid, int attached);
196 void remove_process (struct process_info *process);
197 struct process_info *find_process_pid (int pid);
198 int have_started_inferiors_p (void);
199 int have_attached_inferiors_p (void);
201 ptid_t thread_id_to_gdb_id (ptid_t);
202 ptid_t thread_to_gdb_id (struct thread_info *);
203 ptid_t gdb_id_to_thread_id (ptid_t);
205 void clear_inferiors (void);
206 struct inferior_list_entry *find_inferior
207 (struct inferior_list *,
208 int (*func) (struct inferior_list_entry *,
211 struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
213 void *inferior_target_data (struct thread_info *);
214 void set_inferior_target_data (struct thread_info *, void *);
215 void *inferior_regcache_data (struct thread_info *);
216 void set_inferior_regcache_data (struct thread_info *, void *);
218 void loaded_dll (const char *name, CORE_ADDR base_addr);
219 void unloaded_dll (const char *name, CORE_ADDR base_addr);
221 /* Public variables in server.c */
223 extern ptid_t cont_thread;
224 extern ptid_t general_thread;
226 extern int server_waiting;
227 extern int debug_threads;
228 extern int debug_hw_points;
229 extern int pass_signals[];
230 extern int program_signals[];
231 extern int program_signals_p;
233 extern jmp_buf toplevel;
235 extern int disable_packet_vCont;
236 extern int disable_packet_Tthread;
237 extern int disable_packet_qC;
238 extern int disable_packet_qfThreadInfo;
241 extern int multi_process;
244 extern int disable_randomization;
247 #include <winsock2.h>
248 typedef SOCKET gdb_fildes_t;
250 typedef int gdb_fildes_t;
253 /* Functions from event-loop.c. */
254 typedef void *gdb_client_data;
255 typedef int (handler_func) (int, gdb_client_data);
256 typedef int (callback_handler_func) (gdb_client_data);
258 extern void delete_file_handler (gdb_fildes_t fd);
259 extern void add_file_handler (gdb_fildes_t fd, handler_func *proc,
260 gdb_client_data client_data);
261 extern int append_callback_event (callback_handler_func *proc,
262 gdb_client_data client_data);
263 extern void delete_callback_event (int id);
265 extern void start_event_loop (void);
266 extern void initialize_event_loop (void);
268 /* Functions from server.c. */
269 extern int handle_serial_event (int err, gdb_client_data client_data);
270 extern int handle_target_event (int err, gdb_client_data client_data);
272 /* Functions from hostio.c. */
273 extern int handle_vFile (char *, int, int *);
275 /* Functions from hostio-errno.c. */
276 extern void hostio_last_error_from_errno (char *own_buf);
278 /* From remote-utils.c */
280 extern int remote_debug;
281 extern int noack_mode;
282 extern int transport_is_reliable;
284 int gdb_connected (void);
286 #define STDIO_CONNECTION_NAME "stdio"
287 int remote_connection_is_stdio (void);
289 ptid_t read_ptid (char *buf, char **obuf);
290 char *write_ptid (char *buf, ptid_t ptid);
292 int putpkt (char *buf);
293 int putpkt_binary (char *buf, int len);
294 int putpkt_notif (char *buf);
295 int getpkt (char *buf);
296 void remote_prepare (char *name);
297 void remote_open (char *name);
298 void remote_close (void);
299 void write_ok (char *buf);
300 void write_enn (char *buf);
301 void initialize_async_io (void);
302 void enable_async_io (void);
303 void disable_async_io (void);
304 void check_remote_input_interrupt_request (void);
305 void convert_ascii_to_int (const char *from, unsigned char *to, int n);
306 void convert_int_to_ascii (const unsigned char *from, char *to, int n);
307 void new_thread_notify (int id);
308 void dead_thread_notify (int id);
309 void prepare_resume_reply (char *buf, ptid_t ptid,
310 struct target_waitstatus *status);
312 const char *decode_address_to_semicolon (CORE_ADDR *addrp, const char *start);
313 void decode_address (CORE_ADDR *addrp, const char *start, int len);
314 void decode_m_packet (char *from, CORE_ADDR * mem_addr_ptr,
315 unsigned int *len_ptr);
316 void decode_M_packet (char *from, CORE_ADDR * mem_addr_ptr,
317 unsigned int *len_ptr, unsigned char **to_p);
318 int decode_X_packet (char *from, int packet_len, CORE_ADDR * mem_addr_ptr,
319 unsigned int *len_ptr, unsigned char **to_p);
320 int decode_xfer_write (char *buf, int packet_len,
321 CORE_ADDR *offset, unsigned int *len,
322 unsigned char *data);
323 int decode_search_memory_packet (const char *buf, int packet_len,
324 CORE_ADDR *start_addrp,
325 CORE_ADDR *search_space_lenp,
327 unsigned int *pattern_lenp);
329 int unhexify (char *bin, const char *hex, int count);
330 int hexify (char *hex, const char *bin, int count);
331 int remote_escape_output (const gdb_byte *buffer, int len,
332 gdb_byte *out_buf, int *out_len,
334 char *unpack_varlen_hex (char *buff, ULONGEST *result);
336 void clear_symbol_cache (struct sym_cache **symcache_p);
337 int look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb);
339 int relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc);
341 void monitor_output (const char *msg);
343 /* Functions from utils.c */
344 #include "common-utils.h"
346 void perror_with_name (const char *string);
347 void error (const char *string,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
348 void fatal (const char *string,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
349 void warning (const char *string,...) ATTRIBUTE_PRINTF (1, 2);
350 char *paddress (CORE_ADDR addr);
351 char *pulongest (ULONGEST u);
352 char *plongest (LONGEST l);
353 char *phex_nz (ULONGEST l, int sizeof_l);
354 char *pfildes (gdb_fildes_t fd);
356 #include "gdb_assert.h"
358 /* Maximum number of bytes to read/write at once. The value here
359 is chosen to fill up a packet (the headers account for the 32). */
360 #define MAXBUFBYTES(N) (((N)-32)/2)
362 /* Buffer sizes for transferring memory, registers, etc. Set to a constant
363 value to accomodate multiple register formats. This value must be at least
364 as large as the largest register set supported by gdbserver. */
365 #define PBUFSIZ 16384
367 /* Functions from tracepoint.c */
369 /* Size for a small buffer to report problems from the in-process
370 agent back to GDBserver. */
371 #define IPA_BUFSIZ 100
373 void initialize_tracepoint (void);
376 extern int disconnected_tracing;
378 void tracepoint_look_up_symbols (void);
380 void stop_tracing (void);
382 int handle_tracepoint_general_set (char *own_buf);
383 int handle_tracepoint_query (char *own_buf);
385 int tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc);
386 int tracepoint_was_hit (struct thread_info *tinfo, CORE_ADDR stop_pc);
388 void release_while_stepping_state_list (struct thread_info *tinfo);
390 extern int current_traceframe;
392 int in_readonly_region (CORE_ADDR addr, ULONGEST length);
393 int traceframe_read_mem (int tfnum, CORE_ADDR addr,
394 unsigned char *buf, ULONGEST length,
396 int fetch_traceframe_registers (int tfnum,
397 struct regcache *regcache,
400 int traceframe_read_sdata (int tfnum, ULONGEST offset,
401 unsigned char *buf, ULONGEST length,
404 int traceframe_read_info (int tfnum, struct buffer *buffer);
406 /* If a thread is determined to be collecting a fast tracepoint, this
407 structure holds the collect status. */
409 struct fast_tpoint_collect_status
411 /* The tracepoint that is presently being collected. */
413 CORE_ADDR tpoint_addr;
415 /* The address range in the jump pad of where the original
416 instruction the tracepoint jump was inserted was relocated
418 CORE_ADDR adjusted_insn_addr;
419 CORE_ADDR adjusted_insn_addr_end;
422 int fast_tracepoint_collecting (CORE_ADDR thread_area,
424 struct fast_tpoint_collect_status *status);
425 void force_unlock_trace_buffer (void);
427 int handle_tracepoint_bkpts (struct thread_info *tinfo, CORE_ADDR stop_pc);
429 #ifdef IN_PROCESS_AGENT
430 void initialize_low_tracepoint (void);
431 void supply_fast_tracepoint_registers (struct regcache *regcache,
432 const unsigned char *regs);
433 void supply_static_tracepoint_registers (struct regcache *regcache,
434 const unsigned char *regs,
436 void set_trampoline_buffer_space (CORE_ADDR begin, CORE_ADDR end,
439 extern const struct target_desc *ipa_tdesc;
442 void stop_tracing (void);
444 int claim_trampoline_space (ULONGEST used, CORE_ADDR *trampoline);
445 int have_fast_tracepoint_trampoline_buffer (char *msgbuf);
446 void gdb_agent_about_to_close (int pid);
450 struct eval_agent_expr_context;
452 /* Do memory copies for bytecodes. */
453 /* Do the recording of memory blocks for actions and bytecodes. */
455 int agent_mem_read (struct eval_agent_expr_context *ctx,
456 unsigned char *to, CORE_ADDR from,
459 LONGEST agent_get_trace_state_variable_value (int num);
460 void agent_set_trace_state_variable_value (int num, LONGEST val);
462 /* Record the value of a trace state variable. */
464 int agent_tsv_read (struct eval_agent_expr_context *ctx, int n);
465 int agent_mem_read_string (struct eval_agent_expr_context *ctx,
470 /* Bytecode compilation function vector. */
474 void (*emit_prologue) (void);
475 void (*emit_epilogue) (void);
476 void (*emit_add) (void);
477 void (*emit_sub) (void);
478 void (*emit_mul) (void);
479 void (*emit_lsh) (void);
480 void (*emit_rsh_signed) (void);
481 void (*emit_rsh_unsigned) (void);
482 void (*emit_ext) (int arg);
483 void (*emit_log_not) (void);
484 void (*emit_bit_and) (void);
485 void (*emit_bit_or) (void);
486 void (*emit_bit_xor) (void);
487 void (*emit_bit_not) (void);
488 void (*emit_equal) (void);
489 void (*emit_less_signed) (void);
490 void (*emit_less_unsigned) (void);
491 void (*emit_ref) (int size);
492 void (*emit_if_goto) (int *offset_p, int *size_p);
493 void (*emit_goto) (int *offset_p, int *size_p);
494 void (*write_goto_address) (CORE_ADDR from, CORE_ADDR to, int size);
495 void (*emit_const) (LONGEST num);
496 void (*emit_call) (CORE_ADDR fn);
497 void (*emit_reg) (int reg);
498 void (*emit_pop) (void);
499 void (*emit_stack_flush) (void);
500 void (*emit_zero_ext) (int arg);
501 void (*emit_swap) (void);
502 void (*emit_stack_adjust) (int n);
504 /* Emit code for a generic function that takes one fixed integer
505 argument and returns a 64-bit int (for instance, tsv getter). */
506 void (*emit_int_call_1) (CORE_ADDR fn, int arg1);
508 /* Emit code for a generic function that takes one fixed integer
509 argument and a 64-bit int from the top of the stack, and returns
510 nothing (for instance, tsv setter). */
511 void (*emit_void_call_2) (CORE_ADDR fn, int arg1);
513 /* Emit code specialized for common combinations of compare followed
515 void (*emit_eq_goto) (int *offset_p, int *size_p);
516 void (*emit_ne_goto) (int *offset_p, int *size_p);
517 void (*emit_lt_goto) (int *offset_p, int *size_p);
518 void (*emit_le_goto) (int *offset_p, int *size_p);
519 void (*emit_gt_goto) (int *offset_p, int *size_p);
520 void (*emit_ge_goto) (int *offset_p, int *size_p);
523 /* Returns the address of the get_raw_reg function in the IPA. */
524 CORE_ADDR get_raw_reg_func_addr (void);
525 /* Returns the address of the get_trace_state_variable_value
526 function in the IPA. */
527 CORE_ADDR get_get_tsv_func_addr (void);
528 /* Returns the address of the set_trace_state_variable_value
529 function in the IPA. */
530 CORE_ADDR get_set_tsv_func_addr (void);
532 extern CORE_ADDR current_insn_ptr;
533 extern int emit_error;
535 #endif /* SERVER_H */