yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
symbol_provider.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EMU_DEBUG_SYMBOL_PROVIDER_H_
2#define YAZE_APP_EMU_DEBUG_SYMBOL_PROVIDER_H_
3
4#include <cstdint>
5#include <map>
6#include <optional>
7#include <string>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
12
13namespace yaze {
14namespace emu {
15namespace debug {
16
20struct Symbol {
21 std::string name; // Symbol name (e.g., "MainGameLoop", "Reset")
22 uint32_t address; // 24-bit SNES address
23 std::string file; // Source file (if known)
24 int line = 0; // Line number (if known)
25 std::string comment; // Optional comment or description
26 bool is_local = false; // True for local labels (starting with .)
27
28 Symbol() = default;
29 Symbol(const std::string& n, uint32_t addr)
30 : name(n), address(addr) {}
31 Symbol(const std::string& n, uint32_t addr, const std::string& f, int l)
32 : name(n), address(addr), file(f), line(l) {}
33};
34
38enum class SymbolFormat {
39 kAuto, // Auto-detect based on file extension/content
40 kAsar, // Asar-style .asm/.sym files (label: at address #_XXXXXX:)
41 kWlaDx, // WLA-DX .sym format (bank:address name)
42 kMesen, // Mesen .mlb format (address:name)
43 kBsnes, // bsnes .sym format (address name)
44 kNo$snes, // No$snes .sym format (bank:addr name)
45};
46
67 public:
68 SymbolProvider() = default;
69
80 absl::Status LoadAsarAsmFile(const std::string& path);
81
90 absl::Status LoadAsarAsmDirectory(const std::string& directory_path);
91
99 absl::Status LoadSymbolFile(const std::string& path,
101
105 void AddSymbol(const Symbol& symbol);
106
110 void AddAsarSymbols(const std::vector<Symbol>& symbols);
111
115 void Clear();
116
121 std::string GetSymbolName(uint32_t address) const;
122
127 std::optional<Symbol> GetSymbol(uint32_t address) const;
128
132 std::vector<Symbol> GetSymbolsAtAddress(uint32_t address) const;
133
138 std::optional<Symbol> FindSymbol(const std::string& name) const;
139
145 std::vector<Symbol> FindSymbolsMatching(const std::string& pattern) const;
146
150 std::vector<Symbol> GetSymbolsInRange(uint32_t start, uint32_t end) const;
151
157 std::optional<Symbol> GetNearestSymbol(uint32_t address) const;
158
167 std::string FormatAddress(uint32_t address,
168 uint32_t max_offset = 0x100) const;
169
173 size_t GetSymbolCount() const { return symbols_by_address_.size(); }
174
178 bool HasSymbols() const { return !symbols_by_address_.empty(); }
179
183 std::function<std::string(uint32_t)> CreateResolver() const;
184
185 private:
186 // Parse different symbol file formats
187 absl::Status ParseAsarAsmContent(const std::string& content,
188 const std::string& filename);
189 absl::Status ParseWlaDxSymFile(const std::string& content);
190 absl::Status ParseMesenMlbFile(const std::string& content);
191 absl::Status ParseBsnesSymFile(const std::string& content);
192
193 // Detect format from file content
194 SymbolFormat DetectFormat(const std::string& content,
195 const std::string& extension) const;
196
197 // Primary storage: address -> symbols (may have multiple per address)
198 std::multimap<uint32_t, Symbol> symbols_by_address_;
199
200 // Secondary index: name -> symbol (for reverse lookup)
201 std::map<std::string, Symbol> symbols_by_name_;
202};
203
204} // namespace debug
205} // namespace emu
206} // namespace yaze
207
208#endif // YAZE_APP_EMU_DEBUG_SYMBOL_PROVIDER_H_
Provider for symbol (label) resolution in disassembly.
std::function< std::string(uint32_t)> CreateResolver() const
Create a symbol resolver function for the disassembler.
std::vector< Symbol > GetSymbolsInRange(uint32_t start, uint32_t end) const
Get all symbols in an address range.
bool HasSymbols() const
Check if any symbols are loaded.
std::string FormatAddress(uint32_t address, uint32_t max_offset=0x100) const
Format an address with symbol info.
void AddSymbol(const Symbol &symbol)
Add a single symbol manually.
std::map< std::string, Symbol > symbols_by_name_
size_t GetSymbolCount() const
Get total number of loaded symbols.
std::vector< Symbol > GetSymbolsAtAddress(uint32_t address) const
Get all symbols at an address (there may be multiple)
void AddAsarSymbols(const std::vector< Symbol > &symbols)
Add symbols from Asar patch results.
absl::Status ParseBsnesSymFile(const std::string &content)
absl::Status LoadAsarAsmDirectory(const std::string &directory_path)
Load symbols from a directory of ASM files.
absl::Status ParseWlaDxSymFile(const std::string &content)
std::multimap< uint32_t, Symbol > symbols_by_address_
absl::Status LoadAsarAsmFile(const std::string &path)
Load symbols from an Asar-style ASM file (usdasm format)
SymbolFormat DetectFormat(const std::string &content, const std::string &extension) const
absl::Status LoadSymbolFile(const std::string &path, SymbolFormat format=SymbolFormat::kAuto)
Load symbols from a .sym file (various formats)
std::string GetSymbolName(uint32_t address) const
Get symbol name for an address.
void Clear()
Clear all loaded symbols.
std::optional< Symbol > GetNearestSymbol(uint32_t address) const
Get nearest symbol at or before an address.
absl::Status ParseAsarAsmContent(const std::string &content, const std::string &filename)
absl::Status ParseMesenMlbFile(const std::string &content)
std::optional< Symbol > GetSymbol(uint32_t address) const
Get full symbol info for an address.
std::optional< Symbol > FindSymbol(const std::string &name) const
Find symbol by name.
std::vector< Symbol > FindSymbolsMatching(const std::string &pattern) const
Find symbols matching a pattern (supports wildcards)
SymbolFormat
Supported symbol file formats.
Information about a symbol (label, constant, or address)
Symbol(const std::string &n, uint32_t addr, const std::string &f, int l)
Symbol(const std::string &n, uint32_t addr)