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 
16 #include "lldb/Host/HostThread.h"
17 #include "lldb/Target/Process.h"
18 #include "lldb/Target/Thread.h"
19 #include "lldb/Utility/ArchSpec.h"
22 #include "lldb/Utility/Status.h"
25 
26 #include "CommunicationKDP.h"
27 
28 class ThreadKDP;
29 
31 public:
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 
62  DoLaunch(lldb_private::Module *exe_module,
63  lldb_private::ProcessLaunchInfo &launch_info) override;
64 
66 
68  WillAttachToProcessWithName(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 
93  lldb_private::Status DoResume() override;
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 
101  lldb_private::Status DoDestroy() override;
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 
127  // Process Watchpoints
129  bool notify = true) override;
130 
132  bool notify = true) override;
133 
135 
136 protected:
137  friend class ThreadKDP;
138  friend class CommunicationKDP;
139 
140  // Accessors
142  return state == lldb::eStateRunning || IsStepping(state);
143  }
144 
146  return state == lldb::eStateStepping;
147  }
148 
149  bool CanResume(lldb::StateType state) { return state == lldb::eStateStopped; }
150 
151  bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; }
152 
154 
155  bool ProcessIDIsValid() const;
156 
157  void Clear();
158 
159  bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
160  lldb_private::ThreadList &new_thread_list) override;
161 
162  enum {
165  };
166 
167  lldb::ThreadSP GetKernelThread();
168 
169  /// Broadcaster event bits definitions.
173  llvm::StringRef m_dyld_plugin_name;
175  lldb::CommandObjectSP m_command_sp;
176  lldb::ThreadWP m_kernel_thread_wp;
177 
178  bool StartAsyncThread();
179 
180  void StopAsyncThread();
181 
182  static void *AsyncThread(void *arg);
183 
184 private:
185  // For ProcessKDP only
186 
187  ProcessKDP(const ProcessKDP &) = delete;
188  const ProcessKDP &operator=(const ProcessKDP &) = delete;
189 };
190 
191 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MACOSX_KERNEL_PROCESSKDP_H
ProcessKDP::CanDebug
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
ProcessKDP::m_comm
CommunicationKDP m_comm
Broadcaster event bits definitions.
Definition: ProcessKDP.h:170
ProcessKDP::IsStepping
bool IsStepping(lldb::StateType state)
Definition: ProcessKDP.h:145
lldb_private::ArchSpec
Definition: ArchSpec.h:33
ProcessKDP::IsRunning
bool IsRunning(lldb::StateType state)
Definition: ProcessKDP.h:141
lldb_private::HostThread
Definition: HostThread.h:29
ProcessKDP::DidAttach
void DidAttach(lldb_private::ArchSpec &process_arch) override
Called after attaching a process.
Definition: ProcessKDP.cpp:381
ProcessKDP::GetImageInfoAddress
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
Definition: ProcessKDP.cpp:391
ProcessKDP::GetPluginName
llvm::StringRef GetPluginName() override
Definition: ProcessKDP.h:88
ProcessKDP::DoResume
lldb_private::Status DoResume() override
Resumes all of a process's threads as configured using the Thread run control functions.
Definition: ProcessKDP.cpp:401
ProcessKDP
Definition: ProcessKDP.h:30
ProcessKDP::WillResume
lldb_private::Status WillResume() override
Called before resuming to a process.
Definition: ProcessKDP.cpp:399
ProcessKDP::eBroadcastBitAsyncThreadShouldExit
@ eBroadcastBitAsyncThreadShouldExit
Definition: ProcessKDP.h:164
ProcessKDP::GetPluginCommandObject
lldb_private::CommandObject * GetPluginCommandObject() override
Return a multi-word command object that can be used to expose plug-in specific commands.
Definition: ProcessKDP.cpp:1004
lldb_private::Process
Definition: Process.h:341
ProcessKDP::m_async_broadcaster
lldb_private::Broadcaster m_async_broadcaster
Definition: ProcessKDP.h:171
ProcessKDP::DoAttachToProcessWithID
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:364
ProcessKDP::DisableBreakpointSite
lldb_private::Status DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override
Definition: ProcessKDP.cpp:647
ProcessKDP::DoDestroy
lldb_private::Status DoDestroy() override
Definition: ProcessKDP.cpp:565
lldb_private::Module
Definition: Module.h:85
ProcessKDP::~ProcessKDP
~ProcessKDP() override
Definition: ProcessKDP.cpp:161
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
ProcessKDP::DoUpdateThreadList
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:492
lldb::eStateExited
@ eStateExited
Process has exited and can't be examined.
Definition: lldb-enumerations.h:90
Process.h
ProcessKDP::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: ProcessKDP.h:44
Broadcaster.h
lldb::eStateStopped
@ eStateStopped
Process or thread is stopped and can be examined.
Definition: lldb-enumerations.h:84
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
ProcessKDP::operator=
const ProcessKDP & operator=(const ProcessKDP &)=delete
ProcessKDP::GetHostArchitecture
bool GetHostArchitecture(lldb_private::ArchSpec &arch)
Definition: ProcessKDP.cpp:191
HostThread.h
lldb_private::BreakpointSite
Definition: BreakpointSite.h:35
ThreadSafeValue.h
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb_private::Watchpoint
Definition: Watchpoint.h:24
StreamString.h
ProcessKDP::DoReadMemory
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:578
ProcessKDP::m_kernel_load_addr
lldb::addr_t m_kernel_load_addr
Definition: ProcessKDP.h:174
lldb_private::ThreadList
Definition: ThreadList.h:26
ProcessKDP::ProcessIDIsValid
bool ProcessIDIsValid() const
ProcessKDP::Terminate
static void Terminate()
Definition: ProcessKDP.cpp:99
lldb_private::DynamicLoader
Definition: DynamicLoader.h:52
ProcessKDP::CanResume
bool CanResume(lldb::StateType state)
Definition: ProcessKDP.h:149
ProcessKDP::m_async_thread
lldb_private::HostThread m_async_thread
Definition: ProcessKDP.h:172
lldb_private::Debugger
Definition: Debugger.h:70
ProcessKDP::WillLaunch
lldb_private::Status WillLaunch(lldb_private::Module *module) override
Called before launching to a process.
Definition: ProcessKDP.cpp:170
CommunicationKDP
Definition: CommunicationKDP.h:22
StringList.h
Thread.h
ThreadKDP
Definition: ThreadKDP.h:19
ProcessKDP::DoLaunch
lldb_private::Status DoLaunch(lldb_private::Module *exe_module, lldb_private::ProcessLaunchInfo &launch_info) override
Launch a new process.
Definition: ProcessKDP.cpp:356
ProcessKDP::DebuggerInitialize
static void DebuggerInitialize(lldb_private::Debugger &debugger)
Definition: ProcessKDP.cpp:706
ProcessKDP::DoDeallocateMemory
lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override
Actually deallocate memory in the process.
Definition: ProcessKDP.cpp:621
lldb_private::ProcessAttachInfo
Definition: Process.h:113
lldb_private::CommandObject
Definition: CommandObject.h:67
ProcessKDP::DoAllocateMemory
lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions, lldb_private::Status &error) override
Actually allocate memory in the process.
Definition: ProcessKDP.cpp:614
ProcessKDP::eBroadcastBitAsyncContinue
@ eBroadcastBitAsyncContinue
Definition: ProcessKDP.h:163
lldb::eStateStepping
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
Definition: lldb-enumerations.h:86
lldb_private::Status
Definition: Status.h:44
ProcessKDP::DoAttachToProcessWithName
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:373
ProcessKDP::DoHalt
lldb_private::Status DoHalt(bool &caused_stop) override
Halts a running process.
Definition: ProcessKDP.cpp:515
ProcessKDP::GetDynamicLoader
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
Definition: ProcessKDP.cpp:393
uint32_t
CommunicationKDP.h
ProcessKDP::DoDetach
lldb_private::Status DoDetach(bool keep_stopped) override
Detaches from a running or stopped process.
Definition: ProcessKDP.cpp:531
ProcessKDP::m_kernel_thread_wp
lldb::ThreadWP m_kernel_thread_wp
Definition: ProcessKDP.h:176
ProcessKDP::RefreshStateAfterStop
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
Definition: ProcessKDP.cpp:509
ProcessKDP::CreateInstance
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::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
ProcessKDP::DoConnectRemote
lldb_private::Status DoConnectRemote(llvm::StringRef remote_url) override
Attach to a remote system via a URL.
Definition: ProcessKDP.cpp:205
ProcessKDP::DisableWatchpoint
lldb_private::Status DisableWatchpoint(lldb_private::Watchpoint *wp, bool notify=true) override
Definition: ProcessKDP.cpp:678
ProcessKDP::GetKernelThread
lldb::ThreadSP GetKernelThread()
Definition: ProcessKDP.cpp:480
ArchSpec.h
ProcessKDP::Clear
void Clear()
Definition: ProcessKDP.cpp:685
ProcessKDP::IsAlive
bool IsAlive() override
Check if a process is still alive.
Definition: ProcessKDP.cpp:573
ProcessKDP::ProcessKDP
ProcessKDP(lldb::TargetSP target_sp, lldb::ListenerSP listener)
ProcessKDP::EnableWatchpoint
lldb_private::Status EnableWatchpoint(lldb_private::Watchpoint *wp, bool notify=true) override
Definition: ProcessKDP.cpp:671
ProcessKDP::WillAttachToProcessWithID
lldb_private::Status WillAttachToProcessWithID(lldb::pid_t pid) override
Called before attaching to a process.
Definition: ProcessKDP.cpp:176
ProcessKDP::Initialize
static void Initialize()
Definition: ProcessKDP.cpp:694
Status.h
ProcessKDP::m_dyld_plugin_name
llvm::StringRef m_dyld_plugin_name
Definition: ProcessKDP.h:173
ProcessKDP::WillAttachToProcessWithName
lldb_private::Status WillAttachToProcessWithName(const char *process_name, bool wait_for_launch) override
Called before attaching to a process.
Definition: ProcessKDP.cpp:183
ProcessKDP::EnableBreakpointSite
lldb_private::Status EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override
Definition: ProcessKDP.cpp:628
ProcessKDP::HasExited
bool HasExited(lldb::StateType state)
Definition: ProcessKDP.h:151
ProcessKDP::DoSignal
lldb_private::Status DoSignal(int signal) override
Sends a process a UNIX signal signal.
Definition: ProcessKDP.cpp:687
ConstString.h
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
ProcessKDP::StartAsyncThread
bool StartAsyncThread()
Definition: ProcessKDP.cpp:717
lldb_private::Broadcaster
Definition: Broadcaster.h:242
ProcessKDP::GetPluginDescriptionStatic
static llvm::StringRef GetPluginDescriptionStatic()
Definition: ProcessKDP.cpp:94
lldb::eStateRunning
@ eStateRunning
Process or thread is running and can't be examined.
Definition: lldb-enumerations.h:85
ProcessKDP::AsyncThread
static void * AsyncThread(void *arg)
Definition: ProcessKDP.cpp:749
ProcessKDP::DoWriteMemory
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:606
ProcessKDP::m_command_sp
lldb::CommandObjectSP m_command_sp
Definition: ProcessKDP.h:175
ProcessKDP::StopAsyncThread
void StopAsyncThread()
Definition: ProcessKDP.cpp:737
ProcessKDP::GetCommunication
CommunicationKDP & GetCommunication()
Definition: ProcessKDP.h:134