1 //===-- InstrumentationRuntime.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_InstrumentationRuntime_h_ 11 #define liblldb_InstrumentationRuntime_h_ 12 13 #include <map> 14 #include <vector> 15 16 #include "lldb/Core/PluginInterface.h" 17 #include "lldb/Utility/StructuredData.h" 18 #include "lldb/lldb-forward.h" 19 #include "lldb/lldb-private.h" 20 #include "lldb/lldb-types.h" 21 22 namespace lldb_private { 23 24 typedef std::map<lldb::InstrumentationRuntimeType, 25 lldb::InstrumentationRuntimeSP> 26 InstrumentationRuntimeCollection; 27 28 class InstrumentationRuntime 29 : public std::enable_shared_from_this<InstrumentationRuntime>, 30 public PluginInterface { 31 /// The instrumented process. 32 lldb::ProcessWP m_process_wp; 33 34 /// The module containing the instrumentation runtime. 35 lldb::ModuleSP m_runtime_module; 36 37 /// The breakpoint in the instrumentation runtime. 38 lldb::user_id_t m_breakpoint_id; 39 40 /// Indicates whether or not breakpoints have been registered in the 41 /// instrumentation runtime. 42 bool m_is_active; 43 44 protected: InstrumentationRuntime(const lldb::ProcessSP & process_sp)45 InstrumentationRuntime(const lldb::ProcessSP &process_sp) 46 : m_process_wp(), m_runtime_module(), m_breakpoint_id(0), 47 m_is_active(false) { 48 if (process_sp) 49 m_process_wp = process_sp; 50 } 51 GetProcessSP()52 lldb::ProcessSP GetProcessSP() { return m_process_wp.lock(); } 53 GetRuntimeModuleSP()54 lldb::ModuleSP GetRuntimeModuleSP() { return m_runtime_module; } 55 SetRuntimeModuleSP(lldb::ModuleSP module_sp)56 void SetRuntimeModuleSP(lldb::ModuleSP module_sp) { 57 m_runtime_module = module_sp; 58 } 59 GetBreakpointID()60 lldb::user_id_t GetBreakpointID() const { return m_breakpoint_id; } 61 SetBreakpointID(lldb::user_id_t ID)62 void SetBreakpointID(lldb::user_id_t ID) { m_breakpoint_id = ID; } 63 SetActive(bool IsActive)64 void SetActive(bool IsActive) { m_is_active = IsActive; } 65 66 /// Return a regular expression which can be used to identify a valid version 67 /// of the runtime library. 68 virtual const RegularExpression &GetPatternForRuntimeLibrary() = 0; 69 70 /// Check whether \p module_sp corresponds to a valid runtime library. 71 virtual bool CheckIfRuntimeIsValid(const lldb::ModuleSP module_sp) = 0; 72 73 /// Register a breakpoint in the runtime library and perform any other 74 /// necessary initialization. The runtime library 75 /// is guaranteed to be loaded. 76 virtual void Activate() = 0; 77 78 public: 79 static void ModulesDidLoad(lldb_private::ModuleList &module_list, 80 Process *process, 81 InstrumentationRuntimeCollection &runtimes); 82 83 /// Look for the instrumentation runtime in \p module_list. Register and 84 /// activate the runtime if this hasn't already 85 /// been done. 86 void ModulesDidLoad(lldb_private::ModuleList &module_list); 87 IsActive()88 bool IsActive() const { return m_is_active; } 89 90 virtual lldb::ThreadCollectionSP 91 GetBacktracesFromExtendedStopInfo(StructuredData::ObjectSP info); 92 }; 93 94 } // namespace lldb_private 95 96 #endif // liblldb_InstrumentationRuntime_h_ 97