qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org, alex.bennee@gmail.com
Cc: "David Hildenbrand" <david@redhat.com>,
	"Sunil Muthuswamy" <sunilmut@microsoft.com>,
	"Aurelien Jarno" <aurelien@aurel32.net>,
	"Michael Rolnik" <mrolnik@gmail.com>,
	"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
	"Greg Kurz" <groug@kaod.org>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Thomas Huth" <thuth@redhat.com>,
	qemu-ppc@nongnu.org, "Laurent Vivier" <laurent@vivier.eu>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Marek Vasut" <marex@denx.de>,
	"Stafford Horne" <shorne@gmail.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Taylor Simpson" <tsimpson@quicinc.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Chris Wulff" <crwulff@gmail.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Song Gao" <gaosong@loongson.cn>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Artyom Tarasenko" <atar4qemu@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	qemu-riscv@nongnu.org, qemu-s390x@nongnu.org,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Bastian Koppelmann" <kbastian@mail.uni-paderborn.de>,
	"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Bin Meng" <bin.meng@windriver.com>,
	"Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Yoshinori Sato" <ysato@users.sourceforge.jp>,
	"Xiaojuan Yang" <yangxiaojuan@loongson.cn>,
	qemu-arm@nongnu.org
Subject: [PATCH v2 05/21] gdbstub: define separate user/system structures
Date: Thu,  5 Jan 2023 16:43:04 +0000	[thread overview]
Message-ID: <20230105164320.2164095-6-alex.bennee@linaro.org> (raw)
In-Reply-To: <20230105164320.2164095-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. These will eventually be defined in their own
files.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 gdbstub/gdbstub.c | 91 +++++++++++++++++++++++++++--------------------
 1 file changed, 53 insertions(+), 38 deletions(-)

diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index be88ca0d71..42ae13b344 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -342,6 +342,20 @@ enum RSState {
     RS_CHKSUM1,
     RS_CHKSUM2,
 };
+
+#ifdef CONFIG_USER_ONLY
+typedef struct {
+    int fd;
+    char *socket_path;
+    int running_state;
+} GDBUserState;
+#else
+typedef struct {
+    CharBackend chr;
+    Chardev *mon_chr;
+} GDBSystemState;
+#endif
+
 typedef struct GDBState {
     bool init;       /* have we been initialised? */
     CPUState *c_cpu; /* current CPU for step/continue ops */
@@ -355,12 +369,9 @@ typedef struct GDBState {
     GByteArray *last_packet;
     int signal;
 #ifdef CONFIG_USER_ONLY
-    int fd;
-    char *socket_path;
-    int running_state;
+    GDBUserState user;
 #else
-    CharBackend chr;
-    Chardev *mon_chr;
+    GDBSystemState system;
 #endif
     bool multiprocess;
     GDBProcess *processes;
@@ -413,15 +424,17 @@ static int get_char(void)
     int ret;
 
     for(;;) {
-        ret = recv(gdbserver_state.fd, &ch, 1, 0);
+        ret = recv(gdbserver_state.user.fd, &ch, 1, 0);
         if (ret < 0) {
-            if (errno == ECONNRESET)
-                gdbserver_state.fd = -1;
-            if (errno != EINTR)
+            if (errno == ECONNRESET) {
+                gdbserver_state.user.fd = -1;
+            }
+            if (errno != EINTR) {
                 return -1;
+            }
         } else if (ret == 0) {
-            close(gdbserver_state.fd);
-            gdbserver_state.fd = -1;
+            close(gdbserver_state.user.fd);
+            gdbserver_state.user.fd = -1;
             return -1;
         } else {
             break;
@@ -480,7 +493,7 @@ static inline void gdb_continue(void)
 {
 
 #ifdef CONFIG_USER_ONLY
-    gdbserver_state.running_state = 1;
+    gdbserver_state.user.running_state = 1;
     trace_gdbstub_op_continue();
 #else
     if (!runstate_needs_reset()) {
@@ -509,7 +522,7 @@ static int gdb_continue_partial(char *newstates)
             cpu_single_step(cpu, gdbserver_state.sstep_flags);
         }
     }
-    gdbserver_state.running_state = 1;
+    gdbserver_state.user.running_state = 1;
 #else
     int flag = 0;
 
@@ -561,7 +574,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_state.user.fd, buf, len, 0);
         if (ret < 0) {
             if (errno != EINTR)
                 return;
@@ -573,7 +586,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_state.system.chr, buf, len);
 #endif
 }
 
@@ -2095,7 +2108,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_state.system.mon_chr,
+                      gdbserver_state.mem_buf->data,
                       gdbserver_state.mem_buf->len);
     put_packet("OK");
 }
@@ -3028,10 +3042,10 @@ void gdb_exit(int code)
       return;
   }
 #ifdef CONFIG_USER_ONLY
-  if (gdbserver_state.socket_path) {
-      unlink(gdbserver_state.socket_path);
+  if (gdbserver_state.user.socket_path) {
+      unlink(gdbserver_state.user.socket_path);
   }
-  if (gdbserver_state.fd < 0) {
+  if (gdbserver_state.user.fd < 0) {
       return;
   }
 #endif
@@ -3042,7 +3056,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_state.system.chr, true);
 #endif
 }
 
@@ -3078,7 +3092,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_state.user.fd < 0) {
         return sig;
     }
 
@@ -3096,15 +3110,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_state.user.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_state.user.running_state = 0;
+    while (gdbserver_state.user.running_state == 0) {
+        n = read(gdbserver_state.user.fd, buf, 256);
         if (n > 0) {
             int i;
 
@@ -3115,9 +3129,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_state.user.fd);
             }
-            gdbserver_state.fd = -1;
+            gdbserver_state.user.fd = -1;
             return sig;
         }
     }
@@ -3131,7 +3145,7 @@ void gdb_signalled(CPUArchState *env, int sig)
 {
     char buf[4];
 
-    if (!gdbserver_state.init || gdbserver_state.fd < 0) {
+    if (!gdbserver_state.init || gdbserver_state.user.fd < 0) {
         return;
     }
 
@@ -3146,7 +3160,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_state.user.fd = fd;
     gdb_has_xml = false;
 }
 
@@ -3278,7 +3292,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_state.user.socket_path = g_strdup(port_or_path);
         return 0;
     }
 
@@ -3290,11 +3304,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_state.user.fd < 0) {
         return;
     }
-    close(gdbserver_state.fd);
-    gdbserver_state.fd = -1;
+    close(gdbserver_state.user.fd);
+    gdbserver_state.user.fd = -1;
     cpu_breakpoint_remove_all(cpu, BP_GDB);
     cpu_watchpoint_remove_all(cpu, BP_GDB);
 }
@@ -3488,21 +3502,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_state.system.chr, true);
+        mon_chr = gdbserver_state.system.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_state.system.chr, chr, &error_abort);
+        qemu_chr_fe_set_handlers(&gdbserver_state.system.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_state.system.mon_chr = mon_chr;
     gdbserver_state.current_syscall_cb = NULL;
 
     return 0;
-- 
2.34.1



  parent reply	other threads:[~2023-01-05 16:43 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-05 16:42 [PATCH v2 00/21] gdbstub: re-organise to for better compilation behaviour Alex Bennée
2023-01-05 16:43 ` [PATCH v2 01/21] gdbstub/internals.h: clean up include guard Alex Bennée
2023-01-05 17:01   ` Philippe Mathieu-Daudé
2023-01-08 12:51   ` Bin Meng
2023-01-05 16:43 ` [PATCH v2 02/21] target/arm: fix handling of HLT semihosting in system mode Alex Bennée
2023-01-06 20:36   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 03/21] gdbstub: fix-up copyright and license files Alex Bennée
2023-01-05 17:02   ` Philippe Mathieu-Daudé
2023-01-05 16:43 ` [PATCH v2 04/21] gdbstub: Make syscall_complete/[gs]et_reg target-agnostic typedefs Alex Bennée
2023-01-05 16:43 ` Alex Bennée [this message]
2023-01-06 20:39   ` [PATCH v2 05/21] gdbstub: define separate user/system structures Richard Henderson
2023-01-05 16:43 ` [PATCH v2 06/21] gdbstub: move GDBState to shared internals header Alex Bennée
2023-01-06 20:42   ` Richard Henderson
2023-02-21 10:24     ` Alex Bennée
2023-02-21 10:36       ` Richard Henderson
2023-02-21 10:58         ` Alex Bennée
2023-01-05 16:43 ` [PATCH v2 07/21] includes: move tb_flush into its own header Alex Bennée
2023-01-05 16:43 ` [PATCH v2 08/21] gdbstub: move fromhex/tohex routines to internals Alex Bennée
2023-01-06 20:43   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 09/21] gdbstub: make various helpers visible to the rest of the module Alex Bennée
2023-01-05 17:09   ` Philippe Mathieu-Daudé
2023-01-06 21:37   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 10/21] gdbstub: move chunk of softmmu functionality to own file Alex Bennée
2023-01-06 21:51   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 11/21] gdbstub: move chunks of user code into own files Alex Bennée
2023-01-06 21:56   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 12/21] gdbstub: abstract target specific details from gdb_put_packet_binary Alex Bennée
2023-01-05 17:13   ` Philippe Mathieu-Daudé
2023-01-06 21:57   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 13/21] gdbstub: specialise handle_query_attached Alex Bennée
2023-01-05 17:22   ` Philippe Mathieu-Daudé
2023-01-06 21:59   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 14/21] gdbstub: specialise target_memory_rw_debug Alex Bennée
2023-01-06 23:14   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 15/21] gdbstub: introduce gdb_get_max_cpus Alex Bennée
2023-01-06 23:16   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 16/21] gdbstub: specialise stub_can_reverse Alex Bennée
2023-01-05 17:25   ` Philippe Mathieu-Daudé
2023-01-06 23:17   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 17/21] gdbstub: fix address type of gdb_set_cpu_pc Alex Bennée
2023-01-05 17:26   ` Philippe Mathieu-Daudé
2023-01-06 23:19   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 18/21] gdbstub: don't use target_ulong while handling registers Alex Bennée
2023-01-05 17:28   ` Philippe Mathieu-Daudé
2023-01-06 23:24     ` Richard Henderson
2023-01-06 23:23   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 19/21] gdbstub: move register helpers into standalone include Alex Bennée
2023-01-05 16:56   ` Taylor Simpson
2023-01-05 17:30   ` Philippe Mathieu-Daudé
2023-01-05 19:05   ` Max Filippov
2023-01-06 23:28   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 20/21] gdbstub: move syscall handling to new file Alex Bennée
2023-01-06 23:46   ` Richard Henderson
2023-01-05 16:43 ` [PATCH v2 21/21] gdbstub: only compile gdbstub twice for whole build Alex Bennée
2023-01-06 23:55   ` Richard Henderson

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=20230105164320.2164095-6-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=aleksandar.rikalo@syrmia.com \
    --cc=alex.bennee@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=atar4qemu@gmail.com \
    --cc=aurelien@aurel32.net \
    --cc=bin.meng@windriver.com \
    --cc=clg@kaod.org \
    --cc=crwulff@gmail.com \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=eduardo@habkost.net \
    --cc=erdnaxe@crans.org \
    --cc=gaosong@loongson.cn \
    --cc=groug@kaod.org \
    --cc=iii@linux.ibm.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=kbastian@mail.uni-paderborn.de \
    --cc=laurent@vivier.eu \
    --cc=ma.mandourr@gmail.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=marex@denx.de \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mrolnik@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=shorne@gmail.com \
    --cc=sunilmut@microsoft.com \
    --cc=thuth@redhat.com \
    --cc=tsimpson@quicinc.com \
    --cc=wangyanan55@huawei.com \
    --cc=yangxiaojuan@loongson.cn \
    --cc=ysato@users.sourceforge.jp \
    /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).