269 std::map<uint64_t, user_id_t> &thread_id_map) {
271 data,
".threads",
".thread_count",
275 o->GetValueForExpressionPath(
".tid")->GetValueAsUnsigned(0);
276 uint64_t thread_os_id =
277 o->GetValueForExpressionPath(
".os_id")->GetValueAsUnsigned(0);
280 bool can_update =
true;
281 ThreadSP lldb_thread = process_sp->GetThreadList().FindThreadByID(
282 thread_os_id, can_update);
284 lldb_user_id = lldb_thread->GetIndexID();
290 lldb_user_id = process_sp->AssignIndexIDToThread(thread_os_id);
293 thread_id_map[thread_id] = lldb_user_id;
324 options.
SetTimeout(process_sp->GetUtilityExpressionTimeout());
331 frame_sp->CalculateExecutionContext(exe_ctx);
337 ss <<
"cannot evaluate ThreadSanitizer expression:\n";
339 ss << main_value->GetError().AsCString();
341 process_sp->GetTarget().GetDebugger().GetID());
345 std::map<uint64_t, user_id_t> thread_id_map;
348 auto dict = std::make_shared<StructuredData::Dictionary>();
349 dict->AddStringItem(
"instrumentation_class",
"ThreadSanitizer");
350 dict->AddStringItem(
"issue_type",
352 dict->AddIntegerItem(
"report_count",
353 main_value->GetValueForExpressionPath(
".report_count")
354 ->GetValueAsUnsigned(0));
356 main_value,
".sleep_trace"));
359 main_value,
".stacks",
".stack_count",
362 dict->AddIntegerItem(
364 o->GetValueForExpressionPath(
".idx")->GetValueAsUnsigned(0));
367 dict->AddIntegerItem(
"thread_id", thread_sp->GetIndexID());
369 dict->AddItem(
"stacks", stacks);
372 main_value,
".mops",
".mop_count",
375 dict->AddIntegerItem(
377 o->GetValueForExpressionPath(
".idx")->GetValueAsUnsigned(0));
378 dict->AddIntegerItem(
381 o->GetValueForExpressionPath(
".tid")->GetValueAsUnsigned(0),
383 dict->AddIntegerItem(
385 o->GetValueForExpressionPath(
".size")->GetValueAsUnsigned(0));
386 dict->AddBooleanItem(
388 o->GetValueForExpressionPath(
".write")->GetValueAsUnsigned(0));
389 dict->AddBooleanItem(
391 o->GetValueForExpressionPath(
".atomic")->GetValueAsUnsigned(0));
392 dict->AddIntegerItem(
394 o->GetValueForExpressionPath(
".addr")->GetValueAsUnsigned(0));
397 dict->AddItem(
"mops", mops);
400 main_value,
".locs",
".loc_count",
403 dict->AddIntegerItem(
405 o->GetValueForExpressionPath(
".idx")->GetValueAsUnsigned(0));
406 dict->AddStringItem(
"type",
RetrieveString(o, process_sp,
".type"));
407 dict->AddIntegerItem(
409 o->GetValueForExpressionPath(
".addr")->GetValueAsUnsigned(0));
410 dict->AddIntegerItem(
412 o->GetValueForExpressionPath(
".start")->GetValueAsUnsigned(0));
413 dict->AddIntegerItem(
415 o->GetValueForExpressionPath(
".size")->GetValueAsUnsigned(0));
416 dict->AddIntegerItem(
419 o->GetValueForExpressionPath(
".tid")->GetValueAsUnsigned(0),
421 dict->AddIntegerItem(
423 o->GetValueForExpressionPath(
".fd")->GetValueAsUnsigned(0));
424 dict->AddIntegerItem(
"suppressable",
425 o->GetValueForExpressionPath(
".suppressable")
426 ->GetValueAsUnsigned(0));
428 dict->AddStringItem(
"object_type",
431 dict->AddItem(
"locs", locs);
434 main_value,
".mutexes",
".mutex_count",
436 dict->AddIntegerItem(
438 o->GetValueForExpressionPath(
".idx")->GetValueAsUnsigned(0));
439 dict->AddIntegerItem(
441 o->GetValueForExpressionPath(
".mutex_id")->GetValueAsUnsigned(0));
442 dict->AddIntegerItem(
444 o->GetValueForExpressionPath(
".addr")->GetValueAsUnsigned(0));
445 dict->AddIntegerItem(
447 o->GetValueForExpressionPath(
".destroyed")->GetValueAsUnsigned(0));
450 dict->AddItem(
"mutexes", mutexes);
453 main_value,
".threads",
".thread_count",
456 dict->AddIntegerItem(
458 o->GetValueForExpressionPath(
".idx")->GetValueAsUnsigned(0));
459 dict->AddIntegerItem(
462 o->GetValueForExpressionPath(
".tid")->GetValueAsUnsigned(0),
464 dict->AddIntegerItem(
466 o->GetValueForExpressionPath(
".os_id")->GetValueAsUnsigned(0));
467 dict->AddIntegerItem(
469 o->GetValueForExpressionPath(
".running")->GetValueAsUnsigned(0));
470 dict->AddStringItem(
"name",
RetrieveString(o, process_sp,
".name"));
471 dict->AddIntegerItem(
473 Renumber(o->GetValueForExpressionPath(
".parent_tid")
474 ->GetValueAsUnsigned(0),
478 dict->AddItem(
"threads", threads);
481 main_value,
".unique_tids",
".unique_tid_count",
484 dict->AddIntegerItem(
486 o->GetValueForExpressionPath(
".idx")->GetValueAsUnsigned(0));
487 dict->AddIntegerItem(
490 o->GetValueForExpressionPath(
".tid")->GetValueAsUnsigned(0),
493 dict->AddItem(
"unique_tids", unique_tids);
622 std::string summary = std::string(report->GetAsDictionary()
623 ->GetValueForKey(
"description")
626 bool skip_one_frame =
627 report->GetObjectForDotSeparatedPath(
"issue_type")->GetStringValue() ==
631 if (report->GetAsDictionary()
632 ->GetValueForKey(
"mops")
636 ->GetValueForKey(
"mops")
640 ->GetValueForKey(
"trace"),
643 if (report->GetAsDictionary()
644 ->GetValueForKey(
"stacks")
648 ->GetValueForKey(
"stacks")
652 ->GetValueForKey(
"trace"),
659 if (report->GetAsDictionary()
660 ->GetValueForKey(
"locs")
664 ->GetValueForKey(
"locs")
667 std::string object_type = std::string(loc->GetAsDictionary()
668 ->GetValueForKey(
"object_type")
671 if (!object_type.empty()) {
672 summary =
"Race on " + object_type +
" object";
674 addr_t addr = loc->GetAsDictionary()
675 ->GetValueForKey(
"address")
676 ->GetUnsignedIntegerValue();
678 addr = loc->GetAsDictionary()
679 ->GetValueForKey(
"start")
680 ->GetUnsignedIntegerValue();
684 if (!global_name.empty()) {
685 summary = summary +
" at " + global_name;
687 summary = summary +
" at " +
Sprintf(
"0x%llx", addr);
690 int fd = loc->GetAsDictionary()
691 ->GetValueForKey(
"file_descriptor")
692 ->GetSignedIntegerValue();
694 summary = summary +
" on file descriptor " +
Sprintf(
"%d", fd);
720 std::string &global_name, std::string &filename, uint32_t &line) {
725 if (report->GetAsDictionary()
726 ->GetValueForKey(
"locs")
730 ->GetValueForKey(
"locs")
733 std::string type = std::string(
734 loc->GetAsDictionary()->GetValueForKey(
"type")->GetStringValue());
735 if (type ==
"global") {
736 global_addr = loc->GetAsDictionary()
737 ->GetValueForKey(
"address")
738 ->GetUnsignedIntegerValue();
741 if (!global_name.empty()) {
742 result =
Sprintf(
"'%s' is a global variable (0x%llx)",
743 global_name.c_str(), global_addr);
745 result =
Sprintf(
"0x%llx is a global variable", global_addr);
754 }
else if (type ==
"heap") {
755 addr_t addr = loc->GetAsDictionary()
756 ->GetValueForKey(
"start")
757 ->GetUnsignedIntegerValue();
759 size_t size = loc->GetAsDictionary()
760 ->GetValueForKey(
"size")
761 ->GetUnsignedIntegerValue();
763 std::string object_type = std::string(loc->GetAsDictionary()
764 ->GetValueForKey(
"object_type")
767 if (!object_type.empty()) {
768 result =
Sprintf(
"Location is a %ld-byte %s object at 0x%llx", size,
769 object_type.c_str(), addr);
772 Sprintf(
"Location is a %ld-byte heap object at 0x%llx", size, addr);
774 }
else if (type ==
"stack") {
776 ->GetValueForKey(
"thread_id")
777 ->GetUnsignedIntegerValue();
779 result =
Sprintf(
"Location is stack of thread %d", tid);
780 }
else if (type ==
"tls") {
782 ->GetValueForKey(
"thread_id")
783 ->GetUnsignedIntegerValue();
785 result =
Sprintf(
"Location is TLS of thread %d", tid);
786 }
else if (type ==
"fd") {
787 int fd = loc->GetAsDictionary()
788 ->GetValueForKey(
"file_descriptor")
789 ->GetSignedIntegerValue();
791 result =
Sprintf(
"Location is file descriptor %d", fd);
801 assert(baton &&
"null baton");
810 if (process_sp->GetModIDRef().IsLastResumeForUserExpression())
815 std::string stop_reason_description =
816 "unknown thread sanitizer fault (unable to extract thread sanitizer "
820 report->GetAsDictionary()->AddStringItem(
"description", issue_description);
821 stop_reason_description = issue_description +
" detected";
822 report->GetAsDictionary()->AddStringItem(
"stop_description",
823 stop_reason_description);
825 report->GetAsDictionary()->AddStringItem(
"summary", summary);
827 report->GetAsDictionary()->AddIntegerItem(
"memory_address", main_address);
830 std::string global_name;
831 std::string location_filename;
832 uint32_t location_line = 0;
834 report, global_addr, global_name, location_filename, location_line);
835 report->GetAsDictionary()->AddStringItem(
"location_description",
836 location_description);
837 if (global_addr != 0) {
838 report->GetAsDictionary()->AddIntegerItem(
"global_address", global_addr);
840 if (!global_name.empty()) {
841 report->GetAsDictionary()->AddStringItem(
"global_name", global_name);
843 if (location_filename !=
"") {
844 report->GetAsDictionary()->AddStringItem(
"location_filename",
846 report->GetAsDictionary()->AddIntegerItem(
"location_line", location_line);
849 bool all_addresses_are_same =
true;
850 report->GetObjectForDotSeparatedPath(
"mops")->GetAsArray()->ForEach(
851 [&all_addresses_are_same,
854 ->GetUnsignedIntegerValue();
855 if (main_address != addr)
856 all_addresses_are_same =
false;
859 report->GetAsDictionary()->AddBooleanItem(
"all_addresses_are_same",
860 all_addresses_are_same);
867 thread_sp->SetStopInfo(
869 CreateStopReasonWithInstrumentationData(
870 *thread_sp, stop_reason_description, report));
873 process_sp->GetTarget().GetDebugger().GetAsyncOutputStream();
874 s->Printf(
"ThreadSanitizer report breakpoint hit. Use 'thread "
875 "info -s' to get extended information about the "
949 std::string result =
"additional information";
951 if (path ==
"mops") {
963 std::string addr_string =
Sprintf(
" at 0x%llx", addr);
965 if (main_info->GetObjectForDotSeparatedPath(
"all_addresses_are_same")
966 ->GetBooleanValue()) {
970 if (main_info->GetObjectForDotSeparatedPath(
"issue_type")
971 ->GetStringValue() ==
"external-race") {
972 result =
Sprintf(
"%s access by thread %d",
973 is_write ?
"mutating" :
"read-only", thread_id);
974 }
else if (main_info->GetObjectForDotSeparatedPath(
"issue_type")
975 ->GetStringValue() ==
"swift-access-race") {
976 result =
Sprintf(
"modifying access by thread %d", thread_id);
978 result =
Sprintf(
"%s%s of size %zu%s by thread %" PRIu64,
979 is_atomic ?
"atomic " :
"", is_write ?
"write" :
"read",
980 size, addr_string.c_str(), thread_id);
984 if (path ==
"threads") {
987 result =
Sprintf(
"Thread %zu created", thread_id);
990 if (path ==
"locs") {
991 std::string type = std::string(
996 ->GetSignedIntegerValue();
997 if (type ==
"heap") {
998 result =
Sprintf(
"Heap block allocated by thread %" PRIu64, thread_id);
999 }
else if (type ==
"fd") {
1000 result =
Sprintf(
"File descriptor %d created by thread %" PRIu64, fd,
1005 if (path ==
"mutexes") {
1009 result =
Sprintf(
"Mutex M%d created", mutex_id);
1012 if (path ==
"stacks") {
1015 result =
Sprintf(
"Thread %" PRIu64, thread_id);
1018 result[0] = toupper(result[0]);
1026 info->GetObjectForDotSeparatedPath(path)->GetAsArray()->ForEach(
1028 std::vector<lldb::addr_t> pcs;
1031 pcs.push_back(
pc->GetUnsignedIntegerValue());
1035 if (pcs.size() == 0)
1041 thread_id_obj ? thread_id_obj->GetUnsignedIntegerValue() : 0;
1044 std::make_shared<HistoryThread>(*process_sp, tid, pcs);
1049 process_sp->GetExtendedThreadList().AddThread(new_thread_sp);
1050 threads->AddThread(new_thread_sp);
1062 if (info->GetObjectForDotSeparatedPath(
"instrumentation_class")
1063 ->GetStringValue() !=
"ThreadSanitizer")
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *>
Report warning events.
A class that describes the declaration location of a lldb object.
uint32_t GetLine() const
Get accessor for the declaration line number.
FileSpec & GetFile()
Get accessor for file specification.
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.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
StructuredData::ObjectSP RetrieveReportData(ExecutionContextRef exe_ctx_ref)
bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) override
Check whether module_sp corresponds to a valid runtime library.
std::string GetLocationDescription(StructuredData::ObjectSP report, lldb::addr_t &global_addr, std::string &global_name, std::string &filename, uint32_t &line)
const RegularExpression & GetPatternForRuntimeLibrary() override
Return a regular expression which can be used to identify a valid version of the runtime library.
~InstrumentationRuntimeTSan() override
static llvm::StringRef GetPluginNameStatic()
lldb::addr_t GetMainRacyAddress(StructuredData::ObjectSP report)
static lldb::InstrumentationRuntimeSP CreateInstance(const lldb::ProcessSP &process_sp)
static lldb::InstrumentationRuntimeType GetTypeStatic()
void Activate() override
Register a breakpoint in the runtime library and perform any other necessary initialization.
static bool NotifyBreakpointHit(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
InstrumentationRuntimeTSan(const lldb::ProcessSP &process_sp)
lldb::addr_t GetFirstNonInternalFramePc(StructuredData::ObjectSP trace, bool skip_one_frame=false)
std::string GenerateSummary(StructuredData::ObjectSP report)
lldb::ThreadCollectionSP GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) override
std::string FormatDescription(StructuredData::ObjectSP report)
void SetBreakpointID(lldb::user_id_t ID)
void SetActive(bool IsActive)
lldb::user_id_t GetBreakpointID() const
lldb::ModuleSP GetRuntimeModuleSP()
lldb::ProcessSP GetProcessSP()
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
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
size_t size_t PrintfVarArg(const char *format, va_list args)
std::optional< IntType > GetItemAtIndexAsInteger(size_t idx) const
ObjectSP GetValueForKey(llvm::StringRef key) const
Dictionary * GetAsDictionary()
ObjectSP GetObjectForDotSeparatedPath(llvm::StringRef path)
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
std::shared_ptr< Array > ArraySP
bool ValueIsAddress() const
lldb::ModuleSP CalculateSymbolContextModule() override
Address & GetAddressRef()
ConstString GetName() const
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...
lldb::VariableSP GetVariableAtIndex(size_t idx) const
#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
@ eLanguageTypeC
Non-standardized C, such as K&R.
std::shared_ptr< lldb_private::Stream > StreamSP
ExpressionResults
The results of expression evaluation.
std::shared_ptr< lldb_private::Process > ProcessSP
InstrumentationRuntimeType
@ eInstrumentationRuntimeTypeThreadSanitizer
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::InstrumentationRuntime > InstrumentationRuntimeSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::ThreadCollection > ThreadCollectionSP