summary refs log tree commit diff stats
path: root/tests/tcg/multiarch/gdbstub
diff options
context:
space:
mode:
authorIlya Leoshkevich <iii@linux.ibm.com>2024-01-29 10:32:16 +0100
committerRichard Henderson <richard.henderson@linaro.org>2024-01-29 20:48:49 +1000
commit82607a73f8f6dc84d50a7f9b04ab740cc493d1cc (patch)
treea9967cb71c70c7c8bc2642128d69531cb4445ffa /tests/tcg/multiarch/gdbstub
parent4d48c1bc079147a02ec1a3df9a41497c515d2e61 (diff)
downloadfocaccia-qemu-82607a73f8f6dc84d50a7f9b04ab740cc493d1cc.tar.gz
focaccia-qemu-82607a73f8f6dc84d50a7f9b04ab740cc493d1cc.zip
tests/tcg: Add the PROT_NONE gdbstub test
Make sure that qemu gdbstub, like gdbserver, allows reading from and
writing to PROT_NONE pages.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Message-Id: <20240129093410.3151-4-iii@linux.ibm.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'tests/tcg/multiarch/gdbstub')
-rw-r--r--tests/tcg/multiarch/gdbstub/prot-none.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/tcg/multiarch/gdbstub/prot-none.py b/tests/tcg/multiarch/gdbstub/prot-none.py
new file mode 100644
index 0000000000..e829d3ebc5
--- /dev/null
+++ b/tests/tcg/multiarch/gdbstub/prot-none.py
@@ -0,0 +1,36 @@
+"""Test that GDB can access PROT_NONE pages.
+
+This runs as a sourced script (via -x, via run-test.py).
+
+SPDX-License-Identifier: GPL-2.0-or-later
+"""
+import ctypes
+from test_gdbstub import main, report
+
+
+def probe_proc_self_mem():
+    buf = ctypes.create_string_buffer(b'aaa')
+    try:
+        with open("/proc/self/mem", "rb") as fp:
+            fp.seek(ctypes.addressof(buf))
+            return fp.read(3) == b'aaa'
+    except OSError:
+        return False
+
+
+def run_test():
+    """Run through the tests one by one"""
+    if not probe_proc_self_mem:
+        print("SKIP: /proc/self/mem is not usable")
+        exit(0)
+    gdb.Breakpoint("break_here")
+    gdb.execute("continue")
+    val = gdb.parse_and_eval("*(char[2] *)q").string()
+    report(val == "42", "{} == 42".format(val))
+    gdb.execute("set *(char[3] *)q = \"24\"")
+    gdb.execute("continue")
+    exitcode = int(gdb.parse_and_eval("$_exitcode"))
+    report(exitcode == 0, "{} == 0".format(exitcode))
+
+
+main(run_test)