root / gdbstub.c @ 5b50e790
History | View | Annotate | Download (43.6 kB)
1 | b4608c04 | bellard | /*
|
---|---|---|---|
2 | b4608c04 | bellard | * gdb server stub
|
3 | 5fafdf24 | ths | *
|
4 | 3475187d | bellard | * Copyright (c) 2003-2005 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 | 8167ee88 | Blue Swirl | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | b4608c04 | bellard | */
|
19 | 978efd6a | pbrook | #include "config.h" |
20 | 56aebc89 | pbrook | #include "qemu-common.h" |
21 | 1fddef4b | bellard | #ifdef CONFIG_USER_ONLY
|
22 | 1fddef4b | bellard | #include <stdlib.h> |
23 | 1fddef4b | bellard | #include <stdio.h> |
24 | 1fddef4b | bellard | #include <stdarg.h> |
25 | 1fddef4b | bellard | #include <string.h> |
26 | 1fddef4b | bellard | #include <errno.h> |
27 | 1fddef4b | bellard | #include <unistd.h> |
28 | 978efd6a | pbrook | #include <fcntl.h> |
29 | 1fddef4b | bellard | |
30 | 1fddef4b | bellard | #include "qemu.h" |
31 | 1fddef4b | bellard | #else
|
32 | 83c9089e | Paolo Bonzini | #include "monitor/monitor.h" |
33 | dccfcd0e | Paolo Bonzini | #include "sysemu/char.h" |
34 | 9c17d615 | Paolo Bonzini | #include "sysemu/sysemu.h" |
35 | 022c62cb | Paolo Bonzini | #include "exec/gdbstub.h" |
36 | 1fddef4b | bellard | #endif
|
37 | 67b915a5 | bellard | |
38 | 56aebc89 | pbrook | #define MAX_PACKET_LENGTH 4096 |
39 | 56aebc89 | pbrook | |
40 | 2b41f10e | Blue Swirl | #include "cpu.h" |
41 | 1de7afc9 | Paolo Bonzini | #include "qemu/sockets.h" |
42 | 9c17d615 | Paolo Bonzini | #include "sysemu/kvm.h" |
43 | ca587a8e | aurel32 | |
44 | f3659eee | Andreas Färber | static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr, |
45 | f3659eee | Andreas Färber | uint8_t *buf, int len, bool is_write) |
46 | 44520db1 | Fabien Chouteau | { |
47 | f3659eee | Andreas Färber | CPUClass *cc = CPU_GET_CLASS(cpu); |
48 | f3659eee | Andreas Färber | |
49 | f3659eee | Andreas Färber | if (cc->memory_rw_debug) {
|
50 | f3659eee | Andreas Färber | return cc->memory_rw_debug(cpu, addr, buf, len, is_write);
|
51 | f3659eee | Andreas Färber | } |
52 | f3659eee | Andreas Färber | return cpu_memory_rw_debug(cpu, addr, buf, len, is_write);
|
53 | 44520db1 | Fabien Chouteau | } |
54 | ca587a8e | aurel32 | |
55 | ca587a8e | aurel32 | enum {
|
56 | ca587a8e | aurel32 | GDB_SIGNAL_0 = 0,
|
57 | ca587a8e | aurel32 | GDB_SIGNAL_INT = 2,
|
58 | 425189a8 | Jan Kiszka | GDB_SIGNAL_QUIT = 3,
|
59 | ca587a8e | aurel32 | GDB_SIGNAL_TRAP = 5,
|
60 | 425189a8 | Jan Kiszka | GDB_SIGNAL_ABRT = 6,
|
61 | 425189a8 | Jan Kiszka | GDB_SIGNAL_ALRM = 14,
|
62 | 425189a8 | Jan Kiszka | GDB_SIGNAL_IO = 23,
|
63 | 425189a8 | Jan Kiszka | GDB_SIGNAL_XCPU = 24,
|
64 | ca587a8e | aurel32 | GDB_SIGNAL_UNKNOWN = 143
|
65 | ca587a8e | aurel32 | }; |
66 | ca587a8e | aurel32 | |
67 | ca587a8e | aurel32 | #ifdef CONFIG_USER_ONLY
|
68 | ca587a8e | aurel32 | |
69 | ca587a8e | aurel32 | /* Map target signal numbers to GDB protocol signal numbers and vice
|
70 | ca587a8e | aurel32 | * versa. For user emulation's currently supported systems, we can
|
71 | ca587a8e | aurel32 | * assume most signals are defined.
|
72 | ca587a8e | aurel32 | */
|
73 | ca587a8e | aurel32 | |
74 | ca587a8e | aurel32 | static int gdb_signal_table[] = { |
75 | ca587a8e | aurel32 | 0,
|
76 | ca587a8e | aurel32 | TARGET_SIGHUP, |
77 | ca587a8e | aurel32 | TARGET_SIGINT, |
78 | ca587a8e | aurel32 | TARGET_SIGQUIT, |
79 | ca587a8e | aurel32 | TARGET_SIGILL, |
80 | ca587a8e | aurel32 | TARGET_SIGTRAP, |
81 | ca587a8e | aurel32 | TARGET_SIGABRT, |
82 | ca587a8e | aurel32 | -1, /* SIGEMT */ |
83 | ca587a8e | aurel32 | TARGET_SIGFPE, |
84 | ca587a8e | aurel32 | TARGET_SIGKILL, |
85 | ca587a8e | aurel32 | TARGET_SIGBUS, |
86 | ca587a8e | aurel32 | TARGET_SIGSEGV, |
87 | ca587a8e | aurel32 | TARGET_SIGSYS, |
88 | ca587a8e | aurel32 | TARGET_SIGPIPE, |
89 | ca587a8e | aurel32 | TARGET_SIGALRM, |
90 | ca587a8e | aurel32 | TARGET_SIGTERM, |
91 | ca587a8e | aurel32 | TARGET_SIGURG, |
92 | ca587a8e | aurel32 | TARGET_SIGSTOP, |
93 | ca587a8e | aurel32 | TARGET_SIGTSTP, |
94 | ca587a8e | aurel32 | TARGET_SIGCONT, |
95 | ca587a8e | aurel32 | TARGET_SIGCHLD, |
96 | ca587a8e | aurel32 | TARGET_SIGTTIN, |
97 | ca587a8e | aurel32 | TARGET_SIGTTOU, |
98 | ca587a8e | aurel32 | TARGET_SIGIO, |
99 | ca587a8e | aurel32 | TARGET_SIGXCPU, |
100 | ca587a8e | aurel32 | TARGET_SIGXFSZ, |
101 | ca587a8e | aurel32 | TARGET_SIGVTALRM, |
102 | ca587a8e | aurel32 | TARGET_SIGPROF, |
103 | ca587a8e | aurel32 | TARGET_SIGWINCH, |
104 | ca587a8e | aurel32 | -1, /* SIGLOST */ |
105 | ca587a8e | aurel32 | TARGET_SIGUSR1, |
106 | ca587a8e | aurel32 | TARGET_SIGUSR2, |
107 | c72d5bf8 | blueswir1 | #ifdef TARGET_SIGPWR
|
108 | ca587a8e | aurel32 | TARGET_SIGPWR, |
109 | c72d5bf8 | blueswir1 | #else
|
110 | c72d5bf8 | blueswir1 | -1,
|
111 | c72d5bf8 | blueswir1 | #endif
|
112 | ca587a8e | aurel32 | -1, /* SIGPOLL */ |
113 | ca587a8e | aurel32 | -1,
|
114 | ca587a8e | aurel32 | -1,
|
115 | ca587a8e | aurel32 | -1,
|
116 | ca587a8e | aurel32 | -1,
|
117 | ca587a8e | aurel32 | -1,
|
118 | ca587a8e | aurel32 | -1,
|
119 | ca587a8e | aurel32 | -1,
|
120 | ca587a8e | aurel32 | -1,
|
121 | ca587a8e | aurel32 | -1,
|
122 | ca587a8e | aurel32 | -1,
|
123 | ca587a8e | aurel32 | -1,
|
124 | c72d5bf8 | blueswir1 | #ifdef __SIGRTMIN
|
125 | ca587a8e | aurel32 | __SIGRTMIN + 1,
|
126 | ca587a8e | aurel32 | __SIGRTMIN + 2,
|
127 | ca587a8e | aurel32 | __SIGRTMIN + 3,
|
128 | ca587a8e | aurel32 | __SIGRTMIN + 4,
|
129 | ca587a8e | aurel32 | __SIGRTMIN + 5,
|
130 | ca587a8e | aurel32 | __SIGRTMIN + 6,
|
131 | ca587a8e | aurel32 | __SIGRTMIN + 7,
|
132 | ca587a8e | aurel32 | __SIGRTMIN + 8,
|
133 | ca587a8e | aurel32 | __SIGRTMIN + 9,
|
134 | ca587a8e | aurel32 | __SIGRTMIN + 10,
|
135 | ca587a8e | aurel32 | __SIGRTMIN + 11,
|
136 | ca587a8e | aurel32 | __SIGRTMIN + 12,
|
137 | ca587a8e | aurel32 | __SIGRTMIN + 13,
|
138 | ca587a8e | aurel32 | __SIGRTMIN + 14,
|
139 | ca587a8e | aurel32 | __SIGRTMIN + 15,
|
140 | ca587a8e | aurel32 | __SIGRTMIN + 16,
|
141 | ca587a8e | aurel32 | __SIGRTMIN + 17,
|
142 | ca587a8e | aurel32 | __SIGRTMIN + 18,
|
143 | ca587a8e | aurel32 | __SIGRTMIN + 19,
|
144 | ca587a8e | aurel32 | __SIGRTMIN + 20,
|
145 | ca587a8e | aurel32 | __SIGRTMIN + 21,
|
146 | ca587a8e | aurel32 | __SIGRTMIN + 22,
|
147 | ca587a8e | aurel32 | __SIGRTMIN + 23,
|
148 | ca587a8e | aurel32 | __SIGRTMIN + 24,
|
149 | ca587a8e | aurel32 | __SIGRTMIN + 25,
|
150 | ca587a8e | aurel32 | __SIGRTMIN + 26,
|
151 | ca587a8e | aurel32 | __SIGRTMIN + 27,
|
152 | ca587a8e | aurel32 | __SIGRTMIN + 28,
|
153 | ca587a8e | aurel32 | __SIGRTMIN + 29,
|
154 | ca587a8e | aurel32 | __SIGRTMIN + 30,
|
155 | ca587a8e | aurel32 | __SIGRTMIN + 31,
|
156 | ca587a8e | aurel32 | -1, /* SIGCANCEL */ |
157 | ca587a8e | aurel32 | __SIGRTMIN, |
158 | ca587a8e | aurel32 | __SIGRTMIN + 32,
|
159 | ca587a8e | aurel32 | __SIGRTMIN + 33,
|
160 | ca587a8e | aurel32 | __SIGRTMIN + 34,
|
161 | ca587a8e | aurel32 | __SIGRTMIN + 35,
|
162 | ca587a8e | aurel32 | __SIGRTMIN + 36,
|
163 | ca587a8e | aurel32 | __SIGRTMIN + 37,
|
164 | ca587a8e | aurel32 | __SIGRTMIN + 38,
|
165 | ca587a8e | aurel32 | __SIGRTMIN + 39,
|
166 | ca587a8e | aurel32 | __SIGRTMIN + 40,
|
167 | ca587a8e | aurel32 | __SIGRTMIN + 41,
|
168 | ca587a8e | aurel32 | __SIGRTMIN + 42,
|
169 | ca587a8e | aurel32 | __SIGRTMIN + 43,
|
170 | ca587a8e | aurel32 | __SIGRTMIN + 44,
|
171 | ca587a8e | aurel32 | __SIGRTMIN + 45,
|
172 | ca587a8e | aurel32 | __SIGRTMIN + 46,
|
173 | ca587a8e | aurel32 | __SIGRTMIN + 47,
|
174 | ca587a8e | aurel32 | __SIGRTMIN + 48,
|
175 | ca587a8e | aurel32 | __SIGRTMIN + 49,
|
176 | ca587a8e | aurel32 | __SIGRTMIN + 50,
|
177 | ca587a8e | aurel32 | __SIGRTMIN + 51,
|
178 | ca587a8e | aurel32 | __SIGRTMIN + 52,
|
179 | ca587a8e | aurel32 | __SIGRTMIN + 53,
|
180 | ca587a8e | aurel32 | __SIGRTMIN + 54,
|
181 | ca587a8e | aurel32 | __SIGRTMIN + 55,
|
182 | ca587a8e | aurel32 | __SIGRTMIN + 56,
|
183 | ca587a8e | aurel32 | __SIGRTMIN + 57,
|
184 | ca587a8e | aurel32 | __SIGRTMIN + 58,
|
185 | ca587a8e | aurel32 | __SIGRTMIN + 59,
|
186 | ca587a8e | aurel32 | __SIGRTMIN + 60,
|
187 | ca587a8e | aurel32 | __SIGRTMIN + 61,
|
188 | ca587a8e | aurel32 | __SIGRTMIN + 62,
|
189 | ca587a8e | aurel32 | __SIGRTMIN + 63,
|
190 | ca587a8e | aurel32 | __SIGRTMIN + 64,
|
191 | ca587a8e | aurel32 | __SIGRTMIN + 65,
|
192 | ca587a8e | aurel32 | __SIGRTMIN + 66,
|
193 | ca587a8e | aurel32 | __SIGRTMIN + 67,
|
194 | ca587a8e | aurel32 | __SIGRTMIN + 68,
|
195 | ca587a8e | aurel32 | __SIGRTMIN + 69,
|
196 | ca587a8e | aurel32 | __SIGRTMIN + 70,
|
197 | ca587a8e | aurel32 | __SIGRTMIN + 71,
|
198 | ca587a8e | aurel32 | __SIGRTMIN + 72,
|
199 | ca587a8e | aurel32 | __SIGRTMIN + 73,
|
200 | ca587a8e | aurel32 | __SIGRTMIN + 74,
|
201 | ca587a8e | aurel32 | __SIGRTMIN + 75,
|
202 | ca587a8e | aurel32 | __SIGRTMIN + 76,
|
203 | ca587a8e | aurel32 | __SIGRTMIN + 77,
|
204 | ca587a8e | aurel32 | __SIGRTMIN + 78,
|
205 | ca587a8e | aurel32 | __SIGRTMIN + 79,
|
206 | ca587a8e | aurel32 | __SIGRTMIN + 80,
|
207 | ca587a8e | aurel32 | __SIGRTMIN + 81,
|
208 | ca587a8e | aurel32 | __SIGRTMIN + 82,
|
209 | ca587a8e | aurel32 | __SIGRTMIN + 83,
|
210 | ca587a8e | aurel32 | __SIGRTMIN + 84,
|
211 | ca587a8e | aurel32 | __SIGRTMIN + 85,
|
212 | ca587a8e | aurel32 | __SIGRTMIN + 86,
|
213 | ca587a8e | aurel32 | __SIGRTMIN + 87,
|
214 | ca587a8e | aurel32 | __SIGRTMIN + 88,
|
215 | ca587a8e | aurel32 | __SIGRTMIN + 89,
|
216 | ca587a8e | aurel32 | __SIGRTMIN + 90,
|
217 | ca587a8e | aurel32 | __SIGRTMIN + 91,
|
218 | ca587a8e | aurel32 | __SIGRTMIN + 92,
|
219 | ca587a8e | aurel32 | __SIGRTMIN + 93,
|
220 | ca587a8e | aurel32 | __SIGRTMIN + 94,
|
221 | ca587a8e | aurel32 | __SIGRTMIN + 95,
|
222 | ca587a8e | aurel32 | -1, /* SIGINFO */ |
223 | ca587a8e | aurel32 | -1, /* UNKNOWN */ |
224 | ca587a8e | aurel32 | -1, /* DEFAULT */ |
225 | ca587a8e | aurel32 | -1,
|
226 | ca587a8e | aurel32 | -1,
|
227 | ca587a8e | aurel32 | -1,
|
228 | ca587a8e | aurel32 | -1,
|
229 | ca587a8e | aurel32 | -1,
|
230 | ca587a8e | aurel32 | -1
|
231 | c72d5bf8 | blueswir1 | #endif
|
232 | ca587a8e | aurel32 | }; |
233 | 8f447cc7 | bellard | #else
|
234 | ca587a8e | aurel32 | /* In system mode we only need SIGINT and SIGTRAP; other signals
|
235 | ca587a8e | aurel32 | are not yet supported. */
|
236 | ca587a8e | aurel32 | |
237 | ca587a8e | aurel32 | enum {
|
238 | ca587a8e | aurel32 | TARGET_SIGINT = 2,
|
239 | ca587a8e | aurel32 | TARGET_SIGTRAP = 5
|
240 | ca587a8e | aurel32 | }; |
241 | ca587a8e | aurel32 | |
242 | ca587a8e | aurel32 | static int gdb_signal_table[] = { |
243 | ca587a8e | aurel32 | -1,
|
244 | ca587a8e | aurel32 | -1,
|
245 | ca587a8e | aurel32 | TARGET_SIGINT, |
246 | ca587a8e | aurel32 | -1,
|
247 | ca587a8e | aurel32 | -1,
|
248 | ca587a8e | aurel32 | TARGET_SIGTRAP |
249 | ca587a8e | aurel32 | }; |
250 | ca587a8e | aurel32 | #endif
|
251 | ca587a8e | aurel32 | |
252 | ca587a8e | aurel32 | #ifdef CONFIG_USER_ONLY
|
253 | ca587a8e | aurel32 | static int target_signal_to_gdb (int sig) |
254 | ca587a8e | aurel32 | { |
255 | ca587a8e | aurel32 | int i;
|
256 | ca587a8e | aurel32 | for (i = 0; i < ARRAY_SIZE (gdb_signal_table); i++) |
257 | ca587a8e | aurel32 | if (gdb_signal_table[i] == sig)
|
258 | ca587a8e | aurel32 | return i;
|
259 | ca587a8e | aurel32 | return GDB_SIGNAL_UNKNOWN;
|
260 | ca587a8e | aurel32 | } |
261 | 8f447cc7 | bellard | #endif
|
262 | b4608c04 | bellard | |
263 | ca587a8e | aurel32 | static int gdb_signal_to_target (int sig) |
264 | ca587a8e | aurel32 | { |
265 | ca587a8e | aurel32 | if (sig < ARRAY_SIZE (gdb_signal_table))
|
266 | ca587a8e | aurel32 | return gdb_signal_table[sig];
|
267 | ca587a8e | aurel32 | else
|
268 | ca587a8e | aurel32 | return -1; |
269 | ca587a8e | aurel32 | } |
270 | ca587a8e | aurel32 | |
271 | 4abe615b | bellard | //#define DEBUG_GDB
|
272 | b4608c04 | bellard | |
273 | 56aebc89 | pbrook | typedef struct GDBRegisterState { |
274 | 56aebc89 | pbrook | int base_reg;
|
275 | 56aebc89 | pbrook | int num_regs;
|
276 | 56aebc89 | pbrook | gdb_reg_cb get_reg; |
277 | 56aebc89 | pbrook | gdb_reg_cb set_reg; |
278 | 56aebc89 | pbrook | const char *xml; |
279 | 56aebc89 | pbrook | struct GDBRegisterState *next;
|
280 | 56aebc89 | pbrook | } GDBRegisterState; |
281 | 56aebc89 | pbrook | |
282 | 858693c6 | bellard | enum RSState {
|
283 | 36556b20 | aliguori | RS_INACTIVE, |
284 | 858693c6 | bellard | RS_IDLE, |
285 | 858693c6 | bellard | RS_GETLINE, |
286 | 858693c6 | bellard | RS_CHKSUM1, |
287 | 858693c6 | bellard | RS_CHKSUM2, |
288 | 858693c6 | bellard | }; |
289 | 858693c6 | bellard | typedef struct GDBState { |
290 | 2e0f2cfb | Andreas Färber | CPUState *c_cpu; /* current CPU for step/continue ops */
|
291 | 2e0f2cfb | Andreas Färber | CPUState *g_cpu; /* current CPU for other ops */
|
292 | 52f34623 | Andreas Färber | CPUState *query_cpu; /* for q{f|s}ThreadInfo */
|
293 | 41625033 | bellard | enum RSState state; /* parsing state */ |
294 | 56aebc89 | pbrook | char line_buf[MAX_PACKET_LENGTH];
|
295 | 858693c6 | bellard | int line_buf_index;
|
296 | 858693c6 | bellard | int line_csum;
|
297 | 56aebc89 | pbrook | uint8_t last_packet[MAX_PACKET_LENGTH + 4];
|
298 | 4046d913 | pbrook | int last_packet_len;
|
299 | 1f487ee9 | edgar_igl | int signal;
|
300 | 41625033 | bellard | #ifdef CONFIG_USER_ONLY
|
301 | 4046d913 | pbrook | int fd;
|
302 | 41625033 | bellard | int running_state;
|
303 | 4046d913 | pbrook | #else
|
304 | 4046d913 | pbrook | CharDriverState *chr; |
305 | 8a34a0fb | aliguori | CharDriverState *mon_chr; |
306 | 41625033 | bellard | #endif
|
307 | cdb432b2 | Meador Inge | char syscall_buf[256]; |
308 | cdb432b2 | Meador Inge | gdb_syscall_complete_cb current_syscall_cb; |
309 | 858693c6 | bellard | } GDBState; |
310 | b4608c04 | bellard | |
311 | 60897d36 | edgar_igl | /* By default use no IRQs and no timers while single stepping so as to
|
312 | 60897d36 | edgar_igl | * make single stepping like an ICE HW step.
|
313 | 60897d36 | edgar_igl | */
|
314 | 60897d36 | edgar_igl | static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; |
315 | 60897d36 | edgar_igl | |
316 | 880a7578 | aliguori | static GDBState *gdbserver_state;
|
317 | 880a7578 | aliguori | |
318 | 5b50e790 | Andreas Färber | bool gdb_has_xml;
|
319 | 56aebc89 | pbrook | |
320 | 1fddef4b | bellard | #ifdef CONFIG_USER_ONLY
|
321 | 4046d913 | pbrook | /* XXX: This is not thread safe. Do we care? */
|
322 | 4046d913 | pbrook | static int gdbserver_fd = -1; |
323 | 4046d913 | pbrook | |
324 | 858693c6 | bellard | static int get_char(GDBState *s) |
325 | b4608c04 | bellard | { |
326 | b4608c04 | bellard | uint8_t ch; |
327 | b4608c04 | bellard | int ret;
|
328 | b4608c04 | bellard | |
329 | b4608c04 | bellard | for(;;) {
|
330 | 00aa0040 | Blue Swirl | ret = qemu_recv(s->fd, &ch, 1, 0); |
331 | b4608c04 | bellard | if (ret < 0) { |
332 | 1f487ee9 | edgar_igl | if (errno == ECONNRESET)
|
333 | 1f487ee9 | edgar_igl | s->fd = -1;
|
334 | b4608c04 | bellard | if (errno != EINTR && errno != EAGAIN)
|
335 | b4608c04 | bellard | return -1; |
336 | b4608c04 | bellard | } else if (ret == 0) { |
337 | 1f487ee9 | edgar_igl | close(s->fd); |
338 | 1f487ee9 | edgar_igl | s->fd = -1;
|
339 | b4608c04 | bellard | return -1; |
340 | b4608c04 | bellard | } else {
|
341 | b4608c04 | bellard | break;
|
342 | b4608c04 | bellard | } |
343 | b4608c04 | bellard | } |
344 | b4608c04 | bellard | return ch;
|
345 | b4608c04 | bellard | } |
346 | 4046d913 | pbrook | #endif
|
347 | b4608c04 | bellard | |
348 | 654efcf3 | blueswir1 | static enum { |
349 | a2d1ebaf | pbrook | GDB_SYS_UNKNOWN, |
350 | a2d1ebaf | pbrook | GDB_SYS_ENABLED, |
351 | a2d1ebaf | pbrook | GDB_SYS_DISABLED, |
352 | a2d1ebaf | pbrook | } gdb_syscall_mode; |
353 | a2d1ebaf | pbrook | |
354 | a2d1ebaf | pbrook | /* If gdb is connected when the first semihosting syscall occurs then use
|
355 | a2d1ebaf | pbrook | remote gdb syscalls. Otherwise use native file IO. */
|
356 | a2d1ebaf | pbrook | int use_gdb_syscalls(void) |
357 | a2d1ebaf | pbrook | { |
358 | a2d1ebaf | pbrook | if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
|
359 | 880a7578 | aliguori | gdb_syscall_mode = (gdbserver_state ? GDB_SYS_ENABLED |
360 | 880a7578 | aliguori | : GDB_SYS_DISABLED); |
361 | a2d1ebaf | pbrook | } |
362 | a2d1ebaf | pbrook | return gdb_syscall_mode == GDB_SYS_ENABLED;
|
363 | a2d1ebaf | pbrook | } |
364 | a2d1ebaf | pbrook | |
365 | ba70a624 | edgar_igl | /* Resume execution. */
|
366 | ba70a624 | edgar_igl | static inline void gdb_continue(GDBState *s) |
367 | ba70a624 | edgar_igl | { |
368 | ba70a624 | edgar_igl | #ifdef CONFIG_USER_ONLY
|
369 | ba70a624 | edgar_igl | s->running_state = 1;
|
370 | ba70a624 | edgar_igl | #else
|
371 | bc7d0e66 | Paolo Bonzini | if (runstate_check(RUN_STATE_GUEST_PANICKED)) {
|
372 | bc7d0e66 | Paolo Bonzini | runstate_set(RUN_STATE_DEBUG); |
373 | bc7d0e66 | Paolo Bonzini | } |
374 | 26ac7a31 | Paolo Bonzini | if (!runstate_needs_reset()) {
|
375 | 87f25c12 | Paolo Bonzini | vm_start(); |
376 | 87f25c12 | Paolo Bonzini | } |
377 | ba70a624 | edgar_igl | #endif
|
378 | ba70a624 | edgar_igl | } |
379 | ba70a624 | edgar_igl | |
380 | 858693c6 | bellard | static void put_buffer(GDBState *s, const uint8_t *buf, int len) |
381 | b4608c04 | bellard | { |
382 | 4046d913 | pbrook | #ifdef CONFIG_USER_ONLY
|
383 | b4608c04 | bellard | int ret;
|
384 | b4608c04 | bellard | |
385 | b4608c04 | bellard | while (len > 0) { |
386 | 8f447cc7 | bellard | ret = send(s->fd, buf, len, 0);
|
387 | b4608c04 | bellard | if (ret < 0) { |
388 | b4608c04 | bellard | if (errno != EINTR && errno != EAGAIN)
|
389 | b4608c04 | bellard | return;
|
390 | b4608c04 | bellard | } else {
|
391 | b4608c04 | bellard | buf += ret; |
392 | b4608c04 | bellard | len -= ret; |
393 | b4608c04 | bellard | } |
394 | b4608c04 | bellard | } |
395 | 4046d913 | pbrook | #else
|
396 | 2cc6e0a1 | Anthony Liguori | qemu_chr_fe_write(s->chr, buf, len); |
397 | 4046d913 | pbrook | #endif
|
398 | b4608c04 | bellard | } |
399 | b4608c04 | bellard | |
400 | b4608c04 | bellard | static inline int fromhex(int v) |
401 | b4608c04 | bellard | { |
402 | b4608c04 | bellard | if (v >= '0' && v <= '9') |
403 | b4608c04 | bellard | return v - '0'; |
404 | b4608c04 | bellard | else if (v >= 'A' && v <= 'F') |
405 | b4608c04 | bellard | return v - 'A' + 10; |
406 | b4608c04 | bellard | else if (v >= 'a' && v <= 'f') |
407 | b4608c04 | bellard | return v - 'a' + 10; |
408 | b4608c04 | bellard | else
|
409 | b4608c04 | bellard | return 0; |
410 | b4608c04 | bellard | } |
411 | b4608c04 | bellard | |
412 | b4608c04 | bellard | static inline int tohex(int v) |
413 | b4608c04 | bellard | { |
414 | b4608c04 | bellard | if (v < 10) |
415 | b4608c04 | bellard | return v + '0'; |
416 | b4608c04 | bellard | else
|
417 | b4608c04 | bellard | return v - 10 + 'a'; |
418 | b4608c04 | bellard | } |
419 | b4608c04 | bellard | |
420 | b4608c04 | bellard | static void memtohex(char *buf, const uint8_t *mem, int len) |
421 | b4608c04 | bellard | { |
422 | b4608c04 | bellard | int i, c;
|
423 | b4608c04 | bellard | char *q;
|
424 | b4608c04 | bellard | q = buf; |
425 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
426 | b4608c04 | bellard | c = mem[i]; |
427 | b4608c04 | bellard | *q++ = tohex(c >> 4);
|
428 | b4608c04 | bellard | *q++ = tohex(c & 0xf);
|
429 | b4608c04 | bellard | } |
430 | b4608c04 | bellard | *q = '\0';
|
431 | b4608c04 | bellard | } |
432 | b4608c04 | bellard | |
433 | b4608c04 | bellard | static void hextomem(uint8_t *mem, const char *buf, int len) |
434 | b4608c04 | bellard | { |
435 | b4608c04 | bellard | int i;
|
436 | b4608c04 | bellard | |
437 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
438 | b4608c04 | bellard | mem[i] = (fromhex(buf[0]) << 4) | fromhex(buf[1]); |
439 | b4608c04 | bellard | buf += 2;
|
440 | b4608c04 | bellard | } |
441 | b4608c04 | bellard | } |
442 | b4608c04 | bellard | |
443 | b4608c04 | bellard | /* return -1 if error, 0 if OK */
|
444 | 56aebc89 | pbrook | static int put_packet_binary(GDBState *s, const char *buf, int len) |
445 | b4608c04 | bellard | { |
446 | 56aebc89 | pbrook | int csum, i;
|
447 | 60fe76f3 | ths | uint8_t *p; |
448 | b4608c04 | bellard | |
449 | b4608c04 | bellard | for(;;) {
|
450 | 4046d913 | pbrook | p = s->last_packet; |
451 | 4046d913 | pbrook | *(p++) = '$';
|
452 | 4046d913 | pbrook | memcpy(p, buf, len); |
453 | 4046d913 | pbrook | p += len; |
454 | b4608c04 | bellard | csum = 0;
|
455 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
456 | b4608c04 | bellard | csum += buf[i]; |
457 | b4608c04 | bellard | } |
458 | 4046d913 | pbrook | *(p++) = '#';
|
459 | 4046d913 | pbrook | *(p++) = tohex((csum >> 4) & 0xf); |
460 | 4046d913 | pbrook | *(p++) = tohex((csum) & 0xf);
|
461 | b4608c04 | bellard | |
462 | 4046d913 | pbrook | s->last_packet_len = p - s->last_packet; |
463 | ffe8ab83 | ths | put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); |
464 | b4608c04 | bellard | |
465 | 4046d913 | pbrook | #ifdef CONFIG_USER_ONLY
|
466 | 4046d913 | pbrook | i = get_char(s); |
467 | 4046d913 | pbrook | if (i < 0) |
468 | b4608c04 | bellard | return -1; |
469 | 4046d913 | pbrook | if (i == '+') |
470 | b4608c04 | bellard | break;
|
471 | 4046d913 | pbrook | #else
|
472 | 4046d913 | pbrook | break;
|
473 | 4046d913 | pbrook | #endif
|
474 | b4608c04 | bellard | } |
475 | b4608c04 | bellard | return 0; |
476 | b4608c04 | bellard | } |
477 | b4608c04 | bellard | |
478 | 56aebc89 | pbrook | /* return -1 if error, 0 if OK */
|
479 | 56aebc89 | pbrook | static int put_packet(GDBState *s, const char *buf) |
480 | 56aebc89 | pbrook | { |
481 | 56aebc89 | pbrook | #ifdef DEBUG_GDB
|
482 | 56aebc89 | pbrook | printf("reply='%s'\n", buf);
|
483 | 56aebc89 | pbrook | #endif
|
484 | 79808573 | bellard | |
485 | 56aebc89 | pbrook | return put_packet_binary(s, buf, strlen(buf));
|
486 | 56aebc89 | pbrook | } |
487 | 56aebc89 | pbrook | |
488 | 5b50e790 | Andreas Färber | #if defined(TARGET_PPC)
|
489 | 9e62fd7f | bellard | |
490 | e571cb47 | aurel32 | #if defined (TARGET_PPC64)
|
491 | e571cb47 | aurel32 | #define GDB_CORE_XML "power64-core.xml" |
492 | e571cb47 | aurel32 | #else
|
493 | e571cb47 | aurel32 | #define GDB_CORE_XML "power-core.xml" |
494 | e571cb47 | aurel32 | #endif
|
495 | 9e62fd7f | bellard | |
496 | 1fddef4b | bellard | #elif defined (TARGET_ARM)
|
497 | 6da41eaf | bellard | |
498 | 56aebc89 | pbrook | #define GDB_CORE_XML "arm-core.xml" |
499 | e6e5906b | pbrook | |
500 | 56aebc89 | pbrook | #elif defined (TARGET_M68K)
|
501 | 6f970bd9 | bellard | |
502 | 56aebc89 | pbrook | #define GDB_CORE_XML "cf-core.xml" |
503 | 6f970bd9 | bellard | |
504 | 56aebc89 | pbrook | #endif
|
505 | f1ccf904 | ths | |
506 | 56aebc89 | pbrook | #ifdef GDB_CORE_XML
|
507 | 56aebc89 | pbrook | /* Encode data using the encoding for 'x' packets. */
|
508 | 56aebc89 | pbrook | static int memtox(char *buf, const char *mem, int len) |
509 | 56aebc89 | pbrook | { |
510 | 56aebc89 | pbrook | char *p = buf;
|
511 | 56aebc89 | pbrook | char c;
|
512 | 56aebc89 | pbrook | |
513 | 56aebc89 | pbrook | while (len--) {
|
514 | 56aebc89 | pbrook | c = *(mem++); |
515 | 56aebc89 | pbrook | switch (c) {
|
516 | 56aebc89 | pbrook | case '#': case '$': case '*': case '}': |
517 | 56aebc89 | pbrook | *(p++) = '}';
|
518 | 56aebc89 | pbrook | *(p++) = c ^ 0x20;
|
519 | 56aebc89 | pbrook | break;
|
520 | 56aebc89 | pbrook | default:
|
521 | 56aebc89 | pbrook | *(p++) = c; |
522 | 56aebc89 | pbrook | break;
|
523 | 56aebc89 | pbrook | } |
524 | 56aebc89 | pbrook | } |
525 | 56aebc89 | pbrook | return p - buf;
|
526 | 56aebc89 | pbrook | } |
527 | f1ccf904 | ths | |
528 | 3faf778e | aurel32 | static const char *get_feature_xml(const char *p, const char **newp) |
529 | 56aebc89 | pbrook | { |
530 | 56aebc89 | pbrook | size_t len; |
531 | 56aebc89 | pbrook | int i;
|
532 | 56aebc89 | pbrook | const char *name; |
533 | 56aebc89 | pbrook | static char target_xml[1024]; |
534 | 56aebc89 | pbrook | |
535 | 56aebc89 | pbrook | len = 0;
|
536 | 56aebc89 | pbrook | while (p[len] && p[len] != ':') |
537 | 56aebc89 | pbrook | len++; |
538 | 56aebc89 | pbrook | *newp = p + len; |
539 | 56aebc89 | pbrook | |
540 | 56aebc89 | pbrook | name = NULL;
|
541 | 56aebc89 | pbrook | if (strncmp(p, "target.xml", len) == 0) { |
542 | 56aebc89 | pbrook | /* Generate the XML description for this CPU. */
|
543 | 56aebc89 | pbrook | if (!target_xml[0]) { |
544 | 56aebc89 | pbrook | GDBRegisterState *r; |
545 | eac8b355 | Andreas Färber | CPUState *cpu = first_cpu; |
546 | 56aebc89 | pbrook | |
547 | 5b3715bf | blueswir1 | snprintf(target_xml, sizeof(target_xml),
|
548 | 5b3715bf | blueswir1 | "<?xml version=\"1.0\"?>"
|
549 | 5b3715bf | blueswir1 | "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">"
|
550 | 5b3715bf | blueswir1 | "<target>"
|
551 | 5b3715bf | blueswir1 | "<xi:include href=\"%s\"/>",
|
552 | 5b3715bf | blueswir1 | GDB_CORE_XML); |
553 | 56aebc89 | pbrook | |
554 | eac8b355 | Andreas Färber | for (r = cpu->gdb_regs; r; r = r->next) {
|
555 | 2dc766da | blueswir1 | pstrcat(target_xml, sizeof(target_xml), "<xi:include href=\""); |
556 | 2dc766da | blueswir1 | pstrcat(target_xml, sizeof(target_xml), r->xml);
|
557 | 2dc766da | blueswir1 | pstrcat(target_xml, sizeof(target_xml), "\"/>"); |
558 | 56aebc89 | pbrook | } |
559 | 2dc766da | blueswir1 | pstrcat(target_xml, sizeof(target_xml), "</target>"); |
560 | 56aebc89 | pbrook | } |
561 | 56aebc89 | pbrook | return target_xml;
|
562 | 56aebc89 | pbrook | } |
563 | 56aebc89 | pbrook | for (i = 0; ; i++) { |
564 | 56aebc89 | pbrook | name = xml_builtin[i][0];
|
565 | 56aebc89 | pbrook | if (!name || (strncmp(name, p, len) == 0 && strlen(name) == len)) |
566 | 56aebc89 | pbrook | break;
|
567 | 56aebc89 | pbrook | } |
568 | 56aebc89 | pbrook | return name ? xml_builtin[i][1] : NULL; |
569 | 56aebc89 | pbrook | } |
570 | 56aebc89 | pbrook | #endif
|
571 | f1ccf904 | ths | |
572 | 385b9f0e | Andreas Färber | static int gdb_read_register(CPUState *cpu, uint8_t *mem_buf, int reg) |
573 | 56aebc89 | pbrook | { |
574 | a0e372f0 | Andreas Färber | CPUClass *cc = CPU_GET_CLASS(cpu); |
575 | 385b9f0e | Andreas Färber | CPUArchState *env = cpu->env_ptr; |
576 | 56aebc89 | pbrook | GDBRegisterState *r; |
577 | f1ccf904 | ths | |
578 | a0e372f0 | Andreas Färber | if (reg < cc->gdb_num_core_regs) {
|
579 | 5b50e790 | Andreas Färber | return cc->gdb_read_register(cpu, mem_buf, reg);
|
580 | a0e372f0 | Andreas Färber | } |
581 | f1ccf904 | ths | |
582 | eac8b355 | Andreas Färber | for (r = cpu->gdb_regs; r; r = r->next) {
|
583 | 56aebc89 | pbrook | if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) {
|
584 | 56aebc89 | pbrook | return r->get_reg(env, mem_buf, reg - r->base_reg);
|
585 | 56aebc89 | pbrook | } |
586 | 56aebc89 | pbrook | } |
587 | 56aebc89 | pbrook | return 0; |
588 | f1ccf904 | ths | } |
589 | f1ccf904 | ths | |
590 | 385b9f0e | Andreas Färber | static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg) |
591 | f1ccf904 | ths | { |
592 | a0e372f0 | Andreas Färber | CPUClass *cc = CPU_GET_CLASS(cpu); |
593 | 385b9f0e | Andreas Färber | CPUArchState *env = cpu->env_ptr; |
594 | 56aebc89 | pbrook | GDBRegisterState *r; |
595 | f1ccf904 | ths | |
596 | a0e372f0 | Andreas Färber | if (reg < cc->gdb_num_core_regs) {
|
597 | 5b50e790 | Andreas Färber | return cc->gdb_write_register(cpu, mem_buf, reg);
|
598 | a0e372f0 | Andreas Färber | } |
599 | 56aebc89 | pbrook | |
600 | eac8b355 | Andreas Färber | for (r = cpu->gdb_regs; r; r = r->next) {
|
601 | 56aebc89 | pbrook | if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) {
|
602 | 56aebc89 | pbrook | return r->set_reg(env, mem_buf, reg - r->base_reg);
|
603 | 56aebc89 | pbrook | } |
604 | 56aebc89 | pbrook | } |
605 | 6da41eaf | bellard | return 0; |
606 | 6da41eaf | bellard | } |
607 | 6da41eaf | bellard | |
608 | 56aebc89 | pbrook | /* Register a supplemental set of CPU registers. If g_pos is nonzero it
|
609 | 56aebc89 | pbrook | specifies the first register number and these registers are included in
|
610 | 56aebc89 | pbrook | a standard "g" packet. Direction is relative to gdb, i.e. get_reg is
|
611 | 56aebc89 | pbrook | gdb reading a CPU register, and set_reg is gdb modifying a CPU register.
|
612 | 56aebc89 | pbrook | */
|
613 | 56aebc89 | pbrook | |
614 | 22169d41 | Andreas Färber | void gdb_register_coprocessor(CPUState *cpu,
|
615 | 22169d41 | Andreas Färber | gdb_reg_cb get_reg, gdb_reg_cb set_reg, |
616 | 22169d41 | Andreas Färber | int num_regs, const char *xml, int g_pos) |
617 | 6da41eaf | bellard | { |
618 | 56aebc89 | pbrook | GDBRegisterState *s; |
619 | 56aebc89 | pbrook | GDBRegisterState **p; |
620 | 56aebc89 | pbrook | |
621 | eac8b355 | Andreas Färber | p = &cpu->gdb_regs; |
622 | 56aebc89 | pbrook | while (*p) {
|
623 | 56aebc89 | pbrook | /* Check for duplicates. */
|
624 | 56aebc89 | pbrook | if (strcmp((*p)->xml, xml) == 0) |
625 | 56aebc89 | pbrook | return;
|
626 | 56aebc89 | pbrook | p = &(*p)->next; |
627 | 56aebc89 | pbrook | } |
628 | 9643c25f | Stefan Weil | |
629 | 9643c25f | Stefan Weil | s = g_new0(GDBRegisterState, 1);
|
630 | a0e372f0 | Andreas Färber | s->base_reg = cpu->gdb_num_regs; |
631 | 9643c25f | Stefan Weil | s->num_regs = num_regs; |
632 | 9643c25f | Stefan Weil | s->get_reg = get_reg; |
633 | 9643c25f | Stefan Weil | s->set_reg = set_reg; |
634 | 9643c25f | Stefan Weil | s->xml = xml; |
635 | 9643c25f | Stefan Weil | |
636 | 56aebc89 | pbrook | /* Add to end of list. */
|
637 | a0e372f0 | Andreas Färber | cpu->gdb_num_regs += num_regs; |
638 | 56aebc89 | pbrook | *p = s; |
639 | 56aebc89 | pbrook | if (g_pos) {
|
640 | 56aebc89 | pbrook | if (g_pos != s->base_reg) {
|
641 | 56aebc89 | pbrook | fprintf(stderr, "Error: Bad gdb register numbering for '%s'\n"
|
642 | 56aebc89 | pbrook | "Expected %d got %d\n", xml, g_pos, s->base_reg);
|
643 | 56aebc89 | pbrook | } |
644 | 56aebc89 | pbrook | } |
645 | 6da41eaf | bellard | } |
646 | 6da41eaf | bellard | |
647 | a1d1bb31 | aliguori | #ifndef CONFIG_USER_ONLY
|
648 | a1d1bb31 | aliguori | static const int xlat_gdb_type[] = { |
649 | a1d1bb31 | aliguori | [GDB_WATCHPOINT_WRITE] = BP_GDB | BP_MEM_WRITE, |
650 | a1d1bb31 | aliguori | [GDB_WATCHPOINT_READ] = BP_GDB | BP_MEM_READ, |
651 | a1d1bb31 | aliguori | [GDB_WATCHPOINT_ACCESS] = BP_GDB | BP_MEM_ACCESS, |
652 | a1d1bb31 | aliguori | }; |
653 | a1d1bb31 | aliguori | #endif
|
654 | a1d1bb31 | aliguori | |
655 | 880a7578 | aliguori | static int gdb_breakpoint_insert(target_ulong addr, target_ulong len, int type) |
656 | a1d1bb31 | aliguori | { |
657 | 182735ef | Andreas Färber | CPUState *cpu; |
658 | 9349b4f9 | Andreas Färber | CPUArchState *env; |
659 | 880a7578 | aliguori | int err = 0; |
660 | 880a7578 | aliguori | |
661 | 62278814 | Andreas Färber | if (kvm_enabled()) {
|
662 | 2e0f2cfb | Andreas Färber | return kvm_insert_breakpoint(gdbserver_state->c_cpu, addr, len, type);
|
663 | 62278814 | Andreas Färber | } |
664 | e22a25c9 | aliguori | |
665 | a1d1bb31 | aliguori | switch (type) {
|
666 | a1d1bb31 | aliguori | case GDB_BREAKPOINT_SW:
|
667 | a1d1bb31 | aliguori | case GDB_BREAKPOINT_HW:
|
668 | 182735ef | Andreas Färber | for (cpu = first_cpu; cpu != NULL; cpu = cpu->next_cpu) { |
669 | 182735ef | Andreas Färber | env = cpu->env_ptr; |
670 | 880a7578 | aliguori | err = cpu_breakpoint_insert(env, addr, BP_GDB, NULL);
|
671 | 880a7578 | aliguori | if (err)
|
672 | 880a7578 | aliguori | break;
|
673 | 880a7578 | aliguori | } |
674 | 880a7578 | aliguori | return err;
|
675 | a1d1bb31 | aliguori | #ifndef CONFIG_USER_ONLY
|
676 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_WRITE:
|
677 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_READ:
|
678 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_ACCESS:
|
679 | 182735ef | Andreas Färber | for (cpu = first_cpu; cpu != NULL; cpu = cpu->next_cpu) { |
680 | 182735ef | Andreas Färber | env = cpu->env_ptr; |
681 | 880a7578 | aliguori | err = cpu_watchpoint_insert(env, addr, len, xlat_gdb_type[type], |
682 | 880a7578 | aliguori | NULL);
|
683 | 880a7578 | aliguori | if (err)
|
684 | 880a7578 | aliguori | break;
|
685 | 880a7578 | aliguori | } |
686 | 880a7578 | aliguori | return err;
|
687 | a1d1bb31 | aliguori | #endif
|
688 | a1d1bb31 | aliguori | default:
|
689 | a1d1bb31 | aliguori | return -ENOSYS;
|
690 | a1d1bb31 | aliguori | } |
691 | a1d1bb31 | aliguori | } |
692 | a1d1bb31 | aliguori | |
693 | 880a7578 | aliguori | static int gdb_breakpoint_remove(target_ulong addr, target_ulong len, int type) |
694 | a1d1bb31 | aliguori | { |
695 | 182735ef | Andreas Färber | CPUState *cpu; |
696 | 9349b4f9 | Andreas Färber | CPUArchState *env; |
697 | 880a7578 | aliguori | int err = 0; |
698 | 880a7578 | aliguori | |
699 | 62278814 | Andreas Färber | if (kvm_enabled()) {
|
700 | 2e0f2cfb | Andreas Färber | return kvm_remove_breakpoint(gdbserver_state->c_cpu, addr, len, type);
|
701 | 62278814 | Andreas Färber | } |
702 | e22a25c9 | aliguori | |
703 | a1d1bb31 | aliguori | switch (type) {
|
704 | a1d1bb31 | aliguori | case GDB_BREAKPOINT_SW:
|
705 | a1d1bb31 | aliguori | case GDB_BREAKPOINT_HW:
|
706 | 182735ef | Andreas Färber | for (cpu = first_cpu; cpu != NULL; cpu = cpu->next_cpu) { |
707 | 182735ef | Andreas Färber | env = cpu->env_ptr; |
708 | 880a7578 | aliguori | err = cpu_breakpoint_remove(env, addr, BP_GDB); |
709 | 880a7578 | aliguori | if (err)
|
710 | 880a7578 | aliguori | break;
|
711 | 880a7578 | aliguori | } |
712 | 880a7578 | aliguori | return err;
|
713 | a1d1bb31 | aliguori | #ifndef CONFIG_USER_ONLY
|
714 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_WRITE:
|
715 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_READ:
|
716 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_ACCESS:
|
717 | 182735ef | Andreas Färber | for (cpu = first_cpu; cpu != NULL; cpu = cpu->next_cpu) { |
718 | 182735ef | Andreas Färber | env = cpu->env_ptr; |
719 | 880a7578 | aliguori | err = cpu_watchpoint_remove(env, addr, len, xlat_gdb_type[type]); |
720 | 880a7578 | aliguori | if (err)
|
721 | 880a7578 | aliguori | break;
|
722 | 880a7578 | aliguori | } |
723 | 880a7578 | aliguori | return err;
|
724 | a1d1bb31 | aliguori | #endif
|
725 | a1d1bb31 | aliguori | default:
|
726 | a1d1bb31 | aliguori | return -ENOSYS;
|
727 | a1d1bb31 | aliguori | } |
728 | a1d1bb31 | aliguori | } |
729 | a1d1bb31 | aliguori | |
730 | 880a7578 | aliguori | static void gdb_breakpoint_remove_all(void) |
731 | a1d1bb31 | aliguori | { |
732 | 182735ef | Andreas Färber | CPUState *cpu; |
733 | 9349b4f9 | Andreas Färber | CPUArchState *env; |
734 | 880a7578 | aliguori | |
735 | e22a25c9 | aliguori | if (kvm_enabled()) {
|
736 | 2e0f2cfb | Andreas Färber | kvm_remove_all_breakpoints(gdbserver_state->c_cpu); |
737 | e22a25c9 | aliguori | return;
|
738 | e22a25c9 | aliguori | } |
739 | e22a25c9 | aliguori | |
740 | 182735ef | Andreas Färber | for (cpu = first_cpu; cpu != NULL; cpu = cpu->next_cpu) { |
741 | 182735ef | Andreas Färber | env = cpu->env_ptr; |
742 | 880a7578 | aliguori | cpu_breakpoint_remove_all(env, BP_GDB); |
743 | a1d1bb31 | aliguori | #ifndef CONFIG_USER_ONLY
|
744 | 880a7578 | aliguori | cpu_watchpoint_remove_all(env, BP_GDB); |
745 | a1d1bb31 | aliguori | #endif
|
746 | 880a7578 | aliguori | } |
747 | a1d1bb31 | aliguori | } |
748 | a1d1bb31 | aliguori | |
749 | fab9d284 | aurel32 | static void gdb_set_cpu_pc(GDBState *s, target_ulong pc) |
750 | fab9d284 | aurel32 | { |
751 | 2e0f2cfb | Andreas Färber | CPUState *cpu = s->c_cpu; |
752 | f45748f1 | Andreas Färber | CPUClass *cc = CPU_GET_CLASS(cpu); |
753 | f45748f1 | Andreas Färber | |
754 | f45748f1 | Andreas Färber | cpu_synchronize_state(cpu); |
755 | f45748f1 | Andreas Färber | if (cc->set_pc) {
|
756 | f45748f1 | Andreas Färber | cc->set_pc(cpu, pc); |
757 | ff1d1977 | Nathan Froyd | } |
758 | fab9d284 | aurel32 | } |
759 | fab9d284 | aurel32 | |
760 | 2e0f2cfb | Andreas Färber | static CPUState *find_cpu(uint32_t thread_id)
|
761 | 1e9fa730 | Nathan Froyd | { |
762 | 0d34282f | Andreas Färber | CPUState *cpu; |
763 | 1e9fa730 | Nathan Froyd | |
764 | 182735ef | Andreas Färber | for (cpu = first_cpu; cpu != NULL; cpu = cpu->next_cpu) { |
765 | aa48dd93 | Andreas Färber | if (cpu_index(cpu) == thread_id) {
|
766 | 2e0f2cfb | Andreas Färber | return cpu;
|
767 | aa48dd93 | Andreas Färber | } |
768 | 1e9fa730 | Nathan Froyd | } |
769 | aa48dd93 | Andreas Färber | |
770 | aa48dd93 | Andreas Färber | return NULL; |
771 | 1e9fa730 | Nathan Froyd | } |
772 | 1e9fa730 | Nathan Froyd | |
773 | 880a7578 | aliguori | static int gdb_handle_packet(GDBState *s, const char *line_buf) |
774 | b4608c04 | bellard | { |
775 | 2e0f2cfb | Andreas Färber | CPUState *cpu; |
776 | b4608c04 | bellard | const char *p; |
777 | 1e9fa730 | Nathan Froyd | uint32_t thread; |
778 | 1e9fa730 | Nathan Froyd | int ch, reg_size, type, res;
|
779 | 56aebc89 | pbrook | char buf[MAX_PACKET_LENGTH];
|
780 | 56aebc89 | pbrook | uint8_t mem_buf[MAX_PACKET_LENGTH]; |
781 | 56aebc89 | pbrook | uint8_t *registers; |
782 | 9d9754a3 | bellard | target_ulong addr, len; |
783 | 3b46e624 | ths | |
784 | 858693c6 | bellard | #ifdef DEBUG_GDB
|
785 | 858693c6 | bellard | printf("command='%s'\n", line_buf);
|
786 | 858693c6 | bellard | #endif
|
787 | 858693c6 | bellard | p = line_buf; |
788 | 858693c6 | bellard | ch = *p++; |
789 | 858693c6 | bellard | switch(ch) {
|
790 | 858693c6 | bellard | case '?': |
791 | 1fddef4b | bellard | /* TODO: Make this return the correct value for user-mode. */
|
792 | ca587a8e | aurel32 | snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP, |
793 | 2e0f2cfb | Andreas Färber | cpu_index(s->c_cpu)); |
794 | 858693c6 | bellard | put_packet(s, buf); |
795 | 7d03f82f | edgar_igl | /* Remove all the breakpoints when this query is issued,
|
796 | 7d03f82f | edgar_igl | * because gdb is doing and initial connect and the state
|
797 | 7d03f82f | edgar_igl | * should be cleaned up.
|
798 | 7d03f82f | edgar_igl | */
|
799 | 880a7578 | aliguori | gdb_breakpoint_remove_all(); |
800 | 858693c6 | bellard | break;
|
801 | 858693c6 | bellard | case 'c': |
802 | 858693c6 | bellard | if (*p != '\0') { |
803 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
804 | fab9d284 | aurel32 | gdb_set_cpu_pc(s, addr); |
805 | 858693c6 | bellard | } |
806 | ca587a8e | aurel32 | s->signal = 0;
|
807 | ba70a624 | edgar_igl | gdb_continue(s); |
808 | 41625033 | bellard | return RS_IDLE;
|
809 | 1f487ee9 | edgar_igl | case 'C': |
810 | ca587a8e | aurel32 | s->signal = gdb_signal_to_target (strtoul(p, (char **)&p, 16)); |
811 | ca587a8e | aurel32 | if (s->signal == -1) |
812 | ca587a8e | aurel32 | s->signal = 0;
|
813 | 1f487ee9 | edgar_igl | gdb_continue(s); |
814 | 1f487ee9 | edgar_igl | return RS_IDLE;
|
815 | dd32aa10 | Jan Kiszka | case 'v': |
816 | dd32aa10 | Jan Kiszka | if (strncmp(p, "Cont", 4) == 0) { |
817 | dd32aa10 | Jan Kiszka | int res_signal, res_thread;
|
818 | dd32aa10 | Jan Kiszka | |
819 | dd32aa10 | Jan Kiszka | p += 4;
|
820 | dd32aa10 | Jan Kiszka | if (*p == '?') { |
821 | dd32aa10 | Jan Kiszka | put_packet(s, "vCont;c;C;s;S");
|
822 | dd32aa10 | Jan Kiszka | break;
|
823 | dd32aa10 | Jan Kiszka | } |
824 | dd32aa10 | Jan Kiszka | res = 0;
|
825 | dd32aa10 | Jan Kiszka | res_signal = 0;
|
826 | dd32aa10 | Jan Kiszka | res_thread = 0;
|
827 | dd32aa10 | Jan Kiszka | while (*p) {
|
828 | dd32aa10 | Jan Kiszka | int action, signal;
|
829 | dd32aa10 | Jan Kiszka | |
830 | dd32aa10 | Jan Kiszka | if (*p++ != ';') { |
831 | dd32aa10 | Jan Kiszka | res = 0;
|
832 | dd32aa10 | Jan Kiszka | break;
|
833 | dd32aa10 | Jan Kiszka | } |
834 | dd32aa10 | Jan Kiszka | action = *p++; |
835 | dd32aa10 | Jan Kiszka | signal = 0;
|
836 | dd32aa10 | Jan Kiszka | if (action == 'C' || action == 'S') { |
837 | dd32aa10 | Jan Kiszka | signal = strtoul(p, (char **)&p, 16); |
838 | dd32aa10 | Jan Kiszka | } else if (action != 'c' && action != 's') { |
839 | dd32aa10 | Jan Kiszka | res = 0;
|
840 | dd32aa10 | Jan Kiszka | break;
|
841 | dd32aa10 | Jan Kiszka | } |
842 | dd32aa10 | Jan Kiszka | thread = 0;
|
843 | dd32aa10 | Jan Kiszka | if (*p == ':') { |
844 | dd32aa10 | Jan Kiszka | thread = strtoull(p+1, (char **)&p, 16); |
845 | dd32aa10 | Jan Kiszka | } |
846 | dd32aa10 | Jan Kiszka | action = tolower(action); |
847 | dd32aa10 | Jan Kiszka | if (res == 0 || (res == 'c' && action == 's')) { |
848 | dd32aa10 | Jan Kiszka | res = action; |
849 | dd32aa10 | Jan Kiszka | res_signal = signal; |
850 | dd32aa10 | Jan Kiszka | res_thread = thread; |
851 | dd32aa10 | Jan Kiszka | } |
852 | dd32aa10 | Jan Kiszka | } |
853 | dd32aa10 | Jan Kiszka | if (res) {
|
854 | dd32aa10 | Jan Kiszka | if (res_thread != -1 && res_thread != 0) { |
855 | 2e0f2cfb | Andreas Färber | cpu = find_cpu(res_thread); |
856 | 2e0f2cfb | Andreas Färber | if (cpu == NULL) { |
857 | dd32aa10 | Jan Kiszka | put_packet(s, "E22");
|
858 | dd32aa10 | Jan Kiszka | break;
|
859 | dd32aa10 | Jan Kiszka | } |
860 | 2e0f2cfb | Andreas Färber | s->c_cpu = cpu; |
861 | dd32aa10 | Jan Kiszka | } |
862 | dd32aa10 | Jan Kiszka | if (res == 's') { |
863 | 2e0f2cfb | Andreas Färber | cpu_single_step(s->c_cpu, sstep_flags); |
864 | dd32aa10 | Jan Kiszka | } |
865 | dd32aa10 | Jan Kiszka | s->signal = res_signal; |
866 | dd32aa10 | Jan Kiszka | gdb_continue(s); |
867 | dd32aa10 | Jan Kiszka | return RS_IDLE;
|
868 | dd32aa10 | Jan Kiszka | } |
869 | dd32aa10 | Jan Kiszka | break;
|
870 | dd32aa10 | Jan Kiszka | } else {
|
871 | dd32aa10 | Jan Kiszka | goto unknown_command;
|
872 | dd32aa10 | Jan Kiszka | } |
873 | 7d03f82f | edgar_igl | case 'k': |
874 | 00e94dbc | Jan Kiszka | #ifdef CONFIG_USER_ONLY
|
875 | 7d03f82f | edgar_igl | /* Kill the target */
|
876 | 7d03f82f | edgar_igl | fprintf(stderr, "\nQEMU: Terminated via GDBstub\n");
|
877 | 7d03f82f | edgar_igl | exit(0);
|
878 | 00e94dbc | Jan Kiszka | #endif
|
879 | 7d03f82f | edgar_igl | case 'D': |
880 | 7d03f82f | edgar_igl | /* Detach packet */
|
881 | 880a7578 | aliguori | gdb_breakpoint_remove_all(); |
882 | 7ea06da3 | Daniel Gutson | gdb_syscall_mode = GDB_SYS_DISABLED; |
883 | 7d03f82f | edgar_igl | gdb_continue(s); |
884 | 7d03f82f | edgar_igl | put_packet(s, "OK");
|
885 | 7d03f82f | edgar_igl | break;
|
886 | 858693c6 | bellard | case 's': |
887 | 858693c6 | bellard | if (*p != '\0') { |
888 | 8fac5803 | ths | addr = strtoull(p, (char **)&p, 16); |
889 | fab9d284 | aurel32 | gdb_set_cpu_pc(s, addr); |
890 | 858693c6 | bellard | } |
891 | 2e0f2cfb | Andreas Färber | cpu_single_step(s->c_cpu, sstep_flags); |
892 | ba70a624 | edgar_igl | gdb_continue(s); |
893 | 41625033 | bellard | return RS_IDLE;
|
894 | a2d1ebaf | pbrook | case 'F': |
895 | a2d1ebaf | pbrook | { |
896 | a2d1ebaf | pbrook | target_ulong ret; |
897 | a2d1ebaf | pbrook | target_ulong err; |
898 | a2d1ebaf | pbrook | |
899 | a2d1ebaf | pbrook | ret = strtoull(p, (char **)&p, 16); |
900 | a2d1ebaf | pbrook | if (*p == ',') { |
901 | a2d1ebaf | pbrook | p++; |
902 | a2d1ebaf | pbrook | err = strtoull(p, (char **)&p, 16); |
903 | a2d1ebaf | pbrook | } else {
|
904 | a2d1ebaf | pbrook | err = 0;
|
905 | a2d1ebaf | pbrook | } |
906 | a2d1ebaf | pbrook | if (*p == ',') |
907 | a2d1ebaf | pbrook | p++; |
908 | a2d1ebaf | pbrook | type = *p; |
909 | cdb432b2 | Meador Inge | if (s->current_syscall_cb) {
|
910 | 2e0f2cfb | Andreas Färber | s->current_syscall_cb(s->c_cpu, ret, err); |
911 | cdb432b2 | Meador Inge | s->current_syscall_cb = NULL;
|
912 | cdb432b2 | Meador Inge | } |
913 | a2d1ebaf | pbrook | if (type == 'C') { |
914 | a2d1ebaf | pbrook | put_packet(s, "T02");
|
915 | a2d1ebaf | pbrook | } else {
|
916 | ba70a624 | edgar_igl | gdb_continue(s); |
917 | a2d1ebaf | pbrook | } |
918 | a2d1ebaf | pbrook | } |
919 | a2d1ebaf | pbrook | break;
|
920 | 858693c6 | bellard | case 'g': |
921 | 2e0f2cfb | Andreas Färber | cpu_synchronize_state(s->g_cpu); |
922 | 56aebc89 | pbrook | len = 0;
|
923 | a0e372f0 | Andreas Färber | for (addr = 0; addr < s->g_cpu->gdb_num_regs; addr++) { |
924 | 2e0f2cfb | Andreas Färber | reg_size = gdb_read_register(s->g_cpu, mem_buf + len, addr); |
925 | 56aebc89 | pbrook | len += reg_size; |
926 | 56aebc89 | pbrook | } |
927 | 56aebc89 | pbrook | memtohex(buf, mem_buf, len); |
928 | 858693c6 | bellard | put_packet(s, buf); |
929 | 858693c6 | bellard | break;
|
930 | 858693c6 | bellard | case 'G': |
931 | 2e0f2cfb | Andreas Färber | cpu_synchronize_state(s->g_cpu); |
932 | 56aebc89 | pbrook | registers = mem_buf; |
933 | 858693c6 | bellard | len = strlen(p) / 2;
|
934 | 858693c6 | bellard | hextomem((uint8_t *)registers, p, len); |
935 | a0e372f0 | Andreas Färber | for (addr = 0; addr < s->g_cpu->gdb_num_regs && len > 0; addr++) { |
936 | 2e0f2cfb | Andreas Färber | reg_size = gdb_write_register(s->g_cpu, registers, addr); |
937 | 56aebc89 | pbrook | len -= reg_size; |
938 | 56aebc89 | pbrook | registers += reg_size; |
939 | 56aebc89 | pbrook | } |
940 | 858693c6 | bellard | put_packet(s, "OK");
|
941 | 858693c6 | bellard | break;
|
942 | 858693c6 | bellard | case 'm': |
943 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
944 | 858693c6 | bellard | if (*p == ',') |
945 | 858693c6 | bellard | p++; |
946 | 9d9754a3 | bellard | len = strtoull(p, NULL, 16); |
947 | 2e0f2cfb | Andreas Färber | if (target_memory_rw_debug(s->g_cpu, addr, mem_buf, len, false) != 0) { |
948 | 6f970bd9 | bellard | put_packet (s, "E14");
|
949 | 6f970bd9 | bellard | } else {
|
950 | 6f970bd9 | bellard | memtohex(buf, mem_buf, len); |
951 | 6f970bd9 | bellard | put_packet(s, buf); |
952 | 6f970bd9 | bellard | } |
953 | 858693c6 | bellard | break;
|
954 | 858693c6 | bellard | case 'M': |
955 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
956 | 858693c6 | bellard | if (*p == ',') |
957 | 858693c6 | bellard | p++; |
958 | 9d9754a3 | bellard | len = strtoull(p, (char **)&p, 16); |
959 | b328f873 | bellard | if (*p == ':') |
960 | 858693c6 | bellard | p++; |
961 | 858693c6 | bellard | hextomem(mem_buf, p, len); |
962 | 2e0f2cfb | Andreas Färber | if (target_memory_rw_debug(s->g_cpu, addr, mem_buf, len,
|
963 | f3659eee | Andreas Färber | true) != 0) { |
964 | 905f20b1 | bellard | put_packet(s, "E14");
|
965 | 44520db1 | Fabien Chouteau | } else {
|
966 | 858693c6 | bellard | put_packet(s, "OK");
|
967 | 44520db1 | Fabien Chouteau | } |
968 | 858693c6 | bellard | break;
|
969 | 56aebc89 | pbrook | case 'p': |
970 | 56aebc89 | pbrook | /* Older gdb are really dumb, and don't use 'g' if 'p' is avaialable.
|
971 | 56aebc89 | pbrook | This works, but can be very slow. Anything new enough to
|
972 | 56aebc89 | pbrook | understand XML also knows how to use this properly. */
|
973 | 56aebc89 | pbrook | if (!gdb_has_xml)
|
974 | 56aebc89 | pbrook | goto unknown_command;
|
975 | 56aebc89 | pbrook | addr = strtoull(p, (char **)&p, 16); |
976 | 2e0f2cfb | Andreas Färber | reg_size = gdb_read_register(s->g_cpu, mem_buf, addr); |
977 | 56aebc89 | pbrook | if (reg_size) {
|
978 | 56aebc89 | pbrook | memtohex(buf, mem_buf, reg_size); |
979 | 56aebc89 | pbrook | put_packet(s, buf); |
980 | 56aebc89 | pbrook | } else {
|
981 | 56aebc89 | pbrook | put_packet(s, "E14");
|
982 | 56aebc89 | pbrook | } |
983 | 56aebc89 | pbrook | break;
|
984 | 56aebc89 | pbrook | case 'P': |
985 | 56aebc89 | pbrook | if (!gdb_has_xml)
|
986 | 56aebc89 | pbrook | goto unknown_command;
|
987 | 56aebc89 | pbrook | addr = strtoull(p, (char **)&p, 16); |
988 | 56aebc89 | pbrook | if (*p == '=') |
989 | 56aebc89 | pbrook | p++; |
990 | 56aebc89 | pbrook | reg_size = strlen(p) / 2;
|
991 | 56aebc89 | pbrook | hextomem(mem_buf, p, reg_size); |
992 | 2e0f2cfb | Andreas Färber | gdb_write_register(s->g_cpu, mem_buf, addr); |
993 | 56aebc89 | pbrook | put_packet(s, "OK");
|
994 | 56aebc89 | pbrook | break;
|
995 | 858693c6 | bellard | case 'Z': |
996 | 858693c6 | bellard | case 'z': |
997 | 858693c6 | bellard | type = strtoul(p, (char **)&p, 16); |
998 | 858693c6 | bellard | if (*p == ',') |
999 | 858693c6 | bellard | p++; |
1000 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
1001 | 858693c6 | bellard | if (*p == ',') |
1002 | 858693c6 | bellard | p++; |
1003 | 9d9754a3 | bellard | len = strtoull(p, (char **)&p, 16); |
1004 | a1d1bb31 | aliguori | if (ch == 'Z') |
1005 | 880a7578 | aliguori | res = gdb_breakpoint_insert(addr, len, type); |
1006 | a1d1bb31 | aliguori | else
|
1007 | 880a7578 | aliguori | res = gdb_breakpoint_remove(addr, len, type); |
1008 | a1d1bb31 | aliguori | if (res >= 0) |
1009 | a1d1bb31 | aliguori | put_packet(s, "OK");
|
1010 | a1d1bb31 | aliguori | else if (res == -ENOSYS) |
1011 | 0f459d16 | pbrook | put_packet(s, "");
|
1012 | a1d1bb31 | aliguori | else
|
1013 | a1d1bb31 | aliguori | put_packet(s, "E22");
|
1014 | 858693c6 | bellard | break;
|
1015 | 880a7578 | aliguori | case 'H': |
1016 | 880a7578 | aliguori | type = *p++; |
1017 | 880a7578 | aliguori | thread = strtoull(p, (char **)&p, 16); |
1018 | 880a7578 | aliguori | if (thread == -1 || thread == 0) { |
1019 | 880a7578 | aliguori | put_packet(s, "OK");
|
1020 | 880a7578 | aliguori | break;
|
1021 | 880a7578 | aliguori | } |
1022 | 2e0f2cfb | Andreas Färber | cpu = find_cpu(thread); |
1023 | 2e0f2cfb | Andreas Färber | if (cpu == NULL) { |
1024 | 880a7578 | aliguori | put_packet(s, "E22");
|
1025 | 880a7578 | aliguori | break;
|
1026 | 880a7578 | aliguori | } |
1027 | 880a7578 | aliguori | switch (type) {
|
1028 | 880a7578 | aliguori | case 'c': |
1029 | 2e0f2cfb | Andreas Färber | s->c_cpu = cpu; |
1030 | 880a7578 | aliguori | put_packet(s, "OK");
|
1031 | 880a7578 | aliguori | break;
|
1032 | 880a7578 | aliguori | case 'g': |
1033 | 2e0f2cfb | Andreas Färber | s->g_cpu = cpu; |
1034 | 880a7578 | aliguori | put_packet(s, "OK");
|
1035 | 880a7578 | aliguori | break;
|
1036 | 880a7578 | aliguori | default:
|
1037 | 880a7578 | aliguori | put_packet(s, "E22");
|
1038 | 880a7578 | aliguori | break;
|
1039 | 880a7578 | aliguori | } |
1040 | 880a7578 | aliguori | break;
|
1041 | 880a7578 | aliguori | case 'T': |
1042 | 880a7578 | aliguori | thread = strtoull(p, (char **)&p, 16); |
1043 | 2e0f2cfb | Andreas Färber | cpu = find_cpu(thread); |
1044 | 1e9fa730 | Nathan Froyd | |
1045 | 2e0f2cfb | Andreas Färber | if (cpu != NULL) { |
1046 | 1e9fa730 | Nathan Froyd | put_packet(s, "OK");
|
1047 | 1e9fa730 | Nathan Froyd | } else {
|
1048 | 880a7578 | aliguori | put_packet(s, "E22");
|
1049 | 1e9fa730 | Nathan Froyd | } |
1050 | 880a7578 | aliguori | break;
|
1051 | 978efd6a | pbrook | case 'q': |
1052 | 60897d36 | edgar_igl | case 'Q': |
1053 | 60897d36 | edgar_igl | /* parse any 'q' packets here */
|
1054 | 60897d36 | edgar_igl | if (!strcmp(p,"qemu.sstepbits")) { |
1055 | 60897d36 | edgar_igl | /* Query Breakpoint bit definitions */
|
1056 | 363a37d5 | blueswir1 | snprintf(buf, sizeof(buf), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x", |
1057 | 363a37d5 | blueswir1 | SSTEP_ENABLE, |
1058 | 363a37d5 | blueswir1 | SSTEP_NOIRQ, |
1059 | 363a37d5 | blueswir1 | SSTEP_NOTIMER); |
1060 | 60897d36 | edgar_igl | put_packet(s, buf); |
1061 | 60897d36 | edgar_igl | break;
|
1062 | 60897d36 | edgar_igl | } else if (strncmp(p,"qemu.sstep",10) == 0) { |
1063 | 60897d36 | edgar_igl | /* Display or change the sstep_flags */
|
1064 | 60897d36 | edgar_igl | p += 10;
|
1065 | 60897d36 | edgar_igl | if (*p != '=') { |
1066 | 60897d36 | edgar_igl | /* Display current setting */
|
1067 | 363a37d5 | blueswir1 | snprintf(buf, sizeof(buf), "0x%x", sstep_flags); |
1068 | 60897d36 | edgar_igl | put_packet(s, buf); |
1069 | 60897d36 | edgar_igl | break;
|
1070 | 60897d36 | edgar_igl | } |
1071 | 60897d36 | edgar_igl | p++; |
1072 | 60897d36 | edgar_igl | type = strtoul(p, (char **)&p, 16); |
1073 | 60897d36 | edgar_igl | sstep_flags = type; |
1074 | 60897d36 | edgar_igl | put_packet(s, "OK");
|
1075 | 60897d36 | edgar_igl | break;
|
1076 | 880a7578 | aliguori | } else if (strcmp(p,"C") == 0) { |
1077 | 880a7578 | aliguori | /* "Current thread" remains vague in the spec, so always return
|
1078 | 880a7578 | aliguori | * the first CPU (gdb returns the first thread). */
|
1079 | 880a7578 | aliguori | put_packet(s, "QC1");
|
1080 | 880a7578 | aliguori | break;
|
1081 | 880a7578 | aliguori | } else if (strcmp(p,"fThreadInfo") == 0) { |
1082 | 52f34623 | Andreas Färber | s->query_cpu = first_cpu; |
1083 | 880a7578 | aliguori | goto report_cpuinfo;
|
1084 | 880a7578 | aliguori | } else if (strcmp(p,"sThreadInfo") == 0) { |
1085 | 880a7578 | aliguori | report_cpuinfo:
|
1086 | 880a7578 | aliguori | if (s->query_cpu) {
|
1087 | 52f34623 | Andreas Färber | snprintf(buf, sizeof(buf), "m%x", cpu_index(s->query_cpu)); |
1088 | 880a7578 | aliguori | put_packet(s, buf); |
1089 | 52f34623 | Andreas Färber | s->query_cpu = s->query_cpu->next_cpu; |
1090 | 880a7578 | aliguori | } else
|
1091 | 880a7578 | aliguori | put_packet(s, "l");
|
1092 | 880a7578 | aliguori | break;
|
1093 | 880a7578 | aliguori | } else if (strncmp(p,"ThreadExtraInfo,", 16) == 0) { |
1094 | 880a7578 | aliguori | thread = strtoull(p+16, (char **)&p, 16); |
1095 | 2e0f2cfb | Andreas Färber | cpu = find_cpu(thread); |
1096 | 2e0f2cfb | Andreas Färber | if (cpu != NULL) { |
1097 | cb446eca | Andreas Färber | cpu_synchronize_state(cpu); |
1098 | 1e9fa730 | Nathan Froyd | len = snprintf((char *)mem_buf, sizeof(mem_buf), |
1099 | 55e5c285 | Andreas Färber | "CPU#%d [%s]", cpu->cpu_index,
|
1100 | 259186a7 | Andreas Färber | cpu->halted ? "halted " : "running"); |
1101 | 1e9fa730 | Nathan Froyd | memtohex(buf, mem_buf, len); |
1102 | 1e9fa730 | Nathan Froyd | put_packet(s, buf); |
1103 | 1e9fa730 | Nathan Froyd | } |
1104 | 880a7578 | aliguori | break;
|
1105 | 60897d36 | edgar_igl | } |
1106 | 0b8a988c | blueswir1 | #ifdef CONFIG_USER_ONLY
|
1107 | 60897d36 | edgar_igl | else if (strncmp(p, "Offsets", 7) == 0) { |
1108 | 2e0f2cfb | Andreas Färber | CPUArchState *env = s->c_cpu->env_ptr; |
1109 | 2e0f2cfb | Andreas Färber | TaskState *ts = env->opaque; |
1110 | 978efd6a | pbrook | |
1111 | 363a37d5 | blueswir1 | snprintf(buf, sizeof(buf),
|
1112 | 363a37d5 | blueswir1 | "Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx |
1113 | 363a37d5 | blueswir1 | ";Bss=" TARGET_ABI_FMT_lx,
|
1114 | 363a37d5 | blueswir1 | ts->info->code_offset, |
1115 | 363a37d5 | blueswir1 | ts->info->data_offset, |
1116 | 363a37d5 | blueswir1 | ts->info->data_offset); |
1117 | 978efd6a | pbrook | put_packet(s, buf); |
1118 | 978efd6a | pbrook | break;
|
1119 | 978efd6a | pbrook | } |
1120 | 0b8a988c | blueswir1 | #else /* !CONFIG_USER_ONLY */ |
1121 | 8a34a0fb | aliguori | else if (strncmp(p, "Rcmd,", 5) == 0) { |
1122 | 8a34a0fb | aliguori | int len = strlen(p + 5); |
1123 | 8a34a0fb | aliguori | |
1124 | 8a34a0fb | aliguori | if ((len % 2) != 0) { |
1125 | 8a34a0fb | aliguori | put_packet(s, "E01");
|
1126 | 8a34a0fb | aliguori | break;
|
1127 | 8a34a0fb | aliguori | } |
1128 | 8a34a0fb | aliguori | hextomem(mem_buf, p + 5, len);
|
1129 | 8a34a0fb | aliguori | len = len / 2;
|
1130 | 8a34a0fb | aliguori | mem_buf[len++] = 0;
|
1131 | fa5efccb | Anthony Liguori | qemu_chr_be_write(s->mon_chr, mem_buf, len); |
1132 | 8a34a0fb | aliguori | put_packet(s, "OK");
|
1133 | 8a34a0fb | aliguori | break;
|
1134 | 8a34a0fb | aliguori | } |
1135 | 0b8a988c | blueswir1 | #endif /* !CONFIG_USER_ONLY */ |
1136 | 56aebc89 | pbrook | if (strncmp(p, "Supported", 9) == 0) { |
1137 | 5b3715bf | blueswir1 | snprintf(buf, sizeof(buf), "PacketSize=%x", MAX_PACKET_LENGTH); |
1138 | 56aebc89 | pbrook | #ifdef GDB_CORE_XML
|
1139 | 2dc766da | blueswir1 | pstrcat(buf, sizeof(buf), ";qXfer:features:read+"); |
1140 | 56aebc89 | pbrook | #endif
|
1141 | 56aebc89 | pbrook | put_packet(s, buf); |
1142 | 56aebc89 | pbrook | break;
|
1143 | 56aebc89 | pbrook | } |
1144 | 56aebc89 | pbrook | #ifdef GDB_CORE_XML
|
1145 | 56aebc89 | pbrook | if (strncmp(p, "Xfer:features:read:", 19) == 0) { |
1146 | 56aebc89 | pbrook | const char *xml; |
1147 | 56aebc89 | pbrook | target_ulong total_len; |
1148 | 56aebc89 | pbrook | |
1149 | 5b50e790 | Andreas Färber | gdb_has_xml = true;
|
1150 | 56aebc89 | pbrook | p += 19;
|
1151 | 880a7578 | aliguori | xml = get_feature_xml(p, &p); |
1152 | 56aebc89 | pbrook | if (!xml) {
|
1153 | 5b3715bf | blueswir1 | snprintf(buf, sizeof(buf), "E00"); |
1154 | 56aebc89 | pbrook | put_packet(s, buf); |
1155 | 56aebc89 | pbrook | break;
|
1156 | 56aebc89 | pbrook | } |
1157 | 56aebc89 | pbrook | |
1158 | 56aebc89 | pbrook | if (*p == ':') |
1159 | 56aebc89 | pbrook | p++; |
1160 | 56aebc89 | pbrook | addr = strtoul(p, (char **)&p, 16); |
1161 | 56aebc89 | pbrook | if (*p == ',') |
1162 | 56aebc89 | pbrook | p++; |
1163 | 56aebc89 | pbrook | len = strtoul(p, (char **)&p, 16); |
1164 | 56aebc89 | pbrook | |
1165 | 56aebc89 | pbrook | total_len = strlen(xml); |
1166 | 56aebc89 | pbrook | if (addr > total_len) {
|
1167 | 5b3715bf | blueswir1 | snprintf(buf, sizeof(buf), "E00"); |
1168 | 56aebc89 | pbrook | put_packet(s, buf); |
1169 | 56aebc89 | pbrook | break;
|
1170 | 56aebc89 | pbrook | } |
1171 | 56aebc89 | pbrook | if (len > (MAX_PACKET_LENGTH - 5) / 2) |
1172 | 56aebc89 | pbrook | len = (MAX_PACKET_LENGTH - 5) / 2; |
1173 | 56aebc89 | pbrook | if (len < total_len - addr) {
|
1174 | 56aebc89 | pbrook | buf[0] = 'm'; |
1175 | 56aebc89 | pbrook | len = memtox(buf + 1, xml + addr, len);
|
1176 | 56aebc89 | pbrook | } else {
|
1177 | 56aebc89 | pbrook | buf[0] = 'l'; |
1178 | 56aebc89 | pbrook | len = memtox(buf + 1, xml + addr, total_len - addr);
|
1179 | 56aebc89 | pbrook | } |
1180 | 56aebc89 | pbrook | put_packet_binary(s, buf, len + 1);
|
1181 | 56aebc89 | pbrook | break;
|
1182 | 56aebc89 | pbrook | } |
1183 | 56aebc89 | pbrook | #endif
|
1184 | 56aebc89 | pbrook | /* Unrecognised 'q' command. */
|
1185 | 56aebc89 | pbrook | goto unknown_command;
|
1186 | 56aebc89 | pbrook | |
1187 | 858693c6 | bellard | default:
|
1188 | 56aebc89 | pbrook | unknown_command:
|
1189 | 858693c6 | bellard | /* put empty packet */
|
1190 | 858693c6 | bellard | buf[0] = '\0'; |
1191 | 858693c6 | bellard | put_packet(s, buf); |
1192 | 858693c6 | bellard | break;
|
1193 | 858693c6 | bellard | } |
1194 | 858693c6 | bellard | return RS_IDLE;
|
1195 | 858693c6 | bellard | } |
1196 | 858693c6 | bellard | |
1197 | 64f6b346 | Andreas Färber | void gdb_set_stop_cpu(CPUState *cpu)
|
1198 | 880a7578 | aliguori | { |
1199 | 2e0f2cfb | Andreas Färber | gdbserver_state->c_cpu = cpu; |
1200 | 2e0f2cfb | Andreas Färber | gdbserver_state->g_cpu = cpu; |
1201 | 880a7578 | aliguori | } |
1202 | 880a7578 | aliguori | |
1203 | 1fddef4b | bellard | #ifndef CONFIG_USER_ONLY
|
1204 | 1dfb4dd9 | Luiz Capitulino | static void gdb_vm_state_change(void *opaque, int running, RunState state) |
1205 | 858693c6 | bellard | { |
1206 | 880a7578 | aliguori | GDBState *s = gdbserver_state; |
1207 | 2e0f2cfb | Andreas Färber | CPUArchState *env = s->c_cpu->env_ptr; |
1208 | 2e0f2cfb | Andreas Färber | CPUState *cpu = s->c_cpu; |
1209 | 858693c6 | bellard | char buf[256]; |
1210 | d6fc1b39 | aliguori | const char *type; |
1211 | 858693c6 | bellard | int ret;
|
1212 | 858693c6 | bellard | |
1213 | cdb432b2 | Meador Inge | if (running || s->state == RS_INACTIVE) {
|
1214 | cdb432b2 | Meador Inge | return;
|
1215 | cdb432b2 | Meador Inge | } |
1216 | cdb432b2 | Meador Inge | /* Is there a GDB syscall waiting to be sent? */
|
1217 | cdb432b2 | Meador Inge | if (s->current_syscall_cb) {
|
1218 | cdb432b2 | Meador Inge | put_packet(s, s->syscall_buf); |
1219 | a2d1ebaf | pbrook | return;
|
1220 | e07bbac5 | Jan Kiszka | } |
1221 | 1dfb4dd9 | Luiz Capitulino | switch (state) {
|
1222 | 0461d5a6 | Luiz Capitulino | case RUN_STATE_DEBUG:
|
1223 | 880a7578 | aliguori | if (env->watchpoint_hit) {
|
1224 | 880a7578 | aliguori | switch (env->watchpoint_hit->flags & BP_MEM_ACCESS) {
|
1225 | a1d1bb31 | aliguori | case BP_MEM_READ:
|
1226 | d6fc1b39 | aliguori | type = "r";
|
1227 | d6fc1b39 | aliguori | break;
|
1228 | a1d1bb31 | aliguori | case BP_MEM_ACCESS:
|
1229 | d6fc1b39 | aliguori | type = "a";
|
1230 | d6fc1b39 | aliguori | break;
|
1231 | d6fc1b39 | aliguori | default:
|
1232 | d6fc1b39 | aliguori | type = "";
|
1233 | d6fc1b39 | aliguori | break;
|
1234 | d6fc1b39 | aliguori | } |
1235 | 880a7578 | aliguori | snprintf(buf, sizeof(buf),
|
1236 | 880a7578 | aliguori | "T%02xthread:%02x;%swatch:" TARGET_FMT_lx ";", |
1237 | 0d34282f | Andreas Färber | GDB_SIGNAL_TRAP, cpu_index(cpu), type, |
1238 | 880a7578 | aliguori | env->watchpoint_hit->vaddr); |
1239 | 880a7578 | aliguori | env->watchpoint_hit = NULL;
|
1240 | 425189a8 | Jan Kiszka | goto send_packet;
|
1241 | 6658ffb8 | pbrook | } |
1242 | 425189a8 | Jan Kiszka | tb_flush(env); |
1243 | ca587a8e | aurel32 | ret = GDB_SIGNAL_TRAP; |
1244 | 425189a8 | Jan Kiszka | break;
|
1245 | 0461d5a6 | Luiz Capitulino | case RUN_STATE_PAUSED:
|
1246 | 9781e040 | aliguori | ret = GDB_SIGNAL_INT; |
1247 | 425189a8 | Jan Kiszka | break;
|
1248 | 0461d5a6 | Luiz Capitulino | case RUN_STATE_SHUTDOWN:
|
1249 | 425189a8 | Jan Kiszka | ret = GDB_SIGNAL_QUIT; |
1250 | 425189a8 | Jan Kiszka | break;
|
1251 | 0461d5a6 | Luiz Capitulino | case RUN_STATE_IO_ERROR:
|
1252 | 425189a8 | Jan Kiszka | ret = GDB_SIGNAL_IO; |
1253 | 425189a8 | Jan Kiszka | break;
|
1254 | 0461d5a6 | Luiz Capitulino | case RUN_STATE_WATCHDOG:
|
1255 | 425189a8 | Jan Kiszka | ret = GDB_SIGNAL_ALRM; |
1256 | 425189a8 | Jan Kiszka | break;
|
1257 | 0461d5a6 | Luiz Capitulino | case RUN_STATE_INTERNAL_ERROR:
|
1258 | 425189a8 | Jan Kiszka | ret = GDB_SIGNAL_ABRT; |
1259 | 425189a8 | Jan Kiszka | break;
|
1260 | 0461d5a6 | Luiz Capitulino | case RUN_STATE_SAVE_VM:
|
1261 | 0461d5a6 | Luiz Capitulino | case RUN_STATE_RESTORE_VM:
|
1262 | 425189a8 | Jan Kiszka | return;
|
1263 | 0461d5a6 | Luiz Capitulino | case RUN_STATE_FINISH_MIGRATE:
|
1264 | 425189a8 | Jan Kiszka | ret = GDB_SIGNAL_XCPU; |
1265 | 425189a8 | Jan Kiszka | break;
|
1266 | 425189a8 | Jan Kiszka | default:
|
1267 | 425189a8 | Jan Kiszka | ret = GDB_SIGNAL_UNKNOWN; |
1268 | 425189a8 | Jan Kiszka | break;
|
1269 | bbeb7b5c | bellard | } |
1270 | 0d34282f | Andreas Färber | snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_index(cpu)); |
1271 | 425189a8 | Jan Kiszka | |
1272 | 425189a8 | Jan Kiszka | send_packet:
|
1273 | 858693c6 | bellard | put_packet(s, buf); |
1274 | 425189a8 | Jan Kiszka | |
1275 | 425189a8 | Jan Kiszka | /* disable single step if it was enabled */
|
1276 | 3825b28f | Andreas Färber | cpu_single_step(cpu, 0);
|
1277 | 858693c6 | bellard | } |
1278 | 1fddef4b | bellard | #endif
|
1279 | 858693c6 | bellard | |
1280 | a2d1ebaf | pbrook | /* Send a gdb syscall request.
|
1281 | a2d1ebaf | pbrook | This accepts limited printf-style format specifiers, specifically:
|
1282 | a87295e8 | pbrook | %x - target_ulong argument printed in hex.
|
1283 | a87295e8 | pbrook | %lx - 64-bit argument printed in hex.
|
1284 | a87295e8 | pbrook | %s - string pointer (target_ulong) and length (int) pair. */
|
1285 | 7ccfb2eb | blueswir1 | void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...) |
1286 | a2d1ebaf | pbrook | { |
1287 | a2d1ebaf | pbrook | va_list va; |
1288 | a2d1ebaf | pbrook | char *p;
|
1289 | cdb432b2 | Meador Inge | char *p_end;
|
1290 | a2d1ebaf | pbrook | target_ulong addr; |
1291 | a87295e8 | pbrook | uint64_t i64; |
1292 | a2d1ebaf | pbrook | GDBState *s; |
1293 | a2d1ebaf | pbrook | |
1294 | 880a7578 | aliguori | s = gdbserver_state; |
1295 | a2d1ebaf | pbrook | if (!s)
|
1296 | a2d1ebaf | pbrook | return;
|
1297 | cdb432b2 | Meador Inge | s->current_syscall_cb = cb; |
1298 | a2d1ebaf | pbrook | #ifndef CONFIG_USER_ONLY
|
1299 | 0461d5a6 | Luiz Capitulino | vm_stop(RUN_STATE_DEBUG); |
1300 | a2d1ebaf | pbrook | #endif
|
1301 | a2d1ebaf | pbrook | va_start(va, fmt); |
1302 | cdb432b2 | Meador Inge | p = s->syscall_buf; |
1303 | cdb432b2 | Meador Inge | p_end = &s->syscall_buf[sizeof(s->syscall_buf)];
|
1304 | a2d1ebaf | pbrook | *(p++) = 'F';
|
1305 | a2d1ebaf | pbrook | while (*fmt) {
|
1306 | a2d1ebaf | pbrook | if (*fmt == '%') { |
1307 | a2d1ebaf | pbrook | fmt++; |
1308 | a2d1ebaf | pbrook | switch (*fmt++) {
|
1309 | a2d1ebaf | pbrook | case 'x': |
1310 | a2d1ebaf | pbrook | addr = va_arg(va, target_ulong); |
1311 | cdb432b2 | Meador Inge | p += snprintf(p, p_end - p, TARGET_FMT_lx, addr); |
1312 | a2d1ebaf | pbrook | break;
|
1313 | a87295e8 | pbrook | case 'l': |
1314 | a87295e8 | pbrook | if (*(fmt++) != 'x') |
1315 | a87295e8 | pbrook | goto bad_format;
|
1316 | a87295e8 | pbrook | i64 = va_arg(va, uint64_t); |
1317 | cdb432b2 | Meador Inge | p += snprintf(p, p_end - p, "%" PRIx64, i64);
|
1318 | a87295e8 | pbrook | break;
|
1319 | a2d1ebaf | pbrook | case 's': |
1320 | a2d1ebaf | pbrook | addr = va_arg(va, target_ulong); |
1321 | cdb432b2 | Meador Inge | p += snprintf(p, p_end - p, TARGET_FMT_lx "/%x",
|
1322 | 363a37d5 | blueswir1 | addr, va_arg(va, int));
|
1323 | a2d1ebaf | pbrook | break;
|
1324 | a2d1ebaf | pbrook | default:
|
1325 | a87295e8 | pbrook | bad_format:
|
1326 | a2d1ebaf | pbrook | fprintf(stderr, "gdbstub: Bad syscall format string '%s'\n",
|
1327 | a2d1ebaf | pbrook | fmt - 1);
|
1328 | a2d1ebaf | pbrook | break;
|
1329 | a2d1ebaf | pbrook | } |
1330 | a2d1ebaf | pbrook | } else {
|
1331 | a2d1ebaf | pbrook | *(p++) = *(fmt++); |
1332 | a2d1ebaf | pbrook | } |
1333 | a2d1ebaf | pbrook | } |
1334 | 8a93e02a | pbrook | *p = 0;
|
1335 | a2d1ebaf | pbrook | va_end(va); |
1336 | a2d1ebaf | pbrook | #ifdef CONFIG_USER_ONLY
|
1337 | cdb432b2 | Meador Inge | put_packet(s, s->syscall_buf); |
1338 | 2e0f2cfb | Andreas Färber | gdb_handlesig(s->c_cpu, 0);
|
1339 | a2d1ebaf | pbrook | #else
|
1340 | cdb432b2 | Meador Inge | /* In this case wait to send the syscall packet until notification that
|
1341 | cdb432b2 | Meador Inge | the CPU has stopped. This must be done because if the packet is sent
|
1342 | cdb432b2 | Meador Inge | now the reply from the syscall request could be received while the CPU
|
1343 | cdb432b2 | Meador Inge | is still in the running state, which can cause packets to be dropped
|
1344 | cdb432b2 | Meador Inge | and state transition 'T' packets to be sent while the syscall is still
|
1345 | cdb432b2 | Meador Inge | being processed. */
|
1346 | 2e0f2cfb | Andreas Färber | cpu_exit(s->c_cpu); |
1347 | a2d1ebaf | pbrook | #endif
|
1348 | a2d1ebaf | pbrook | } |
1349 | a2d1ebaf | pbrook | |
1350 | 6a00d601 | bellard | static void gdb_read_byte(GDBState *s, int ch) |
1351 | 858693c6 | bellard | { |
1352 | 858693c6 | bellard | int i, csum;
|
1353 | 60fe76f3 | ths | uint8_t reply; |
1354 | 858693c6 | bellard | |
1355 | 1fddef4b | bellard | #ifndef CONFIG_USER_ONLY
|
1356 | 4046d913 | pbrook | if (s->last_packet_len) {
|
1357 | 4046d913 | pbrook | /* Waiting for a response to the last packet. If we see the start
|
1358 | 4046d913 | pbrook | of a new command then abandon the previous response. */
|
1359 | 4046d913 | pbrook | if (ch == '-') { |
1360 | 4046d913 | pbrook | #ifdef DEBUG_GDB
|
1361 | 4046d913 | pbrook | printf("Got NACK, retransmitting\n");
|
1362 | 4046d913 | pbrook | #endif
|
1363 | ffe8ab83 | ths | put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); |
1364 | 4046d913 | pbrook | } |
1365 | 4046d913 | pbrook | #ifdef DEBUG_GDB
|
1366 | 4046d913 | pbrook | else if (ch == '+') |
1367 | 4046d913 | pbrook | printf("Got ACK\n");
|
1368 | 4046d913 | pbrook | else
|
1369 | 4046d913 | pbrook | printf("Got '%c' when expecting ACK/NACK\n", ch);
|
1370 | 4046d913 | pbrook | #endif
|
1371 | 4046d913 | pbrook | if (ch == '+' || ch == '$') |
1372 | 4046d913 | pbrook | s->last_packet_len = 0;
|
1373 | 4046d913 | pbrook | if (ch != '$') |
1374 | 4046d913 | pbrook | return;
|
1375 | 4046d913 | pbrook | } |
1376 | 1354869c | Luiz Capitulino | if (runstate_is_running()) {
|
1377 | 858693c6 | bellard | /* when the CPU is running, we cannot do anything except stop
|
1378 | 858693c6 | bellard | it when receiving a char */
|
1379 | 0461d5a6 | Luiz Capitulino | vm_stop(RUN_STATE_PAUSED); |
1380 | 5fafdf24 | ths | } else
|
1381 | 1fddef4b | bellard | #endif
|
1382 | 41625033 | bellard | { |
1383 | 858693c6 | bellard | switch(s->state) {
|
1384 | 858693c6 | bellard | case RS_IDLE:
|
1385 | 858693c6 | bellard | if (ch == '$') { |
1386 | 858693c6 | bellard | s->line_buf_index = 0;
|
1387 | 858693c6 | bellard | s->state = RS_GETLINE; |
1388 | c33a346e | bellard | } |
1389 | b4608c04 | bellard | break;
|
1390 | 858693c6 | bellard | case RS_GETLINE:
|
1391 | 858693c6 | bellard | if (ch == '#') { |
1392 | 858693c6 | bellard | s->state = RS_CHKSUM1; |
1393 | 858693c6 | bellard | } else if (s->line_buf_index >= sizeof(s->line_buf) - 1) { |
1394 | 858693c6 | bellard | s->state = RS_IDLE; |
1395 | 4c3a88a2 | bellard | } else {
|
1396 | 858693c6 | bellard | s->line_buf[s->line_buf_index++] = ch; |
1397 | 4c3a88a2 | bellard | } |
1398 | 4c3a88a2 | bellard | break;
|
1399 | 858693c6 | bellard | case RS_CHKSUM1:
|
1400 | 858693c6 | bellard | s->line_buf[s->line_buf_index] = '\0';
|
1401 | 858693c6 | bellard | s->line_csum = fromhex(ch) << 4;
|
1402 | 858693c6 | bellard | s->state = RS_CHKSUM2; |
1403 | 858693c6 | bellard | break;
|
1404 | 858693c6 | bellard | case RS_CHKSUM2:
|
1405 | 858693c6 | bellard | s->line_csum |= fromhex(ch); |
1406 | 858693c6 | bellard | csum = 0;
|
1407 | 858693c6 | bellard | for(i = 0; i < s->line_buf_index; i++) { |
1408 | 858693c6 | bellard | csum += s->line_buf[i]; |
1409 | 858693c6 | bellard | } |
1410 | 858693c6 | bellard | if (s->line_csum != (csum & 0xff)) { |
1411 | 60fe76f3 | ths | reply = '-';
|
1412 | 60fe76f3 | ths | put_buffer(s, &reply, 1);
|
1413 | 858693c6 | bellard | s->state = RS_IDLE; |
1414 | 4c3a88a2 | bellard | } else {
|
1415 | 60fe76f3 | ths | reply = '+';
|
1416 | 60fe76f3 | ths | put_buffer(s, &reply, 1);
|
1417 | 880a7578 | aliguori | s->state = gdb_handle_packet(s, s->line_buf); |
1418 | 4c3a88a2 | bellard | } |
1419 | 4c3a88a2 | bellard | break;
|
1420 | a2d1ebaf | pbrook | default:
|
1421 | a2d1ebaf | pbrook | abort(); |
1422 | 858693c6 | bellard | } |
1423 | 858693c6 | bellard | } |
1424 | 858693c6 | bellard | } |
1425 | 858693c6 | bellard | |
1426 | 0e1c9c54 | Paul Brook | /* Tell the remote gdb that the process has exited. */
|
1427 | 9349b4f9 | Andreas Färber | void gdb_exit(CPUArchState *env, int code) |
1428 | 0e1c9c54 | Paul Brook | { |
1429 | 0e1c9c54 | Paul Brook | GDBState *s; |
1430 | 0e1c9c54 | Paul Brook | char buf[4]; |
1431 | 0e1c9c54 | Paul Brook | |
1432 | 0e1c9c54 | Paul Brook | s = gdbserver_state; |
1433 | 0e1c9c54 | Paul Brook | if (!s) {
|
1434 | 0e1c9c54 | Paul Brook | return;
|
1435 | 0e1c9c54 | Paul Brook | } |
1436 | 0e1c9c54 | Paul Brook | #ifdef CONFIG_USER_ONLY
|
1437 | 0e1c9c54 | Paul Brook | if (gdbserver_fd < 0 || s->fd < 0) { |
1438 | 0e1c9c54 | Paul Brook | return;
|
1439 | 0e1c9c54 | Paul Brook | } |
1440 | 0e1c9c54 | Paul Brook | #endif
|
1441 | 0e1c9c54 | Paul Brook | |
1442 | 0e1c9c54 | Paul Brook | snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); |
1443 | 0e1c9c54 | Paul Brook | put_packet(s, buf); |
1444 | e2af15b2 | Fabien Chouteau | |
1445 | e2af15b2 | Fabien Chouteau | #ifndef CONFIG_USER_ONLY
|
1446 | e2af15b2 | Fabien Chouteau | if (s->chr) {
|
1447 | 70f24fb6 | Anthony Liguori | qemu_chr_delete(s->chr); |
1448 | e2af15b2 | Fabien Chouteau | } |
1449 | e2af15b2 | Fabien Chouteau | #endif
|
1450 | 0e1c9c54 | Paul Brook | } |
1451 | 0e1c9c54 | Paul Brook | |
1452 | 1fddef4b | bellard | #ifdef CONFIG_USER_ONLY
|
1453 | 1fddef4b | bellard | int
|
1454 | ca587a8e | aurel32 | gdb_queuesig (void)
|
1455 | ca587a8e | aurel32 | { |
1456 | ca587a8e | aurel32 | GDBState *s; |
1457 | ca587a8e | aurel32 | |
1458 | ca587a8e | aurel32 | s = gdbserver_state; |
1459 | ca587a8e | aurel32 | |
1460 | ca587a8e | aurel32 | if (gdbserver_fd < 0 || s->fd < 0) |
1461 | ca587a8e | aurel32 | return 0; |
1462 | ca587a8e | aurel32 | else
|
1463 | ca587a8e | aurel32 | return 1; |
1464 | ca587a8e | aurel32 | } |
1465 | ca587a8e | aurel32 | |
1466 | ca587a8e | aurel32 | int
|
1467 | db6b81d4 | Andreas Färber | gdb_handlesig(CPUState *cpu, int sig)
|
1468 | 1fddef4b | bellard | { |
1469 | db6b81d4 | Andreas Färber | CPUArchState *env = cpu->env_ptr; |
1470 | 5ca666c7 | Andreas Färber | GDBState *s; |
1471 | 5ca666c7 | Andreas Färber | char buf[256]; |
1472 | 5ca666c7 | Andreas Färber | int n;
|
1473 | 1fddef4b | bellard | |
1474 | 5ca666c7 | Andreas Färber | s = gdbserver_state; |
1475 | 5ca666c7 | Andreas Färber | if (gdbserver_fd < 0 || s->fd < 0) { |
1476 | 5ca666c7 | Andreas Färber | return sig;
|
1477 | 5ca666c7 | Andreas Färber | } |
1478 | 1fddef4b | bellard | |
1479 | 5ca666c7 | Andreas Färber | /* disable single step if it was enabled */
|
1480 | 3825b28f | Andreas Färber | cpu_single_step(cpu, 0);
|
1481 | 5ca666c7 | Andreas Färber | tb_flush(env); |
1482 | 1fddef4b | bellard | |
1483 | 5ca666c7 | Andreas Färber | if (sig != 0) { |
1484 | 5ca666c7 | Andreas Färber | snprintf(buf, sizeof(buf), "S%02x", target_signal_to_gdb(sig)); |
1485 | 5ca666c7 | Andreas Färber | put_packet(s, buf); |
1486 | 5ca666c7 | Andreas Färber | } |
1487 | 5ca666c7 | Andreas Färber | /* put_packet() might have detected that the peer terminated the
|
1488 | 5ca666c7 | Andreas Färber | connection. */
|
1489 | 5ca666c7 | Andreas Färber | if (s->fd < 0) { |
1490 | 5ca666c7 | Andreas Färber | return sig;
|
1491 | 5ca666c7 | Andreas Färber | } |
1492 | 1fddef4b | bellard | |
1493 | 5ca666c7 | Andreas Färber | sig = 0;
|
1494 | 5ca666c7 | Andreas Färber | s->state = RS_IDLE; |
1495 | 5ca666c7 | Andreas Färber | s->running_state = 0;
|
1496 | 5ca666c7 | Andreas Färber | while (s->running_state == 0) { |
1497 | 5ca666c7 | Andreas Färber | n = read(s->fd, buf, 256);
|
1498 | 5ca666c7 | Andreas Färber | if (n > 0) { |
1499 | 5ca666c7 | Andreas Färber | int i;
|
1500 | 5ca666c7 | Andreas Färber | |
1501 | 5ca666c7 | Andreas Färber | for (i = 0; i < n; i++) { |
1502 | 5ca666c7 | Andreas Färber | gdb_read_byte(s, buf[i]); |
1503 | 5ca666c7 | Andreas Färber | } |
1504 | 5ca666c7 | Andreas Färber | } else if (n == 0 || errno != EAGAIN) { |
1505 | 5ca666c7 | Andreas Färber | /* XXX: Connection closed. Should probably wait for another
|
1506 | 5ca666c7 | Andreas Färber | connection before continuing. */
|
1507 | 5ca666c7 | Andreas Färber | return sig;
|
1508 | 1fddef4b | bellard | } |
1509 | 5ca666c7 | Andreas Färber | } |
1510 | 5ca666c7 | Andreas Färber | sig = s->signal; |
1511 | 5ca666c7 | Andreas Färber | s->signal = 0;
|
1512 | 5ca666c7 | Andreas Färber | return sig;
|
1513 | 1fddef4b | bellard | } |
1514 | e9009676 | bellard | |
1515 | ca587a8e | aurel32 | /* Tell the remote gdb that the process has exited due to SIG. */
|
1516 | 9349b4f9 | Andreas Färber | void gdb_signalled(CPUArchState *env, int sig) |
1517 | ca587a8e | aurel32 | { |
1518 | 5ca666c7 | Andreas Färber | GDBState *s; |
1519 | 5ca666c7 | Andreas Färber | char buf[4]; |
1520 | ca587a8e | aurel32 | |
1521 | 5ca666c7 | Andreas Färber | s = gdbserver_state; |
1522 | 5ca666c7 | Andreas Färber | if (gdbserver_fd < 0 || s->fd < 0) { |
1523 | 5ca666c7 | Andreas Färber | return;
|
1524 | 5ca666c7 | Andreas Färber | } |
1525 | ca587a8e | aurel32 | |
1526 | 5ca666c7 | Andreas Färber | snprintf(buf, sizeof(buf), "X%02x", target_signal_to_gdb(sig)); |
1527 | 5ca666c7 | Andreas Färber | put_packet(s, buf); |
1528 | ca587a8e | aurel32 | } |
1529 | 1fddef4b | bellard | |
1530 | 880a7578 | aliguori | static void gdb_accept(void) |
1531 | 858693c6 | bellard | { |
1532 | 858693c6 | bellard | GDBState *s; |
1533 | 858693c6 | bellard | struct sockaddr_in sockaddr;
|
1534 | 858693c6 | bellard | socklen_t len; |
1535 | bf1c852a | MORITA Kazutaka | int fd;
|
1536 | 858693c6 | bellard | |
1537 | 858693c6 | bellard | for(;;) {
|
1538 | 858693c6 | bellard | len = sizeof(sockaddr);
|
1539 | 858693c6 | bellard | fd = accept(gdbserver_fd, (struct sockaddr *)&sockaddr, &len);
|
1540 | 858693c6 | bellard | if (fd < 0 && errno != EINTR) { |
1541 | 858693c6 | bellard | perror("accept");
|
1542 | 858693c6 | bellard | return;
|
1543 | 858693c6 | bellard | } else if (fd >= 0) { |
1544 | 40ff6d7e | Kevin Wolf | #ifndef _WIN32
|
1545 | 40ff6d7e | Kevin Wolf | fcntl(fd, F_SETFD, FD_CLOEXEC); |
1546 | 40ff6d7e | Kevin Wolf | #endif
|
1547 | b4608c04 | bellard | break;
|
1548 | b4608c04 | bellard | } |
1549 | b4608c04 | bellard | } |
1550 | 858693c6 | bellard | |
1551 | 858693c6 | bellard | /* set short latency */
|
1552 | bf1c852a | MORITA Kazutaka | socket_set_nodelay(fd); |
1553 | 3b46e624 | ths | |
1554 | 7267c094 | Anthony Liguori | s = g_malloc0(sizeof(GDBState));
|
1555 | 2e0f2cfb | Andreas Färber | s->c_cpu = first_cpu; |
1556 | 2e0f2cfb | Andreas Färber | s->g_cpu = first_cpu; |
1557 | 858693c6 | bellard | s->fd = fd; |
1558 | 5b50e790 | Andreas Färber | gdb_has_xml = false;
|
1559 | 858693c6 | bellard | |
1560 | 880a7578 | aliguori | gdbserver_state = s; |
1561 | a2d1ebaf | pbrook | |
1562 | 858693c6 | bellard | fcntl(fd, F_SETFL, O_NONBLOCK); |
1563 | 858693c6 | bellard | } |
1564 | 858693c6 | bellard | |
1565 | 858693c6 | bellard | static int gdbserver_open(int port) |
1566 | 858693c6 | bellard | { |
1567 | 858693c6 | bellard | struct sockaddr_in sockaddr;
|
1568 | 858693c6 | bellard | int fd, val, ret;
|
1569 | 858693c6 | bellard | |
1570 | 858693c6 | bellard | fd = socket(PF_INET, SOCK_STREAM, 0);
|
1571 | 858693c6 | bellard | if (fd < 0) { |
1572 | 858693c6 | bellard | perror("socket");
|
1573 | 858693c6 | bellard | return -1; |
1574 | 858693c6 | bellard | } |
1575 | 40ff6d7e | Kevin Wolf | #ifndef _WIN32
|
1576 | 40ff6d7e | Kevin Wolf | fcntl(fd, F_SETFD, FD_CLOEXEC); |
1577 | 40ff6d7e | Kevin Wolf | #endif
|
1578 | 858693c6 | bellard | |
1579 | 858693c6 | bellard | /* allow fast reuse */
|
1580 | 858693c6 | bellard | val = 1;
|
1581 | 9957fc7f | Stefan Weil | qemu_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
1582 | 858693c6 | bellard | |
1583 | 858693c6 | bellard | sockaddr.sin_family = AF_INET; |
1584 | 858693c6 | bellard | sockaddr.sin_port = htons(port); |
1585 | 858693c6 | bellard | sockaddr.sin_addr.s_addr = 0;
|
1586 | 858693c6 | bellard | ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)); |
1587 | 858693c6 | bellard | if (ret < 0) { |
1588 | 858693c6 | bellard | perror("bind");
|
1589 | bb16172c | Peter Maydell | close(fd); |
1590 | 858693c6 | bellard | return -1; |
1591 | 858693c6 | bellard | } |
1592 | 858693c6 | bellard | ret = listen(fd, 0);
|
1593 | 858693c6 | bellard | if (ret < 0) { |
1594 | 858693c6 | bellard | perror("listen");
|
1595 | bb16172c | Peter Maydell | close(fd); |
1596 | 858693c6 | bellard | return -1; |
1597 | 858693c6 | bellard | } |
1598 | 858693c6 | bellard | return fd;
|
1599 | 858693c6 | bellard | } |
1600 | 858693c6 | bellard | |
1601 | 858693c6 | bellard | int gdbserver_start(int port) |
1602 | 858693c6 | bellard | { |
1603 | 858693c6 | bellard | gdbserver_fd = gdbserver_open(port); |
1604 | 858693c6 | bellard | if (gdbserver_fd < 0) |
1605 | 858693c6 | bellard | return -1; |
1606 | 858693c6 | bellard | /* accept connections */
|
1607 | 880a7578 | aliguori | gdb_accept(); |
1608 | 4046d913 | pbrook | return 0; |
1609 | 4046d913 | pbrook | } |
1610 | 2b1319c8 | aurel32 | |
1611 | 2b1319c8 | aurel32 | /* Disable gdb stub for child processes. */
|
1612 | 9349b4f9 | Andreas Färber | void gdbserver_fork(CPUArchState *env)
|
1613 | 2b1319c8 | aurel32 | { |
1614 | 2b1319c8 | aurel32 | GDBState *s = gdbserver_state; |
1615 | 9f6164d6 | edgar_igl | if (gdbserver_fd < 0 || s->fd < 0) |
1616 | 2b1319c8 | aurel32 | return;
|
1617 | 2b1319c8 | aurel32 | close(s->fd); |
1618 | 2b1319c8 | aurel32 | s->fd = -1;
|
1619 | 2b1319c8 | aurel32 | cpu_breakpoint_remove_all(env, BP_GDB); |
1620 | 2b1319c8 | aurel32 | cpu_watchpoint_remove_all(env, BP_GDB); |
1621 | 2b1319c8 | aurel32 | } |
1622 | 1fddef4b | bellard | #else
|
1623 | aa1f17c1 | ths | static int gdb_chr_can_receive(void *opaque) |
1624 | 4046d913 | pbrook | { |
1625 | 56aebc89 | pbrook | /* We can handle an arbitrarily large amount of data.
|
1626 | 56aebc89 | pbrook | Pick the maximum packet size, which is as good as anything. */
|
1627 | 56aebc89 | pbrook | return MAX_PACKET_LENGTH;
|
1628 | 4046d913 | pbrook | } |
1629 | 4046d913 | pbrook | |
1630 | aa1f17c1 | ths | static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size) |
1631 | 4046d913 | pbrook | { |
1632 | 4046d913 | pbrook | int i;
|
1633 | 4046d913 | pbrook | |
1634 | 4046d913 | pbrook | for (i = 0; i < size; i++) { |
1635 | 880a7578 | aliguori | gdb_read_byte(gdbserver_state, buf[i]); |
1636 | 4046d913 | pbrook | } |
1637 | 4046d913 | pbrook | } |
1638 | 4046d913 | pbrook | |
1639 | 4046d913 | pbrook | static void gdb_chr_event(void *opaque, int event) |
1640 | 4046d913 | pbrook | { |
1641 | 4046d913 | pbrook | switch (event) {
|
1642 | b6b8df56 | Amit Shah | case CHR_EVENT_OPENED:
|
1643 | 0461d5a6 | Luiz Capitulino | vm_stop(RUN_STATE_PAUSED); |
1644 | 5b50e790 | Andreas Färber | gdb_has_xml = false;
|
1645 | 4046d913 | pbrook | break;
|
1646 | 4046d913 | pbrook | default:
|
1647 | 4046d913 | pbrook | break;
|
1648 | 4046d913 | pbrook | } |
1649 | 4046d913 | pbrook | } |
1650 | 4046d913 | pbrook | |
1651 | 8a34a0fb | aliguori | static void gdb_monitor_output(GDBState *s, const char *msg, int len) |
1652 | 8a34a0fb | aliguori | { |
1653 | 8a34a0fb | aliguori | char buf[MAX_PACKET_LENGTH];
|
1654 | 8a34a0fb | aliguori | |
1655 | 8a34a0fb | aliguori | buf[0] = 'O'; |
1656 | 8a34a0fb | aliguori | if (len > (MAX_PACKET_LENGTH/2) - 1) |
1657 | 8a34a0fb | aliguori | len = (MAX_PACKET_LENGTH/2) - 1; |
1658 | 8a34a0fb | aliguori | memtohex(buf + 1, (uint8_t *)msg, len);
|
1659 | 8a34a0fb | aliguori | put_packet(s, buf); |
1660 | 8a34a0fb | aliguori | } |
1661 | 8a34a0fb | aliguori | |
1662 | 8a34a0fb | aliguori | static int gdb_monitor_write(CharDriverState *chr, const uint8_t *buf, int len) |
1663 | 8a34a0fb | aliguori | { |
1664 | 8a34a0fb | aliguori | const char *p = (const char *)buf; |
1665 | 8a34a0fb | aliguori | int max_sz;
|
1666 | 8a34a0fb | aliguori | |
1667 | 8a34a0fb | aliguori | max_sz = (sizeof(gdbserver_state->last_packet) - 2) / 2; |
1668 | 8a34a0fb | aliguori | for (;;) {
|
1669 | 8a34a0fb | aliguori | if (len <= max_sz) {
|
1670 | 8a34a0fb | aliguori | gdb_monitor_output(gdbserver_state, p, len); |
1671 | 8a34a0fb | aliguori | break;
|
1672 | 8a34a0fb | aliguori | } |
1673 | 8a34a0fb | aliguori | gdb_monitor_output(gdbserver_state, p, max_sz); |
1674 | 8a34a0fb | aliguori | p += max_sz; |
1675 | 8a34a0fb | aliguori | len -= max_sz; |
1676 | 8a34a0fb | aliguori | } |
1677 | 8a34a0fb | aliguori | return len;
|
1678 | 8a34a0fb | aliguori | } |
1679 | 8a34a0fb | aliguori | |
1680 | 59030a8c | aliguori | #ifndef _WIN32
|
1681 | 59030a8c | aliguori | static void gdb_sigterm_handler(int signal) |
1682 | 59030a8c | aliguori | { |
1683 | 1354869c | Luiz Capitulino | if (runstate_is_running()) {
|
1684 | 0461d5a6 | Luiz Capitulino | vm_stop(RUN_STATE_PAUSED); |
1685 | e07bbac5 | Jan Kiszka | } |
1686 | 59030a8c | aliguori | } |
1687 | 59030a8c | aliguori | #endif
|
1688 | 59030a8c | aliguori | |
1689 | 59030a8c | aliguori | int gdbserver_start(const char *device) |
1690 | 4046d913 | pbrook | { |
1691 | 4046d913 | pbrook | GDBState *s; |
1692 | 59030a8c | aliguori | char gdbstub_device_name[128]; |
1693 | 36556b20 | aliguori | CharDriverState *chr = NULL;
|
1694 | 36556b20 | aliguori | CharDriverState *mon_chr; |
1695 | cfc3475a | pbrook | |
1696 | 59030a8c | aliguori | if (!device)
|
1697 | 59030a8c | aliguori | return -1; |
1698 | 59030a8c | aliguori | if (strcmp(device, "none") != 0) { |
1699 | 59030a8c | aliguori | if (strstart(device, "tcp:", NULL)) { |
1700 | 59030a8c | aliguori | /* enforce required TCP attributes */
|
1701 | 59030a8c | aliguori | snprintf(gdbstub_device_name, sizeof(gdbstub_device_name),
|
1702 | 59030a8c | aliguori | "%s,nowait,nodelay,server", device);
|
1703 | 59030a8c | aliguori | device = gdbstub_device_name; |
1704 | 36556b20 | aliguori | } |
1705 | 59030a8c | aliguori | #ifndef _WIN32
|
1706 | 59030a8c | aliguori | else if (strcmp(device, "stdio") == 0) { |
1707 | 59030a8c | aliguori | struct sigaction act;
|
1708 | 4046d913 | pbrook | |
1709 | 59030a8c | aliguori | memset(&act, 0, sizeof(act)); |
1710 | 59030a8c | aliguori | act.sa_handler = gdb_sigterm_handler; |
1711 | 59030a8c | aliguori | sigaction(SIGINT, &act, NULL);
|
1712 | 59030a8c | aliguori | } |
1713 | 59030a8c | aliguori | #endif
|
1714 | 27143a44 | Anthony Liguori | chr = qemu_chr_new("gdb", device, NULL); |
1715 | 36556b20 | aliguori | if (!chr)
|
1716 | 36556b20 | aliguori | return -1; |
1717 | 36556b20 | aliguori | |
1718 | 456d6069 | Hans de Goede | qemu_chr_fe_claim_no_fail(chr); |
1719 | 36556b20 | aliguori | qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive, |
1720 | 36556b20 | aliguori | gdb_chr_event, NULL);
|
1721 | cfc3475a | pbrook | } |
1722 | cfc3475a | pbrook | |
1723 | 36556b20 | aliguori | s = gdbserver_state; |
1724 | 36556b20 | aliguori | if (!s) {
|
1725 | 7267c094 | Anthony Liguori | s = g_malloc0(sizeof(GDBState));
|
1726 | 36556b20 | aliguori | gdbserver_state = s; |
1727 | 4046d913 | pbrook | |
1728 | 36556b20 | aliguori | qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);
|
1729 | 36556b20 | aliguori | |
1730 | 36556b20 | aliguori | /* Initialize a monitor terminal for gdb */
|
1731 | 7267c094 | Anthony Liguori | mon_chr = g_malloc0(sizeof(*mon_chr));
|
1732 | 36556b20 | aliguori | mon_chr->chr_write = gdb_monitor_write; |
1733 | 36556b20 | aliguori | monitor_init(mon_chr, 0);
|
1734 | 36556b20 | aliguori | } else {
|
1735 | 36556b20 | aliguori | if (s->chr)
|
1736 | 70f24fb6 | Anthony Liguori | qemu_chr_delete(s->chr); |
1737 | 36556b20 | aliguori | mon_chr = s->mon_chr; |
1738 | 36556b20 | aliguori | memset(s, 0, sizeof(GDBState)); |
1739 | 36556b20 | aliguori | } |
1740 | 2e0f2cfb | Andreas Färber | s->c_cpu = first_cpu; |
1741 | 2e0f2cfb | Andreas Färber | s->g_cpu = first_cpu; |
1742 | 4046d913 | pbrook | s->chr = chr; |
1743 | 36556b20 | aliguori | s->state = chr ? RS_IDLE : RS_INACTIVE; |
1744 | 36556b20 | aliguori | s->mon_chr = mon_chr; |
1745 | cdb432b2 | Meador Inge | s->current_syscall_cb = NULL;
|
1746 | 8a34a0fb | aliguori | |
1747 | b4608c04 | bellard | return 0; |
1748 | b4608c04 | bellard | } |
1749 | 4046d913 | pbrook | #endif |