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"
47 /* On some systems such as MinGW, alloca is declared in malloc.h
48 (there is no alloca.h). */
53 #if !HAVE_DECL_STRERROR
55 extern char *strerror (int); /* X3.159-1989 4.11.6.2 */
61 extern void perror (const char *);
65 #if !HAVE_DECL_VASPRINTF
66 extern int vasprintf(char **strp
, const char *fmt
, va_list ap
);
68 #if !HAVE_DECL_VSNPRINTF
69 int vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
);
72 /* Define underscore macro, if not available, to be able to use it inside
73 code shared with gdb in common directory. */
75 #define _(String) (String)
78 #ifdef IN_PROCESS_AGENT
81 # define PROG "gdbserver"
84 /* A type used for binary buffers. */
85 typedef unsigned char gdb_byte
;
89 #include "xml-utils.h"
90 #include "gdb_locale.h"
92 /* FIXME: This should probably be autoconf'd for. It's an integer type at
93 least the size of a (void *). */
94 typedef long long CORE_ADDR
;
96 typedef long long LONGEST
;
97 typedef unsigned long long ULONGEST
;
99 /* Generic information for tracking a list of ``inferiors'' - threads,
103 struct inferior_list_entry
*head
;
104 struct inferior_list_entry
*tail
;
106 struct inferior_list_entry
109 struct inferior_list_entry
*next
;
116 #include "regcache.h"
117 #include "gdb/signals.h"
118 #include "gdb_signals.h"
120 #include "mem-break.h"
121 #include "gdbthread.h"
125 struct inferior_list_entry entry
;
132 struct raw_breakpoint
;
133 struct fast_tracepoint_jump
;
134 struct process_info_private
;
138 struct inferior_list_entry head
;
140 /* Nonzero if this child process was attached rather than
144 /* True if GDB asked us to detach from this process, but we remained
148 /* The symbol cache. */
149 struct sym_cache
*symbol_cache
;
151 /* The list of memory breakpoints. */
152 struct breakpoint
*breakpoints
;
154 /* The list of raw memory breakpoints. */
155 struct raw_breakpoint
*raw_breakpoints
;
157 /* The list of installed fast tracepoints. */
158 struct fast_tracepoint_jump
*fast_tracepoint_jumps
;
160 /* Private target data. */
161 struct process_info_private
*private;
164 /* Return a pointer to the process that corresponds to the current
165 thread (current_inferior). It is an error to call this if there is
166 no current thread selected. */
168 struct process_info
*current_process (void);
169 struct process_info
*get_thread_process (struct thread_info
*);
171 /* Target-specific functions */
173 void initialize_low ();
175 /* From inferiors.c. */
177 extern struct inferior_list all_processes
;
178 extern struct inferior_list all_dlls
;
179 extern int dlls_changed
;
180 extern void clear_dlls (void);
182 void add_inferior_to_list (struct inferior_list
*list
,
183 struct inferior_list_entry
*new_inferior
);
184 void for_each_inferior (struct inferior_list
*list
,
185 void (*action
) (struct inferior_list_entry
*));
187 extern struct thread_info
*current_inferior
;
188 void remove_inferior (struct inferior_list
*list
,
189 struct inferior_list_entry
*entry
);
191 struct process_info
*add_process (int pid
, int attached
);
192 void remove_process (struct process_info
*process
);
193 struct process_info
*find_process_pid (int pid
);
194 int have_started_inferiors_p (void);
195 int have_attached_inferiors_p (void);
197 ptid_t
thread_id_to_gdb_id (ptid_t
);
198 ptid_t
thread_to_gdb_id (struct thread_info
*);
199 ptid_t
gdb_id_to_thread_id (ptid_t
);
201 void clear_inferiors (void);
202 struct inferior_list_entry
*find_inferior
203 (struct inferior_list
*,
204 int (*func
) (struct inferior_list_entry
*,
207 struct inferior_list_entry
*find_inferior_id (struct inferior_list
*list
,
209 void *inferior_target_data (struct thread_info
*);
210 void set_inferior_target_data (struct thread_info
*, void *);
211 void *inferior_regcache_data (struct thread_info
*);
212 void set_inferior_regcache_data (struct thread_info
*, void *);
214 void loaded_dll (const char *name
, CORE_ADDR base_addr
);
215 void unloaded_dll (const char *name
, CORE_ADDR base_addr
);
217 /* Public variables in server.c */
219 extern ptid_t cont_thread
;
220 extern ptid_t general_thread
;
222 extern int server_waiting
;
223 extern int debug_threads
;
224 extern int debug_hw_points
;
225 extern int pass_signals
[];
226 extern int program_signals
[];
227 extern int program_signals_p
;
229 extern jmp_buf toplevel
;
231 extern int disable_packet_vCont
;
232 extern int disable_packet_Tthread
;
233 extern int disable_packet_qC
;
234 extern int disable_packet_qfThreadInfo
;
237 extern int multi_process
;
240 extern int disable_randomization
;
243 #include <winsock2.h>
244 typedef SOCKET gdb_fildes_t
;
246 typedef int gdb_fildes_t
;
249 /* Functions from event-loop.c. */
250 typedef void *gdb_client_data
;
251 typedef int (handler_func
) (int, gdb_client_data
);
252 typedef int (callback_handler_func
) (gdb_client_data
);
254 extern void delete_file_handler (gdb_fildes_t fd
);
255 extern void add_file_handler (gdb_fildes_t fd
, handler_func
*proc
,
256 gdb_client_data client_data
);
257 extern int append_callback_event (callback_handler_func
*proc
,
258 gdb_client_data client_data
);
259 extern void delete_callback_event (int id
);
261 extern void start_event_loop (void);
263 /* Functions from server.c. */
264 extern int handle_serial_event (int err
, gdb_client_data client_data
);
265 extern int handle_target_event (int err
, gdb_client_data client_data
);
267 /* Functions from hostio.c. */
268 extern int handle_vFile (char *, int, int *);
270 /* Functions from hostio-errno.c. */
271 extern void hostio_last_error_from_errno (char *own_buf
);
273 /* From remote-utils.c */
275 extern int remote_debug
;
276 extern int noack_mode
;
277 extern int transport_is_reliable
;
279 int gdb_connected (void);
281 #define STDIO_CONNECTION_NAME "stdio"
282 int remote_connection_is_stdio (void);
284 ptid_t
read_ptid (char *buf
, char **obuf
);
285 char *write_ptid (char *buf
, ptid_t ptid
);
287 int putpkt (char *buf
);
288 int putpkt_binary (char *buf
, int len
);
289 int putpkt_notif (char *buf
);
290 int getpkt (char *buf
);
291 void remote_prepare (char *name
);
292 void remote_open (char *name
);
293 void remote_close (void);
294 void write_ok (char *buf
);
295 void write_enn (char *buf
);
296 void initialize_async_io (void);
297 void enable_async_io (void);
298 void disable_async_io (void);
299 void check_remote_input_interrupt_request (void);
300 void convert_ascii_to_int (const char *from
, unsigned char *to
, int n
);
301 void convert_int_to_ascii (const unsigned char *from
, char *to
, int n
);
302 void new_thread_notify (int id
);
303 void dead_thread_notify (int id
);
304 void prepare_resume_reply (char *buf
, ptid_t ptid
,
305 struct target_waitstatus
*status
);
307 const char *decode_address_to_semicolon (CORE_ADDR
*addrp
, const char *start
);
308 void decode_address (CORE_ADDR
*addrp
, const char *start
, int len
);
309 void decode_m_packet (char *from
, CORE_ADDR
* mem_addr_ptr
,
310 unsigned int *len_ptr
);
311 void decode_M_packet (char *from
, CORE_ADDR
* mem_addr_ptr
,
312 unsigned int *len_ptr
, unsigned char **to_p
);
313 int decode_X_packet (char *from
, int packet_len
, CORE_ADDR
* mem_addr_ptr
,
314 unsigned int *len_ptr
, unsigned char **to_p
);
315 int decode_xfer_write (char *buf
, int packet_len
,
316 CORE_ADDR
*offset
, unsigned int *len
,
317 unsigned char *data
);
318 int decode_search_memory_packet (const char *buf
, int packet_len
,
319 CORE_ADDR
*start_addrp
,
320 CORE_ADDR
*search_space_lenp
,
322 unsigned int *pattern_lenp
);
324 int unhexify (char *bin
, const char *hex
, int count
);
325 int hexify (char *hex
, const char *bin
, int count
);
326 int remote_escape_output (const gdb_byte
*buffer
, int len
,
327 gdb_byte
*out_buf
, int *out_len
,
329 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
331 void clear_symbol_cache (struct sym_cache
**symcache_p
);
332 int look_up_one_symbol (const char *name
, CORE_ADDR
*addrp
, int may_ask_gdb
);
334 int relocate_instruction (CORE_ADDR
*to
, CORE_ADDR oldloc
);
336 void monitor_output (const char *msg
);
338 /* Functions from utils.c */
339 #include "common-utils.h"
341 void perror_with_name (const char *string
);
342 void error (const char *string
,...) ATTRIBUTE_NORETURN
ATTRIBUTE_PRINTF (1, 2);
343 void fatal (const char *string
,...) ATTRIBUTE_NORETURN
ATTRIBUTE_PRINTF (1, 2);
344 void warning (const char *string
,...) ATTRIBUTE_PRINTF (1, 2);
345 char *paddress (CORE_ADDR addr
);
346 char *pulongest (ULONGEST u
);
347 char *plongest (LONGEST l
);
348 char *phex_nz (ULONGEST l
, int sizeof_l
);
349 char *pfildes (gdb_fildes_t fd
);
351 #include "gdb_assert.h"
353 /* Maximum number of bytes to read/write at once. The value here
354 is chosen to fill up a packet (the headers account for the 32). */
355 #define MAXBUFBYTES(N) (((N)-32)/2)
357 /* Buffer sizes for transferring memory, registers, etc. Set to a constant
358 value to accomodate multiple register formats. This value must be at least
359 as large as the largest register set supported by gdbserver. */
360 #define PBUFSIZ 16384
362 /* Functions from tracepoint.c */
364 /* Size for a small buffer to report problems from the in-process
365 agent back to GDBserver. */
366 #define IPA_BUFSIZ 100
368 void initialize_tracepoint (void);
371 extern int disconnected_tracing
;
373 void tracepoint_look_up_symbols (void);
375 void stop_tracing (void);
377 int handle_tracepoint_general_set (char *own_buf
);
378 int handle_tracepoint_query (char *own_buf
);
380 int tracepoint_finished_step (struct thread_info
*tinfo
, CORE_ADDR stop_pc
);
381 int tracepoint_was_hit (struct thread_info
*tinfo
, CORE_ADDR stop_pc
);
383 void release_while_stepping_state_list (struct thread_info
*tinfo
);
385 extern int current_traceframe
;
387 int in_readonly_region (CORE_ADDR addr
, ULONGEST length
);
388 int traceframe_read_mem (int tfnum
, CORE_ADDR addr
,
389 unsigned char *buf
, ULONGEST length
,
391 int fetch_traceframe_registers (int tfnum
,
392 struct regcache
*regcache
,
395 int traceframe_read_sdata (int tfnum
, ULONGEST offset
,
396 unsigned char *buf
, ULONGEST length
,
399 int traceframe_read_info (int tfnum
, struct buffer
*buffer
);
401 /* If a thread is determined to be collecting a fast tracepoint, this
402 structure holds the collect status. */
404 struct fast_tpoint_collect_status
406 /* The tracepoint that is presently being collected. */
408 CORE_ADDR tpoint_addr
;
410 /* The address range in the jump pad of where the original
411 instruction the tracepoint jump was inserted was relocated
413 CORE_ADDR adjusted_insn_addr
;
414 CORE_ADDR adjusted_insn_addr_end
;
417 int fast_tracepoint_collecting (CORE_ADDR thread_area
,
419 struct fast_tpoint_collect_status
*status
);
420 void force_unlock_trace_buffer (void);
422 int handle_tracepoint_bkpts (struct thread_info
*tinfo
, CORE_ADDR stop_pc
);
424 #ifdef IN_PROCESS_AGENT
425 void initialize_low_tracepoint (void);
426 void supply_fast_tracepoint_registers (struct regcache
*regcache
,
427 const unsigned char *regs
);
428 void supply_static_tracepoint_registers (struct regcache
*regcache
,
429 const unsigned char *regs
,
431 void set_trampoline_buffer_space (CORE_ADDR begin
, CORE_ADDR end
,
434 void stop_tracing (void);
436 int claim_trampoline_space (ULONGEST used
, CORE_ADDR
*trampoline
);
437 int have_fast_tracepoint_trampoline_buffer (char *msgbuf
);
438 void gdb_agent_about_to_close (int pid
);
442 struct eval_agent_expr_context
;
444 /* Do memory copies for bytecodes. */
445 /* Do the recording of memory blocks for actions and bytecodes. */
447 int agent_mem_read (struct eval_agent_expr_context
*ctx
,
448 unsigned char *to
, CORE_ADDR from
,
451 LONGEST
agent_get_trace_state_variable_value (int num
);
452 void agent_set_trace_state_variable_value (int num
, LONGEST val
);
454 /* Record the value of a trace state variable. */
456 int agent_tsv_read (struct eval_agent_expr_context
*ctx
, int n
);
457 int agent_mem_read_string (struct eval_agent_expr_context
*ctx
,
462 /* Bytecode compilation function vector. */
466 void (*emit_prologue
) (void);
467 void (*emit_epilogue
) (void);
468 void (*emit_add
) (void);
469 void (*emit_sub
) (void);
470 void (*emit_mul
) (void);
471 void (*emit_lsh
) (void);
472 void (*emit_rsh_signed
) (void);
473 void (*emit_rsh_unsigned
) (void);
474 void (*emit_ext
) (int arg
);
475 void (*emit_log_not
) (void);
476 void (*emit_bit_and
) (void);
477 void (*emit_bit_or
) (void);
478 void (*emit_bit_xor
) (void);
479 void (*emit_bit_not
) (void);
480 void (*emit_equal
) (void);
481 void (*emit_less_signed
) (void);
482 void (*emit_less_unsigned
) (void);
483 void (*emit_ref
) (int size
);
484 void (*emit_if_goto
) (int *offset_p
, int *size_p
);
485 void (*emit_goto
) (int *offset_p
, int *size_p
);
486 void (*write_goto_address
) (CORE_ADDR from
, CORE_ADDR to
, int size
);
487 void (*emit_const
) (LONGEST num
);
488 void (*emit_call
) (CORE_ADDR fn
);
489 void (*emit_reg
) (int reg
);
490 void (*emit_pop
) (void);
491 void (*emit_stack_flush
) (void);
492 void (*emit_zero_ext
) (int arg
);
493 void (*emit_swap
) (void);
494 void (*emit_stack_adjust
) (int n
);
496 /* Emit code for a generic function that takes one fixed integer
497 argument and returns a 64-bit int (for instance, tsv getter). */
498 void (*emit_int_call_1
) (CORE_ADDR fn
, int arg1
);
500 /* Emit code for a generic function that takes one fixed integer
501 argument and a 64-bit int from the top of the stack, and returns
502 nothing (for instance, tsv setter). */
503 void (*emit_void_call_2
) (CORE_ADDR fn
, int arg1
);
505 /* Emit code specialized for common combinations of compare followed
507 void (*emit_eq_goto
) (int *offset_p
, int *size_p
);
508 void (*emit_ne_goto
) (int *offset_p
, int *size_p
);
509 void (*emit_lt_goto
) (int *offset_p
, int *size_p
);
510 void (*emit_le_goto
) (int *offset_p
, int *size_p
);
511 void (*emit_gt_goto
) (int *offset_p
, int *size_p
);
512 void (*emit_ge_goto
) (int *offset_p
, int *size_p
);
515 /* Returns the address of the get_raw_reg function in the IPA. */
516 CORE_ADDR
get_raw_reg_func_addr (void);
517 /* Returns the address of the get_trace_state_variable_value
518 function in the IPA. */
519 CORE_ADDR
get_get_tsv_func_addr (void);
520 /* Returns the address of the set_trace_state_variable_value
521 function in the IPA. */
522 CORE_ADDR
get_set_tsv_func_addr (void);
524 extern CORE_ADDR current_insn_ptr
;
525 extern int emit_error
;
527 /* Version information, from version.c. */
528 extern const char version
[];
529 extern const char host_name
[];
531 #endif /* SERVER_H */