mirror of
https://github.com/zeldaret/oot.git
synced 2025-08-11 01:10:33 +00:00
sym_info.py
: QoL features (#2539)
* Add `./sym_info.py --build-dir` to print symbols from an arbitrary build/ folder * Make sym_info.py return more results (in both vram and vrom)
This commit is contained in:
parent
4201359f89
commit
385cf23064
1 changed files with 59 additions and 17 deletions
72
sym_info.py
72
sym_info.py
|
@ -288,6 +288,13 @@ def sym_info_main():
|
||||||
help="which version should be processed (default: gc-eu-mq-dbg)",
|
help="which version should be processed (default: gc-eu-mq-dbg)",
|
||||||
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -302,14 +309,44 @@ def sym_info_main():
|
||||||
else:
|
else:
|
||||||
colors = sys.stdout.isatty()
|
colors = sys.stdout.isatty()
|
||||||
|
|
||||||
BUILTMAP = Path("build") / args.oot_version / f"oot-{args.oot_version}.map"
|
build_dir: Path = args.build_dir
|
||||||
BUILTELF = Path("build") / args.oot_version / f"oot-{args.oot_version}.elf"
|
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:
|
if args.use_expected:
|
||||||
map_path = "expected" / BUILTMAP
|
map_path = (
|
||||||
elf_path = "expected" / BUILTELF
|
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():
|
if not map_path.exists():
|
||||||
print(f"Could not find map_file at '{map_path}'")
|
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 = mapfile_parser.mapfile.MapFile()
|
||||||
map_file.readMapFile(map_path)
|
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)
|
local_symbols = read_local_symbols_from_mdebug(elf_path)
|
||||||
merge_local_symbols(map_file, local_symbols)
|
merge_local_symbols(map_file, local_symbols)
|
||||||
else:
|
else:
|
||||||
print(
|
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
|
sym_name = args.symname
|
||||||
|
@ -332,25 +371,28 @@ def sym_info_main():
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
infos: list[mapfile_parser.mapfile.FoundSymbolInfo] = []
|
infos: list[mapfile_parser.mapfile.FoundSymbolInfo] = []
|
||||||
possible_files: list[mapfile_parser.mapfile.File] = []
|
all_possible_files: list[mapfile_parser.mapfile.File] = []
|
||||||
try:
|
try:
|
||||||
address = int(sym_name, 0)
|
address = int(sym_name, 0)
|
||||||
if address >= 0x01000000:
|
|
||||||
|
if address >= 0x0100_0000:
|
||||||
info, possible_files = map_file.findSymbolByVram(address)
|
info, possible_files = map_file.findSymbolByVram(address)
|
||||||
if info is not None:
|
if info is not None:
|
||||||
infos = [info]
|
infos += [info]
|
||||||
else:
|
all_possible_files += possible_files
|
||||||
|
|
||||||
info, possible_files = map_file.findSymbolByVrom(address)
|
info, possible_files = map_file.findSymbolByVrom(address)
|
||||||
if info is not None:
|
if info is not None:
|
||||||
infos = [info]
|
infos += [info]
|
||||||
|
all_possible_files += possible_files
|
||||||
except ValueError:
|
except ValueError:
|
||||||
infos = find_symbols_by_name(map_file, sym_name)
|
infos = find_symbols_by_name(map_file, sym_name)
|
||||||
|
|
||||||
if not infos:
|
if not infos:
|
||||||
print(f"'{sym_name}' not found in map file '{map_path}'")
|
print(f"'{sym_name}' not found in map file '{map_path}'")
|
||||||
if len(possible_files) > 0:
|
if all_possible_files:
|
||||||
print("But it may be a local symbol of either of the following files:")
|
print("But it may be a local symbol of either of the following files:")
|
||||||
for f in possible_files:
|
for f in all_possible_files:
|
||||||
print(f" {f.asStr()})")
|
print(f" {f.asStr()})")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue