LLDB mainline
NativeProcessWindows.h
Go to the documentation of this file.
1//===-- NativeProcessWindows.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 liblldb_NativeProcessWindows_h_
10#define liblldb_NativeProcessWindows_h_
11
14#include "lldb/lldb-forward.h"
15
16#include "IDebugDelegate.h"
17#include "LoadedModuleList.h"
18#include "ProcessDebugger.h"
19
20namespace lldb_private {
21
22class HostProcess;
26class PseudoConsole;
27
28using NativeDebugDelegateSP = std::shared_ptr<NativeDebugDelegate>;
29
30//------------------------------------------------------------------
31// NativeProcessWindows
32//------------------------------------------------------------------
34 public ProcessDebugger {
35
36public:
38 public:
40
41 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
42 Launch(ProcessLaunchInfo &launch_info,
43 NativeDelegate &native_delegate) override;
44
45 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
46 Attach(lldb::pid_t pid, NativeDelegate &native_delegate) override;
47
50 }
51 };
52
53 ~NativeProcessWindows() override;
54
55 Status Resume(const ResumeActionList &resume_actions) override;
56
57 Status Halt() override;
58
59 Status Detach() override;
60
61 Status Signal(int signo) override;
62
63 Status Interrupt() override;
64
65 Status Kill() override;
66
67 Status IgnoreSignals(llvm::ArrayRef<int> signals) override;
68
70 MemoryRegionInfo &range_info) override;
71
72 Status ReadMemory(const ProcessAddress &addr, void *buf, size_t size,
73 size_t &bytes_read) override;
74
75 Status DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size,
76 size_t &bytes_written) override;
77
78 llvm::Expected<lldb::addr_t> AllocateMemory(size_t size,
79 uint32_t permissions) override;
80
81 llvm::Error DeallocateMemory(lldb::addr_t addr) override;
82
84
85 bool IsAlive() const override;
86
87 size_t UpdateThreads() override;
88
89 const ArchSpec &GetArchitecture() const override { return m_arch; }
90
91 void SetArchitecture(const ArchSpec &arch_spec) { m_arch = arch_spec; }
92
93 Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
94 bool hardware) override;
95
96 Status RemoveBreakpoint(lldb::addr_t addr, bool hardware = false) override;
97
98 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
99 GetAuxvData() const override;
100
101 Status GetLoadedModuleFileSpec(const char *module_path,
102 FileSpec &file_spec) override;
103
104 Status GetFileLoadAddress(const llvm::StringRef &file_name,
105 lldb::addr_t &load_addr) override;
106
107 llvm::Expected<std::vector<LoadedLibraryInfo>> GetLoadedLibraries() override;
108
109 bool HasPendingLibraryEvents() override;
110
114
115 /// Forwards to NativeProcessProtocol's bookkeeping.
121
122 /// Forward bytes from the gdb-remote `I` packet into the inferior's
123 /// ConPTY-backed stdin via `m_stdio_communication.Write` →
124 /// `ConnectionConPTY::Write` → `WriteFile` on the parent-side STDIN
125 /// HANDLE. Returns the number of bytes written (0 if the PTY is
126 /// disconnected or write fails).
127 size_t WriteStdin(const void *buf, size_t len, Status &error) override;
128
129 // ProcessDebugger Overrides
130 void OnExitProcess(uint32_t exit_code) override;
131 void OnDebuggerConnected(lldb::addr_t image_base) override;
132 ExceptionResult OnDebugException(bool first_chance,
133 const ExceptionRecord &record) override;
134 void OnCreateThread(const HostThread &thread) override;
135 void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override;
136 DllEventAction OnLoadDll(const ModuleSpec &module_spec,
137 lldb::addr_t module_addr,
138 lldb::tid_t thread_id) override;
140 lldb::tid_t thread_id) override;
141 void OnDebugString(lldb::addr_t debug_string_addr, bool is_unicode,
142 uint16_t length_lower_word) override;
143
144protected:
146
147 llvm::Expected<llvm::ArrayRef<uint8_t>>
148 GetSoftwareBreakpointTrapOpcode(size_t size_hint) override;
149
150 size_t GetSoftwareBreakpointPCOffset() override;
151
153
154 void StopThread(lldb::tid_t thread_id, lldb::StopReason reason,
155 std::string description = "");
156
158 lldb::StopReason reason,
159 std::string description = "");
160
161private:
163
165 llvm::Error &E);
166
167 NativeProcessWindows(lldb::pid_t pid, int terminal_fd,
168 NativeDelegate &delegate, llvm::Error &E);
169
172 ExceptionResult HandleGenericException(bool first_chance,
173 const ExceptionRecord &record);
174
176
178
179 /// Set whenever an OS DLL load/unload event has been seen since the last stop
180 /// reply.
182
183 /// Whether we've seen the loader breakpoint that fires once per process at
184 /// launch / attach.
186
188
189 /// Set when Halt() / Interrupt() schedules a DebugBreakProcess injection.
190 bool m_pending_halt = false;
191
193
194 /// PseudoConsole for the lldb-server stdio-forwarding path.
195 std::shared_ptr<PseudoConsole> m_pty;
196
197 /// Wraps a ConnectionConPTY around the PTY's parent-side STDOUT HANDLE.
199
200 /// Bridge between m_stdio_communication's read thread and
201 /// NativeDelegate::NewProcessOutput.
202 static void STDIOReadThreadBytesReceived(void *baton, const void *src,
203 size_t src_len);
204
205 /// Wire up m_stdio_communication on m_pty's STDOUT HANDLE.
207
208 /// Tear down the read thread and disconnect m_stdio_communication.
209 void StopStdioForwarding();
210};
211
212//------------------------------------------------------------------
213// NativeDebugDelegate
214//------------------------------------------------------------------
216public:
218
219 void OnExitProcess(uint32_t exit_code) override {
220 m_process.OnExitProcess(exit_code);
221 }
222
223 void OnDebuggerConnected(lldb::addr_t image_base) override {
224 m_process.OnDebuggerConnected(image_base);
225 }
226
228 const ExceptionRecord &record) override {
229 return m_process.OnDebugException(first_chance, record);
230 }
231
232 void OnCreateThread(const HostThread &thread) override {
233 m_process.OnCreateThread(thread);
234 }
235
236 void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override {
237 m_process.OnExitThread(thread_id, exit_code);
238 }
239
241 lldb::addr_t module_addr,
242 lldb::tid_t thread_id) override {
243 return m_process.OnLoadDll(module_spec, module_addr, thread_id);
244 }
245
247 lldb::tid_t thread_id) override {
248 return m_process.OnUnloadDll(module_addr, thread_id);
249 }
250
251 void OnDebugString(lldb::addr_t debug_string_addr, bool is_unicode,
252 uint16_t length_lower_word) override {
253 m_process.OnDebugString(debug_string_addr, is_unicode, length_lower_word);
254 }
255
256 void OnDebuggerError(const Status &error, uint32_t type) override {
257 return m_process.OnDebuggerError(error, type);
258 }
259
260private:
262};
263
264} // namespace lldb_private
265
266#endif // #ifndef liblldb_NativeProcessWindows_h_
static llvm::raw_ostream & error(Stream &strm)
ExceptionResult
Definition ForwardDecl.h:16
DllEventAction
Definition ForwardDecl.h:29
An architecture specification class.
Definition ArchSpec.h:32
A file utility class.
Definition FileSpec.h:56
The images mapped into the inferior.
DllEventAction OnLoadDll(const lldb_private::ModuleSpec &module_spec, lldb::addr_t module_addr, lldb::tid_t thread_id) override
void OnExitProcess(uint32_t exit_code) override
void OnDebugString(lldb::addr_t debug_string_addr, bool is_unicode, uint16_t length_lower_word) override
void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override
void OnDebuggerError(const Status &error, uint32_t type) override
ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) override
void OnCreateThread(const HostThread &thread) override
DllEventAction OnUnloadDll(lldb::addr_t module_addr, lldb::tid_t thread_id) override
NativeDebugDelegate(NativeProcessWindows &process)
void OnDebuggerConnected(lldb::addr_t image_base) override
virtual void SetEnabledExtensions(Extension flags)
Method called in order to propagate the bitmap of protocol extensions supported by the client.
NativeProcessProtocol(lldb::pid_t pid, int terminal_fd, NativeDelegate &delegate)
Extension
Extension flag constants, returned by Manager::GetSupportedExtensions() and passed to SetEnabledExten...
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate) override
Launch a process for debugging.
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Attach(lldb::pid_t pid, NativeDelegate &native_delegate) override
Attach to an existing process.
Extension GetSupportedExtensions() const override
Get the bitmask of extensions supported by this process plugin.
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) override
ExceptionResult HandleBreakpointException(const ExceptionRecord &record)
llvm::Error DeallocateMemory(lldb::addr_t addr) override
Status Resume(const ResumeActionList &resume_actions) override
void OnCreateThread(const HostThread &thread) override
void OnExitProcess(uint32_t exit_code) override
Status GetLoadedModuleFileSpec(const char *module_path, FileSpec &file_spec) override
void StartStdioForwarding()
Wire up m_stdio_communication on m_pty's STDOUT HANDLE.
static void STDIOReadThreadBytesReceived(void *baton, const void *src, size_t src_len)
Bridge between m_stdio_communication's read thread and NativeDelegate::NewProcessOutput.
llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint) override
void OnDebuggerConnected(lldb::addr_t image_base) override
NativeProcessWindows(ProcessLaunchInfo &launch_info, NativeDelegate &delegate, llvm::Error &E)
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
void StopStdioForwarding()
Tear down the read thread and disconnect m_stdio_communication.
size_t WriteStdin(const void *buf, size_t len, Status &error) override
Forward bytes from the gdb-remote I packet into the inferior's ConPTY-backed stdin via m_stdio_commun...
void SetEnabledExtensions(Extension flags) override
Forwards to NativeProcessProtocol's bookkeeping.
Status DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override
bool m_pending_halt
Set when Halt() / Interrupt() schedules a DebugBreakProcess injection.
ExceptionResult HandleGenericException(bool first_chance, const ExceptionRecord &record)
void SetArchitecture(const ArchSpec &arch_spec)
ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) override
void OnDebugString(lldb::addr_t debug_string_addr, bool is_unicode, uint16_t length_lower_word) override
Status ReadMemory(const ProcessAddress &addr, void *buf, size_t size, size_t &bytes_read) override
Plugins without address spaces should error on a non-default one.
size_t GetSoftwareBreakpointPCOffset() override
Return the offset of the PC relative to the software breakpoint that was hit.
std::shared_ptr< PseudoConsole > m_pty
PseudoConsole for the lldb-server stdio-forwarding path.
ThreadedCommunication m_stdio_communication
Wraps a ConnectionConPTY around the PTY's parent-side STDOUT HANDLE.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > GetAuxvData() const override
DllEventAction OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr, lldb::tid_t thread_id) override
Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) override
NativeThreadWindows * GetThreadByID(lldb::tid_t thread_id)
void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override
llvm::Expected< lldb::addr_t > AllocateMemory(size_t size, uint32_t permissions) override
DllEventAction OnUnloadDll(lldb::addr_t module_addr, lldb::tid_t thread_id) override
Status Signal(int signo) override
Sends a process a UNIX signal signal.
Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false) override
const ArchSpec & GetArchitecture() const override
void SetStopReasonForThread(NativeThreadWindows &thread, lldb::StopReason reason, std::string description="")
Status Interrupt() override
Tells a process to interrupt all operations as if by a Ctrl-C.
void StopThread(lldb::tid_t thread_id, lldb::StopReason reason, std::string description="")
ExceptionResult HandleSingleStepException(const ExceptionRecord &record)
bool m_initial_stop_seen
Whether we've seen the loader breakpoint that fires once per process at launch / attach.
bool m_pending_library_events
Set whenever an OS DLL load/unload event has been seen since the last stop reply.
llvm::Expected< std::vector< LoadedLibraryInfo > > GetLoadedLibraries() override
Return the currently loaded libraries of the target in the qXfer:libraries:read form (generic name + ...
lldb::addr_t GetSharedLibraryInfoAddress() override
Status IgnoreSignals(llvm::ArrayRef< int > signals) override
An address in a process, qualified by an address space.
An error handling class.
Definition Status.h:118
"lldb/Core/ThreadedCommunication.h" Variation of Communication that supports threaded reads.
A class that represents a running process on the host machine.
std::shared_ptr< NativeDebugDelegate > NativeDebugDelegateSP
uint64_t pid_t
Definition lldb-types.h:84
uint64_t addr_t
Definition lldb-types.h:80
StopReason
Thread stop reasons.
uint64_t tid_t
Definition lldb-types.h:85