36 if (!process_sp.get())
39 Target &target = process_sp->GetTarget();
41 for (
ModuleSP module_sp : target.GetImages().Modules()) {
42 const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
43 ConstString(
"__asan_get_alloc_stack"), lldb::eSymbolTypeAny);
45 if (symbol != nullptr)
46 return MemoryHistorySP(new MemoryHistoryASan(process_sp));
69 size_t __asan_get_alloc_stack(void *addr, void **trace, size_t size, int *thread_id);
70 size_t __asan_get_free_stack(void *addr, void **trace, size_t size, int *thread_id);
77 void *alloc_trace[256];
81 void *free_trace[256];
86 t.alloc_count = __asan_get_alloc_stack((void *)0x%)" PRIx64
87 R"(, t.alloc_trace, 256, &t.alloc_tid);
88 t.free_count = __asan_get_free_stack((void *)0x%)" PRIx64
89 R"(, t.free_trace, 256, &t.free_tid);
96 const char *type,
const char *thread_name,
HistoryThreads &result) {
97 std::string count_path =
"." + std::string(type) +
"_count";
98 std::string tid_path =
"." + std::string(type) +
"_tid";
99 std::string trace_path =
"." + std::string(type) +
"_trace";
102 return_value_sp->GetValueForExpressionPath(count_path.c_str());
104 return_value_sp->GetValueForExpressionPath(tid_path.c_str());
106 if (!count_sp || !tid_sp)
109 int count = count_sp->GetValueAsUnsigned(0);
110 lldb::tid_t tid = tid_sp->GetValueAsUnsigned(0) + 1;
116 return_value_sp->GetValueForExpressionPath(trace_path.c_str());
121 std::vector<lldb::addr_t> pcs;
122 for (
int i = 0; i < count; i++) {
123 addr_t pc = trace_sp->GetChildAtIndex(i)->GetValueAsUnsigned(0);
131 ThreadSP new_thread_sp(history_thread);
132 std::ostringstream thread_name_with_number;
133 thread_name_with_number << thread_name <<
" Thread " << tid;
134 history_thread->
SetThreadName(thread_name_with_number.str().c_str());
137 process_sp->GetExtendedThreadList().AddThread(new_thread_sp);
138 result.push_back(new_thread_sp);
149 process_sp->GetThreadList().GetExpressionExecutionThread();
168 options.
SetTimeout(process_sp->GetUtilityExpressionTimeout());
181 exe_ctx, options, expr.
GetString(),
"", return_value_sp);
184 ss <<
"cannot evaluate AddressSanitizer expression:\n";
186 ss << return_value_sp->GetError().AsCString();
188 process_sp->GetTarget().GetDebugger().GetID());
192 if (!return_value_sp)
196 "free",
"Memory deallocated by", result);
198 "alloc",
"Memory allocated by", result);
const char * memory_history_asan_command_prefix
const char * memory_history_asan_command_format
static void CreateHistoryThreadFromValueObject(ProcessSP process_sp, ValueObjectSP return_value_sp, HistoryPCType pc_type, const char *type, const char *thread_name, HistoryThreads &result)
#define LLDB_PLUGIN_DEFINE(PluginName)
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
void SetPreferredSymbolContexts(SymbolContextList contexts)
void SetUnwindOnError(bool unwind=false)
void SetLanguage(lldb::LanguageType language_type)
void SetPrefix(const char *prefix)
void SetTryAllThreads(bool try_others=true)
void SetTimeout(const Timeout< std::micro > &timeout)
void SetAutoApplyFixIts(bool b)
void SetStopOthers(bool stop_others=true)
void SetIgnoreBreakpoints(bool ignore=false)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A thread object representing a backtrace from a previous point in the process execution.
void SetThreadName(const char *name)
MemoryHistoryASan(const lldb::ProcessSP &process_sp)
lldb_private::HistoryThreads GetHistoryThreads(lldb::addr_t address) override
static llvm::StringRef GetPluginNameStatic()
static lldb::MemoryHistorySP CreateInstance(const lldb::ProcessSP &process_sp)
lldb::ProcessWP m_process_wp
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Defines a list of symbol context objects.
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
Defines a symbol context baton that can be handed other debug core functions.
static lldb::ExpressionResults Evaluate(ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, llvm::StringRef expr_cstr, llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp, std::string *fixed_expression=nullptr, ValueObject *ctx_obj=nullptr)
Evaluate one expression in the scratch context of the target passed in the exe_ctx and return its res...
#define LLDB_INVALID_ADDRESS
@ DoNoSelectMostRelevantFrame
A class that represents a running process on the host machine.
std::tuple< lldb::ModuleSP, HistoryPCType > GetPreferredAsanModule(const Target &target)
On Darwin, if LLDB loaded libclang_rt, it's coming from a locally built compiler-rt,...
HistoryPCType
Specifies the type of PCs when creating a HistoryThread.
std::vector< lldb::ThreadSP > HistoryThreads
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
@ eLanguageTypeObjC_plus_plus
Objective-C++.
std::shared_ptr< lldb_private::MemoryHistory > MemoryHistorySP
ExpressionResults
The results of expression evaluation.
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Module > ModuleSP