From patchwork Thu Oct 24 09:56:01 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: 838096 Delivered-To: patch@linaro.org Received: by 2002:adf:a399:0:b0:37d:45d0:187 with SMTP id l25csp270387wrb; Thu, 24 Oct 2024 02:57:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWQejp7yDD0aVnw/zvltdyRgFe4zTWyxGdNumTjC1k8x4K22MVbhVWkyob5+aFZmNm9+o4vRA==@linaro.org X-Google-Smtp-Source: AGHT+IHYUt1aP75GZsiDfdjWvnTK9nzBHIcuz6reGzzd4LX4L6vT33H5QCFpC5augSBGcKRC4cx+ X-Received: by 2002:a05:6214:4489:b0:6cb:4b70:8ead with SMTP id 6a1803df08f44-6ce342864famr72060246d6.37.1729763858121; Thu, 24 Oct 2024 02:57:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729763858; cv=none; d=google.com; s=arc-20240605; b=Ohx2Vv0I9ieQJHMg5E0wr98BE7kM4flrONwyFnoLkh3mev5t3a7p28xit2pSyWokev cgh6+azfF0OQXApvQssAj6L1I4k7MhdMvR0dsz8p3LdK/3WX8lK0+JwkqsfHFN7EYGjO xOP1KmfJLBSZQ+Yk35cfbbYjVoEMyK5706FCy32ZmFQKdrGsnFGP5lrr1qjziE7wBVpS mB3uh0NkyrTJY7a63J9T/LUhuq0UemlMElinddho0ksfiBooZtda4AXXYQqJWlR7SW0s smaxDgNipoVMZWRK63G9bLZQKELK/EG8Vi2lGPyaoubxw+tfySXoVNhBinyu/WaVrGzq agPg== 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=QHD6OSG9G96Lp9DOw44GLfWhawl8Jnq29lPwNBLaOd0=; fh=CDBl/6iM7fhPEx1p3IyqBgapH7VgH6DZlFWbR6y7avg=; b=hWGd6qcPVRDsstE2k1WIJNf6AHHsRUibsGamEzP75q2Tl35uZ77Y0m8s+iQrvpt68M 6S532U3o6/+ZXT8Zq9fnr+PXSoAExy1cf3o3XqKZjmrBZKAnrFgPg+BlXuYjrw1SwLKW 3MmhIEem9GxIVP8ISc3wb8955CrwuDB6bul7Vvjl9YOKfTihZXvvBvwhpWFpLmcDMyG+ DC2qPmYH1i/Ajjt+2tcj5rBrXVNnq+8OXpB77wviThEEqFt0v0mjWvujOanvpDbfYmfR jFv2Sr3xf6xVnbZhBBbg/ZLzuvlm62Dnwt7l/hDMXeERHEinjiarg7jOUhYXJmV7RxqC DciQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MQZ55JRv; 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 6a1803df08f44-6ce00899531si10526396d6.11.2024.10.24.02.57.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Oct 2024 02:57:38 -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=MQZ55JRv; 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 1t3ua2-0001ED-Oh; Thu, 24 Oct 2024 05:56:34 -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 1t3uZn-00019h-3h for qemu-devel@nongnu.org; Thu, 24 Oct 2024 05:56:19 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3uZk-0003os-ED for qemu-devel@nongnu.org; Thu, 24 Oct 2024 05:56:18 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a9a0ec0a94fso89118466b.1 for ; Thu, 24 Oct 2024 02:56:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729763775; x=1730368575; 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=QHD6OSG9G96Lp9DOw44GLfWhawl8Jnq29lPwNBLaOd0=; b=MQZ55JRv9Ay9zhaQVyQeHfLFEoxDVNeLkSId7qSgmu5vYGKfERxlMo4lZrSWOvNTZX xz2O17oz58msUE0CwFzxJSm1O3ghK1ntNNeBnupT7jPqbWHYOQrvSWutof5cTRBY51Ww rwsh18C+mcLzBIsw+4KO9uwPtCvY616RxiiTSufQAJKcy3cbu1b2alnaznJ/+uiFC8xS OtI8Tc5Yquf0eFExchKDOT38ruzg7bkQOBfLKMiYgcTkRAz151OyDzAi2UhHtWCc2F6M NAfwAUoSIwx9SIaheOvJO3KEwwnCFWESPpUDr+lyNgYufKdhrtUdYIQ0UruUEg7qDNtk I4Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729763775; x=1730368575; 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=QHD6OSG9G96Lp9DOw44GLfWhawl8Jnq29lPwNBLaOd0=; b=wcZmAOMyuTLayo27AHey/6qvFcTmMuYP/1DQR9HiBpDeqjonU3JfUDn7IKQvcD4i+p i2W91gJlnLwlwXUzoCuuyc+dRvezhkbU5sXbxluVA+PkcPs4qTwm8nKbuXxZCWGsPdIN p6iuA7RsbUNeSXqol/5tR87ZotC3wrGTpMbbRfeLoSSvo3HrSU4EynFuo2eflUYfj8OA fqTtlnQ12RfiKJ+UfPM1rKyiY6d7HJI5wztO0IGI3OzLkYQs89KlPrePerjWggHd7GFW xeVR3Vdz8T/RqFKENZ1w0PD2gL8zo5RW04cyYlFAxewiFzw1p6Bx4ZJtvM0UiWToZqhe 7ljQ== X-Gm-Message-State: AOJu0YzMcMpTebnHc8UzCI8SMN1PVYRxVzrUARm4gTiPRIMTOUJWB2hk ntDQouNsFi+4A5ntzJ0Q/Xq4KmOe+8j3HscVcnBHymR2FBgpWhUyClrhqZ8xwEI= X-Received: by 2002:a17:907:1c19:b0:a9a:8a4:e090 with SMTP id a640c23a62f3a-a9ad2813d7cmr134421466b.50.1729763774960; Thu, 24 Oct 2024 02:56:14 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a91370e04sm590077066b.108.2024.10.24.02.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:56:12 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 50D515FC0F; Thu, 24 Oct 2024 10:56:05 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gustavo Romero , Pierrick Bouvier , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , John Snow , Cleber Rosa Subject: [PULL 15/17] testing: Enhance gdb probe script Date: Thu, 24 Oct 2024 10:56:01 +0100 Message-Id: <20241024095603.1813285-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241024095603.1813285-1-alex.bennee@linaro.org> References: <20241024095603.1813285-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62a.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=ham 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 Reviewed-by: Pierrick Bouvier Message-Id: <20241015145848.387281-1-gustavo.romero@linaro.org> Signed-off-by: Alex Bennée Message-Id: <20241023113406.1284676-16-alex.bennee@linaro.org> 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')