Skip to content

Commit

Permalink
Merge pull request #179 from chaoticgd/febfix3
Browse files Browse the repository at this point in the history
Add SymbolDatabase::symbol_with_name accessor function
  • Loading branch information
chaoticgd authored Feb 17, 2024
2 parents 1b41e15 + c0003c6 commit 4e217ac
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
27 changes: 24 additions & 3 deletions src/ccc/symbol_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ s32 SymbolDatabase::symbol_count() const
return sum;
}

const Symbol* SymbolDatabase::first_symbol_starting_at_address(
const Symbol* SymbolDatabase::symbol_starting_at_address(
Address address, u32 descriptors, SymbolDescriptor* descriptor_out) const
{
#define CCC_X(SymbolType, symbol_list) \
Expand All @@ -757,7 +757,7 @@ const Symbol* SymbolDatabase::first_symbol_starting_at_address(
return nullptr;
}

const Symbol* SymbolDatabase::first_symbol_after_address(
const Symbol* SymbolDatabase::symbol_after_address(
Address address, u32 descriptors, SymbolDescriptor* descriptor_out) const
{
const Symbol* result = nullptr;
Expand All @@ -779,7 +779,7 @@ const Symbol* SymbolDatabase::first_symbol_after_address(
return result;
}

const Symbol* SymbolDatabase::first_symbol_overlapping_address(
const Symbol* SymbolDatabase::symbol_overlapping_address(
Address address, u32 descriptors, SymbolDescriptor* descriptor_out) const
{
#define CCC_X(SymbolType, symbol_list) \
Expand All @@ -799,6 +799,27 @@ const Symbol* SymbolDatabase::first_symbol_overlapping_address(
return nullptr;
}

const Symbol* SymbolDatabase::symbol_with_name(
const std::string& name, u32 descriptors, SymbolDescriptor* descriptor_out) const
{
#define CCC_X(SymbolType, symbol_list) \
if constexpr(SymbolType::FLAGS & WITH_ADDRESS_MAP) { \
if(descriptors & SymbolType::DESCRIPTOR) { \
const SymbolHandle<SymbolType> handle = symbol_list.first_handle_from_name(name); \
const SymbolType* symbol = symbol_list.symbol_from_handle(handle); \
if(symbol) { \
if(descriptor_out) { \
*descriptor_out = SymbolType::DESCRIPTOR; \
} \
return symbol; \
} \
} \
}
CCC_FOR_EACH_SYMBOL_TYPE_DO_X
#undef CCC_X
return nullptr;
}

Result<SymbolSourceHandle> SymbolDatabase::get_symbol_source(const std::string& name)
{
SymbolSourceHandle handle = symbol_sources.first_handle_from_name(name);
Expand Down
16 changes: 12 additions & 4 deletions src/ccc/symbol_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ class SymbolList {
using AddressToHandleMapIterators = Iterators<typename AddressToHandleMap::const_iterator>;
using NameToHandleMapIterators = Iterators<typename NameToHandleMap::const_iterator>;

// Lookup symbol by their address.
// Lookup symbols by their address.
AddressToHandleMapIterators handles_from_starting_address(Address address) const;
AddressToHandleMapIterators handles_from_address_range(AddressRange range) const;
SymbolHandle<SymbolType> first_handle_from_starting_address(Address address) const;
SymbolHandle<SymbolType> first_handle_after_address(Address address) const;

// Lookup symbols by their name.
NameToHandleMapIterators handles_from_name(const std::string& name) const;
SymbolHandle<SymbolType> first_handle_from_name(const std::string& name) const;

Expand Down Expand Up @@ -618,13 +620,19 @@ class SymbolDatabase {
// Find a symbol of any of the specified types given an address. Symbols of
// the types specified higher up in the CCC_FOR_EACH_SYMBOL_TYPE_DO_X macro
// are checked for first.
const Symbol* first_symbol_starting_at_address(
const Symbol* symbol_starting_at_address(
Address address, u32 descriptors = ALL_SYMBOL_TYPES, SymbolDescriptor* descriptor_out = nullptr) const;
const Symbol* first_symbol_after_address(
const Symbol* symbol_after_address(
Address address, u32 descriptors = ALL_SYMBOL_TYPES, SymbolDescriptor* descriptor_out = nullptr) const;
const Symbol* first_symbol_overlapping_address(
const Symbol* symbol_overlapping_address(
Address address, u32 descriptors = ALL_SYMBOL_TYPES, SymbolDescriptor* descriptor_out = nullptr) const;

// Find a symbol of any of the specified types given its name. Symbols of
// the types specified higher up in the CCC_FOR_EACH_SYMBOL_TYPE_DO_X macro
// are checked for first.
const Symbol* symbol_with_name(
const std::string& name, u32 descriptors = ALL_SYMBOL_TYPES, SymbolDescriptor* descriptor_out = nullptr) const;

// Finds a symbol source object with the given name or creates one if it
// doesn't already exist.
Result<SymbolSourceHandle> get_symbol_source(const std::string& name);
Expand Down

0 comments on commit 4e217ac

Please sign in to comment.