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#ifdef NEED_CPU_H
14#include "cpu.h"
15
16typedef void (*gdb_syscall_complete_cb)(CPUState *cpu,
17 target_ulong ret, target_ulong err);
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);
37
38
39
40
41
42
43
44
45
46void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va);
47int use_gdb_syscalls(void);
48
49#ifdef CONFIG_USER_ONLY
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65int gdb_handlesig(CPUState *, int);
66void gdb_signalled(CPUArchState *, int);
67void gdbserver_fork(CPUState *);
68#endif
69
70typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg);
71typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg);
72void gdb_register_coprocessor(CPUState *cpu,
73 gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
74 int num_regs, const char *xml, int g_pos);
75
76
77
78
79
80
81
82static inline int gdb_get_reg8(GByteArray *buf, uint8_t val)
83{
84 g_byte_array_append(buf, &val, 1);
85 return 1;
86}
87
88static inline int gdb_get_reg16(GByteArray *buf, uint16_t val)
89{
90 uint16_t to_word = tswap16(val);
91 g_byte_array_append(buf, (uint8_t *) &to_word, 2);
92 return 2;
93}
94
95static inline int gdb_get_reg32(GByteArray *buf, uint32_t val)
96{
97 uint32_t to_long = tswap32(val);
98 g_byte_array_append(buf, (uint8_t *) &to_long, 4);
99 return 4;
100}
101
102static inline int gdb_get_reg64(GByteArray *buf, uint64_t val)
103{
104 uint64_t to_quad = tswap64(val);
105 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
106 return 8;
107}
108
109static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi,
110 uint64_t val_lo)
111{
112 uint64_t to_quad;
113#ifdef TARGET_WORDS_BIGENDIAN
114 to_quad = tswap64(val_hi);
115 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
116 to_quad = tswap64(val_lo);
117 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
118#else
119 to_quad = tswap64(val_lo);
120 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
121 to_quad = tswap64(val_hi);
122 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
123#endif
124 return 16;
125}
126
127static inline int gdb_get_zeroes(GByteArray *array, size_t len)
128{
129 guint oldlen = array->len;
130 g_byte_array_set_size(array, oldlen + len);
131 memset(array->data + oldlen, 0, len);
132
133 return len;
134}
135
136
137
138
139
140
141
142
143
144static inline uint8_t * gdb_get_reg_ptr(GByteArray *buf, int len)
145{
146 return buf->data + buf->len - len;
147}
148
149#if TARGET_LONG_BITS == 64
150#define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
151#define ldtul_p(addr) ldq_p(addr)
152#else
153#define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
154#define ldtul_p(addr) ldl_p(addr)
155#endif
156
157#endif
158
159
160
161
162
163
164
165
166
167int gdbserver_start(const char *port_or_device);
168
169
170
171
172
173
174
175
176
177void gdb_exit(int code);
178
179void gdb_set_stop_cpu(CPUState *cpu);
180
181
182
183
184
185
186
187extern bool gdb_has_xml;
188
189
190extern const char *const xml_builtin[][2];
191
192#endif
193