Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- InstrumentationRuntimeTSan.cpp ------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "InstrumentationRuntimeTSan.h"
10
11
#include "Plugins/Process/Utility/HistoryThread.h"
12
#include "lldb/Breakpoint/StoppointCallbackContext.h"
13
#include "lldb/Core/Debugger.h"
14
#include "lldb/Core/Module.h"
15
#include "lldb/Core/PluginInterface.h"
16
#include "lldb/Core/PluginManager.h"
17
#include "lldb/Core/StreamFile.h"
18
#include "lldb/Core/ValueObject.h"
19
#include "lldb/Expression/UserExpression.h"
20
#include "lldb/Interpreter/CommandReturnObject.h"
21
#include "lldb/Symbol/Symbol.h"
22
#include "lldb/Symbol/SymbolContext.h"
23
#include "lldb/Symbol/Variable.h"
24
#include "lldb/Symbol/VariableList.h"
25
#include "lldb/Target/InstrumentationRuntimeStopInfo.h"
26
#include "lldb/Target/SectionLoadList.h"
27
#include "lldb/Target/StopInfo.h"
28
#include "lldb/Target/Target.h"
29
#include "lldb/Target/Thread.h"
30
#include "lldb/Utility/RegularExpression.h"
31
#include "lldb/Utility/Stream.h"
32
33
#include <memory>
34
35
using namespace lldb;
36
using namespace lldb_private;
37
38
LLDB_PLUGIN_DEFINE(InstrumentationRuntimeTSan)
39
40
lldb::InstrumentationRuntimeSP
41
2.69k
InstrumentationRuntimeTSan::CreateInstance(const lldb::ProcessSP &process_sp) {
42
2.69k
  return InstrumentationRuntimeSP(new InstrumentationRuntimeTSan(process_sp));
43
2.69k
}
44
45
3.44k
void InstrumentationRuntimeTSan::Initialize() {
46
3.44k
  PluginManager::RegisterPlugin(
47
3.44k
      GetPluginNameStatic(), "ThreadSanitizer instrumentation runtime plugin.",
48
3.44k
      CreateInstance, GetTypeStatic);
49
3.44k
}
50
51
3.43k
void InstrumentationRuntimeTSan::Terminate() {
52
3.43k
  PluginManager::UnregisterPlugin(CreateInstance);
53
3.43k
}
54
55
11.4k
lldb::InstrumentationRuntimeType InstrumentationRuntimeTSan::GetTypeStatic() {
56
11.4k
  return eInstrumentationRuntimeTypeThreadSanitizer;
57
11.4k
}
58
59
2.69k
InstrumentationRuntimeTSan::~InstrumentationRuntimeTSan() { Deactivate(); }
60
61
const char *thread_sanitizer_retrieve_report_data_prefix = R"(
62
extern "C"
63
{
64
    void *__tsan_get_current_report();
65
    int __tsan_get_report_data(void *report, const char **description, int *count,
66
                               int *stack_count, int *mop_count, int *loc_count,
67
                               int *mutex_count, int *thread_count,
68
                               int *unique_tid_count, void **sleep_trace,
69
                               unsigned long trace_size);
70
    int __tsan_get_report_stack(void *report, unsigned long idx, void **trace,
71
                                unsigned long trace_size);
72
    int __tsan_get_report_mop(void *report, unsigned long idx, int *tid, void **addr,
73
                              int *size, int *write, int *atomic, void **trace,
74
                              unsigned long trace_size);
75
    int __tsan_get_report_loc(void *report, unsigned long idx, const char **type,
76
                              void **addr, unsigned long *start, unsigned long *size, int *tid,
77
                              int *fd, int *suppressable, void **trace,
78
                              unsigned long trace_size);
79
    int __tsan_get_report_mutex(void *report, unsigned long idx, unsigned long *mutex_id, void **addr,
80
                                int *destroyed, void **trace, unsigned long trace_size);
81
    int __tsan_get_report_thread(void *report, unsigned long idx, int *tid, unsigned long *os_id,
82
                                 int *running, const char **name, int *parent_tid,
83
                                 void **trace, unsigned long trace_size);
84
    int __tsan_get_report_unique_tid(void *report, unsigned long idx, int *tid);
85
86
    // TODO: dlsym won't work on Windows.
87
    void *dlsym(void* handle, const char* symbol);
88
    int (*ptr__tsan_get_report_loc_object_type)(void *report, unsigned long idx, const char **object_type);
89
}
90
91
const int REPORT_TRACE_SIZE = 128;
92
const int REPORT_ARRAY_SIZE = 4;
93
94
struct data {
95
    void *report;
96
    const char *description;
97
    int report_count;
98
99
    void *sleep_trace[REPORT_TRACE_SIZE];
100
101
    int stack_count;
102
    struct {
103
        int idx;
104
        void *trace[REPORT_TRACE_SIZE];
105
    } stacks[REPORT_ARRAY_SIZE];
106
107
    int mop_count;
108
    struct {
109
        int idx;
110
        int tid;
111
        int size;
112
        int write;
113
        int atomic;
114
        void *addr;
115
        void *trace[REPORT_TRACE_SIZE];
116
    } mops[REPORT_ARRAY_SIZE];
117
118
    int loc_count;
119
    struct {
120
        int idx;
121
        const char *type;
122
        void *addr;
123
        unsigned long start;
124
        unsigned long size;
125
        int tid;
126
        int fd;
127
        int suppressable;
128
        void *trace[REPORT_TRACE_SIZE];
129
        const char *object_type;
130
    } locs[REPORT_ARRAY_SIZE];
131
132
    int mutex_count;
133
    struct {
134
        int idx;
135
        unsigned long mutex_id;
136
        void *addr;
137
        int destroyed;
138
        void *trace[REPORT_TRACE_SIZE];
139
    } mutexes[REPORT_ARRAY_SIZE];
140
141
    int thread_count;
142
    struct {
143
        int idx;
144
        int tid;
145
        unsigned long os_id;
146
        int running;
147
        const char *name;
148
        int parent_tid;
149
        void *trace[REPORT_TRACE_SIZE];
150
    } threads[REPORT_ARRAY_SIZE];
151
152
    int unique_tid_count;
153
    struct {
154
        int idx;
155
        int tid;
156
    } unique_tids[REPORT_ARRAY_SIZE];
157
};
158
)";
159
160
const char *thread_sanitizer_retrieve_report_data_command = R"(
161
data t = {0};
162
163
ptr__tsan_get_report_loc_object_type = (typeof(ptr__tsan_get_report_loc_object_type))(void *)dlsym((void*)-2 /*RTLD_DEFAULT*/, "__tsan_get_report_loc_object_type");
164
165
t.report = __tsan_get_current_report();
166
__tsan_get_report_data(t.report, &t.description, &t.report_count, &t.stack_count, &t.mop_count, &t.loc_count, &t.mutex_count, &t.thread_count, &t.unique_tid_count, t.sleep_trace, REPORT_TRACE_SIZE);
167
168
if (t.stack_count > REPORT_ARRAY_SIZE) t.stack_count = REPORT_ARRAY_SIZE;
169
for (int i = 0; i < t.stack_count; i++) {
170
    t.stacks[i].idx = i;
171
    __tsan_get_report_stack(t.report, i, t.stacks[i].trace, REPORT_TRACE_SIZE);
172
}
173
174
if (t.mop_count > REPORT_ARRAY_SIZE) t.mop_count = REPORT_ARRAY_SIZE;
175
for (int i = 0; i < t.mop_count; i++) {
176
    t.mops[i].idx = i;
177
    __tsan_get_report_mop(t.report, i, &t.mops[i].tid, &t.mops[i].addr, &t.mops[i].size, &t.mops[i].write, &t.mops[i].atomic, t.mops[i].trace, REPORT_TRACE_SIZE);
178
}
179
180
if (t.loc_count > REPORT_ARRAY_SIZE) t.loc_count = REPORT_ARRAY_SIZE;
181
for (int i = 0; i < t.loc_count; i++) {
182
    t.locs[i].idx = i;
183
    __tsan_get_report_loc(t.report, i, &t.locs[i].type, &t.locs[i].addr, &t.locs[i].start, &t.locs[i].size, &t.locs[i].tid, &t.locs[i].fd, &t.locs[i].suppressable, t.locs[i].trace, REPORT_TRACE_SIZE);
184
    if (ptr__tsan_get_report_loc_object_type)
185
        ptr__tsan_get_report_loc_object_type(t.report, i, &t.locs[i].object_type);
186
}
187
188
if (t.mutex_count > REPORT_ARRAY_SIZE) t.mutex_count = REPORT_ARRAY_SIZE;
189
for (int i = 0; i < t.mutex_count; i++) {
190
    t.mutexes[i].idx = i;
191
    __tsan_get_report_mutex(t.report, i, &t.mutexes[i].mutex_id, &t.mutexes[i].addr, &t.mutexes[i].destroyed, t.mutexes[i].trace, REPORT_TRACE_SIZE);
192
}
193
194
if (t.thread_count > REPORT_ARRAY_SIZE) t.thread_count = REPORT_ARRAY_SIZE;
195
for (int i = 0; i < t.thread_count; i++) {
196
    t.threads[i].idx = i;
197
    __tsan_get_report_thread(t.report, i, &t.threads[i].tid, &t.threads[i].os_id, &t.threads[i].running, &t.threads[i].name, &t.threads[i].parent_tid, t.threads[i].trace, REPORT_TRACE_SIZE);
198
}
199
200
if (t.unique_tid_count > REPORT_ARRAY_SIZE) t.unique_tid_count = REPORT_ARRAY_SIZE;
201
for (int i = 0; i < t.unique_tid_count; i++) {
202
    t.unique_tids[i].idx = i;
203
    __tsan_get_report_unique_tid(t.report, i, &t.unique_tids[i].tid);
204
}
205
206
t;
207
)";
208
209
static StructuredData::Array *
210
CreateStackTrace(ValueObjectSP o,
211
0
                 const std::string &trace_item_name = ".trace") {
212
0
  StructuredData::Array *trace = new StructuredData::Array();
213
0
  ValueObjectSP trace_value_object =
214
0
      o->GetValueForExpressionPath(trace_item_name.c_str());
215
0
  size_t count = trace_value_object->GetNumChildren();
216
0
  for (size_t j = 0; j < count; j++) {
217
0
    addr_t trace_addr =
218
0
        trace_value_object->GetChildAtIndex(j, true)->GetValueAsUnsigned(0);
219
0
    if (trace_addr == 0)
220
0
      break;
221
0
    trace->AddItem(
222
0
        StructuredData::ObjectSP(new StructuredData::Integer(trace_addr)));
223
0
  }
224
0
  return trace;
225
0
}
226
227
static StructuredData::Array *ConvertToStructuredArray(
228
    ValueObjectSP return_value_sp, const std::string &items_name,
229
    const std::string &count_name,
230
    std::function<void(ValueObjectSP o, StructuredData::Dictionary *dict)> const
231
0
        &callback) {
232
0
  StructuredData::Array *array = new StructuredData::Array();
233
0
  unsigned int count =
234
0
      return_value_sp->GetValueForExpressionPath(count_name.c_str())
235
0
          ->GetValueAsUnsigned(0);
236
0
  ValueObjectSP objects =
237
0
      return_value_sp->GetValueForExpressionPath(items_name.c_str());
238
0
  for (unsigned int i = 0; i < count; i++) {
239
0
    ValueObjectSP o = objects->GetChildAtIndex(i, true);
240
0
    StructuredData::Dictionary *dict = new StructuredData::Dictionary();
241
242
0
    callback(o, dict);
243
244
0
    array->AddItem(StructuredData::ObjectSP(dict));
245
0
  }
246
0
  return array;
247
0
}
248
249
static std::string RetrieveString(ValueObjectSP return_value_sp,
250
                                  ProcessSP process_sp,
251
0
                                  const std::string &expression_path) {
252
0
  addr_t ptr =
253
0
      return_value_sp->GetValueForExpressionPath(expression_path.c_str())
254
0
          ->GetValueAsUnsigned(0);
255
0
  std::string str;
256
0
  Status error;
257
0
  process_sp->ReadCStringFromMemory(ptr, str, error);
258
0
  return str;
259
0
}
260
261
static void
262
GetRenumberedThreadIds(ProcessSP process_sp, ValueObjectSP data,
263
0
                       std::map<uint64_t, user_id_t> &thread_id_map) {
264
0
  ConvertToStructuredArray(
265
0
      data, ".threads", ".thread_count",
266
0
      [process_sp, &thread_id_map](ValueObjectSP o,
267
0
                                   StructuredData::Dictionary *dict) {
268
0
        uint64_t thread_id =
269
0
            o->GetValueForExpressionPath(".tid")->GetValueAsUnsigned(0);
270
0
        uint64_t thread_os_id =
271
0
            o->GetValueForExpressionPath(".os_id")->GetValueAsUnsigned(0);
272
0
        user_id_t lldb_user_id = 0;
273
274
0
        bool can_update = true;
275
0
        ThreadSP lldb_thread = process_sp->GetThreadList().FindThreadByID(
276
0
            thread_os_id, can_update);
277
0
        if (lldb_thread) {
278
0
          lldb_user_id = lldb_thread->GetIndexID();
279
0
        } else {
280
          // This isn't a live thread anymore.  Ask process to assign a new
281
          // Index ID (or return an old one if we've already seen this
282
          // thread_os_id). It will also make sure that no new threads are
283
          // assigned this Index ID.
284
0
          lldb_user_id = process_sp->AssignIndexIDToThread(thread_os_id);
285
0
        }
286
287
0
        thread_id_map[thread_id] = lldb_user_id;
288
0
      });
289
0
}
290
291
static user_id_t Renumber(uint64_t id,
292
0
                          std::map<uint64_t, user_id_t> &thread_id_map) {
293
0
  auto IT = thread_id_map.find(id);
294
0
  if (IT == thread_id_map.end())
295
0
    return 0;
296
297
0
  return IT->second;
298
0
}
299
300
StructuredData::ObjectSP InstrumentationRuntimeTSan::RetrieveReportData(
301
0
    ExecutionContextRef exe_ctx_ref) {
302
0
  ProcessSP process_sp = GetProcessSP();
303
0
  if (!process_sp)
304
0
    return StructuredData::ObjectSP();
305
306
0
  ThreadSP thread_sp = exe_ctx_ref.GetThreadSP();
307
0
  StackFrameSP frame_sp = thread_sp->GetSelectedFrame();
308
309
0
  if (!frame_sp)
310
0
    return StructuredData::ObjectSP();
311
312
0
  EvaluateExpressionOptions options;
313
0
  options.SetUnwindOnError(true);
314
0
  options.SetTryAllThreads(true);
315
0
  options.SetStopOthers(true);
316
0
  options.SetIgnoreBreakpoints(true);
317
0
  options.SetTimeout(process_sp->GetUtilityExpressionTimeout());
318
0
  options.SetPrefix(thread_sanitizer_retrieve_report_data_prefix);
319
0
  options.SetAutoApplyFixIts(false);
320
0
  options.SetLanguage(eLanguageTypeObjC_plus_plus);
321
322
0
  ValueObjectSP main_value;
323
0
  ExecutionContext exe_ctx;
324
0
  Status eval_error;
325
0
  frame_sp->CalculateExecutionContext(exe_ctx);
326
0
  ExpressionResults result = UserExpression::Evaluate(
327
0
      exe_ctx, options, thread_sanitizer_retrieve_report_data_command, "",
328
0
      main_value, eval_error);
329
0
  if (result != eExpressionCompleted) {
330
0
    process_sp->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf(
331
0
        "Warning: Cannot evaluate ThreadSanitizer expression:\n%s\n",
332
0
        eval_error.AsCString());
333
0
    return StructuredData::ObjectSP();
334
0
  }
335
336
0
  std::map<uint64_t, user_id_t> thread_id_map;
337
0
  GetRenumberedThreadIds(process_sp, main_value, thread_id_map);
338
339
0
  StructuredData::Dictionary *dict = new StructuredData::Dictionary();
340
0
  dict->AddStringItem("instrumentation_class", "ThreadSanitizer");
341
0
  dict->AddStringItem("issue_type",
342
0
                      RetrieveString(main_value, process_sp, ".description"));
343
0
  dict->AddIntegerItem("report_count",
344
0
                       main_value->GetValueForExpressionPath(".report_count")
345
0
                           ->GetValueAsUnsigned(0));
346
0
  dict->AddItem("sleep_trace", StructuredData::ObjectSP(CreateStackTrace(
347
0
                                   main_value, ".sleep_trace")));
348
349
0
  StructuredData::Array *stacks = ConvertToStructuredArray(
350
0
      main_value, ".stacks", ".stack_count",
351
0
      [thread_sp](ValueObjectSP o, StructuredData::Dictionary *dict) {
352
0
        dict->AddIntegerItem(
353
0
            "index",
354
0
            o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
355
0
        dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o)));
356
        // "stacks" happen on the current thread
357
0
        dict->AddIntegerItem("thread_id", thread_sp->GetIndexID());
358
0
      });
359
0
  dict->AddItem("stacks", StructuredData::ObjectSP(stacks));
360
361
0
  StructuredData::Array *mops = ConvertToStructuredArray(
362
0
      main_value, ".mops", ".mop_count",
363
0
      [&thread_id_map](ValueObjectSP o, StructuredData::Dictionary *dict) {
364
0
        dict->AddIntegerItem(
365
0
            "index",
366
0
            o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
367
0
        dict->AddIntegerItem(
368
0
            "thread_id",
369
0
            Renumber(
370
0
                o->GetValueForExpressionPath(".tid")->GetValueAsUnsigned(0),
371
0
                thread_id_map));
372
0
        dict->AddIntegerItem(
373
0
            "size",
374
0
            o->GetValueForExpressionPath(".size")->GetValueAsUnsigned(0));
375
0
        dict->AddBooleanItem(
376
0
            "is_write",
377
0
            o->GetValueForExpressionPath(".write")->GetValueAsUnsigned(0));
378
0
        dict->AddBooleanItem(
379
0
            "is_atomic",
380
0
            o->GetValueForExpressionPath(".atomic")->GetValueAsUnsigned(0));
381
0
        dict->AddIntegerItem(
382
0
            "address",
383
0
            o->GetValueForExpressionPath(".addr")->GetValueAsUnsigned(0));
384
0
        dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o)));
385
0
      });
386
0
  dict->AddItem("mops", StructuredData::ObjectSP(mops));
387
388
0
  StructuredData::Array *locs = ConvertToStructuredArray(
389
0
      main_value, ".locs", ".loc_count",
390
0
      [process_sp, &thread_id_map](ValueObjectSP o,
391
0
                                   StructuredData::Dictionary *dict) {
392
0
        dict->AddIntegerItem(
393
0
            "index",
394
0
            o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
395
0
        dict->AddStringItem("type", RetrieveString(o, process_sp, ".type"));
396
0
        dict->AddIntegerItem(
397
0
            "address",
398
0
            o->GetValueForExpressionPath(".addr")->GetValueAsUnsigned(0));
399
0
        dict->AddIntegerItem(
400
0
            "start",
401
0
            o->GetValueForExpressionPath(".start")->GetValueAsUnsigned(0));
402
0
        dict->AddIntegerItem(
403
0
            "size",
404
0
            o->GetValueForExpressionPath(".size")->GetValueAsUnsigned(0));
405
0
        dict->AddIntegerItem(
406
0
            "thread_id",
407
0
            Renumber(
408
0
                o->GetValueForExpressionPath(".tid")->GetValueAsUnsigned(0),
409
0
                thread_id_map));
410
0
        dict->AddIntegerItem(
411
0
            "file_descriptor",
412
0
            o->GetValueForExpressionPath(".fd")->GetValueAsUnsigned(0));
413
0
        dict->AddIntegerItem("suppressable",
414
0
                             o->GetValueForExpressionPath(".suppressable")
415
0
                                 ->GetValueAsUnsigned(0));
416
0
        dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o)));
417
0
        dict->AddStringItem("object_type",
418
0
                            RetrieveString(o, process_sp, ".object_type"));
419
0
      });
420
0
  dict->AddItem("locs", StructuredData::ObjectSP(locs));
421
422
0
  StructuredData::Array *mutexes = ConvertToStructuredArray(
423
0
      main_value, ".mutexes", ".mutex_count",
424
0
      [](ValueObjectSP o, StructuredData::Dictionary *dict) {
425
0
        dict->AddIntegerItem(
426
0
            "index",
427
0
            o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
428
0
        dict->AddIntegerItem(
429
0
            "mutex_id",
430
0
            o->GetValueForExpressionPath(".mutex_id")->GetValueAsUnsigned(0));
431
0
        dict->AddIntegerItem(
432
0
            "address",
433
0
            o->GetValueForExpressionPath(".addr")->GetValueAsUnsigned(0));
434
0
        dict->AddIntegerItem(
435
0
            "destroyed",
436
0
            o->GetValueForExpressionPath(".destroyed")->GetValueAsUnsigned(0));
437
0
        dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o)));
438
0
      });
439
0
  dict->AddItem("mutexes", StructuredData::ObjectSP(mutexes));
440
441
0
  StructuredData::Array *threads = ConvertToStructuredArray(
442
0
      main_value, ".threads", ".thread_count",
443
0
      [process_sp, &thread_id_map](ValueObjectSP o,
444
0
                                   StructuredData::Dictionary *dict) {
445
0
        dict->AddIntegerItem(
446
0
            "index",
447
0
            o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
448
0
        dict->AddIntegerItem(
449
0
            "thread_id",
450
0
            Renumber(
451
0
                o->GetValueForExpressionPath(".tid")->GetValueAsUnsigned(0),
452
0
                thread_id_map));
453
0
        dict->AddIntegerItem(
454
0
            "thread_os_id",
455
0
            o->GetValueForExpressionPath(".os_id")->GetValueAsUnsigned(0));
456
0
        dict->AddIntegerItem(
457
0
            "running",
458
0
            o->GetValueForExpressionPath(".running")->GetValueAsUnsigned(0));
459
0
        dict->AddStringItem("name", RetrieveString(o, process_sp, ".name"));
460
0
        dict->AddIntegerItem(
461
0
            "parent_thread_id",
462
0
            Renumber(o->GetValueForExpressionPath(".parent_tid")
463
0
                         ->GetValueAsUnsigned(0),
464
0
                     thread_id_map));
465
0
        dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o)));
466
0
      });
467
0
  dict->AddItem("threads", StructuredData::ObjectSP(threads));
468
469
0
  StructuredData::Array *unique_tids = ConvertToStructuredArray(
470
0
      main_value, ".unique_tids", ".unique_tid_count",
471
0
      [&thread_id_map](ValueObjectSP o, StructuredData::Dictionary *dict) {
472
0
        dict->AddIntegerItem(
473
0
            "index",
474
0
            o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
475
0
        dict->AddIntegerItem(
476
0
            "tid",
477
0
            Renumber(
478
0
                o->GetValueForExpressionPath(".tid")->GetValueAsUnsigned(0),
479
0
                thread_id_map));
480
0
      });
481
0
  dict->AddItem("unique_tids", StructuredData::ObjectSP(unique_tids));
482
483
0
  return StructuredData::ObjectSP(dict);
484
0
}
485
486
std::string
487
0
InstrumentationRuntimeTSan::FormatDescription(StructuredData::ObjectSP report) {
488
0
  std::string description = std::string(report->GetAsDictionary()
489
0
                                            ->GetValueForKey("issue_type")
490
0
                                            ->GetAsString()
491
0
                                            ->GetValue());
492
493
0
  if (description == "data-race") {
494
0
    return "Data race";
495
0
  } else if (description == "data-race-vptr") {
496
0
    return "Data race on C++ virtual pointer";
497
0
  } else if (description == "heap-use-after-free") {
498
0
    return "Use of deallocated memory";
499
0
  } else if (description == "heap-use-after-free-vptr") {
500
0
    return "Use of deallocated C++ virtual pointer";
501
0
  } else if (description == "thread-leak") {
502
0
    return "Thread leak";
503
0
  } else if (description == "locked-mutex-destroy") {
504
0
    return "Destruction of a locked mutex";
505
0
  } else if (description == "mutex-double-lock") {
506
0
    return "Double lock of a mutex";
507
0
  } else if (description == "mutex-invalid-access") {
508
0
    return "Use of an uninitialized or destroyed mutex";
509
0
  } else if (description == "mutex-bad-unlock") {
510
0
    return "Unlock of an unlocked mutex (or by a wrong thread)";
511
0
  } else if (description == "mutex-bad-read-lock") {
512
0
    return "Read lock of a write locked mutex";
513
0
  } else if (description == "mutex-bad-read-unlock") {
514
0
    return "Read unlock of a write locked mutex";
515
0
  } else if (description == "signal-unsafe-call") {
516
0
    return "Signal-unsafe call inside a signal handler";
517
0
  } else if (description == "errno-in-signal-handler") {
518
0
    return "Overwrite of errno in a signal handler";
519
0
  } else if (description == "lock-order-inversion") {
520
0
    return "Lock order inversion (potential deadlock)";
521
0
  } else if (description == "external-race") {
522
0
    return "Race on a library object";
523
0
  } else if (description == "swift-access-race") {
524
0
    return "Swift access race";
525
0
  }
526
527
  // for unknown report codes just show the code
528
0
  return description;
529
0
}
530
531
0
static std::string Sprintf(const char *format, ...) {
532
0
  StreamString s;
533
0
  va_list args;
534
0
  va_start(args, format);
535
0
  s.PrintfVarArg(format, args);
536
0
  va_end(args);
537
0
  return std::string(s.GetString());
538
0
}
539
540
0
static std::string GetSymbolNameFromAddress(ProcessSP process_sp, addr_t addr) {
541
0
  lldb_private::Address so_addr;
542
0
  if (!process_sp->GetTarget().GetSectionLoadList().ResolveLoadAddress(addr,
543
0
                                                                       so_addr))
544
0
    return "";
545
546
0
  lldb_private::Symbol *symbol = so_addr.CalculateSymbolContextSymbol();
547
0
  if (!symbol)
548
0
    return "";
549
550
0
  std::string sym_name = symbol->GetName().GetCString();
551
0
  return sym_name;
552
0
}
553
554
static void GetSymbolDeclarationFromAddress(ProcessSP process_sp, addr_t addr,
555
0
                                            Declaration &decl) {
556
0
  lldb_private::Address so_addr;
557
0
  if (!process_sp->GetTarget().GetSectionLoadList().ResolveLoadAddress(addr,
558
0
                                                                       so_addr))
559
0
    return;
560
561
0
  lldb_private::Symbol *symbol = so_addr.CalculateSymbolContextSymbol();
562
0
  if (!symbol)
563
0
    return;
564
565
0
  ConstString sym_name = symbol->GetMangled().GetName(Mangled::ePreferMangled);
566
567
0
  ModuleSP module = symbol->CalculateSymbolContextModule();
568
0
  if (!module)
569
0
    return;
570
571
0
  VariableList var_list;
572
0
  module->FindGlobalVariables(sym_name, CompilerDeclContext(), 1U, var_list);
573
0
  if (var_list.GetSize() < 1)
574
0
    return;
575
576
0
  VariableSP var = var_list.GetVariableAtIndex(0);
577
0
  decl = var->GetDeclaration();
578
0
}
579
580
addr_t InstrumentationRuntimeTSan::GetFirstNonInternalFramePc(
581
0
    StructuredData::ObjectSP trace, bool skip_one_frame) {
582
0
  ProcessSP process_sp = GetProcessSP();
583
0
  ModuleSP runtime_module_sp = GetRuntimeModuleSP();
584
585
0
  StructuredData::Array *trace_array = trace->GetAsArray();
586
0
  for (size_t i = 0; i < trace_array->GetSize(); i++) {
587
0
    if (skip_one_frame && i == 0)
588
0
      continue;
589
590
0
    addr_t addr;
591
0
    if (!trace_array->GetItemAtIndexAsInteger(i, addr))
592
0
      continue;
593
594
0
    lldb_private::Address so_addr;
595
0
    if (!process_sp->GetTarget().GetSectionLoadList().ResolveLoadAddress(
596
0
            addr, so_addr))
597
0
      continue;
598
599
0
    if (so_addr.GetModule() == runtime_module_sp)
600
0
      continue;
601
602
0
    return addr;
603
0
  }
604
605
0
  return 0;
606
0
}
607
608
std::string
609
0
InstrumentationRuntimeTSan::GenerateSummary(StructuredData::ObjectSP report) {
610
0
  ProcessSP process_sp = GetProcessSP();
611
612
0
  std::string summary = std::string(report->GetAsDictionary()
613
0
                                        ->GetValueForKey("description")
614
0
                                        ->GetAsString()
615
0
                                        ->GetValue());
616
0
  bool skip_one_frame =
617
0
      report->GetObjectForDotSeparatedPath("issue_type")->GetStringValue() ==
618
0
      "external-race";
619
620
0
  addr_t pc = 0;
621
0
  if (report->GetAsDictionary()
622
0
          ->GetValueForKey("mops")
623
0
          ->GetAsArray()
624
0
          ->GetSize() > 0)
625
0
    pc = GetFirstNonInternalFramePc(report->GetAsDictionary()
626
0
                                        ->GetValueForKey("mops")
627
0
                                        ->GetAsArray()
628
0
                                        ->GetItemAtIndex(0)
629
0
                                        ->GetAsDictionary()
630
0
                                        ->GetValueForKey("trace"),
631
0
                                    skip_one_frame);
632
633
0
  if (report->GetAsDictionary()
634
0
          ->GetValueForKey("stacks")
635
0
          ->GetAsArray()
636
0
          ->GetSize() > 0)
637
0
    pc = GetFirstNonInternalFramePc(report->GetAsDictionary()
638
0
                                        ->GetValueForKey("stacks")
639
0
                                        ->GetAsArray()
640
0
                                        ->GetItemAtIndex(0)
641
0
                                        ->GetAsDictionary()
642
0
                                        ->GetValueForKey("trace"),
643
0
                                    skip_one_frame);
644
645
0
  if (pc != 0) {
646
0
    summary = summary + " in " + GetSymbolNameFromAddress(process_sp, pc);
647
0
  }
648
649
0
  if (report->GetAsDictionary()
650
0
          ->GetValueForKey("locs")
651
0
          ->GetAsArray()
652
0
          ->GetSize() > 0) {
653
0
    StructuredData::ObjectSP loc = report->GetAsDictionary()
654
0
                                       ->GetValueForKey("locs")
655
0
                                       ->GetAsArray()
656
0
                                       ->GetItemAtIndex(0);
657
0
    std::string object_type = std::string(loc->GetAsDictionary()
658
0
                                              ->GetValueForKey("object_type")
659
0
                                              ->GetAsString()
660
0
                                              ->GetValue());
661
0
    if (!object_type.empty()) {
662
0
      summary = "Race on " + object_type + " object";
663
0
    }
664
0
    addr_t addr = loc->GetAsDictionary()
665
0
                      ->GetValueForKey("address")
666
0
                      ->GetAsInteger()
667
0
                      ->GetValue();
668
0
    if (addr == 0)
669
0
      addr = loc->GetAsDictionary()
670
0
                 ->GetValueForKey("start")
671
0
                 ->GetAsInteger()
672
0
                 ->GetValue();
673
674
0
    if (addr != 0) {
675
0
      std::string global_name = GetSymbolNameFromAddress(process_sp, addr);
676
0
      if (!global_name.empty()) {
677
0
        summary = summary + " at " + global_name;
678
0
      } else {
679
0
        summary = summary + " at " + Sprintf("0x%llx", addr);
680
0
      }
681
0
    } else {
682
0
      int fd = loc->GetAsDictionary()
683
0
                   ->GetValueForKey("file_descriptor")
684
0
                   ->GetAsInteger()
685
0
                   ->GetValue();
686
0
      if (fd != 0) {
687
0
        summary = summary + " on file descriptor " + Sprintf("%d", fd);
688
0
      }
689
0
    }
690
0
  }
691
692
0
  return summary;
693
0
}
694
695
addr_t InstrumentationRuntimeTSan::GetMainRacyAddress(
696
0
    StructuredData::ObjectSP report) {
697
0
  addr_t result = (addr_t)-1;
698
699
0
  report->GetObjectForDotSeparatedPath("mops")->GetAsArray()->ForEach(
700
0
      [&result](StructuredData::Object *o) -> bool {
701
0
        addr_t addr =
702
0
            o->GetObjectForDotSeparatedPath("address")->GetIntegerValue();
703
0
        if (addr < result)
704
0
          result = addr;
705
0
        return true;
706
0
      });
707
708
0
  return (result == (addr_t)-1) ? 0 : result;
709
0
}
710
711
std::string InstrumentationRuntimeTSan::GetLocationDescription(
712
    StructuredData::ObjectSP report, addr_t &global_addr,
713
0
    std::string &global_name, std::string &filename, uint32_t &line) {
714
0
  std::string result;
715
716
0
  ProcessSP process_sp = GetProcessSP();
717
718
0
  if (report->GetAsDictionary()
719
0
          ->GetValueForKey("locs")
720
0
          ->GetAsArray()
721
0
          ->GetSize() > 0) {
722
0
    StructuredData::ObjectSP loc = report->GetAsDictionary()
723
0
                                       ->GetValueForKey("locs")
724
0
                                       ->GetAsArray()
725
0
                                       ->GetItemAtIndex(0);
726
0
    std::string type = std::string(
727
0
        loc->GetAsDictionary()->GetValueForKey("type")->GetStringValue());
728
0
    if (type == "global") {
729
0
      global_addr = loc->GetAsDictionary()
730
0
                        ->GetValueForKey("address")
731
0
                        ->GetAsInteger()
732
0
                        ->GetValue();
733
0
      global_name = GetSymbolNameFromAddress(process_sp, global_addr);
734
0
      if (!global_name.empty()) {
735
0
        result = Sprintf("'%s' is a global variable (0x%llx)",
736
0
                         global_name.c_str(), global_addr);
737
0
      } else {
738
0
        result = Sprintf("0x%llx is a global variable", global_addr);
739
0
      }
740
741
0
      Declaration decl;
742
0
      GetSymbolDeclarationFromAddress(process_sp, global_addr, decl);
743
0
      if (decl.GetFile()) {
744
0
        filename = decl.GetFile().GetPath();
745
0
        line = decl.GetLine();
746
0
      }
747
0
    } else if (type == "heap") {
748
0
      addr_t addr = loc->GetAsDictionary()
749
0
                        ->GetValueForKey("start")
750
0
                        ->GetAsInteger()
751
0
                        ->GetValue();
752
0
      long size = loc->GetAsDictionary()
753
0
                      ->GetValueForKey("size")
754
0
                      ->GetAsInteger()
755
0
                      ->GetValue();
756
0
      std::string object_type = std::string(loc->GetAsDictionary()
757
0
                                                ->GetValueForKey("object_type")
758
0
                                                ->GetAsString()
759
0
                                                ->GetValue());
760
0
      if (!object_type.empty()) {
761
0
        result = Sprintf("Location is a %ld-byte %s object at 0x%llx", size,
762
0
                         object_type.c_str(), addr);
763
0
      } else {
764
0
        result =
765
0
            Sprintf("Location is a %ld-byte heap object at 0x%llx", size, addr);
766
0
      }
767
0
    } else if (type == "stack") {
768
0
      int tid = loc->GetAsDictionary()
769
0
                    ->GetValueForKey("thread_id")
770
0
                    ->GetAsInteger()
771
0
                    ->GetValue();
772
0
      result = Sprintf("Location is stack of thread %d", tid);
773
0
    } else if (type == "tls") {
774
0
      int tid = loc->GetAsDictionary()
775
0
                    ->GetValueForKey("thread_id")
776
0
                    ->GetAsInteger()
777
0
                    ->GetValue();
778
0
      result = Sprintf("Location is TLS of thread %d", tid);
779
0
    } else if (type == "fd") {
780
0
      int fd = loc->GetAsDictionary()
781
0
                   ->GetValueForKey("file_descriptor")
782
0
                   ->GetAsInteger()
783
0
                   ->GetValue();
784
0
      result = Sprintf("Location is file descriptor %d", fd);
785
0
    }
786
0
  }
787
788
0
  return result;
789
0
}
790
791
bool InstrumentationRuntimeTSan::NotifyBreakpointHit(
792
    void *baton, StoppointCallbackContext *context, user_id_t break_id,
793
0
    user_id_t break_loc_id) {
794
0
  assert(baton && "null baton");
795
0
  if (!baton)
796
0
    return false;
797
798
0
  InstrumentationRuntimeTSan *const instance =
799
0
      static_cast<InstrumentationRuntimeTSan *>(baton);
800
801
0
  ProcessSP process_sp = instance->GetProcessSP();
802
803
0
  if (process_sp->GetModIDRef().IsLastResumeForUserExpression())
804
0
    return false;
805
806
0
  StructuredData::ObjectSP report =
807
0
      instance->RetrieveReportData(context->exe_ctx_ref);
808
0
  std::string stop_reason_description =
809
0
      "unknown thread sanitizer fault (unable to extract thread sanitizer "
810
0
      "report)";
811
0
  if (report) {
812
0
    std::string issue_description = instance->FormatDescription(report);
813
0
    report->GetAsDictionary()->AddStringItem("description", issue_description);
814
0
    stop_reason_description = issue_description + " detected";
815
0
    report->GetAsDictionary()->AddStringItem("stop_description",
816
0
                                             stop_reason_description);
817
0
    std::string summary = instance->GenerateSummary(report);
818
0
    report->GetAsDictionary()->AddStringItem("summary", summary);
819
0
    addr_t main_address = instance->GetMainRacyAddress(report);
820
0
    report->GetAsDictionary()->AddIntegerItem("memory_address", main_address);
821
822
0
    addr_t global_addr = 0;
823
0
    std::string global_name;
824
0
    std::string location_filename;
825
0
    uint32_t location_line = 0;
826
0
    std::string location_description = instance->GetLocationDescription(
827
0
        report, global_addr, global_name, location_filename, location_line);
828
0
    report->GetAsDictionary()->AddStringItem("location_description",
829
0
                                             location_description);
830
0
    if (global_addr != 0) {
831
0
      report->GetAsDictionary()->AddIntegerItem("global_address", global_addr);
832
0
    }
833
0
    if (!global_name.empty()) {
834
0
      report->GetAsDictionary()->AddStringItem("global_name", global_name);
835
0
    }
836
0
    if (location_filename != "") {
837
0
      report->GetAsDictionary()->AddStringItem("location_filename",
838
0
                                               location_filename);
839
0
      report->GetAsDictionary()->AddIntegerItem("location_line", location_line);
840
0
    }
841
842
0
    bool all_addresses_are_same = true;
843
0
    report->GetObjectForDotSeparatedPath("mops")->GetAsArray()->ForEach(
844
0
        [&all_addresses_are_same,
845
0
         main_address](StructuredData::Object *o) -> bool {
846
0
          addr_t addr =
847
0
              o->GetObjectForDotSeparatedPath("address")->GetIntegerValue();
848
0
          if (main_address != addr)
849
0
            all_addresses_are_same = false;
850
0
          return true;
851
0
        });
852
0
    report->GetAsDictionary()->AddBooleanItem("all_addresses_are_same",
853
0
                                              all_addresses_are_same);
854
0
  }
855
856
  // Make sure this is the right process
857
0
  if (process_sp && process_sp == context->exe_ctx_ref.GetProcessSP()) {
858
0
    ThreadSP thread_sp = context->exe_ctx_ref.GetThreadSP();
859
0
    if (thread_sp)
860
0
      thread_sp->SetStopInfo(
861
0
          InstrumentationRuntimeStopInfo::
862
0
              CreateStopReasonWithInstrumentationData(
863
0
                  *thread_sp, stop_reason_description, report));
864
865
0
    StreamFile &s = process_sp->GetTarget().GetDebugger().GetOutputStream();
866
0
    s.Printf("ThreadSanitizer report breakpoint hit. Use 'thread "
867
0
             "info -s' to get extended information about the "
868
0
             "report.\n");
869
870
0
    return true; // Return true to stop the target
871
0
  } else
872
0
    return false; // Let target run
873
0
}
874
875
const RegularExpression &
876
139k
InstrumentationRuntimeTSan::GetPatternForRuntimeLibrary() {
877
139k
  static RegularExpression regex(llvm::StringRef("libclang_rt.tsan_"));
878
139k
  return regex;
879
139k
}
880
881
bool InstrumentationRuntimeTSan::CheckIfRuntimeIsValid(
882
2.68k
    const lldb::ModuleSP module_sp) {
883
2.68k
  static ConstString g_tsan_get_current_report("__tsan_get_current_report");
884
2.68k
  const Symbol *symbol = module_sp->FindFirstSymbolWithNameAndType(
885
2.68k
      g_tsan_get_current_report, lldb::eSymbolTypeAny);
886
2.68k
  return symbol != nullptr;
887
2.68k
}
888
889
0
void InstrumentationRuntimeTSan::Activate() {
890
0
  if (IsActive())
891
0
    return;
892
893
0
  ProcessSP process_sp = GetProcessSP();
894
0
  if (!process_sp)
895
0
    return;
896
897
0
  ConstString symbol_name("__tsan_on_report");
898
0
  const Symbol *symbol = GetRuntimeModuleSP()->FindFirstSymbolWithNameAndType(
899
0
      symbol_name, eSymbolTypeCode);
900
901
0
  if (symbol == nullptr)
902
0
    return;
903
904
0
  if (!symbol->ValueIsAddress() || !symbol->GetAddressRef().IsValid())
905
0
    return;
906
907
0
  Target &target = process_sp->GetTarget();
908
0
  addr_t symbol_address = symbol->GetAddressRef().GetOpcodeLoadAddress(&target);
909
910
0
  if (symbol_address == LLDB_INVALID_ADDRESS)
911
0
    return;
912
913
0
  bool internal = true;
914
0
  bool hardware = false;
915
0
  Breakpoint *breakpoint =
916
0
      process_sp->GetTarget()
917
0
          .CreateBreakpoint(symbol_address, internal, hardware)
918
0
          .get();
919
0
  breakpoint->SetCallback(InstrumentationRuntimeTSan::NotifyBreakpointHit, this,
920
0
                          true);
921
0
  breakpoint->SetBreakpointKind("thread-sanitizer-report");
922
0
  SetBreakpointID(breakpoint->GetID());
923
924
0
  SetActive(true);
925
0
}
926
927
2.69k
void InstrumentationRuntimeTSan::Deactivate() {
928
2.69k
  if (GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
929
0
    ProcessSP process_sp = GetProcessSP();
930
0
    if (process_sp) {
931
0
      process_sp->GetTarget().RemoveBreakpointByID(GetBreakpointID());
932
0
      SetBreakpointID(LLDB_INVALID_BREAK_ID);
933
0
    }
934
0
  }
935
2.69k
  SetActive(false);
936
2.69k
}
937
static std::string GenerateThreadName(const std::string &path,
938
                                      StructuredData::Object *o,
939
0
                                      StructuredData::ObjectSP main_info) {
940
0
  std::string result = "additional information";
941
942
0
  if (path == "mops") {
943
0
    int size = o->GetObjectForDotSeparatedPath("size")->GetIntegerValue();
944
0
    int thread_id =
945
0
        o->GetObjectForDotSeparatedPath("thread_id")->GetIntegerValue();
946
0
    bool is_write =
947
0
        o->GetObjectForDotSeparatedPath("is_write")->GetBooleanValue();
948
0
    bool is_atomic =
949
0
        o->GetObjectForDotSeparatedPath("is_atomic")->GetBooleanValue();
950
0
    addr_t addr = o->GetObjectForDotSeparatedPath("address")->GetIntegerValue();
951
952
0
    std::string addr_string = Sprintf(" at 0x%llx", addr);
953
954
0
    if (main_info->GetObjectForDotSeparatedPath("all_addresses_are_same")
955
0
            ->GetBooleanValue()) {
956
0
      addr_string = "";
957
0
    }
958
959
0
    if (main_info->GetObjectForDotSeparatedPath("issue_type")
960
0
            ->GetStringValue() == "external-race") {
961
0
      result = Sprintf("%s access by thread %d",
962
0
                       is_write ? "mutating" : "read-only", thread_id);
963
0
    } else if (main_info->GetObjectForDotSeparatedPath("issue_type")
964
0
                   ->GetStringValue() == "swift-access-race") {
965
0
      result = Sprintf("modifying access by thread %d", thread_id);
966
0
    } else {
967
0
      result = Sprintf("%s%s of size %d%s by thread %d",
968
0
                       is_atomic ? "atomic " : "", is_write ? "write" : "read",
969
0
                       size, addr_string.c_str(), thread_id);
970
0
    }
971
0
  }
972
973
0
  if (path == "threads") {
974
0
    int thread_id =
975
0
        o->GetObjectForDotSeparatedPath("thread_id")->GetIntegerValue();
976
0
    result = Sprintf("Thread %d created", thread_id);
977
0
  }
978
979
0
  if (path == "locs") {
980
0
    std::string type = std::string(
981
0
        o->GetAsDictionary()->GetValueForKey("type")->GetStringValue());
982
0
    int thread_id =
983
0
        o->GetObjectForDotSeparatedPath("thread_id")->GetIntegerValue();
984
0
    int fd =
985
0
        o->GetObjectForDotSeparatedPath("file_descriptor")->GetIntegerValue();
986
0
    if (type == "heap") {
987
0
      result = Sprintf("Heap block allocated by thread %d", thread_id);
988
0
    } else if (type == "fd") {
989
0
      result =
990
0
          Sprintf("File descriptor %d created by thread %t", fd, thread_id);
991
0
    }
992
0
  }
993
994
0
  if (path == "mutexes") {
995
0
    int mutex_id =
996
0
        o->GetObjectForDotSeparatedPath("mutex_id")->GetIntegerValue();
997
998
0
    result = Sprintf("Mutex M%d created", mutex_id);
999
0
  }
1000
1001
0
  if (path == "stacks") {
1002
0
    int thread_id =
1003
0
        o->GetObjectForDotSeparatedPath("thread_id")->GetIntegerValue();
1004
0
    result = Sprintf("Thread %d", thread_id);
1005
0
  }
1006
1007
0
  result[0] = toupper(result[0]);
1008
1009
0
  return result;
1010
0
}
1011
1012
static void AddThreadsForPath(const std::string &path,
1013
                              ThreadCollectionSP threads, ProcessSP process_sp,
1014
0
                              StructuredData::ObjectSP info) {
1015
0
  info->GetObjectForDotSeparatedPath(path)->GetAsArray()->ForEach(
1016
0
      [process_sp, threads, path, info](StructuredData::Object *o) -> bool {
1017
0
        std::vector<lldb::addr_t> pcs;
1018
0
        o->GetObjectForDotSeparatedPath("trace")->GetAsArray()->ForEach(
1019
0
            [&pcs](StructuredData::Object *pc) -> bool {
1020
0
              pcs.push_back(pc->GetAsInteger()->GetValue());
1021
0
              return true;
1022
0
            });
1023
1024
0
        if (pcs.size() == 0)
1025
0
          return true;
1026
1027
0
        StructuredData::ObjectSP thread_id_obj =
1028
0
            o->GetObjectForDotSeparatedPath("thread_os_id");
1029
0
        tid_t tid = thread_id_obj ? thread_id_obj->GetIntegerValue() : 0;
1030
1031
0
        HistoryThread *history_thread =
1032
0
            new HistoryThread(*process_sp, tid, pcs);
1033
0
        ThreadSP new_thread_sp(history_thread);
1034
0
        new_thread_sp->SetName(GenerateThreadName(path, o, info).c_str());
1035
1036
        // Save this in the Process' ExtendedThreadList so a strong pointer
1037
        // retains the object
1038
0
        process_sp->GetExtendedThreadList().AddThread(new_thread_sp);
1039
0
        threads->AddThread(new_thread_sp);
1040
1041
0
        return true;
1042
0
      });
1043
0
}
1044
1045
lldb::ThreadCollectionSP
1046
InstrumentationRuntimeTSan::GetBacktracesFromExtendedStopInfo(
1047
0
    StructuredData::ObjectSP info) {
1048
0
  ThreadCollectionSP threads;
1049
0
  threads = std::make_shared<ThreadCollection>();
1050
1051
0
  if (info->GetObjectForDotSeparatedPath("instrumentation_class")
1052
0
          ->GetStringValue() != "ThreadSanitizer")
1053
0
    return threads;
1054
1055
0
  ProcessSP process_sp = GetProcessSP();
1056
1057
0
  AddThreadsForPath("stacks", threads, process_sp, info);
1058
0
  AddThreadsForPath("mops", threads, process_sp, info);
1059
0
  AddThreadsForPath("locs", threads, process_sp, info);
1060
0
  AddThreadsForPath("mutexes", threads, process_sp, info);
1061
0
  AddThreadsForPath("threads", threads, process_sp, info);
1062
1063
0
  return threads;
1064
0
}