1 //===-- OperatingSystemPython.h ---------------------------------*- C++ -*-===// 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 #ifndef liblldb_OperatingSystemPython_h_ 10 #define liblldb_OperatingSystemPython_h_ 11 12 #include "lldb/Host/Config.h" 13 14 #if LLDB_ENABLE_PYTHON 15 16 #include "lldb/Target/DynamicRegisterInfo.h" 17 #include "lldb/Target/OperatingSystem.h" 18 #include "lldb/Utility/StructuredData.h" 19 20 namespace lldb_private { 21 class ScriptInterpreter; 22 } 23 24 class OperatingSystemPython : public lldb_private::OperatingSystem { 25 public: 26 OperatingSystemPython(lldb_private::Process *process, 27 const lldb_private::FileSpec &python_module_path); 28 29 ~OperatingSystemPython() override; 30 31 // Static Functions 32 static lldb_private::OperatingSystem * 33 CreateInstance(lldb_private::Process *process, bool force); 34 35 static void Initialize(); 36 37 static void Terminate(); 38 39 static lldb_private::ConstString GetPluginNameStatic(); 40 41 static const char *GetPluginDescriptionStatic(); 42 43 // lldb_private::PluginInterface Methods 44 llvm::StringRef GetPluginName() override { 45 return GetPluginNameStatic().GetStringRef(); 46 } 47 48 // lldb_private::OperatingSystem Methods 49 bool UpdateThreadList(lldb_private::ThreadList &old_thread_list, 50 lldb_private::ThreadList &real_thread_list, 51 lldb_private::ThreadList &new_thread_list) override; 52 53 void ThreadWasSelected(lldb_private::Thread *thread) override; 54 55 lldb::RegisterContextSP 56 CreateRegisterContextForThread(lldb_private::Thread *thread, 57 lldb::addr_t reg_data_addr) override; 58 59 lldb::StopInfoSP 60 CreateThreadStopReason(lldb_private::Thread *thread) override; 61 62 // Method for lazy creation of threads on demand 63 lldb::ThreadSP CreateThread(lldb::tid_t tid, lldb::addr_t context) override; 64 65 protected: 66 bool IsValid() const { 67 return m_python_object_sp && m_python_object_sp->IsValid(); 68 } 69 70 lldb::ThreadSP CreateThreadFromThreadInfo( 71 lldb_private::StructuredData::Dictionary &thread_dict, 72 lldb_private::ThreadList &core_thread_list, 73 lldb_private::ThreadList &old_thread_list, 74 std::vector<bool> &core_used_map, bool *did_create_ptr); 75 76 lldb_private::DynamicRegisterInfo *GetDynamicRegisterInfo(); 77 78 lldb::ValueObjectSP m_thread_list_valobj_sp; 79 std::unique_ptr<lldb_private::DynamicRegisterInfo> m_register_info_up; 80 lldb_private::ScriptInterpreter *m_interpreter; 81 lldb_private::StructuredData::ObjectSP m_python_object_sp; 82 }; 83 84 #endif // LLDB_ENABLE_PYTHON 85 86 #endif // liblldb_OperatingSystemPython_h_ 87