28#include "llvm/ADT/StringSwitch.h"
35lldb::InstrumentationRuntimeSP
60 llvm::StringRef(
"libclang_rt.asan_(.*)_dynamic\\.dylib"));
65 const lldb::ModuleSP module_sp) {
66 const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
69 return symbol !=
nullptr;
75int __asan_report_present();
76void *__asan_get_report_pc();
77void *__asan_get_report_bp();
78void *__asan_get_report_sp();
79void *__asan_get_report_address();
80const char *__asan_get_report_description();
81int __asan_get_report_access_type();
82size_t __asan_get_report_access_size();
95 const char *description;
98t.present = __asan_report_present();
99t.access_type = __asan_get_report_access_type();
100t.pc = __asan_get_report_pc();
101t.bp = __asan_get_report_bp();
102t.sp = __asan_get_report_sp();
103t.address = __asan_get_report_address();
104t.access_size = __asan_get_report_access_size();
105t.description = __asan_get_report_description();
115 process_sp->GetThreadList().GetExpressionExecutionThread();
116 StackFrameSP frame_sp = thread_sp->GetSelectedFrame();
126 options.
SetTimeout(process_sp->GetUtilityExpressionTimeout());
131 ValueObjectSP return_value_sp;
134 frame_sp->CalculateExecutionContext(exe_ctx);
137 return_value_sp, eval_error);
140 ss <<
"cannot evaluate AddressSanitizer expression:\n";
143 process_sp->GetTarget().GetDebugger().GetID());
147 int present = return_value_sp->GetValueForExpressionPath(
".present")
148 ->GetValueAsUnsigned(0);
153 return_value_sp->GetValueForExpressionPath(
".pc")->GetValueAsUnsigned(0);
160 addr_t address = return_value_sp->GetValueForExpressionPath(
".address")
161 ->GetValueAsUnsigned(0);
163 return_value_sp->GetValueForExpressionPath(
".access_type")
164 ->GetValueAsUnsigned(0);
166 return_value_sp->GetValueForExpressionPath(
".access_size")
167 ->GetValueAsUnsigned(0);
169 return_value_sp->GetValueForExpressionPath(
".description")
170 ->GetValueAsUnsigned(0);
171 std::string description;
173 process_sp->ReadCStringFromMemory(description_ptr, description,
error);
176 dict->
AddStringItem(
"instrumentation_class",
"AddressSanitizer");
193 std::string description = std::string(report->GetAsDictionary()
194 ->GetValueForKey(
"description")
197 return llvm::StringSwitch<std::string>(description)
198 .Case(
"heap-use-after-free",
"Use of deallocated memory")
199 .Case(
"heap-buffer-overflow",
"Heap buffer overflow")
200 .Case(
"stack-buffer-underflow",
"Stack buffer underflow")
201 .Case(
"initialization-order-fiasco",
"Initialization order problem")
202 .Case(
"stack-buffer-overflow",
"Stack buffer overflow")
203 .Case(
"stack-use-after-return",
"Use of stack memory after return")
204 .Case(
"use-after-poison",
"Use of poisoned memory")
205 .Case(
"container-overflow",
"Container overflow")
206 .Case(
"stack-use-after-scope",
"Use of out-of-scope stack memory")
207 .Case(
"global-buffer-overflow",
"Global buffer overflow")
208 .Case(
"unknown-crash",
"Invalid memory access")
209 .Case(
"stack-overflow",
"Stack space exhausted")
210 .Case(
"null-deref",
"Dereference of null pointer")
211 .Case(
"wild-jump",
"Jump to non-executable address")
212 .Case(
"wild-addr-write",
"Write through wild pointer")
213 .Case(
"wild-addr-read",
"Read from wild pointer")
214 .Case(
"wild-addr",
"Access through wild pointer")
215 .Case(
"signal",
"Deadly signal")
216 .Case(
"double-free",
"Deallocation of freed memory")
217 .Case(
"new-delete-type-mismatch",
218 "Deallocation size different from allocation size")
219 .Case(
"bad-free",
"Deallocation of non-allocated memory")
220 .Case(
"alloc-dealloc-mismatch",
221 "Mismatch between allocation and deallocation APIs")
222 .Case(
"bad-malloc_usable_size",
"Invalid argument to malloc_usable_size")
223 .Case(
"bad-__sanitizer_get_allocated_size",
224 "Invalid argument to __sanitizer_get_allocated_size")
225 .Case(
"param-overlap",
226 "Call to function disallowing overlapping memory ranges")
227 .Case(
"negative-size-param",
"Negative size used when accessing memory")
228 .Case(
"bad-__sanitizer_annotate_contiguous_container",
229 "Invalid argument to __sanitizer_annotate_contiguous_container")
230 .Case(
"odr-violation",
"Symbol defined in multiple translation units")
232 "invalid-pointer-pair",
233 "Comparison or arithmetic on pointers from different memory regions")
235 .Default(
"AddressSanitizer detected: " + description);
241 assert(baton &&
"null baton");
250 if (process_sp->GetModIDRef().IsLastResumeForUserExpression())
254 std::string description;
263 CreateStopReasonWithInstrumentationData(
264 *thread_sp, description, report));
266 StreamFileSP stream_sp(
267 process_sp->GetTarget().GetDebugger().GetOutputStreamSP());
269 stream_sp->Printf(
"AddressSanitizer report breakpoint hit. Use 'thread "
270 "info -s' to get extended information about the "
290 if (symbol ==
nullptr)
296 Target &target = process_sp->GetTarget();
302 const bool internal =
true;
303 const bool hardware =
false;
304 const bool sync =
false;
static llvm::raw_ostream & error(Stream &strm)
const char * address_sanitizer_retrieve_report_data_command
const char * address_sanitizer_retrieve_report_data_prefix
#define LLDB_PLUGIN_DEFINE(PluginName)
lldb::addr_t GetOpcodeLoadAddress(Target *target, AddressClass addr_class=AddressClass::eInvalid) const
Get the load address as an opcode load address.
bool IsValid() const
Check if the object state is valid.
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
void SetBreakpointKind(const char *kind)
Set the "kind" description for a breakpoint.
Target & GetTarget()
Accessor for the breakpoint Target.
void SetCallback(BreakpointHitCallback callback, void *baton, bool is_synchronous=false)
Set the callback action invoked when the breakpoint is hit.
A uniqued constant string class.
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 SetLanguage(lldb::LanguageType language)
void SetUnwindOnError(bool unwind=false)
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::ThreadSP GetThreadSP() const
Get accessor that creates a strong reference from the weak thread reference contained in this object.
lldb::ProcessSP GetProcessSP() const
Get accessor that creates a strong reference from the weak process reference contained in this object...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
static lldb::InstrumentationRuntimeType GetTypeStatic()
static bool NotifyBreakpointHit(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
~InstrumentationRuntimeASan() override
void Activate() override
Register a breakpoint in the runtime library and perform any other necessary initialization.
static lldb::InstrumentationRuntimeSP CreateInstance(const lldb::ProcessSP &process_sp)
std::string FormatDescription(StructuredData::ObjectSP report)
StructuredData::ObjectSP RetrieveReportData()
static llvm::StringRef GetPluginNameStatic()
const RegularExpression & GetPatternForRuntimeLibrary() override
Return a regular expression which can be used to identify a valid version of the runtime library.
bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) override
Check whether module_sp corresponds to a valid runtime library.
void SetBreakpointID(lldb::user_id_t ID)
void SetActive(bool IsActive)
lldb::user_id_t GetBreakpointID() const
lldb::ModuleSP GetRuntimeModuleSP()
lldb::ProcessSP GetProcessSP()
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
ExecutionContextRef exe_ctx_ref
lldb::break_id_t GetID() const
llvm::StringRef GetString() const
void AddIntegerItem(llvm::StringRef key, uint64_t value)
void AddStringItem(llvm::StringRef key, llvm::StringRef value)
std::shared_ptr< Object > ObjectSP
bool ValueIsAddress() const
Address & GetAddressRef()
lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, uint32_t column, lldb::addr_t offset, LazyBool check_inlines, LazyBool skip_prologue, bool internal, bool request_hardware, LazyBool move_to_nearest_code)
static lldb::ExpressionResults Evaluate(ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, llvm::StringRef expr_cstr, llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp, Status &error, 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_BREAK_ID
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
ExpressionResults
The results of expression evaluation.
InstrumentationRuntimeType
@ eInstrumentationRuntimeTypeAddressSanitizer