mirror of https://github.com/xemu-project/xemu.git
testing: Enhance gdb probe script
Use list and set comprehension to simplify code. Also, gently handle invalid gdb filenames. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Message-Id: <20241015145848.387281-1-gustavo.romero@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20241023113406.1284676-16-alex.bennee@linaro.org>
This commit is contained in:
parent
bb77c68dbd
commit
345dedbad2
|
@ -19,58 +19,61 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
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 from gdb arch to QEMU target
|
||||||
mappings = {
|
MAP = {
|
||||||
"alpha" : "alpha",
|
"alpha" : ["alpha"],
|
||||||
"aarch64" : ["aarch64", "aarch64_be"],
|
"aarch64" : ["aarch64", "aarch64_be"],
|
||||||
"armv7": "arm",
|
"armv7": ["arm"],
|
||||||
"armv8-a" : ["aarch64", "aarch64_be"],
|
"armv8-a" : ["aarch64", "aarch64_be"],
|
||||||
"avr" : "avr",
|
"avr" : ["avr"],
|
||||||
# no hexagon in upstream gdb
|
# no hexagon in upstream gdb
|
||||||
"hppa1.0" : "hppa",
|
"hppa1.0" : ["hppa"],
|
||||||
"i386" : "i386",
|
"i386" : ["i386"],
|
||||||
"i386:x86-64" : "x86_64",
|
"i386:x86-64" : ["x86_64"],
|
||||||
"Loongarch64" : "loongarch64",
|
"Loongarch64" : ["loongarch64"],
|
||||||
"m68k" : "m68k",
|
"m68k" : ["m68k"],
|
||||||
"MicroBlaze" : "microblaze",
|
"MicroBlaze" : ["microblaze"],
|
||||||
"mips:isa64" : ["mips64", "mips64el"],
|
"mips:isa64" : ["mips64", "mips64el"],
|
||||||
"or1k" : "or1k",
|
"or1k" : ["or1k"],
|
||||||
"powerpc:common" : "ppc",
|
"powerpc:common" : ["ppc"],
|
||||||
"powerpc:common64" : ["ppc64", "ppc64le"],
|
"powerpc:common64" : ["ppc64", "ppc64le"],
|
||||||
"riscv:rv32" : "riscv32",
|
"riscv:rv32" : ["riscv32"],
|
||||||
"riscv:rv64" : "riscv64",
|
"riscv:rv64" : ["riscv64"],
|
||||||
"s390:64-bit" : "s390x",
|
"s390:64-bit" : ["s390x"],
|
||||||
"sh4" : ["sh4", "sh4eb"],
|
"sh4" : ["sh4", "sh4eb"],
|
||||||
"sparc": "sparc",
|
"sparc": ["sparc"],
|
||||||
"sparc:v8plus": "sparc32plus",
|
"sparc:v8plus": ["sparc32plus"],
|
||||||
"sparc:v9a" : "sparc64",
|
"sparc:v9a" : ["sparc64"],
|
||||||
# no tricore in upstream gdb
|
# no tricore in upstream gdb
|
||||||
"xtensa" : ["xtensa", "xtensaeb"]
|
"xtensa" : ["xtensa", "xtensaeb"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def do_probe(gdb):
|
def do_probe(gdb):
|
||||||
gdb_out = check_output([gdb,
|
try:
|
||||||
"-ex", "set architecture",
|
gdb_out = check_output([gdb,
|
||||||
"-ex", "quit"], stderr=STDOUT)
|
"-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}')
|
||||||
|
|
||||||
m = re.search(r"Valid arguments are (.*)",
|
found_gdb_archs = re.search(r'Valid arguments are (.*)', gdb_out)
|
||||||
gdb_out.decode("utf-8"))
|
|
||||||
|
|
||||||
valid_arches = set()
|
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]
|
||||||
|
|
||||||
if m.group(1):
|
targets = {target for arch in mapped_gdb_archs for target in MAP[arch]}
|
||||||
for arch in m.group(1).split(", "):
|
|
||||||
if arch in mappings:
|
# QEMU targets
|
||||||
mapping = mappings[arch]
|
return targets
|
||||||
if isinstance(mapping, str):
|
|
||||||
valid_arches.add(mapping)
|
|
||||||
else:
|
|
||||||
for entry in mapping:
|
|
||||||
valid_arches.add(entry)
|
|
||||||
|
|
||||||
return valid_arches
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
parser = argparse.ArgumentParser(description='Probe GDB Architectures')
|
parser = argparse.ArgumentParser(description='Probe GDB Architectures')
|
||||||
|
|
Loading…
Reference in New Issue