From patchwork Tue Oct 22 10:56:09 2024 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: 837545 Delivered-To: patch@linaro.org Received: by 2002:a5d:50c9:0:b0:37d:45d0:187 with SMTP id f9csp2475805wrt; Tue, 22 Oct 2024 03:59:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWIuKW2Ud+YJJlb6unTqKmC39j9F1wXCVxBXGrBNwbzr1uEJUurp1AefTomaOLMY815XId9tg==@linaro.org X-Google-Smtp-Source: AGHT+IGOgc9S3Adi8nY2HCv1Zrmuxrep6iaYrI9pAKBS51AVAOduHmXCB57/nLbuvPHdPvciqaJ0 X-Received: by 2002:a05:6102:54a9:b0:4a3:a137:ba7 with SMTP id ada2fe7eead31-4a742d3424bmr2547592137.9.1729594742168; Tue, 22 Oct 2024 03:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729594742; cv=none; d=google.com; s=arc-20240605; b=DTcPZSoxGJAq0mn8OP1RMbIn6lxmAqc2GmEa1v2ijqjarhtgQUonTWCBDSfZ5HNvhd zSov1PzzwZgyZ1DTybQaWeLAowcdsqfvaD31QceT56P4kI6ucNHNaIzuvOYv0J9L/1j0 PZC7Bfz0xYq6u5S9BOFbTPMUi2jMqAHvp/ACH/qYdcm9nDRJV/CbjtJhWsAlsoli1RRQ Jsk7aBHItAWeonBvQ2udLJwWtjrVn8e7GJTOLiJhg1s0xGZb3TRGGAyCWVMM08VHHLiG w6NFstkRevgCXCKR0Tj318cX/JZ+fQmOi6DH5/d5aKqXNx4KjAi3vC0ENfaFxDU8q9dX Mptw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=rLOsiFp7nSYSKf/se2Emh5FqkyaR/LV5KofnrCQ0C68=; fh=TliP8gu8zXfyTr07vi8XCJx2pv3j20R8WlOer8ddxq4=; b=G2qTMYhkk4sOsZu09E6lke+9O0l9pPni5H9K1FiXYyWnnafIHPUuOi2ek+wrIWPtKR u397tMjl+Pi6nHnvG0cp59gECGvzXWebU0euCvtlJxTDq0GG0NOFJtV1eOErStPGM/Aw jqjn8V8b58ZOHuIzuES9rOZ2wavPo1E4Fael3so1HdPGVoHOBEXgqoE6htqgpHgMJGg1 COBA1ri1xMB2spWbuJQfp1vBZgui3mYpqM24VUhz5n4kK8pT5WYk1E2n3V5Iti5ZjcSS UlimzDVkyiZBPxSjTW7MCc3Jq4olkqKbmLYJynboL5IAyjTZOyV3BzqErxdwB2k4ylCn dC6g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UbY5ohl8; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7b165a87c23si622563685a.452.2024.10.22.03.59.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Oct 2024 03:59:02 -0700 (PDT) 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=UbY5ohl8; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3CZg-0002TH-Nq; Tue, 22 Oct 2024 06:57:16 -0400 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 1t3CZ1-0001oz-0Q for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:56:36 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3CYx-00024L-Se for qemu-devel@nongnu.org; Tue, 22 Oct 2024 06:56:33 -0400 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a9a3dc089d8so763055166b.3 for ; Tue, 22 Oct 2024 03:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729594590; x=1730199390; darn=nongnu.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=rLOsiFp7nSYSKf/se2Emh5FqkyaR/LV5KofnrCQ0C68=; b=UbY5ohl8Tq3r6oyeREt35aX2B3LpoO/9UggZwAPQVIcx1mMQckDgp4HNoZmC9xGfOn eOiOb54x611JeEjN997BoalrBOLowFARFUNxjmxZrbXDAi+IgeTukrCyOD87I+Kj2X5A U4dDLqp5g6z+febzw4/PVaOyNCJscVowrIsAl441cwfsNt8dSPNXY+uMvTQLpgtBrvBA Ic5sMugk1D/Ivtba6AijAZ+My95pO/5j4+l4oMofFH5zJnHs3gJKJE0rSpDbjeaYGys/ dDnES4VgEX+IXe70yLxcVVnzFaEVt7pZsWrYUatpxQOUoqJCTZvAeN4JtnNX21IjvqWI /mZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729594590; x=1730199390; 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=rLOsiFp7nSYSKf/se2Emh5FqkyaR/LV5KofnrCQ0C68=; b=BxMENMefWvgZoTlflj4yznQD9PP5TtTmyD88RpeBZMxHpCIq9YfiBYjZez6mNdTzyE qNCmo1gjHg3CKTkkCf5CGNVaWFG0ZN9tVqmPGs0bMZTpkCSWfgcMNvcKDzZI+iiZOGYw 691wUBqo7DFhc5L7Z1IdDIjLDfcbgDFxVxTXz5XdYqL3LmhMwXRM4+855R49vbM13QpK g8BeUMPySjtK41rTFkL4xRXGlI/mjhh7Yj5jZu8ArzUePALTLQ1HsjgUN3z/rNzAjAeB eKh6rmq3rIhgISqLJZXz+EkBc0xOMkDLKJb9BT3CErg1xVM1tQ9GcW00BlB+MwZb0aIS DtTQ== X-Gm-Message-State: AOJu0YyxuZWGr10MT55RjYm6x4eJIykFCSqEY2qJWssC3H1qRh4yvoF1 UkSUsl4qk1REv9QJdGUZVs34+ODCRL8ULA+n40xVYp/JelBWkUCXTLP9QOkNZAY= X-Received: by 2002:a17:907:3182:b0:a9a:a7fd:d840 with SMTP id a640c23a62f3a-a9aa7fdd87bmr350993366b.1.1729594590177; Tue, 22 Oct 2024 03:56:30 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912d6355sm324467166b.37.2024.10.22.03.56.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 03:56:28 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id ECA855FC11; Tue, 22 Oct 2024 11:56:15 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Beraldo Leal , Laurent Vivier , Wainer dos Santos Moschetta , Mahmoud Mandour , Jiaxun Yang , =?utf-8?q?Alex_Benn=C3=A9e?= , Yanan Wang , Thomas Huth , John Snow , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-arm@nongnu.org, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , devel@lists.libvirt.org, Cleber Rosa , kvm@vger.kernel.org, =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= , Alexandre Iooss , Peter Maydell , Richard Henderson , Riku Voipio , Zhao Liu , Marcelo Tosatti , "Edgar E. Iglesias" , Marcel Apfelbaum , Pierrick Bouvier , Paolo Bonzini , Gustavo Romero Subject: [PATCH v2 15/20] testing: Enhance gdb probe script Date: Tue, 22 Oct 2024 11:56:09 +0100 Message-Id: <20241022105614.839199-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241022105614.839199-1-alex.bennee@linaro.org> References: <20241022105614.839199-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62c.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 From: Gustavo Romero Use list and set comprehension to simplify code. Also, gently handle invalid gdb filenames. Signed-off-by: Gustavo Romero Message-Id: <20241015145848.387281-1-gustavo.romero@linaro.org> Signed-off-by: Alex Bennée Reviewed-by: Pierrick Bouvier --- 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 @@ import argparse import re -from subprocess import check_output, STDOUT +from subprocess import check_output, STDOUT, CalledProcessError +import sys -# mappings from gdb arch to QEMU target -mappings = { - "alpha" : "alpha", +# Mappings from gdb arch to QEMU target +MAP = { + "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"] } + def do_probe(gdb): - gdb_out = check_output([gdb, - "-ex", "set architecture", - "-ex", "quit"], stderr=STDOUT) + try: + gdb_out = check_output([gdb, + "-ex", "set architecture", + "-ex", "quit"], stderr=STDOUT, encoding="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 = re.search(r'Valid arguments are (.*)', gdb_out) - m = re.search(r"Valid arguments are (.*)", - gdb_out.decode("utf-8")) + targets = set() + if found_gdb_archs: + gdb_archs = found_gdb_archs.group(1).split(", ") + mapped_gdb_archs = [arch for arch in gdb_archs if arch in MAP] - valid_arches = set() + targets = {target for arch in mapped_gdb_archs for target in MAP[arch]} - 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) + # QEMU targets + return targets - return valid_arches def main() -> None: parser = argparse.ArgumentParser(description='Probe GDB Architectures')