From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Weiwei Li" <liweiwei@iscas.ac.cn>,
"Cédric Le Goater" <clg@kaod.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Laurent Vivier" <laurent@vivier.eu>,
nicolas.eder@lauterbach.com,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
kvm@vger.kernel.org,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Max Filippov" <jcmvbkbc@gmail.com>,
"Sunil Muthuswamy" <sunilmut@microsoft.com>,
qemu-s390x@nongnu.org, "Stafford Horne" <shorne@gmail.com>,
"Bin Meng" <bin.meng@windriver.com>,
"Marek Vasut" <marex@denx.de>, "Greg Kurz" <groug@kaod.org>,
"Song Gao" <gaosong@loongson.cn>,
"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Chris Wulff" <crwulff@gmail.com>,
qemu-riscv@nongnu.org, "Michael Rolnik" <mrolnik@gmail.com>,
qemu-arm@nongnu.org, "Cleber Rosa" <crosa@redhat.com>,
"Artyom Tarasenko" <atar4qemu@gmail.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Yoshinori Sato" <ysato@users.sourceforge.jp>,
"Alexandre Iooss" <erdnaxe@crans.org>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
mads@ynddal.dk,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
qemu-ppc@nongnu.org,
"Richard Henderson" <richard.henderson@linaro.org>,
"John Snow" <jsnow@redhat.com>,
"Xiaojuan Yang" <yangxiaojuan@loongson.cn>,
"Thomas Huth" <thuth@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Mahmoud Mandour" <ma.mandourr@gmail.com>,
"Aurelien Jarno" <aurelien@aurel32.net>,
"Bastian Koppelmann" <kbastian@mail.uni-paderborn.de>,
"Yanan Wang" <wangyanan55@huawei.com>,
"David Hildenbrand" <david@redhat.com>,
"Taylor Simpson" <tsimpson@quicinc.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: [PATCH v4 23/26] testing: probe gdb for supported architectures ahead of time
Date: Thu, 2 Mar 2023 19:08:43 +0000 [thread overview]
Message-ID: <20230302190846.2593720-24-alex.bennee@linaro.org> (raw)
In-Reply-To: <20230302190846.2593720-1-alex.bennee@linaro.org>
Currently when we encounter a gdb that is old or not built with
multiarch in mind we fail rather messily. Try and improve the
situation by probing ahead of time and setting
HOST_GDB_SUPPORTS_ARCH=y in the relevant tcg configs. We can then skip
and give a more meaningful message if we don't run the test.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
---
v4
- convert script to python, use mapping to set arches
- update MAINTAINERS
---
MAINTAINERS | 1 +
configure | 8 ++
scripts/probe-gdb-support.py | 88 +++++++++++++++++++
tests/tcg/aarch64/Makefile.target | 2 +-
tests/tcg/multiarch/Makefile.target | 5 ++
.../multiarch/system/Makefile.softmmu-target | 6 +-
tests/tcg/s390x/Makefile.target | 2 +-
7 files changed, 109 insertions(+), 3 deletions(-)
create mode 100755 scripts/probe-gdb-support.py
diff --git a/MAINTAINERS b/MAINTAINERS
index c7a8e2307f..8d0113b8f9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2739,6 +2739,7 @@ F: include/gdbstub/*
F: gdb-xml/
F: tests/tcg/multiarch/gdbstub/
F: scripts/feature_to_c.sh
+F: scripts/probe-gdb-support.py
Memory API
M: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/configure b/configure
index 50a0b80b27..f0cd3923f3 100755
--- a/configure
+++ b/configure
@@ -230,6 +230,7 @@ stack_protector=""
safe_stack=""
use_containers="yes"
gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
+gdb_arches=""
if test -e "$source_path/.git"
then
@@ -2392,6 +2393,7 @@ if test -n "$gdb_bin"; then
gdb_version=$($gdb_bin --version | head -n 1)
if version_ge ${gdb_version##* } 9.1; then
echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
+ gdb_arches=$("$source_path/scripts/probe-gdb-support.py" $gdb_bin)
else
gdb_bin=""
fi
@@ -2516,6 +2518,12 @@ for target in $target_list; do
write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
+
+ # will GDB work with these binaries?
+ if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
+ echo "HOST_GDB_SUPPORTS_ARCH=y" >> "$config_target_mak"
+ fi
+
echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
tcg_tests_targets="$tcg_tests_targets $target"
fi
diff --git a/scripts/probe-gdb-support.py b/scripts/probe-gdb-support.py
new file mode 100755
index 0000000000..c786b7620e
--- /dev/null
+++ b/scripts/probe-gdb-support.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python3
+# coding: utf-8
+#
+# Probe gdb for supported architectures.
+#
+# This is required to support testing of the gdbstub as its hard to
+# handle errors gracefully during the test. Instead this script when
+# passed a GDB binary will probe its architecture support and return a
+# string of supported arches, stripped of guff.
+#
+# Copyright 2023 Linaro Ltd
+#
+# Author: Alex Bennée <alex.bennee@linaro.org>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import argparse
+import re
+from subprocess import check_output, STDOUT
+
+# mappings from gdb arch to QEMU target
+mappings = {
+ "alpha" : "alpha",
+ "aarch64" : ["aarch64", "aarch64_be"],
+ "armv7": "arm",
+ "armv8-a" : ["aarch64", "aarch64_be"],
+ "avr" : "avr",
+ "cris" : "cris",
+ # hexagon?
+ "hppa1.0" : "hppa",
+ "i386" : "i386",
+ "i386:x86-64" : "x86_64",
+ # loongarch?
+ "m68k" : "m68k",
+ "MicroBlaze" : "microblaze",
+ "mips:isa64" : ["mips64", "mips64el"],
+ "nios2" : "nios2",
+ "or1k" : "or1k",
+ "powerpc:common" : "ppc",
+ "powerpc:common64" : "ppc64",
+ "riscv:rv32" : "riscv32",
+ "riscv:rv64" : "riscv64",
+ "s390:64-bit" : "s390x",
+ "sh4" : ["sh4", "sh4eb"],
+ "sparc": "sparc",
+ "sparc:v8plus": "sparc32plus",
+ "sparc:v9a" : "sparc64",
+ # no tricore in upstream gdb
+ "xtensa" : ["xtensa", "xtensaeb"]
+}
+
+def do_probe(gdb):
+ gdb_out = check_output([gdb,
+ "-ex", "set architecture",
+ "-ex", "quit"], stderr=STDOUT)
+
+ m = re.search(r"Valid arguments are (.*)",
+ gdb_out.decode("utf-8"))
+
+ valid_arches = set()
+
+ if m.group(1):
+ for arch in m.group(1).split(", "):
+ if arch in mappings:
+ mapping = mappings[arch]
+ if isinstance(mapping, str):
+ valid_arches.add(mapping)
+ else:
+ for entry in mapping:
+ valid_arches.add(entry)
+
+ return valid_arches
+
+def main() -> None:
+ parser = argparse.ArgumentParser(description='Probe GDB Architectures')
+ parser.add_argument('gdb', help='Path to GDB binary.')
+
+ args = parser.parse_args()
+
+ supported = do_probe(args.gdb)
+
+ print(" ".join(supported))
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
index db122ab4ff..9e91a20b0d 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -81,7 +81,7 @@ sha512-vector: sha512.c
TESTS += sha512-vector
-ifneq ($(HAVE_GDB_BIN),)
+ifeq ($(HOST_GDB_SUPPORTS_ARCH),y)
GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py
run-gdbstub-sysregs: sysregs
diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target
index ae8b3d7268..373db69648 100644
--- a/tests/tcg/multiarch/Makefile.target
+++ b/tests/tcg/multiarch/Makefile.target
@@ -64,6 +64,7 @@ run-test-mmap-%: test-mmap
$(call run-test, test-mmap-$*, $(QEMU) -p $* $<, $< ($* byte pages))
ifneq ($(HAVE_GDB_BIN),)
+ifeq ($(HOST_GDB_SUPPORTS_ARCH),y)
GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py
run-gdbstub-sha1: sha1
@@ -87,6 +88,10 @@ run-gdbstub-thread-breakpoint: testthread
--bin $< --test $(MULTIARCH_SRC)/gdbstub/test-thread-breakpoint.py, \
hitting a breakpoint on non-main thread)
+else
+run-gdbstub-%:
+ $(call skip-test, "gdbstub test $*", "no guest arch support")
+endif
else
run-gdbstub-%:
$(call skip-test, "gdbstub test $*", "need working gdb")
diff --git a/tests/tcg/multiarch/system/Makefile.softmmu-target b/tests/tcg/multiarch/system/Makefile.softmmu-target
index 368b64d531..5f432c95f3 100644
--- a/tests/tcg/multiarch/system/Makefile.softmmu-target
+++ b/tests/tcg/multiarch/system/Makefile.softmmu-target
@@ -15,6 +15,7 @@ MULTIARCH_TEST_SRCS=$(wildcard $(MULTIARCH_SYSTEM_SRC)/*.c)
MULTIARCH_TESTS = $(patsubst $(MULTIARCH_SYSTEM_SRC)/%.c, %, $(MULTIARCH_TEST_SRCS))
ifneq ($(HAVE_GDB_BIN),)
+ifeq ($(HOST_GDB_SUPPORTS_ARCH),y)
GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py
run-gdbstub-memory: memory
@@ -26,7 +27,10 @@ run-gdbstub-memory: memory
"-monitor none -display none -chardev file$(COMMA)path=$<.out$(COMMA)id=output $(QEMU_OPTS)" \
--bin $< --test $(MULTIARCH_SRC)/gdbstub/memory.py, \
softmmu gdbstub support)
-
+else
+run-gdbstub-%:
+ $(call skip-test, "gdbstub test $*", "no guest arch support")
+endif
else
run-gdbstub-%:
$(call skip-test, "gdbstub test $*", "need working gdb")
diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 72ad309b27..b7f576f983 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -51,7 +51,7 @@ $(Z15_TESTS): CFLAGS+=-march=z15 -O2
TESTS+=$(Z15_TESTS)
endif
-ifneq ($(HAVE_GDB_BIN),)
+ifeq ($(HOST_GDB_SUPPORTS_ARCH),y)
GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py
run-gdbstub-signals-s390x: signals-s390x
--
2.39.2
next prev parent reply other threads:[~2023-03-02 19:16 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 19:08 [PATCH v4 00/26] gdbstub/next: re-organise and split build Alex Bennée
2023-03-02 19:08 ` [PATCH v4 01/26] gdbstub/internals.h: clean up include guard Alex Bennée
2023-03-02 19:08 ` [PATCH v4 02/26] gdbstub: fix-up copyright and license files Alex Bennée
2023-03-02 19:08 ` [PATCH v4 03/26] gdbstub: Make syscall_complete/[gs]et_reg target-agnostic typedefs Alex Bennée
2023-03-02 19:08 ` [PATCH v4 04/26] gdbstub: clean-up indent on gdb_exit Alex Bennée
2023-03-02 20:29 ` Richard Henderson
2023-03-03 8:33 ` Daniel Henrique Barboza
2023-03-02 19:08 ` [PATCH v4 05/26] gdbstub: define separate user/system structures Alex Bennée
2023-03-02 19:08 ` [PATCH v4 06/26] gdbstub: move GDBState to shared internals header Alex Bennée
2023-03-02 19:08 ` [PATCH v4 07/26] includes: move tb_flush into its own header Alex Bennée
2023-03-02 19:08 ` [PATCH v4 08/26] gdbstub: move fromhex/tohex routines to internals Alex Bennée
2023-03-02 19:08 ` [PATCH v4 09/26] gdbstub: make various helpers visible to the rest of the module Alex Bennée
2023-03-02 19:08 ` [PATCH v4 10/26] gdbstub: move chunk of softmmu functionality to own file Alex Bennée
2023-03-02 19:08 ` [PATCH v4 11/26] gdbstub: move chunks of user code into own files Alex Bennée
2023-03-02 19:08 ` [PATCH v4 12/26] gdbstub: rationalise signal mapping in softmmu Alex Bennée
2023-03-02 19:08 ` [PATCH v4 13/26] gdbstub: abstract target specific details from gdb_put_packet_binary Alex Bennée
2023-03-02 19:08 ` [PATCH v4 14/26] gdbstub: specialise handle_query_attached Alex Bennée
2023-03-02 19:08 ` [PATCH v4 15/26] gdbstub: specialise target_memory_rw_debug Alex Bennée
2023-03-02 19:08 ` [PATCH v4 16/26] gdbstub: introduce gdb_get_max_cpus Alex Bennée
2023-03-02 19:08 ` [PATCH v4 17/26] gdbstub: specialise stub_can_reverse Alex Bennée
2023-03-02 19:08 ` [PATCH v4 18/26] gdbstub: fix address type of gdb_set_cpu_pc Alex Bennée
2023-03-02 19:08 ` [PATCH v4 19/26] gdbstub: don't use target_ulong while handling registers Alex Bennée
2023-03-02 19:08 ` [PATCH v4 20/26] gdbstub: move register helpers into standalone include Alex Bennée
2023-03-02 19:08 ` [PATCH v4 21/26] gdbstub: move syscall handling to new file Alex Bennée
2023-03-02 19:08 ` [PATCH v4 22/26] gdbstub: only compile gdbstub twice for whole build Alex Bennée
2023-03-02 22:00 ` Richard Henderson
2023-03-02 19:08 ` Alex Bennée [this message]
2023-03-02 20:47 ` [PATCH v4 23/26] testing: probe gdb for supported architectures ahead of time Richard Henderson
2023-03-02 21:52 ` Richard Henderson
2023-03-02 19:08 ` [PATCH v4 24/26] include: split target_long definition from cpu-defs Alex Bennée
2023-03-02 19:08 ` [PATCH v4 25/26] gdbstub: split out softmmu/user specifics for syscall handling Alex Bennée
2023-03-02 22:21 ` Richard Henderson
2023-03-02 19:08 ` [PATCH v4 26/26] gdbstub: move update guest debug to accel ops Alex Bennée
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=20230302190846.2593720-24-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=aleksandar.rikalo@syrmia.com \
--cc=alistair.francis@wdc.com \
--cc=atar4qemu@gmail.com \
--cc=aurelien@aurel32.net \
--cc=bin.meng@windriver.com \
--cc=clg@kaod.org \
--cc=crosa@redhat.com \
--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=jsnow@redhat.com \
--cc=kbastian@mail.uni-paderborn.de \
--cc=kvm@vger.kernel.org \
--cc=laurent@vivier.eu \
--cc=liweiwei@iscas.ac.cn \
--cc=ma.mandourr@gmail.com \
--cc=mads@ynddal.dk \
--cc=marcel.apfelbaum@gmail.com \
--cc=marex@denx.de \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mrolnik@gmail.com \
--cc=nicolas.eder@lauterbach.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 \
--cc=zhiwei_liu@linux.alibaba.com \
/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).