1 //===-- ScriptedProcess.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 LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
10 #define LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
11 
12 #include "lldb/Target/Process.h"
13 #include "lldb/Utility/ConstString.h"
14 #include "lldb/Utility/Status.h"
15 
16 namespace lldb_private {
17 
18 class ScriptedProcess : public Process {
19 protected:
20   class LaunchInfo {
21   public:
22     LaunchInfo(const ProcessLaunchInfo &launch_info) {
23       m_class_name = launch_info.GetScriptedProcessClassName();
24       m_dictionary_sp = launch_info.GetScriptedProcessDictionarySP();
25     }
26 
27     std::string GetClassName() const { return m_class_name; }
28     StructuredData::DictionarySP GetDictionarySP() const {
29       return m_dictionary_sp;
30     }
31 
32   private:
33     std::string m_class_name;
34     StructuredData::DictionarySP m_dictionary_sp;
35   };
36 
37 public:
38   static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
39                                         lldb::ListenerSP listener_sp,
40                                         const FileSpec *crash_file_path,
41                                         bool can_connect);
42 
43   static void Initialize();
44 
45   static void Terminate();
46 
47   static ConstString GetPluginNameStatic();
48 
49   static const char *GetPluginDescriptionStatic();
50 
51   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
52                   const ScriptedProcess::LaunchInfo &launch_info);
53 
54   ~ScriptedProcess() override;
55 
56   bool CanDebug(lldb::TargetSP target_sp,
57                 bool plugin_specified_by_name) override;
58 
59   DynamicLoader *GetDynamicLoader() override { return nullptr; }
60 
61   ConstString GetPluginName() override;
62 
63   uint32_t GetPluginVersion() override;
64 
65   SystemRuntime *GetSystemRuntime() override { return nullptr; }
66 
67   Status DoLoadCore() override;
68 
69   Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
70 
71   void DidLaunch() override;
72 
73   Status DoResume() override;
74 
75   Status DoDestroy() override;
76 
77   void RefreshStateAfterStop() override{};
78 
79   bool IsAlive() override;
80 
81   size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size,
82                     Status &error) override;
83 
84   size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
85                       Status &error) override;
86 
87   ArchSpec GetArchitecture();
88 
89   Status GetMemoryRegionInfo(lldb::addr_t load_addr,
90                              MemoryRegionInfo &range_info) override;
91 
92   Status
93   GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list) override;
94 
95   bool GetProcessInfo(ProcessInstanceInfo &info) override;
96 
97 protected:
98   void Clear();
99 
100   bool DoUpdateThreadList(ThreadList &old_thread_list,
101                           ThreadList &new_thread_list) override;
102 
103 private:
104   ScriptedProcessInterface &GetInterface() const;
105 
106   const LaunchInfo m_launch_info;
107   lldb_private::ScriptInterpreter *m_interpreter = nullptr;
108   lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
109 };
110 
111 } // namespace lldb_private
112 
113 #endif // LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
114