summary refs log tree commit diff stats
path: root/tests/tcg/multiarch/late-attach.c
diff options
context:
space:
mode:
authorIlya Leoshkevich <iii@linux.ibm.com>2025-02-07 15:31:12 +0000
committerAlex Bennée <alex.bennee@linaro.org>2025-02-10 13:47:59 +0000
commit24c61663dcec0e87bb4206a7623f0e222e188b47 (patch)
treeae327e96dda16dc89ee383199b343523f496c365 /tests/tcg/multiarch/late-attach.c
parent628d64222e6bef249d23ce3147cbfb47259f2ede (diff)
downloadfocaccia-qemu-24c61663dcec0e87bb4206a7623f0e222e188b47.tar.gz
focaccia-qemu-24c61663dcec0e87bb4206a7623f0e222e188b47.zip
tests/tcg: Add late gdbstub attach test
Add a small test to prevent regressions.
Make sure that host_interrupt_signal is not visible to the guest.

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Message-Id: <20250117001542.8290-9-iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20250207153112.3939799-18-alex.bennee@linaro.org>
Diffstat (limited to 'tests/tcg/multiarch/late-attach.c')
-rw-r--r--tests/tcg/multiarch/late-attach.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/tcg/multiarch/late-attach.c b/tests/tcg/multiarch/late-attach.c
new file mode 100644
index 0000000000..20a364034b
--- /dev/null
+++ b/tests/tcg/multiarch/late-attach.c
@@ -0,0 +1,41 @@
+/*
+ * Test attaching GDB to a running process.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static const char *phase = "start";
+
+int main(void)
+{
+    sigset_t set;
+    int sig;
+
+    assert(sigfillset(&set) == 0);
+    assert(sigprocmask(SIG_BLOCK, &set, NULL) == 0);
+
+    /* Let GDB know it can send SIGUSR1. */
+    phase = "sigwait";
+    if (getenv("LATE_ATTACH_PY")) {
+        assert(sigwait(&set, &sig) == 0);
+        if (sig != SIGUSR1) {
+            fprintf(stderr, "Unexpected signal %d\n", sig);
+            return EXIT_FAILURE;
+        }
+    }
+
+    /* Check that the guest does not see host_interrupt_signal. */
+    assert(sigpending(&set) == 0);
+    for (sig = 1; sig < NSIG; sig++) {
+        if (sigismember(&set, sig)) {
+            fprintf(stderr, "Unexpected signal %d\n", sig);
+            return EXIT_FAILURE;
+        }
+    }
+
+    return EXIT_SUCCESS;
+}