1
2
3
4
5
6
7
8
9#ifndef GDBSTUB_INTERNALS_H
10#define GDBSTUB_INTERNALS_H
11
12#include "exec/cpu-common.h"
13
14#define MAX_PACKET_LENGTH 4096
15
16
17
18
19
20enum {
21 GDB_SIGNAL_0 = 0,
22 GDB_SIGNAL_INT = 2,
23 GDB_SIGNAL_QUIT = 3,
24 GDB_SIGNAL_TRAP = 5,
25 GDB_SIGNAL_ABRT = 6,
26 GDB_SIGNAL_ALRM = 14,
27 GDB_SIGNAL_IO = 23,
28 GDB_SIGNAL_XCPU = 24,
29 GDB_SIGNAL_UNKNOWN = 143
30};
31
32typedef struct GDBProcess {
33 uint32_t pid;
34 bool attached;
35
36 char target_xml[1024];
37} GDBProcess;
38
39enum RSState {
40 RS_INACTIVE,
41 RS_IDLE,
42 RS_GETLINE,
43 RS_GETLINE_ESC,
44 RS_GETLINE_RLE,
45 RS_CHKSUM1,
46 RS_CHKSUM2,
47};
48
49typedef struct GDBState {
50 bool init;
51 CPUState *c_cpu;
52 CPUState *g_cpu;
53 CPUState *query_cpu;
54 enum RSState state;
55 char line_buf[MAX_PACKET_LENGTH];
56 int line_buf_index;
57 int line_sum;
58 int line_csum;
59 GByteArray *last_packet;
60 int signal;
61 bool multiprocess;
62 GDBProcess *processes;
63 int process_num;
64 GString *str_buf;
65 GByteArray *mem_buf;
66 int sstep_flags;
67 int supported_sstep_flags;
68} GDBState;
69
70
71extern GDBState gdbserver_state;
72
73
74
75
76
77static inline int fromhex(int v)
78{
79 if (v >= '0' && v <= '9') {
80 return v - '0';
81 } else if (v >= 'A' && v <= 'F') {
82 return v - 'A' + 10;
83 } else if (v >= 'a' && v <= 'f') {
84 return v - 'a' + 10;
85 } else {
86 return 0;
87 }
88}
89
90static inline int tohex(int v)
91{
92 if (v < 10) {
93 return v + '0';
94 } else {
95 return v - 10 + 'a';
96 }
97}
98
99
100
101
102
103void gdb_put_strbuf(void);
104int gdb_put_packet(const char *buf);
105int gdb_put_packet_binary(const char *buf, int len, bool dump);
106void gdb_hextomem(GByteArray *mem, const char *buf, int len);
107void gdb_memtohex(GString *buf, const uint8_t *mem, int len);
108void gdb_memtox(GString *buf, const char *mem, int len);
109void gdb_read_byte(uint8_t ch);
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125bool gdb_got_immediate_ack(void);
126
127CPUState *gdb_first_attached_cpu(void);
128void gdb_append_thread_id(CPUState *cpu, GString *buf);
129int gdb_get_cpu_index(CPUState *cpu);
130unsigned int gdb_get_max_cpus(void);
131bool gdb_can_reverse(void);
132
133void gdb_create_default_process(GDBState *s);
134
135
136int gdb_signal_to_target(int sig);
137int gdb_target_signal_to_gdb(int sig);
138
139int gdb_get_char(void);
140
141
142
143
144void gdb_continue(void);
145
146
147
148
149int gdb_continue_partial(char *newstates);
150
151
152
153
154void gdb_put_buffer(const uint8_t *buf, int len);
155
156
157
158
159void gdb_init_gdbserver_state(void);
160
161typedef enum GDBThreadIdKind {
162 GDB_ONE_THREAD = 0,
163 GDB_ALL_THREADS,
164 GDB_ALL_PROCESSES,
165 GDB_READ_THREAD_ERR
166} GDBThreadIdKind;
167
168typedef union GdbCmdVariant {
169 const char *data;
170 uint8_t opcode;
171 unsigned long val_ul;
172 unsigned long long val_ull;
173 struct {
174 GDBThreadIdKind kind;
175 uint32_t pid;
176 uint32_t tid;
177 } thread_id;
178} GdbCmdVariant;
179
180#define get_param(p, i) (&g_array_index(p, GdbCmdVariant, i))
181
182void gdb_handle_query_rcmd(GArray *params, void *user_ctx);
183void gdb_handle_query_offsets(GArray *params, void *user_ctx);
184void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx);
185
186void gdb_handle_query_attached(GArray *params, void *user_ctx);
187
188
189void gdb_handle_query_qemu_phy_mem_mode(GArray *params, void *user_ctx);
190void gdb_handle_set_qemu_phy_mem_mode(GArray *params, void *user_ctx);
191
192
193void gdb_handle_file_io(GArray *params, void *user_ctx);
194bool gdb_handled_syscall(void);
195void gdb_disable_syscalls(void);
196void gdb_syscall_reset(void);
197
198
199void gdb_syscall_handling(const char *syscall_packet);
200
201
202
203
204
205bool gdb_supports_guest_debug(void);
206int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len);
207int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len);
208void gdb_breakpoint_remove_all(CPUState *cs);
209
210
211
212
213
214
215
216
217
218
219
220
221
222int gdb_target_memory_rw_debug(CPUState *cs, hwaddr addr,
223 uint8_t *buf, int len, bool is_write);
224
225#endif
226