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/ScriptedMetadata.h"
15#include "lldb/Utility/State.h"
16#include "lldb/Utility/Status.h"
17
18#include "ScriptedThread.h"
19
20#include <mutex>
21
22namespace lldb_private {
23class ScriptedProcess : public Process {
24public:
25 static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
26 lldb::ListenerSP listener_sp,
27 const FileSpec *crash_file_path,
28 bool can_connect);
29
30 static void Initialize();
31
32 static void Terminate();
33
34 static llvm::StringRef GetPluginNameStatic() { return "ScriptedProcess"; }
35
36 static llvm::StringRef GetPluginDescriptionStatic();
37
38 ~ScriptedProcess() override;
39
40 bool CanDebug(lldb::TargetSP target_sp,
41 bool plugin_specified_by_name) override;
42
43 DynamicLoader *GetDynamicLoader() override { return nullptr; }
44
45 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
46
47 Status DoLoadCore() override;
48
49 Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
50
51 void DidLaunch() override;
52
53 void DidResume() override;
54
55 Status DoResume() override;
56
57 Status DoAttachToProcessWithID(lldb::pid_t pid,
58 const ProcessAttachInfo &attach_info) override;
59
60 Status
61 DoAttachToProcessWithName(const char *process_name,
62 const ProcessAttachInfo &attach_info) override;
63
64 void DidAttach(ArchSpec &process_arch) override;
65
66 Status DoDestroy() override;
67
68 void RefreshStateAfterStop() override;
69
70 bool IsAlive() override;
71
72 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
73 Status &error) override;
74
75 size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
76 Status &error) override;
77
78 Status EnableBreakpointSite(BreakpointSite *bp_site) override;
79
80 ArchSpec GetArchitecture();
81
82 Status
83 GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list) override;
84
85 bool GetProcessInfo(ProcessInstanceInfo &info) override;
86
87 lldb_private::StructuredData::ObjectSP
88 GetLoadedDynamicLibrariesInfos() override;
89
90 lldb_private::StructuredData::DictionarySP GetMetadata() override;
91
92 void UpdateQueueListIfNeeded() override;
93
94 void *GetImplementation() override;
95
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, must_exist: true))
101 GetLoadedDynamicLibrariesInfos();
102 SetPrivateState(state);
103 }
104
105protected:
106 ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
107 const ScriptedMetadata &scripted_metadata, Status &error);
108
109 void Clear();
110
111 bool DoUpdateThreadList(ThreadList &old_thread_list,
112 ThreadList &new_thread_list) override;
113
114 Status DoGetMemoryRegionInfo(lldb::addr_t load_addr,
115 MemoryRegionInfo &range_info) override;
116
117 Status DoAttach(const ProcessAttachInfo &attach_info);
118
119private:
120 friend class ScriptedThread;
121
122 inline void CheckScriptedInterface() const {
123 lldbassert(m_interface_up && "Invalid scripted process interface.");
124 }
125
126 ScriptedProcessInterface &GetInterface() const;
127 static bool IsScriptLanguageSupported(lldb::ScriptLanguage language);
128
129 // Member variables.
130 const ScriptedMetadata m_scripted_metadata;
131 lldb::ScriptedProcessInterfaceUP m_interface_up;
132};
133
134} // namespace lldb_private
135
136#endif // LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
137

source code of lldb/source/Plugins/Process/scripted/ScriptedProcess.h