diff mbox series

[v2,12/21] gdbstub: abstract target specific details from gdb_put_packet_binary

Message ID 20230105164320.2164095-13-alex.bennee@linaro.org
State Superseded
Headers show
Series gdbstub: re-organise to for better compilation behaviour | expand

Commit Message

Alex Bennée Jan. 5, 2023, 4:43 p.m. UTC
We unfortunately handle the checking of packet acknowledgement
differently for user and softmmu modes. Abstract the user mode stuff
behind gdb_got_immediate_ack with a stub for softmmu.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 gdbstub/internals.h | 15 +++++++++++++++
 gdbstub/gdbstub.c   | 10 ++--------
 gdbstub/softmmu.c   |  8 ++++++++
 gdbstub/user.c      | 19 +++++++++++++++++++
 4 files changed, 44 insertions(+), 8 deletions(-)

Comments

Philippe Mathieu-Daudé Jan. 5, 2023, 5:13 p.m. UTC | #1
On 5/1/23 17:43, Alex Bennée wrote:
> We unfortunately handle the checking of packet acknowledgement
> differently for user and softmmu modes. Abstract the user mode stuff
> behind gdb_got_immediate_ack with a stub for softmmu.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   gdbstub/internals.h | 15 +++++++++++++++
>   gdbstub/gdbstub.c   | 10 ++--------
>   gdbstub/softmmu.c   |  8 ++++++++
>   gdbstub/user.c      | 19 +++++++++++++++++++
>   4 files changed, 44 insertions(+), 8 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Richard Henderson Jan. 6, 2023, 9:57 p.m. UTC | #2
On 1/5/23 08:43, Alex Bennée wrote:
> We unfortunately handle the checking of packet acknowledgement
> differently for user and softmmu modes. Abstract the user mode stuff
> behind gdb_got_immediate_ack with a stub for softmmu.
> 
> Signed-off-by: Alex Bennée<alex.bennee@linaro.org>
> ---
>   gdbstub/internals.h | 15 +++++++++++++++
>   gdbstub/gdbstub.c   | 10 ++--------
>   gdbstub/softmmu.c   |  8 ++++++++
>   gdbstub/user.c      | 19 +++++++++++++++++++
>   4 files changed, 44 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/gdbstub/internals.h b/gdbstub/internals.h
index 568b432220..8d260e2481 100644
--- a/gdbstub/internals.h
+++ b/gdbstub/internals.h
@@ -106,6 +106,21 @@  void gdb_memtohex(GString *buf, const uint8_t *mem, int len);
 void gdb_memtox(GString *buf, const char *mem, int len);
 void gdb_read_byte(uint8_t ch);
 
+/*
+ * Packet acknowledgement - we handle this slightly differently
+ * between user and softmmu mode, mainly to deal with the differences
+ * between the flexible chardev and the direct fd approaches.
+ *
+ * We currently don't support a negotiated QStartNoAckMode
+ */
+
+/**
+ * gdb_got_immediate_ack() - check ok to continue
+ *
+ * Returns true to continue, false to re-transmit for user only, the
+ * softmmu stub always returns true.
+ */
+bool gdb_got_immediate_ack(void);
 /* utility helpers */
 CPUState *gdb_first_attached_cpu(void);
 void gdb_append_thread_id(CPUState *cpu, GString *buf);
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 4bf99783a6..76c24b7cb6 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -239,15 +239,9 @@  int gdb_put_packet_binary(const char *buf, int len, bool dump)
         gdb_put_buffer(gdbserver_state.last_packet->data,
                    gdbserver_state.last_packet->len);
 
-#ifdef CONFIG_USER_ONLY
-        i = gdb_get_char();
-        if (i < 0)
-            return -1;
-        if (i == '+')
+        if (gdb_got_immediate_ack()) {
             break;
-#else
-        break;
-#endif
+        }
     }
     return 0;
 }
diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c
index ee5daad0cf..534370081d 100644
--- a/gdbstub/softmmu.c
+++ b/gdbstub/softmmu.c
@@ -58,6 +58,14 @@  int gdb_get_cpu_index(CPUState *cpu)
     return cpu->cpu_index + 1;
 }
 
+/*
+ * We check the status of the last message in the chardev receive code
+ */
+bool gdb_got_immediate_ack(void)
+{
+    return true;
+}
+
 /*
  * GDB Connection management. For system emulation we do all of this
  * via our existing Chardev infrastructure which allows us to support
diff --git a/gdbstub/user.c b/gdbstub/user.c
index 4898f16c90..fa19ec5263 100644
--- a/gdbstub/user.c
+++ b/gdbstub/user.c
@@ -57,6 +57,25 @@  int gdb_get_char(void)
     return ch;
 }
 
+bool gdb_got_immediate_ack(void)
+{
+    int i;
+
+    i = gdb_get_char();
+    if (i < 0) {
+        /* no response, continue anyway */
+        return true;
+    }
+
+    if (i == '+') {
+        /* received correctly, continue */
+        return true;
+    }
+
+    /* anything else, including '-' then try again */
+    return false;
+}
+
 void gdb_put_buffer(const uint8_t *buf, int len)
 {
     int ret;