LLDB mainline
ScriptedProcess.h
Go to the documentation of this file.
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"
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:
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
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
79
81
82 Status
84
85 bool GetProcessInfo(ProcessInstanceInfo &info) override;
86
89
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, true))
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
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
128
129 // Member variables.
132};
133
134} // namespace lldb_private
135
136#endif // LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
static llvm::raw_ostream & error(Stream &strm)
#define lldbassert(x)
Definition: LLDBAssert.h:15
An architecture specification class.
Definition: ArchSpec.h:31
Class that manages the actual breakpoint that will be inserted into the running program.
A plug-in interface definition class for dynamic loaders.
Definition: DynamicLoader.h:52
A file utility class.
Definition: FileSpec.h:56
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:88
A plug-in interface definition class for debugging a process.
Definition: Process.h:340
void SetPrivateState(lldb::StateType state)
Definition: Process.cpp:1419
Status DoResume() override
Resumes all of a process's threads as configured using the Thread run control functions.
Status DoAttachToProcessWithID(lldb::pid_t pid, const ProcessAttachInfo &attach_info) override
Attach to an existing process using a process ID.
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
bool DoUpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list) override
Update the thread list following process plug-in's specific logic.
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, Status &error) override
Actually do the reading of memory from a process.
lldb_private::StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos() override
const ScriptedMetadata m_scripted_metadata
void DidAttach(ArchSpec &process_arch) override
Called after attaching a process.
static llvm::StringRef GetPluginNameStatic()
Status GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list) override
Obtain all the mapped memory regions within this process.
static bool IsScriptLanguageSupported(lldb::ScriptLanguage language)
bool IsAlive() override
Check if a process is still alive.
Status DoAttach(const ProcessAttachInfo &attach_info)
bool GetProcessInfo(ProcessInstanceInfo &info) override
void DidResume() override
Called after resuming a process.
DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override
Launch a new process.
size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size, Status &error) override
Actually do the writing of memory to a process.
lldb::ScriptedProcessInterfaceUP m_interface_up
llvm::StringRef GetPluginName() override
Status EnableBreakpointSite(BreakpointSite *bp_site) override
void ForceScriptedState(lldb::StateType state) override
lldb_private::StructuredData::DictionarySP GetMetadata() override
Fetch process defined metadata.
Status DoAttachToProcessWithName(const char *process_name, const ProcessAttachInfo &attach_info) override
Attach to an existing process using a partial process name.
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const FileSpec *crash_file_path, bool can_connect)
static llvm::StringRef GetPluginDescriptionStatic()
ScriptedProcessInterface & GetInterface() const
void DidLaunch() override
Called after launching a process.
Status DoGetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) override
DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has removed non address bits from loa...
An error handling class.
Definition: Status.h:44
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
bool StateIsStoppedState(lldb::StateType state, bool must_exist)
Check if a state represents a state where the process or thread is stopped.
Definition: State.cpp:89
ScriptLanguage
Script interpreter types.
StateType
Process and Thread States.
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:381
uint64_t pid_t
Definition: lldb-types.h:81
std::shared_ptr< lldb_private::Listener > ListenerSP
Definition: lldb-forward.h:360
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:436
std::unique_ptr< lldb_private::ScriptedProcessInterface > ScriptedProcessInterfaceUP
Definition: lldb-forward.h:403