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