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 /* Define underscore macro, if not available, to be able to use it inside
77 code shared with gdb in common directory. */
79 #define _(String) (String)
82 #ifdef IN_PROCESS_AGENT
85 # define PROG "gdbserver"
88 /* A type used for binary buffers. */
89 typedef unsigned char gdb_byte;
93 #include "xml-utils.h"
94 #include "gdb_locale.h"
96 /* FIXME: This should probably be autoconf'd for. It's an integer type at
97 least the size of a (void *). */
98 typedef long long CORE_ADDR;
100 typedef long long LONGEST;
101 typedef unsigned long long ULONGEST;
103 /* Generic information for tracking a list of ``inferiors'' - threads,
107 struct inferior_list_entry *head;
108 struct inferior_list_entry *tail;
110 struct inferior_list_entry
113 struct inferior_list_entry *next;
121 #include "regcache.h"
122 #include "gdb/signals.h"
123 #include "gdb_signals.h"
125 #include "mem-break.h"
126 #include "gdbthread.h"
130 struct inferior_list_entry entry;
137 struct raw_breakpoint;
138 struct fast_tracepoint_jump;
139 struct process_info_private;
143 struct inferior_list_entry head;
145 /* Nonzero if this child process was attached rather than
149 /* True if GDB asked us to detach from this process, but we remained
153 /* The symbol cache. */
154 struct sym_cache *symbol_cache;
156 /* The list of memory breakpoints. */
157 struct breakpoint *breakpoints;
159 /* The list of raw memory breakpoints. */
160 struct raw_breakpoint *raw_breakpoints;
162 /* The list of installed fast tracepoints. */
163 struct fast_tracepoint_jump *fast_tracepoint_jumps;
165 const struct target_desc *tdesc;
167 /* Private target data. */
168 struct process_info_private *private;
171 /* Return a pointer to the process that corresponds to the current
172 thread (current_inferior). It is an error to call this if there is
173 no current thread selected. */
175 struct process_info *current_process (void);
176 struct process_info *get_thread_process (struct thread_info *);
178 /* Target-specific functions */
180 void initialize_low ();
182 /* From inferiors.c. */
184 extern struct inferior_list all_processes;
185 extern struct inferior_list all_dlls;
186 extern int dlls_changed;
187 extern void clear_dlls (void);
189 void add_inferior_to_list (struct inferior_list *list,
190 struct inferior_list_entry *new_inferior);
191 void for_each_inferior (struct inferior_list *list,
192 void (*action) (struct inferior_list_entry *));
194 extern struct thread_info *current_inferior;
195 void remove_inferior (struct inferior_list *list,
196 struct inferior_list_entry *entry);
198 struct process_info *add_process (int pid, int attached);
199 void remove_process (struct process_info *process);
200 struct process_info *find_process_pid (int pid);
201 int have_started_inferiors_p (void);
202 int have_attached_inferiors_p (void);
204 ptid_t thread_id_to_gdb_id (ptid_t);
205 ptid_t thread_to_gdb_id (struct thread_info *);
206 ptid_t gdb_id_to_thread_id (ptid_t);
208 void clear_inferiors (void);
209 struct inferior_list_entry *find_inferior
210 (struct inferior_list *,
211 int (*func) (struct inferior_list_entry *,
214 struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
216 void *inferior_target_data (struct thread_info *);
217 void set_inferior_target_data (struct thread_info *, void *);
218 void *inferior_regcache_data (struct thread_info *);
219 void set_inferior_regcache_data (struct thread_info *, void *);
221 void loaded_dll (const char *name, CORE_ADDR base_addr);
222 void unloaded_dll (const char *name, CORE_ADDR base_addr);
224 /* Public variables in server.c */
226 extern ptid_t cont_thread;
227 extern ptid_t general_thread;
229 extern int server_waiting;
230 extern int debug_threads;
231 extern int debug_hw_points;
232 extern int pass_signals[];
233 extern int program_signals[];
234 extern int program_signals_p;
236 extern jmp_buf toplevel;
238 extern int disable_packet_vCont;
239 extern int disable_packet_Tthread;
240 extern int disable_packet_qC;
241 extern int disable_packet_qfThreadInfo;
244 extern int multi_process;
247 extern int disable_randomization;
250 #include <winsock2.h>
251 typedef SOCKET gdb_fildes_t;
253 typedef int gdb_fildes_t;
256 /* Functions from event-loop.c. */
257 typedef void *gdb_client_data;
258 typedef int (handler_func) (int, gdb_client_data);
259 typedef int (callback_handler_func) (gdb_client_data);
261 extern void delete_file_handler (gdb_fildes_t fd);
262 extern void add_file_handler (gdb_fildes_t fd, handler_func *proc,
263 gdb_client_data client_data);
264 extern int append_callback_event (callback_handler_func *proc,
265 gdb_client_data client_data);
266 extern void delete_callback_event (int id);
268 extern void start_event_loop (void);
269 extern void initialize_event_loop (void);
271 /* Functions from server.c. */
272 extern int handle_serial_event (int err, gdb_client_data client_data);
273 extern int handle_target_event (int err, gdb_client_data client_data);
275 /* Functions from hostio.c. */
276 extern int handle_vFile (char *, int, int *);
278 /* Functions from hostio-errno.c. */
279 extern void hostio_last_error_from_errno (char *own_buf);
281 /* From remote-utils.c */
283 extern int remote_debug;
284 extern int noack_mode;
285 extern int transport_is_reliable;
287 int gdb_connected (void);
289 #define STDIO_CONNECTION_NAME "stdio"
290 int remote_connection_is_stdio (void);
292 ptid_t read_ptid (char *buf, char **obuf);
293 char *write_ptid (char *buf, ptid_t ptid);
295 int putpkt (char *buf);
296 int putpkt_binary (char *buf, int len);
297 int putpkt_notif (char *buf);
298 int getpkt (char *buf);
299 void remote_prepare (char *name);
300 void remote_open (char *name);
301 void remote_close (void);
302 void write_ok (char *buf);
303 void write_enn (char *buf);
304 void initialize_async_io (void);
305 void enable_async_io (void);
306 void disable_async_io (void);
307 void check_remote_input_interrupt_request (void);
308 void convert_ascii_to_int (const char *from, unsigned char *to, int n);
309 void convert_int_to_ascii (const unsigned char *from, char *to, int n);
310 void new_thread_notify (int id);
311 void dead_thread_notify (int id);
312 void prepare_resume_reply (char *buf, ptid_t ptid,
313 struct target_waitstatus *status);
315 const char *decode_address_to_semicolon (CORE_ADDR *addrp, const char *start);
316 void decode_address (CORE_ADDR *addrp, const char *start, int len);
317 void decode_m_packet (char *from, CORE_ADDR * mem_addr_ptr,
318 unsigned int *len_ptr);
319 void decode_M_packet (char *from, CORE_ADDR * mem_addr_ptr,
320 unsigned int *len_ptr, unsigned char **to_p);
321 int decode_X_packet (char *from, int packet_len, CORE_ADDR * mem_addr_ptr,
322 unsigned int *len_ptr, unsigned char **to_p);
323 int decode_xfer_write (char *buf, int packet_len,
324 CORE_ADDR *offset, unsigned int *len,
325 unsigned char *data);
326 int decode_search_memory_packet (const char *buf, int packet_len,
327 CORE_ADDR *start_addrp,
328 CORE_ADDR *search_space_lenp,
330 unsigned int *pattern_lenp);
332 int unhexify (char *bin, const char *hex, int count);
333 int hexify (char *hex, const char *bin, int count);
334 int remote_escape_output (const gdb_byte *buffer, int len,
335 gdb_byte *out_buf, int *out_len,
337 char *unpack_varlen_hex (char *buff, ULONGEST *result);
339 void clear_symbol_cache (struct sym_cache **symcache_p);
340 int look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb);
342 int relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc);
344 void monitor_output (const char *msg);
346 /* Functions from utils.c */
347 #include "common-utils.h"
349 void perror_with_name (const char *string);
350 void error (const char *string,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
351 void fatal (const char *string,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
352 void warning (const char *string,...) ATTRIBUTE_PRINTF (1, 2);
353 char *paddress (CORE_ADDR addr);
354 char *pulongest (ULONGEST u);
355 char *plongest (LONGEST l);
356 char *phex_nz (ULONGEST l, int sizeof_l);
357 char *pfildes (gdb_fildes_t fd);
359 #include "gdb_assert.h"
361 /* Maximum number of bytes to read/write at once. The value here
362 is chosen to fill up a packet (the headers account for the 32). */
363 #define MAXBUFBYTES(N) (((N)-32)/2)
365 /* Buffer sizes for transferring memory, registers, etc. Set to a constant
366 value to accomodate multiple register formats. This value must be at least
367 as large as the largest register set supported by gdbserver. */
368 #define PBUFSIZ 16384
370 /* Functions from tracepoint.c */
372 /* Size for a small buffer to report problems from the in-process
373 agent back to GDBserver. */
374 #define IPA_BUFSIZ 100
376 void initialize_tracepoint (void);
379 extern int disconnected_tracing;
381 void tracepoint_look_up_symbols (void);
383 void stop_tracing (void);
385 int handle_tracepoint_general_set (char *own_buf);
386 int handle_tracepoint_query (char *own_buf);
388 int tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc);
389 int tracepoint_was_hit (struct thread_info *tinfo, CORE_ADDR stop_pc);
391 void release_while_stepping_state_list (struct thread_info *tinfo);
393 extern int current_traceframe;
395 int in_readonly_region (CORE_ADDR addr, ULONGEST length);
396 int traceframe_read_mem (int tfnum, CORE_ADDR addr,
397 unsigned char *buf, ULONGEST length,
399 int fetch_traceframe_registers (int tfnum,
400 struct regcache *regcache,
403 int traceframe_read_sdata (int tfnum, ULONGEST offset,
404 unsigned char *buf, ULONGEST length,
407 int traceframe_read_info (int tfnum, struct buffer *buffer);
409 /* If a thread is determined to be collecting a fast tracepoint, this
410 structure holds the collect status. */
412 struct fast_tpoint_collect_status
414 /* The tracepoint that is presently being collected. */
416 CORE_ADDR tpoint_addr;
418 /* The address range in the jump pad of where the original
419 instruction the tracepoint jump was inserted was relocated
421 CORE_ADDR adjusted_insn_addr;
422 CORE_ADDR adjusted_insn_addr_end;
425 int fast_tracepoint_collecting (CORE_ADDR thread_area,
427 struct fast_tpoint_collect_status *status);
428 void force_unlock_trace_buffer (void);
430 int handle_tracepoint_bkpts (struct thread_info *tinfo, CORE_ADDR stop_pc);
432 #ifdef IN_PROCESS_AGENT
433 void initialize_low_tracepoint (void);
434 void supply_fast_tracepoint_registers (struct regcache *regcache,
435 const unsigned char *regs);
436 void supply_static_tracepoint_registers (struct regcache *regcache,
437 const unsigned char *regs,
439 void set_trampoline_buffer_space (CORE_ADDR begin, CORE_ADDR end,
442 extern const struct target_desc *ipa_tdesc;
445 void stop_tracing (void);
447 int claim_trampoline_space (ULONGEST used, CORE_ADDR *trampoline);
448 int have_fast_tracepoint_trampoline_buffer (char *msgbuf);
449 void gdb_agent_about_to_close (int pid);
453 struct eval_agent_expr_context;
455 /* Do memory copies for bytecodes. */
456 /* Do the recording of memory blocks for actions and bytecodes. */
458 int agent_mem_read (struct eval_agent_expr_context *ctx,
459 unsigned char *to, CORE_ADDR from,
462 LONGEST agent_get_trace_state_variable_value (int num);
463 void agent_set_trace_state_variable_value (int num, LONGEST val);
465 /* Record the value of a trace state variable. */
467 int agent_tsv_read (struct eval_agent_expr_context *ctx, int n);
468 int agent_mem_read_string (struct eval_agent_expr_context *ctx,
473 /* Bytecode compilation function vector. */
477 void (*emit_prologue) (void);
478 void (*emit_epilogue) (void);
479 void (*emit_add) (void);
480 void (*emit_sub) (void);
481 void (*emit_mul) (void);
482 void (*emit_lsh) (void);
483 void (*emit_rsh_signed) (void);
484 void (*emit_rsh_unsigned) (void);
485 void (*emit_ext) (int arg);
486 void (*emit_log_not) (void);
487 void (*emit_bit_and) (void);
488 void (*emit_bit_or) (void);
489 void (*emit_bit_xor) (void);
490 void (*emit_bit_not) (void);
491 void (*emit_equal) (void);
492 void (*emit_less_signed) (void);
493 void (*emit_less_unsigned) (void);
494 void (*emit_ref) (int size);
495 void (*emit_if_goto) (int *offset_p, int *size_p);
496 void (*emit_goto) (int *offset_p, int *size_p);
497 void (*write_goto_address) (CORE_ADDR from, CORE_ADDR to, int size);
498 void (*emit_const) (LONGEST num);
499 void (*emit_call) (CORE_ADDR fn);
500 void (*emit_reg) (int reg);
501 void (*emit_pop) (void);
502 void (*emit_stack_flush) (void);
503 void (*emit_zero_ext) (int arg);
504 void (*emit_swap) (void);
505 void (*emit_stack_adjust) (int n);
507 /* Emit code for a generic function that takes one fixed integer
508 argument and returns a 64-bit int (for instance, tsv getter). */
509 void (*emit_int_call_1) (CORE_ADDR fn, int arg1);
511 /* Emit code for a generic function that takes one fixed integer
512 argument and a 64-bit int from the top of the stack, and returns
513 nothing (for instance, tsv setter). */
514 void (*emit_void_call_2) (CORE_ADDR fn, int arg1);
516 /* Emit code specialized for common combinations of compare followed
518 void (*emit_eq_goto) (int *offset_p, int *size_p);
519 void (*emit_ne_goto) (int *offset_p, int *size_p);
520 void (*emit_lt_goto) (int *offset_p, int *size_p);
521 void (*emit_le_goto) (int *offset_p, int *size_p);
522 void (*emit_gt_goto) (int *offset_p, int *size_p);
523 void (*emit_ge_goto) (int *offset_p, int *size_p);
526 /* Returns the address of the get_raw_reg function in the IPA. */
527 CORE_ADDR get_raw_reg_func_addr (void);
528 /* Returns the address of the get_trace_state_variable_value
529 function in the IPA. */
530 CORE_ADDR get_get_tsv_func_addr (void);
531 /* Returns the address of the set_trace_state_variable_value
532 function in the IPA. */
533 CORE_ADDR get_set_tsv_func_addr (void);
535 extern CORE_ADDR current_insn_ptr;
536 extern int emit_error;
538 #endif /* SERVER_H */