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 
13 #include "lldb/lldb-forward.h"
14 
15 #include "IDebugDelegate.h"
16 #include "ProcessDebugger.h"
17 
18 namespace lldb_private {
19 
20 class HostProcess;
21 class NativeProcessWindows;
22 class NativeThreadWindows;
24 
25 typedef std::shared_ptr<NativeDebugDelegate> NativeDebugDelegateSP;
26 
27 //------------------------------------------------------------------
28 // NativeProcessWindows
29 //------------------------------------------------------------------
31  public ProcessDebugger {
32 
33 public:
35  public:
36  llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
37  Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
38  MainLoop &mainloop) const override;
39 
40  llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
41  Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
42  MainLoop &mainloop) const override;
43  };
44 
45  Status Resume(const ResumeActionList &resume_actions) override;
46 
47  Status Halt() override;
48 
49  Status Detach() override;
50 
51  Status Signal(int signo) override;
52 
53  Status Interrupt() override;
54 
55  Status Kill() override;
56 
57  Status IgnoreSignals(llvm::ArrayRef<int> signals) override;
58 
60  MemoryRegionInfo &range_info) override;
61 
62  Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
63  size_t &bytes_read) override;
64 
65  Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
66  size_t &bytes_written) override;
67 
68  llvm::Expected<lldb::addr_t> AllocateMemory(size_t size,
69  uint32_t permissions) override;
70 
72 
74 
75  bool IsAlive() const override;
76 
77  size_t UpdateThreads() override;
78 
79  const ArchSpec &GetArchitecture() const override { return m_arch; }
80 
81  void SetArchitecture(const ArchSpec &arch_spec) { m_arch = arch_spec; }
82 
84  bool hardware) override;
85 
86  Status RemoveBreakpoint(lldb::addr_t addr, bool hardware = false) override;
87 
88  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
89  GetAuxvData() const override;
90 
91  Status GetLoadedModuleFileSpec(const char *module_path,
92  FileSpec &file_spec) override;
93 
94  Status GetFileLoadAddress(const llvm::StringRef &file_name,
95  lldb::addr_t &load_addr) override;
96 
97  // ProcessDebugger Overrides
98  void OnExitProcess(uint32_t exit_code) override;
99  void OnDebuggerConnected(lldb::addr_t image_base) override;
100  ExceptionResult OnDebugException(bool first_chance,
101  const ExceptionRecord &record) override;
102  void OnCreateThread(const HostThread &thread) override;
103  void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override;
104  void OnLoadDll(const ModuleSpec &module_spec,
105  lldb::addr_t module_addr) override;
106  void OnUnloadDll(lldb::addr_t module_addr) override;
107 
108 protected:
110 
112 
113  void StopThread(lldb::tid_t thread_id, lldb::StopReason reason,
114  std::string description = "");
115 
117  lldb::StopReason reason,
118  std::string description = "");
119 
120 private:
122 
123  NativeProcessWindows(ProcessLaunchInfo &launch_info, NativeDelegate &delegate,
124  llvm::Error &E);
125 
126  NativeProcessWindows(lldb::pid_t pid, int terminal_fd,
127  NativeDelegate &delegate, llvm::Error &E);
128 
130  std::map<lldb_private::FileSpec, lldb::addr_t> m_loaded_modules;
131 };
132 
133 //------------------------------------------------------------------
134 // NativeDebugDelegate
135 //------------------------------------------------------------------
137 public:
139 
140  void OnExitProcess(uint32_t exit_code) override {
141  m_process.OnExitProcess(exit_code);
142  }
143 
144  void OnDebuggerConnected(lldb::addr_t image_base) override {
145  m_process.OnDebuggerConnected(image_base);
146  }
147 
149  const ExceptionRecord &record) override {
150  return m_process.OnDebugException(first_chance, record);
151  }
152 
153  void OnCreateThread(const HostThread &thread) override {
154  m_process.OnCreateThread(thread);
155  }
156 
157  void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override {
158  m_process.OnExitThread(thread_id, exit_code);
159  }
160 
161  void OnLoadDll(const lldb_private::ModuleSpec &module_spec,
162  lldb::addr_t module_addr) override {
163  m_process.OnLoadDll(module_spec, module_addr);
164  }
165 
166  void OnUnloadDll(lldb::addr_t module_addr) override {
167  m_process.OnUnloadDll(module_addr);
168  }
169 
170  void OnDebugString(const std::string &string) override {
171  m_process.OnDebugString(string);
172  }
173 
174  void OnDebuggerError(const Status &error, uint32_t type) override {
175  return m_process.OnDebuggerError(error, type);
176  }
177 
178 private:
180 };
181 
182 } // namespace lldb_private
183 
184 #endif // #ifndef liblldb_NativeProcessWindows_h_
lldb_private::NativeDebugDelegate::OnCreateThread
void OnCreateThread(const HostThread &thread) override
Definition: NativeProcessWindows.h:153
lldb_private::NativeProcessWindows::OnLoadDll
void OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr) override
Definition: NativeProcessWindows.cpp:569
lldb_private::NativeProcessWindows::NativeProcessWindows
NativeProcessWindows(ProcessLaunchInfo &launch_info, NativeDelegate &delegate, llvm::Error &E)
Definition: NativeProcessWindows.cpp:47
lldb_private::NativeProcessProtocol::NativeDelegate
Definition: NativeProcessProtocol.h:221
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::NativeProcessWindows::Halt
Status Halt() override
Definition: NativeProcessWindows.cpp:161
lldb_private::NativeThreadWindows
Definition: NativeThreadWindows.h:22
lldb_private::NativeProcessWindows::m_loaded_modules
std::map< lldb_private::FileSpec, lldb::addr_t > m_loaded_modules
Definition: NativeProcessWindows.h:130
lldb_private::NativeDebugDelegate::OnUnloadDll
void OnUnloadDll(lldb::addr_t module_addr) override
Definition: NativeProcessWindows.h:166
lldb_private::NativeDebugDelegate::OnDebugString
void OnDebugString(const std::string &string) override
Definition: NativeProcessWindows.h:170
lldb_private::HostThread
Definition: HostThread.h:29
lldb_private::NativeProcessWindows::Kill
Status Kill() override
Definition: NativeProcessWindows.cpp:196
lldb_private::NativeProcessWindows::IsAlive
bool IsAlive() const override
Definition: NativeProcessWindows.cpp:235
lldb_private::NativeProcessWindows::OnDebuggerConnected
void OnDebuggerConnected(lldb::addr_t image_base) override
Definition: NativeProcessWindows.cpp:395
IDebugDelegate.h
lldb_private::NativeDebugDelegate
Definition: NativeProcessWindows.h:136
lldb_private::NativeDebugDelegate::OnDebuggerError
void OnDebuggerError(const Status &error, uint32_t type) override
Definition: NativeProcessWindows.h:174
lldb::StopReason
StopReason
Thread stop reasons.
Definition: lldb-enumerations.h:239
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb_private::NativeProcessWindows::IgnoreSignals
Status IgnoreSignals(llvm::ArrayRef< int > signals) override
Definition: NativeProcessWindows.cpp:201
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::NativeProcessWindows::Factory::Launch
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate, MainLoop &mainloop) const override
Launch a process for debugging.
Definition: NativeProcessWindows.cpp:582
lldb_private::NativeProcessWindows::OnExitProcess
void OnExitProcess(uint32_t exit_code) override
Definition: NativeProcessWindows.cpp:381
lldb_private::IDebugDelegate
Definition: IDebugDelegate.h:25
lldb_private::NativeProcessWindows::Interrupt
Status Interrupt() override
Tells a process to interrupt all operations as if by a Ctrl-C.
Definition: NativeProcessWindows.cpp:194
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::ProcessDebugger
Definition: ProcessDebugger.h:48
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::NativeDebugDelegate::OnExitThread
void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override
Definition: NativeProcessWindows.h:157
lldb_private::NativeProcessWindows::StopThread
void StopThread(lldb::tid_t thread_id, lldb::StopReason reason, std::string description="")
Definition: NativeProcessWindows.cpp:268
lldb_private::NativeProcessWindows::DeallocateMemory
llvm::Error DeallocateMemory(lldb::addr_t addr) override
Definition: NativeProcessWindows.cpp:229
lldb_private::NativeProcessWindows::GetLoadedModuleFileSpec
Status GetLoadedModuleFileSpec(const char *module_path, FileSpec &file_spec) override
Definition: NativeProcessWindows.cpp:343
lldb_private::NativeProcessWindows::ReadMemory
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override
Definition: NativeProcessWindows.cpp:210
lldb_private::NativeProcessWindows::GetMemoryRegionInfo
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) override
Definition: NativeProcessWindows.cpp:205
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb_private::NativeProcessWindows::OnUnloadDll
void OnUnloadDll(lldb::addr_t module_addr) override
Definition: NativeProcessWindows.cpp:576
lldb_private::NativeProcessWindows::GetFileLoadAddress
Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) override
Definition: NativeProcessWindows.cpp:362
lldb_private::NativeProcessWindows::Factory
Definition: NativeProcessWindows.h:34
lldb_private::ProcessDebugger::OnDebuggerError
virtual void OnDebuggerError(const Status &error, uint32_t type)
Definition: ProcessDebugger.cpp:539
ExceptionResult
ExceptionResult
Definition: ForwardDecl.h:16
lldb_private::NativeProcessWindows::GetAuxvData
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > GetAuxvData() const override
Definition: NativeProcessWindows.cpp:287
lldb_private::NativeProcessWindows::FindSoftwareBreakpoint
bool FindSoftwareBreakpoint(lldb::addr_t addr)
Definition: NativeProcessWindows.cpp:292
lldb_private::NativeProcessWindows::OnExitThread
void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override
Definition: NativeProcessWindows.cpp:553
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
lldb_private::NativeProcessWindows::Factory::Attach
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Attach(lldb::pid_t pid, NativeDelegate &native_delegate, MainLoop &mainloop) const override
Attach to an existing process.
Definition: NativeProcessWindows.cpp:595
lldb_private::NativeProcessWindows::SetBreakpoint
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
Definition: NativeProcessWindows.cpp:299
lldb_private::NativeProcessWindows::OnDebugException
ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) override
Definition: NativeProcessWindows.cpp:422
NativeProcessProtocol.h
lldb_private::NativeProcessWindows::GetArchitecture
const ArchSpec & GetArchitecture() const override
Definition: NativeProcessWindows.h:79
lldb_private::NativeDebugDelegate::NativeDebugDelegate
NativeDebugDelegate(NativeProcessWindows &process)
Definition: NativeProcessWindows.h:138
lldb_private::NativeProcessWindows::SetArchitecture
void SetArchitecture(const ArchSpec &arch_spec)
Definition: NativeProcessWindows.h:81
lldb_private::NativeDebugDelegate::OnExitProcess
void OnExitProcess(uint32_t exit_code) override
Definition: NativeProcessWindows.h:140
lldb_private::NativeProcessWindows::SetStopReasonForThread
void SetStopReasonForThread(NativeThreadWindows &thread, lldb::StopReason reason, std::string description="")
Definition: NativeProcessWindows.cpp:249
lldb_private::NativeProcessWindows::CacheLoadedModules
Status CacheLoadedModules()
Definition: NativeProcessWindows.cpp:313
lldb_private::ModuleSpec
Definition: ModuleSpec.h:26
lldb_private::NativeProcessWindows::Signal
Status Signal(int signo) override
Sends a process a UNIX signal signal.
Definition: NativeProcessWindows.cpp:188
lldb_private::Status
Definition: Status.h:44
lldb_private::NativeDebugDelegate::OnDebuggerConnected
void OnDebuggerConnected(lldb::addr_t image_base) override
Definition: NativeProcessWindows.h:144
uint32_t
lldb_private::MainLoop
Definition: MainLoop.h:38
lldb_private::NativeProcessWindows::OnCreateThread
void OnCreateThread(const HostThread &thread) override
Definition: NativeProcessWindows.cpp:539
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::NativeProcessProtocol
Definition: NativeProcessProtocol.h:47
lldb_private::NativeProcessWindows::UpdateThreads
size_t UpdateThreads() override
Definition: NativeProcessWindows.cpp:284
lldb_private::NativeDebugDelegateSP
std::shared_ptr< NativeDebugDelegate > NativeDebugDelegateSP
Definition: NativeProcessWindows.h:23
lldb_private::NativeProcessWindows::m_arch
ArchSpec m_arch
Definition: NativeProcessWindows.h:121
lldb_private::NativeProcessWindows::Detach
Status Detach() override
Definition: NativeProcessWindows.cpp:169
lldb-forward.h
lldb_private::ProcessDebugger::OnDebugString
virtual void OnDebugString(const std::string &string)
Definition: ProcessDebugger.cpp:537
lldb_private::NativeProcessWindows
Definition: NativeProcessWindows.h:30
lldb_private::NativeProcessWindows::AllocateMemory
llvm::Expected< lldb::addr_t > AllocateMemory(size_t size, uint32_t permissions) override
Definition: NativeProcessWindows.cpp:221
lldb_private::ResumeActionList
Definition: Debug.h:33
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:29
ProcessDebugger.h
lldb_private::NativeProcessWindows::RemoveBreakpoint
Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false) override
Definition: NativeProcessWindows.cpp:306
lldb_private::NativeProcessWindows::Resume
Status Resume(const ResumeActionList &resume_actions) override
Definition: NativeProcessWindows.cpp:86
lldb_private::NativeDebugDelegate::OnDebugException
ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) override
Definition: NativeProcessWindows.h:148
lldb_private::NativeProcessWindows::GetSharedLibraryInfoAddress
lldb::addr_t GetSharedLibraryInfoAddress() override
Definition: NativeProcessWindows.cpp:233
lldb_private::NativeProcessProtocol::Factory
Definition: NativeProcessProtocol.h:258
lldb_private::NativeProcessWindows::WriteMemory
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override
Definition: NativeProcessWindows.cpp:215
lldb_private::NativeDebugDelegate::m_process
NativeProcessWindows & m_process
Definition: NativeProcessWindows.h:179
lldb_private::ExceptionRecord
Definition: ExceptionRecord.h:25
lldb_private::NativeProcessWindows::GetThreadByID
NativeThreadWindows * GetThreadByID(lldb::tid_t thread_id)
Definition: NativeProcessWindows.cpp:156
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
lldb_private::NativeDebugDelegate::OnLoadDll
void OnLoadDll(const lldb_private::ModuleSpec &module_spec, lldb::addr_t module_addr) override
Definition: NativeProcessWindows.h:161