qapi: allow unions to contain further unions
[qemu/armbru.git] / scripts / probe-gdb-support.py
blob575525596629230a30141c4ae30758a6f1bb1d8a
1 #!/usr/bin/env python3
2 # coding: utf-8
4 # Probe gdb for supported architectures.
6 # This is required to support testing of the gdbstub as its hard to
7 # handle errors gracefully during the test. Instead this script when
8 # passed a GDB binary will probe its architecture support and return a
9 # string of supported arches, stripped of guff.
11 # Copyright 2023 Linaro Ltd
13 # Author: Alex Bennée <alex.bennee@linaro.org>
15 # This work is licensed under the terms of the GNU GPL, version 2 or later.
16 # See the COPYING file in the top-level directory.
18 # SPDX-License-Identifier: GPL-2.0-or-later
20 import argparse
21 import re
22 from subprocess import check_output, STDOUT
24 # mappings from gdb arch to QEMU target
25 mappings = {
26 "alpha" : "alpha",
27 "aarch64" : ["aarch64", "aarch64_be"],
28 "armv7": "arm",
29 "armv8-a" : ["aarch64", "aarch64_be"],
30 "avr" : "avr",
31 "cris" : "cris",
32 # no hexagon in upstream gdb
33 "hppa1.0" : "hppa",
34 "i386" : "i386",
35 "i386:x86-64" : "x86_64",
36 "Loongarch64" : "loongarch64",
37 "m68k" : "m68k",
38 "MicroBlaze" : "microblaze",
39 "mips:isa64" : ["mips64", "mips64el"],
40 "nios2" : "nios2",
41 "or1k" : "or1k",
42 "powerpc:common" : "ppc",
43 "powerpc:common64" : ["ppc64", "ppc64le"],
44 "riscv:rv32" : "riscv32",
45 "riscv:rv64" : "riscv64",
46 "s390:64-bit" : "s390x",
47 "sh4" : ["sh4", "sh4eb"],
48 "sparc": "sparc",
49 "sparc:v8plus": "sparc32plus",
50 "sparc:v9a" : "sparc64",
51 # no tricore in upstream gdb
52 "xtensa" : ["xtensa", "xtensaeb"]
55 def do_probe(gdb):
56 gdb_out = check_output([gdb,
57 "-ex", "set architecture",
58 "-ex", "quit"], stderr=STDOUT)
60 m = re.search(r"Valid arguments are (.*)",
61 gdb_out.decode("utf-8"))
63 valid_arches = set()
65 if m.group(1):
66 for arch in m.group(1).split(", "):
67 if arch in mappings:
68 mapping = mappings[arch]
69 if isinstance(mapping, str):
70 valid_arches.add(mapping)
71 else:
72 for entry in mapping:
73 valid_arches.add(entry)
75 return valid_arches
77 def main() -> None:
78 parser = argparse.ArgumentParser(description='Probe GDB Architectures')
79 parser.add_argument('gdb', help='Path to GDB binary.')
81 args = parser.parse_args()
83 supported = do_probe(args.gdb)
85 print(" ".join(supported))
87 if __name__ == '__main__':
88 main()