4f13cd9099d8aff84c425f0cde4fa9a96e8fc22a
[external/binutils.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 #ifdef IN_PROCESS_AGENT
77 #  define PROG "ipa"
78 #else
79 #  define PROG "gdbserver"
80 #endif
81
82 /* A type used for binary buffers.  */
83 typedef unsigned char gdb_byte;
84
85 #include "ptid.h"
86 #include "buffer.h"
87 #include "xml-utils.h"
88 #include "gdb_locale.h"
89
90 /* FIXME: This should probably be autoconf'd for.  It's an integer type at
91    least the size of a (void *).  */
92 typedef long long CORE_ADDR;
93
94 typedef long long LONGEST;
95 typedef unsigned long long ULONGEST;
96
97 /* Generic information for tracking a list of ``inferiors'' - threads,
98    processes, etc.  */
99 struct inferior_list
100 {
101   struct inferior_list_entry *head;
102   struct inferior_list_entry *tail;
103 };
104 struct inferior_list_entry
105 {
106   ptid_t id;
107   struct inferior_list_entry *next;
108 };
109
110 struct thread_info;
111 struct process_info;
112 struct regcache;
113 struct target_desc;
114
115 #include "regcache.h"
116 #include "gdb/signals.h"
117 #include "gdb_signals.h"
118 #include "target.h"
119 #include "mem-break.h"
120 #include "gdbthread.h"
121
122 struct dll_info
123 {
124   struct inferior_list_entry entry;
125   char *name;
126   CORE_ADDR base_addr;
127 };
128
129 struct sym_cache;
130 struct breakpoint;
131 struct raw_breakpoint;
132 struct fast_tracepoint_jump;
133 struct process_info_private;
134
135 struct process_info
136 {
137   struct inferior_list_entry head;
138
139   /* Nonzero if this child process was attached rather than
140      spawned.  */
141   int attached;
142
143   /* True if GDB asked us to detach from this process, but we remained
144      attached anyway.  */
145   int gdb_detached;
146
147   /* The symbol cache.  */
148   struct sym_cache *symbol_cache;
149
150   /* The list of memory breakpoints.  */
151   struct breakpoint *breakpoints;
152
153   /* The list of raw memory breakpoints.  */
154   struct raw_breakpoint *raw_breakpoints;
155
156   /* The list of installed fast tracepoints.  */
157   struct fast_tracepoint_jump *fast_tracepoint_jumps;
158
159   const struct target_desc *tdesc;
160
161   /* Private target data.  */
162   struct process_info_private *private;
163 };
164
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.  */
168
169 struct process_info *current_process (void);
170 struct process_info *get_thread_process (struct thread_info *);
171
172 /* Target-specific functions */
173
174 void initialize_low ();
175
176 /* From inferiors.c.  */
177
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);
182
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 *));
187
188 extern struct thread_info *current_inferior;
189 void remove_inferior (struct inferior_list *list,
190                       struct inferior_list_entry *entry);
191
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);
197
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);
201
202 void clear_inferiors (void);
203 struct inferior_list_entry *find_inferior
204      (struct inferior_list *,
205       int (*func) (struct inferior_list_entry *,
206                    void *),
207       void *arg);
208 struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
209                                               ptid_t id);
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 *);
214
215 void loaded_dll (const char *name, CORE_ADDR base_addr);
216 void unloaded_dll (const char *name, CORE_ADDR base_addr);
217
218 /* Public variables in server.c */
219
220 extern ptid_t cont_thread;
221 extern ptid_t general_thread;
222
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;
229
230 extern jmp_buf toplevel;
231
232 extern int disable_packet_vCont;
233 extern int disable_packet_Tthread;
234 extern int disable_packet_qC;
235 extern int disable_packet_qfThreadInfo;
236
237 extern int run_once;
238 extern int multi_process;
239 extern int non_stop;
240
241 extern int disable_randomization;
242
243 #if USE_WIN32API
244 #include <winsock2.h>
245 typedef SOCKET gdb_fildes_t;
246 #else
247 typedef int gdb_fildes_t;
248 #endif
249
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);
254
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);
261
262 extern void start_event_loop (void);
263 extern void initialize_event_loop (void);
264
265 /* Functions from server.c.  */
266 extern int handle_serial_event (int err, gdb_client_data client_data);
267 extern int handle_target_event (int err, gdb_client_data client_data);
268
269 /* Functions from hostio.c.  */
270 extern int handle_vFile (char *, int, int *);
271
272 /* Functions from hostio-errno.c.  */
273 extern void hostio_last_error_from_errno (char *own_buf);
274
275 #include "remote-utils.h"
276
277 /* Functions from utils.c */
278 #include "common-utils.h"
279
280 void perror_with_name (const char *string);
281 void error (const char *string,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
282 void fatal (const char *string,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
283 void warning (const char *string,...) ATTRIBUTE_PRINTF (1, 2);
284 char *paddress (CORE_ADDR addr);
285 char *pulongest (ULONGEST u);
286 char *plongest (LONGEST l);
287 char *phex_nz (ULONGEST l, int sizeof_l);
288 char *pfildes (gdb_fildes_t fd);
289
290 #include "gdb_assert.h"
291
292 /* Maximum number of bytes to read/write at once.  The value here
293    is chosen to fill up a packet (the headers account for the 32).  */
294 #define MAXBUFBYTES(N) (((N)-32)/2)
295
296 /* Buffer sizes for transferring memory, registers, etc.   Set to a constant
297    value to accomodate multiple register formats.  This value must be at least
298    as large as the largest register set supported by gdbserver.  */
299 #define PBUFSIZ 16384
300
301 /* Functions from tracepoint.c */
302
303 /* Size for a small buffer to report problems from the in-process
304    agent back to GDBserver.  */
305 #define IPA_BUFSIZ 100
306
307 void initialize_tracepoint (void);
308
309 extern int tracing;
310 extern int disconnected_tracing;
311
312 void tracepoint_look_up_symbols (void);
313
314 void stop_tracing (void);
315
316 int handle_tracepoint_general_set (char *own_buf);
317 int handle_tracepoint_query (char *own_buf);
318
319 int tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc);
320 int tracepoint_was_hit (struct thread_info *tinfo, CORE_ADDR stop_pc);
321
322 void release_while_stepping_state_list (struct thread_info *tinfo);
323
324 extern int current_traceframe;
325
326 int in_readonly_region (CORE_ADDR addr, ULONGEST length);
327 int traceframe_read_mem (int tfnum, CORE_ADDR addr,
328                          unsigned char *buf, ULONGEST length,
329                          ULONGEST *nbytes);
330 int fetch_traceframe_registers (int tfnum,
331                                 struct regcache *regcache,
332                                 int regnum);
333
334 int traceframe_read_sdata (int tfnum, ULONGEST offset,
335                            unsigned char *buf, ULONGEST length,
336                            ULONGEST *nbytes);
337
338 int traceframe_read_info (int tfnum, struct buffer *buffer);
339
340 /* If a thread is determined to be collecting a fast tracepoint, this
341    structure holds the collect status.  */
342
343 struct fast_tpoint_collect_status
344 {
345   /* The tracepoint that is presently being collected.  */
346   int tpoint_num;
347   CORE_ADDR tpoint_addr;
348
349   /* The address range in the jump pad of where the original
350      instruction the tracepoint jump was inserted was relocated
351      to.  */
352   CORE_ADDR adjusted_insn_addr;
353   CORE_ADDR adjusted_insn_addr_end;
354 };
355
356 int fast_tracepoint_collecting (CORE_ADDR thread_area,
357                                 CORE_ADDR stop_pc,
358                                 struct fast_tpoint_collect_status *status);
359 void force_unlock_trace_buffer (void);
360
361 int handle_tracepoint_bkpts (struct thread_info *tinfo, CORE_ADDR stop_pc);
362
363 #ifdef IN_PROCESS_AGENT
364 void initialize_low_tracepoint (void);
365 void supply_fast_tracepoint_registers (struct regcache *regcache,
366                                        const unsigned char *regs);
367 void supply_static_tracepoint_registers (struct regcache *regcache,
368                                          const unsigned char *regs,
369                                          CORE_ADDR pc);
370 void set_trampoline_buffer_space (CORE_ADDR begin, CORE_ADDR end,
371                                   char *errmsg);
372
373 extern const struct target_desc *ipa_tdesc;
374
375 #else
376 void stop_tracing (void);
377
378 int claim_trampoline_space (ULONGEST used, CORE_ADDR *trampoline);
379 int have_fast_tracepoint_trampoline_buffer (char *msgbuf);
380 void gdb_agent_about_to_close (int pid);
381 #endif
382
383 struct traceframe;
384 struct eval_agent_expr_context;
385
386 /* Do memory copies for bytecodes.  */
387 /* Do the recording of memory blocks for actions and bytecodes.  */
388
389 int agent_mem_read (struct eval_agent_expr_context *ctx,
390                     unsigned char *to, CORE_ADDR from,
391                     ULONGEST len);
392
393 LONGEST agent_get_trace_state_variable_value (int num);
394 void agent_set_trace_state_variable_value (int num, LONGEST val);
395
396 /* Record the value of a trace state variable.  */
397
398 int agent_tsv_read (struct eval_agent_expr_context *ctx, int n);
399 int agent_mem_read_string (struct eval_agent_expr_context *ctx,
400                            unsigned char *to,
401                            CORE_ADDR from,
402                            ULONGEST len);
403
404 /* Bytecode compilation function vector.  */
405
406 struct emit_ops
407 {
408   void (*emit_prologue) (void);
409   void (*emit_epilogue) (void);
410   void (*emit_add) (void);
411   void (*emit_sub) (void);
412   void (*emit_mul) (void);
413   void (*emit_lsh) (void);
414   void (*emit_rsh_signed) (void);
415   void (*emit_rsh_unsigned) (void);
416   void (*emit_ext) (int arg);
417   void (*emit_log_not) (void);
418   void (*emit_bit_and) (void);
419   void (*emit_bit_or) (void);
420   void (*emit_bit_xor) (void);
421   void (*emit_bit_not) (void);
422   void (*emit_equal) (void);
423   void (*emit_less_signed) (void);
424   void (*emit_less_unsigned) (void);
425   void (*emit_ref) (int size);
426   void (*emit_if_goto) (int *offset_p, int *size_p);
427   void (*emit_goto) (int *offset_p, int *size_p);
428   void (*write_goto_address) (CORE_ADDR from, CORE_ADDR to, int size);
429   void (*emit_const) (LONGEST num);
430   void (*emit_call) (CORE_ADDR fn);
431   void (*emit_reg) (int reg);
432   void (*emit_pop) (void);
433   void (*emit_stack_flush) (void);
434   void (*emit_zero_ext) (int arg);
435   void (*emit_swap) (void);
436   void (*emit_stack_adjust) (int n);
437
438   /* Emit code for a generic function that takes one fixed integer
439      argument and returns a 64-bit int (for instance, tsv getter).  */
440   void (*emit_int_call_1) (CORE_ADDR fn, int arg1);
441
442   /* Emit code for a generic function that takes one fixed integer
443      argument and a 64-bit int from the top of the stack, and returns
444      nothing (for instance, tsv setter).  */
445   void (*emit_void_call_2) (CORE_ADDR fn, int arg1);
446
447   /* Emit code specialized for common combinations of compare followed
448      by a goto.  */
449   void (*emit_eq_goto) (int *offset_p, int *size_p);
450   void (*emit_ne_goto) (int *offset_p, int *size_p);
451   void (*emit_lt_goto) (int *offset_p, int *size_p);
452   void (*emit_le_goto) (int *offset_p, int *size_p);
453   void (*emit_gt_goto) (int *offset_p, int *size_p);
454   void (*emit_ge_goto) (int *offset_p, int *size_p);
455 };
456
457 /* Returns the address of the get_raw_reg function in the IPA.  */
458 CORE_ADDR get_raw_reg_func_addr (void);
459 /* Returns the address of the get_trace_state_variable_value
460    function in the IPA.  */
461 CORE_ADDR get_get_tsv_func_addr (void);
462 /* Returns the address of the set_trace_state_variable_value
463    function in the IPA.  */
464 CORE_ADDR get_set_tsv_func_addr (void);
465
466 extern CORE_ADDR current_insn_ptr;
467 extern int emit_error;
468
469 #endif /* SERVER_H */