gdb/gdbserver/
[deliverable/binutils-gdb.git] / gdb / gdbserver / server.h
CommitLineData
c906108c 1/* Common definitions for remote server for GDB.
0b302171
JB
2 Copyright (C) 1993, 1995, 1997-2000, 2002-2012 Free Software
3 Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 19
0a30fbc4
DJ
20#ifndef SERVER_H
21#define SERVER_H
22
23#include "config.h"
406b1477 24#include "build-gnulib-gdbserver/config.h"
0729219d 25
68070c10
PA
26#ifdef __MINGW32CE__
27#include "wincecompat.h"
28#endif
29
18c1b81a
YQ
30#include "libiberty.h"
31#include "ansidecl.h"
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;
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
95954743
PA
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
169struct process_info *current_process (void);
7fe519cb 170struct process_info *get_thread_process (struct thread_info *);
95954743 171
c906108c
SS
172/* Target-specific functions */
173
4ce44c66 174void initialize_low ();
c906108c 175
ce3a066d
DJ
176/* From inferiors.c. */
177
95954743 178extern struct inferior_list all_processes;
255e7678
DJ
179extern struct inferior_list all_dlls;
180extern int dlls_changed;
bf4c19f7 181extern void clear_dlls (void);
255e7678 182
0d62e5e8
DJ
183void add_inferior_to_list (struct inferior_list *list,
184 struct inferior_list_entry *new_inferior);
185void for_each_inferior (struct inferior_list *list,
186 void (*action) (struct inferior_list_entry *));
95954743 187
0d62e5e8
DJ
188extern struct thread_info *current_inferior;
189void remove_inferior (struct inferior_list *list,
190 struct inferior_list_entry *entry);
95954743
PA
191
192struct process_info *add_process (int pid, int attached);
193void remove_process (struct process_info *process);
194struct process_info *find_process_pid (int pid);
9f767825
DE
195int have_started_inferiors_p (void);
196int have_attached_inferiors_p (void);
95954743 197
95954743
PA
198ptid_t thread_id_to_gdb_id (ptid_t);
199ptid_t thread_to_gdb_id (struct thread_info *);
200ptid_t gdb_id_to_thread_id (ptid_t);
623b6bdf 201
ce3a066d 202void clear_inferiors (void);
0d62e5e8
DJ
203struct inferior_list_entry *find_inferior
204 (struct inferior_list *,
205 int (*func) (struct inferior_list_entry *,
206 void *),
207 void *arg);
208struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
95954743 209 ptid_t id);
0d62e5e8
DJ
210void *inferior_target_data (struct thread_info *);
211void set_inferior_target_data (struct thread_info *, void *);
212void *inferior_regcache_data (struct thread_info *);
213void set_inferior_regcache_data (struct thread_info *, void *);
ce3a066d 214
255e7678
DJ
215void loaded_dll (const char *name, CORE_ADDR base_addr);
216void unloaded_dll (const char *name, CORE_ADDR base_addr);
217
c906108c
SS
218/* Public variables in server.c */
219
95954743
PA
220extern ptid_t cont_thread;
221extern ptid_t general_thread;
5b1c542e 222
0d62e5e8 223extern int server_waiting;
c74d0ad8 224extern int debug_threads;
aa5ca48f 225extern int debug_hw_points;
89be2091 226extern int pass_signals[];
9b224c5e
PA
227extern int program_signals[];
228extern int program_signals_p;
c906108c
SS
229
230extern jmp_buf toplevel;
c906108c 231
db42f210
PA
232extern int disable_packet_vCont;
233extern int disable_packet_Tthread;
234extern int disable_packet_qC;
235extern int disable_packet_qfThreadInfo;
236
03f2bd59 237extern int run_once;
95954743 238extern int multi_process;
bd99dc85
PA
239extern int non_stop;
240
03583c20
UW
241extern int disable_randomization;
242
ec48365d
PA
243#if USE_WIN32API
244#include <winsock2.h>
245typedef SOCKET gdb_fildes_t;
246#else
247typedef int gdb_fildes_t;
248#endif
249
bd99dc85
PA
250/* Functions from event-loop.c. */
251typedef void *gdb_client_data;
8336d594 252typedef int (handler_func) (int, gdb_client_data);
24b066ba 253typedef int (callback_handler_func) (gdb_client_data);
bd99dc85 254
ec48365d
PA
255extern void delete_file_handler (gdb_fildes_t fd);
256extern void add_file_handler (gdb_fildes_t fd, handler_func *proc,
bd99dc85 257 gdb_client_data client_data);
24b066ba
DE
258extern int append_callback_event (callback_handler_func *proc,
259 gdb_client_data client_data);
260extern void delete_callback_event (int id);
bd99dc85
PA
261
262extern void start_event_loop (void);
263
264/* Functions from server.c. */
8336d594
PA
265extern int handle_serial_event (int err, gdb_client_data client_data);
266extern int handle_target_event (int err, gdb_client_data client_data);
bd99dc85 267
95954743 268extern void push_event (ptid_t ptid, struct target_waitstatus *status);
bd99dc85 269
a6b151f1
DJ
270/* Functions from hostio.c. */
271extern int handle_vFile (char *, int, int *);
272
59a016f0
PA
273/* Functions from hostio-errno.c. */
274extern void hostio_last_error_from_errno (char *own_buf);
275
ea025f5f
DJ
276/* From remote-utils.c */
277
c74d0ad8 278extern int remote_debug;
a6f3e723
SL
279extern int noack_mode;
280extern int transport_is_reliable;
c906108c 281
8336d594
PA
282int gdb_connected (void);
283
e0f9f062
DE
284#define STDIO_CONNECTION_NAME "stdio"
285int remote_connection_is_stdio (void);
286
95954743
PA
287ptid_t read_ptid (char *buf, char **obuf);
288char *write_ptid (char *buf, ptid_t ptid);
289
a14ed312 290int putpkt (char *buf);
01f9e8fa 291int putpkt_binary (char *buf, int len);
bd99dc85 292int putpkt_notif (char *buf);
a14ed312 293int getpkt (char *buf);
03f2bd59 294void remote_prepare (char *name);
a14ed312
KB
295void remote_open (char *name);
296void remote_close (void);
297void write_ok (char *buf);
298void write_enn (char *buf);
a20d5e98 299void initialize_async_io (void);
a14ed312
KB
300void enable_async_io (void);
301void disable_async_io (void);
7390519e 302void check_remote_input_interrupt_request (void);
fa593d66
PA
303void convert_ascii_to_int (const char *from, unsigned char *to, int n);
304void convert_int_to_ascii (const unsigned char *from, char *to, int n);
0d62e5e8
DJ
305void new_thread_notify (int id);
306void dead_thread_notify (int id);
95954743 307void prepare_resume_reply (char *buf, ptid_t ptid,
5b1c542e 308 struct target_waitstatus *status);
c906108c 309
89be2091 310const char *decode_address_to_semicolon (CORE_ADDR *addrp, const char *start);
dae5f5cf 311void decode_address (CORE_ADDR *addrp, const char *start, int len);
a14ed312
KB
312void decode_m_packet (char *from, CORE_ADDR * mem_addr_ptr,
313 unsigned int *len_ptr);
314void decode_M_packet (char *from, CORE_ADDR * mem_addr_ptr,
fa593d66 315 unsigned int *len_ptr, unsigned char **to_p);
01f9e8fa 316int decode_X_packet (char *from, int packet_len, CORE_ADDR * mem_addr_ptr,
fa593d66 317 unsigned int *len_ptr, unsigned char **to_p);
d08aafef 318int decode_xfer_write (char *buf, int packet_len,
0e7f50da
UW
319 CORE_ADDR *offset, unsigned int *len,
320 unsigned char *data);
08388c79
DE
321int decode_search_memory_packet (const char *buf, int packet_len,
322 CORE_ADDR *start_addrp,
323 CORE_ADDR *search_space_lenp,
493e2a69
MS
324 gdb_byte *pattern,
325 unsigned int *pattern_lenp);
c906108c 326
ce3a066d
DJ
327int unhexify (char *bin, const char *hex, int count);
328int hexify (char *hex, const char *bin, int count);
01f9e8fa
DJ
329int remote_escape_output (const gdb_byte *buffer, int len,
330 gdb_byte *out_buf, int *out_len,
331 int out_maxlen);
219f2f23 332char *unpack_varlen_hex (char *buff, ULONGEST *result);
ce3a066d 333
95954743 334void clear_symbol_cache (struct sym_cache **symcache_p);
9836d6ea 335int look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb);
ce3a066d 336
fa593d66
PA
337int relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc);
338
bce7165d 339void monitor_output (const char *msg);
c74d0ad8 340
c906108c 341/* Functions from utils.c */
d26e3629 342#include "common-utils.h"
c906108c 343
54363045 344void perror_with_name (const char *string);
18c1b81a
YQ
345void error (const char *string,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
346void fatal (const char *string,...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
347void warning (const char *string,...) ATTRIBUTE_PRINTF (1, 2);
aa5ca48f 348char *paddress (CORE_ADDR addr);
219f2f23
PA
349char *pulongest (ULONGEST u);
350char *plongest (LONGEST l);
351char *phex_nz (ULONGEST l, int sizeof_l);
ec48365d 352char *pfildes (gdb_fildes_t fd);
0a30fbc4 353
d26e3629 354#include "gdb_assert.h"
e92d13d5 355
5c44784c
JM
356/* Maximum number of bytes to read/write at once. The value here
357 is chosen to fill up a packet (the headers account for the 32). */
358#define MAXBUFBYTES(N) (((N)-32)/2)
359
bb9c3d36
UW
360/* Buffer sizes for transferring memory, registers, etc. Set to a constant
361 value to accomodate multiple register formats. This value must be at least
362 as large as the largest register set supported by gdbserver. */
363#define PBUFSIZ 16384
0a30fbc4 364
219f2f23
PA
365/* Functions from tracepoint.c */
366
405f8e94
SS
367/* Size for a small buffer to report problems from the in-process
368 agent back to GDBserver. */
369#define IPA_BUFSIZ 100
370
219f2f23
PA
371void initialize_tracepoint (void);
372
8336d594
PA
373extern int tracing;
374extern int disconnected_tracing;
375
fa593d66
PA
376void tracepoint_look_up_symbols (void);
377
8336d594
PA
378void stop_tracing (void);
379
219f2f23
PA
380int handle_tracepoint_general_set (char *own_buf);
381int handle_tracepoint_query (char *own_buf);
382
383int tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc);
384int tracepoint_was_hit (struct thread_info *tinfo, CORE_ADDR stop_pc);
385
386void release_while_stepping_state_list (struct thread_info *tinfo);
387
388extern int current_traceframe;
389
390int in_readonly_region (CORE_ADDR addr, ULONGEST length);
391int traceframe_read_mem (int tfnum, CORE_ADDR addr,
392 unsigned char *buf, ULONGEST length,
393 ULONGEST *nbytes);
394int fetch_traceframe_registers (int tfnum,
395 struct regcache *regcache,
396 int regnum);
397
0fb4aa4b
PA
398int traceframe_read_sdata (int tfnum, ULONGEST offset,
399 unsigned char *buf, ULONGEST length,
400 ULONGEST *nbytes);
401
b3b9301e
PA
402int traceframe_read_info (int tfnum, struct buffer *buffer);
403
fa593d66
PA
404/* If a thread is determined to be collecting a fast tracepoint, this
405 structure holds the collect status. */
406
407struct fast_tpoint_collect_status
408{
409 /* The tracepoint that is presently being collected. */
410 int tpoint_num;
411 CORE_ADDR tpoint_addr;
412
413 /* The address range in the jump pad of where the original
414 instruction the tracepoint jump was inserted was relocated
415 to. */
416 CORE_ADDR adjusted_insn_addr;
417 CORE_ADDR adjusted_insn_addr_end;
418};
419
420int fast_tracepoint_collecting (CORE_ADDR thread_area,
421 CORE_ADDR stop_pc,
422 struct fast_tpoint_collect_status *status);
423void force_unlock_trace_buffer (void);
424
425int handle_tracepoint_bkpts (struct thread_info *tinfo, CORE_ADDR stop_pc);
426
427#ifdef IN_PROCESS_AGENT
428void initialize_low_tracepoint (void);
429void supply_fast_tracepoint_registers (struct regcache *regcache,
430 const unsigned char *regs);
0fb4aa4b
PA
431void supply_static_tracepoint_registers (struct regcache *regcache,
432 const unsigned char *regs,
433 CORE_ADDR pc);
405f8e94
SS
434void set_trampoline_buffer_space (CORE_ADDR begin, CORE_ADDR end,
435 char *errmsg);
fa593d66
PA
436#else
437void stop_tracing (void);
405f8e94
SS
438
439int claim_trampoline_space (ULONGEST used, CORE_ADDR *trampoline);
440int have_fast_tracepoint_trampoline_buffer (char *msgbuf);
7255706c 441void gdb_agent_about_to_close (int pid);
fa593d66
PA
442#endif
443
5e1dc496
LM
444struct traceframe;
445
446/* Do memory copies for bytecodes. */
447/* Do the recording of memory blocks for actions and bytecodes. */
448
449int agent_mem_read (struct traceframe *tframe,
450 unsigned char *to, CORE_ADDR from,
451 ULONGEST len);
452
453LONGEST agent_get_trace_state_variable_value (int num);
454void agent_set_trace_state_variable_value (int num, LONGEST val);
455
456/* Record the value of a trace state variable. */
457
458int agent_tsv_read (struct traceframe *tframe, int n);
459int agent_mem_read_string (struct traceframe *tframe,
460 unsigned char *to,
461 CORE_ADDR from,
462 ULONGEST len);
463
6a271cae
PA
464/* Bytecode compilation function vector. */
465
466struct emit_ops
467{
468 void (*emit_prologue) (void);
469 void (*emit_epilogue) (void);
470 void (*emit_add) (void);
471 void (*emit_sub) (void);
472 void (*emit_mul) (void);
473 void (*emit_lsh) (void);
474 void (*emit_rsh_signed) (void);
475 void (*emit_rsh_unsigned) (void);
476 void (*emit_ext) (int arg);
477 void (*emit_log_not) (void);
478 void (*emit_bit_and) (void);
479 void (*emit_bit_or) (void);
480 void (*emit_bit_xor) (void);
481 void (*emit_bit_not) (void);
482 void (*emit_equal) (void);
483 void (*emit_less_signed) (void);
484 void (*emit_less_unsigned) (void);
485 void (*emit_ref) (int size);
486 void (*emit_if_goto) (int *offset_p, int *size_p);
487 void (*emit_goto) (int *offset_p, int *size_p);
488 void (*write_goto_address) (CORE_ADDR from, CORE_ADDR to, int size);
4e29fb54 489 void (*emit_const) (LONGEST num);
6a271cae
PA
490 void (*emit_call) (CORE_ADDR fn);
491 void (*emit_reg) (int reg);
492 void (*emit_pop) (void);
493 void (*emit_stack_flush) (void);
494 void (*emit_zero_ext) (int arg);
495 void (*emit_swap) (void);
496 void (*emit_stack_adjust) (int n);
497
498 /* Emit code for a generic function that takes one fixed integer
499 argument and returns a 64-bit int (for instance, tsv getter). */
500 void (*emit_int_call_1) (CORE_ADDR fn, int arg1);
501
502 /* Emit code for a generic function that takes one fixed integer
503 argument and a 64-bit int from the top of the stack, and returns
504 nothing (for instance, tsv setter). */
505 void (*emit_void_call_2) (CORE_ADDR fn, int arg1);
6b9801d4
SS
506
507 /* Emit code specialized for common combinations of compare followed
508 by a goto. */
509 void (*emit_eq_goto) (int *offset_p, int *size_p);
510 void (*emit_ne_goto) (int *offset_p, int *size_p);
511 void (*emit_lt_goto) (int *offset_p, int *size_p);
512 void (*emit_le_goto) (int *offset_p, int *size_p);
513 void (*emit_gt_goto) (int *offset_p, int *size_p);
514 void (*emit_ge_goto) (int *offset_p, int *size_p);
6a271cae
PA
515};
516
517/* Returns the address of the get_raw_reg function in the IPA. */
518CORE_ADDR get_raw_reg_func_addr (void);
5e1dc496
LM
519/* Returns the address of the get_trace_state_variable_value
520 function in the IPA. */
521CORE_ADDR get_get_tsv_func_addr (void);
522/* Returns the address of the set_trace_state_variable_value
523 function in the IPA. */
524CORE_ADDR get_set_tsv_func_addr (void);
6a271cae
PA
525
526CORE_ADDR current_insn_ptr;
527int emit_error;
528
dd24457d
DJ
529/* Version information, from version.c. */
530extern const char version[];
531extern const char host_name[];
532
0a30fbc4 533#endif /* SERVER_H */
This page took 0.92987 seconds and 4 git commands to generate.