21#include "llvm/Support/Error.h"
22#include "llvm/Support/FormatVariadic.h"
29 bool strip_underscore)
34 std::vector<ConstString> &C_names,
ConstString name) {
37 C_names.push_back(name);
41 std::vector<ConstString> &CPP_names,
42 const std::vector<ConstString> &C_names,
const SymbolContext &sc) {
46 if (cpp_lang->SymbolNameFitsToLanguage(mangled)) {
48 cpp_lang->FindBestAlternateFunctionMangledName(mangled, sc)) {
49 CPP_names.push_back(best_alternate);
53 std::vector<ConstString> alternates =
54 cpp_lang->GenerateAlternateFunctionManglings(name);
55 CPP_names.insert(CPP_names.end(), alternates.begin(), alternates.end());
60 cpp_lang->GetDemangledFunctionNameWithoutArguments(mangled);
61 CPP_names.push_back(basename);
83 if (!candidate_sc.symbol ||
85 !candidate_sc.symbol->IsWeak())
89 if (candidate_sc.symbol) {
90 load_address = candidate_sc.symbol->ResolveCallableAddress(
93 Address addr = candidate_sc.symbol->GetAddress();
94 load_address =
m_target.GetProcessSP()
102 Address addr = candidate_sc.function->GetAddress();
103 load_address =
m_target.GetProcessSP()
111 const bool is_external =
112 (candidate_sc.function) ||
113 (candidate_sc.symbol && candidate_sc.symbol->IsExternal());
143static llvm::Expected<lldb::addr_t>
146 bool &symbol_was_missing_weak) {
147 symbol_was_missing_weak =
false;
150 return llvm::createStringError(
"target not available");
154 return llvm::createStringError(
155 llvm::formatv(
"failed to find module by UID {0}", label.
module_id));
157 auto *symbol_file = module_sp->GetSymbolFile();
159 return llvm::createStringError(
160 llvm::formatv(
"no SymbolFile found on module {0:x}.", module_sp.get()));
162 auto sc_or_err = symbol_file->ResolveFunctionCallLabel(label);
164 return llvm::joinErrors(
165 llvm::createStringError(
"failed to resolve function by UID:"),
166 sc_or_err.takeError());
169 sc_list.
Append(*sc_or_err);
175 return llvm::createStringError(
"couldn't resolve address for function");
177 return resolved_addr;
183 bool &symbol_was_missing_weak) {
184 symbol_was_missing_weak =
false;
201 for (
size_t i = non_local_images.
GetSize(); i > 0; --i) {
204 non_local_images.
Remove(module_sp);
224 lldb::eFunctionNameTypeFull, function_options,
226 if (
auto load_addr = resolver.
Resolve(sc_list))
233 function_options, sc_list);
234 if (
auto load_addr = resolver.
Resolve(sc_list))
240 non_local_images.
FindFunctions(name, lldb::eFunctionNameTypeFull,
241 function_options, sc_list);
242 if (
auto load_addr = resolver.
Resolve(sc_list))
250 if (
auto load_addr = resolver.
Resolve(sc_list))
258 if (
auto load_addr = resolver.
Resolve(sc_list))
266 if (
auto load_addr = resolver.
Resolve(sc_list))
273 return best_internal_load_address;
296 lldb::addr_t symbol_load_addr = runtime->LookupRuntimeSymbol(name);
299 return symbol_load_addr;
307 const std::vector<ConstString> &names,
312 lldb::addr_t symbol_load_addr = target_sp->GetPersistentSymbol(name);
315 return symbol_load_addr;
322 bool &missing_weak) {
327 "failed to create FunctionCallLabel from '{1}': {0}",
332 if (
auto addr_or_err =
337 "Failed to resolve function call label '{1}': {0}",
344 name.
SetString(label_or_err->lookup_name);
351 std::vector<ConstString> candidate_C_names;
352 std::vector<ConstString> candidate_CPlusPlus_names;
362 missing_weak =
false;
static llvm::Expected< lldb::addr_t > ResolveFunctionCallLabel(FunctionCallLabel &label, const lldb_private::SymbolContext &sc, bool &symbol_was_missing_weak)
Returns address of the function referred to by the special function call label label.
#define LLDB_LOG_ERROR(log, error,...)
LoadAddressResolver(Target &target, bool &symbol_was_missing_weak)
lldb::addr_t m_best_internal_load_address
bool & m_symbol_was_missing_weak
std::optional< lldb::addr_t > Resolve(SymbolContextList &sc_list)
lldb::addr_t GetBestInternalLoadAddress() const
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
lldb::addr_t GetCallableLoadAddress(Target *target, bool is_indirect=false) const
Get the load address as a callable code load address.
lldb::addr_t GetFileAddress() const
Get the file address.
Represents a generic declaration context in a program.
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetString(llvm::StringRef s)
const char * GetCString() const
Get the string value as a C string.
ExternalSymbolResolver(const SymbolContext &sym_ctx, bool strip_underscore)
Constructor.
SymbolContext m_sym_ctx
Used for symbol lookups.
lldb::addr_t FindSymbol(ConstString name, bool &missing_weak)
Find the load address of name.
lldb::addr_t FindInSymbols(const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc, bool &symbol_was_missing_weak)
lldb::addr_t FindInUserDefinedSymbols(const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc)
lldb::addr_t FindInRuntimes(const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc)
ModuleList m_preferred_modules
Any Module in this list will be used for symbol/function lookup before any other module (except for t...
void CollectCandidateCPlusPlusNames(std::vector< ConstString > &CPP_names, const std::vector< ConstString > &C_names, const SymbolContext &sc)
bool m_strip_underscore
True for platforms where global symbols have a _ prefix.
void CollectCandidateCNames(std::vector< ConstString > &C_names, ConstString name)
static Language * FindPlugin(lldb::LanguageType language)
A class that handles mangled names.
A collection class for Module objects.
void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list) const
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
bool Remove(const lldb::ModuleSP &module_sp, bool notify=true)
Remove a module from the module list.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
size_t GetSize() const
Gets the size of the module list.
Defines a list of symbol context objects.
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
SymbolContextIterable SymbolContexts()
Defines a symbol context baton that can be handed other debug core functions.
lldb::ModuleSP module_sp
The Module for a given query.
lldb::TargetSP target_sp
The Target for a given query.
bool ModuleIsExcludedForUnconstrainedSearches(const FileSpec &module_spec)
Return whether this FileSpec corresponds to a module that should be considered for general searches.
const ModuleList & GetImages() const
Get accessor for the images for this process.
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
constexpr llvm::StringRef FunctionCallLabelPrefix
LLDB attaches this prefix to mangled names of functions that get called from JITted expressions.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
Holds parsed information about a function call label that LLDB attaches as an AsmLabel to function AS...
static llvm::Expected< FunctionCallLabel > fromString(llvm::StringRef label)
Decodes the specified function label into a FunctionCallLabel.
lldb::user_id_t module_id
Unique identifier of the lldb_private::Module which contains the symbol identified by symbol_id.
Options used by Module::FindFunctions.
bool include_inlines
Include inlined functions.
bool include_symbols
Include the symbol table.