From patchwork Thu Mar 2 19:08:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 658144 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp67384wrb; Thu, 2 Mar 2023 11:16:09 -0800 (PST) X-Google-Smtp-Source: AK7set99NBjbxInTS5QQ9G0JLkqUjat/WgtbsOTnmAYA6Rk7kcKUC3KgVmNCXsCj19Gb698qrJOO X-Received: by 2002:ac8:5dd1:0:b0:3bf:daae:7ee3 with SMTP id e17-20020ac85dd1000000b003bfdaae7ee3mr18668159qtx.53.1677784568831; Thu, 02 Mar 2023 11:16:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677784568; cv=none; d=google.com; s=arc-20160816; b=XchnfLmwf+jWduLQnB0iFffQhc08RgETePyLyLyDUEmxMV90OfSZT5jIUUBNwH/RC0 2uIdhgOoKCUYvGtOsE7GeL20lsBMF2bVwWYJD8h8ZoE6AEvMUNohRQILAPoC1UQDrXZy AQ6AMeGoC+5G6VBtdnHPEZzRJBkTajw8t0hQof/24mkswo3H+xGTmXie6hHKfWpIkP8k Hihsx44RAiQgCr3tT2Bv4Ogh9O3oAFP6bOhdNR2YPwpoViIDWUXrALvOgGUQVo4NMedF TWIlRwoAnY/gkaltZyhDM79z9KeDIqjTJ/O1SG8ZWUs7woL9OmqaEKi1FN9NOC5G10CN rz6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SHqP0mS63nM1LMhj8fwJgrUBh7QK4PmkZnnhc4Xo7qc=; b=tf2l0lMf3iks42ltP1b69VzVn/84hQReb7Zz0ROr47q55X5XC1QHJ9394Y8OyxII0Q LA34hp6tLT7t3D2xlrrCGEkrR46HiX6C7l6OVaGTHlcRQYHQa4I3TEPtyzx/ZJU3OuEL YrNOiwGLIi3exTb3fMx4oKxlTLuVWBc/ujdxC3NfDUhku+u4s9jtpPBO4uxhP+PJp3ZF HEuJ4NySyjXtD9bmyZK7xl1rPtEsZneDe9j2hqp3ucNd8lePVwkhwnH+Et+eS+iqZdQz OUUViUWPNy/xg+01GbzqeH/wltfvk4A+LZqMi5EmF5//tNAjke01cgRM8vMrRQ0L4VhQ C9XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PDa/dcDp"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z21-20020ac87f95000000b003b688677fc1si227670qtj.732.2023.03.02.11.16.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Mar 2023 11:16:08 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PDa/dcDp"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXoNq-0006Zn-3g; Thu, 02 Mar 2023 14:14:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXoNo-0006Ws-M1 for qemu-devel@nongnu.org; Thu, 02 Mar 2023 14:14:28 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXoNi-0000ju-Ne for qemu-devel@nongnu.org; Thu, 02 Mar 2023 14:14:27 -0500 Received: by mail-wm1-x32d.google.com with SMTP id az36so305649wmb.1 for ; Thu, 02 Mar 2023 11:14:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SHqP0mS63nM1LMhj8fwJgrUBh7QK4PmkZnnhc4Xo7qc=; b=PDa/dcDpBdf7Yr/DlQC5v0nFm6bicQJa3gMfQr9zCWc/O2mMZdUA66hkUwZr3TWQQa ++eYUJCpL1OhQY7j9NaQyyIjvFQgS5xaZk3+XzPxaMLVXt2kz+M1aijI0+pSpWEAApQc PBY3jR0+j5DK2Q0QSMPeP0ymoF340mHvkakUHMIv05uJX1Hn6ruNPYEpErT73Xiqbrbx NqCf5JrB7+miCS8laKMpFsy3yGjibw+6EIbTKE+a6pLgU+0ZJKVQ3mTkDGnBOLkl5JzY anO0FFFqtKJXdfqfkiBkqGswtq3htwxR61fqNWsXLiZuRRz2zQsouFqvtHz/GrVhIJNT uhYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SHqP0mS63nM1LMhj8fwJgrUBh7QK4PmkZnnhc4Xo7qc=; b=y1qprabkKJ2F+kkU7X/gYE0iCnU8j0klCQR4jlmTrSYlfxlzPb9Iqx7vr29tJ9sR/L DE89FkSNumxn5DShsRjpIk+1/Tf36/kHy6lIZj50+cTXBQi1NSQeYpUpb1r/Ex5zt2QN FphfsSa1wK2LazOf4ocWKUgr6N1TFwr1DqM/dGrpR71pOC85pasdpw1iuGjDBLSb7QEq WR1h9Pf7TEHstflb4rCw3AL/pHYsvHaJk3+Wix0BiMjFDFiDtGAXiiFqXBQP58sUXEwC DuzdZFc5zlgLbf1eDl66HrhkNMbWNE4I0TCEqmMQL9IKIGv8/xj3/J94+c88tnL15yrz EoJQ== X-Gm-Message-State: AO0yUKWKGIg/0QBzI23DKogHK+obAnPY6KoM5k5BpLrP16dJWt8sdCu7 K/asTqUnAbOJK8aM6h8STnP2sw== X-Received: by 2002:a05:600c:746:b0:3ea:e554:77fe with SMTP id j6-20020a05600c074600b003eae55477femr8390053wmn.12.1677784460910; Thu, 02 Mar 2023 11:14:20 -0800 (PST) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id o13-20020a5d670d000000b002c8476dde7asm120991wru.114.2023.03.02.11.14.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 11:14:20 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3E8B91FFBE; Thu, 2 Mar 2023 19:08:50 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Weiwei Li , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Palmer Dabbelt , Laurent Vivier , nicolas.eder@lauterbach.com, Ilya Leoshkevich , kvm@vger.kernel.org, "Edgar E. Iglesias" , David Gibson , Max Filippov , Sunil Muthuswamy , qemu-s390x@nongnu.org, Stafford Horne , Bin Meng , Marek Vasut , Greg Kurz , Song Gao , Aleksandar Rikalo , Liu Zhiwei , Alistair Francis , Chris Wulff , qemu-riscv@nongnu.org, Michael Rolnik , qemu-arm@nongnu.org, Cleber Rosa , Artyom Tarasenko , Marcel Apfelbaum , Eduardo Habkost , Yoshinori Sato , Alexandre Iooss , Daniel Henrique Barboza , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , mads@ynddal.dk, Mark Cave-Ayland , qemu-ppc@nongnu.org, Richard Henderson , John Snow , Xiaojuan Yang , Thomas Huth , Paolo Bonzini , Mahmoud Mandour , Aurelien Jarno , Bastian Koppelmann , Yanan Wang , David Hildenbrand , Taylor Simpson , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v4 23/26] testing: probe gdb for supported architectures ahead of time Date: Thu, 2 Mar 2023 19:08:43 +0000 Message-Id: <20230302190846.2593720-24-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302190846.2593720-1-alex.bennee@linaro.org> References: <20230302190846.2593720-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.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 Cc: Richard Henderson Cc: Paolo Bonzini Reviewed-by: Richard Henderson --- 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 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 +# +# 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