1fe6060f1SDimitry Andric //===-- ScriptedProcess.h ------------------------------------- -*- C++ -*-===// 2fe6060f1SDimitry Andric // 3fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6fe6060f1SDimitry Andric // 7fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 8fe6060f1SDimitry Andric 9fe6060f1SDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H 10fe6060f1SDimitry Andric #define LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H 11fe6060f1SDimitry Andric 12fe6060f1SDimitry Andric #include "lldb/Target/Process.h" 13fe6060f1SDimitry Andric #include "lldb/Utility/ConstString.h" 14*06c3fb27SDimitry Andric #include "lldb/Utility/ScriptedMetadata.h" 15*06c3fb27SDimitry Andric #include "lldb/Utility/State.h" 16fe6060f1SDimitry Andric #include "lldb/Utility/Status.h" 17fe6060f1SDimitry Andric 18349cc55cSDimitry Andric #include "ScriptedThread.h" 19349cc55cSDimitry Andric 20fe6060f1SDimitry Andric #include <mutex> 21fe6060f1SDimitry Andric 22fe6060f1SDimitry Andric namespace lldb_private { 23fe6060f1SDimitry Andric class ScriptedProcess : public Process { 24fe6060f1SDimitry Andric public: 25fe6060f1SDimitry Andric static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, 26fe6060f1SDimitry Andric lldb::ListenerSP listener_sp, 27fe6060f1SDimitry Andric const FileSpec *crash_file_path, 28fe6060f1SDimitry Andric bool can_connect); 29fe6060f1SDimitry Andric 30fe6060f1SDimitry Andric static void Initialize(); 31fe6060f1SDimitry Andric 32fe6060f1SDimitry Andric static void Terminate(); 33fe6060f1SDimitry Andric GetPluginNameStatic()34349cc55cSDimitry Andric static llvm::StringRef GetPluginNameStatic() { return "ScriptedProcess"; } 35fe6060f1SDimitry Andric 36349cc55cSDimitry Andric static llvm::StringRef GetPluginDescriptionStatic(); 37fe6060f1SDimitry Andric 38fe6060f1SDimitry Andric ~ScriptedProcess() override; 39fe6060f1SDimitry Andric 40fe6060f1SDimitry Andric bool CanDebug(lldb::TargetSP target_sp, 41fe6060f1SDimitry Andric bool plugin_specified_by_name) override; 42fe6060f1SDimitry Andric GetDynamicLoader()43fe6060f1SDimitry Andric DynamicLoader *GetDynamicLoader() override { return nullptr; } 44fe6060f1SDimitry Andric GetPluginName()45349cc55cSDimitry Andric llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } 46fe6060f1SDimitry Andric 47fe6060f1SDimitry Andric Status DoLoadCore() override; 48fe6060f1SDimitry Andric 49fe6060f1SDimitry Andric Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override; 50fe6060f1SDimitry Andric 51fe6060f1SDimitry Andric void DidLaunch() override; 52fe6060f1SDimitry Andric 53*06c3fb27SDimitry Andric void DidResume() override; 54*06c3fb27SDimitry Andric 55fe6060f1SDimitry Andric Status DoResume() override; 56fe6060f1SDimitry Andric 57*06c3fb27SDimitry Andric Status DoAttachToProcessWithID(lldb::pid_t pid, 58*06c3fb27SDimitry Andric const ProcessAttachInfo &attach_info) override; 59*06c3fb27SDimitry Andric 60*06c3fb27SDimitry Andric Status 61*06c3fb27SDimitry Andric DoAttachToProcessWithName(const char *process_name, 62*06c3fb27SDimitry Andric const ProcessAttachInfo &attach_info) override; 63*06c3fb27SDimitry Andric 64*06c3fb27SDimitry Andric void DidAttach(ArchSpec &process_arch) override; 65*06c3fb27SDimitry Andric 66fe6060f1SDimitry Andric Status DoDestroy() override; 67fe6060f1SDimitry Andric 68349cc55cSDimitry Andric void RefreshStateAfterStop() override; 69fe6060f1SDimitry Andric 70fe6060f1SDimitry Andric bool IsAlive() override; 71fe6060f1SDimitry Andric 72fe6060f1SDimitry Andric size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, 73fe6060f1SDimitry Andric Status &error) override; 74fe6060f1SDimitry Andric 75*06c3fb27SDimitry Andric size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, 76*06c3fb27SDimitry Andric Status &error) override; 77*06c3fb27SDimitry Andric 78*06c3fb27SDimitry Andric Status EnableBreakpointSite(BreakpointSite *bp_site) override; 79*06c3fb27SDimitry Andric 80fe6060f1SDimitry Andric ArchSpec GetArchitecture(); 81fe6060f1SDimitry Andric 82fe6060f1SDimitry Andric Status 83fe6060f1SDimitry Andric GetMemoryRegions(lldb_private::MemoryRegionInfos ®ion_list) override; 84fe6060f1SDimitry Andric 85fe6060f1SDimitry Andric bool GetProcessInfo(ProcessInstanceInfo &info) override; 86fe6060f1SDimitry Andric 8781ad6265SDimitry Andric lldb_private::StructuredData::ObjectSP 8881ad6265SDimitry Andric GetLoadedDynamicLibrariesInfos() override; 8981ad6265SDimitry Andric 90bdd1243dSDimitry Andric lldb_private::StructuredData::DictionarySP GetMetadata() override; 91bdd1243dSDimitry Andric 92bdd1243dSDimitry Andric void UpdateQueueListIfNeeded() override; 93bdd1243dSDimitry Andric 94*06c3fb27SDimitry Andric void *GetImplementation() override; 95*06c3fb27SDimitry Andric ForceScriptedState(lldb::StateType state)96*06c3fb27SDimitry Andric void ForceScriptedState(lldb::StateType state) override { 97*06c3fb27SDimitry Andric // If we're about to stop, we should fetch the loaded dynamic libraries 98*06c3fb27SDimitry Andric // dictionary before emitting the private stop event to avoid having the 99*06c3fb27SDimitry Andric // module loading happen while the process state is changing. 100*06c3fb27SDimitry Andric if (StateIsStoppedState(state, true)) 101*06c3fb27SDimitry Andric GetLoadedDynamicLibrariesInfos(); 102*06c3fb27SDimitry Andric SetPrivateState(state); 103*06c3fb27SDimitry Andric } 104*06c3fb27SDimitry Andric 105fe6060f1SDimitry Andric protected: 106bdd1243dSDimitry Andric ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, 107bdd1243dSDimitry Andric const ScriptedMetadata &scripted_metadata, Status &error); 108bdd1243dSDimitry Andric 109fe6060f1SDimitry Andric void Clear(); 110fe6060f1SDimitry Andric 111fe6060f1SDimitry Andric bool DoUpdateThreadList(ThreadList &old_thread_list, 112fe6060f1SDimitry Andric ThreadList &new_thread_list) override; 113fe6060f1SDimitry Andric 114d56accc7SDimitry Andric Status DoGetMemoryRegionInfo(lldb::addr_t load_addr, 115d56accc7SDimitry Andric MemoryRegionInfo &range_info) override; 116d56accc7SDimitry Andric 117*06c3fb27SDimitry Andric Status DoAttach(const ProcessAttachInfo &attach_info); 118*06c3fb27SDimitry Andric 119fe6060f1SDimitry Andric private: 120349cc55cSDimitry Andric friend class ScriptedThread; 121349cc55cSDimitry Andric CheckScriptedInterface()122*06c3fb27SDimitry Andric inline void CheckScriptedInterface() const { 123*06c3fb27SDimitry Andric lldbassert(m_interface_up && "Invalid scripted process interface."); 124*06c3fb27SDimitry Andric } 125*06c3fb27SDimitry Andric 126fe6060f1SDimitry Andric ScriptedProcessInterface &GetInterface() const; 127fe6060f1SDimitry Andric static bool IsScriptLanguageSupported(lldb::ScriptLanguage language); 128fe6060f1SDimitry Andric 129fe6060f1SDimitry Andric // Member variables. 130bdd1243dSDimitry Andric const ScriptedMetadata m_scripted_metadata; 131*06c3fb27SDimitry Andric lldb::ScriptedProcessInterfaceUP m_interface_up; 132fe6060f1SDimitry Andric }; 133fe6060f1SDimitry Andric 134fe6060f1SDimitry Andric } // namespace lldb_private 135fe6060f1SDimitry Andric 136fe6060f1SDimitry Andric #endif // LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H 137