PR 15657
[deliverable/binutils-gdb.git] / gdb / gdbserver / server.h
CommitLineData
c906108c 1/* Common definitions for remote server for GDB.
28e7fd62 2 Copyright (C) 1993-2013 Free Software Foundation, Inc.
c906108c 3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
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
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
c5aa993b 9 (at your option) any later version.
c906108c 10
c5aa993b
JM
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.
c906108c 15
c5aa993b 16 You should have received a copy of the GNU General Public License
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 18
0a30fbc4
DJ
19#ifndef SERVER_H
20#define SERVER_H
21
22#include "config.h"
406b1477 23#include "build-gnulib-gdbserver/config.h"
0729219d 24
68070c10
PA
25#ifdef __MINGW32CE__
26#include "wincecompat.h"
27#endif
28
18c1b81a
YQ
29#include "libiberty.h"
30#include "ansidecl.h"
31
0a30fbc4
DJ
32#include <stdarg.h>
33#include <stdio.h>
34#include <stdlib.h>
68070c10 35#ifdef HAVE_ERRNO_H
0a30fbc4 36#include <errno.h>
68070c10 37#endif
0729219d 38#include <setjmp.h>
0a30fbc4 39
d64b8841
DJ
40#ifdef HAVE_STRING_H
41#include <string.h>
42#endif
43
a1723c35 44#ifdef HAVE_ALLOCA_H
45#include <alloca.h>
46#endif
a778ab81 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
a1723c35 52
e122f1f5 53#if !HAVE_DECL_STRERROR
43d5792c
DJ
54#ifndef strerror
55extern char *strerror (int); /* X3.159-1989 4.11.6.2 */
56#endif
57#endif
58
68070c10
PA
59#if !HAVE_DECL_PERROR
60#ifndef perror
61extern void perror (const char *);
62#endif
63#endif
64
bb0116a4
JB
65#if !HAVE_DECL_VASPRINTF
66extern int vasprintf(char **strp, const char *fmt, va_list ap);
67#endif
68#if !HAVE_DECL_VSNPRINTF
69int vsnprintf(char *str, size_t size, const char *format, va_list ap);
70#endif
71
9e0627f1
PM
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
5e1dc496
LM
78#ifdef IN_PROCESS_AGENT
79# define PROG "ipa"
80#else
81# define PROG "gdbserver"
82#endif
83
01f9e8fa
DJ
84/* A type used for binary buffers. */
85typedef unsigned char gdb_byte;
86
d26e3629
KY
87#include "ptid.h"
88#include "buffer.h"
89#include "xml-utils.h"
90#include "gdb_locale.h"
91
0729219d
DJ
92/* FIXME: This should probably be autoconf'd for. It's an integer type at
93 least the size of a (void *). */
0a30fbc4
DJ
94typedef long long CORE_ADDR;
95
219f2f23 96typedef long long LONGEST;
95954743
PA
97typedef unsigned long long ULONGEST;
98
0d62e5e8
DJ
99/* Generic information for tracking a list of ``inferiors'' - threads,
100 processes, etc. */
101struct inferior_list
102{
103 struct inferior_list_entry *head;
104 struct inferior_list_entry *tail;
105};
106struct inferior_list_entry
107{
95954743 108 ptid_t id;
0d62e5e8
DJ
109 struct inferior_list_entry *next;
110};
111
0d62e5e8 112struct thread_info;
d50171e4
PA
113struct process_info;
114struct regcache;
3aee8918 115struct target_desc;
d50171e4
PA
116
117#include "regcache.h"
118#include "gdb/signals.h"
119#include "gdb_signals.h"
120#include "target.h"
121#include "mem-break.h"
623b6bdf 122#include "gdbthread.h"
c04a1aa8 123
255e7678
DJ
124struct dll_info
125{
126 struct inferior_list_entry entry;
127 char *name;
128 CORE_ADDR base_addr;
129};
130
95954743
PA
131struct sym_cache;
132struct breakpoint;
8b07ae33 133struct raw_breakpoint;
fa593d66 134struct fast_tracepoint_jump;
95954743
PA
135struct process_info_private;
136
137struct process_info
138{
139 struct inferior_list_entry head;
140
8336d594
PA
141 /* Nonzero if this child process was attached rather than
142 spawned. */
95954743
PA
143 int attached;
144
8336d594
PA
145 /* True if GDB asked us to detach from this process, but we remained
146 attached anyway. */
147 int gdb_detached;
148
95954743
PA
149 /* The symbol cache. */
150 struct sym_cache *symbol_cache;
151
95954743
PA
152 /* The list of memory breakpoints. */
153 struct breakpoint *breakpoints;
154
8b07ae33
PA
155 /* The list of raw memory breakpoints. */
156 struct raw_breakpoint *raw_breakpoints;
157
fa593d66
PA
158 /* The list of installed fast tracepoints. */
159 struct fast_tracepoint_jump *fast_tracepoint_jumps;
160
3aee8918
PA
161 const struct target_desc *tdesc;
162
95954743
PA
163 /* Private target data. */
164 struct process_info_private *private;
165};
166
167/* Return a pointer to the process that corresponds to the current
168 thread (current_inferior). It is an error to call this if there is
169 no current thread selected. */
170
171struct process_info *current_process (void);
7fe519cb 172struct process_info *get_thread_process (struct thread_info *);
95954743 173
c906108c
SS
174/* Target-specific functions */
175
4ce44c66 176void initialize_low ();
c906108c 177
ce3a066d
DJ
178/* From inferiors.c. */
179
95954743 180extern struct inferior_list all_processes;
255e7678
DJ
181extern struct inferior_list all_dlls;
182extern int dlls_changed;
bf4c19f7 183extern void clear_dlls (void);
255e7678 184
0d62e5e8
DJ
185void add_inferior_to_list (struct inferior_list *list,
186 struct inferior_list_entry *new_inferior);
187void for_each_inferior (struct inferior_list *list,
188 void (*action) (struct inferior_list_entry *));
95954743 189
0d62e5e8
DJ
190extern struct thread_info *current_inferior;
191void remove_inferior (struct inferior_list *list,
192 struct inferior_list_entry *entry);
95954743
PA
193
194struct process_info *add_process (int pid, int attached);
195void remove_process (struct process_info *process);
196struct process_info *find_process_pid (int pid);
9f767825
DE
197int have_started_inferiors_p (void);
198int have_attached_inferiors_p (void);
95954743 199
95954743
PA
200ptid_t thread_id_to_gdb_id (ptid_t);
201ptid_t thread_to_gdb_id (struct thread_info *);
202ptid_t gdb_id_to_thread_id (ptid_t);
623b6bdf 203
ce3a066d 204void clear_inferiors (void);
0d62e5e8
DJ
205struct inferior_list_entry *find_inferior
206 (struct inferior_list *,
207 int (*func) (struct inferior_list_entry *,
208 void *),
209 void *arg);
210struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
95954743 211 ptid_t id);
0d62e5e8
DJ
212void *inferior_target_data (struct thread_info *);
213void set_inferior_target_data (struct thread_info *, void *);
214void *inferior_regcache_data (struct thread_info *);
215void set_inferior_regcache_data (struct thread_info *, void *);
ce3a066d 216
255e7678
DJ
217void loaded_dll (const char *name, CORE_ADDR base_addr);
218void unloaded_dll (const char *name, CORE_ADDR base_addr);
219
c906108c
SS
220/* Public variables in server.c */
221
95954743
PA
222extern ptid_t cont_thread;
223extern ptid_t general_thread;
5b1c542e 224
0d62e5e8 225extern int server_waiting;
c74d0ad8 226extern int debug_threads;
aa5ca48f 227extern int debug_hw_points;
89be2091 228extern int pass_signals[];
9b224c5e
PA
229extern int program_signals[];
230extern int program_signals_p;
c906108c
SS
231
232extern jmp_buf toplevel;
c906108c 233
db42f210
PA
234extern int disable_packet_vCont;
235extern int disable_packet_Tthread;
236extern int disable_packet_qC;
237extern int disable_packet_qfThreadInfo;
238
03f2bd59 239extern int run_once;
95954743 240extern int multi_process;
bd99dc85
PA
241extern int non_stop;
242
03583c20
UW
243extern int disable_randomization;
244
ec48365d
PA
245#if USE_WIN32API
246#include <winsock2.h>
247typedef SOCKET gdb_fildes_t;
248#else
249typedef int gdb_fildes_t;
250#endif
251
bd99dc85
PA
252/* Functions from event-loop.c. */
253typedef void *gdb_client_data;
8336d594 254typedef int (handler_func) (int, gdb_client_data);
24b066ba 255typedef int (callback_handler_func) (gdb_client_data);
bd99dc85 256
ec48365d
PA
257extern void delete_file_handler (gdb_fildes_t fd);
258extern void add_file_handler (gdb_fildes_t fd, handler_func *proc,
bd99dc85 259 gdb_client_data client_data);
24b066ba
DE
260extern int append_callback_event (callback_handler_func *proc,
261 gdb_client_data client_data);
262extern void delete_callback_event (int id);
bd99dc85
PA
263
264extern void start_event_loop (void);
60f662b0 265extern void initialize_event_loop (void);
bd99dc85
PA
266
267/* Functions from server.c. */
8336d594
PA
268extern int handle_serial_event (int err, gdb_client_data client_data);
269extern int handle_target_event (int err, gdb_client_data client_data);
bd99dc85 270
a6b151f1
DJ
271/* Functions from hostio.c. */
272extern int handle_vFile (char *, int, int *);
273
59a016f0
PA
274/* Functions from hostio-errno.c. */
275extern void hostio_last_error_from_errno (char *own_buf);
276
ea025f5f
DJ
277/* From remote-utils.c */
278
c74d0ad8 279extern int remote_debug;
a6f3e723
SL
280extern int noack_mode;
281extern int transport_is_reliable;
c906108c 282
8336d594
PA
283int gdb_connected (void);
284
e0f9f062
DE
285#define STDIO_CONNECTION_NAME "stdio"
286int remote_connection_is_stdio (void);
287
95954743
PA
288ptid_t read_ptid (char *buf, char **obuf);
289char *write_ptid (char *buf, ptid_t ptid);
290
a14ed312 291int putpkt (char *buf);
01f9e8fa 292int putpkt_binary (char *buf, int len);
bd99dc85 293int putpkt_notif (char *buf);
a14ed312 294int getpkt (char *buf);
03f2bd59 295void remote_prepare (char *name);
a14ed312
KB
296void remote_open (char *name);
297void remote_close (void);
298void write_ok (char *buf);
299void write_enn (char *buf);
a20d5e98 300void initialize_async_io (void);
a14ed312
KB
301void enable_async_io (void);
302void disable_async_io (void);
7390519e 303void check_remote_input_interrupt_request (void);
fa593d66
PA
304void convert_ascii_to_int (const char *from, unsigned char *to, int n);
305void convert_int_to_ascii (const unsigned char *from, char *to, int n);
0d62e5e8
DJ
306void new_thread_notify (int id);
307void dead_thread_notify (int id);
95954743 308void prepare_resume_reply (char *buf, ptid_t ptid,
5b1c542e 309 struct target_waitstatus *status);
c906108c 310
89be2091 311const char *decode_address_to_semicolon (CORE_ADDR *addrp, const char *start);
dae5f5cf 312void decode_address (CORE_ADDR *addrp, const char *start, int len);
a14ed312
KB
313void decode_m_packet (char *from, CORE_ADDR * mem_addr_ptr,
314 unsigned int *len_ptr);
315void decode_M_packet (char *from, CORE_ADDR * mem_addr_ptr,
fa593d66 316 unsigned int *len_ptr, unsigned char **to_p);
01f9e8fa 317int decode_X_packet (char *from, int packet_len, CORE_ADDR * mem_addr_ptr,
fa593d66 318 unsigned int *len_ptr, unsigned char **to_p);
d08aafef 319int decode_xfer_write (char *buf, int packet_len,
0e7f50da
UW
320 CORE_ADDR *offset, unsigned int *len,
321 unsigned char *data);
08388c79
DE
322int decode_search_memory_packet (const char *buf, int packet_len,
323 CORE_ADDR *start_addrp,
324 CORE_ADDR *search_space_lenp,
493e2a69
MS
325 gdb_byte *pattern,
326 unsigned int *pattern_lenp);
c906108c 327
ce3a066d
DJ
328int unhexify (char *bin, const char *hex, int count);
329int hexify (char *hex, const char *bin, int count);
01f9e8fa
DJ
330int remote_escape_output (const gdb_byte *buffer, int len,
331 gdb_byte *out_buf, int *out_len,
332 int out_maxlen);
219f2f23 333char *unpack_varlen_hex (char *buff, ULONGEST *result);
ce3a066d 334
95954743 335void clear_symbol_cache (struct sym_cache **symcache_p);
9836d6ea 336int look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb);
ce3a066d 337
fa593d66
PA
338int relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc);
339
bce7165d 340void monitor_output (const char *msg);
c74d0ad8 341
c906108c 342/* Functions from utils.c */
d26e3629 343#include "common-utils.h"
c906108c 344
54363045 345void perror_with_name (const char *string);
18c1b81a
YQ
346void error (const char *string,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
347void fatal (const char *string,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
348void warning (const char *string,...) ATTRIBUTE_PRINTF (1, 2);
aa5ca48f 349char *paddress (CORE_ADDR addr);
219f2f23
PA
350char *pulongest (ULONGEST u);
351char *plongest (LONGEST l);
352char *phex_nz (ULONGEST l, int sizeof_l);
ec48365d 353char *pfildes (gdb_fildes_t fd);
0a30fbc4 354
d26e3629 355#include "gdb_assert.h"
e92d13d5 356
5c44784c
JM
357/* Maximum number of bytes to read/write at once. The value here
358 is chosen to fill up a packet (the headers account for the 32). */
359#define MAXBUFBYTES(N) (((N)-32)/2)
360
bb9c3d36
UW
361/* Buffer sizes for transferring memory, registers, etc. Set to a constant
362 value to accomodate multiple register formats. This value must be at least
363 as large as the largest register set supported by gdbserver. */
364#define PBUFSIZ 16384
0a30fbc4 365
219f2f23
PA
366/* Functions from tracepoint.c */
367
405f8e94
SS
368/* Size for a small buffer to report problems from the in-process
369 agent back to GDBserver. */
370#define IPA_BUFSIZ 100
371
219f2f23
PA
372void initialize_tracepoint (void);
373
8336d594
PA
374extern int tracing;
375extern int disconnected_tracing;
376
fa593d66
PA
377void tracepoint_look_up_symbols (void);
378
8336d594
PA
379void stop_tracing (void);
380
219f2f23
PA
381int handle_tracepoint_general_set (char *own_buf);
382int handle_tracepoint_query (char *own_buf);
383
384int tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc);
385int tracepoint_was_hit (struct thread_info *tinfo, CORE_ADDR stop_pc);
386
387void release_while_stepping_state_list (struct thread_info *tinfo);
388
389extern int current_traceframe;
390
391int in_readonly_region (CORE_ADDR addr, ULONGEST length);
392int traceframe_read_mem (int tfnum, CORE_ADDR addr,
393 unsigned char *buf, ULONGEST length,
394 ULONGEST *nbytes);
395int fetch_traceframe_registers (int tfnum,
396 struct regcache *regcache,
397 int regnum);
398
0fb4aa4b
PA
399int traceframe_read_sdata (int tfnum, ULONGEST offset,
400 unsigned char *buf, ULONGEST length,
401 ULONGEST *nbytes);
402
b3b9301e
PA
403int traceframe_read_info (int tfnum, struct buffer *buffer);
404
fa593d66
PA
405/* If a thread is determined to be collecting a fast tracepoint, this
406 structure holds the collect status. */
407
408struct fast_tpoint_collect_status
409{
410 /* The tracepoint that is presently being collected. */
411 int tpoint_num;
412 CORE_ADDR tpoint_addr;
413
414 /* The address range in the jump pad of where the original
415 instruction the tracepoint jump was inserted was relocated
416 to. */
417 CORE_ADDR adjusted_insn_addr;
418 CORE_ADDR adjusted_insn_addr_end;
419};
420
421int fast_tracepoint_collecting (CORE_ADDR thread_area,
422 CORE_ADDR stop_pc,
423 struct fast_tpoint_collect_status *status);
424void force_unlock_trace_buffer (void);
425
426int handle_tracepoint_bkpts (struct thread_info *tinfo, CORE_ADDR stop_pc);
427
428#ifdef IN_PROCESS_AGENT
429void initialize_low_tracepoint (void);
430void supply_fast_tracepoint_registers (struct regcache *regcache,
431 const unsigned char *regs);
0fb4aa4b
PA
432void supply_static_tracepoint_registers (struct regcache *regcache,
433 const unsigned char *regs,
434 CORE_ADDR pc);
405f8e94
SS
435void set_trampoline_buffer_space (CORE_ADDR begin, CORE_ADDR end,
436 char *errmsg);
3aee8918
PA
437
438extern const struct target_desc *ipa_tdesc;
439
fa593d66
PA
440#else
441void stop_tracing (void);
405f8e94
SS
442
443int claim_trampoline_space (ULONGEST used, CORE_ADDR *trampoline);
444int have_fast_tracepoint_trampoline_buffer (char *msgbuf);
7255706c 445void gdb_agent_about_to_close (int pid);
fa593d66
PA
446#endif
447
5e1dc496 448struct traceframe;
5ae4861a 449struct eval_agent_expr_context;
5e1dc496
LM
450
451/* Do memory copies for bytecodes. */
452/* Do the recording of memory blocks for actions and bytecodes. */
453
5ae4861a 454int agent_mem_read (struct eval_agent_expr_context *ctx,
5e1dc496
LM
455 unsigned char *to, CORE_ADDR from,
456 ULONGEST len);
457
458LONGEST agent_get_trace_state_variable_value (int num);
459void agent_set_trace_state_variable_value (int num, LONGEST val);
460
461/* Record the value of a trace state variable. */
462
5ae4861a
YQ
463int agent_tsv_read (struct eval_agent_expr_context *ctx, int n);
464int agent_mem_read_string (struct eval_agent_expr_context *ctx,
5e1dc496
LM
465 unsigned char *to,
466 CORE_ADDR from,
467 ULONGEST len);
468
6a271cae
PA
469/* Bytecode compilation function vector. */
470
471struct emit_ops
472{
473 void (*emit_prologue) (void);
474 void (*emit_epilogue) (void);
475 void (*emit_add) (void);
476 void (*emit_sub) (void);
477 void (*emit_mul) (void);
478 void (*emit_lsh) (void);
479 void (*emit_rsh_signed) (void);
480 void (*emit_rsh_unsigned) (void);
481 void (*emit_ext) (int arg);
482 void (*emit_log_not) (void);
483 void (*emit_bit_and) (void);
484 void (*emit_bit_or) (void);
485 void (*emit_bit_xor) (void);
486 void (*emit_bit_not) (void);
487 void (*emit_equal) (void);
488 void (*emit_less_signed) (void);
489 void (*emit_less_unsigned) (void);
490 void (*emit_ref) (int size);
491 void (*emit_if_goto) (int *offset_p, int *size_p);
492 void (*emit_goto) (int *offset_p, int *size_p);
493 void (*write_goto_address) (CORE_ADDR from, CORE_ADDR to, int size);
4e29fb54 494 void (*emit_const) (LONGEST num);
6a271cae
PA
495 void (*emit_call) (CORE_ADDR fn);
496 void (*emit_reg) (int reg);
497 void (*emit_pop) (void);
498 void (*emit_stack_flush) (void);
499 void (*emit_zero_ext) (int arg);
500 void (*emit_swap) (void);
501 void (*emit_stack_adjust) (int n);
502
503 /* Emit code for a generic function that takes one fixed integer
504 argument and returns a 64-bit int (for instance, tsv getter). */
505 void (*emit_int_call_1) (CORE_ADDR fn, int arg1);
506
507 /* Emit code for a generic function that takes one fixed integer
508 argument and a 64-bit int from the top of the stack, and returns
509 nothing (for instance, tsv setter). */
510 void (*emit_void_call_2) (CORE_ADDR fn, int arg1);
6b9801d4
SS
511
512 /* Emit code specialized for common combinations of compare followed
513 by a goto. */
514 void (*emit_eq_goto) (int *offset_p, int *size_p);
515 void (*emit_ne_goto) (int *offset_p, int *size_p);
516 void (*emit_lt_goto) (int *offset_p, int *size_p);
517 void (*emit_le_goto) (int *offset_p, int *size_p);
518 void (*emit_gt_goto) (int *offset_p, int *size_p);
519 void (*emit_ge_goto) (int *offset_p, int *size_p);
6a271cae
PA
520};
521
522/* Returns the address of the get_raw_reg function in the IPA. */
523CORE_ADDR get_raw_reg_func_addr (void);
5e1dc496
LM
524/* Returns the address of the get_trace_state_variable_value
525 function in the IPA. */
526CORE_ADDR get_get_tsv_func_addr (void);
527/* Returns the address of the set_trace_state_variable_value
528 function in the IPA. */
529CORE_ADDR get_set_tsv_func_addr (void);
6a271cae 530
e90e9ad9
TT
531extern CORE_ADDR current_insn_ptr;
532extern int emit_error;
6a271cae 533
dd24457d
DJ
534/* Version information, from version.c. */
535extern const char version[];
536extern const char host_name[];
537
0a30fbc4 538#endif /* SERVER_H */
This page took 1.149974 seconds and 4 git commands to generate.