1/* Common definitions for remote server for GDB.
2   Copyright (C) 1993, 1995, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005,
3   2006, 2007 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
43extern char *strerror (int);	/* X3.159-1989  4.11.6.2 */
44#endif
45#endif
46
47#if !HAVE_DECL_PERROR
48#ifndef perror
49extern void perror (const char *);
50#endif
51#endif
52
53#ifndef ATTR_NORETURN
54#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
55#define ATTR_NORETURN __attribute__ ((noreturn))
56#else
57#define ATTR_NORETURN           /* nothing */
58#endif
59#endif
60
61#ifndef ATTR_FORMAT
62#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 4))
63#define ATTR_FORMAT(type, x, y) __attribute__ ((format(type, x, y)))
64#else
65#define ATTR_FORMAT(type, x, y) /* nothing */
66#endif
67#endif
68
69/* A type used for binary buffers.  */
70typedef unsigned char gdb_byte;
71
72/* FIXME: This should probably be autoconf'd for.  It's an integer type at
73   least the size of a (void *).  */
74typedef long long CORE_ADDR;
75
76/* Generic information for tracking a list of ``inferiors'' - threads,
77   processes, etc.  */
78struct inferior_list
79{
80  struct inferior_list_entry *head;
81  struct inferior_list_entry *tail;
82};
83struct inferior_list_entry
84{
85  unsigned long id;
86  struct inferior_list_entry *next;
87};
88
89/* Opaque type for user-visible threads.  */
90struct thread_info;
91
92struct dll_info
93{
94  struct inferior_list_entry entry;
95  char *name;
96  CORE_ADDR base_addr;
97};
98
99#include "regcache.h"
100#include "gdb/signals.h"
101
102#include "target.h"
103#include "mem-break.h"
104
105/* Target-specific functions */
106
107void initialize_low ();
108
109/* From inferiors.c.  */
110
111extern struct inferior_list all_threads;
112extern struct inferior_list all_dlls;
113extern int dlls_changed;
114
115void add_inferior_to_list (struct inferior_list *list,
116			   struct inferior_list_entry *new_inferior);
117void for_each_inferior (struct inferior_list *list,
118			void (*action) (struct inferior_list_entry *));
119extern struct thread_info *current_inferior;
120void remove_inferior (struct inferior_list *list,
121		      struct inferior_list_entry *entry);
122void remove_thread (struct thread_info *thread);
123void add_thread (unsigned long thread_id, void *target_data, unsigned int);
124unsigned int thread_id_to_gdb_id (unsigned long);
125unsigned int thread_to_gdb_id (struct thread_info *);
126unsigned long gdb_id_to_thread_id (unsigned int);
127struct thread_info *gdb_id_to_thread (unsigned int);
128void clear_inferiors (void);
129struct inferior_list_entry *find_inferior
130     (struct inferior_list *,
131      int (*func) (struct inferior_list_entry *,
132		   void *),
133      void *arg);
134struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
135					      unsigned long id);
136void *inferior_target_data (struct thread_info *);
137void set_inferior_target_data (struct thread_info *, void *);
138void *inferior_regcache_data (struct thread_info *);
139void set_inferior_regcache_data (struct thread_info *, void *);
140void change_inferior_id (struct inferior_list *list,
141			 unsigned long new_id);
142
143void loaded_dll (const char *name, CORE_ADDR base_addr);
144void unloaded_dll (const char *name, CORE_ADDR base_addr);
145
146/* Public variables in server.c */
147
148extern unsigned long cont_thread;
149extern unsigned long general_thread;
150extern unsigned long step_thread;
151extern unsigned long thread_from_wait;
152extern unsigned long old_thread_from_wait;
153extern int server_waiting;
154extern int debug_threads;
155extern int pass_signals[];
156
157extern jmp_buf toplevel;
158
159/* From remote-utils.c */
160
161extern int remote_debug;
162extern int all_symbols_looked_up;
163
164int putpkt (char *buf);
165int putpkt_binary (char *buf, int len);
166int getpkt (char *buf);
167void remote_open (char *name);
168void remote_close (void);
169void write_ok (char *buf);
170void write_enn (char *buf);
171void enable_async_io (void);
172void disable_async_io (void);
173void unblock_async_io (void);
174void block_async_io (void);
175void check_remote_input_interrupt_request (void);
176void convert_ascii_to_int (char *from, unsigned char *to, int n);
177void convert_int_to_ascii (unsigned char *from, char *to, int n);
178void new_thread_notify (int id);
179void dead_thread_notify (int id);
180void prepare_resume_reply (char *buf, char status, unsigned char sig);
181
182const char *decode_address_to_semicolon (CORE_ADDR *addrp, const char *start);
183void decode_address (CORE_ADDR *addrp, const char *start, int len);
184void decode_m_packet (char *from, CORE_ADDR * mem_addr_ptr,
185		      unsigned int *len_ptr);
186void decode_M_packet (char *from, CORE_ADDR * mem_addr_ptr,
187		      unsigned int *len_ptr, unsigned char *to);
188int decode_X_packet (char *from, int packet_len, CORE_ADDR * mem_addr_ptr,
189		     unsigned int *len_ptr, unsigned char *to);
190int decode_xfer_write (char *buf, int packet_len, char **annex,
191		       CORE_ADDR *offset, unsigned int *len,
192		       unsigned char *data);
193
194int unhexify (char *bin, const char *hex, int count);
195int hexify (char *hex, const char *bin, int count);
196int remote_escape_output (const gdb_byte *buffer, int len,
197			  gdb_byte *out_buf, int *out_len,
198			  int out_maxlen);
199
200int look_up_one_symbol (const char *name, CORE_ADDR *addrp);
201
202void monitor_output (const char *msg);
203
204char *xml_escape_text (const char *text);
205
206/* Functions from ``signals.c''.  */
207enum target_signal target_signal_from_host (int hostsig);
208int target_signal_to_host_p (enum target_signal oursig);
209int target_signal_to_host (enum target_signal oursig);
210char *target_signal_to_name (enum target_signal);
211
212/* Functions from utils.c */
213
214void perror_with_name (char *string);
215void error (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
216void fatal (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
217void warning (const char *string,...) ATTR_FORMAT (printf, 1, 2);
218
219/* Functions from the register cache definition.  */
220
221void init_registers (void);
222
223/* Maximum number of bytes to read/write at once.  The value here
224   is chosen to fill up a packet (the headers account for the 32).  */
225#define MAXBUFBYTES(N) (((N)-32)/2)
226
227/* Buffer sizes for transferring memory, registers, etc.  Round up PBUFSIZ to
228   hold all the registers, at least.  */
229#define	PBUFSIZ ((registers_length () + 32 > 2000) \
230		 ? (registers_length () + 32) \
231		 : 2000)
232
233/* Version information, from version.c.  */
234extern const char version[];
235extern const char host_name[];
236
237#endif /* SERVER_H */
238