From nobody Sat Nov 23 22:22:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1729683911531874.428999148344; Wed, 23 Oct 2024 04:45:11 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 726FC1A69; Wed, 23 Oct 2024 07:45:10 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 53BB519F9; Wed, 23 Oct 2024 07:44:13 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id F300FC85; Wed, 23 Oct 2024 07:44:06 -0400 (EDT) Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 269E2148D for ; Wed, 23 Oct 2024 07:44:06 -0400 (EDT) Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-539f7606199so7479650e87.0 for ; Wed, 23 Oct 2024 04:44:06 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a91370e54sm462834566b.102.2024.10.23.04.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 04:44:03 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 6AE8B5FC0F; Wed, 23 Oct 2024 12:34:08 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729683845; x=1730288645; darn=lists.libvirt.org; 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=goM9TWkvUJk023ZZ8+wq0WOvMkki4+LOppFI2tLZ0P4=; b=CF69McBabetsliR7Ch6gT0VcUj2QIH/15KWKAQX3hDzhtNpmpI0nLTysbTDkuE3O1z 4b7kNeZdFAXl+S+fOJzJrYJ7WaVu9UaGw0bcdbxKpSRn43kyZ4aSYvrhZ2EQGcE4gXKa +RRM8/FRD7sQqJvGPAEZSlxBmmgvX/YtVWVGXkWr59H+fBVZT8RuNyl1RgewT7OjqOt/ fNZkxJL37Wy0cPL2KqEY5slWVJsEq+4EDlS7xk48RjcVfbtRPnPWeoeQjSbOJ6KybWrv QoqPDGS9kSLSfMIqZUzJM4CmfL6X/KclopVbkLut1As6gRZWgTqMucEamXuYnpQxCcw1 M+QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729683845; x=1730288645; 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=goM9TWkvUJk023ZZ8+wq0WOvMkki4+LOppFI2tLZ0P4=; b=sc4ytu1gFvKfkTQpWMnhpTdBTeX5doC8uJa5fCEyLZ0Z2j/opnMNODhgyJ2sRT28ag EnbX4Bpk/wG3Axo1dVZ8FVHLLB2WyxcrccLeyxYSzn/R/YBXrAwHTVNiZ4ziHNWvt1Oi GWqWdToGm9pGyNtXJmXrUajnTYZKjUQyuPsrL18UyBC8Ohs3I1uQDjq/Aa0op/uGZp5K Z1peby7pHKDDaW3x13GmNQGBu2Nv4Zk+YvJ/nrPvpRJ4/F32BmNrNJnNr/SQL8o0XDq5 sPNbCJNZrUj2H5yabxSlCpGjr2WyPC5PsuBT2+xgcZhGZNeqb0/J8MSbztCeK/MRsmO9 LcOA== X-Forwarded-Encrypted: i=1; AJvYcCWrbeIPEQ0R8jNX5iOBGBQc/LBBPFkaOUTIkrx7TrseatWHiFntn02EafbWl4pZL7sdHfo0hg==@lists.libvirt.org X-Gm-Message-State: AOJu0Yz6Y2xknnbQThQc9UpH+tJa2oiIsp3+ha+nusRiceZKMBRtT+Ct o+ozoDNiB8wcO0bbhLIdamlC90vx4VnbDJ/lEj289KCxawhPXioWk+boGj73tFM= X-Google-Smtp-Source: AGHT+IHDtHU0ccJr5rc5xz8My9arnYk+SlnudjoCir3kQRdzjKiDoRSU1ko8s5OGs4YQqLHIEVXPxQ== X-Received: by 2002:a05:6512:398a:b0:539:f2f6:c70f with SMTP id 2adb3069b0e04-53b1a2fed80mr1092099e87.8.1729683844676; Wed, 23 Oct 2024 04:44:04 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v3 15/18] testing: Enhance gdb probe script Date: Wed, 23 Oct 2024 12:34:03 +0100 Message-Id: <20241023113406.1284676-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023113406.1284676-1-alex.bennee@linaro.org> References: <20241023113406.1284676-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 7OKF7XJZEOS5RP5HQEMUXAUA4UJSH2UW X-Message-ID-Hash: 7OKF7XJZEOS5RP5HQEMUXAUA4UJSH2UW X-MailFrom: alex.bennee@linaro.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: Zhao Liu , Eduardo Habkost , Pierrick Bouvier , Peter Maydell , Yanan Wang , John Snow , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , devel@lists.libvirt.org, Marcelo Tosatti , Riku Voipio , Wainer dos Santos Moschetta , Marcel Apfelbaum , Paolo Bonzini , Mahmoud Mandour , Laurent Vivier , Jiaxun Yang , "Edgar E. Iglesias" , Richard Henderson , Alexandre Iooss , qemu-arm@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Cleber Rosa , kvm@vger.kernel.org, Beraldo Leal , Thomas Huth , =?UTF-8?q?Al ex=20Benn=C3=A9e?= , Gustavo Romero X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1729683913238116600 Content-Type: text/plain; charset="utf-8" From: Gustavo Romero Use list and set comprehension to simplify code. Also, gently handle invalid gdb filenames. Signed-off-by: Gustavo Romero Reviewed-by: Pierrick Bouvier Message-Id: <20241022105614.839199-16-alex.bennee@linaro.org> Message-Id: <20241015145848.387281-1-gustavo.romero@linaro.org> Signed-off-by: Alex Benn=C3=A9e --- scripts/probe-gdb-support.py | 75 +++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/scripts/probe-gdb-support.py b/scripts/probe-gdb-support.py index 6dc58d06c7..6bcadce150 100644 --- a/scripts/probe-gdb-support.py +++ b/scripts/probe-gdb-support.py @@ -19,58 +19,61 @@ =20 import argparse import re -from subprocess import check_output, STDOUT +from subprocess import check_output, STDOUT, CalledProcessError +import sys =20 -# mappings from gdb arch to QEMU target -mappings =3D { - "alpha" : "alpha", +# Mappings from gdb arch to QEMU target +MAP =3D { + "alpha" : ["alpha"], "aarch64" : ["aarch64", "aarch64_be"], - "armv7": "arm", + "armv7": ["arm"], "armv8-a" : ["aarch64", "aarch64_be"], - "avr" : "avr", + "avr" : ["avr"], # no hexagon in upstream gdb - "hppa1.0" : "hppa", - "i386" : "i386", - "i386:x86-64" : "x86_64", - "Loongarch64" : "loongarch64", - "m68k" : "m68k", - "MicroBlaze" : "microblaze", + "hppa1.0" : ["hppa"], + "i386" : ["i386"], + "i386:x86-64" : ["x86_64"], + "Loongarch64" : ["loongarch64"], + "m68k" : ["m68k"], + "MicroBlaze" : ["microblaze"], "mips:isa64" : ["mips64", "mips64el"], - "or1k" : "or1k", - "powerpc:common" : "ppc", + "or1k" : ["or1k"], + "powerpc:common" : ["ppc"], "powerpc:common64" : ["ppc64", "ppc64le"], - "riscv:rv32" : "riscv32", - "riscv:rv64" : "riscv64", - "s390:64-bit" : "s390x", + "riscv:rv32" : ["riscv32"], + "riscv:rv64" : ["riscv64"], + "s390:64-bit" : ["s390x"], "sh4" : ["sh4", "sh4eb"], - "sparc": "sparc", - "sparc:v8plus": "sparc32plus", - "sparc:v9a" : "sparc64", + "sparc": ["sparc"], + "sparc:v8plus": ["sparc32plus"], + "sparc:v9a" : ["sparc64"], # no tricore in upstream gdb "xtensa" : ["xtensa", "xtensaeb"] } =20 + def do_probe(gdb): - gdb_out =3D check_output([gdb, - "-ex", "set architecture", - "-ex", "quit"], stderr=3DSTDOUT) + try: + gdb_out =3D check_output([gdb, + "-ex", "set architecture", + "-ex", "quit"], stderr=3DSTDOUT, encoding= =3D"utf-8") + except (OSError) as e: + sys.exit(e) + except CalledProcessError as e: + sys.exit(f'{e}. Output:\n\n{e.output}') + + found_gdb_archs =3D re.search(r'Valid arguments are (.*)', gdb_out) =20 - m =3D re.search(r"Valid arguments are (.*)", - gdb_out.decode("utf-8")) + targets =3D set() + if found_gdb_archs: + gdb_archs =3D found_gdb_archs.group(1).split(", ") + mapped_gdb_archs =3D [arch for arch in gdb_archs if arch in MAP] =20 - valid_arches =3D set() + targets =3D {target for arch in mapped_gdb_archs for target in MAP= [arch]} =20 - if m.group(1): - for arch in m.group(1).split(", "): - if arch in mappings: - mapping =3D mappings[arch] - if isinstance(mapping, str): - valid_arches.add(mapping) - else: - for entry in mapping: - valid_arches.add(entry) + # QEMU targets + return targets =20 - return valid_arches =20 def main() -> None: parser =3D argparse.ArgumentParser(description=3D'Probe GDB Architectu= res') --=20 2.39.5