1#ifndef GDBSTUB_H
2#define GDBSTUB_H
3
4#define DEFAULT_GDBSTUB_PORT "1234"
5
6
7#define GDB_BREAKPOINT_SW 0
8#define GDB_BREAKPOINT_HW 1
9#define GDB_WATCHPOINT_WRITE 2
10#define GDB_WATCHPOINT_READ 3
11#define GDB_WATCHPOINT_ACCESS 4
12
13
14#define GDB_O_RDONLY 0
15#define GDB_O_WRONLY 1
16#define GDB_O_RDWR 2
17#define GDB_O_APPEND 8
18#define GDB_O_CREAT 0x200
19#define GDB_O_TRUNC 0x400
20#define GDB_O_EXCL 0x800
21
22
23#define GDB_EPERM 1
24#define GDB_ENOENT 2
25#define GDB_EINTR 4
26#define GDB_EBADF 9
27#define GDB_EACCES 13
28#define GDB_EFAULT 14
29#define GDB_EBUSY 16
30#define GDB_EEXIST 17
31#define GDB_ENODEV 19
32#define GDB_ENOTDIR 20
33#define GDB_EISDIR 21
34#define GDB_EINVAL 22
35#define GDB_ENFILE 23
36#define GDB_EMFILE 24
37#define GDB_EFBIG 27
38#define GDB_ENOSPC 28
39#define GDB_ESPIPE 29
40#define GDB_EROFS 30
41#define GDB_ENAMETOOLONG 91
42#define GDB_EUNKNOWN 9999
43
44
45#define GDB_SEEK_SET 0
46#define GDB_SEEK_CUR 1
47#define GDB_SEEK_END 2
48
49
50typedef uint32_t gdb_mode_t;
51typedef uint32_t gdb_time_t;
52
53struct gdb_stat {
54 uint32_t gdb_st_dev;
55 uint32_t gdb_st_ino;
56 gdb_mode_t gdb_st_mode;
57 uint32_t gdb_st_nlink;
58 uint32_t gdb_st_uid;
59 uint32_t gdb_st_gid;
60 uint32_t gdb_st_rdev;
61 uint64_t gdb_st_size;
62 uint64_t gdb_st_blksize;
63 uint64_t gdb_st_blocks;
64 gdb_time_t gdb_st_atime;
65 gdb_time_t gdb_st_mtime;
66 gdb_time_t gdb_st_ctime;
67} QEMU_PACKED;
68
69struct gdb_timeval {
70 gdb_time_t tv_sec;
71 uint64_t tv_usec;
72} QEMU_PACKED;
73
74#ifdef NEED_CPU_H
75#include "cpu.h"
76
77typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, uint64_t ret, int err);
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);
97
98
99
100
101
102
103
104
105
106void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va);
107int use_gdb_syscalls(void);
108
109#ifdef CONFIG_USER_ONLY
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125int gdb_handlesig(CPUState *, int);
126void gdb_signalled(CPUArchState *, int);
127void gdbserver_fork(CPUState *);
128#endif
129
130typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg);
131typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg);
132void gdb_register_coprocessor(CPUState *cpu,
133 gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
134 int num_regs, const char *xml, int g_pos);
135
136
137
138
139
140
141
142static inline int gdb_get_reg8(GByteArray *buf, uint8_t val)
143{
144 g_byte_array_append(buf, &val, 1);
145 return 1;
146}
147
148static inline int gdb_get_reg16(GByteArray *buf, uint16_t val)
149{
150 uint16_t to_word = tswap16(val);
151 g_byte_array_append(buf, (uint8_t *) &to_word, 2);
152 return 2;
153}
154
155static inline int gdb_get_reg32(GByteArray *buf, uint32_t val)
156{
157 uint32_t to_long = tswap32(val);
158 g_byte_array_append(buf, (uint8_t *) &to_long, 4);
159 return 4;
160}
161
162static inline int gdb_get_reg64(GByteArray *buf, uint64_t val)
163{
164 uint64_t to_quad = tswap64(val);
165 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
166 return 8;
167}
168
169static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi,
170 uint64_t val_lo)
171{
172 uint64_t to_quad;
173#if TARGET_BIG_ENDIAN
174 to_quad = tswap64(val_hi);
175 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
176 to_quad = tswap64(val_lo);
177 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
178#else
179 to_quad = tswap64(val_lo);
180 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
181 to_quad = tswap64(val_hi);
182 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
183#endif
184 return 16;
185}
186
187static inline int gdb_get_zeroes(GByteArray *array, size_t len)
188{
189 guint oldlen = array->len;
190 g_byte_array_set_size(array, oldlen + len);
191 memset(array->data + oldlen, 0, len);
192
193 return len;
194}
195
196
197
198
199
200
201
202
203
204static inline uint8_t * gdb_get_reg_ptr(GByteArray *buf, int len)
205{
206 return buf->data + buf->len - len;
207}
208
209#if TARGET_LONG_BITS == 64
210#define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
211#define ldtul_p(addr) ldq_p(addr)
212#else
213#define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
214#define ldtul_p(addr) ldl_p(addr)
215#endif
216
217#endif
218
219
220
221
222
223
224
225
226
227int gdbserver_start(const char *port_or_device);
228
229
230
231
232
233
234
235
236
237void gdb_exit(int code);
238
239void gdb_set_stop_cpu(CPUState *cpu);
240
241
242
243
244
245
246
247extern bool gdb_has_xml;
248
249
250extern const char *const xml_builtin[][2];
251
252#endif
253