1
- // ===-- TSanRuntime .cpp --------------- --------------------------*- C++ -*-===//
1
+ // ===-- InstrumentationRuntimeTSan .cpp --------------------------*- C++ -*-===//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
5
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
9
- #include " TSanRuntime .h"
9
+ #include " InstrumentationRuntimeTSan .h"
10
10
11
11
#include " Plugins/Process/Utility/HistoryThread.h"
12
12
#include " lldb/Breakpoint/StoppointCallbackContext.h"
@@ -36,29 +36,29 @@ using namespace lldb;
36
36
using namespace lldb_private ;
37
37
38
38
lldb::InstrumentationRuntimeSP
39
- ThreadSanitizerRuntime ::CreateInstance (const lldb::ProcessSP &process_sp) {
40
- return InstrumentationRuntimeSP (new ThreadSanitizerRuntime (process_sp));
39
+ InstrumentationRuntimeTSan ::CreateInstance (const lldb::ProcessSP &process_sp) {
40
+ return InstrumentationRuntimeSP (new InstrumentationRuntimeTSan (process_sp));
41
41
}
42
42
43
- void ThreadSanitizerRuntime ::Initialize () {
43
+ void InstrumentationRuntimeTSan ::Initialize () {
44
44
PluginManager::RegisterPlugin (
45
45
GetPluginNameStatic (), " ThreadSanitizer instrumentation runtime plugin." ,
46
46
CreateInstance, GetTypeStatic);
47
47
}
48
48
49
- void ThreadSanitizerRuntime ::Terminate () {
49
+ void InstrumentationRuntimeTSan ::Terminate () {
50
50
PluginManager::UnregisterPlugin (CreateInstance);
51
51
}
52
52
53
- lldb_private::ConstString ThreadSanitizerRuntime ::GetPluginNameStatic () {
53
+ lldb_private::ConstString InstrumentationRuntimeTSan ::GetPluginNameStatic () {
54
54
return ConstString (" ThreadSanitizer" );
55
55
}
56
56
57
- lldb::InstrumentationRuntimeType ThreadSanitizerRuntime ::GetTypeStatic () {
57
+ lldb::InstrumentationRuntimeType InstrumentationRuntimeTSan ::GetTypeStatic () {
58
58
return eInstrumentationRuntimeTypeThreadSanitizer;
59
59
}
60
60
61
- ThreadSanitizerRuntime ::~ThreadSanitizerRuntime () { Deactivate (); }
61
+ InstrumentationRuntimeTSan ::~InstrumentationRuntimeTSan () { Deactivate (); }
62
62
63
63
const char *thread_sanitizer_retrieve_report_data_prefix = R"(
64
64
extern "C"
@@ -84,7 +84,7 @@ extern "C"
84
84
int *running, const char **name, int *parent_tid,
85
85
void **trace, unsigned long trace_size);
86
86
int __tsan_get_report_unique_tid(void *report, unsigned long idx, int *tid);
87
-
87
+
88
88
// TODO: dlsym won't work on Windows.
89
89
void *dlsym(void* handle, const char* symbol);
90
90
int (*ptr__tsan_get_report_loc_object_type)(void *report, unsigned long idx, const char **object_type);
@@ -97,15 +97,15 @@ struct data {
97
97
void *report;
98
98
const char *description;
99
99
int report_count;
100
-
100
+
101
101
void *sleep_trace[REPORT_TRACE_SIZE];
102
-
102
+
103
103
int stack_count;
104
104
struct {
105
105
int idx;
106
106
void *trace[REPORT_TRACE_SIZE];
107
107
} stacks[REPORT_ARRAY_SIZE];
108
-
108
+
109
109
int mop_count;
110
110
struct {
111
111
int idx;
@@ -116,7 +116,7 @@ struct data {
116
116
void *addr;
117
117
void *trace[REPORT_TRACE_SIZE];
118
118
} mops[REPORT_ARRAY_SIZE];
119
-
119
+
120
120
int loc_count;
121
121
struct {
122
122
int idx;
@@ -130,7 +130,7 @@ struct data {
130
130
void *trace[REPORT_TRACE_SIZE];
131
131
const char *object_type;
132
132
} locs[REPORT_ARRAY_SIZE];
133
-
133
+
134
134
int mutex_count;
135
135
struct {
136
136
int idx;
@@ -139,7 +139,7 @@ struct data {
139
139
int destroyed;
140
140
void *trace[REPORT_TRACE_SIZE];
141
141
} mutexes[REPORT_ARRAY_SIZE];
142
-
142
+
143
143
int thread_count;
144
144
struct {
145
145
int idx;
@@ -150,7 +150,7 @@ struct data {
150
150
int parent_tid;
151
151
void *trace[REPORT_TRACE_SIZE];
152
152
} threads[REPORT_ARRAY_SIZE];
153
-
153
+
154
154
int unique_tid_count;
155
155
struct {
156
156
int idx;
@@ -299,8 +299,8 @@ static user_id_t Renumber(uint64_t id,
299
299
return IT->second ;
300
300
}
301
301
302
- StructuredData::ObjectSP
303
- ThreadSanitizerRuntime::RetrieveReportData ( ExecutionContextRef exe_ctx_ref) {
302
+ StructuredData::ObjectSP InstrumentationRuntimeTSan::RetrieveReportData (
303
+ ExecutionContextRef exe_ctx_ref) {
304
304
ProcessSP process_sp = GetProcessSP ();
305
305
if (!process_sp)
306
306
return StructuredData::ObjectSP ();
@@ -486,7 +486,7 @@ ThreadSanitizerRuntime::RetrieveReportData(ExecutionContextRef exe_ctx_ref) {
486
486
}
487
487
488
488
std::string
489
- ThreadSanitizerRuntime ::FormatDescription (StructuredData::ObjectSP report) {
489
+ InstrumentationRuntimeTSan ::FormatDescription (StructuredData::ObjectSP report) {
490
490
std::string description = report->GetAsDictionary ()
491
491
->GetValueForKey (" issue_type" )
492
492
->GetAsString ()
@@ -580,7 +580,7 @@ static void GetSymbolDeclarationFromAddress(ProcessSP process_sp, addr_t addr,
580
580
decl = var->GetDeclaration ();
581
581
}
582
582
583
- addr_t ThreadSanitizerRuntime ::GetFirstNonInternalFramePc (
583
+ addr_t InstrumentationRuntimeTSan ::GetFirstNonInternalFramePc (
584
584
StructuredData::ObjectSP trace, bool skip_one_frame) {
585
585
ProcessSP process_sp = GetProcessSP ();
586
586
ModuleSP runtime_module_sp = GetRuntimeModuleSP ();
@@ -609,7 +609,7 @@ addr_t ThreadSanitizerRuntime::GetFirstNonInternalFramePc(
609
609
}
610
610
611
611
std::string
612
- ThreadSanitizerRuntime ::GenerateSummary (StructuredData::ObjectSP report) {
612
+ InstrumentationRuntimeTSan ::GenerateSummary (StructuredData::ObjectSP report) {
613
613
ProcessSP process_sp = GetProcessSP ();
614
614
615
615
std::string summary = report->GetAsDictionary ()
@@ -695,8 +695,8 @@ ThreadSanitizerRuntime::GenerateSummary(StructuredData::ObjectSP report) {
695
695
return summary;
696
696
}
697
697
698
- addr_t
699
- ThreadSanitizerRuntime::GetMainRacyAddress ( StructuredData::ObjectSP report) {
698
+ addr_t InstrumentationRuntimeTSan::GetMainRacyAddress (
699
+ StructuredData::ObjectSP report) {
700
700
addr_t result = (addr_t )-1 ;
701
701
702
702
report->GetObjectForDotSeparatedPath (" mops" )->GetAsArray ()->ForEach (
@@ -711,7 +711,7 @@ ThreadSanitizerRuntime::GetMainRacyAddress(StructuredData::ObjectSP report) {
711
711
return (result == (addr_t )-1 ) ? 0 : result;
712
712
}
713
713
714
- std::string ThreadSanitizerRuntime ::GetLocationDescription (
714
+ std::string InstrumentationRuntimeTSan ::GetLocationDescription (
715
715
StructuredData::ObjectSP report, addr_t &global_addr,
716
716
std::string &global_name, std::string &filename, uint32_t &line) {
717
717
std::string result = " " ;
@@ -791,15 +791,15 @@ std::string ThreadSanitizerRuntime::GetLocationDescription(
791
791
return result;
792
792
}
793
793
794
- bool ThreadSanitizerRuntime ::NotifyBreakpointHit (
794
+ bool InstrumentationRuntimeTSan ::NotifyBreakpointHit (
795
795
void *baton, StoppointCallbackContext *context, user_id_t break_id,
796
796
user_id_t break_loc_id) {
797
797
assert (baton && " null baton" );
798
798
if (!baton)
799
799
return false ;
800
800
801
- ThreadSanitizerRuntime *const instance =
802
- static_cast <ThreadSanitizerRuntime *>(baton);
801
+ InstrumentationRuntimeTSan *const instance =
802
+ static_cast <InstrumentationRuntimeTSan *>(baton);
803
803
804
804
ProcessSP process_sp = instance->GetProcessSP ();
805
805
@@ -873,20 +873,21 @@ bool ThreadSanitizerRuntime::NotifyBreakpointHit(
873
873
return false ; // Let target run
874
874
}
875
875
876
- const RegularExpression &ThreadSanitizerRuntime::GetPatternForRuntimeLibrary () {
876
+ const RegularExpression &
877
+ InstrumentationRuntimeTSan::GetPatternForRuntimeLibrary () {
877
878
static RegularExpression regex (llvm::StringRef (" libclang_rt.tsan_" ));
878
879
return regex;
879
880
}
880
881
881
- bool ThreadSanitizerRuntime ::CheckIfRuntimeIsValid (
882
+ bool InstrumentationRuntimeTSan ::CheckIfRuntimeIsValid (
882
883
const lldb::ModuleSP module_sp) {
883
884
static ConstString g_tsan_get_current_report (" __tsan_get_current_report" );
884
885
const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType (
885
886
g_tsan_get_current_report, lldb::eSymbolTypeAny);
886
887
return symbol != nullptr ;
887
888
}
888
889
889
- void ThreadSanitizerRuntime ::Activate () {
890
+ void InstrumentationRuntimeTSan ::Activate () {
890
891
if (IsActive ())
891
892
return ;
892
893
@@ -916,15 +917,15 @@ void ThreadSanitizerRuntime::Activate() {
916
917
process_sp->GetTarget ()
917
918
.CreateBreakpoint (symbol_address, internal, hardware)
918
919
.get ();
919
- breakpoint->SetCallback (ThreadSanitizerRuntime ::NotifyBreakpointHit, this ,
920
+ breakpoint->SetCallback (InstrumentationRuntimeTSan ::NotifyBreakpointHit, this ,
920
921
true );
921
922
breakpoint->SetBreakpointKind (" thread-sanitizer-report" );
922
923
SetBreakpointID (breakpoint->GetID ());
923
924
924
925
SetActive (true );
925
926
}
926
927
927
- void ThreadSanitizerRuntime ::Deactivate () {
928
+ void InstrumentationRuntimeTSan ::Deactivate () {
928
929
if (GetBreakpointID () != LLDB_INVALID_BREAK_ID) {
929
930
ProcessSP process_sp = GetProcessSP ();
930
931
if (process_sp) {
@@ -1043,7 +1044,7 @@ static void AddThreadsForPath(const std::string &path,
1043
1044
}
1044
1045
1045
1046
lldb::ThreadCollectionSP
1046
- ThreadSanitizerRuntime ::GetBacktracesFromExtendedStopInfo (
1047
+ InstrumentationRuntimeTSan ::GetBacktracesFromExtendedStopInfo (
1047
1048
StructuredData::ObjectSP info) {
1048
1049
ThreadCollectionSP threads;
1049
1050
threads = std::make_shared<ThreadCollection>();
0 commit comments