1 //===-- ThreadSanitizerRuntime.h --------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_ThreadSanitizerRuntime_h_
11 #define liblldb_ThreadSanitizerRuntime_h_
12 
13 #include "lldb/Target/ABI.h"
14 #include "lldb/Target/InstrumentationRuntime.h"
15 #include "lldb/Utility/StructuredData.h"
16 #include "lldb/lldb-private.h"
17 
18 namespace lldb_private {
19 
20 class ThreadSanitizerRuntime : public lldb_private::InstrumentationRuntime {
21 public:
22   ~ThreadSanitizerRuntime() override;
23 
24   static lldb::InstrumentationRuntimeSP
25   CreateInstance(const lldb::ProcessSP &process_sp);
26 
27   static void Initialize();
28 
29   static void Terminate();
30 
31   static lldb_private::ConstString GetPluginNameStatic();
32 
33   static lldb::InstrumentationRuntimeType GetTypeStatic();
34 
GetPluginName()35   lldb_private::ConstString GetPluginName() override {
36     return GetPluginNameStatic();
37   }
38 
GetType()39   virtual lldb::InstrumentationRuntimeType GetType() { return GetTypeStatic(); }
40 
GetPluginVersion()41   uint32_t GetPluginVersion() override { return 1; }
42 
43   lldb::ThreadCollectionSP
44   GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info) override;
45 
46 private:
ThreadSanitizerRuntime(const lldb::ProcessSP & process_sp)47   ThreadSanitizerRuntime(const lldb::ProcessSP &process_sp)
48       : lldb_private::InstrumentationRuntime(process_sp) {}
49 
50   const RegularExpression &GetPatternForRuntimeLibrary() override;
51 
52   bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) override;
53 
54   void Activate() override;
55 
56   void Deactivate();
57 
58   static bool NotifyBreakpointHit(void *baton,
59                                   StoppointCallbackContext *context,
60                                   lldb::user_id_t break_id,
61                                   lldb::user_id_t break_loc_id);
62 
63   StructuredData::ObjectSP RetrieveReportData(ExecutionContextRef exe_ctx_ref);
64 
65   std::string FormatDescription(StructuredData::ObjectSP report);
66 
67   std::string GenerateSummary(StructuredData::ObjectSP report);
68 
69   lldb::addr_t GetMainRacyAddress(StructuredData::ObjectSP report);
70 
71   std::string GetLocationDescription(StructuredData::ObjectSP report,
72                                      lldb::addr_t &global_addr,
73                                      std::string &global_name,
74                                      std::string &filename, uint32_t &line);
75 
76   lldb::addr_t GetFirstNonInternalFramePc(StructuredData::ObjectSP trace,
77                                           bool skip_one_frame = false);
78 };
79 
80 } // namespace lldb_private
81 
82 #endif // liblldb_ThreadSanitizerRuntime_h_
83