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
15#include "lldb/Core/ThreadSafeValue.h"
16#include "lldb/Host/HostThread.h"
17#include "lldb/Target/Process.h"
18#include "lldb/Target/Thread.h"
19#include "lldb/Utility/ArchSpec.h"
20#include "lldb/Utility/Broadcaster.h"
21#include "lldb/Utility/ConstString.h"
22#include "lldb/Utility/Status.h"
23#include "lldb/Utility/StreamString.h"
24#include "lldb/Utility/StringList.h"
25
26#include "CommunicationKDP.h"
27
28class ThreadKDP;
29
30class ProcessKDP : public lldb_private::Process {
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;
56 lldb_private::CommandObject *GetPluginCommandObject() override;
57
58 // Creating a new process, or attaching to an existing one
59 lldb_private::Status DoWillLaunch(lldb_private::Module *module) override;
60
61 lldb_private::Status
62 DoLaunch(lldb_private::Module *exe_module,
63 lldb_private::ProcessLaunchInfo &launch_info) override;
64
65 lldb_private::Status DoWillAttachToProcessWithID(lldb::pid_t pid) override;
66
67 lldb_private::Status
68 DoWillAttachToProcessWithName(const char *process_name,
69 bool wait_for_launch) override;
70
71 lldb_private::Status DoConnectRemote(llvm::StringRef remote_url) override;
72
73 lldb_private::Status DoAttachToProcessWithID(
74 lldb::pid_t pid,
75 const lldb_private::ProcessAttachInfo &attach_info) override;
76
77 lldb_private::Status DoAttachToProcessWithName(
78 const char *process_name,
79 const lldb_private::ProcessAttachInfo &attach_info) override;
80
81 void DidAttach(lldb_private::ArchSpec &process_arch) override;
82
83 lldb::addr_t GetImageInfoAddress() override;
84
85 lldb_private::DynamicLoader *GetDynamicLoader() override;
86
87 // PluginInterface protocol
88 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
89
90 // Process Control
91 lldb_private::Status WillResume() override;
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
118 lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override;
119
120 // Process Breakpoints
121 lldb_private::Status
122 EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
123
124 lldb_private::Status
125 DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
126
127 CommunicationKDP &GetCommunication() { return m_comm; }
128
129protected:
130 friend class ThreadKDP;
131 friend class CommunicationKDP;
132
133 // Accessors
134 bool IsRunning(lldb::StateType state) {
135 return state == lldb::eStateRunning || IsStepping(state);
136 }
137
138 bool IsStepping(lldb::StateType state) {
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
146 bool GetHostArchitecture(lldb_private::ArchSpec &arch);
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 {
156 eBroadcastBitAsyncContinue = (1 << 0),
157 eBroadcastBitAsyncThreadShouldExit = (1 << 1)
158 };
159
160 lldb::ThreadSP GetKernelThread();
161
162 /// Broadcaster event bits definitions.
163 CommunicationKDP m_comm;
164 lldb_private::Broadcaster m_async_broadcaster;
165 lldb_private::HostThread m_async_thread;
166 llvm::StringRef m_dyld_plugin_name;
167 lldb::addr_t m_kernel_load_addr;
168 lldb::CommandObjectSP m_command_sp;
169 lldb::ThreadWP m_kernel_thread_wp;
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
185

source code of lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h