43lldb::InstrumentationRuntimeSP
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);
111 StackFrameSP frame_sp = thread_sp->GetSelectedFrame();
113 Target &target = process_sp->GetTarget();
125 options.
SetTimeout(process_sp->GetUtilityExpressionTimeout());
130 ValueObjectSP main_value;
133 frame_sp->CalculateExecutionContext(exe_ctx);
136 main_value, eval_error);
139 ss <<
"cannot evaluate UndefinedBehaviorSanitizer expression:\n";
142 process_sp->GetTarget().GetDebugger().GetID());
149 for (
unsigned I = 0; I < thread_sp->GetStackFrameCount(); ++I) {
150 const Address FCA = thread_sp->GetStackFrameAtIndex(I)
151 ->GetFrameCodeAddressForSymbolication();
152 if (FCA.
GetModule() == runtime_module_sp)
159 std::string IssueKind =
RetrieveString(main_value, process_sp,
".issue_kind");
160 std::string ErrMessage =
RetrieveString(main_value, process_sp,
".message");
161 std::string Filename =
RetrieveString(main_value, process_sp,
".filename");
164 uintptr_t MemoryAddr =
169 d->AddStringItem(
"instrumentation_class",
"UndefinedBehaviorSanitizer");
170 d->AddStringItem(
"description", IssueKind);
171 d->AddStringItem(
"summary", ErrMessage);
172 d->AddStringItem(
"filename", Filename);
173 d->AddIntegerItem(
"line", Line);
174 d->AddIntegerItem(
"col", Col);
175 d->AddIntegerItem(
"memory_address", MemoryAddr);
176 d->AddIntegerItem(
"tid", thread_sp->GetID());
177 d->AddItem(
"trace", trace_sp);
182 llvm::StringRef stop_reason_description_ref;
183 report->GetAsDictionary()->GetValueForKeyAsString(
184 "description", stop_reason_description_ref);
185 std::string stop_reason_description =
186 std::string(stop_reason_description_ref);
188 if (!stop_reason_description.size()) {
189 stop_reason_description =
"Undefined behavior detected";
191 stop_reason_description[0] = toupper(stop_reason_description[0]);
192 for (
unsigned I = 1; I < stop_reason_description.size(); ++I)
193 if (stop_reason_description[I] ==
'-')
194 stop_reason_description[I] =
' ';
196 return stop_reason_description;
202 assert(baton &&
"null baton");
211 if (!process_sp || !thread_sp ||
215 if (process_sp->GetModIDRef().IsLastResumeForUserExpression())
222 thread_sp->SetStopInfo(
238 const lldb::ModuleSP module_sp) {
239 static ConstString ubsan_test_sym(
"__ubsan_on_report");
240 const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
242 return symbol !=
nullptr;
257 const Symbol *symbol = runtime_module_sp->FindFirstSymbolWithNameAndType(
260 if (symbol ==
nullptr)
266 Target &target = process_sp->GetTarget();
277 const bool sync =
false;
294 process_sp->GetTarget().RemoveBreakpointByID(BID);
299lldb::ThreadCollectionSP
302 ThreadCollectionSP threads;
303 threads = std::make_shared<ThreadCollection>();
307 if (info->GetObjectForDotSeparatedPath(
"instrumentation_class")
308 ->GetStringValue() !=
"UndefinedBehaviorSanitizer")
311 std::vector<lldb::addr_t> PCs;
312 auto trace = info->GetObjectForDotSeparatedPath(
"trace")->GetAsArray();
322 info->GetObjectForDotSeparatedPath(
"tid");
323 tid_t tid = thread_id_obj ? thread_id_obj->GetIntegerValue() : 0;
327 bool pcs_are_call_addresses =
true;
328 ThreadSP new_thread_sp = std::make_shared<HistoryThread>(
329 *process_sp, tid, PCs, pcs_are_call_addresses);
331 new_thread_sp->SetName(stop_reason_description.c_str());
335 process_sp->GetExtendedThreadList().AddThread(new_thread_sp);
336 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 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)
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)
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
A stream class that can stream formatted output to a file.
void AddItem(const ObjectSP &item)
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
@ eInstrumentationRuntimeTypeUndefinedBehaviorSanitizer