Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lldb/include/lldb/Expression/IRExecutionUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <atomic>
#include <memory>
#include <string>
#include <unordered_set>
#include <vector>

#include "llvm/ExecutionEngine/SectionMemoryManager.h"
Expand Down Expand Up @@ -161,6 +162,10 @@ class IRExecutionUnit : public std::enable_shared_from_this<IRExecutionUnit>,
return m_jitted_global_variables;
}

void SetPreferredModules(std::unordered_set<lldb::ModuleSP> modules) {
m_preferred_modules = std::move(modules);
}

private:
/// Look up the object in m_address_map that contains a given address, find
/// where it was copied to, and return the remote address at the same offset
Expand Down Expand Up @@ -396,6 +401,7 @@ class IRExecutionUnit : public std::enable_shared_from_this<IRExecutionUnit>,
///< defining no functions using that variable, would do this.) If this
///< is true, any allocations need to be committed immediately -- no
///< opportunity for relocation.
std::unordered_set<lldb::ModuleSP> m_preferred_modules;
};

} // namespace lldb_private
Expand Down
10 changes: 10 additions & 0 deletions lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ class EvaluateExpressionOptions {
m_language = SourceLanguage(language_type);
}

void SetPreferredModules(std::unordered_set<lldb::ModuleSP> modules) {
m_preferred_modules = std::move(modules);
}

const std::unordered_set<lldb::ModuleSP> &GetPreferredModules() const {
return m_preferred_modules;
}

/// Set the language using a pair of language code and version as
/// defined by the DWARF 6 specification.
/// WARNING: These codes may change until DWARF 6 is finalized.
Expand Down Expand Up @@ -500,6 +508,8 @@ class EvaluateExpressionOptions {
// originates
mutable std::string m_pound_line_file;
mutable uint32_t m_pound_line_line = 0;

std::unordered_set<lldb::ModuleSP> m_preferred_modules;
};

// Target
Expand Down
25 changes: 24 additions & 1 deletion lldb/source/Expression/IRExecutionUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ IRExecutionUnit::IRExecutionUnit(std::unique_ptr<llvm::LLVMContext> &context_up,
m_cpu_features(cpu_features), m_name(name), m_sym_ctx(sym_ctx),
m_did_jit(false), m_function_load_addr(LLDB_INVALID_ADDRESS),
m_function_end_load_addr(LLDB_INVALID_ADDRESS),
m_reported_allocations(false) {}
m_reported_allocations(false), m_preferred_modules() {}

lldb::addr_t IRExecutionUnit::WriteNow(const uint8_t *bytes, size_t size,
Status &error) {
Expand Down Expand Up @@ -785,6 +785,13 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
// We'll process module_sp separately, before the other modules.
non_local_images.Remove(sc.module_sp);

ModuleList preferred_images;
// TODO: make m_preferred_modules a ModuleList
for (auto const &m : m_preferred_modules) {
non_local_images.Remove(m);
preferred_images.Append(m);
}

LoadAddressResolver resolver(target, symbol_was_missing_weak);

ModuleFunctionSearchOptions function_options;
Expand All @@ -806,6 +813,14 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
return *load_addr;
}

{
SymbolContextList sc_list;
preferred_images.FindFunctions(name, lldb::eFunctionNameTypeFull,
function_options, sc_list);
if (auto load_addr = resolver.Resolve(sc_list))
return *load_addr;
}

{
SymbolContextList sc_list;
non_local_images.FindFunctions(name, lldb::eFunctionNameTypeFull,
Expand All @@ -822,6 +837,14 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
return *load_addr;
}

{
SymbolContextList sc_list;
preferred_images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
sc_list);
if (auto load_addr = resolver.Resolve(sc_list))
return *load_addr;
}

{
SymbolContextList sc_list;
non_local_images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,9 @@ lldb_private::Status ClangExpressionParser::DoPrepareForExecution(
function_name, exe_ctx.GetTargetSP(), sc,
m_compiler->getTargetOpts().Features);

if (auto *options = m_expr.GetOptions())
execution_unit_sp->SetPreferredModules(options->GetPreferredModules());

ClangExpressionHelper *type_system_helper =
dyn_cast<ClangExpressionHelper>(m_expr.GetTypeSystemHelper());
ClangExpressionDeclMap *decl_map =
Expand Down
15 changes: 15 additions & 0 deletions lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ HistoryThreads MemoryHistoryASan::GetHistoryThreads(lldb::addr_t address) {
options.SetAutoApplyFixIts(false);
options.SetLanguage(eLanguageTypeObjC_plus_plus);

const auto &target = process_sp->GetTarget();
std::unordered_set<ModuleSP> preferred_modules;
target.GetImages().ForEach([&](const lldb::ModuleSP &m) {
llvm::Regex pattern("libclang_rt.asan_.*_dynamic.dylib");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wrotki is this going to hold in the long-term? Will the locally built compiler-rt always be libclang_rt?

Copy link
Contributor

@wrotki wrotki Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libclang_rt is here to stay forever I believe.

Can you escape literal dots in the regex (i.e. to be libclang_rt\.asan_.*_dynamic\.dylib) ? As it is, they're matching any character, which is not intended.

if (pattern.match(m->GetFileSpec().GetFilename().GetStringRef())) {
preferred_modules.insert(m);
return false;
}

return true;
});

if (!preferred_modules.empty())
options.SetPreferredModules(std::move(preferred_modules));

ExpressionResults expr_result = UserExpression::Evaluate(
exe_ctx, options, expr.GetString(), "", return_value_sp);
if (expr_result != eExpressionCompleted) {
Expand Down