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 "ProcessDebugger.h"
18
19namespace lldb_private {
20
21class HostProcess;
25class PseudoConsole;
26
27using NativeDebugDelegateSP = std::shared_ptr<NativeDebugDelegate>;
28
29//------------------------------------------------------------------
30// NativeProcessWindows
31//------------------------------------------------------------------
33 public ProcessDebugger {
34
35public:
37 public:
39
40 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
41 Launch(ProcessLaunchInfo &launch_info,
42 NativeDelegate &native_delegate) override;
43
44 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
45 Attach(lldb::pid_t pid, NativeDelegate &native_delegate) override;
46
49 }
50 };
51
52 ~NativeProcessWindows() override;
53
54 Status Resume(const ResumeActionList &resume_actions) override;
55
56 Status Halt() override;
57
58 Status Detach() override;
59
60 Status Signal(int signo) override;
61
62 Status Interrupt() override;
63
64 Status Kill() override;
65
66 Status IgnoreSignals(llvm::ArrayRef<int> signals) override;
67
69 MemoryRegionInfo &range_info) override;
70
71 Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
72 size_t &bytes_read) override;
73
74 Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
75 size_t &bytes_written) override;
76
77 llvm::Expected<lldb::addr_t> AllocateMemory(size_t size,
78 uint32_t permissions) override;
79
80 llvm::Error DeallocateMemory(lldb::addr_t addr) override;
81
83
84 bool IsAlive() const override;
85
86 size_t UpdateThreads() override;
87
88 const ArchSpec &GetArchitecture() const override { return m_arch; }
89
90 void SetArchitecture(const ArchSpec &arch_spec) { m_arch = arch_spec; }
91
92 Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
93 bool hardware) override;
94
95 Status RemoveBreakpoint(lldb::addr_t addr, bool hardware = false) override;
96
97 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
98 GetAuxvData() const override;
99
100 Status GetLoadedModuleFileSpec(const char *module_path,
101 FileSpec &file_spec) override;
102
103 Status GetFileLoadAddress(const llvm::StringRef &file_name,
104 lldb::addr_t &load_addr) override;
105
106 llvm::Expected<std::vector<LoadedLibraryInfo>> GetLoadedLibraries() override;
107
108 bool HasPendingLibraryEvents() override;
109
110 /// Forward bytes from the gdb-remote `I` packet into the inferior's
111 /// ConPTY-backed stdin via `m_stdio_communication.Write` →
112 /// `ConnectionConPTY::Write` → `WriteFile` on the parent-side STDIN
113 /// HANDLE. Returns the number of bytes written (0 if the PTY is
114 /// disconnected or write fails).
115 size_t WriteStdin(const void *buf, size_t len, Status &error) override;
116
117 // ProcessDebugger Overrides
118 void OnExitProcess(uint32_t exit_code) override;
119 void OnDebuggerConnected(lldb::addr_t image_base) override;
120 ExceptionResult OnDebugException(bool first_chance,
121 const ExceptionRecord &record) override;
122 void OnCreateThread(const HostThread &thread) override;
123 void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override;
124 void OnLoadDll(const ModuleSpec &module_spec,
125 lldb::addr_t module_addr) override;
126 void OnUnloadDll(lldb::addr_t module_addr) override;
127 void OnDebugString(lldb::addr_t debug_string_addr, bool is_unicode,
128 uint16_t length_lower_word) override;
129
130protected:
132
133 llvm::Expected<llvm::ArrayRef<uint8_t>>
134 GetSoftwareBreakpointTrapOpcode(size_t size_hint) override;
135
136 size_t GetSoftwareBreakpointPCOffset() override;
137
139
140 void StopThread(lldb::tid_t thread_id, lldb::StopReason reason,
141 std::string description = "");
142
144 lldb::StopReason reason,
145 std::string description = "");
146
147private:
149
151 llvm::Error &E);
152
153 NativeProcessWindows(lldb::pid_t pid, int terminal_fd,
154 NativeDelegate &delegate, llvm::Error &E);
155
158 ExceptionResult HandleGenericException(bool first_chance,
159 const ExceptionRecord &record);
160
162 std::map<lldb_private::FileSpec, lldb::addr_t> m_loaded_modules;
163
164 /// Set whenever an OS DLL load/unload event has been seen since the last stop
165 /// reply.
167
168 /// Whether we've seen the loader breakpoint that fires once per process at
169 /// launch / attach.
171
172 /// Set when Halt() / Interrupt() schedules a DebugBreakProcess injection.
173 bool m_pending_halt = false;
174
175 /// PseudoConsole for the lldb-server stdio-forwarding path.
176 std::shared_ptr<PseudoConsole> m_pty;
177
178 /// Wraps a ConnectionConPTY around the PTY's parent-side STDOUT HANDLE.
180
181 /// Bridge between m_stdio_communication's read thread and
182 /// NativeDelegate::NewProcessOutput.
183 static void STDIOReadThreadBytesReceived(void *baton, const void *src,
184 size_t src_len);
185
186 /// Wire up m_stdio_communication on m_pty's STDOUT HANDLE.
188
189 /// Tear down the read thread and disconnect m_stdio_communication.
190 void StopStdioForwarding();
191};
192
193//------------------------------------------------------------------
194// NativeDebugDelegate
195//------------------------------------------------------------------
197public:
199
200 void OnExitProcess(uint32_t exit_code) override {
201 m_process.OnExitProcess(exit_code);
202 }
203
204 void OnDebuggerConnected(lldb::addr_t image_base) override {
205 m_process.OnDebuggerConnected(image_base);
206 }
207
209 const ExceptionRecord &record) override {
210 return m_process.OnDebugException(first_chance, record);
211 }
212
213 void OnCreateThread(const HostThread &thread) override {
214 m_process.OnCreateThread(thread);
215 }
216
217 void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override {
218 m_process.OnExitThread(thread_id, exit_code);
219 }
220
221 void OnLoadDll(const lldb_private::ModuleSpec &module_spec,
222 lldb::addr_t module_addr) override {
223 m_process.OnLoadDll(module_spec, module_addr);
224 }
225
226 void OnUnloadDll(lldb::addr_t module_addr) override {
227 m_process.OnUnloadDll(module_addr);
228 }
229
230 void OnDebugString(lldb::addr_t debug_string_addr, bool is_unicode,
231 uint16_t length_lower_word) override {
232 m_process.OnDebugString(debug_string_addr, is_unicode, length_lower_word);
233 }
234
235 void OnDebuggerError(const Status &error, uint32_t type) override {
236 return m_process.OnDebuggerError(error, type);
237 }
238
239private:
241};
242
243} // namespace lldb_private
244
245#endif // #ifndef liblldb_NativeProcessWindows_h_
static llvm::raw_ostream & error(Stream &strm)
ExceptionResult
Definition ForwardDecl.h:16
An architecture specification class.
Definition ArchSpec.h:32
A file utility class.
Definition FileSpec.h:57
void OnLoadDll(const lldb_private::ModuleSpec &module_spec, lldb::addr_t module_addr) 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 OnUnloadDll(lldb::addr_t module_addr) override
void OnCreateThread(const HostThread &thread) override
NativeDebugDelegate(NativeProcessWindows &process)
void OnDebuggerConnected(lldb::addr_t image_base) override
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
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) 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...
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
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
void OnUnloadDll(lldb::addr_t module_addr) override
Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) override
NativeThreadWindows * GetThreadByID(lldb::tid_t thread_id)
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override
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
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 OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr) override
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
std::map< lldb_private::FileSpec, lldb::addr_t > m_loaded_modules
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:83
uint64_t addr_t
Definition lldb-types.h:80
StopReason
Thread stop reasons.
uint64_t tid_t
Definition lldb-types.h:84