gdbstub: replace exit calls with proper shutdown for softmmu
authorClément Chigot <chigot@adacore.com>
Tue, 3 Oct 2023 07:14:27 +0000 (09:14 +0200)
committerAlistair Francis <alistair.francis@wdc.com>
Thu, 12 Oct 2023 02:36:37 +0000 (12:36 +1000)
This replaces the exit calls by shutdown requests, ensuring a proper
cleanup of Qemu. Features like net/vhost-vdpa.c are expecting
qemu_cleanup to be called to remove their last residuals.

Signed-off-by: Clément Chigot <chigot@adacore.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20231003071427.188697-6-chigot@adacore.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
gdbstub/gdbstub.c
gdbstub/system.c
gdbstub/user.c
include/gdbstub/syscalls.h

index b1532118d1a183657e8cb94244be32cf942f99eb..1e96a71c0cb68ac97bfcf7900d0a6b9b7c4d7549 100644 (file)
@@ -1324,7 +1324,7 @@ static void handle_v_kill(GArray *params, void *user_ctx)
     gdb_put_packet("OK");
     error_report("QEMU: Terminated via GDBstub");
     gdb_exit(0);
-    exit(0);
+    gdb_qemu_exit(0);
 }
 
 static const GdbCmdParseEntry gdb_v_commands_table[] = {
@@ -1843,7 +1843,8 @@ static int gdb_handle_packet(const char *line_buf)
         /* Kill the target */
         error_report("QEMU: Terminated via GDBstub");
         gdb_exit(0);
-        exit(0);
+        gdb_qemu_exit(0);
+        break;
     case 'D':
         {
             static const GdbCmdParseEntry detach_cmd_desc = {
index 48976873d20c7bf30ebd1838236429d2e31444b0..783ac140b9829c7ad28a357e010698844cf801da 100644 (file)
@@ -435,6 +435,12 @@ void gdb_exit(int code)
     qemu_chr_fe_deinit(&gdbserver_system_state.chr, true);
 }
 
+void gdb_qemu_exit(int code)
+{
+    qemu_system_shutdown_request_with_code(SHUTDOWN_CAUSE_GUEST_SHUTDOWN,
+                                           code);
+}
+
 /*
  * Memory access
  */
index 7ab6e5d975e0512922e7cd97ba2a06cd608d9e04..dbe1d9b887541f59c2301633b70458f95e96a1d7 100644 (file)
@@ -113,6 +113,12 @@ void gdb_exit(int code)
         gdb_put_packet(buf);
         gdbserver_state.allow_stop_reply = false;
     }
+
+}
+
+void gdb_qemu_exit(int code)
+{
+    exit(code);
 }
 
 int gdb_handlesig(CPUState *cpu, int sig)
index 243eaf8ce439cc1fe75cd3c7b83db13320ca93e0..54ff7245a11de3914c0ef4c449e451d8afd9730e 100644 (file)
@@ -110,4 +110,13 @@ int use_gdb_syscalls(void);
  */
 void gdb_exit(int code);
 
+/**
+ * gdb_qemu_exit: ask qemu to exit
+ * @code: exit code reported
+ *
+ * This requests qemu to exit. This function is allowed to return as
+ * the exit request might be processed asynchronously by qemu backend.
+ */
+void gdb_qemu_exit(int code);
+
 #endif /* _SYSCALLS_H_ */