Merge tag 'v9.1.0'
[qemu/ar7.git] / gdbstub / user.c
blobb36033bc7a29e38ddae0fbc20c685c2e4f4003c3
1 /*
2 * gdbstub user-mode helper routines.
4 * We know for user-mode we are using TCG so we can call stuff directly.
6 * Copyright (c) 2003-2005 Fabrice Bellard
7 * Copyright (c) 2022 Linaro Ltd
9 * SPDX-License-Identifier: LGPL-2.0+
12 #include "qemu/osdep.h"
13 #include "qemu/bitops.h"
14 #include "qemu/cutils.h"
15 #include "qemu/sockets.h"
16 #include "exec/hwaddr.h"
17 #include "exec/tb-flush.h"
18 #include "exec/gdbstub.h"
19 #include "gdbstub/commands.h"
20 #include "gdbstub/syscalls.h"
21 #include "gdbstub/user.h"
22 #include "gdbstub/enums.h"
23 #include "hw/core/cpu.h"
24 #include "trace.h"
25 #include "internals.h"
27 #define GDB_NR_SYSCALLS 1024
28 typedef unsigned long GDBSyscallsMask[BITS_TO_LONGS(GDB_NR_SYSCALLS)];
31 * Forked child talks to its parent in order to let GDB enforce the
32 * follow-fork-mode. This happens inside a start_exclusive() section, so that
33 * the other threads, which may be forking too, do not interfere. The
34 * implementation relies on GDB not sending $vCont until it has detached
35 * either from the parent (follow-fork-mode child) or from the child
36 * (follow-fork-mode parent).
38 * The parent and the child share the GDB socket; at any given time only one
39 * of them is allowed to use it, as is reflected in the respective fork_state.
40 * This is negotiated via the fork_sockets pair as a reaction to $Hg.
42 * Below is a short summary of the possible state transitions:
44 * ENABLED : Terminal state.
45 * DISABLED : Terminal state.
46 * ACTIVE : Parent initial state.
47 * INACTIVE : Child initial state.
48 * ACTIVE -> DEACTIVATING: On $Hg.
49 * ACTIVE -> ENABLING : On $D.
50 * ACTIVE -> DISABLING : On $D.
51 * ACTIVE -> DISABLED : On communication error.
52 * DEACTIVATING -> INACTIVE : On gdb_read_byte() return.
53 * DEACTIVATING -> DISABLED : On communication error.
54 * INACTIVE -> ACTIVE : On $Hg in the peer.
55 * INACTIVE -> ENABLE : On $D in the peer.
56 * INACTIVE -> DISABLE : On $D in the peer.
57 * INACTIVE -> DISABLED : On communication error.
58 * ENABLING -> ENABLED : On gdb_read_byte() return.
59 * ENABLING -> DISABLED : On communication error.
60 * DISABLING -> DISABLED : On gdb_read_byte() return.
62 enum GDBForkState {
63 /* Fully owning the GDB socket. */
64 GDB_FORK_ENABLED,
65 /* Working with the GDB socket; the peer is inactive. */
66 GDB_FORK_ACTIVE,
67 /* Handing off the GDB socket to the peer. */
68 GDB_FORK_DEACTIVATING,
69 /* The peer is working with the GDB socket. */
70 GDB_FORK_INACTIVE,
71 /* Asking the peer to close its GDB socket fd. */
72 GDB_FORK_ENABLING,
73 /* Asking the peer to take over, closing our GDB socket fd. */
74 GDB_FORK_DISABLING,
75 /* The peer has taken over, our GDB socket fd is closed. */
76 GDB_FORK_DISABLED,
79 enum GDBForkMessage {
80 GDB_FORK_ACTIVATE = 'a',
81 GDB_FORK_ENABLE = 'e',
82 GDB_FORK_DISABLE = 'd',
85 /* User-mode specific state */
86 typedef struct {
87 int fd;
88 char *socket_path;
89 int running_state;
91 * Store syscalls mask without memory allocation in order to avoid
92 * implementing synchronization.
94 bool catch_all_syscalls;
95 GDBSyscallsMask catch_syscalls_mask;
96 bool fork_events;
97 enum GDBForkState fork_state;
98 int fork_sockets[2];
99 pid_t fork_peer_pid, fork_peer_tid;
100 uint8_t siginfo[MAX_SIGINFO_LENGTH];
101 unsigned long siginfo_len;
102 } GDBUserState;
104 static GDBUserState gdbserver_user_state;
106 int gdb_get_char(void)
108 uint8_t ch;
109 int ret;
111 for (;;) {
112 ret = recv(gdbserver_user_state.fd, &ch, 1, 0);
113 if (ret < 0) {
114 if (errno == ECONNRESET) {
115 gdbserver_user_state.fd = -1;
117 if (errno != EINTR) {
118 return -1;
120 } else if (ret == 0) {
121 close(gdbserver_user_state.fd);
122 gdbserver_user_state.fd = -1;
123 return -1;
124 } else {
125 break;
128 return ch;
131 bool gdb_got_immediate_ack(void)
133 int i;
135 i = gdb_get_char();
136 if (i < 0) {
137 /* no response, continue anyway */
138 return true;
141 if (i == '+') {
142 /* received correctly, continue */
143 return true;
146 /* anything else, including '-' then try again */
147 return false;
150 void gdb_put_buffer(const uint8_t *buf, int len)
152 int ret;
154 while (len > 0) {
155 ret = send(gdbserver_user_state.fd, buf, len, 0);
156 if (ret < 0) {
157 if (errno != EINTR) {
158 return;
160 } else {
161 buf += ret;
162 len -= ret;
167 /* Tell the remote gdb that the process has exited. */
168 void gdb_exit(int code)
170 char buf[4];
172 if (!gdbserver_state.init) {
173 return;
175 if (gdbserver_user_state.socket_path) {
176 unlink(gdbserver_user_state.socket_path);
178 if (gdbserver_user_state.fd < 0) {
179 return;
182 trace_gdbstub_op_exiting((uint8_t)code);
184 if (gdbserver_state.allow_stop_reply) {
185 snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code);
186 gdb_put_packet(buf);
187 gdbserver_state.allow_stop_reply = false;
192 void gdb_qemu_exit(int code)
194 exit(code);
197 int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo,
198 int siginfo_len)
200 char buf[256];
201 int n;
203 if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
204 return sig;
207 if (siginfo) {
209 * Save target-specific siginfo.
211 * siginfo size, i.e. siginfo_len, is asserted at compile-time to fit in
212 * gdbserver_user_state.siginfo, usually in the source file calling
213 * gdb_handlesig. See, for instance, {linux,bsd}-user/signal.c.
215 memcpy(gdbserver_user_state.siginfo, siginfo, siginfo_len);
216 gdbserver_user_state.siginfo_len = siginfo_len;
219 /* disable single step if it was enabled */
220 cpu_single_step(cpu, 0);
221 tb_flush(cpu);
223 if (sig != 0) {
224 gdb_set_stop_cpu(cpu);
225 if (gdbserver_state.allow_stop_reply) {
226 g_string_printf(gdbserver_state.str_buf,
227 "T%02xthread:", gdb_target_signal_to_gdb(sig));
228 gdb_append_thread_id(cpu, gdbserver_state.str_buf);
229 g_string_append_c(gdbserver_state.str_buf, ';');
230 if (reason) {
231 g_string_append(gdbserver_state.str_buf, reason);
233 gdb_put_strbuf();
234 gdbserver_state.allow_stop_reply = false;
238 * gdb_put_packet() might have detected that the peer terminated the
239 * connection.
241 if (gdbserver_user_state.fd < 0) {
242 return sig;
245 sig = 0;
246 gdbserver_state.state = RS_IDLE;
247 gdbserver_user_state.running_state = 0;
248 while (gdbserver_user_state.running_state == 0) {
249 n = read(gdbserver_user_state.fd, buf, 256);
250 if (n > 0) {
251 int i;
253 for (i = 0; i < n; i++) {
254 gdb_read_byte(buf[i]);
256 } else {
258 * XXX: Connection closed. Should probably wait for another
259 * connection before continuing.
261 if (n == 0) {
262 close(gdbserver_user_state.fd);
264 gdbserver_user_state.fd = -1;
265 return sig;
268 sig = gdbserver_state.signal;
269 gdbserver_state.signal = 0;
270 return sig;
273 /* Tell the remote gdb that the process has exited due to SIG. */
274 void gdb_signalled(CPUArchState *env, int sig)
276 char buf[4];
278 if (!gdbserver_state.init || gdbserver_user_state.fd < 0 ||
279 !gdbserver_state.allow_stop_reply) {
280 return;
283 snprintf(buf, sizeof(buf), "X%02x", gdb_target_signal_to_gdb(sig));
284 gdb_put_packet(buf);
285 gdbserver_state.allow_stop_reply = false;
288 static void gdb_accept_init(int fd)
290 gdb_init_gdbserver_state();
291 gdb_create_default_process(&gdbserver_state);
292 gdbserver_state.processes[0].attached = true;
293 gdbserver_state.c_cpu = gdb_first_attached_cpu();
294 gdbserver_state.g_cpu = gdbserver_state.c_cpu;
295 gdbserver_user_state.fd = fd;
298 static bool gdb_accept_socket(int gdb_fd)
300 int fd;
302 for (;;) {
303 fd = accept(gdb_fd, NULL, NULL);
304 if (fd < 0 && errno != EINTR) {
305 perror("accept socket");
306 return false;
307 } else if (fd >= 0) {
308 qemu_set_cloexec(fd);
309 break;
313 gdb_accept_init(fd);
314 return true;
317 static int gdbserver_open_socket(const char *path)
319 struct sockaddr_un sockaddr = {};
320 int fd, ret;
322 fd = socket(AF_UNIX, SOCK_STREAM, 0);
323 if (fd < 0) {
324 perror("create socket");
325 return -1;
328 sockaddr.sun_family = AF_UNIX;
329 pstrcpy(sockaddr.sun_path, sizeof(sockaddr.sun_path) - 1, path);
330 ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
331 if (ret < 0) {
332 perror("bind socket");
333 close(fd);
334 return -1;
336 ret = listen(fd, 1);
337 if (ret < 0) {
338 perror("listen socket");
339 close(fd);
340 return -1;
343 return fd;
346 static bool gdb_accept_tcp(int gdb_fd)
348 struct sockaddr_in sockaddr = {};
349 socklen_t len;
350 int fd;
352 for (;;) {
353 len = sizeof(sockaddr);
354 fd = accept(gdb_fd, (struct sockaddr *)&sockaddr, &len);
355 if (fd < 0 && errno != EINTR) {
356 perror("accept");
357 return false;
358 } else if (fd >= 0) {
359 qemu_set_cloexec(fd);
360 break;
364 /* set short latency */
365 if (socket_set_nodelay(fd)) {
366 perror("setsockopt");
367 close(fd);
368 return false;
371 gdb_accept_init(fd);
372 return true;
375 static int gdbserver_open_port(int port)
377 struct sockaddr_in sockaddr;
378 int fd, ret;
380 fd = socket(PF_INET, SOCK_STREAM, 0);
381 if (fd < 0) {
382 perror("socket");
383 return -1;
385 qemu_set_cloexec(fd);
387 socket_set_fast_reuse(fd);
389 sockaddr.sin_family = AF_INET;
390 sockaddr.sin_port = htons(port);
391 sockaddr.sin_addr.s_addr = 0;
392 ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
393 if (ret < 0) {
394 perror("bind");
395 close(fd);
396 return -1;
398 ret = listen(fd, 1);
399 if (ret < 0) {
400 perror("listen");
401 close(fd);
402 return -1;
405 return fd;
408 int gdbserver_start(const char *port_or_path)
410 int port = g_ascii_strtoull(port_or_path, NULL, 10);
411 int gdb_fd;
413 if (port > 0) {
414 gdb_fd = gdbserver_open_port(port);
415 } else {
416 gdb_fd = gdbserver_open_socket(port_or_path);
419 if (gdb_fd < 0) {
420 return -1;
423 if (port > 0 && gdb_accept_tcp(gdb_fd)) {
424 return 0;
425 } else if (gdb_accept_socket(gdb_fd)) {
426 gdbserver_user_state.socket_path = g_strdup(port_or_path);
427 return 0;
430 /* gone wrong */
431 close(gdb_fd);
432 return -1;
435 void gdbserver_fork_start(void)
437 if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
438 return;
440 if (!gdbserver_user_state.fork_events ||
441 qemu_socketpair(AF_UNIX, SOCK_STREAM, 0,
442 gdbserver_user_state.fork_sockets) < 0) {
443 gdbserver_user_state.fork_state = GDB_FORK_DISABLED;
444 return;
446 gdbserver_user_state.fork_state = GDB_FORK_INACTIVE;
447 gdbserver_user_state.fork_peer_pid = getpid();
448 gdbserver_user_state.fork_peer_tid = qemu_get_thread_id();
451 static void disable_gdbstub(CPUState *thread_cpu)
453 CPUState *cpu;
455 close(gdbserver_user_state.fd);
456 gdbserver_user_state.fd = -1;
457 CPU_FOREACH(cpu) {
458 cpu_breakpoint_remove_all(cpu, BP_GDB);
459 /* no cpu_watchpoint_remove_all for user-mode */
460 cpu_single_step(cpu, 0);
462 tb_flush(thread_cpu);
465 void gdbserver_fork_end(CPUState *cpu, pid_t pid)
467 char b;
468 int fd;
470 if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
471 return;
474 if (pid == -1) {
475 if (gdbserver_user_state.fork_state != GDB_FORK_DISABLED) {
476 g_assert(gdbserver_user_state.fork_state == GDB_FORK_INACTIVE);
477 close(gdbserver_user_state.fork_sockets[0]);
478 close(gdbserver_user_state.fork_sockets[1]);
480 return;
483 if (gdbserver_user_state.fork_state == GDB_FORK_DISABLED) {
484 if (pid == 0) {
485 disable_gdbstub(cpu);
487 return;
490 if (pid == 0) {
491 close(gdbserver_user_state.fork_sockets[0]);
492 fd = gdbserver_user_state.fork_sockets[1];
493 g_assert(gdbserver_state.process_num == 1);
494 g_assert(gdbserver_state.processes[0].pid ==
495 gdbserver_user_state.fork_peer_pid);
496 g_assert(gdbserver_state.processes[0].attached);
497 gdbserver_state.processes[0].pid = getpid();
498 } else {
499 close(gdbserver_user_state.fork_sockets[1]);
500 fd = gdbserver_user_state.fork_sockets[0];
501 gdbserver_user_state.fork_state = GDB_FORK_ACTIVE;
502 gdbserver_user_state.fork_peer_pid = pid;
503 gdbserver_user_state.fork_peer_tid = pid;
505 if (!gdbserver_state.allow_stop_reply) {
506 goto fail;
508 g_string_printf(gdbserver_state.str_buf,
509 "T%02xfork:p%02x.%02x;thread:p%02x.%02x;",
510 gdb_target_signal_to_gdb(gdb_target_sigtrap()),
511 pid, pid, (int)getpid(), qemu_get_thread_id());
512 gdb_put_strbuf();
515 gdbserver_state.state = RS_IDLE;
516 gdbserver_state.allow_stop_reply = false;
517 gdbserver_user_state.running_state = 0;
518 for (;;) {
519 switch (gdbserver_user_state.fork_state) {
520 case GDB_FORK_ENABLED:
521 if (gdbserver_user_state.running_state) {
522 close(fd);
523 return;
525 QEMU_FALLTHROUGH;
526 case GDB_FORK_ACTIVE:
527 if (read(gdbserver_user_state.fd, &b, 1) != 1) {
528 goto fail;
530 gdb_read_byte(b);
531 break;
532 case GDB_FORK_DEACTIVATING:
533 b = GDB_FORK_ACTIVATE;
534 if (write(fd, &b, 1) != 1) {
535 goto fail;
537 gdbserver_user_state.fork_state = GDB_FORK_INACTIVE;
538 break;
539 case GDB_FORK_INACTIVE:
540 if (read(fd, &b, 1) != 1) {
541 goto fail;
543 switch (b) {
544 case GDB_FORK_ACTIVATE:
545 gdbserver_user_state.fork_state = GDB_FORK_ACTIVE;
546 break;
547 case GDB_FORK_ENABLE:
548 gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
549 break;
550 case GDB_FORK_DISABLE:
551 gdbserver_user_state.fork_state = GDB_FORK_DISABLED;
552 break;
553 default:
554 g_assert_not_reached();
556 break;
557 case GDB_FORK_ENABLING:
558 b = GDB_FORK_DISABLE;
559 if (write(fd, &b, 1) != 1) {
560 goto fail;
562 gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
563 break;
564 case GDB_FORK_DISABLING:
565 b = GDB_FORK_ENABLE;
566 if (write(fd, &b, 1) != 1) {
567 goto fail;
569 gdbserver_user_state.fork_state = GDB_FORK_DISABLED;
570 break;
571 case GDB_FORK_DISABLED:
572 close(fd);
573 disable_gdbstub(cpu);
574 return;
575 default:
576 g_assert_not_reached();
580 fail:
581 close(fd);
582 if (pid == 0) {
583 disable_gdbstub(cpu);
587 void gdb_handle_query_supported_user(const char *gdb_supported)
589 if (strstr(gdb_supported, "fork-events+")) {
590 gdbserver_user_state.fork_events = true;
592 g_string_append(gdbserver_state.str_buf, ";fork-events+");
595 bool gdb_handle_set_thread_user(uint32_t pid, uint32_t tid)
597 if (gdbserver_user_state.fork_state == GDB_FORK_ACTIVE &&
598 pid == gdbserver_user_state.fork_peer_pid &&
599 tid == gdbserver_user_state.fork_peer_tid) {
600 gdbserver_user_state.fork_state = GDB_FORK_DEACTIVATING;
601 gdb_put_packet("OK");
602 return true;
604 return false;
607 bool gdb_handle_detach_user(uint32_t pid)
609 bool enable;
611 if (gdbserver_user_state.fork_state == GDB_FORK_ACTIVE) {
612 enable = pid == gdbserver_user_state.fork_peer_pid;
613 if (enable || pid == getpid()) {
614 gdbserver_user_state.fork_state = enable ? GDB_FORK_ENABLING :
615 GDB_FORK_DISABLING;
616 gdb_put_packet("OK");
617 return true;
620 return false;
624 * Execution state helpers
627 void gdb_handle_query_attached(GArray *params, void *user_ctx)
629 gdb_put_packet("0");
632 void gdb_continue(void)
634 gdbserver_user_state.running_state = 1;
635 trace_gdbstub_op_continue();
639 * Resume execution, for user-mode emulation it's equivalent to
640 * gdb_continue.
642 int gdb_continue_partial(char *newstates)
644 CPUState *cpu;
645 int res = 0;
647 * This is not exactly accurate, but it's an improvement compared to the
648 * previous situation, where only one CPU would be single-stepped.
650 CPU_FOREACH(cpu) {
651 if (newstates[cpu->cpu_index] == 's') {
652 trace_gdbstub_op_stepping(cpu->cpu_index);
653 cpu_single_step(cpu, gdbserver_state.sstep_flags);
656 gdbserver_user_state.running_state = 1;
657 return res;
661 * Memory access helpers
663 int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr,
664 uint8_t *buf, int len, bool is_write)
666 CPUClass *cc;
668 cc = CPU_GET_CLASS(cpu);
669 if (cc->memory_rw_debug) {
670 return cc->memory_rw_debug(cpu, addr, buf, len, is_write);
672 return cpu_memory_rw_debug(cpu, addr, buf, len, is_write);
676 * cpu helpers
679 unsigned int gdb_get_max_cpus(void)
681 CPUState *cpu;
682 unsigned int max_cpus = 1;
684 CPU_FOREACH(cpu) {
685 max_cpus = max_cpus <= cpu->cpu_index ? cpu->cpu_index + 1 : max_cpus;
688 return max_cpus;
691 /* replay not supported for user-mode */
692 bool gdb_can_reverse(void)
694 return false;
698 * Break/Watch point helpers
701 bool gdb_supports_guest_debug(void)
703 /* user-mode == TCG == supported */
704 return true;
707 int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len)
709 CPUState *cpu;
710 int err = 0;
712 switch (type) {
713 case GDB_BREAKPOINT_SW:
714 case GDB_BREAKPOINT_HW:
715 CPU_FOREACH(cpu) {
716 err = cpu_breakpoint_insert(cpu, addr, BP_GDB, NULL);
717 if (err) {
718 break;
721 return err;
722 default:
723 /* user-mode doesn't support watchpoints */
724 return -ENOSYS;
728 int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len)
730 CPUState *cpu;
731 int err = 0;
733 switch (type) {
734 case GDB_BREAKPOINT_SW:
735 case GDB_BREAKPOINT_HW:
736 CPU_FOREACH(cpu) {
737 err = cpu_breakpoint_remove(cpu, addr, BP_GDB);
738 if (err) {
739 break;
742 return err;
743 default:
744 /* user-mode doesn't support watchpoints */
745 return -ENOSYS;
749 void gdb_breakpoint_remove_all(CPUState *cs)
751 cpu_breakpoint_remove_all(cs, BP_GDB);
755 * For user-mode syscall support we send the system call immediately
756 * and then return control to gdb for it to process the syscall request.
757 * Since the protocol requires that gdb hands control back to us
758 * using a "here are the results" F packet, we don't need to check
759 * gdb_handlesig's return value (which is the signal to deliver if
760 * execution was resumed via a continue packet).
762 void gdb_syscall_handling(const char *syscall_packet)
764 gdb_put_packet(syscall_packet);
765 gdb_handlesig(gdbserver_state.c_cpu, 0, NULL, NULL, 0);
768 static bool should_catch_syscall(int num)
770 if (gdbserver_user_state.catch_all_syscalls) {
771 return true;
773 if (num < 0 || num >= GDB_NR_SYSCALLS) {
774 return false;
776 return test_bit(num, gdbserver_user_state.catch_syscalls_mask);
779 void gdb_syscall_entry(CPUState *cs, int num)
781 if (should_catch_syscall(num)) {
782 g_autofree char *reason = g_strdup_printf("syscall_entry:%x;", num);
783 gdb_handlesig(cs, gdb_target_sigtrap(), reason, NULL, 0);
787 void gdb_syscall_return(CPUState *cs, int num)
789 if (should_catch_syscall(num)) {
790 g_autofree char *reason = g_strdup_printf("syscall_return:%x;", num);
791 gdb_handlesig(cs, gdb_target_sigtrap(), reason, NULL, 0);
795 void gdb_handle_set_catch_syscalls(GArray *params, void *user_ctx)
797 const char *param = gdb_get_cmd_param(params, 0)->data;
798 GDBSyscallsMask catch_syscalls_mask;
799 bool catch_all_syscalls;
800 unsigned int num;
801 const char *p;
803 /* "0" means not catching any syscalls. */
804 if (strcmp(param, "0") == 0) {
805 gdbserver_user_state.catch_all_syscalls = false;
806 memset(gdbserver_user_state.catch_syscalls_mask, 0,
807 sizeof(gdbserver_user_state.catch_syscalls_mask));
808 gdb_put_packet("OK");
809 return;
812 /* "1" means catching all syscalls. */
813 if (strcmp(param, "1") == 0) {
814 gdbserver_user_state.catch_all_syscalls = true;
815 gdb_put_packet("OK");
816 return;
820 * "1;..." means catching only the specified syscalls.
821 * The syscall list must not be empty.
823 if (param[0] == '1' && param[1] == ';') {
824 catch_all_syscalls = false;
825 memset(catch_syscalls_mask, 0, sizeof(catch_syscalls_mask));
826 for (p = &param[2];; p++) {
827 if (qemu_strtoui(p, &p, 16, &num) || (*p && *p != ';')) {
828 goto err;
830 if (num >= GDB_NR_SYSCALLS) {
832 * Fall back to reporting all syscalls. Reporting extra
833 * syscalls is inefficient, but the spec explicitly allows it.
834 * Keep parsing in case there is a syntax error ahead.
836 catch_all_syscalls = true;
837 } else {
838 set_bit(num, catch_syscalls_mask);
840 if (!*p) {
841 break;
844 gdbserver_user_state.catch_all_syscalls = catch_all_syscalls;
845 if (!catch_all_syscalls) {
846 memcpy(gdbserver_user_state.catch_syscalls_mask,
847 catch_syscalls_mask, sizeof(catch_syscalls_mask));
849 gdb_put_packet("OK");
850 return;
853 err:
854 gdb_put_packet("E00");
857 void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx)
859 unsigned long offset, len;
860 uint8_t *siginfo_offset;
862 offset = gdb_get_cmd_param(params, 0)->val_ul;
863 len = gdb_get_cmd_param(params, 1)->val_ul;
865 if (offset + len > gdbserver_user_state.siginfo_len) {
866 /* Invalid offset and/or requested length. */
867 gdb_put_packet("E01");
868 return;
871 siginfo_offset = (uint8_t *)gdbserver_user_state.siginfo + offset;
873 /* Reply */
874 g_string_assign(gdbserver_state.str_buf, "l");
875 gdb_memtox(gdbserver_state.str_buf, (const char *)siginfo_offset, len);
876 gdb_put_packet_binary(gdbserver_state.str_buf->str,
877 gdbserver_state.str_buf->len, true);