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);
262 extern void initialize_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 /* Functions from hostio.c. */
269 extern int handle_vFile (char *, int, int *);
271 /* Functions from hostio-errno.c. */
272 extern void hostio_last_error_from_errno (char *own_buf
);
274 /* From remote-utils.c */
276 extern int remote_debug
;
277 extern int noack_mode
;
278 extern int transport_is_reliable
;
280 int gdb_connected (void);
282 #define STDIO_CONNECTION_NAME "stdio"
283 int remote_connection_is_stdio (void);
285 ptid_t
read_ptid (char *buf
, char **obuf
);
286 char *write_ptid (char *buf
, ptid_t ptid
);
288 int putpkt (char *buf
);
289 int putpkt_binary (char *buf
, int len
);
290 int putpkt_notif (char *buf
);
291 int getpkt (char *buf
);
292 void remote_prepare (char *name
);
293 void remote_open (char *name
);
294 void remote_close (void);
295 void write_ok (char *buf
);
296 void write_enn (char *buf
);
297 void initialize_async_io (void);
298 void enable_async_io (void);
299 void disable_async_io (void);
300 void check_remote_input_interrupt_request (void);
301 void convert_ascii_to_int (const char *from
, unsigned char *to
, int n
);
302 void convert_int_to_ascii (const unsigned char *from
, char *to
, int n
);
303 void new_thread_notify (int id
);
304 void dead_thread_notify (int id
);
305 void prepare_resume_reply (char *buf
, ptid_t ptid
,
306 struct target_waitstatus
*status
);
308 const char *decode_address_to_semicolon (CORE_ADDR
*addrp
, const char *start
);
309 void decode_address (CORE_ADDR
*addrp
, const char *start
, int len
);
310 void decode_m_packet (char *from
, CORE_ADDR
* mem_addr_ptr
,
311 unsigned int *len_ptr
);
312 void decode_M_packet (char *from
, CORE_ADDR
* mem_addr_ptr
,
313 unsigned int *len_ptr
, unsigned char **to_p
);
314 int decode_X_packet (char *from
, int packet_len
, CORE_ADDR
* mem_addr_ptr
,
315 unsigned int *len_ptr
, unsigned char **to_p
);
316 int decode_xfer_write (char *buf
, int packet_len
,
317 CORE_ADDR
*offset
, unsigned int *len
,
318 unsigned char *data
);
319 int decode_search_memory_packet (const char *buf
, int packet_len
,
320 CORE_ADDR
*start_addrp
,
321 CORE_ADDR
*search_space_lenp
,
323 unsigned int *pattern_lenp
);
325 int unhexify (char *bin
, const char *hex
, int count
);
326 int hexify (char *hex
, const char *bin
, int count
);
327 int remote_escape_output (const gdb_byte
*buffer
, int len
,
328 gdb_byte
*out_buf
, int *out_len
,
330 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
332 void clear_symbol_cache (struct sym_cache
**symcache_p
);
333 int look_up_one_symbol (const char *name
, CORE_ADDR
*addrp
, int may_ask_gdb
);
335 int relocate_instruction (CORE_ADDR
*to
, CORE_ADDR oldloc
);
337 void monitor_output (const char *msg
);
339 /* Functions from utils.c */
340 #include "common-utils.h"
342 void perror_with_name (const char *string
);
343 void error (const char *string
,...) ATTRIBUTE_NORETURN
ATTRIBUTE_PRINTF (1, 2);
344 void fatal (const char *string
,...) ATTRIBUTE_NORETURN
ATTRIBUTE_PRINTF (1, 2);
345 void warning (const char *string
,...) ATTRIBUTE_PRINTF (1, 2);
346 char *paddress (CORE_ADDR addr
);
347 char *pulongest (ULONGEST u
);
348 char *plongest (LONGEST l
);
349 char *phex_nz (ULONGEST l
, int sizeof_l
);
350 char *pfildes (gdb_fildes_t fd
);
352 #include "gdb_assert.h"
354 /* Maximum number of bytes to read/write at once. The value here
355 is chosen to fill up a packet (the headers account for the 32). */
356 #define MAXBUFBYTES(N) (((N)-32)/2)
358 /* Buffer sizes for transferring memory, registers, etc. Set to a constant
359 value to accomodate multiple register formats. This value must be at least
360 as large as the largest register set supported by gdbserver. */
361 #define PBUFSIZ 16384
363 /* Functions from tracepoint.c */
365 /* Size for a small buffer to report problems from the in-process
366 agent back to GDBserver. */
367 #define IPA_BUFSIZ 100
369 void initialize_tracepoint (void);
372 extern int disconnected_tracing
;
374 void tracepoint_look_up_symbols (void);
376 void stop_tracing (void);
378 int handle_tracepoint_general_set (char *own_buf
);
379 int handle_tracepoint_query (char *own_buf
);
381 int tracepoint_finished_step (struct thread_info
*tinfo
, CORE_ADDR stop_pc
);
382 int tracepoint_was_hit (struct thread_info
*tinfo
, CORE_ADDR stop_pc
);
384 void release_while_stepping_state_list (struct thread_info
*tinfo
);
386 extern int current_traceframe
;
388 int in_readonly_region (CORE_ADDR addr
, ULONGEST length
);
389 int traceframe_read_mem (int tfnum
, CORE_ADDR addr
,
390 unsigned char *buf
, ULONGEST length
,
392 int fetch_traceframe_registers (int tfnum
,
393 struct regcache
*regcache
,
396 int traceframe_read_sdata (int tfnum
, ULONGEST offset
,
397 unsigned char *buf
, ULONGEST length
,
400 int traceframe_read_info (int tfnum
, struct buffer
*buffer
);
402 /* If a thread is determined to be collecting a fast tracepoint, this
403 structure holds the collect status. */
405 struct fast_tpoint_collect_status
407 /* The tracepoint that is presently being collected. */
409 CORE_ADDR tpoint_addr
;
411 /* The address range in the jump pad of where the original
412 instruction the tracepoint jump was inserted was relocated
414 CORE_ADDR adjusted_insn_addr
;
415 CORE_ADDR adjusted_insn_addr_end
;
418 int fast_tracepoint_collecting (CORE_ADDR thread_area
,
420 struct fast_tpoint_collect_status
*status
);
421 void force_unlock_trace_buffer (void);
423 int handle_tracepoint_bkpts (struct thread_info
*tinfo
, CORE_ADDR stop_pc
);
425 #ifdef IN_PROCESS_AGENT
426 void initialize_low_tracepoint (void);
427 void supply_fast_tracepoint_registers (struct regcache
*regcache
,
428 const unsigned char *regs
);
429 void supply_static_tracepoint_registers (struct regcache
*regcache
,
430 const unsigned char *regs
,
432 void set_trampoline_buffer_space (CORE_ADDR begin
, CORE_ADDR end
,
435 void stop_tracing (void);
437 int claim_trampoline_space (ULONGEST used
, CORE_ADDR
*trampoline
);
438 int have_fast_tracepoint_trampoline_buffer (char *msgbuf
);
439 void gdb_agent_about_to_close (int pid
);
443 struct eval_agent_expr_context
;
445 /* Do memory copies for bytecodes. */
446 /* Do the recording of memory blocks for actions and bytecodes. */
448 int agent_mem_read (struct eval_agent_expr_context
*ctx
,
449 unsigned char *to
, CORE_ADDR from
,
452 LONGEST
agent_get_trace_state_variable_value (int num
);
453 void agent_set_trace_state_variable_value (int num
, LONGEST val
);
455 /* Record the value of a trace state variable. */
457 int agent_tsv_read (struct eval_agent_expr_context
*ctx
, int n
);
458 int agent_mem_read_string (struct eval_agent_expr_context
*ctx
,
463 /* Bytecode compilation function vector. */
467 void (*emit_prologue
) (void);
468 void (*emit_epilogue
) (void);
469 void (*emit_add
) (void);
470 void (*emit_sub
) (void);
471 void (*emit_mul
) (void);
472 void (*emit_lsh
) (void);
473 void (*emit_rsh_signed
) (void);
474 void (*emit_rsh_unsigned
) (void);
475 void (*emit_ext
) (int arg
);
476 void (*emit_log_not
) (void);
477 void (*emit_bit_and
) (void);
478 void (*emit_bit_or
) (void);
479 void (*emit_bit_xor
) (void);
480 void (*emit_bit_not
) (void);
481 void (*emit_equal
) (void);
482 void (*emit_less_signed
) (void);
483 void (*emit_less_unsigned
) (void);
484 void (*emit_ref
) (int size
);
485 void (*emit_if_goto
) (int *offset_p
, int *size_p
);
486 void (*emit_goto
) (int *offset_p
, int *size_p
);
487 void (*write_goto_address
) (CORE_ADDR from
, CORE_ADDR to
, int size
);
488 void (*emit_const
) (LONGEST num
);
489 void (*emit_call
) (CORE_ADDR fn
);
490 void (*emit_reg
) (int reg
);
491 void (*emit_pop
) (void);
492 void (*emit_stack_flush
) (void);
493 void (*emit_zero_ext
) (int arg
);
494 void (*emit_swap
) (void);
495 void (*emit_stack_adjust
) (int n
);
497 /* Emit code for a generic function that takes one fixed integer
498 argument and returns a 64-bit int (for instance, tsv getter). */
499 void (*emit_int_call_1
) (CORE_ADDR fn
, int arg1
);
501 /* Emit code for a generic function that takes one fixed integer
502 argument and a 64-bit int from the top of the stack, and returns
503 nothing (for instance, tsv setter). */
504 void (*emit_void_call_2
) (CORE_ADDR fn
, int arg1
);
506 /* Emit code specialized for common combinations of compare followed
508 void (*emit_eq_goto
) (int *offset_p
, int *size_p
);
509 void (*emit_ne_goto
) (int *offset_p
, int *size_p
);
510 void (*emit_lt_goto
) (int *offset_p
, int *size_p
);
511 void (*emit_le_goto
) (int *offset_p
, int *size_p
);
512 void (*emit_gt_goto
) (int *offset_p
, int *size_p
);
513 void (*emit_ge_goto
) (int *offset_p
, int *size_p
);
516 /* Returns the address of the get_raw_reg function in the IPA. */
517 CORE_ADDR
get_raw_reg_func_addr (void);
518 /* Returns the address of the get_trace_state_variable_value
519 function in the IPA. */
520 CORE_ADDR
get_get_tsv_func_addr (void);
521 /* Returns the address of the set_trace_state_variable_value
522 function in the IPA. */
523 CORE_ADDR
get_set_tsv_func_addr (void);
525 extern CORE_ADDR current_insn_ptr
;
526 extern int emit_error
;
528 /* Version information, from version.c. */
529 extern const char version
[];
530 extern const char host_name
[];
532 #endif /* SERVER_H */