From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, "Alex Bennée" <alex.bennee@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 05/30] gdbstub: define separate user/system structures
Date: Tue, 7 Mar 2023 21:21:14 +0000 [thread overview]
Message-ID: <20230307212139.883112-6-alex.bennee@linaro.org> (raw)
In-Reply-To: <20230307212139.883112-1-alex.bennee@linaro.org>
In preparation for moving user/softmmu specific bits from the main
gdbstub file we need to separate the connection details into a
user/softmmu state. As these will eventually be defined in their own
files we move them out of the common GDBState structure.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230302190846.2593720-6-alex.bennee@linaro.org>
Message-Id: <20230303025805.625589-6-richard.henderson@linaro.org>
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 63b56f0027..1e6f8978b5 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -341,6 +341,22 @@ enum RSState {
RS_CHKSUM1,
RS_CHKSUM2,
};
+
+#ifdef CONFIG_USER_ONLY
+typedef struct {
+ int fd;
+ char *socket_path;
+ int running_state;
+} GDBUserState;
+static GDBUserState gdbserver_user_state;
+#else
+typedef struct {
+ CharBackend chr;
+ Chardev *mon_chr;
+} GDBSystemState;
+static GDBSystemState gdbserver_system_state;
+#endif
+
typedef struct GDBState {
bool init; /* have we been initialised? */
CPUState *c_cpu; /* current CPU for step/continue ops */
@@ -353,14 +369,6 @@ typedef struct GDBState {
int line_csum; /* checksum at the end of the packet */
GByteArray *last_packet;
int signal;
-#ifdef CONFIG_USER_ONLY
- int fd;
- char *socket_path;
- int running_state;
-#else
- CharBackend chr;
- Chardev *mon_chr;
-#endif
bool multiprocess;
GDBProcess *processes;
int process_num;
@@ -412,15 +420,17 @@ static int get_char(void)
int ret;
for(;;) {
- ret = recv(gdbserver_state.fd, &ch, 1, 0);
+ ret = recv(gdbserver_user_state.fd, &ch, 1, 0);
if (ret < 0) {
- if (errno == ECONNRESET)
- gdbserver_state.fd = -1;
- if (errno != EINTR)
+ if (errno == ECONNRESET) {
+ gdbserver_user_state.fd = -1;
+ }
+ if (errno != EINTR) {
return -1;
+ }
} else if (ret == 0) {
- close(gdbserver_state.fd);
- gdbserver_state.fd = -1;
+ close(gdbserver_user_state.fd);
+ gdbserver_user_state.fd = -1;
return -1;
} else {
break;
@@ -479,7 +489,7 @@ static inline void gdb_continue(void)
{
#ifdef CONFIG_USER_ONLY
- gdbserver_state.running_state = 1;
+ gdbserver_user_state.running_state = 1;
trace_gdbstub_op_continue();
#else
if (!runstate_needs_reset()) {
@@ -508,7 +518,7 @@ static int gdb_continue_partial(char *newstates)
cpu_single_step(cpu, gdbserver_state.sstep_flags);
}
}
- gdbserver_state.running_state = 1;
+ gdbserver_user_state.running_state = 1;
#else
int flag = 0;
@@ -560,7 +570,7 @@ static void put_buffer(const uint8_t *buf, int len)
int ret;
while (len > 0) {
- ret = send(gdbserver_state.fd, buf, len, 0);
+ ret = send(gdbserver_user_state.fd, buf, len, 0);
if (ret < 0) {
if (errno != EINTR)
return;
@@ -572,7 +582,7 @@ static void put_buffer(const uint8_t *buf, int len)
#else
/* XXX this blocks entire thread. Rewrite to use
* qemu_chr_fe_write and background I/O callbacks */
- qemu_chr_fe_write_all(&gdbserver_state.chr, buf, len);
+ qemu_chr_fe_write_all(&gdbserver_system_state.chr, buf, len);
#endif
}
@@ -2094,7 +2104,8 @@ static void handle_query_rcmd(GArray *params, void *user_ctx)
len = len / 2;
hextomem(gdbserver_state.mem_buf, get_param(params, 0)->data, len);
g_byte_array_append(gdbserver_state.mem_buf, &zero, 1);
- qemu_chr_be_write(gdbserver_state.mon_chr, gdbserver_state.mem_buf->data,
+ qemu_chr_be_write(gdbserver_system_state.mon_chr,
+ gdbserver_state.mem_buf->data,
gdbserver_state.mem_buf->len);
put_packet("OK");
}
@@ -3027,10 +3038,10 @@ void gdb_exit(int code)
return;
}
#ifdef CONFIG_USER_ONLY
- if (gdbserver_state.socket_path) {
- unlink(gdbserver_state.socket_path);
+ if (gdbserver_user_state.socket_path) {
+ unlink(gdbserver_user_state.socket_path);
}
- if (gdbserver_state.fd < 0) {
+ if (gdbserver_user_state.fd < 0) {
return;
}
#endif
@@ -3041,7 +3052,7 @@ void gdb_exit(int code)
put_packet(buf);
#ifndef CONFIG_USER_ONLY
- qemu_chr_fe_deinit(&gdbserver_state.chr, true);
+ qemu_chr_fe_deinit(&gdbserver_system_state.chr, true);
#endif
}
@@ -3077,7 +3088,7 @@ gdb_handlesig(CPUState *cpu, int sig)
char buf[256];
int n;
- if (!gdbserver_state.init || gdbserver_state.fd < 0) {
+ if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
return sig;
}
@@ -3095,15 +3106,15 @@ gdb_handlesig(CPUState *cpu, int sig)
}
/* put_packet() might have detected that the peer terminated the
connection. */
- if (gdbserver_state.fd < 0) {
+ if (gdbserver_user_state.fd < 0) {
return sig;
}
sig = 0;
gdbserver_state.state = RS_IDLE;
- gdbserver_state.running_state = 0;
- while (gdbserver_state.running_state == 0) {
- n = read(gdbserver_state.fd, buf, 256);
+ gdbserver_user_state.running_state = 0;
+ while (gdbserver_user_state.running_state == 0) {
+ n = read(gdbserver_user_state.fd, buf, 256);
if (n > 0) {
int i;
@@ -3114,9 +3125,9 @@ gdb_handlesig(CPUState *cpu, int sig)
/* XXX: Connection closed. Should probably wait for another
connection before continuing. */
if (n == 0) {
- close(gdbserver_state.fd);
+ close(gdbserver_user_state.fd);
}
- gdbserver_state.fd = -1;
+ gdbserver_user_state.fd = -1;
return sig;
}
}
@@ -3130,7 +3141,7 @@ void gdb_signalled(CPUArchState *env, int sig)
{
char buf[4];
- if (!gdbserver_state.init || gdbserver_state.fd < 0) {
+ if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
return;
}
@@ -3145,7 +3156,7 @@ static void gdb_accept_init(int fd)
gdbserver_state.processes[0].attached = true;
gdbserver_state.c_cpu = gdb_first_attached_cpu();
gdbserver_state.g_cpu = gdbserver_state.c_cpu;
- gdbserver_state.fd = fd;
+ gdbserver_user_state.fd = fd;
gdb_has_xml = false;
}
@@ -3277,7 +3288,7 @@ int gdbserver_start(const char *port_or_path)
if (port > 0 && gdb_accept_tcp(gdb_fd)) {
return 0;
} else if (gdb_accept_socket(gdb_fd)) {
- gdbserver_state.socket_path = g_strdup(port_or_path);
+ gdbserver_user_state.socket_path = g_strdup(port_or_path);
return 0;
}
@@ -3289,11 +3300,11 @@ int gdbserver_start(const char *port_or_path)
/* Disable gdb stub for child processes. */
void gdbserver_fork(CPUState *cpu)
{
- if (!gdbserver_state.init || gdbserver_state.fd < 0) {
+ if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
return;
}
- close(gdbserver_state.fd);
- gdbserver_state.fd = -1;
+ close(gdbserver_user_state.fd);
+ gdbserver_user_state.fd = -1;
cpu_breakpoint_remove_all(cpu, BP_GDB);
cpu_watchpoint_remove_all(cpu, BP_GDB);
}
@@ -3487,21 +3498,22 @@ int gdbserver_start(const char *device)
NULL, NULL, &error_abort);
monitor_init_hmp(mon_chr, false, &error_abort);
} else {
- qemu_chr_fe_deinit(&gdbserver_state.chr, true);
- mon_chr = gdbserver_state.mon_chr;
+ qemu_chr_fe_deinit(&gdbserver_system_state.chr, true);
+ mon_chr = gdbserver_system_state.mon_chr;
reset_gdbserver_state();
}
create_processes(&gdbserver_state);
if (chr) {
- qemu_chr_fe_init(&gdbserver_state.chr, chr, &error_abort);
- qemu_chr_fe_set_handlers(&gdbserver_state.chr, gdb_chr_can_receive,
+ qemu_chr_fe_init(&gdbserver_system_state.chr, chr, &error_abort);
+ qemu_chr_fe_set_handlers(&gdbserver_system_state.chr,
+ gdb_chr_can_receive,
gdb_chr_receive, gdb_chr_event,
NULL, &gdbserver_state, NULL, true);
}
gdbserver_state.state = chr ? RS_IDLE : RS_INACTIVE;
- gdbserver_state.mon_chr = mon_chr;
+ gdbserver_system_state.mon_chr = mon_chr;
gdbserver_state.current_syscall_cb = NULL;
return 0;
--
2.39.2
next prev parent reply other threads:[~2023-03-07 21:23 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 21:21 [PULL 00/30] gdbstub refactor for smaller build Alex Bennée
2023-03-07 21:21 ` [PULL 01/30] gdbstub/internals.h: clean up include guard Alex Bennée
2023-03-07 21:21 ` [PULL 02/30] gdbstub: fix-up copyright and license files Alex Bennée
2023-03-07 21:21 ` [PULL 03/30] gdbstub: Make syscall_complete/[gs]et_reg target-agnostic typedefs Alex Bennée
2023-03-07 21:21 ` [PULL 04/30] gdbstub: clean-up indent on gdb_exit Alex Bennée
2023-03-07 21:21 ` Alex Bennée [this message]
2023-03-07 21:21 ` [PULL 06/30] gdbstub: move GDBState to shared internals header Alex Bennée
2023-03-07 21:21 ` [PULL 07/30] includes: move tb_flush into its own header Alex Bennée
2023-03-07 21:21 ` [PULL 08/30] gdbstub: move fromhex/tohex routines to internals Alex Bennée
2023-03-07 21:21 ` [PULL 09/30] gdbstub: make various helpers visible to the rest of the module Alex Bennée
2023-03-07 21:21 ` [PULL 10/30] gdbstub: move chunk of softmmu functionality to own file Alex Bennée
2023-03-07 21:21 ` [PULL 11/30] gdbstub: move chunks of user code into own files Alex Bennée
2023-03-07 21:21 ` [PULL 12/30] gdbstub: rationalise signal mapping in softmmu Alex Bennée
2023-03-07 21:21 ` [PULL 13/30] gdbstub: abstract target specific details from gdb_put_packet_binary Alex Bennée
2023-03-07 21:21 ` [PULL 14/30] gdbstub: specialise handle_query_attached Alex Bennée
2023-03-07 21:21 ` [PULL 15/30] gdbstub: specialise target_memory_rw_debug Alex Bennée
2023-03-07 21:21 ` [PULL 16/30] gdbstub: introduce gdb_get_max_cpus Alex Bennée
2023-03-07 21:21 ` [PULL 17/30] gdbstub: specialise stub_can_reverse Alex Bennée
2023-03-07 21:21 ` [PULL 18/30] gdbstub: fix address type of gdb_set_cpu_pc Alex Bennée
2023-03-07 21:21 ` [PULL 19/30] gdbstub: don't use target_ulong while handling registers Alex Bennée
2023-03-07 21:21 ` [PULL 20/30] gdbstub: move register helpers into standalone include Alex Bennée
2023-03-07 21:21 ` [PULL 21/30] gdbstub: move syscall handling to new file Alex Bennée
2023-03-07 21:21 ` [PULL 22/30] gdbstub: only compile gdbstub twice for whole build Alex Bennée
2023-03-23 10:05 ` Philippe Mathieu-Daudé
2023-03-29 16:04 ` Philippe Mathieu-Daudé
2023-03-07 21:21 ` [PULL 23/30] testing: probe gdb for supported architectures ahead of time Alex Bennée
2023-03-07 21:21 ` [PULL 24/30] include: split target_long definition from cpu-defs Alex Bennée
2023-03-07 21:21 ` [PULL 25/30] gdbstub: split out softmmu/user specifics for syscall handling Alex Bennée
2023-03-07 21:21 ` [PULL 26/30] gdbstub: Remove gdb_do_syscallv Alex Bennée
2023-03-07 21:21 ` [PULL 27/30] gdbstub: Adjust gdb_do_syscall to only use uint32_t and uint64_t Alex Bennée
2023-03-07 21:21 ` [PULL 28/30] stubs: split semihosting_get_target from system only stubs Alex Bennée
2023-03-07 21:21 ` [PULL 29/30] gdbstub: Build syscall.c once Alex Bennée
2023-03-07 21:21 ` [PULL 30/30] gdbstub: move update guest debug to accel ops Alex Bennée
2023-03-09 21:50 ` [PULL 00/30] gdbstub refactor for smaller build Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230307212139.883112-6-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).