51 "UndefinedBehaviorSanitizer instrumentation runtime plugin.",
66__ubsan_get_current_report_data(const char **OutIssueKind,
67 const char **OutMessage, const char **OutFilename, unsigned *OutLine,
68 unsigned *OutCol, char **OutMemoryAddr);
74 const char *issue_kind;
82__ubsan_get_current_report_data(&t.issue_kind, &t.message, &t.filename, &t.line,
83 &t.col, &t.memory_addr);
89 const std::string &expression_path) {
90 return return_value_sp->GetValueForExpressionPath(expression_path.c_str())
91 ->GetValueAsUnsigned(0);
96 const std::string &expression_path) {
100 process_sp->ReadCStringFromMemory(ptr, str,
error);
114 Target &target = process_sp->GetTarget();
126 options.
SetTimeout(process_sp->GetUtilityExpressionTimeout());
133 frame_sp->CalculateExecutionContext(exe_ctx);
139 ss <<
"cannot evaluate UndefinedBehaviorSanitizer expression:\n";
141 ss << main_value->GetError().AsCString();
143 process_sp->GetTarget().GetDebugger().GetID());
150 for (
unsigned I = 0; I < thread_sp->GetStackFrameCount(); ++I) {
151 const Address FCA = thread_sp->GetStackFrameAtIndex(I)
152 ->GetFrameCodeAddressForSymbolication();
153 if (FCA.
GetModule() == runtime_module_sp)
160 std::string IssueKind =
RetrieveString(main_value, process_sp,
".issue_kind");
161 std::string ErrMessage =
RetrieveString(main_value, process_sp,
".message");
162 std::string Filename =
RetrieveString(main_value, process_sp,
".filename");
165 uintptr_t MemoryAddr =
170 d->AddStringItem(
"instrumentation_class",
"UndefinedBehaviorSanitizer");
171 d->AddStringItem(
"description", IssueKind);
172 d->AddStringItem(
"summary", ErrMessage);
173 d->AddStringItem(
"filename", Filename);
174 d->AddIntegerItem(
"line", Line);
175 d->AddIntegerItem(
"col", Col);
176 d->AddIntegerItem(
"memory_address", MemoryAddr);
177 d->AddIntegerItem(
"tid", thread_sp->GetID());
178 d->AddItem(
"trace", trace_sp);
183 llvm::StringRef stop_reason_description_ref;
184 report->GetAsDictionary()->GetValueForKeyAsString(
185 "description", stop_reason_description_ref);
186 std::string stop_reason_description =
187 std::string(stop_reason_description_ref);
189 if (!stop_reason_description.size()) {
190 stop_reason_description =
"Undefined behavior detected";
192 stop_reason_description[0] = toupper(stop_reason_description[0]);
193 for (
unsigned I = 1; I < stop_reason_description.size(); ++I)
194 if (stop_reason_description[I] ==
'-')
195 stop_reason_description[I] =
' ';
197 return stop_reason_description;
203 assert(baton &&
"null baton");
212 if (!process_sp || !thread_sp ||
216 if (process_sp->GetModIDRef().IsLastResumeForUserExpression())
223 thread_sp->SetStopInfo(
240 static ConstString ubsan_test_sym(
"__ubsan_on_report");
241 const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
243 return symbol !=
nullptr;
258 const Symbol *symbol = runtime_module_sp->FindFirstSymbolWithNameAndType(
261 if (symbol ==
nullptr)
267 Target &target = process_sp->GetTarget();
278 const bool sync =
false;
295 process_sp->GetTarget().RemoveBreakpointByID(BID);
304 threads = std::make_shared<ThreadCollection>();
308 if (info->GetObjectForDotSeparatedPath(
"instrumentation_class")
309 ->GetStringValue() !=
"UndefinedBehaviorSanitizer")
312 std::vector<lldb::addr_t> PCs;
313 auto trace = info->GetObjectForDotSeparatedPath(
"trace")->GetAsArray();
323 info->GetObjectForDotSeparatedPath(
"tid");
325 thread_id_obj ? thread_id_obj->GetUnsignedIntegerValue() : 0;
329 bool pcs_are_call_addresses =
true;
330 ThreadSP new_thread_sp = std::make_shared<HistoryThread>(
331 *process_sp, tid, PCs, pcs_are_call_addresses);
333 new_thread_sp->SetName(stop_reason_description.c_str());
337 process_sp->GetExtendedThreadList().AddThread(new_thread_sp);
338 threads->AddThread(new_thread_sp);
static llvm::raw_ostream & error(Stream &strm)
static std::string RetrieveString(ValueObjectSP return_value_sp, ProcessSP process_sp, const std::string &expression_path)
static addr_t RetrieveUnsigned(ValueObjectSP return_value_sp, ProcessSP process_sp, const std::string &expression_path)
static const char * ub_sanitizer_retrieve_report_data_command
static std::string GetStopReasonDescription(StructuredData::ObjectSP report)
static const char * ub_sanitizer_retrieve_report_data_prefix
#define LLDB_PLUGIN_DEFINE(PluginName)
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
lldb::addr_t GetOpcodeLoadAddress(Target *target, AddressClass addr_class=AddressClass::eInvalid) const
Get the load address as an opcode load address.
lldb::ModuleSP GetModule() const
Get accessor for the module for this 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.
lldb::StreamFileSP GetOutputStreamSP()
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)
Execution context objects refer to objects in the execution of the program that is being debugged.
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::StopInfoSP CreateStopReasonWithInstrumentationData(Thread &thread, std::string description, StructuredData::ObjectSP additional_data)
void Activate() override
Register a breakpoint in the runtime library and perform any other necessary initialization.
static lldb::InstrumentationRuntimeType GetTypeStatic()
static bool NotifyBreakpointHit(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) override
Check whether module_sp corresponds to a valid runtime library.
StructuredData::ObjectSP RetrieveReportData(ExecutionContextRef exe_ctx_ref)
lldb::ThreadCollectionSP GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) override
const RegularExpression & GetPatternForRuntimeLibrary() override
Return a regular expression which can be used to identify a valid version of the runtime library.
static lldb::InstrumentationRuntimeSP CreateInstance(const lldb::ProcessSP &process_sp)
static llvm::StringRef GetPluginNameStatic()
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)
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
A stream class that can stream formatted output to a file.
void AddIntegerItem(T value)
uint64_t GetUnsignedIntegerValue(uint64_t fail_value=0)
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, 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
@ DoNoSelectMostRelevantFrame
A class that represents a running process on the host machine.
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++.
ExpressionResults
The results of expression evaluation.
std::shared_ptr< lldb_private::Process > ProcessSP
InstrumentationRuntimeType
@ eInstrumentationRuntimeTypeUndefinedBehaviorSanitizer
std::shared_ptr< lldb_private::StreamFile > StreamFileSP
std::shared_ptr< lldb_private::InstrumentationRuntime > InstrumentationRuntimeSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::ThreadCollection > ThreadCollectionSP