xref: /src/contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedProcess.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1344a3780SDimitry Andric //===-- ScriptedProcess.h ------------------------------------- -*- C++ -*-===//
2344a3780SDimitry Andric //
3344a3780SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4344a3780SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5344a3780SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6344a3780SDimitry Andric //
7344a3780SDimitry Andric //===----------------------------------------------------------------------===//
8344a3780SDimitry Andric 
9344a3780SDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
10344a3780SDimitry Andric #define LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
11344a3780SDimitry Andric 
12344a3780SDimitry Andric #include "lldb/Target/Process.h"
13344a3780SDimitry Andric #include "lldb/Utility/ConstString.h"
147fa27ce4SDimitry Andric #include "lldb/Utility/ScriptedMetadata.h"
157fa27ce4SDimitry Andric #include "lldb/Utility/State.h"
16344a3780SDimitry Andric #include "lldb/Utility/Status.h"
17344a3780SDimitry Andric 
18c0981da4SDimitry Andric #include "ScriptedThread.h"
19c0981da4SDimitry Andric 
20344a3780SDimitry Andric #include <mutex>
21344a3780SDimitry Andric 
22344a3780SDimitry Andric namespace lldb_private {
23344a3780SDimitry Andric class ScriptedProcess : public Process {
24344a3780SDimitry Andric public:
25344a3780SDimitry Andric   static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
26344a3780SDimitry Andric                                         lldb::ListenerSP listener_sp,
27344a3780SDimitry Andric                                         const FileSpec *crash_file_path,
28344a3780SDimitry Andric                                         bool can_connect);
29344a3780SDimitry Andric 
30344a3780SDimitry Andric   static void Initialize();
31344a3780SDimitry Andric 
32344a3780SDimitry Andric   static void Terminate();
33344a3780SDimitry Andric 
GetPluginNameStatic()34c0981da4SDimitry Andric   static llvm::StringRef GetPluginNameStatic() { return "ScriptedProcess"; }
35344a3780SDimitry Andric 
36c0981da4SDimitry Andric   static llvm::StringRef GetPluginDescriptionStatic();
37344a3780SDimitry Andric 
38344a3780SDimitry Andric   ~ScriptedProcess() override;
39344a3780SDimitry Andric 
40344a3780SDimitry Andric   bool CanDebug(lldb::TargetSP target_sp,
41344a3780SDimitry Andric                 bool plugin_specified_by_name) override;
42344a3780SDimitry Andric 
GetDynamicLoader()43344a3780SDimitry Andric   DynamicLoader *GetDynamicLoader() override { return nullptr; }
44344a3780SDimitry Andric 
GetPluginName()45c0981da4SDimitry Andric   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
46344a3780SDimitry Andric 
47344a3780SDimitry Andric   Status DoLoadCore() override;
48344a3780SDimitry Andric 
49344a3780SDimitry Andric   Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
50344a3780SDimitry Andric 
51344a3780SDimitry Andric   void DidLaunch() override;
52344a3780SDimitry Andric 
537fa27ce4SDimitry Andric   void DidResume() override;
547fa27ce4SDimitry Andric 
55344a3780SDimitry Andric   Status DoResume() override;
56344a3780SDimitry Andric 
577fa27ce4SDimitry Andric   Status DoAttachToProcessWithID(lldb::pid_t pid,
587fa27ce4SDimitry Andric                                  const ProcessAttachInfo &attach_info) override;
597fa27ce4SDimitry Andric 
607fa27ce4SDimitry Andric   Status
617fa27ce4SDimitry Andric   DoAttachToProcessWithName(const char *process_name,
627fa27ce4SDimitry Andric                             const ProcessAttachInfo &attach_info) override;
637fa27ce4SDimitry Andric 
647fa27ce4SDimitry Andric   void DidAttach(ArchSpec &process_arch) override;
657fa27ce4SDimitry Andric 
66344a3780SDimitry Andric   Status DoDestroy() override;
67344a3780SDimitry Andric 
68c0981da4SDimitry Andric   void RefreshStateAfterStop() override;
69344a3780SDimitry Andric 
70344a3780SDimitry Andric   bool IsAlive() override;
71344a3780SDimitry Andric 
72344a3780SDimitry Andric   size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
73344a3780SDimitry Andric                       Status &error) override;
74344a3780SDimitry Andric 
757fa27ce4SDimitry Andric   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
767fa27ce4SDimitry Andric                        Status &error) override;
777fa27ce4SDimitry Andric 
787fa27ce4SDimitry Andric   Status EnableBreakpointSite(BreakpointSite *bp_site) override;
797fa27ce4SDimitry Andric 
80344a3780SDimitry Andric   ArchSpec GetArchitecture();
81344a3780SDimitry Andric 
82344a3780SDimitry Andric   Status
83344a3780SDimitry Andric   GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list) override;
84344a3780SDimitry Andric 
85344a3780SDimitry Andric   bool GetProcessInfo(ProcessInstanceInfo &info) override;
86344a3780SDimitry Andric 
87145449b1SDimitry Andric   lldb_private::StructuredData::ObjectSP
88145449b1SDimitry Andric   GetLoadedDynamicLibrariesInfos() override;
89145449b1SDimitry Andric 
90e3b55780SDimitry Andric   lldb_private::StructuredData::DictionarySP GetMetadata() override;
91e3b55780SDimitry Andric 
92e3b55780SDimitry Andric   void UpdateQueueListIfNeeded() override;
93e3b55780SDimitry Andric 
947fa27ce4SDimitry Andric   void *GetImplementation() override;
957fa27ce4SDimitry Andric 
ForceScriptedState(lldb::StateType state)967fa27ce4SDimitry Andric   void ForceScriptedState(lldb::StateType state) override {
977fa27ce4SDimitry Andric     // If we're about to stop, we should fetch the loaded dynamic libraries
987fa27ce4SDimitry Andric     // dictionary before emitting the private stop event to avoid having the
997fa27ce4SDimitry Andric     // module loading happen while the process state is changing.
1007fa27ce4SDimitry Andric     if (StateIsStoppedState(state, true))
1017fa27ce4SDimitry Andric       GetLoadedDynamicLibrariesInfos();
1027fa27ce4SDimitry Andric     SetPrivateState(state);
1037fa27ce4SDimitry Andric   }
1047fa27ce4SDimitry Andric 
105344a3780SDimitry Andric protected:
106e3b55780SDimitry Andric   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
107e3b55780SDimitry Andric                   const ScriptedMetadata &scripted_metadata, Status &error);
108e3b55780SDimitry Andric 
109344a3780SDimitry Andric   void Clear();
110344a3780SDimitry Andric 
111344a3780SDimitry Andric   bool DoUpdateThreadList(ThreadList &old_thread_list,
112344a3780SDimitry Andric                           ThreadList &new_thread_list) override;
113344a3780SDimitry Andric 
114145449b1SDimitry Andric   Status DoGetMemoryRegionInfo(lldb::addr_t load_addr,
115145449b1SDimitry Andric                                MemoryRegionInfo &range_info) override;
116145449b1SDimitry Andric 
1177fa27ce4SDimitry Andric   Status DoAttach(const ProcessAttachInfo &attach_info);
1187fa27ce4SDimitry Andric 
119344a3780SDimitry Andric private:
120c0981da4SDimitry Andric   friend class ScriptedThread;
121c0981da4SDimitry Andric 
CheckScriptedInterface()1227fa27ce4SDimitry Andric   inline void CheckScriptedInterface() const {
1237fa27ce4SDimitry Andric     lldbassert(m_interface_up && "Invalid scripted process interface.");
1247fa27ce4SDimitry Andric   }
1257fa27ce4SDimitry Andric 
126344a3780SDimitry Andric   ScriptedProcessInterface &GetInterface() const;
127344a3780SDimitry Andric   static bool IsScriptLanguageSupported(lldb::ScriptLanguage language);
128344a3780SDimitry Andric 
129344a3780SDimitry Andric   // Member variables.
130e3b55780SDimitry Andric   const ScriptedMetadata m_scripted_metadata;
1317fa27ce4SDimitry Andric   lldb::ScriptedProcessInterfaceUP m_interface_up;
132344a3780SDimitry Andric };
133344a3780SDimitry Andric 
134344a3780SDimitry Andric } // namespace lldb_private
135344a3780SDimitry Andric 
136344a3780SDimitry Andric #endif // LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
137