gdb/gdbserver:
[deliverable/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
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #ifdef HAVE_ERRNO_H
36 #include <errno.h>
37 #endif
38 #include <setjmp.h>
39
40 #ifdef HAVE_STRING_H
41 #include <string.h>
42 #endif
43
44 #ifdef HAVE_ALLOCA_H
45 #include <alloca.h>
46 #endif
47 /* On some systems such as MinGW, alloca is declared in malloc.h
48 (there is no alloca.h). */
49 #if HAVE_MALLOC_H
50 #include <malloc.h>
51 #endif
52
53 #if !HAVE_DECL_STRERROR
54 #ifndef strerror
55 extern char *strerror (int); /* X3.159-1989 4.11.6.2 */
56 #endif
57 #endif
58
59 #if !HAVE_DECL_PERROR
60 #ifndef perror
61 extern void perror (const char *);
62 #endif
63 #endif
64
65 #if !HAVE_DECL_VASPRINTF
66 extern int vasprintf(char **strp, const char *fmt, va_list ap);
67 #endif
68 #if !HAVE_DECL_VSNPRINTF
69 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
70 #endif
71
72 /* Define underscore macro, if not available, to be able to use it inside
73 code shared with gdb in common directory. */
74 #ifndef _
75 #define _(String) (String)
76 #endif
77
78 #ifdef IN_PROCESS_AGENT
79 # define PROG "ipa"
80 #else
81 # define PROG "gdbserver"
82 #endif
83
84 /* A type used for binary buffers. */
85 typedef unsigned char gdb_byte;
86
87 #include "ptid.h"
88 #include "buffer.h"
89 #include "xml-utils.h"
90 #include "gdb_locale.h"
91
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;
95
96 typedef long long LONGEST;
97 typedef unsigned long long ULONGEST;
98
99 /* Generic information for tracking a list of ``inferiors'' - threads,
100 processes, etc. */
101 struct inferior_list
102 {
103 struct inferior_list_entry *head;
104 struct inferior_list_entry *tail;
105 };
106 struct inferior_list_entry
107 {
108 ptid_t id;
109 struct inferior_list_entry *next;
110 };
111
112 struct thread_info;
113 struct process_info;
114 struct regcache;
115
116 #include "regcache.h"
117 #include "gdb/signals.h"
118 #include "gdb_signals.h"
119 #include "target.h"
120 #include "mem-break.h"
121 #include "gdbthread.h"
122
123 struct dll_info
124 {
125 struct inferior_list_entry entry;
126 char *name;
127 CORE_ADDR base_addr;
128 };
129
130 struct sym_cache;
131 struct breakpoint;
132 struct raw_breakpoint;
133 struct fast_tracepoint_jump;
134 struct process_info_private;
135
136 struct process_info
137 {
138 struct inferior_list_entry head;
139
140 /* Nonzero if this child process was attached rather than
141 spawned. */
142 int attached;
143
144 /* True if GDB asked us to detach from this process, but we remained
145 attached anyway. */
146 int gdb_detached;
147
148 /* The symbol cache. */
149 struct sym_cache *symbol_cache;
150
151 /* The list of memory breakpoints. */
152 struct breakpoint *breakpoints;
153
154 /* The list of raw memory breakpoints. */
155 struct raw_breakpoint *raw_breakpoints;
156
157 /* The list of installed fast tracepoints. */
158 struct fast_tracepoint_jump *fast_tracepoint_jumps;
159
160 /* Private target data. */
161 struct process_info_private *private;
162 };
163
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. */
167
168 struct process_info *current_process (void);
169 struct process_info *get_thread_process (struct thread_info *);
170
171 /* Target-specific functions */
172
173 void initialize_low ();
174
175 /* From inferiors.c. */
176
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);
181
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 *));
186
187 extern struct thread_info *current_inferior;
188 void remove_inferior (struct inferior_list *list,
189 struct inferior_list_entry *entry);
190
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);
196
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);
200
201 void clear_inferiors (void);
202 struct inferior_list_entry *find_inferior
203 (struct inferior_list *,
204 int (*func) (struct inferior_list_entry *,
205 void *),
206 void *arg);
207 struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
208 ptid_t id);
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 *);
213
214 void loaded_dll (const char *name, CORE_ADDR base_addr);
215 void unloaded_dll (const char *name, CORE_ADDR base_addr);
216
217 /* Public variables in server.c */
218
219 extern ptid_t cont_thread;
220 extern ptid_t general_thread;
221
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;
228
229 extern jmp_buf toplevel;
230
231 extern int disable_packet_vCont;
232 extern int disable_packet_Tthread;
233 extern int disable_packet_qC;
234 extern int disable_packet_qfThreadInfo;
235
236 extern int run_once;
237 extern int multi_process;
238 extern int non_stop;
239
240 extern int disable_randomization;
241
242 #if USE_WIN32API
243 #include <winsock2.h>
244 typedef SOCKET gdb_fildes_t;
245 #else
246 typedef int gdb_fildes_t;
247 #endif
248
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);
253
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);
260
261 extern void start_event_loop (void);
262
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);
266
267 /* Functions from hostio.c. */
268 extern int handle_vFile (char *, int, int *);
269
270 /* Functions from hostio-errno.c. */
271 extern void hostio_last_error_from_errno (char *own_buf);
272
273 /* From remote-utils.c */
274
275 extern int remote_debug;
276 extern int noack_mode;
277 extern int transport_is_reliable;
278
279 int gdb_connected (void);
280
281 #define STDIO_CONNECTION_NAME "stdio"
282 int remote_connection_is_stdio (void);
283
284 ptid_t read_ptid (char *buf, char **obuf);
285 char *write_ptid (char *buf, ptid_t ptid);
286
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);
306
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,
321 gdb_byte *pattern,
322 unsigned int *pattern_lenp);
323
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,
328 int out_maxlen);
329 char *unpack_varlen_hex (char *buff, ULONGEST *result);
330
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);
333
334 int relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc);
335
336 void monitor_output (const char *msg);
337
338 /* Functions from utils.c */
339 #include "common-utils.h"
340
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);
350
351 #include "gdb_assert.h"
352
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)
356
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
361
362 /* Functions from tracepoint.c */
363
364 /* Size for a small buffer to report problems from the in-process
365 agent back to GDBserver. */
366 #define IPA_BUFSIZ 100
367
368 void initialize_tracepoint (void);
369
370 extern int tracing;
371 extern int disconnected_tracing;
372
373 void tracepoint_look_up_symbols (void);
374
375 void stop_tracing (void);
376
377 int handle_tracepoint_general_set (char *own_buf);
378 int handle_tracepoint_query (char *own_buf);
379
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);
382
383 void release_while_stepping_state_list (struct thread_info *tinfo);
384
385 extern int current_traceframe;
386
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,
390 ULONGEST *nbytes);
391 int fetch_traceframe_registers (int tfnum,
392 struct regcache *regcache,
393 int regnum);
394
395 int traceframe_read_sdata (int tfnum, ULONGEST offset,
396 unsigned char *buf, ULONGEST length,
397 ULONGEST *nbytes);
398
399 int traceframe_read_info (int tfnum, struct buffer *buffer);
400
401 /* If a thread is determined to be collecting a fast tracepoint, this
402 structure holds the collect status. */
403
404 struct fast_tpoint_collect_status
405 {
406 /* The tracepoint that is presently being collected. */
407 int tpoint_num;
408 CORE_ADDR tpoint_addr;
409
410 /* The address range in the jump pad of where the original
411 instruction the tracepoint jump was inserted was relocated
412 to. */
413 CORE_ADDR adjusted_insn_addr;
414 CORE_ADDR adjusted_insn_addr_end;
415 };
416
417 int fast_tracepoint_collecting (CORE_ADDR thread_area,
418 CORE_ADDR stop_pc,
419 struct fast_tpoint_collect_status *status);
420 void force_unlock_trace_buffer (void);
421
422 int handle_tracepoint_bkpts (struct thread_info *tinfo, CORE_ADDR stop_pc);
423
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,
430 CORE_ADDR pc);
431 void set_trampoline_buffer_space (CORE_ADDR begin, CORE_ADDR end,
432 char *errmsg);
433 #else
434 void stop_tracing (void);
435
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);
439 #endif
440
441 struct traceframe;
442 struct eval_agent_expr_context;
443
444 /* Do memory copies for bytecodes. */
445 /* Do the recording of memory blocks for actions and bytecodes. */
446
447 int agent_mem_read (struct eval_agent_expr_context *ctx,
448 unsigned char *to, CORE_ADDR from,
449 ULONGEST len);
450
451 LONGEST agent_get_trace_state_variable_value (int num);
452 void agent_set_trace_state_variable_value (int num, LONGEST val);
453
454 /* Record the value of a trace state variable. */
455
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,
458 unsigned char *to,
459 CORE_ADDR from,
460 ULONGEST len);
461
462 /* Bytecode compilation function vector. */
463
464 struct emit_ops
465 {
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);
495
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);
499
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);
504
505 /* Emit code specialized for common combinations of compare followed
506 by a goto. */
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);
513 };
514
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);
523
524 extern CORE_ADDR current_insn_ptr;
525 extern int emit_error;
526
527 /* Version information, from version.c. */
528 extern const char version[];
529 extern const char host_name[];
530
531 #endif /* SERVER_H */
This page took 0.043559 seconds and 4 git commands to generate.