From 3d87a958504afbfad56e34041ae4adf34bb3bfbc Mon Sep 17 00:00:00 2001 From: UsernameFodder Date: Thu, 28 Dec 2023 23:37:51 -0600 Subject: [PATCH] Support syncing BSS symbols to pmdsky-debug These data symbols can be added to ram.yml. Since information is lost, it's not possible to go in the other direction, so RAM syncing can only be done TO pmdsky-debug. --- tools/sync_pmdsky_debug/pmdsky_debug_reader.py | 1 + tools/sync_pmdsky_debug/sync_from_pmdsky_debug.py | 4 ++++ tools/sync_pmdsky_debug/sync_to_pmdsky_debug.py | 2 ++ tools/sync_pmdsky_debug/xmap_reader.py | 7 ++++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/sync_pmdsky_debug/pmdsky_debug_reader.py b/tools/sync_pmdsky_debug/pmdsky_debug_reader.py index d54ddbd5..1a9e61a0 100644 --- a/tools/sync_pmdsky_debug/pmdsky_debug_reader.py +++ b/tools/sync_pmdsky_debug/pmdsky_debug_reader.py @@ -114,5 +114,6 @@ def read_pmdsky_debug_symbols() -> Dict[str, Dict[str, Dict[int, SymbolDetails]] for file in os.listdir(overlay_folder): if file.endswith('.yml'): read_yaml_symbols(os.path.join(overlay_name, file), str(i)) + read_yaml_symbols('ram.yml', 'ram') return pmdsky_debug_symbols diff --git a/tools/sync_pmdsky_debug/sync_from_pmdsky_debug.py b/tools/sync_pmdsky_debug/sync_from_pmdsky_debug.py index 199b0a5e..7c404c09 100644 --- a/tools/sync_pmdsky_debug/sync_from_pmdsky_debug.py +++ b/tools/sync_pmdsky_debug/sync_from_pmdsky_debug.py @@ -39,6 +39,10 @@ replaced_symbols = set() for language, pmdsky_debug_language_symbols in pmdsky_debug_symbols.items(): xmap_language_symbols = xmap_symbols[language] for section_name, pmdsky_debug_section in pmdsky_debug_language_symbols.items(): + if section_name == 'ram': + # We can't distinguish between different types of RAM symbols. + # E.g., they could be in the BSS, heap, etc. + continue if section_name in xmap_language_symbols: xmap_section = xmap_language_symbols[section_name] else: diff --git a/tools/sync_pmdsky_debug/sync_to_pmdsky_debug.py b/tools/sync_pmdsky_debug/sync_to_pmdsky_debug.py index 7aac60e4..aea84896 100644 --- a/tools/sync_pmdsky_debug/sync_to_pmdsky_debug.py +++ b/tools/sync_pmdsky_debug/sync_to_pmdsky_debug.py @@ -70,6 +70,8 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_ma base_symbol_path = 'arm7.yml' elif section_name == 'ITCM': base_symbol_path = os.path.join('arm9', 'itcm.yml') + elif section_name == 'ram': + base_symbol_path = 'ram.yml' else: base_symbol_path = f'overlay{int(section_name):02d}.yml' diff --git a/tools/sync_pmdsky_debug/xmap_reader.py b/tools/sync_pmdsky_debug/xmap_reader.py index b948d652..e74da77d 100644 --- a/tools/sync_pmdsky_debug/xmap_reader.py +++ b/tools/sync_pmdsky_debug/xmap_reader.py @@ -56,6 +56,9 @@ def read_xmap_symbols_for_language(language: str) -> Dict[str, Dict[int, SymbolD for line in xmap_lines: if line.startswith(SECTION_START): section_name = line[len(SECTION_START) : -1] + # The corresponding BSS sections can contain RAM data symbols + is_ram = section_name.endswith('.bss') + section_name = section_name.removesuffix('.bss') if section_name in overlay_names: current_section = str(overlay_names[section_name]) elif section_name == 'main' or section_name == 'ITCM' or section_name == 'arm7': @@ -64,10 +67,12 @@ def read_xmap_symbols_for_language(language: str) -> Dict[str, Dict[int, SymbolD current_section = 'arm7' else: current_section = None + if current_section is not None and is_ram: + current_section = 'ram' if current_section is not None and current_section not in xmap_symbols: xmap_symbols[current_section]: Dict[str, int] = {} - elif current_section is not None and line.startswith(' ') and ('.text' in line or '.data' in line) and len(line) > 28 and line[28] not in NON_FUNCTION_SYMBOLS: + elif current_section is not None and line.startswith(' ') and ('.text' in line or '.data' in line or '.bss' in line) and len(line) > 28 and line[28] not in NON_FUNCTION_SYMBOLS: symbol_split = line[28:-1].split('\t') symbol_name = symbol_split[0] symbol_address = int(line[2:10], 16)