Add `./sym_info.py --build-dir` to print symbols from an arbitrary build/ folder

This commit is contained in:
Dragorn421 2025-05-24 01:37:22 +02:00
parent f7073a7837
commit 6e3236b8a0
No known key found for this signature in database
GPG Key ID: 381AEBAF3D429335
1 changed files with 47 additions and 8 deletions

View File

@ -288,6 +288,13 @@ def sym_info_main():
help="which version should be processed (default: gc-eu-mq-dbg)",
default="gc-eu-mq-dbg",
)
parser.add_argument(
"--build-dir",
dest="build_dir",
help="the build folder in which to read the map and elf (default: `build/VERSION/`)",
type=Path,
default=None,
)
args = parser.parse_args()
@ -302,14 +309,44 @@ def sym_info_main():
else:
colors = sys.stdout.isatty()
BUILTMAP = Path("build") / args.oot_version / f"oot-{args.oot_version}.map"
BUILTELF = Path("build") / args.oot_version / f"oot-{args.oot_version}.elf"
build_dir: Path = args.build_dir
if build_dir is None:
build_dir = Path("build") / args.oot_version
map_path = build_dir / f"oot-{args.oot_version}.map"
elf_path = build_dir / f"oot-{args.oot_version}.elf"
else:
map_paths = list(build_dir.glob("*.map"))
elf_paths = list(build_dir.glob("*.elf"))
if len(map_paths) > 1:
print(f"Found several .map files instead of just one:")
print("\n".join(map(str, map_paths)))
sys.exit(1)
if not map_paths:
print("Could not find map file")
sys.exit(1)
if len(elf_paths) > 1:
print(f"Found several .elf files instead of just one:")
print("\n".join(map(str, elf_paths)))
sys.exit(1)
map_path = map_paths[0]
elf_path = elf_paths[0] if elf_paths else None
map_path = BUILTMAP
elf_path = BUILTELF
if args.use_expected:
map_path = "expected" / BUILTMAP
elf_path = "expected" / BUILTELF
map_path = (
Path("expected")
/ "build"
/ args.oot_version
/ f"oot-{args.oot_version}.map"
)
elf_path = (
Path("expected")
/ "build"
/ args.oot_version
/ f"oot-{args.oot_version}.elf"
)
if not map_path.exists():
print(f"Could not find map_file at '{map_path}'")
@ -318,12 +355,14 @@ def sym_info_main():
map_file = mapfile_parser.mapfile.MapFile()
map_file.readMapFile(map_path)
if elf_path.exists():
if elf_path and elf_path.exists():
local_symbols = read_local_symbols_from_mdebug(elf_path)
merge_local_symbols(map_file, local_symbols)
else:
print(
f"Could not find ELF file at '{elf_path}', local symbols will not be available"
"Could not find ELF file"
+ (f" at '{elf_path}'" if elf_path else "")
+ ", local symbols will not be available"
)
sym_name = args.symname