12fef0feb3ff3db0622ff3805bf8a6bed396d33f
[deliverable/binutils-gdb.git] / gdb / gdbserver / server.h
1 /* Common definitions for remote server for GDB.
2 Copyright (C) 1993, 1995, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005,
3 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef SERVER_H
21 #define SERVER_H
22
23 #include "config.h"
24
25 #ifdef __MINGW32CE__
26 #include "wincecompat.h"
27 #endif
28
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #ifdef HAVE_ERRNO_H
33 #include <errno.h>
34 #endif
35 #include <setjmp.h>
36
37 #ifdef HAVE_STRING_H
38 #include <string.h>
39 #endif
40
41 #if !HAVE_DECL_STRERROR
42 #ifndef strerror
43 extern char *strerror (int); /* X3.159-1989 4.11.6.2 */
44 #endif
45 #endif
46
47 #if !HAVE_DECL_PERROR
48 #ifndef perror
49 extern void perror (const char *);
50 #endif
51 #endif
52
53 #if !HAVE_DECL_MEMMEM
54 extern void *memmem (const void *, size_t , const void *, size_t);
55 #endif
56
57 #ifndef ATTR_NORETURN
58 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
59 #define ATTR_NORETURN __attribute__ ((noreturn))
60 #else
61 #define ATTR_NORETURN /* nothing */
62 #endif
63 #endif
64
65 #ifndef ATTR_FORMAT
66 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 4))
67 #define ATTR_FORMAT(type, x, y) __attribute__ ((format(type, x, y)))
68 #else
69 #define ATTR_FORMAT(type, x, y) /* nothing */
70 #endif
71 #endif
72
73 #ifndef ATTR_MALLOC
74 #if defined(__GNUC__) && (__GNUC__ >= 3)
75 #define ATTR_MALLOC __attribute__ ((__malloc__))
76 #else
77 #define ATTR_MALLOC /* nothing */
78 #endif
79 #endif
80
81 /* A type used for binary buffers. */
82 typedef unsigned char gdb_byte;
83
84 /* FIXME: This should probably be autoconf'd for. It's an integer type at
85 least the size of a (void *). */
86 typedef long long CORE_ADDR;
87
88 /* Generic information for tracking a list of ``inferiors'' - threads,
89 processes, etc. */
90 struct inferior_list
91 {
92 struct inferior_list_entry *head;
93 struct inferior_list_entry *tail;
94 };
95 struct inferior_list_entry
96 {
97 unsigned long id;
98 struct inferior_list_entry *next;
99 };
100
101 /* Opaque type for user-visible threads. */
102 struct thread_info;
103
104 struct dll_info
105 {
106 struct inferior_list_entry entry;
107 char *name;
108 CORE_ADDR base_addr;
109 };
110
111 #include "regcache.h"
112 #include "gdb/signals.h"
113 #include "gdb_signals.h"
114 #include "target.h"
115 #include "mem-break.h"
116
117 /* Target-specific functions */
118
119 void initialize_low ();
120
121 /* From inferiors.c. */
122
123 extern struct inferior_list all_threads;
124 extern struct inferior_list all_dlls;
125 extern int dlls_changed;
126
127 void add_inferior_to_list (struct inferior_list *list,
128 struct inferior_list_entry *new_inferior);
129 void for_each_inferior (struct inferior_list *list,
130 void (*action) (struct inferior_list_entry *));
131 extern struct thread_info *current_inferior;
132 void remove_inferior (struct inferior_list *list,
133 struct inferior_list_entry *entry);
134 void remove_thread (struct thread_info *thread);
135 void add_thread (unsigned long thread_id, void *target_data, unsigned int);
136 unsigned int thread_id_to_gdb_id (unsigned long);
137 unsigned int thread_to_gdb_id (struct thread_info *);
138 unsigned long gdb_id_to_thread_id (unsigned int);
139 struct thread_info *gdb_id_to_thread (unsigned int);
140 void clear_inferiors (void);
141 struct inferior_list_entry *find_inferior
142 (struct inferior_list *,
143 int (*func) (struct inferior_list_entry *,
144 void *),
145 void *arg);
146 struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
147 unsigned long id);
148 void *inferior_target_data (struct thread_info *);
149 void set_inferior_target_data (struct thread_info *, void *);
150 void *inferior_regcache_data (struct thread_info *);
151 void set_inferior_regcache_data (struct thread_info *, void *);
152 void add_pid_to_list (struct inferior_list *list, unsigned long pid);
153 int pull_pid_from_list (struct inferior_list *list, unsigned long pid);
154
155 void loaded_dll (const char *name, CORE_ADDR base_addr);
156 void unloaded_dll (const char *name, CORE_ADDR base_addr);
157
158 /* Public variables in server.c */
159
160 extern unsigned long cont_thread;
161 extern unsigned long general_thread;
162 extern unsigned long step_thread;
163
164 extern int server_waiting;
165 extern int debug_threads;
166 extern int pass_signals[];
167
168 extern jmp_buf toplevel;
169
170 extern int disable_packet_vCont;
171 extern int disable_packet_Tthread;
172 extern int disable_packet_qC;
173 extern int disable_packet_qfThreadInfo;
174
175 extern int non_stop;
176
177 /* Functions from event-loop.c. */
178 typedef void *gdb_client_data;
179 typedef void (handler_func) (int, gdb_client_data);
180
181 extern void delete_file_handler (int fd);
182 extern void add_file_handler (int fd, handler_func *proc,
183 gdb_client_data client_data);
184
185 extern void start_event_loop (void);
186
187 /* Functions from server.c. */
188 extern void handle_serial_event (int err, gdb_client_data client_data);
189 extern void handle_target_event (int err, gdb_client_data client_data);
190
191 extern void push_event (unsigned long ptid, struct target_waitstatus *status);
192
193 /* Functions from hostio.c. */
194 extern int handle_vFile (char *, int, int *);
195
196 /* Functions from hostio-errno.c. */
197 extern void hostio_last_error_from_errno (char *own_buf);
198
199 /* From remote-utils.c */
200
201 extern int remote_debug;
202 extern int all_symbols_looked_up;
203 extern int noack_mode;
204 extern int transport_is_reliable;
205
206 int putpkt (char *buf);
207 int putpkt_binary (char *buf, int len);
208 int putpkt_notif (char *buf);
209 int getpkt (char *buf);
210 void remote_open (char *name);
211 void remote_close (void);
212 void write_ok (char *buf);
213 void write_enn (char *buf);
214 void initialize_async_io (void);
215 void enable_async_io (void);
216 void disable_async_io (void);
217 void check_remote_input_interrupt_request (void);
218 void convert_ascii_to_int (char *from, unsigned char *to, int n);
219 void convert_int_to_ascii (unsigned char *from, char *to, int n);
220 void new_thread_notify (int id);
221 void dead_thread_notify (int id);
222 void prepare_resume_reply (char *buf, unsigned long thread_id,
223 struct target_waitstatus *status);
224
225 const char *decode_address_to_semicolon (CORE_ADDR *addrp, const char *start);
226 void decode_address (CORE_ADDR *addrp, const char *start, int len);
227 void decode_m_packet (char *from, CORE_ADDR * mem_addr_ptr,
228 unsigned int *len_ptr);
229 void decode_M_packet (char *from, CORE_ADDR * mem_addr_ptr,
230 unsigned int *len_ptr, unsigned char *to);
231 int decode_X_packet (char *from, int packet_len, CORE_ADDR * mem_addr_ptr,
232 unsigned int *len_ptr, unsigned char *to);
233 int decode_xfer_write (char *buf, int packet_len, char **annex,
234 CORE_ADDR *offset, unsigned int *len,
235 unsigned char *data);
236 int decode_search_memory_packet (const char *buf, int packet_len,
237 CORE_ADDR *start_addrp,
238 CORE_ADDR *search_space_lenp,
239 gdb_byte *pattern, unsigned int *pattern_lenp);
240
241 int unhexify (char *bin, const char *hex, int count);
242 int hexify (char *hex, const char *bin, int count);
243 int remote_escape_output (const gdb_byte *buffer, int len,
244 gdb_byte *out_buf, int *out_len,
245 int out_maxlen);
246
247 int look_up_one_symbol (const char *name, CORE_ADDR *addrp);
248
249 void monitor_output (const char *msg);
250
251 char *xml_escape_text (const char *text);
252
253 /* Simple growing buffer. */
254
255 struct buffer
256 {
257 char *buffer;
258 size_t buffer_size; /* allocated size */
259 size_t used_size; /* actually used size */
260 };
261
262 /* Append DATA of size SIZE to the end of BUFFER. Grows the buffer to
263 accommodate the new data. */
264 void buffer_grow (struct buffer *buffer, const char *data, size_t size);
265
266 /* Release any memory held by BUFFER. */
267 void buffer_free (struct buffer *buffer);
268
269 /* Initialize BUFFER. BUFFER holds no memory afterwards. */
270 void buffer_init (struct buffer *buffer);
271
272 /* Return a pointer into BUFFER data, effectivelly transfering
273 ownership of the buffer memory to the caller. Calling buffer_free
274 afterwards has no effect on the returned data. */
275 char* buffer_finish (struct buffer *buffer);
276
277 /* Simple printf to BUFFER function. Current implemented formatters:
278 %s - grow an xml escaped text in OBSTACK. */
279 void buffer_xml_printf (struct buffer *buffer, const char *format, ...)
280 ATTR_FORMAT (printf, 2, 3);;
281
282 #define buffer_grow_str(BUFFER,STRING) \
283 buffer_grow (BUFFER, STRING, strlen (STRING))
284 #define buffer_grow_str0(BUFFER,STRING) \
285 buffer_grow (BUFFER, STRING, strlen (STRING) + 1)
286
287 /* Functions from utils.c */
288
289 void *xmalloc (size_t) ATTR_MALLOC;
290 void *xcalloc (size_t, size_t) ATTR_MALLOC;
291 char *xstrdup (const char *) ATTR_MALLOC;
292 void freeargv (char **argv);
293 void perror_with_name (const char *string);
294 void error (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
295 void fatal (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
296 void warning (const char *string,...) ATTR_FORMAT (printf, 1, 2);
297
298 /* Maximum number of bytes to read/write at once. The value here
299 is chosen to fill up a packet (the headers account for the 32). */
300 #define MAXBUFBYTES(N) (((N)-32)/2)
301
302 /* Buffer sizes for transferring memory, registers, etc. Set to a constant
303 value to accomodate multiple register formats. This value must be at least
304 as large as the largest register set supported by gdbserver. */
305 #define PBUFSIZ 16384
306
307 /* Version information, from version.c. */
308 extern const char version[];
309 extern const char host_name[];
310
311 #endif /* SERVER_H */
This page took 0.034959 seconds and 4 git commands to generate.