Merge tag 'pull-tcg-20240619' of https://gitlab.com/rth7680/qemu into staging
[qemu/armbru.git] / gdbstub / user.c
blobedeb72efebcb7f1dba13e61950bda78a14702210
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 "hw/core/cpu.h"
22 #include "trace.h"
23 #include "internals.h"
25 #define GDB_NR_SYSCALLS 1024
26 typedef unsigned long GDBSyscallsMask[BITS_TO_LONGS(GDB_NR_SYSCALLS)];
29 * Forked child talks to its parent in order to let GDB enforce the
30 * follow-fork-mode. This happens inside a start_exclusive() section, so that
31 * the other threads, which may be forking too, do not interfere. The
32 * implementation relies on GDB not sending $vCont until it has detached
33 * either from the parent (follow-fork-mode child) or from the child
34 * (follow-fork-mode parent).
36 * The parent and the child share the GDB socket; at any given time only one
37 * of them is allowed to use it, as is reflected in the respective fork_state.
38 * This is negotiated via the fork_sockets pair as a reaction to $Hg.
40 * Below is a short summary of the possible state transitions:
42 * ENABLED : Terminal state.
43 * DISABLED : Terminal state.
44 * ACTIVE : Parent initial state.
45 * INACTIVE : Child initial state.
46 * ACTIVE -> DEACTIVATING: On $Hg.
47 * ACTIVE -> ENABLING : On $D.
48 * ACTIVE -> DISABLING : On $D.
49 * ACTIVE -> DISABLED : On communication error.
50 * DEACTIVATING -> INACTIVE : On gdb_read_byte() return.
51 * DEACTIVATING -> DISABLED : On communication error.
52 * INACTIVE -> ACTIVE : On $Hg in the peer.
53 * INACTIVE -> ENABLE : On $D in the peer.
54 * INACTIVE -> DISABLE : On $D in the peer.
55 * INACTIVE -> DISABLED : On communication error.
56 * ENABLING -> ENABLED : On gdb_read_byte() return.
57 * ENABLING -> DISABLED : On communication error.
58 * DISABLING -> DISABLED : On gdb_read_byte() return.
60 enum GDBForkState {
61 /* Fully owning the GDB socket. */
62 GDB_FORK_ENABLED,
63 /* Working with the GDB socket; the peer is inactive. */
64 GDB_FORK_ACTIVE,
65 /* Handing off the GDB socket to the peer. */
66 GDB_FORK_DEACTIVATING,
67 /* The peer is working with the GDB socket. */
68 GDB_FORK_INACTIVE,
69 /* Asking the peer to close its GDB socket fd. */
70 GDB_FORK_ENABLING,
71 /* Asking the peer to take over, closing our GDB socket fd. */
72 GDB_FORK_DISABLING,
73 /* The peer has taken over, our GDB socket fd is closed. */
74 GDB_FORK_DISABLED,
77 enum GDBForkMessage {
78 GDB_FORK_ACTIVATE = 'a',
79 GDB_FORK_ENABLE = 'e',
80 GDB_FORK_DISABLE = 'd',
83 /* User-mode specific state */
84 typedef struct {
85 int fd;
86 char *socket_path;
87 int running_state;
89 * Store syscalls mask without memory allocation in order to avoid
90 * implementing synchronization.
92 bool catch_all_syscalls;
93 GDBSyscallsMask catch_syscalls_mask;
94 bool fork_events;
95 enum GDBForkState fork_state;
96 int fork_sockets[2];
97 pid_t fork_peer_pid, fork_peer_tid;
98 uint8_t siginfo[MAX_SIGINFO_LENGTH];
99 unsigned long siginfo_len;
100 } GDBUserState;
102 static GDBUserState gdbserver_user_state;
104 int gdb_get_char(void)
106 uint8_t ch;
107 int ret;
109 for (;;) {
110 ret = recv(gdbserver_user_state.fd, &ch, 1, 0);
111 if (ret < 0) {
112 if (errno == ECONNRESET) {
113 gdbserver_user_state.fd = -1;
115 if (errno != EINTR) {
116 return -1;
118 } else if (ret == 0) {
119 close(gdbserver_user_state.fd);
120 gdbserver_user_state.fd = -1;
121 return -1;
122 } else {
123 break;
126 return ch;
129 bool gdb_got_immediate_ack(void)
131 int i;
133 i = gdb_get_char();
134 if (i < 0) {
135 /* no response, continue anyway */
136 return true;
139 if (i == '+') {
140 /* received correctly, continue */
141 return true;
144 /* anything else, including '-' then try again */
145 return false;
148 void gdb_put_buffer(const uint8_t *buf, int len)
150 int ret;
152 while (len > 0) {
153 ret = send(gdbserver_user_state.fd, buf, len, 0);
154 if (ret < 0) {
155 if (errno != EINTR) {
156 return;
158 } else {
159 buf += ret;
160 len -= ret;
165 /* Tell the remote gdb that the process has exited. */
166 void gdb_exit(int code)
168 char buf[4];
170 if (!gdbserver_state.init) {
171 return;
173 if (gdbserver_user_state.socket_path) {
174 unlink(gdbserver_user_state.socket_path);
176 if (gdbserver_user_state.fd < 0) {
177 return;
180 trace_gdbstub_op_exiting((uint8_t)code);
182 if (gdbserver_state.allow_stop_reply) {
183 snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code);
184 gdb_put_packet(buf);
185 gdbserver_state.allow_stop_reply = false;
190 void gdb_qemu_exit(int code)
192 exit(code);
195 int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo,
196 int siginfo_len)
198 char buf[256];
199 int n;
201 if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
202 return sig;
205 if (siginfo) {
207 * Save target-specific siginfo.
209 * siginfo size, i.e. siginfo_len, is asserted at compile-time to fit in
210 * gdbserver_user_state.siginfo, usually in the source file calling
211 * gdb_handlesig. See, for instance, {linux,bsd}-user/signal.c.
213 memcpy(gdbserver_user_state.siginfo, siginfo, siginfo_len);
214 gdbserver_user_state.siginfo_len = siginfo_len;
217 /* disable single step if it was enabled */
218 cpu_single_step(cpu, 0);
219 tb_flush(cpu);
221 if (sig != 0) {
222 gdb_set_stop_cpu(cpu);
223 if (gdbserver_state.allow_stop_reply) {
224 g_string_printf(gdbserver_state.str_buf,
225 "T%02xthread:", gdb_target_signal_to_gdb(sig));
226 gdb_append_thread_id(cpu, gdbserver_state.str_buf);
227 g_string_append_c(gdbserver_state.str_buf, ';');
228 if (reason) {
229 g_string_append(gdbserver_state.str_buf, reason);
231 gdb_put_strbuf();
232 gdbserver_state.allow_stop_reply = false;
236 * gdb_put_packet() might have detected that the peer terminated the
237 * connection.
239 if (gdbserver_user_state.fd < 0) {
240 return sig;
243 sig = 0;
244 gdbserver_state.state = RS_IDLE;
245 gdbserver_user_state.running_state = 0;
246 while (gdbserver_user_state.running_state == 0) {
247 n = read(gdbserver_user_state.fd, buf, 256);
248 if (n > 0) {
249 int i;
251 for (i = 0; i < n; i++) {
252 gdb_read_byte(buf[i]);
254 } else {
256 * XXX: Connection closed. Should probably wait for another
257 * connection before continuing.
259 if (n == 0) {
260 close(gdbserver_user_state.fd);
262 gdbserver_user_state.fd = -1;
263 return sig;
266 sig = gdbserver_state.signal;
267 gdbserver_state.signal = 0;
268 return sig;
271 /* Tell the remote gdb that the process has exited due to SIG. */
272 void gdb_signalled(CPUArchState *env, int sig)
274 char buf[4];
276 if (!gdbserver_state.init || gdbserver_user_state.fd < 0 ||
277 !gdbserver_state.allow_stop_reply) {
278 return;
281 snprintf(buf, sizeof(buf), "X%02x", gdb_target_signal_to_gdb(sig));
282 gdb_put_packet(buf);
283 gdbserver_state.allow_stop_reply = false;
286 static void gdb_accept_init(int fd)
288 gdb_init_gdbserver_state();
289 gdb_create_default_process(&gdbserver_state);
290 gdbserver_state.processes[0].attached = true;
291 gdbserver_state.c_cpu = gdb_first_attached_cpu();
292 gdbserver_state.g_cpu = gdbserver_state.c_cpu;
293 gdbserver_user_state.fd = fd;
296 static bool gdb_accept_socket(int gdb_fd)
298 int fd;
300 for (;;) {
301 fd = accept(gdb_fd, NULL, NULL);
302 if (fd < 0 && errno != EINTR) {
303 perror("accept socket");
304 return false;
305 } else if (fd >= 0) {
306 qemu_set_cloexec(fd);
307 break;
311 gdb_accept_init(fd);
312 return true;
315 static int gdbserver_open_socket(const char *path)
317 struct sockaddr_un sockaddr = {};
318 int fd, ret;
320 fd = socket(AF_UNIX, SOCK_STREAM, 0);
321 if (fd < 0) {
322 perror("create socket");
323 return -1;
326 sockaddr.sun_family = AF_UNIX;
327 pstrcpy(sockaddr.sun_path, sizeof(sockaddr.sun_path) - 1, path);
328 ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
329 if (ret < 0) {
330 perror("bind socket");
331 close(fd);
332 return -1;
334 ret = listen(fd, 1);
335 if (ret < 0) {
336 perror("listen socket");
337 close(fd);
338 return -1;
341 return fd;
344 static bool gdb_accept_tcp(int gdb_fd)
346 struct sockaddr_in sockaddr = {};
347 socklen_t len;
348 int fd;
350 for (;;) {
351 len = sizeof(sockaddr);
352 fd = accept(gdb_fd, (struct sockaddr *)&sockaddr, &len);
353 if (fd < 0 && errno != EINTR) {
354 perror("accept");
355 return false;
356 } else if (fd >= 0) {
357 qemu_set_cloexec(fd);
358 break;
362 /* set short latency */
363 if (socket_set_nodelay(fd)) {
364 perror("setsockopt");
365 close(fd);
366 return false;
369 gdb_accept_init(fd);
370 return true;
373 static int gdbserver_open_port(int port)
375 struct sockaddr_in sockaddr;
376 int fd, ret;
378 fd = socket(PF_INET, SOCK_STREAM, 0);
379 if (fd < 0) {
380 perror("socket");
381 return -1;
383 qemu_set_cloexec(fd);
385 socket_set_fast_reuse(fd);
387 sockaddr.sin_family = AF_INET;
388 sockaddr.sin_port = htons(port);
389 sockaddr.sin_addr.s_addr = 0;
390 ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
391 if (ret < 0) {
392 perror("bind");
393 close(fd);
394 return -1;
396 ret = listen(fd, 1);
397 if (ret < 0) {
398 perror("listen");
399 close(fd);
400 return -1;
403 return fd;
406 int gdbserver_start(const char *port_or_path)
408 int port = g_ascii_strtoull(port_or_path, NULL, 10);
409 int gdb_fd;
411 if (port > 0) {
412 gdb_fd = gdbserver_open_port(port);
413 } else {
414 gdb_fd = gdbserver_open_socket(port_or_path);
417 if (gdb_fd < 0) {
418 return -1;
421 if (port > 0 && gdb_accept_tcp(gdb_fd)) {
422 return 0;
423 } else if (gdb_accept_socket(gdb_fd)) {
424 gdbserver_user_state.socket_path = g_strdup(port_or_path);
425 return 0;
428 /* gone wrong */
429 close(gdb_fd);
430 return -1;
433 void gdbserver_fork_start(void)
435 if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
436 return;
438 if (!gdbserver_user_state.fork_events ||
439 qemu_socketpair(AF_UNIX, SOCK_STREAM, 0,
440 gdbserver_user_state.fork_sockets) < 0) {
441 gdbserver_user_state.fork_state = GDB_FORK_DISABLED;
442 return;
444 gdbserver_user_state.fork_state = GDB_FORK_INACTIVE;
445 gdbserver_user_state.fork_peer_pid = getpid();
446 gdbserver_user_state.fork_peer_tid = qemu_get_thread_id();
449 static void disable_gdbstub(CPUState *thread_cpu)
451 CPUState *cpu;
453 close(gdbserver_user_state.fd);
454 gdbserver_user_state.fd = -1;
455 CPU_FOREACH(cpu) {
456 cpu_breakpoint_remove_all(cpu, BP_GDB);
457 /* no cpu_watchpoint_remove_all for user-mode */
458 cpu_single_step(cpu, 0);
460 tb_flush(thread_cpu);
463 void gdbserver_fork_end(CPUState *cpu, pid_t pid)
465 char b;
466 int fd;
468 if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
469 return;
472 if (pid == -1) {
473 if (gdbserver_user_state.fork_state != GDB_FORK_DISABLED) {
474 g_assert(gdbserver_user_state.fork_state == GDB_FORK_INACTIVE);
475 close(gdbserver_user_state.fork_sockets[0]);
476 close(gdbserver_user_state.fork_sockets[1]);
478 return;
481 if (gdbserver_user_state.fork_state == GDB_FORK_DISABLED) {
482 if (pid == 0) {
483 disable_gdbstub(cpu);
485 return;
488 if (pid == 0) {
489 close(gdbserver_user_state.fork_sockets[0]);
490 fd = gdbserver_user_state.fork_sockets[1];
491 g_assert(gdbserver_state.process_num == 1);
492 g_assert(gdbserver_state.processes[0].pid ==
493 gdbserver_user_state.fork_peer_pid);
494 g_assert(gdbserver_state.processes[0].attached);
495 gdbserver_state.processes[0].pid = getpid();
496 } else {
497 close(gdbserver_user_state.fork_sockets[1]);
498 fd = gdbserver_user_state.fork_sockets[0];
499 gdbserver_user_state.fork_state = GDB_FORK_ACTIVE;
500 gdbserver_user_state.fork_peer_pid = pid;
501 gdbserver_user_state.fork_peer_tid = pid;
503 if (!gdbserver_state.allow_stop_reply) {
504 goto fail;
506 g_string_printf(gdbserver_state.str_buf,
507 "T%02xfork:p%02x.%02x;thread:p%02x.%02x;",
508 gdb_target_signal_to_gdb(gdb_target_sigtrap()),
509 pid, pid, (int)getpid(), qemu_get_thread_id());
510 gdb_put_strbuf();
513 gdbserver_state.state = RS_IDLE;
514 gdbserver_state.allow_stop_reply = false;
515 gdbserver_user_state.running_state = 0;
516 for (;;) {
517 switch (gdbserver_user_state.fork_state) {
518 case GDB_FORK_ENABLED:
519 if (gdbserver_user_state.running_state) {
520 close(fd);
521 return;
523 QEMU_FALLTHROUGH;
524 case GDB_FORK_ACTIVE:
525 if (read(gdbserver_user_state.fd, &b, 1) != 1) {
526 goto fail;
528 gdb_read_byte(b);
529 break;
530 case GDB_FORK_DEACTIVATING:
531 b = GDB_FORK_ACTIVATE;
532 if (write(fd, &b, 1) != 1) {
533 goto fail;
535 gdbserver_user_state.fork_state = GDB_FORK_INACTIVE;
536 break;
537 case GDB_FORK_INACTIVE:
538 if (read(fd, &b, 1) != 1) {
539 goto fail;
541 switch (b) {
542 case GDB_FORK_ACTIVATE:
543 gdbserver_user_state.fork_state = GDB_FORK_ACTIVE;
544 break;
545 case GDB_FORK_ENABLE:
546 gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
547 break;
548 case GDB_FORK_DISABLE:
549 gdbserver_user_state.fork_state = GDB_FORK_DISABLED;
550 break;
551 default:
552 g_assert_not_reached();
554 break;
555 case GDB_FORK_ENABLING:
556 b = GDB_FORK_DISABLE;
557 if (write(fd, &b, 1) != 1) {
558 goto fail;
560 gdbserver_user_state.fork_state = GDB_FORK_ENABLED;
561 break;
562 case GDB_FORK_DISABLING:
563 b = GDB_FORK_ENABLE;
564 if (write(fd, &b, 1) != 1) {
565 goto fail;
567 gdbserver_user_state.fork_state = GDB_FORK_DISABLED;
568 break;
569 case GDB_FORK_DISABLED:
570 close(fd);
571 disable_gdbstub(cpu);
572 return;
573 default:
574 g_assert_not_reached();
578 fail:
579 close(fd);
580 if (pid == 0) {
581 disable_gdbstub(cpu);
585 void gdb_handle_query_supported_user(const char *gdb_supported)
587 if (strstr(gdb_supported, "fork-events+")) {
588 gdbserver_user_state.fork_events = true;
590 g_string_append(gdbserver_state.str_buf, ";fork-events+");
593 bool gdb_handle_set_thread_user(uint32_t pid, uint32_t tid)
595 if (gdbserver_user_state.fork_state == GDB_FORK_ACTIVE &&
596 pid == gdbserver_user_state.fork_peer_pid &&
597 tid == gdbserver_user_state.fork_peer_tid) {
598 gdbserver_user_state.fork_state = GDB_FORK_DEACTIVATING;
599 gdb_put_packet("OK");
600 return true;
602 return false;
605 bool gdb_handle_detach_user(uint32_t pid)
607 bool enable;
609 if (gdbserver_user_state.fork_state == GDB_FORK_ACTIVE) {
610 enable = pid == gdbserver_user_state.fork_peer_pid;
611 if (enable || pid == getpid()) {
612 gdbserver_user_state.fork_state = enable ? GDB_FORK_ENABLING :
613 GDB_FORK_DISABLING;
614 gdb_put_packet("OK");
615 return true;
618 return false;
622 * Execution state helpers
625 void gdb_handle_query_attached(GArray *params, void *user_ctx)
627 gdb_put_packet("0");
630 void gdb_continue(void)
632 gdbserver_user_state.running_state = 1;
633 trace_gdbstub_op_continue();
637 * Resume execution, for user-mode emulation it's equivalent to
638 * gdb_continue.
640 int gdb_continue_partial(char *newstates)
642 CPUState *cpu;
643 int res = 0;
645 * This is not exactly accurate, but it's an improvement compared to the
646 * previous situation, where only one CPU would be single-stepped.
648 CPU_FOREACH(cpu) {
649 if (newstates[cpu->cpu_index] == 's') {
650 trace_gdbstub_op_stepping(cpu->cpu_index);
651 cpu_single_step(cpu, gdbserver_state.sstep_flags);
654 gdbserver_user_state.running_state = 1;
655 return res;
659 * Memory access helpers
661 int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr,
662 uint8_t *buf, int len, bool is_write)
664 CPUClass *cc;
666 cc = CPU_GET_CLASS(cpu);
667 if (cc->memory_rw_debug) {
668 return cc->memory_rw_debug(cpu, addr, buf, len, is_write);
670 return cpu_memory_rw_debug(cpu, addr, buf, len, is_write);
674 * cpu helpers
677 unsigned int gdb_get_max_cpus(void)
679 CPUState *cpu;
680 unsigned int max_cpus = 1;
682 CPU_FOREACH(cpu) {
683 max_cpus = max_cpus <= cpu->cpu_index ? cpu->cpu_index + 1 : max_cpus;
686 return max_cpus;
689 /* replay not supported for user-mode */
690 bool gdb_can_reverse(void)
692 return false;
696 * Break/Watch point helpers
699 bool gdb_supports_guest_debug(void)
701 /* user-mode == TCG == supported */
702 return true;
705 int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len)
707 CPUState *cpu;
708 int err = 0;
710 switch (type) {
711 case GDB_BREAKPOINT_SW:
712 case GDB_BREAKPOINT_HW:
713 CPU_FOREACH(cpu) {
714 err = cpu_breakpoint_insert(cpu, addr, BP_GDB, NULL);
715 if (err) {
716 break;
719 return err;
720 default:
721 /* user-mode doesn't support watchpoints */
722 return -ENOSYS;
726 int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len)
728 CPUState *cpu;
729 int err = 0;
731 switch (type) {
732 case GDB_BREAKPOINT_SW:
733 case GDB_BREAKPOINT_HW:
734 CPU_FOREACH(cpu) {
735 err = cpu_breakpoint_remove(cpu, addr, BP_GDB);
736 if (err) {
737 break;
740 return err;
741 default:
742 /* user-mode doesn't support watchpoints */
743 return -ENOSYS;
747 void gdb_breakpoint_remove_all(CPUState *cs)
749 cpu_breakpoint_remove_all(cs, BP_GDB);
753 * For user-mode syscall support we send the system call immediately
754 * and then return control to gdb for it to process the syscall request.
755 * Since the protocol requires that gdb hands control back to us
756 * using a "here are the results" F packet, we don't need to check
757 * gdb_handlesig's return value (which is the signal to deliver if
758 * execution was resumed via a continue packet).
760 void gdb_syscall_handling(const char *syscall_packet)
762 gdb_put_packet(syscall_packet);
763 gdb_handlesig(gdbserver_state.c_cpu, 0, NULL, NULL, 0);
766 static bool should_catch_syscall(int num)
768 if (gdbserver_user_state.catch_all_syscalls) {
769 return true;
771 if (num < 0 || num >= GDB_NR_SYSCALLS) {
772 return false;
774 return test_bit(num, gdbserver_user_state.catch_syscalls_mask);
777 void gdb_syscall_entry(CPUState *cs, int num)
779 if (should_catch_syscall(num)) {
780 g_autofree char *reason = g_strdup_printf("syscall_entry:%x;", num);
781 gdb_handlesig(cs, gdb_target_sigtrap(), reason, NULL, 0);
785 void gdb_syscall_return(CPUState *cs, int num)
787 if (should_catch_syscall(num)) {
788 g_autofree char *reason = g_strdup_printf("syscall_return:%x;", num);
789 gdb_handlesig(cs, gdb_target_sigtrap(), reason, NULL, 0);
793 void gdb_handle_set_catch_syscalls(GArray *params, void *user_ctx)
795 const char *param = get_param(params, 0)->data;
796 GDBSyscallsMask catch_syscalls_mask;
797 bool catch_all_syscalls;
798 unsigned int num;
799 const char *p;
801 /* "0" means not catching any syscalls. */
802 if (strcmp(param, "0") == 0) {
803 gdbserver_user_state.catch_all_syscalls = false;
804 memset(gdbserver_user_state.catch_syscalls_mask, 0,
805 sizeof(gdbserver_user_state.catch_syscalls_mask));
806 gdb_put_packet("OK");
807 return;
810 /* "1" means catching all syscalls. */
811 if (strcmp(param, "1") == 0) {
812 gdbserver_user_state.catch_all_syscalls = true;
813 gdb_put_packet("OK");
814 return;
818 * "1;..." means catching only the specified syscalls.
819 * The syscall list must not be empty.
821 if (param[0] == '1' && param[1] == ';') {
822 catch_all_syscalls = false;
823 memset(catch_syscalls_mask, 0, sizeof(catch_syscalls_mask));
824 for (p = &param[2];; p++) {
825 if (qemu_strtoui(p, &p, 16, &num) || (*p && *p != ';')) {
826 goto err;
828 if (num >= GDB_NR_SYSCALLS) {
830 * Fall back to reporting all syscalls. Reporting extra
831 * syscalls is inefficient, but the spec explicitly allows it.
832 * Keep parsing in case there is a syntax error ahead.
834 catch_all_syscalls = true;
835 } else {
836 set_bit(num, catch_syscalls_mask);
838 if (!*p) {
839 break;
842 gdbserver_user_state.catch_all_syscalls = catch_all_syscalls;
843 if (!catch_all_syscalls) {
844 memcpy(gdbserver_user_state.catch_syscalls_mask,
845 catch_syscalls_mask, sizeof(catch_syscalls_mask));
847 gdb_put_packet("OK");
848 return;
851 err:
852 gdb_put_packet("E00");
855 void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx)
857 unsigned long offset, len;
858 uint8_t *siginfo_offset;
860 offset = get_param(params, 0)->val_ul;
861 len = get_param(params, 1)->val_ul;
863 if (offset + len > gdbserver_user_state.siginfo_len) {
864 /* Invalid offset and/or requested length. */
865 gdb_put_packet("E01");
866 return;
869 siginfo_offset = (uint8_t *)gdbserver_user_state.siginfo + offset;
871 /* Reply */
872 g_string_assign(gdbserver_state.str_buf, "l");
873 gdb_memtox(gdbserver_state.str_buf, (const char *)siginfo_offset, len);
874 gdb_put_packet_binary(gdbserver_state.str_buf->str,
875 gdbserver_state.str_buf->len, true);