opcodes/
[binutils-gdb.git] / gdb / gdbserver / server.h
1 /* Common definitions for remote server for GDB.
2 Copyright (C) 1993-2013 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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/>. */
18
19 #ifndef SERVER_H
20 #define SERVER_H
21
22 #include "config.h"
23 #include "build-gnulib-gdbserver/config.h"
24
25 #ifdef __MINGW32CE__
26 #include "wincecompat.h"
27 #endif
28
29 #include "libiberty.h"
30 #include "ansidecl.h"
31 #include "version.h"
32
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #ifdef HAVE_ERRNO_H
37 #include <errno.h>
38 #endif
39 #include <setjmp.h>
40
41 /* For gnulib's PATH_MAX. */
42 #include "pathmax.h"
43
44 #ifdef HAVE_STRING_H
45 #include <string.h>
46 #endif
47
48 #ifdef HAVE_ALLOCA_H
49 #include <alloca.h>
50 #endif
51 /* On some systems such as MinGW, alloca is declared in malloc.h
52 (there is no alloca.h). */
53 #if HAVE_MALLOC_H
54 #include <malloc.h>
55 #endif
56
57 #if !HAVE_DECL_STRERROR
58 #ifndef strerror
59 extern char *strerror (int); /* X3.159-1989 4.11.6.2 */
60 #endif
61 #endif
62
63 #if !HAVE_DECL_PERROR
64 #ifndef perror
65 extern void perror (const char *);
66 #endif
67 #endif
68
69 #if !HAVE_DECL_VASPRINTF
70 extern int vasprintf(char **strp, const char *fmt, va_list ap);
71 #endif
72 #if !HAVE_DECL_VSNPRINTF
73 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
74 #endif
75
76 /* Define underscore macro, if not available, to be able to use it inside
77 code shared with gdb in common directory. */
78 #ifndef _
79 #define _(String) (String)
80 #endif
81
82 #ifdef IN_PROCESS_AGENT
83 # define PROG "ipa"
84 #else
85 # define PROG "gdbserver"
86 #endif
87
88 /* A type used for binary buffers. */
89 typedef unsigned char gdb_byte;
90
91 #include "ptid.h"
92 #include "buffer.h"
93 #include "xml-utils.h"
94 #include "gdb_locale.h"
95
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;
99
100 typedef long long LONGEST;
101 typedef unsigned long long ULONGEST;
102
103 /* Generic information for tracking a list of ``inferiors'' - threads,
104 processes, etc. */
105 struct inferior_list
106 {
107 struct inferior_list_entry *head;
108 struct inferior_list_entry *tail;
109 };
110 struct inferior_list_entry
111 {
112 ptid_t id;
113 struct inferior_list_entry *next;
114 };
115
116 struct thread_info;
117 struct process_info;
118 struct regcache;
119 struct target_desc;
120
121 #include "regcache.h"
122 #include "gdb/signals.h"
123 #include "gdb_signals.h"
124 #include "target.h"
125 #include "mem-break.h"
126 #include "gdbthread.h"
127
128 struct dll_info
129 {
130 struct inferior_list_entry entry;
131 char *name;
132 CORE_ADDR base_addr;
133 };
134
135 struct sym_cache;
136 struct breakpoint;
137 struct raw_breakpoint;
138 struct fast_tracepoint_jump;
139 struct process_info_private;
140
141 struct process_info
142 {
143 struct inferior_list_entry head;
144
145 /* Nonzero if this child process was attached rather than
146 spawned. */
147 int attached;
148
149 /* True if GDB asked us to detach from this process, but we remained
150 attached anyway. */
151 int gdb_detached;
152
153 /* The symbol cache. */
154 struct sym_cache *symbol_cache;
155
156 /* The list of memory breakpoints. */
157 struct breakpoint *breakpoints;
158
159 /* The list of raw memory breakpoints. */
160 struct raw_breakpoint *raw_breakpoints;
161
162 /* The list of installed fast tracepoints. */
163 struct fast_tracepoint_jump *fast_tracepoint_jumps;
164
165 const struct target_desc *tdesc;
166
167 /* Private target data. */
168 struct process_info_private *private;
169 };
170
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. */
174
175 struct process_info *current_process (void);
176 struct process_info *get_thread_process (struct thread_info *);
177
178 /* Target-specific functions */
179
180 void initialize_low ();
181
182 /* From inferiors.c. */
183
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);
188
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 *));
193
194 extern struct thread_info *current_inferior;
195 void remove_inferior (struct inferior_list *list,
196 struct inferior_list_entry *entry);
197
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);
203
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);
207
208 void clear_inferiors (void);
209 struct inferior_list_entry *find_inferior
210 (struct inferior_list *,
211 int (*func) (struct inferior_list_entry *,
212 void *),
213 void *arg);
214 struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
215 ptid_t id);
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 *);
220
221 void loaded_dll (const char *name, CORE_ADDR base_addr);
222 void unloaded_dll (const char *name, CORE_ADDR base_addr);
223
224 /* Public variables in server.c */
225
226 extern ptid_t cont_thread;
227 extern ptid_t general_thread;
228
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;
235
236 extern jmp_buf toplevel;
237
238 extern int disable_packet_vCont;
239 extern int disable_packet_Tthread;
240 extern int disable_packet_qC;
241 extern int disable_packet_qfThreadInfo;
242
243 extern int run_once;
244 extern int multi_process;
245 extern int non_stop;
246
247 extern int disable_randomization;
248
249 #if USE_WIN32API
250 #include <winsock2.h>
251 typedef SOCKET gdb_fildes_t;
252 #else
253 typedef int gdb_fildes_t;
254 #endif
255
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);
260
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);
267
268 extern void start_event_loop (void);
269 extern void initialize_event_loop (void);
270
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);
274
275 /* Functions from hostio.c. */
276 extern int handle_vFile (char *, int, int *);
277
278 /* Functions from hostio-errno.c. */
279 extern void hostio_last_error_from_errno (char *own_buf);
280
281 /* From remote-utils.c */
282
283 extern int remote_debug;
284 extern int noack_mode;
285 extern int transport_is_reliable;
286
287 int gdb_connected (void);
288
289 #define STDIO_CONNECTION_NAME "stdio"
290 int remote_connection_is_stdio (void);
291
292 ptid_t read_ptid (char *buf, char **obuf);
293 char *write_ptid (char *buf, ptid_t ptid);
294
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);
314
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,
329 gdb_byte *pattern,
330 unsigned int *pattern_lenp);
331
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,
336 int out_maxlen);
337 char *unpack_varlen_hex (char *buff, ULONGEST *result);
338
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);
341
342 int relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc);
343
344 void monitor_output (const char *msg);
345
346 /* Functions from utils.c */
347 #include "common-utils.h"
348
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);
358
359 #include "gdb_assert.h"
360
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)
364
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
369
370 /* Functions from tracepoint.c */
371
372 /* Size for a small buffer to report problems from the in-process
373 agent back to GDBserver. */
374 #define IPA_BUFSIZ 100
375
376 void initialize_tracepoint (void);
377
378 extern int tracing;
379 extern int disconnected_tracing;
380
381 void tracepoint_look_up_symbols (void);
382
383 void stop_tracing (void);
384
385 int handle_tracepoint_general_set (char *own_buf);
386 int handle_tracepoint_query (char *own_buf);
387
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);
390
391 void release_while_stepping_state_list (struct thread_info *tinfo);
392
393 extern int current_traceframe;
394
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,
398 ULONGEST *nbytes);
399 int fetch_traceframe_registers (int tfnum,
400 struct regcache *regcache,
401 int regnum);
402
403 int traceframe_read_sdata (int tfnum, ULONGEST offset,
404 unsigned char *buf, ULONGEST length,
405 ULONGEST *nbytes);
406
407 int traceframe_read_info (int tfnum, struct buffer *buffer);
408
409 /* If a thread is determined to be collecting a fast tracepoint, this
410 structure holds the collect status. */
411
412 struct fast_tpoint_collect_status
413 {
414 /* The tracepoint that is presently being collected. */
415 int tpoint_num;
416 CORE_ADDR tpoint_addr;
417
418 /* The address range in the jump pad of where the original
419 instruction the tracepoint jump was inserted was relocated
420 to. */
421 CORE_ADDR adjusted_insn_addr;
422 CORE_ADDR adjusted_insn_addr_end;
423 };
424
425 int fast_tracepoint_collecting (CORE_ADDR thread_area,
426 CORE_ADDR stop_pc,
427 struct fast_tpoint_collect_status *status);
428 void force_unlock_trace_buffer (void);
429
430 int handle_tracepoint_bkpts (struct thread_info *tinfo, CORE_ADDR stop_pc);
431
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,
438 CORE_ADDR pc);
439 void set_trampoline_buffer_space (CORE_ADDR begin, CORE_ADDR end,
440 char *errmsg);
441
442 extern const struct target_desc *ipa_tdesc;
443
444 #else
445 void stop_tracing (void);
446
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);
450 #endif
451
452 struct traceframe;
453 struct eval_agent_expr_context;
454
455 /* Do memory copies for bytecodes. */
456 /* Do the recording of memory blocks for actions and bytecodes. */
457
458 int agent_mem_read (struct eval_agent_expr_context *ctx,
459 unsigned char *to, CORE_ADDR from,
460 ULONGEST len);
461
462 LONGEST agent_get_trace_state_variable_value (int num);
463 void agent_set_trace_state_variable_value (int num, LONGEST val);
464
465 /* Record the value of a trace state variable. */
466
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,
469 unsigned char *to,
470 CORE_ADDR from,
471 ULONGEST len);
472
473 /* Bytecode compilation function vector. */
474
475 struct emit_ops
476 {
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);
506
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);
510
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);
515
516 /* Emit code specialized for common combinations of compare followed
517 by a goto. */
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);
524 };
525
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);
534
535 extern CORE_ADDR current_insn_ptr;
536 extern int emit_error;
537
538 #endif /* SERVER_H */