LLDB mainline
ProcessKDP.h
Go to the documentation of this file.
1//===-- ProcessKDP.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_PROCESS_MACOSX_KERNEL_PROCESSKDP_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_MACOSX_KERNEL_PROCESSKDP_H
11
12#include <list>
13#include <vector>
14
17#include "lldb/Target/Process.h"
18#include "lldb/Target/Thread.h"
22#include "lldb/Utility/Status.h"
25
26#include "CommunicationKDP.h"
27
28class ThreadKDP;
29
31public:
32 // Constructors and Destructors
33 static lldb::ProcessSP
34 CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
35 const lldb_private::FileSpec *crash_file_path,
36 bool can_connect);
37
38 static void Initialize();
39
40 static void DebuggerInitialize(lldb_private::Debugger &debugger);
41
42 static void Terminate();
43
44 static llvm::StringRef GetPluginNameStatic() { return "kdp-remote"; }
45
46 static llvm::StringRef GetPluginDescriptionStatic();
47
48 // Constructors and Destructors
49 ProcessKDP(lldb::TargetSP target_sp, lldb::ListenerSP listener);
50
51 ~ProcessKDP() override;
52
53 // Check if a given Process
54 bool CanDebug(lldb::TargetSP target_sp,
55 bool plugin_specified_by_name) override;
57
58 // Creating a new process, or attaching to an existing one
60
63 lldb_private::ProcessLaunchInfo &launch_info) override;
64
66
68 DoWillAttachToProcessWithName(const char *process_name,
69 bool wait_for_launch) override;
70
71 lldb_private::Status DoConnectRemote(llvm::StringRef remote_url) override;
72
74 lldb::pid_t pid,
75 const lldb_private::ProcessAttachInfo &attach_info) override;
76
78 const char *process_name,
79 const lldb_private::ProcessAttachInfo &attach_info) override;
80
81 void DidAttach(lldb_private::ArchSpec &process_arch) override;
82
84
86
87 // PluginInterface protocol
88 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
89
90 // Process Control
92
94
95 lldb_private::Status DoHalt(bool &caused_stop) override;
96
97 lldb_private::Status DoDetach(bool keep_stopped) override;
98
99 lldb_private::Status DoSignal(int signal) override;
100
102
103 void RefreshStateAfterStop() override;
104
105 // Process Queries
106 bool IsAlive() override;
107
108 // Process Memory
109 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
110 lldb_private::Status &error) override;
111
112 size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size,
113 lldb_private::Status &error) override;
114
115 lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
116 lldb_private::Status &error) override;
117
119
120 // Process Breakpoints
123
126
128
129protected:
130 friend class ThreadKDP;
131 friend class CommunicationKDP;
132
133 // Accessors
135 return state == lldb::eStateRunning || IsStepping(state);
136 }
137
139 return state == lldb::eStateStepping;
140 }
141
142 bool CanResume(lldb::StateType state) { return state == lldb::eStateStopped; }
143
144 bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; }
145
147
148 bool ProcessIDIsValid() const;
149
150 void Clear();
151
152 bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
153 lldb_private::ThreadList &new_thread_list) override;
154
155 enum {
158 };
159
161
162 /// Broadcaster event bits definitions.
166 llvm::StringRef m_dyld_plugin_name;
170
171 bool StartAsyncThread();
172
173 void StopAsyncThread();
174
175 void *AsyncThread();
176
177private:
178 // For ProcessKDP only
179
180 ProcessKDP(const ProcessKDP &) = delete;
181 const ProcessKDP &operator=(const ProcessKDP &) = delete;
182};
183
184#endif // LLDB_SOURCE_PLUGINS_PROCESS_MACOSX_KERNEL_PROCESSKDP_H
static llvm::raw_ostream & error(Stream &strm)
lldb_private::Status DoWillLaunch(lldb_private::Module *module) override
Called before launching to a process.
Definition: ProcessKDP.cpp:171
lldb_private::Broadcaster m_async_broadcaster
Definition: ProcessKDP.h:164
@ eBroadcastBitAsyncThreadShouldExit
Definition: ProcessKDP.h:157
@ eBroadcastBitAsyncContinue
Definition: ProcessKDP.h:156
llvm::StringRef GetPluginName() override
Definition: ProcessKDP.h:88
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Actually do the reading of memory from a process.
Definition: ProcessKDP.cpp:582
lldb::CommandObjectSP m_command_sp
Definition: ProcessKDP.h:168
void DidAttach(lldb_private::ArchSpec &process_arch) override
Called after attaching a process.
Definition: ProcessKDP.cpp:385
static void Terminate()
Definition: ProcessKDP.cpp:99
lldb_private::Status EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override
Definition: ProcessKDP.cpp:632
bool IsRunning(lldb::StateType state)
Definition: ProcessKDP.h:134
lldb::ThreadSP GetKernelThread()
Definition: ProcessKDP.cpp:484
static llvm::StringRef GetPluginDescriptionStatic()
Definition: ProcessKDP.cpp:94
static void Initialize()
Definition: ProcessKDP.cpp:684
llvm::StringRef m_dyld_plugin_name
Definition: ProcessKDP.h:166
bool GetHostArchitecture(lldb_private::ArchSpec &arch)
Definition: ProcessKDP.cpp:192
lldb::ThreadWP m_kernel_thread_wp
Definition: ProcessKDP.h:169
lldb_private::Status DoLaunch(lldb_private::Module *exe_module, lldb_private::ProcessLaunchInfo &launch_info) override
Launch a new process.
Definition: ProcessKDP.cpp:360
void * AsyncThread()
Definition: ProcessKDP.cpp:737
lldb_private::Status DoSignal(int signal) override
Sends a process a UNIX signal signal.
Definition: ProcessKDP.cpp:677
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
Definition: ProcessKDP.cpp:513
lldb_private::HostThread m_async_thread
Definition: ProcessKDP.h:165
const ProcessKDP & operator=(const ProcessKDP &)=delete
~ProcessKDP() override
Definition: ProcessKDP.cpp:162
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
Definition: ProcessKDP.cpp:397
CommunicationKDP & GetCommunication()
Definition: ProcessKDP.h:127
lldb_private::Status WillResume() override
Called before resuming to a process.
Definition: ProcessKDP.cpp:403
ProcessKDP(const ProcessKDP &)=delete
lldb_private::Status DoHalt(bool &caused_stop) override
Halts a running process.
Definition: ProcessKDP.cpp:519
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec *crash_file_path, bool can_connect)
Definition: ProcessKDP.cpp:103
lldb::addr_t m_kernel_load_addr
Definition: ProcessKDP.h:167
void Clear()
Definition: ProcessKDP.cpp:675
bool ProcessIDIsValid() const
lldb_private::Status DoConnectRemote(llvm::StringRef remote_url) override
Attach to a remote system via a URL.
Definition: ProcessKDP.cpp:206
bool IsAlive() override
Check if a process is still alive.
Definition: ProcessKDP.cpp:577
lldb_private::CommandObject * GetPluginCommandObject() override
Return a multi-word command object that can be used to expose plug-in specific commands.
Definition: ProcessKDP.cpp:979
bool StartAsyncThread()
Definition: ProcessKDP.cpp:706
bool CanResume(lldb::StateType state)
Definition: ProcessKDP.h:142
lldb_private::Status DoAttachToProcessWithName(const char *process_name, const lldb_private::ProcessAttachInfo &attach_info) override
Attach to an existing process using a partial process name.
Definition: ProcessKDP.cpp:377
lldb_private::Status DoWillAttachToProcessWithName(const char *process_name, bool wait_for_launch) override
Called before attaching to a process.
Definition: ProcessKDP.cpp:184
bool HasExited(lldb::StateType state)
Definition: ProcessKDP.h:144
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
Definition: ProcessKDP.cpp:395
bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list) override
Update the thread list following process plug-in's specific logic.
Definition: ProcessKDP.cpp:496
static void DebuggerInitialize(lldb_private::Debugger &debugger)
Definition: ProcessKDP.cpp:696
CommunicationKDP m_comm
Broadcaster event bits definitions.
Definition: ProcessKDP.h:163
lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions, lldb_private::Status &error) override
Actually allocate memory in the process.
Definition: ProcessKDP.cpp:618
lldb_private::Status DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override
Definition: ProcessKDP.cpp:651
lldb_private::Status DoWillAttachToProcessWithID(lldb::pid_t pid) override
Called before attaching to a process.
Definition: ProcessKDP.cpp:177
lldb_private::Status DoAttachToProcessWithID(lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info) override
Attach to an existing process using a process ID.
Definition: ProcessKDP.cpp:368
size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size, lldb_private::Status &error) override
Actually do the writing of memory to a process.
Definition: ProcessKDP.cpp:610
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
Definition: ProcessKDP.cpp:113
lldb_private::Status DoDetach(bool keep_stopped) override
Detaches from a running or stopped process.
Definition: ProcessKDP.cpp:535
lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override
Actually deallocate memory in the process.
Definition: ProcessKDP.cpp:625
lldb_private::Status DoDestroy() override
Definition: ProcessKDP.cpp:569
void StopAsyncThread()
Definition: ProcessKDP.cpp:725
bool IsStepping(lldb::StateType state)
Definition: ProcessKDP.h:138
lldb_private::Status DoResume() override
Resumes all of a process's threads as configured using the Thread run control functions.
Definition: ProcessKDP.cpp:405
static llvm::StringRef GetPluginNameStatic()
Definition: ProcessKDP.h:44
An architecture specification class.
Definition: ArchSpec.h:31
Class that manages the actual breakpoint that will be inserted into the running program.
An event broadcasting class.
Definition: Broadcaster.h:145
A class to manage flag bits.
Definition: Debugger.h:80
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:341
An error handling class.
Definition: Status.h:44
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:441
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:328
StateType
Process and Thread States.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateRunning
Process or thread is running and can't be examined.
@ eStateExited
Process has exited and can't be examined.
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:384
uint64_t pid_t
Definition: lldb-types.h:83
std::shared_ptr< lldb_private::Listener > ListenerSP
Definition: lldb-forward.h:363
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:439
std::weak_ptr< lldb_private::Thread > ThreadWP
Definition: lldb-forward.h:442