yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::emu::debug::SymbolProvider Class Reference

Provider for symbol (label) resolution in disassembly. More...

#include <symbol_provider.h>

Public Member Functions

 SymbolProvider ()=default
 
absl::Status LoadAsarAsmFile (const std::string &path)
 Load symbols from an Asar-style ASM file (usdasm format)
 
absl::Status LoadAsarAsmDirectory (const std::string &directory_path)
 Load symbols from a directory of ASM files.
 
absl::Status LoadSymbolFile (const std::string &path, SymbolFormat format=SymbolFormat::kAuto)
 Load symbols from a .sym file (various formats)
 
void AddSymbol (const Symbol &symbol)
 Add a single symbol manually.
 
void AddAsarSymbols (const std::vector< Symbol > &symbols)
 Add symbols from Asar patch results.
 
void Clear ()
 Clear all loaded symbols.
 
std::string GetSymbolName (uint32_t address) const
 Get symbol name for an address.
 
std::optional< SymbolGetSymbol (uint32_t address) const
 Get full symbol info for an address.
 
std::vector< SymbolGetSymbolsAtAddress (uint32_t address) const
 Get all symbols at an address (there may be multiple)
 
std::optional< SymbolFindSymbol (const std::string &name) const
 Find symbol by name.
 
std::vector< SymbolFindSymbolsMatching (const std::string &pattern) const
 Find symbols matching a pattern (supports wildcards)
 
std::vector< SymbolGetSymbolsInRange (uint32_t start, uint32_t end) const
 Get all symbols in an address range.
 
std::optional< SymbolGetNearestSymbol (uint32_t address) const
 Get nearest symbol at or before an address.
 
std::string FormatAddress (uint32_t address, uint32_t max_offset=0x100) const
 Format an address with symbol info.
 
size_t GetSymbolCount () const
 Get total number of loaded symbols.
 
bool HasSymbols () const
 Check if any symbols are loaded.
 
std::function< std::string(uint32_t)> CreateResolver () const
 Create a symbol resolver function for the disassembler.
 

Private Member Functions

absl::Status ParseAsarAsmContent (const std::string &content, const std::string &filename)
 
absl::Status ParseWlaDxSymFile (const std::string &content)
 
absl::Status ParseMesenMlbFile (const std::string &content)
 
absl::Status ParseBsnesSymFile (const std::string &content)
 
SymbolFormat DetectFormat (const std::string &content, const std::string &extension) const
 

Private Attributes

std::multimap< uint32_t, Symbolsymbols_by_address_
 
std::map< std::string, Symbolsymbols_by_name_
 

Detailed Description

Provider for symbol (label) resolution in disassembly.

This class manages symbol tables from multiple sources:

  • Parsed ASM files (usdasm disassembly)
  • Symbol files from various emulators/assemblers
  • Asar patches (runtime symbols)

AI agents use this to see meaningful label names instead of raw addresses when debugging 65816 assembly code.

Usage: SymbolProvider symbols; symbols.LoadAsarAsmFile("bank_00.asm"); symbols.LoadAsarAsmFile("bank_01.asm");

auto name = symbols.GetSymbolName(0x008034); // Returns "MainGameLoop" auto addr = symbols.FindSymbol("Reset"); // Returns Symbol at $008000

Definition at line 66 of file symbol_provider.h.

Constructor & Destructor Documentation

◆ SymbolProvider()

yaze::emu::debug::SymbolProvider::SymbolProvider ( )
default

Member Function Documentation

◆ LoadAsarAsmFile()

absl::Status yaze::emu::debug::SymbolProvider::LoadAsarAsmFile ( const std::string & path)

Load symbols from an Asar-style ASM file (usdasm format)

Parses labels like: MainGameLoop: #_008034: LDA.b $12

Parameters
pathPath to .asm file
Returns
Status indicating success or failure

Definition at line 120 of file symbol_provider.cc.

References ParseAsarAsmContent().

Referenced by LoadAsarAsmDirectory().

Here is the call graph for this function:

◆ LoadAsarAsmDirectory()

absl::Status yaze::emu::debug::SymbolProvider::LoadAsarAsmDirectory ( const std::string & directory_path)

Load symbols from a directory of ASM files.

Scans for all bank_XX.asm files and loads them

Parameters
directory_pathPath to directory containing ASM files
Returns
Status indicating success or failure

Definition at line 129 of file symbol_provider.cc.

References LoadAsarAsmFile().

Referenced by yaze::agent::EmulatorServiceImpl::LoadSymbols().

Here is the call graph for this function:

◆ LoadSymbolFile()

absl::Status yaze::emu::debug::SymbolProvider::LoadSymbolFile ( const std::string & path,
SymbolFormat format = SymbolFormat::kAuto )

Load symbols from a .sym file (various formats)

Parameters
pathPath to symbol file
formatSymbol file format (kAuto for auto-detect)
Returns
Status indicating success or failure

Definition at line 166 of file symbol_provider.cc.

References DetectFormat(), yaze::emu::debug::kAsar, yaze::emu::debug::kAuto, yaze::emu::debug::kBsnes, yaze::emu::debug::kMesen, yaze::emu::debug::kNo$snes, yaze::emu::debug::kWlaDx, ParseAsarAsmContent(), ParseBsnesSymFile(), ParseMesenMlbFile(), and ParseWlaDxSymFile().

Referenced by yaze::agent::EmulatorServiceImpl::LoadSymbols().

◆ AddSymbol()

void yaze::emu::debug::SymbolProvider::AddSymbol ( const Symbol & symbol)

◆ AddAsarSymbols()

void yaze::emu::debug::SymbolProvider::AddAsarSymbols ( const std::vector< Symbol > & symbols)

Add symbols from Asar patch results.

Definition at line 201 of file symbol_provider.cc.

References AddSymbol().

Here is the call graph for this function:

◆ Clear()

void yaze::emu::debug::SymbolProvider::Clear ( )

Clear all loaded symbols.

Definition at line 207 of file symbol_provider.cc.

References symbols_by_address_, and symbols_by_name_.

◆ GetSymbolName()

std::string yaze::emu::debug::SymbolProvider::GetSymbolName ( uint32_t address) const

Get symbol name for an address.

Returns
Symbol name if found, empty string otherwise

Definition at line 212 of file symbol_provider.cc.

References symbols_by_address_.

Referenced by CreateResolver().

◆ GetSymbol()

std::optional< Symbol > yaze::emu::debug::SymbolProvider::GetSymbol ( uint32_t address) const

Get full symbol info for an address.

Returns
Symbol if found, nullopt otherwise

Definition at line 220 of file symbol_provider.cc.

References symbols_by_address_.

Referenced by FormatAddress(), and yaze::agent::EmulatorServiceImpl::GetSymbolAt().

◆ GetSymbolsAtAddress()

std::vector< Symbol > yaze::emu::debug::SymbolProvider::GetSymbolsAtAddress ( uint32_t address) const

Get all symbols at an address (there may be multiple)

Definition at line 228 of file symbol_provider.cc.

References symbols_by_address_.

◆ FindSymbol()

std::optional< Symbol > yaze::emu::debug::SymbolProvider::FindSymbol ( const std::string & name) const

Find symbol by name.

Returns
Symbol if found, nullopt otherwise

Definition at line 238 of file symbol_provider.cc.

References symbols_by_name_.

Referenced by yaze::agent::EmulatorServiceImpl::ResolveSymbol().

◆ FindSymbolsMatching()

std::vector< Symbol > yaze::emu::debug::SymbolProvider::FindSymbolsMatching ( const std::string & pattern) const

Find symbols matching a pattern (supports wildcards)

Parameters
patternPattern with * as wildcard (e.g., "Module*", "*_Init")
Returns
Matching symbols

Definition at line 247 of file symbol_provider.cc.

References symbols_by_name_.

Referenced by yaze::agent::EmulatorServiceImpl::ResolveSymbol().

◆ GetSymbolsInRange()

std::vector< Symbol > yaze::emu::debug::SymbolProvider::GetSymbolsInRange ( uint32_t start,
uint32_t end ) const

Get all symbols in an address range.

Definition at line 258 of file symbol_provider.cc.

References symbols_by_address_.

◆ GetNearestSymbol()

std::optional< Symbol > yaze::emu::debug::SymbolProvider::GetNearestSymbol ( uint32_t address) const

Get nearest symbol at or before an address.

Useful for showing "MainGameLoop+$10" style offsets

Definition at line 269 of file symbol_provider.cc.

References symbols_by_address_.

Referenced by FormatAddress(), and yaze::agent::EmulatorServiceImpl::GetSymbolAt().

◆ FormatAddress()

std::string yaze::emu::debug::SymbolProvider::FormatAddress ( uint32_t address,
uint32_t max_offset = 0x100 ) const

Format an address with symbol info.

Returns formats like: "MainGameLoop" (exact match) "MainGameLoop+$10" (offset from nearest symbol) "$00804D" (no nearby symbol)

Definition at line 286 of file symbol_provider.cc.

References GetNearestSymbol(), and GetSymbol().

Here is the call graph for this function:

◆ GetSymbolCount()

size_t yaze::emu::debug::SymbolProvider::GetSymbolCount ( ) const
inline

Get total number of loaded symbols.

Definition at line 173 of file symbol_provider.h.

References symbols_by_address_.

Referenced by yaze::agent::EmulatorServiceImpl::LoadSymbols().

◆ HasSymbols()

bool yaze::emu::debug::SymbolProvider::HasSymbols ( ) const
inline

Check if any symbols are loaded.

Definition at line 178 of file symbol_provider.h.

References symbols_by_address_.

◆ CreateResolver()

std::function< std::string(uint32_t)> yaze::emu::debug::SymbolProvider::CreateResolver ( ) const

Create a symbol resolver function for the disassembler.

Definition at line 307 of file symbol_provider.cc.

References GetSymbolName().

Here is the call graph for this function:

◆ ParseAsarAsmContent()

absl::Status yaze::emu::debug::SymbolProvider::ParseAsarAsmContent ( const std::string & content,
const std::string & filename )
private

◆ ParseWlaDxSymFile()

absl::Status yaze::emu::debug::SymbolProvider::ParseWlaDxSymFile ( const std::string & content)
private

Definition at line 390 of file symbol_provider.cc.

References AddSymbol().

Referenced by LoadSymbolFile().

Here is the call graph for this function:

◆ ParseMesenMlbFile()

absl::Status yaze::emu::debug::SymbolProvider::ParseMesenMlbFile ( const std::string & content)
private

Definition at line 431 of file symbol_provider.cc.

References AddSymbol().

Referenced by LoadSymbolFile().

Here is the call graph for this function:

◆ ParseBsnesSymFile()

absl::Status yaze::emu::debug::SymbolProvider::ParseBsnesSymFile ( const std::string & content)
private

Definition at line 459 of file symbol_provider.cc.

References AddSymbol().

Referenced by LoadSymbolFile().

Here is the call graph for this function:

◆ DetectFormat()

SymbolFormat yaze::emu::debug::SymbolProvider::DetectFormat ( const std::string & content,
const std::string & extension ) const
private

Member Data Documentation

◆ symbols_by_address_

std::multimap<uint32_t, Symbol> yaze::emu::debug::SymbolProvider::symbols_by_address_
private

◆ symbols_by_name_

std::map<std::string, Symbol> yaze::emu::debug::SymbolProvider::symbols_by_name_
private

Definition at line 201 of file symbol_provider.h.

Referenced by AddSymbol(), Clear(), FindSymbol(), and FindSymbolsMatching().


The documentation for this class was generated from the following files: