1 /* Common definitions for remote server for GDB.
2 Copyright (C) 1993, 1995, 1997-2000, 2002-2012 Free Software
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "build-gnulib-gdbserver/config.h"
27 #include "wincecompat.h"
30 #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
;
117 #include "regcache.h"
118 #include "gdb/signals.h"
119 #include "gdb_signals.h"
121 #include "mem-break.h"
122 #include "gdbthread.h"
126 struct inferior_list_entry entry
;
133 struct raw_breakpoint
;
134 struct fast_tracepoint_jump
;
135 struct process_info_private
;
139 struct inferior_list_entry head
;
141 /* Nonzero if this child process was attached rather than
145 /* True if GDB asked us to detach from this process, but we remained
149 /* The symbol cache. */
150 struct sym_cache
*symbol_cache
;
152 /* The list of memory breakpoints. */
153 struct breakpoint
*breakpoints
;
155 /* The list of raw memory breakpoints. */
156 struct raw_breakpoint
*raw_breakpoints
;
158 /* The list of installed fast tracepoints. */
159 struct fast_tracepoint_jump
*fast_tracepoint_jumps
;
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);
264 /* Functions from server.c. */
265 extern int handle_serial_event (int err
, gdb_client_data client_data
);
266 extern int handle_target_event (int err
, gdb_client_data client_data
);
268 extern void push_event (ptid_t ptid
, struct target_waitstatus
*status
);
270 /* Functions from hostio.c. */
271 extern int handle_vFile (char *, int, int *);
273 /* Functions from hostio-errno.c. */
274 extern void hostio_last_error_from_errno (char *own_buf
);
276 /* From remote-utils.c */
278 extern int remote_debug
;
279 extern int noack_mode
;
280 extern int transport_is_reliable
;
282 int gdb_connected (void);
284 #define STDIO_CONNECTION_NAME "stdio"
285 int remote_connection_is_stdio (void);
287 ptid_t
read_ptid (char *buf
, char **obuf
);
288 char *write_ptid (char *buf
, ptid_t ptid
);
290 int putpkt (char *buf
);
291 int putpkt_binary (char *buf
, int len
);
292 int putpkt_notif (char *buf
);
293 int getpkt (char *buf
);
294 void remote_prepare (char *name
);
295 void remote_open (char *name
);
296 void remote_close (void);
297 void write_ok (char *buf
);
298 void write_enn (char *buf
);
299 void initialize_async_io (void);
300 void enable_async_io (void);
301 void disable_async_io (void);
302 void check_remote_input_interrupt_request (void);
303 void convert_ascii_to_int (const char *from
, unsigned char *to
, int n
);
304 void convert_int_to_ascii (const unsigned char *from
, char *to
, int n
);
305 void new_thread_notify (int id
);
306 void dead_thread_notify (int id
);
307 void prepare_resume_reply (char *buf
, ptid_t ptid
,
308 struct target_waitstatus
*status
);
310 const char *decode_address_to_semicolon (CORE_ADDR
*addrp
, const char *start
);
311 void decode_address (CORE_ADDR
*addrp
, const char *start
, int len
);
312 void decode_m_packet (char *from
, CORE_ADDR
* mem_addr_ptr
,
313 unsigned int *len_ptr
);
314 void decode_M_packet (char *from
, CORE_ADDR
* mem_addr_ptr
,
315 unsigned int *len_ptr
, unsigned char **to_p
);
316 int decode_X_packet (char *from
, int packet_len
, CORE_ADDR
* mem_addr_ptr
,
317 unsigned int *len_ptr
, unsigned char **to_p
);
318 int decode_xfer_write (char *buf
, int packet_len
,
319 CORE_ADDR
*offset
, unsigned int *len
,
320 unsigned char *data
);
321 int decode_search_memory_packet (const char *buf
, int packet_len
,
322 CORE_ADDR
*start_addrp
,
323 CORE_ADDR
*search_space_lenp
,
325 unsigned int *pattern_lenp
);
327 int unhexify (char *bin
, const char *hex
, int count
);
328 int hexify (char *hex
, const char *bin
, int count
);
329 int remote_escape_output (const gdb_byte
*buffer
, int len
,
330 gdb_byte
*out_buf
, int *out_len
,
332 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
334 void clear_symbol_cache (struct sym_cache
**symcache_p
);
335 int look_up_one_symbol (const char *name
, CORE_ADDR
*addrp
, int may_ask_gdb
);
337 int relocate_instruction (CORE_ADDR
*to
, CORE_ADDR oldloc
);
339 void monitor_output (const char *msg
);
341 /* Functions from utils.c */
342 #include "common-utils.h"
344 void perror_with_name (const char *string
);
345 void error (const char *string
,...) ATTRIBUTE_NORETURN
ATTRIBUTE_PRINTF (1, 2);
346 void fatal (const char *string
,...) ATTRIBUTE_NORETURN
ATTRIBUTE_PRINTF (1, 2);
347 void warning (const char *string
,...) ATTRIBUTE_PRINTF (1, 2);
348 char *paddress (CORE_ADDR addr
);
349 char *pulongest (ULONGEST u
);
350 char *plongest (LONGEST l
);
351 char *phex_nz (ULONGEST l
, int sizeof_l
);
352 char *pfildes (gdb_fildes_t fd
);
354 #include "gdb_assert.h"
356 /* Maximum number of bytes to read/write at once. The value here
357 is chosen to fill up a packet (the headers account for the 32). */
358 #define MAXBUFBYTES(N) (((N)-32)/2)
360 /* Buffer sizes for transferring memory, registers, etc. Set to a constant
361 value to accomodate multiple register formats. This value must be at least
362 as large as the largest register set supported by gdbserver. */
363 #define PBUFSIZ 16384
365 /* Functions from tracepoint.c */
367 /* Size for a small buffer to report problems from the in-process
368 agent back to GDBserver. */
369 #define IPA_BUFSIZ 100
371 void initialize_tracepoint (void);
374 extern int disconnected_tracing
;
376 void tracepoint_look_up_symbols (void);
378 void stop_tracing (void);
380 int handle_tracepoint_general_set (char *own_buf
);
381 int handle_tracepoint_query (char *own_buf
);
383 int tracepoint_finished_step (struct thread_info
*tinfo
, CORE_ADDR stop_pc
);
384 int tracepoint_was_hit (struct thread_info
*tinfo
, CORE_ADDR stop_pc
);
386 void release_while_stepping_state_list (struct thread_info
*tinfo
);
388 extern int current_traceframe
;
390 int in_readonly_region (CORE_ADDR addr
, ULONGEST length
);
391 int traceframe_read_mem (int tfnum
, CORE_ADDR addr
,
392 unsigned char *buf
, ULONGEST length
,
394 int fetch_traceframe_registers (int tfnum
,
395 struct regcache
*regcache
,
398 int traceframe_read_sdata (int tfnum
, ULONGEST offset
,
399 unsigned char *buf
, ULONGEST length
,
402 int traceframe_read_info (int tfnum
, struct buffer
*buffer
);
404 /* If a thread is determined to be collecting a fast tracepoint, this
405 structure holds the collect status. */
407 struct fast_tpoint_collect_status
409 /* The tracepoint that is presently being collected. */
411 CORE_ADDR tpoint_addr
;
413 /* The address range in the jump pad of where the original
414 instruction the tracepoint jump was inserted was relocated
416 CORE_ADDR adjusted_insn_addr
;
417 CORE_ADDR adjusted_insn_addr_end
;
420 int fast_tracepoint_collecting (CORE_ADDR thread_area
,
422 struct fast_tpoint_collect_status
*status
);
423 void force_unlock_trace_buffer (void);
425 int handle_tracepoint_bkpts (struct thread_info
*tinfo
, CORE_ADDR stop_pc
);
427 #ifdef IN_PROCESS_AGENT
428 void initialize_low_tracepoint (void);
429 void supply_fast_tracepoint_registers (struct regcache
*regcache
,
430 const unsigned char *regs
);
431 void supply_static_tracepoint_registers (struct regcache
*regcache
,
432 const unsigned char *regs
,
434 void set_trampoline_buffer_space (CORE_ADDR begin
, CORE_ADDR end
,
437 void stop_tracing (void);
439 int claim_trampoline_space (ULONGEST used
, CORE_ADDR
*trampoline
);
440 int have_fast_tracepoint_trampoline_buffer (char *msgbuf
);
441 void gdb_agent_about_to_close (int pid
);
446 /* Do memory copies for bytecodes. */
447 /* Do the recording of memory blocks for actions and bytecodes. */
449 int agent_mem_read (struct traceframe
*tframe
,
450 unsigned char *to
, CORE_ADDR from
,
453 LONGEST
agent_get_trace_state_variable_value (int num
);
454 void agent_set_trace_state_variable_value (int num
, LONGEST val
);
456 /* Record the value of a trace state variable. */
458 int agent_tsv_read (struct traceframe
*tframe
, int n
);
459 int agent_mem_read_string (struct traceframe
*tframe
,
464 /* Bytecode compilation function vector. */
468 void (*emit_prologue
) (void);
469 void (*emit_epilogue
) (void);
470 void (*emit_add
) (void);
471 void (*emit_sub
) (void);
472 void (*emit_mul
) (void);
473 void (*emit_lsh
) (void);
474 void (*emit_rsh_signed
) (void);
475 void (*emit_rsh_unsigned
) (void);
476 void (*emit_ext
) (int arg
);
477 void (*emit_log_not
) (void);
478 void (*emit_bit_and
) (void);
479 void (*emit_bit_or
) (void);
480 void (*emit_bit_xor
) (void);
481 void (*emit_bit_not
) (void);
482 void (*emit_equal
) (void);
483 void (*emit_less_signed
) (void);
484 void (*emit_less_unsigned
) (void);
485 void (*emit_ref
) (int size
);
486 void (*emit_if_goto
) (int *offset_p
, int *size_p
);
487 void (*emit_goto
) (int *offset_p
, int *size_p
);
488 void (*write_goto_address
) (CORE_ADDR from
, CORE_ADDR to
, int size
);
489 void (*emit_const
) (LONGEST num
);
490 void (*emit_call
) (CORE_ADDR fn
);
491 void (*emit_reg
) (int reg
);
492 void (*emit_pop
) (void);
493 void (*emit_stack_flush
) (void);
494 void (*emit_zero_ext
) (int arg
);
495 void (*emit_swap
) (void);
496 void (*emit_stack_adjust
) (int n
);
498 /* Emit code for a generic function that takes one fixed integer
499 argument and returns a 64-bit int (for instance, tsv getter). */
500 void (*emit_int_call_1
) (CORE_ADDR fn
, int arg1
);
502 /* Emit code for a generic function that takes one fixed integer
503 argument and a 64-bit int from the top of the stack, and returns
504 nothing (for instance, tsv setter). */
505 void (*emit_void_call_2
) (CORE_ADDR fn
, int arg1
);
507 /* Emit code specialized for common combinations of compare followed
509 void (*emit_eq_goto
) (int *offset_p
, int *size_p
);
510 void (*emit_ne_goto
) (int *offset_p
, int *size_p
);
511 void (*emit_lt_goto
) (int *offset_p
, int *size_p
);
512 void (*emit_le_goto
) (int *offset_p
, int *size_p
);
513 void (*emit_gt_goto
) (int *offset_p
, int *size_p
);
514 void (*emit_ge_goto
) (int *offset_p
, int *size_p
);
517 /* Returns the address of the get_raw_reg function in the IPA. */
518 CORE_ADDR
get_raw_reg_func_addr (void);
519 /* Returns the address of the get_trace_state_variable_value
520 function in the IPA. */
521 CORE_ADDR
get_get_tsv_func_addr (void);
522 /* Returns the address of the set_trace_state_variable_value
523 function in the IPA. */
524 CORE_ADDR
get_set_tsv_func_addr (void);
526 CORE_ADDR current_insn_ptr
;
529 /* Version information, from version.c. */
530 extern const char version
[];
531 extern const char host_name
[];
533 #endif /* SERVER_H */