root / gdbstub.c @ c321f673
History | View | Annotate | Download (11.9 kB)
1 | b4608c04 | bellard | /*
|
---|---|---|---|
2 | b4608c04 | bellard | * gdb server stub
|
3 | b4608c04 | bellard | *
|
4 | b4608c04 | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | b4608c04 | bellard | *
|
6 | b4608c04 | bellard | * This library is free software; you can redistribute it and/or
|
7 | b4608c04 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | b4608c04 | bellard | * License as published by the Free Software Foundation; either
|
9 | b4608c04 | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | b4608c04 | bellard | *
|
11 | b4608c04 | bellard | * This library is distributed in the hope that it will be useful,
|
12 | b4608c04 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | b4608c04 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | b4608c04 | bellard | * Lesser General Public License for more details.
|
15 | b4608c04 | bellard | *
|
16 | b4608c04 | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | b4608c04 | bellard | * License along with this library; if not, write to the Free Software
|
18 | b4608c04 | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | b4608c04 | bellard | */
|
20 | b4608c04 | bellard | #include <stdlib.h> |
21 | b4608c04 | bellard | #include <stdio.h> |
22 | b4608c04 | bellard | #include <string.h> |
23 | b4608c04 | bellard | #include <unistd.h> |
24 | b4608c04 | bellard | #include <errno.h> |
25 | b4608c04 | bellard | #include <sys/socket.h> |
26 | b4608c04 | bellard | #include <netinet/in.h> |
27 | b4608c04 | bellard | #include <netinet/tcp.h> |
28 | b4608c04 | bellard | #include <signal.h> |
29 | b4608c04 | bellard | |
30 | b4608c04 | bellard | #include "config.h" |
31 | 6180a181 | bellard | #include "cpu.h" |
32 | b4608c04 | bellard | #include "thunk.h" |
33 | 6180a181 | bellard | #include "exec-all.h" |
34 | b4608c04 | bellard | |
35 | 4abe615b | bellard | //#define DEBUG_GDB
|
36 | b4608c04 | bellard | |
37 | b4608c04 | bellard | int gdbstub_fd = -1; |
38 | b4608c04 | bellard | |
39 | b4608c04 | bellard | /* return 0 if OK */
|
40 | b4608c04 | bellard | static int gdbstub_open(int port) |
41 | b4608c04 | bellard | { |
42 | b4608c04 | bellard | struct sockaddr_in sockaddr;
|
43 | b4608c04 | bellard | socklen_t len; |
44 | b4608c04 | bellard | int fd, val, ret;
|
45 | b4608c04 | bellard | |
46 | b4608c04 | bellard | fd = socket(PF_INET, SOCK_STREAM, 0);
|
47 | b4608c04 | bellard | if (fd < 0) { |
48 | b4608c04 | bellard | perror("socket");
|
49 | b4608c04 | bellard | return -1; |
50 | b4608c04 | bellard | } |
51 | b4608c04 | bellard | |
52 | b4608c04 | bellard | /* allow fast reuse */
|
53 | b4608c04 | bellard | val = 1;
|
54 | b4608c04 | bellard | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
55 | b4608c04 | bellard | |
56 | b4608c04 | bellard | sockaddr.sin_family = AF_INET; |
57 | b4608c04 | bellard | sockaddr.sin_port = htons(port); |
58 | b4608c04 | bellard | sockaddr.sin_addr.s_addr = 0;
|
59 | b4608c04 | bellard | ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)); |
60 | b4608c04 | bellard | if (ret < 0) { |
61 | b4608c04 | bellard | perror("bind");
|
62 | b4608c04 | bellard | return -1; |
63 | b4608c04 | bellard | } |
64 | b4608c04 | bellard | ret = listen(fd, 0);
|
65 | b4608c04 | bellard | if (ret < 0) { |
66 | b4608c04 | bellard | perror("listen");
|
67 | b4608c04 | bellard | return -1; |
68 | b4608c04 | bellard | } |
69 | b4608c04 | bellard | |
70 | b4608c04 | bellard | /* now wait for one connection */
|
71 | b4608c04 | bellard | for(;;) {
|
72 | b4608c04 | bellard | len = sizeof(sockaddr);
|
73 | b4608c04 | bellard | gdbstub_fd = accept(fd, (struct sockaddr *)&sockaddr, &len);
|
74 | b4608c04 | bellard | if (gdbstub_fd < 0 && errno != EINTR) { |
75 | b4608c04 | bellard | perror("accept");
|
76 | b4608c04 | bellard | return -1; |
77 | b4608c04 | bellard | } else if (gdbstub_fd >= 0) { |
78 | b4608c04 | bellard | break;
|
79 | b4608c04 | bellard | } |
80 | b4608c04 | bellard | } |
81 | b4608c04 | bellard | |
82 | b4608c04 | bellard | /* set short latency */
|
83 | b4608c04 | bellard | val = 1;
|
84 | b4608c04 | bellard | setsockopt(gdbstub_fd, SOL_TCP, TCP_NODELAY, &val, sizeof(val));
|
85 | b4608c04 | bellard | return 0; |
86 | b4608c04 | bellard | } |
87 | b4608c04 | bellard | |
88 | b4608c04 | bellard | static int get_char(void) |
89 | b4608c04 | bellard | { |
90 | b4608c04 | bellard | uint8_t ch; |
91 | b4608c04 | bellard | int ret;
|
92 | b4608c04 | bellard | |
93 | b4608c04 | bellard | for(;;) {
|
94 | b4608c04 | bellard | ret = read(gdbstub_fd, &ch, 1);
|
95 | b4608c04 | bellard | if (ret < 0) { |
96 | b4608c04 | bellard | if (errno != EINTR && errno != EAGAIN)
|
97 | b4608c04 | bellard | return -1; |
98 | b4608c04 | bellard | } else if (ret == 0) { |
99 | b4608c04 | bellard | return -1; |
100 | b4608c04 | bellard | } else {
|
101 | b4608c04 | bellard | break;
|
102 | b4608c04 | bellard | } |
103 | b4608c04 | bellard | } |
104 | b4608c04 | bellard | return ch;
|
105 | b4608c04 | bellard | } |
106 | b4608c04 | bellard | |
107 | b4608c04 | bellard | static void put_buffer(const uint8_t *buf, int len) |
108 | b4608c04 | bellard | { |
109 | b4608c04 | bellard | int ret;
|
110 | b4608c04 | bellard | |
111 | b4608c04 | bellard | while (len > 0) { |
112 | b4608c04 | bellard | ret = write(gdbstub_fd, buf, len); |
113 | b4608c04 | bellard | if (ret < 0) { |
114 | b4608c04 | bellard | if (errno != EINTR && errno != EAGAIN)
|
115 | b4608c04 | bellard | return;
|
116 | b4608c04 | bellard | } else {
|
117 | b4608c04 | bellard | buf += ret; |
118 | b4608c04 | bellard | len -= ret; |
119 | b4608c04 | bellard | } |
120 | b4608c04 | bellard | } |
121 | b4608c04 | bellard | } |
122 | b4608c04 | bellard | |
123 | b4608c04 | bellard | static inline int fromhex(int v) |
124 | b4608c04 | bellard | { |
125 | b4608c04 | bellard | if (v >= '0' && v <= '9') |
126 | b4608c04 | bellard | return v - '0'; |
127 | b4608c04 | bellard | else if (v >= 'A' && v <= 'F') |
128 | b4608c04 | bellard | return v - 'A' + 10; |
129 | b4608c04 | bellard | else if (v >= 'a' && v <= 'f') |
130 | b4608c04 | bellard | return v - 'a' + 10; |
131 | b4608c04 | bellard | else
|
132 | b4608c04 | bellard | return 0; |
133 | b4608c04 | bellard | } |
134 | b4608c04 | bellard | |
135 | b4608c04 | bellard | static inline int tohex(int v) |
136 | b4608c04 | bellard | { |
137 | b4608c04 | bellard | if (v < 10) |
138 | b4608c04 | bellard | return v + '0'; |
139 | b4608c04 | bellard | else
|
140 | b4608c04 | bellard | return v - 10 + 'a'; |
141 | b4608c04 | bellard | } |
142 | b4608c04 | bellard | |
143 | b4608c04 | bellard | static void memtohex(char *buf, const uint8_t *mem, int len) |
144 | b4608c04 | bellard | { |
145 | b4608c04 | bellard | int i, c;
|
146 | b4608c04 | bellard | char *q;
|
147 | b4608c04 | bellard | q = buf; |
148 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
149 | b4608c04 | bellard | c = mem[i]; |
150 | b4608c04 | bellard | *q++ = tohex(c >> 4);
|
151 | b4608c04 | bellard | *q++ = tohex(c & 0xf);
|
152 | b4608c04 | bellard | } |
153 | b4608c04 | bellard | *q = '\0';
|
154 | b4608c04 | bellard | } |
155 | b4608c04 | bellard | |
156 | b4608c04 | bellard | static void hextomem(uint8_t *mem, const char *buf, int len) |
157 | b4608c04 | bellard | { |
158 | b4608c04 | bellard | int i;
|
159 | b4608c04 | bellard | |
160 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
161 | b4608c04 | bellard | mem[i] = (fromhex(buf[0]) << 4) | fromhex(buf[1]); |
162 | b4608c04 | bellard | buf += 2;
|
163 | b4608c04 | bellard | } |
164 | b4608c04 | bellard | } |
165 | b4608c04 | bellard | |
166 | b4608c04 | bellard | /* return -1 if error or EOF */
|
167 | b4608c04 | bellard | static int get_packet(char *buf, int buf_size) |
168 | b4608c04 | bellard | { |
169 | b4608c04 | bellard | int ch, len, csum, csum1;
|
170 | b4608c04 | bellard | char reply[1]; |
171 | b4608c04 | bellard | |
172 | b4608c04 | bellard | for(;;) {
|
173 | b4608c04 | bellard | for(;;) {
|
174 | b4608c04 | bellard | ch = get_char(); |
175 | b4608c04 | bellard | if (ch < 0) |
176 | b4608c04 | bellard | return -1; |
177 | b4608c04 | bellard | if (ch == '$') |
178 | b4608c04 | bellard | break;
|
179 | b4608c04 | bellard | } |
180 | b4608c04 | bellard | len = 0;
|
181 | b4608c04 | bellard | csum = 0;
|
182 | b4608c04 | bellard | for(;;) {
|
183 | b4608c04 | bellard | ch = get_char(); |
184 | b4608c04 | bellard | if (ch < 0) |
185 | b4608c04 | bellard | return -1; |
186 | b4608c04 | bellard | if (ch == '#') |
187 | b4608c04 | bellard | break;
|
188 | b4608c04 | bellard | if (len > buf_size - 1) |
189 | b4608c04 | bellard | return -1; |
190 | b4608c04 | bellard | buf[len++] = ch; |
191 | b4608c04 | bellard | csum += ch; |
192 | b4608c04 | bellard | } |
193 | b4608c04 | bellard | buf[len] = '\0';
|
194 | b4608c04 | bellard | ch = get_char(); |
195 | b4608c04 | bellard | if (ch < 0) |
196 | b4608c04 | bellard | return -1; |
197 | b4608c04 | bellard | csum1 = fromhex(ch) << 4;
|
198 | b4608c04 | bellard | ch = get_char(); |
199 | b4608c04 | bellard | if (ch < 0) |
200 | b4608c04 | bellard | return -1; |
201 | b4608c04 | bellard | csum1 |= fromhex(ch); |
202 | b4608c04 | bellard | if ((csum & 0xff) != csum1) { |
203 | b4608c04 | bellard | reply[0] = '-'; |
204 | b4608c04 | bellard | put_buffer(reply, 1);
|
205 | b4608c04 | bellard | } else {
|
206 | b4608c04 | bellard | reply[0] = '+'; |
207 | b4608c04 | bellard | put_buffer(reply, 1);
|
208 | b4608c04 | bellard | break;
|
209 | b4608c04 | bellard | } |
210 | b4608c04 | bellard | } |
211 | b4608c04 | bellard | #ifdef DEBUG_GDB
|
212 | b4608c04 | bellard | printf("command='%s'\n", buf);
|
213 | b4608c04 | bellard | #endif
|
214 | b4608c04 | bellard | return len;
|
215 | b4608c04 | bellard | } |
216 | b4608c04 | bellard | |
217 | b4608c04 | bellard | /* return -1 if error, 0 if OK */
|
218 | b4608c04 | bellard | static int put_packet(char *buf) |
219 | b4608c04 | bellard | { |
220 | b4608c04 | bellard | char buf1[3]; |
221 | b4608c04 | bellard | int len, csum, ch, i;
|
222 | b4608c04 | bellard | |
223 | b4608c04 | bellard | #ifdef DEBUG_GDB
|
224 | b4608c04 | bellard | printf("reply='%s'\n", buf);
|
225 | b4608c04 | bellard | #endif
|
226 | b4608c04 | bellard | |
227 | b4608c04 | bellard | for(;;) {
|
228 | b4608c04 | bellard | buf1[0] = '$'; |
229 | b4608c04 | bellard | put_buffer(buf1, 1);
|
230 | b4608c04 | bellard | len = strlen(buf); |
231 | b4608c04 | bellard | put_buffer(buf, len); |
232 | b4608c04 | bellard | csum = 0;
|
233 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
234 | b4608c04 | bellard | csum += buf[i]; |
235 | b4608c04 | bellard | } |
236 | b4608c04 | bellard | buf1[0] = '#'; |
237 | b4608c04 | bellard | buf1[1] = tohex((csum >> 4) & 0xf); |
238 | b4608c04 | bellard | buf1[2] = tohex((csum) & 0xf); |
239 | b4608c04 | bellard | |
240 | b4608c04 | bellard | put_buffer(buf1, 3);
|
241 | b4608c04 | bellard | |
242 | b4608c04 | bellard | ch = get_char(); |
243 | b4608c04 | bellard | if (ch < 0) |
244 | b4608c04 | bellard | return -1; |
245 | b4608c04 | bellard | if (ch == '+') |
246 | b4608c04 | bellard | break;
|
247 | b4608c04 | bellard | } |
248 | b4608c04 | bellard | return 0; |
249 | b4608c04 | bellard | } |
250 | b4608c04 | bellard | |
251 | b4608c04 | bellard | static int memory_rw(uint8_t *buf, uint32_t addr, int len, int is_write) |
252 | b4608c04 | bellard | { |
253 | b4608c04 | bellard | int l, flags;
|
254 | b4608c04 | bellard | uint32_t page; |
255 | b4608c04 | bellard | |
256 | b4608c04 | bellard | while (len > 0) { |
257 | b4608c04 | bellard | page = addr & TARGET_PAGE_MASK; |
258 | b4608c04 | bellard | l = (page + TARGET_PAGE_SIZE) - addr; |
259 | b4608c04 | bellard | if (l > len)
|
260 | b4608c04 | bellard | l = len; |
261 | b4608c04 | bellard | flags = page_get_flags(page); |
262 | b4608c04 | bellard | if (!(flags & PAGE_VALID))
|
263 | b4608c04 | bellard | return -1; |
264 | b4608c04 | bellard | if (is_write) {
|
265 | b4608c04 | bellard | if (!(flags & PAGE_WRITE))
|
266 | b4608c04 | bellard | return -1; |
267 | b4608c04 | bellard | memcpy((uint8_t *)addr, buf, l); |
268 | b4608c04 | bellard | } else {
|
269 | b4608c04 | bellard | if (!(flags & PAGE_READ))
|
270 | b4608c04 | bellard | return -1; |
271 | b4608c04 | bellard | memcpy(buf, (uint8_t *)addr, l); |
272 | b4608c04 | bellard | } |
273 | b4608c04 | bellard | len -= l; |
274 | b4608c04 | bellard | buf += l; |
275 | b4608c04 | bellard | addr += l; |
276 | b4608c04 | bellard | } |
277 | b4608c04 | bellard | return 0; |
278 | b4608c04 | bellard | } |
279 | b4608c04 | bellard | |
280 | b4608c04 | bellard | /* port = 0 means default port */
|
281 | 4c3a88a2 | bellard | int cpu_gdbstub(void *opaque, int (*main_loop)(void *opaque), int port) |
282 | b4608c04 | bellard | { |
283 | b4608c04 | bellard | CPUState *env; |
284 | b4608c04 | bellard | const char *p; |
285 | 4c3a88a2 | bellard | int ret, ch, nb_regs, i, type;
|
286 | b4608c04 | bellard | char buf[4096]; |
287 | b4608c04 | bellard | uint8_t mem_buf[2000];
|
288 | b4608c04 | bellard | uint32_t *registers; |
289 | b4608c04 | bellard | uint32_t addr, len; |
290 | b4608c04 | bellard | |
291 | b4608c04 | bellard | printf("Waiting gdb connection on port %d\n", port);
|
292 | b4608c04 | bellard | if (gdbstub_open(port) < 0) |
293 | b4608c04 | bellard | return -1; |
294 | b4608c04 | bellard | printf("Connected\n");
|
295 | b4608c04 | bellard | for(;;) {
|
296 | b4608c04 | bellard | ret = get_packet(buf, sizeof(buf));
|
297 | b4608c04 | bellard | if (ret < 0) |
298 | b4608c04 | bellard | break;
|
299 | b4608c04 | bellard | p = buf; |
300 | b4608c04 | bellard | ch = *p++; |
301 | b4608c04 | bellard | switch(ch) {
|
302 | b4608c04 | bellard | case '?': |
303 | b4608c04 | bellard | snprintf(buf, sizeof(buf), "S%02x", SIGTRAP); |
304 | b4608c04 | bellard | put_packet(buf); |
305 | b4608c04 | bellard | break;
|
306 | b4608c04 | bellard | case 'c': |
307 | 4c3a88a2 | bellard | if (*p != '\0') { |
308 | 4c3a88a2 | bellard | addr = strtoul(p, (char **)&p, 16); |
309 | 4c3a88a2 | bellard | env = cpu_gdbstub_get_env(opaque); |
310 | 4c3a88a2 | bellard | #if defined(TARGET_I386)
|
311 | 4c3a88a2 | bellard | env->eip = addr; |
312 | 4c3a88a2 | bellard | #endif
|
313 | 4c3a88a2 | bellard | } |
314 | 4c3a88a2 | bellard | ret = main_loop(opaque); |
315 | 4c3a88a2 | bellard | if (ret == EXCP_DEBUG)
|
316 | 4c3a88a2 | bellard | ret = SIGTRAP; |
317 | 4c3a88a2 | bellard | else
|
318 | 4c3a88a2 | bellard | ret = 0;
|
319 | 4c3a88a2 | bellard | snprintf(buf, sizeof(buf), "S%02x", ret); |
320 | b4608c04 | bellard | put_packet(buf); |
321 | b4608c04 | bellard | break;
|
322 | c33a346e | bellard | case 's': |
323 | c33a346e | bellard | env = cpu_gdbstub_get_env(opaque); |
324 | c33a346e | bellard | if (*p != '\0') { |
325 | c33a346e | bellard | addr = strtoul(p, (char **)&p, 16); |
326 | c33a346e | bellard | #if defined(TARGET_I386)
|
327 | c33a346e | bellard | env->eip = addr; |
328 | c33a346e | bellard | #endif
|
329 | c33a346e | bellard | } |
330 | c33a346e | bellard | cpu_single_step(env, 1);
|
331 | c33a346e | bellard | ret = main_loop(opaque); |
332 | c33a346e | bellard | cpu_single_step(env, 0);
|
333 | c33a346e | bellard | if (ret == EXCP_DEBUG)
|
334 | c33a346e | bellard | ret = SIGTRAP; |
335 | c33a346e | bellard | else
|
336 | c33a346e | bellard | ret = 0;
|
337 | c33a346e | bellard | snprintf(buf, sizeof(buf), "S%02x", ret); |
338 | c33a346e | bellard | put_packet(buf); |
339 | c33a346e | bellard | break;
|
340 | b4608c04 | bellard | case 'g': |
341 | b4608c04 | bellard | env = cpu_gdbstub_get_env(opaque); |
342 | b4608c04 | bellard | registers = (void *)mem_buf;
|
343 | b4608c04 | bellard | #if defined(TARGET_I386)
|
344 | b4608c04 | bellard | for(i = 0; i < 8; i++) { |
345 | b4608c04 | bellard | registers[i] = tswapl(env->regs[i]); |
346 | b4608c04 | bellard | } |
347 | b4608c04 | bellard | registers[8] = env->eip;
|
348 | b4608c04 | bellard | registers[9] = env->eflags;
|
349 | b4608c04 | bellard | registers[10] = env->segs[R_CS].selector;
|
350 | b4608c04 | bellard | registers[11] = env->segs[R_SS].selector;
|
351 | b4608c04 | bellard | registers[12] = env->segs[R_DS].selector;
|
352 | b4608c04 | bellard | registers[13] = env->segs[R_ES].selector;
|
353 | b4608c04 | bellard | registers[14] = env->segs[R_FS].selector;
|
354 | b4608c04 | bellard | registers[15] = env->segs[R_GS].selector;
|
355 | b4608c04 | bellard | nb_regs = 16;
|
356 | b4608c04 | bellard | #endif
|
357 | b4608c04 | bellard | memtohex(buf, (const uint8_t *)registers,
|
358 | b4608c04 | bellard | sizeof(registers[0]) * nb_regs); |
359 | b4608c04 | bellard | put_packet(buf); |
360 | b4608c04 | bellard | break;
|
361 | b4608c04 | bellard | case 'G': |
362 | b4608c04 | bellard | env = cpu_gdbstub_get_env(opaque); |
363 | b4608c04 | bellard | registers = (void *)mem_buf;
|
364 | b4608c04 | bellard | #if defined(TARGET_I386)
|
365 | b4608c04 | bellard | hextomem((uint8_t *)registers, p, 16 * 4); |
366 | b4608c04 | bellard | for(i = 0; i < 8; i++) { |
367 | b4608c04 | bellard | env->regs[i] = tswapl(registers[i]); |
368 | b4608c04 | bellard | } |
369 | b4608c04 | bellard | env->eip = registers[8];
|
370 | b4608c04 | bellard | env->eflags = registers[9];
|
371 | 03a6c510 | bellard | #if defined(CONFIG_USER_ONLY)
|
372 | b4608c04 | bellard | #define LOAD_SEG(index, sreg)\
|
373 | b4608c04 | bellard | if (tswapl(registers[index]) != env->segs[sreg].selector)\
|
374 | b4608c04 | bellard | cpu_x86_load_seg(env, sreg, tswapl(registers[index])); |
375 | b4608c04 | bellard | LOAD_SEG(10, R_CS);
|
376 | b4608c04 | bellard | LOAD_SEG(11, R_SS);
|
377 | b4608c04 | bellard | LOAD_SEG(12, R_DS);
|
378 | b4608c04 | bellard | LOAD_SEG(13, R_ES);
|
379 | b4608c04 | bellard | LOAD_SEG(14, R_FS);
|
380 | b4608c04 | bellard | LOAD_SEG(15, R_GS);
|
381 | b4608c04 | bellard | #endif
|
382 | 03a6c510 | bellard | #endif
|
383 | b4608c04 | bellard | put_packet("OK");
|
384 | b4608c04 | bellard | break;
|
385 | b4608c04 | bellard | case 'm': |
386 | b4608c04 | bellard | addr = strtoul(p, (char **)&p, 16); |
387 | b4608c04 | bellard | if (*p == ',') |
388 | b4608c04 | bellard | p++; |
389 | b4608c04 | bellard | len = strtoul(p, NULL, 16); |
390 | b4608c04 | bellard | if (memory_rw(mem_buf, addr, len, 0) != 0) |
391 | b4608c04 | bellard | memset(mem_buf, 0, len);
|
392 | b4608c04 | bellard | memtohex(buf, mem_buf, len); |
393 | b4608c04 | bellard | put_packet(buf); |
394 | b4608c04 | bellard | break;
|
395 | b4608c04 | bellard | case 'M': |
396 | b4608c04 | bellard | addr = strtoul(p, (char **)&p, 16); |
397 | b4608c04 | bellard | if (*p == ',') |
398 | b4608c04 | bellard | p++; |
399 | b4608c04 | bellard | len = strtoul(p, (char **)&p, 16); |
400 | b4608c04 | bellard | if (*p == ',') |
401 | b4608c04 | bellard | p++; |
402 | b4608c04 | bellard | hextomem(mem_buf, p, len); |
403 | b4608c04 | bellard | if (memory_rw(mem_buf, addr, len, 1) != 0) |
404 | b4608c04 | bellard | put_packet("ENN");
|
405 | b4608c04 | bellard | else
|
406 | b4608c04 | bellard | put_packet("OK");
|
407 | b4608c04 | bellard | break;
|
408 | 4c3a88a2 | bellard | case 'Z': |
409 | 4c3a88a2 | bellard | type = strtoul(p, (char **)&p, 16); |
410 | 4c3a88a2 | bellard | if (*p == ',') |
411 | 4c3a88a2 | bellard | p++; |
412 | 4c3a88a2 | bellard | addr = strtoul(p, (char **)&p, 16); |
413 | 4c3a88a2 | bellard | if (*p == ',') |
414 | 4c3a88a2 | bellard | p++; |
415 | 4c3a88a2 | bellard | len = strtoul(p, (char **)&p, 16); |
416 | 4c3a88a2 | bellard | if (type == 0 || type == 1) { |
417 | 4c3a88a2 | bellard | env = cpu_gdbstub_get_env(opaque); |
418 | 4c3a88a2 | bellard | if (cpu_breakpoint_insert(env, addr) < 0) |
419 | 4c3a88a2 | bellard | goto breakpoint_error;
|
420 | 4c3a88a2 | bellard | put_packet("OK");
|
421 | 4c3a88a2 | bellard | } else {
|
422 | 4c3a88a2 | bellard | breakpoint_error:
|
423 | 4c3a88a2 | bellard | put_packet("ENN");
|
424 | 4c3a88a2 | bellard | } |
425 | 4c3a88a2 | bellard | break;
|
426 | 4c3a88a2 | bellard | case 'z': |
427 | 4c3a88a2 | bellard | type = strtoul(p, (char **)&p, 16); |
428 | 4c3a88a2 | bellard | if (*p == ',') |
429 | 4c3a88a2 | bellard | p++; |
430 | 4c3a88a2 | bellard | addr = strtoul(p, (char **)&p, 16); |
431 | 4c3a88a2 | bellard | if (*p == ',') |
432 | 4c3a88a2 | bellard | p++; |
433 | 4c3a88a2 | bellard | len = strtoul(p, (char **)&p, 16); |
434 | 4c3a88a2 | bellard | if (type == 0 || type == 1) { |
435 | 4c3a88a2 | bellard | env = cpu_gdbstub_get_env(opaque); |
436 | 4c3a88a2 | bellard | cpu_breakpoint_remove(env, addr); |
437 | 4c3a88a2 | bellard | put_packet("OK");
|
438 | 4c3a88a2 | bellard | } else {
|
439 | 4c3a88a2 | bellard | goto breakpoint_error;
|
440 | 4c3a88a2 | bellard | } |
441 | 4c3a88a2 | bellard | break;
|
442 | 34865134 | bellard | case 'Q': |
443 | 34865134 | bellard | if (!strncmp(p, "Tinit", 5)) { |
444 | 34865134 | bellard | /* init traces */
|
445 | 34865134 | bellard | put_packet("OK");
|
446 | 34865134 | bellard | } else if (!strncmp(p, "TStart", 6)) { |
447 | 34865134 | bellard | /* start log (gdb 'tstart' command) */
|
448 | 34865134 | bellard | cpu_set_log(CPU_LOG_ALL); |
449 | 34865134 | bellard | put_packet("OK");
|
450 | 34865134 | bellard | } else if (!strncmp(p, "TStop", 5)) { |
451 | 34865134 | bellard | /* stop log (gdb 'tstop' command) */
|
452 | 34865134 | bellard | cpu_set_log(0);
|
453 | 34865134 | bellard | put_packet("OK");
|
454 | 34865134 | bellard | } else {
|
455 | 34865134 | bellard | goto unknown_command;
|
456 | 34865134 | bellard | } |
457 | 34865134 | bellard | break;
|
458 | b4608c04 | bellard | default:
|
459 | 34865134 | bellard | unknown_command:
|
460 | b4608c04 | bellard | /* put empty packet */
|
461 | b4608c04 | bellard | buf[0] = '\0'; |
462 | b4608c04 | bellard | put_packet(buf); |
463 | b4608c04 | bellard | break;
|
464 | b4608c04 | bellard | } |
465 | b4608c04 | bellard | } |
466 | b4608c04 | bellard | return 0; |
467 | b4608c04 | bellard | } |