[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 24/24] gdbstub: split out softmmu/user specifics for syscall h
From: |
Alex Bennée |
Subject: |
[PATCH v3 24/24] gdbstub: split out softmmu/user specifics for syscall handling |
Date: |
Tue, 21 Feb 2023 22:52:27 +0000 |
Most of the syscall code is config agnostic aside from the size of
target_ulong. In preparation for the next patch move the final bits of
specialisation into the appropriate user and softmmu helpers.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
gdbstub/internals.h | 5 +++++
gdbstub/softmmu.c | 24 ++++++++++++++++++++++++
gdbstub/syscalls.c | 32 +++++++++++---------------------
gdbstub/user.c | 24 ++++++++++++++++++++++++
4 files changed, 64 insertions(+), 21 deletions(-)
diff --git a/gdbstub/internals.h b/gdbstub/internals.h
index fe82facaeb..dce7c4f66f 100644
--- a/gdbstub/internals.h
+++ b/gdbstub/internals.h
@@ -193,6 +193,11 @@ bool gdb_handled_syscall(void);
void gdb_disable_syscalls(void);
void gdb_syscall_reset(void);
+/* user/softmmu specific signal handling */
+void gdb_pre_syscall_handling(void);
+bool gdb_send_syscall_now(void);
+void gdb_post_syscall_handling(void);
+
/*
* Break/Watch point support - there is an implementation for softmmu
* and user mode.
diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c
index b7e3829ca0..8f3c8ef449 100644
--- a/gdbstub/softmmu.c
+++ b/gdbstub/softmmu.c
@@ -101,6 +101,30 @@ static void gdb_chr_event(void *opaque, QEMUChrEvent event)
}
}
+/*
+ * In softmmu mode we stop the VM and wait to send the syscall packet
+ * until notification that the CPU has stopped. This must be done
+ * because if the packet is sent now the reply from the syscall
+ * request could be received while the CPU is still in the running
+ * state, which can cause packets to be dropped and state transition
+ * 'T' packets to be sent while the syscall is still being processed.
+ */
+
+void gdb_pre_syscall_handling(void)
+{
+ vm_stop(RUN_STATE_DEBUG);
+}
+
+bool gdb_send_syscall_now(void)
+{
+ return false;
+}
+
+void gdb_post_syscall_handling(void)
+{
+ qemu_cpu_kick(gdbserver_state.c_cpu);
+}
+
static void gdb_vm_state_change(void *opaque, bool running, RunState state)
{
CPUState *cpu = gdbserver_state.c_cpu;
diff --git a/gdbstub/syscalls.c b/gdbstub/syscalls.c
index 1b63a1d197..24eee38136 100644
--- a/gdbstub/syscalls.c
+++ b/gdbstub/syscalls.c
@@ -102,9 +102,10 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const
char *fmt, va_list va)
}
gdbserver_syscall_state.current_syscall_cb = cb;
-#ifndef CONFIG_USER_ONLY
- vm_stop(RUN_STATE_DEBUG);
-#endif
+
+ /* user/softmmu specific handling */
+ gdb_pre_syscall_handling();
+
p = &gdbserver_syscall_state.syscall_buf[0];
p_end =
&gdbserver_syscall_state.syscall_buf[sizeof(gdbserver_syscall_state.syscall_buf)];
*(p++) = 'F';
@@ -138,24 +139,13 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const
char *fmt, va_list va)
}
}
*p = 0;
-#ifdef CONFIG_USER_ONLY
- gdb_put_packet(gdbserver_syscall_state.syscall_buf);
- /* Return control to gdb for it to process the syscall request.
- * Since the protocol requires that gdb hands control back to us
- * using a "here are the results" F packet, we don't need to check
- * gdb_handlesig's return value (which is the signal to deliver if
- * execution was resumed via a continue packet).
- */
- gdb_handlesig(gdbserver_state.c_cpu, 0);
-#else
- /* In this case wait to send the syscall packet until notification that
- the CPU has stopped. This must be done because if the packet is sent
- now the reply from the syscall request could be received while the CPU
- is still in the running state, which can cause packets to be dropped
- and state transition 'T' packets to be sent while the syscall is still
- being processed. */
- qemu_cpu_kick(gdbserver_state.c_cpu);
-#endif
+
+ if (gdb_send_syscall_now()) { /* true only for *-user */
+ gdb_put_packet(gdbserver_syscall_state.syscall_buf);
+ }
+
+ /* user/softmmu specific handling */
+ gdb_post_syscall_handling();
}
void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...)
diff --git a/gdbstub/user.c b/gdbstub/user.c
index cc7eeb9afb..a5227e23cf 100644
--- a/gdbstub/user.c
+++ b/gdbstub/user.c
@@ -467,3 +467,27 @@ void gdb_breakpoint_remove_all(CPUState *cs)
{
cpu_breakpoint_remove_all(cs, BP_GDB);
}
+
+/*
+ * For user-mode syscall support we send the system call immediately
+ * and then return control to gdb for it to process the syscall request.
+ * Since the protocol requires that gdb hands control back to us
+ * using a "here are the results" F packet, we don't need to check
+ * gdb_handlesig's return value (which is the signal to deliver if
+ * execution was resumed via a continue packet).
+ */
+
+void gdb_pre_syscall_handling(void)
+{
+ return;
+}
+
+bool gdb_send_syscall_now(void)
+{
+ return true;
+}
+
+void gdb_post_syscall_handling(void)
+{
+ gdb_handlesig(gdbserver_state.c_cpu, 0);
+}
--
2.39.1
- [PATCH v3 04/24] gdbstub: define separate user/system structures, (continued)
- [PATCH v3 04/24] gdbstub: define separate user/system structures, Alex Bennée, 2023/02/21
- [PATCH v3 06/24] includes: move tb_flush into its own header, Alex Bennée, 2023/02/21
- [PATCH v3 11/24] gdbstub: rationalise signal mapping in softmmu, Alex Bennée, 2023/02/21
- [PATCH v3 07/24] gdbstub: move fromhex/tohex routines to internals, Alex Bennée, 2023/02/21
- [PATCH v3 08/24] gdbstub: make various helpers visible to the rest of the module, Alex Bennée, 2023/02/21
- [PATCH v3 09/24] gdbstub: move chunk of softmmu functionality to own file, Alex Bennée, 2023/02/21
- [PATCH v3 13/24] gdbstub: specialise handle_query_attached, Alex Bennée, 2023/02/21
- [PATCH v3 10/24] gdbstub: move chunks of user code into own files, Alex Bennée, 2023/02/21
- [PATCH v3 23/24] include: split target_long definition from cpu-defs, Alex Bennée, 2023/02/21
- [PATCH v3 15/24] gdbstub: introduce gdb_get_max_cpus, Alex Bennée, 2023/02/21
- [PATCH v3 24/24] gdbstub: split out softmmu/user specifics for syscall handling,
Alex Bennée <=
- [PATCH v3 20/24] gdbstub: move syscall handling to new file, Alex Bennée, 2023/02/21
- [PATCH v3 22/24] testing: probe gdb for supported architectures ahead of time, Alex Bennée, 2023/02/21
- [PATCH v3 17/24] gdbstub: fix address type of gdb_set_cpu_pc, Alex Bennée, 2023/02/21
- [PATCH v3 14/24] gdbstub: specialise target_memory_rw_debug, Alex Bennée, 2023/02/21
- [PATCH v3 16/24] gdbstub: specialise stub_can_reverse, Alex Bennée, 2023/02/21
- [PATCH v3 12/24] gdbstub: abstract target specific details from gdb_put_packet_binary, Alex Bennée, 2023/02/21
- [PATCH v3 21/24] gdbstub: only compile gdbstub twice for whole build, Alex Bennée, 2023/02/21
- [PATCH v3 18/24] gdbstub: don't use target_ulong while handling registers, Alex Bennée, 2023/02/21
- [PATCH v3 19/24] gdbstub: move register helpers into standalone include, Alex Bennée, 2023/02/21