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