1 //===-- ScriptedProcess.h ------------------------------------- -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
10 #define LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
12 #include "lldb/Target/Process.h"
13 #include "lldb/Utility/ConstString.h"
14 #include "lldb/Utility/ScriptedMetadata.h"
15 #include "lldb/Utility/State.h"
16 #include "lldb/Utility/Status.h"
18 #include "ScriptedThread.h"
22 namespace lldb_private
{
23 class ScriptedProcess
: public Process
{
25 static lldb::ProcessSP
CreateInstance(lldb::TargetSP target_sp
,
26 lldb::ListenerSP listener_sp
,
27 const FileSpec
*crash_file_path
,
30 static void Initialize();
32 static void Terminate();
34 static llvm::StringRef
GetPluginNameStatic() { return "ScriptedProcess"; }
36 static llvm::StringRef
GetPluginDescriptionStatic();
38 ~ScriptedProcess() override
;
40 bool CanDebug(lldb::TargetSP target_sp
,
41 bool plugin_specified_by_name
) override
;
43 DynamicLoader
*GetDynamicLoader() override
{ return nullptr; }
45 llvm::StringRef
GetPluginName() override
{ return GetPluginNameStatic(); }
47 Status
DoLoadCore() override
;
49 Status
DoLaunch(Module
*exe_module
, ProcessLaunchInfo
&launch_info
) override
;
51 void DidLaunch() override
;
53 void DidResume() override
;
55 Status
DoResume() override
;
57 Status
DoAttachToProcessWithID(lldb::pid_t pid
,
58 const ProcessAttachInfo
&attach_info
) override
;
61 DoAttachToProcessWithName(const char *process_name
,
62 const ProcessAttachInfo
&attach_info
) override
;
64 void DidAttach(ArchSpec
&process_arch
) override
;
66 Status
DoDestroy() override
;
68 void RefreshStateAfterStop() override
;
70 bool IsAlive() override
;
72 size_t DoReadMemory(lldb::addr_t addr
, void *buf
, size_t size
,
73 Status
&error
) override
;
75 size_t DoWriteMemory(lldb::addr_t vm_addr
, const void *buf
, size_t size
,
76 Status
&error
) override
;
78 Status
EnableBreakpointSite(BreakpointSite
*bp_site
) override
;
80 ArchSpec
GetArchitecture();
83 GetMemoryRegions(lldb_private::MemoryRegionInfos
®ion_list
) override
;
85 bool GetProcessInfo(ProcessInstanceInfo
&info
) override
;
87 lldb_private::StructuredData::ObjectSP
88 GetLoadedDynamicLibrariesInfos() override
;
90 lldb_private::StructuredData::DictionarySP
GetMetadata() override
;
92 void UpdateQueueListIfNeeded() override
;
94 void *GetImplementation() override
;
96 void ForceScriptedState(lldb::StateType state
) override
{
97 // If we're about to stop, we should fetch the loaded dynamic libraries
98 // dictionary before emitting the private stop event to avoid having the
99 // module loading happen while the process state is changing.
100 if (StateIsStoppedState(state
, true))
101 GetLoadedDynamicLibrariesInfos();
102 SetPrivateState(state
);
106 ScriptedProcess(lldb::TargetSP target_sp
, lldb::ListenerSP listener_sp
,
107 const ScriptedMetadata
&scripted_metadata
, Status
&error
);
111 bool DoUpdateThreadList(ThreadList
&old_thread_list
,
112 ThreadList
&new_thread_list
) override
;
114 Status
DoGetMemoryRegionInfo(lldb::addr_t load_addr
,
115 MemoryRegionInfo
&range_info
) override
;
117 Status
DoAttach(const ProcessAttachInfo
&attach_info
);
120 friend class ScriptedThread
;
122 inline void CheckScriptedInterface() const {
123 lldbassert(m_interface_up
&& "Invalid scripted process interface.");
126 ScriptedProcessInterface
&GetInterface() const;
127 static bool IsScriptLanguageSupported(lldb::ScriptLanguage language
);
130 const ScriptedMetadata m_scripted_metadata
;
131 lldb::ScriptedProcessInterfaceUP m_interface_up
;
134 } // namespace lldb_private
136 #endif // LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H