pcie_sriov: Do not manually unrealize
[qemu/armbru.git] / gdbstub / user.c
blobe34b58b40732b66fec701637318701b29ae94f1f
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/syscalls.h"
20 #include "gdbstub/user.h"
21 #include "gdbstub/enums.h"
22 #include "hw/core/cpu.h"
23 #include "trace.h"
24 #include "internals.h"
26 #define GDB_NR_SYSCALLS 1024
27 typedef unsigned long GDBSyscallsMask[BITS_TO_LONGS(GDB_NR_SYSCALLS)];
30 * Forked child talks to its parent in order to let GDB enforce the
31 * follow-fork-mode. This happens inside a start_exclusive() section, so that
32 * the other threads, which may be forking too, do not interfere. The
33 * implementation relies on GDB not sending $vCont until it has detached
34 * either from the parent (follow-fork-mode child) or from the child
35 * (follow-fork-mode parent).
37 * The parent and the child share the GDB socket; at any given time only one
38 * of them is allowed to use it, as is reflected in the respective fork_state.
39 * This is negotiated via the fork_sockets pair as a reaction to $Hg.
41 * Below is a short summary of the possible state transitions:
43 * ENABLED : Terminal state.
44 * DISABLED : Terminal state.
45 * ACTIVE : Parent initial state.
46 * INACTIVE : Child initial state.
47 * ACTIVE -> DEACTIVATING: On $Hg.
48 * ACTIVE -> ENABLING : On $D.
49 * ACTIVE -> DISABLING : On $D.
50 * ACTIVE -> DISABLED : On communication error.
51 * DEACTIVATING -> INACTIVE : On gdb_read_byte() return.
52 * DEACTIVATING -> DISABLED : On communication error.
53 * INACTIVE -> ACTIVE : On $Hg in the peer.
54 * INACTIVE -> ENABLE : On $D in the peer.
55 * INACTIVE -> DISABLE : On $D in the peer.
56 * INACTIVE -> DISABLED : On communication error.
57 * ENABLING -> ENABLED : On gdb_read_byte() return.
58 * ENABLING -> DISABLED : On communication error.
59 * DISABLING -> DISABLED : On gdb_read_byte() return.
61 enum GDBForkState {
62 /* Fully owning the GDB socket. */
63 GDB_FORK_ENABLED,
64 /* Working with the GDB socket; the peer is inactive. */
65 GDB_FORK_ACTIVE,
66 /* Handing off the GDB socket to the peer. */
67 GDB_FORK_DEACTIVATING,
68 /* The peer is working with the GDB socket. */
69 GDB_FORK_INACTIVE,
70 /* Asking the peer to close its GDB socket fd. */
71 GDB_FORK_ENABLING,
72 /* Asking the peer to take over, closing our GDB socket fd. */
73 GDB_FORK_DISABLING,
74 /* The peer has taken over, our GDB socket fd is closed. */
75 GDB_FORK_DISABLED,
78 enum GDBForkMessage {
79 GDB_FORK_ACTIVATE = 'a',
80 GDB_FORK_ENABLE = 'e',
81 GDB_FORK_DISABLE = 'd',
84 /* User-mode specific state */
85 typedef struct {
86 int fd;
87 char *socket_path;
88 int running_state;
90 * Store syscalls mask without memory allocation in order to avoid
91 * implementing synchronization.
93 bool catch_all_syscalls;
94 GDBSyscallsMask catch_syscalls_mask;
95 bool fork_events;
96 enum GDBForkState fork_state;
97 int fork_sockets[2];
98 pid_t fork_peer_pid, fork_peer_tid;
99 uint8_t siginfo[MAX_SIGINFO_LENGTH];
100 unsigned long siginfo_len;
101 } GDBUserState;
103 static GDBUserState gdbserver_user_state;
105 int gdb_get_char(void)
107 uint8_t ch;
108 int ret;
110 for (;;) {
111 ret = recv(gdbserver_user_state.fd, &ch, 1, 0);
112 if (ret < 0) {
113 if (errno == ECONNRESET) {
114 gdbserver_user_state.fd = -1;
116 if (errno != EINTR) {
117 return -1;
119 } else if (ret == 0) {
120 close(gdbserver_user_state.fd);
121 gdbserver_user_state.fd = -1;
122 return -1;
123 } else {
124 break;
127 return ch;
130 bool gdb_got_immediate_ack(void)
132 int i;
134 i = gdb_get_char();
135 if (i < 0) {
136 /* no response, continue anyway */
137 return true;
140 if (i == '+') {
141 /* received correctly, continue */
142 return true;
145 /* anything else, including '-' then try again */
146 return false;
149 void gdb_put_buffer(const uint8_t *buf, int len)
151 int ret;
153 while (len > 0) {
154 ret = send(gdbserver_user_state.fd, buf, len, 0);
155 if (ret < 0) {
156 if (errno != EINTR) {
157 return;
159 } else {
160 buf += ret;
161 len -= ret;
166 /* Tell the remote gdb that the process has exited. */
167 void gdb_exit(int code)
169 char buf[4];
171 if (!gdbserver_state.init) {
172 return;
174 if (gdbserver_user_state.socket_path) {
175 unlink(gdbserver_user_state.socket_path);
177 if (gdbserver_user_state.fd < 0) {
178 return;
181 trace_gdbstub_op_exiting((uint8_t)code);
183 if (gdbserver_state.allow_stop_reply) {
184 snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code);
185 gdb_put_packet(buf);
186 gdbserver_state.allow_stop_reply = false;
191 void gdb_qemu_exit(int code)
193 exit(code);
196 int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo,
197 int siginfo_len)
199 char buf[256];
200 int n;
202 if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
203 return sig;
206 if (siginfo) {
208 * Save target-specific siginfo.
210 * siginfo size, i.e. siginfo_len, is asserted at compile-time to fit in
211 * gdbserver_user_state.siginfo, usually in the source file calling
212 * gdb_handlesig. See, for instance, {linux,bsd}-user/signal.c.
214 memcpy(gdbserver_user_state.siginfo, siginfo, siginfo_len);
215 gdbserver_user_state.siginfo_len = siginfo_len;
218 /* disable single step if it was enabled */
219 cpu_single_step(cpu, 0);
220 tb_flush(cpu);
222 if (sig != 0) {
223 gdb_set_stop_cpu(cpu);
224 if (gdbserver_state.allow_stop_reply) {
225 g_string_printf(gdbserver_state.str_buf,
226 "T%02xthread:", gdb_target_signal_to_gdb(sig));
227 gdb_append_thread_id(cpu, gdbserver_state.str_buf);
228 g_string_append_c(gdbserver_state.str_buf, ';');
229 if (reason) {
230 g_string_append(gdbserver_state.str_buf, reason);
232 gdb_put_strbuf();
233 gdbserver_state.allow_stop_reply = false;
237 * gdb_put_packet() might have detected that the peer terminated the
238 * connection.
240 if (gdbserver_user_state.fd < 0) {
241 return sig;
244 sig = 0;
245 gdbserver_state.state = RS_IDLE;
246 gdbserver_user_state.running_state = 0;
247 while (gdbserver_user_state.running_state == 0) {
248 n = read(gdbserver_user_state.fd, buf, 256);
249 if (n > 0) {
250 int i;
252 for (i = 0; i < n; i++) {
253 gdb_read_byte(buf[i]);
255 } else {
257 * XXX: Connection closed. Should probably wait for another
258 * connection before continuing.
260 if (n == 0) {
261 close(gdbserver_user_state.fd);
263 gdbserver_user_state.fd = -1;
264 return sig;
267 sig = gdbserver_state.signal;
268 gdbserver_state.signal = 0;
269 return sig;
272 /* Tell the remote gdb that the process has exited due to SIG. */
273 void gdb_signalled(CPUArchState *env, int sig)
275 char buf[4];
277 if (!gdbserver_state.init || gdbserver_user_state.fd < 0 ||
278 !gdbserver_state.allow_stop_reply) {
279 return;
282 snprintf(buf, sizeof(buf), "X%02x", gdb_target_signal_to_gdb(sig));
283 gdb_put_packet(buf);
284 gdbserver_state.allow_stop_reply = false;
287 static void gdb_accept_init(int fd)
289 gdb_init_gdbserver_state();
290 gdb_create_default_process(&gdbserver_state);
291 gdbserver_state.processes[0].attached = true;
292 gdbserver_state.c_cpu = gdb_first_attached_cpu();
293 gdbserver_state.g_cpu = gdbserver_state.c_cpu;
294 gdbserver_user_state.fd = fd;
297 static bool gdb_accept_socket(int gdb_fd)
299 int fd;
301 for (;;) {
302 fd = accept(gdb_fd, NULL, NULL);
303 if (fd < 0 && errno != EINTR) {
304 perror("accept socket");
305 return false;
306 } else if (fd >= 0) {
307 qemu_set_cloexec(fd);
308 break;
312 gdb_accept_init(fd);
313 return true;
316 static int gdbserver_open_socket(const char *path)
318 struct sockaddr_un sockaddr = {};
319 int fd, ret;
321 fd = socket(AF_UNIX, SOCK_STREAM, 0);
322 if (fd < 0) {
323 perror("create socket");
324 return -1;
327 sockaddr.sun_family = AF_UNIX;
328 pstrcpy(sockaddr.sun_path, sizeof(sockaddr.sun_path) - 1, path);
329 ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
330 if (ret < 0) {
331 perror("bind socket");
332 close(fd);
333 return -1;
335 ret = listen(fd, 1);
336 if (ret < 0) {
337 perror("listen socket");
338 close(fd);
339 return -1;
342 return fd;
345 static bool gdb_accept_tcp(int gdb_fd)
347 struct sockaddr_in sockaddr = {};
348 socklen_t len;
349 int fd;
351 for (;;) {
352 len = sizeof(sockaddr);
353 fd = accept(gdb_fd, (struct sockaddr *)&sockaddr, &len);
354 if (fd < 0 && errno != EINTR) {
355 perror("accept");
356 return false;
357 } else if (fd >= 0) {
358 qemu_set_cloexec(fd);
359 break;
363 /* set short latency */
364 if (socket_set_nodelay(fd)) {
365 perror("setsockopt");
366 close(fd);
367 return false;
370 gdb_accept_init(fd);
371 return true;
374 static int gdbserver_open_port(int port)
376 struct sockaddr_in sockaddr;
377 int fd, ret;
379 fd = socket(PF_INET, SOCK_STREAM, 0);
380 if (fd < 0) {
381 perror("socket");
382 return -1;
384 qemu_set_cloexec(fd);
386 socket_set_fast_reuse(fd);
388 sockaddr.sin_family = AF_INET;
389 sockaddr.sin_port = htons(port);
390 sockaddr.sin_addr.s_addr = 0;
391 ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
392 if (ret < 0) {
393 perror("bind");
394 close(fd);
395 return -1;
397 ret = listen(fd, 1);
398 if (ret < 0) {
399 perror("listen");
400 close(fd);
401 return -1;
404 return fd;
407 int gdbserver_start(const char *port_or_path)
409 int port = g_ascii_strtoull(port_or_path, NULL, 10);
410 int gdb_fd;
412 if (port > 0) {
413 gdb_fd = gdbserver_open_port(port);
414 } else {
415 gdb_fd = gdbserver_open_socket(port_or_path);
418 if (gdb_fd < 0) {
419 return -1;
422 if (port > 0 && gdb_accept_tcp(gdb_fd)) {
423 return 0;
424 } else if (gdb_accept_socket(gdb_fd)) {
425 gdbserver_user_state.socket_path = g_strdup(port_or_path);
426 return 0;
429 /* gone wrong */
430 close(gdb_fd);
431 return -1;
434 void gdbserver_fork_start(void)
436 if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
437 return;
439 if (!gdbserver_user_state.fork_events ||
440 qemu_socketpair(AF_UNIX, SOCK_STREAM, 0,
441 gdbserver_user_state.fork_sockets) < 0) {
442 gdbserver_user_state.fork_state = GDB_FORK_DISABLED;
443 return;
445 gdbserver_user_state.fork_state = GDB_FORK_INACTIVE;
446 gdbserver_user_state.fork_peer_pid = getpid();
447 gdbserver_user_state.fork_peer_tid = qemu_get_thread_id();
450 static void disable_gdbstub(CPUState *thread_cpu)
452 CPUState *cpu;
454 close(gdbserver_user_state.fd);
455 gdbserver_user_state.fd = -1;
456 CPU_FOREACH(cpu) {
457 cpu_breakpoint_remove_all(cpu, BP_GDB);
458 /* no cpu_watchpoint_remove_all for user-mode */
459 cpu_single_step(cpu, 0);
461 tb_flush(thread_cpu);
464 void gdbserver_fork_end(CPUState *cpu, pid_t pid)
466 char b;
467 int fd;
469 if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
470 return;
473 if (pid == -1) {
474 if (gdbserver_user_state.fork_state != GDB_FORK_DISABLED) {
475 g_assert(gdbserver_user_state.fork_state == GDB_FORK_INACTIVE);
476 close(gdbserver_user_state.fork_sockets[0]);
477 close(gdbserver_user_state.fork_sockets[1]);
479 return;
482 if (gdbserver_user_state.fork_state == GDB_FORK_DISABLED) {
483 if (pid == 0) {
484 disable_gdbstub(cpu);
486 return;
489 if (pid == 0) {
490 close(gdbserver_user_state.fork_sockets[0]);
491 fd = gdbserver_user_state.fork_sockets[1];
492 g_assert(gdbserver_state.process_num == 1);
493 g_assert(gdbserver_state.processes[0].pid ==
494 gdbserver_user_state.fork_peer_pid);
495 g_assert(gdbserver_state.processes[0].attached);
496 gdbserver_state.processes[0].pid = getpid();
497 } else {
498 close(gdbserver_user_state.fork_sockets[1]);
499 fd = gdbserver_user_state.fork_sockets[0];
500 gdbserver_user_state.fork_state = GDB_FORK_ACTIVE;
501 gdbserver_user_state.fork_peer_pid = pid;
502 gdbserver_user_state.fork_peer_tid = pid;
504 if (!gdbserver_state.allow_stop_reply) {
505 goto fail;
507 g_string_printf(gdbserver_state.str_buf,
508 "T%02xfork:p%02x.%02x;thread:p%02x.%02x;",
509 gdb_target_signal_to_gdb(gdb_target_sigtrap()),
510 pid, pid, (int)getpid(), qemu_get_thread_id());
511 gdb_put_strbuf();
514 gdbserver_state.state = RS_IDLE;
515 gdbserver_state.allow_stop_reply = false;
516 gdbserver_user_state.running_state = 0;
517 for (;;) {
518 switch (gdbserver_user_state.fork_state) {
519 case GDB_FORK_ENABLED:
520 if (gdbserver_user_state.running_state) {
521 close(fd);
522 return;
524 QEMU_FALLTHROUGH;
525 case GDB_FORK_ACTIVE:
526 if (read(gdbserver_user_state.fd, &b, 1) != 1) {
527 goto fail;
529 gdb_read_byte(b);
530 break;
531 case GDB_FORK_DEACTIVATING:
532 b = GDB_FORK_ACTIVATE;
533 if (write(fd, &b, 1) != 1) {
534 goto fail;
536 gdbserver_user_state.fork_state = GDB_FORK_INACTIVE;
537 break;
538 case GDB_FORK_INACTIVE:
539 if (read(fd, &b, 1) != 1) {
540 goto fail;
542 switch (b) {
543 case GDB_FORK_ACTIVATE:
544 gdbserver_user_state.fork_state = GDB_FORK_ACTIVE;
545 break;
546 case GDB_FORK_ENABLE:
547 gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
548 break;
549 case GDB_FORK_DISABLE:
550 gdbserver_user_state.fork_state = GDB_FORK_DISABLED;
551 break;
552 default:
553 g_assert_not_reached();
555 break;
556 case GDB_FORK_ENABLING:
557 b = GDB_FORK_DISABLE;
558 if (write(fd, &b, 1) != 1) {
559 goto fail;
561 gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
562 break;
563 case GDB_FORK_DISABLING:
564 b = GDB_FORK_ENABLE;
565 if (write(fd, &b, 1) != 1) {
566 goto fail;
568 gdbserver_user_state.fork_state = GDB_FORK_DISABLED;
569 break;
570 case GDB_FORK_DISABLED:
571 close(fd);
572 disable_gdbstub(cpu);
573 return;
574 default:
575 g_assert_not_reached();
579 fail:
580 close(fd);
581 if (pid == 0) {
582 disable_gdbstub(cpu);
586 void gdb_handle_query_supported_user(const char *gdb_supported)
588 if (strstr(gdb_supported, "fork-events+")) {
589 gdbserver_user_state.fork_events = true;
591 g_string_append(gdbserver_state.str_buf, ";fork-events+");
594 bool gdb_handle_set_thread_user(uint32_t pid, uint32_t tid)
596 if (gdbserver_user_state.fork_state == GDB_FORK_ACTIVE &&
597 pid == gdbserver_user_state.fork_peer_pid &&
598 tid == gdbserver_user_state.fork_peer_tid) {
599 gdbserver_user_state.fork_state = GDB_FORK_DEACTIVATING;
600 gdb_put_packet("OK");
601 return true;
603 return false;
606 bool gdb_handle_detach_user(uint32_t pid)
608 bool enable;
610 if (gdbserver_user_state.fork_state == GDB_FORK_ACTIVE) {
611 enable = pid == gdbserver_user_state.fork_peer_pid;
612 if (enable || pid == getpid()) {
613 gdbserver_user_state.fork_state = enable ? GDB_FORK_ENABLING :
614 GDB_FORK_DISABLING;
615 gdb_put_packet("OK");
616 return true;
619 return false;
623 * Execution state helpers
626 void gdb_handle_query_attached(GArray *params, void *user_ctx)
628 gdb_put_packet("0");
631 void gdb_continue(void)
633 gdbserver_user_state.running_state = 1;
634 trace_gdbstub_op_continue();
638 * Resume execution, for user-mode emulation it's equivalent to
639 * gdb_continue.
641 int gdb_continue_partial(char *newstates)
643 CPUState *cpu;
644 int res = 0;
646 * This is not exactly accurate, but it's an improvement compared to the
647 * previous situation, where only one CPU would be single-stepped.
649 CPU_FOREACH(cpu) {
650 if (newstates[cpu->cpu_index] == 's') {
651 trace_gdbstub_op_stepping(cpu->cpu_index);
652 cpu_single_step(cpu, gdbserver_state.sstep_flags);
655 gdbserver_user_state.running_state = 1;
656 return res;
660 * Memory access helpers
662 int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr,
663 uint8_t *buf, int len, bool is_write)
665 CPUClass *cc;
667 cc = CPU_GET_CLASS(cpu);
668 if (cc->memory_rw_debug) {
669 return cc->memory_rw_debug(cpu, addr, buf, len, is_write);
671 return cpu_memory_rw_debug(cpu, addr, buf, len, is_write);
675 * cpu helpers
678 unsigned int gdb_get_max_cpus(void)
680 CPUState *cpu;
681 unsigned int max_cpus = 1;
683 CPU_FOREACH(cpu) {
684 max_cpus = max_cpus <= cpu->cpu_index ? cpu->cpu_index + 1 : max_cpus;
687 return max_cpus;
690 /* replay not supported for user-mode */
691 bool gdb_can_reverse(void)
693 return false;
697 * Break/Watch point helpers
700 bool gdb_supports_guest_debug(void)
702 /* user-mode == TCG == supported */
703 return true;
706 int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len)
708 CPUState *cpu;
709 int err = 0;
711 switch (type) {
712 case GDB_BREAKPOINT_SW:
713 case GDB_BREAKPOINT_HW:
714 CPU_FOREACH(cpu) {
715 err = cpu_breakpoint_insert(cpu, addr, BP_GDB, NULL);
716 if (err) {
717 break;
720 return err;
721 default:
722 /* user-mode doesn't support watchpoints */
723 return -ENOSYS;
727 int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len)
729 CPUState *cpu;
730 int err = 0;
732 switch (type) {
733 case GDB_BREAKPOINT_SW:
734 case GDB_BREAKPOINT_HW:
735 CPU_FOREACH(cpu) {
736 err = cpu_breakpoint_remove(cpu, addr, BP_GDB);
737 if (err) {
738 break;
741 return err;
742 default:
743 /* user-mode doesn't support watchpoints */
744 return -ENOSYS;
748 void gdb_breakpoint_remove_all(CPUState *cs)
750 cpu_breakpoint_remove_all(cs, BP_GDB);
754 * For user-mode syscall support we send the system call immediately
755 * and then return control to gdb for it to process the syscall request.
756 * Since the protocol requires that gdb hands control back to us
757 * using a "here are the results" F packet, we don't need to check
758 * gdb_handlesig's return value (which is the signal to deliver if
759 * execution was resumed via a continue packet).
761 void gdb_syscall_handling(const char *syscall_packet)
763 gdb_put_packet(syscall_packet);
764 gdb_handlesig(gdbserver_state.c_cpu, 0, NULL, NULL, 0);
767 static bool should_catch_syscall(int num)
769 if (gdbserver_user_state.catch_all_syscalls) {
770 return true;
772 if (num < 0 || num >= GDB_NR_SYSCALLS) {
773 return false;
775 return test_bit(num, gdbserver_user_state.catch_syscalls_mask);
778 void gdb_syscall_entry(CPUState *cs, int num)
780 if (should_catch_syscall(num)) {
781 g_autofree char *reason = g_strdup_printf("syscall_entry:%x;", num);
782 gdb_handlesig(cs, gdb_target_sigtrap(), reason, NULL, 0);
786 void gdb_syscall_return(CPUState *cs, int num)
788 if (should_catch_syscall(num)) {
789 g_autofree char *reason = g_strdup_printf("syscall_return:%x;", num);
790 gdb_handlesig(cs, gdb_target_sigtrap(), reason, NULL, 0);
794 void gdb_handle_set_catch_syscalls(GArray *params, void *user_ctx)
796 const char *param = get_param(params, 0)->data;
797 GDBSyscallsMask catch_syscalls_mask;
798 bool catch_all_syscalls;
799 unsigned int num;
800 const char *p;
802 /* "0" means not catching any syscalls. */
803 if (strcmp(param, "0") == 0) {
804 gdbserver_user_state.catch_all_syscalls = false;
805 memset(gdbserver_user_state.catch_syscalls_mask, 0,
806 sizeof(gdbserver_user_state.catch_syscalls_mask));
807 gdb_put_packet("OK");
808 return;
811 /* "1" means catching all syscalls. */
812 if (strcmp(param, "1") == 0) {
813 gdbserver_user_state.catch_all_syscalls = true;
814 gdb_put_packet("OK");
815 return;
819 * "1;..." means catching only the specified syscalls.
820 * The syscall list must not be empty.
822 if (param[0] == '1' && param[1] == ';') {
823 catch_all_syscalls = false;
824 memset(catch_syscalls_mask, 0, sizeof(catch_syscalls_mask));
825 for (p = &param[2];; p++) {
826 if (qemu_strtoui(p, &p, 16, &num) || (*p && *p != ';')) {
827 goto err;
829 if (num >= GDB_NR_SYSCALLS) {
831 * Fall back to reporting all syscalls. Reporting extra
832 * syscalls is inefficient, but the spec explicitly allows it.
833 * Keep parsing in case there is a syntax error ahead.
835 catch_all_syscalls = true;
836 } else {
837 set_bit(num, catch_syscalls_mask);
839 if (!*p) {
840 break;
843 gdbserver_user_state.catch_all_syscalls = catch_all_syscalls;
844 if (!catch_all_syscalls) {
845 memcpy(gdbserver_user_state.catch_syscalls_mask,
846 catch_syscalls_mask, sizeof(catch_syscalls_mask));
848 gdb_put_packet("OK");
849 return;
852 err:
853 gdb_put_packet("E00");
856 void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx)
858 unsigned long offset, len;
859 uint8_t *siginfo_offset;
861 offset = get_param(params, 0)->val_ul;
862 len = get_param(params, 1)->val_ul;
864 if (offset + len > gdbserver_user_state.siginfo_len) {
865 /* Invalid offset and/or requested length. */
866 gdb_put_packet("E01");
867 return;
870 siginfo_offset = (uint8_t *)gdbserver_user_state.siginfo + offset;
872 /* Reply */
873 g_string_assign(gdbserver_state.str_buf, "l");
874 gdb_memtox(gdbserver_state.str_buf, (const char *)siginfo_offset, len);
875 gdb_put_packet_binary(gdbserver_state.str_buf->str,
876 gdbserver_state.str_buf->len, true);