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