From patchwork Tue Oct 15 14:58:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 835443 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c8f:0:b0:37d:45d0:187 with SMTP id z15csp279382wrs; Tue, 15 Oct 2024 07:59:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV6mn1F4LctQt1q7UTcitnu55WbGKwUTTrzkyhVucdn0OclsgnSIsDxVie7eum0IOTNCDsIEw==@linaro.org X-Google-Smtp-Source: AGHT+IFiLh8TbK2P/I3W3EF5jjxoZ4dMQmnHfeARFR0ZPEFX+0NPiTF0L85Am83QxbFlfxpgBWje X-Received: by 2002:a05:6902:110e:b0:e28:6d13:d179 with SMTP id 3f1490d57ef6-e29782ccdf9mr634523276.9.1729004349151; Tue, 15 Oct 2024 07:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729004349; cv=none; d=google.com; s=arc-20240605; b=COpyAwFCmTzO3iozwfy0AIfHk/YegdXKtvws8+N3rptViagMU/zHNJZFvuiwT+Acr+ MC5hJxWLz3DWwxm7RaxirHyvtgxgfbz+3KkGE3VwgU6lc3XkfN0xJSMxTLIL63l+/56y CSxeR+k3TNjLyXn5tV3sT4LWGuGgV3jbUVFy5zvqudgEemHQcxW73ZWZyiBjPc0ULI4D nGP2tsgnT7usbWG5HhRaFIfeplRM3OYMPB+/5a6epVcFfGEJiHUu73cyMAE/5oPwkY8o eRuqCMl/H6wB25fN5dMzFWUviztuzMByzxPi1GFYh1ZCpyM1Nf19/q0ZFFZZ5iStNmM+ EWnQ== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=xr9VcP67btkW9fdHquP6IjRtytSNpngBeXikWdUm1Z4=; fh=aHUcMQwGKWxmSC28MS2dH7RD7RklTPgDdySuvuaHWHc=; b=FtLJ7moPnENWVNsCSn/7O+xSd8/yXJUkVciz5JDRML9N7kA8tSHdYl2V6P90f7dzxr lWJcO0Ip/E7Wyn4CiGk8rBP93zOg5qxZVT2ZWx3nGJQcD7mBGKHJBZVKH29m1iscTh3H Hzqdj5vho0xO4Dd6t1h6/Bz88/bB7hzXjL8WAOcsJy2D5WvLloa/fsw7HmaFsK9RtZAa NA3Wo79GDVPf0Zh03tNflBZ8GKOzkSZgs/IwKCxuy/zN2Cv0jD13NU3pZjPCTSMGBN1j 5W8dXyEyDRZxtRns4xbjiHh7MeuOgoZDyLnAGU9IB99sfFJKGpdMe2tEAGqczjWeAqpy sMeQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q00wRtYu; 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 d75a77b69052e-4607b0fa035si16580681cf.10.2024.10.15.07.59.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Oct 2024 07:59:09 -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=q00wRtYu; 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 1t0j0o-0001NF-1l; Tue, 15 Oct 2024 10:59:02 -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 1t0j0m-0001Md-SS for qemu-devel@nongnu.org; Tue, 15 Oct 2024 10:59:00 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t0j0l-00008r-7q for qemu-devel@nongnu.org; Tue, 15 Oct 2024 10:59:00 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-20cb89a4e4cso24265975ad.3 for ; Tue, 15 Oct 2024 07:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729004337; x=1729609137; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xr9VcP67btkW9fdHquP6IjRtytSNpngBeXikWdUm1Z4=; b=q00wRtYuDHqZ0lluR0hZuFI/3LHXSmz8vASJdxwfym0s08MkLJLGACOLe6Mr83BMz8 S3y353GiWJywbUkCV0p/fBWp0wmpdGAC9zv+eb62ZvKuIvMWWugPCC17joPgyisGHajR qvwIvaHV4TuyVOtYg2a6JyEqyx/MBHyO3T5nAAwf3/0qxnUEUHYsxPr2173bI3ATSgsX QCGEOC45zwOE9pJq9KKwlBX9vGmQYKcKhPvFCeB72IifSlnTGmMfUeCzd3oWZ4R7zK5M AKaBTs3z3ejohY/AgiVKzi5eu8KJ9quhe+8Up3hOiucTcFP7nZ1N6MzJdKpQCcRH/78B E2EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729004337; x=1729609137; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xr9VcP67btkW9fdHquP6IjRtytSNpngBeXikWdUm1Z4=; b=khU3NHdUGxbsQBCwQZpi9WU3vc1MsBo6LylYHoan7ZXThPl090eXmayFtMPaVs94GI jNJmy7hutOjauhjGvXxc8P6T7yPJCtK9FFjUBCbZ7zwR2B/tfv12AFfl1TSVxnu+dLJe q4uwNyUShvi/nap3tBfKkwi5HBf+iiIu0t80qJ3sce3MybNgHoqDE6pO1H9eBVNc8JJp 15NTciqyfnwaqme+kC/4Zz1FHQH5/kB5X8wovPhpfP57jz6GY4ac5zEs8f+JGGW/SEpF BdPTXknai+Ti5n+TDNHMOue1gsyDHl8b08NGJvMBnKQwsfR8L43JWCXGePQVrwZvAtSd g23Q== X-Gm-Message-State: AOJu0Yzrw8z/M1/Cwv013fuwhS4Zf3TwI3CeikNcCnJ+HefUYd6eautD x3zUE0Yd162WETGde9n/yXXgVPSntCY6j5R3idxVtR83KaKb3OzwkeaZG22TbiknJUc337oWAs5 ic78= X-Received: by 2002:a17:902:d2cc:b0:20c:dbff:b9d8 with SMTP id d9443c01a7336-20d27f0db37mr5201085ad.37.1729004337358; Tue, 15 Oct 2024 07:58:57 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:3301:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20d17f84dbdsm13021505ad.55.2024.10.15.07.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 07:58:57 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org Cc: gustavo.romero@linaro.org, alex.bennee@linaro.org Subject: [PATCH] testing: Enhance gdb probe script Date: Tue, 15 Oct 2024 14:58:48 +0000 Message-Id: <20241015145848.387281-1-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=gustavo.romero@linaro.org; helo=mail-pl1-x631.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 Use list and set comprehension to simplify code. Also, gently handle invalid gdb filenames. Signed-off-by: Gustavo Romero --- 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')