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 
111  llvm::Expected<llvm::ArrayRef<uint8_t>>
112  GetSoftwareBreakpointTrapOpcode(size_t size_hint) override;
113 
114  size_t GetSoftwareBreakpointPCOffset() override;
115 
117 
118  void StopThread(lldb::tid_t thread_id, lldb::StopReason reason,
119  std::string description = "");
120 
122  lldb::StopReason reason,
123  std::string description = "");
124 
125 private:
127 
128  NativeProcessWindows(ProcessLaunchInfo &launch_info, NativeDelegate &delegate,
129  llvm::Error &E);
130 
131  NativeProcessWindows(lldb::pid_t pid, int terminal_fd,
132  NativeDelegate &delegate, llvm::Error &E);
133 
135  std::map<lldb_private::FileSpec, lldb::addr_t> m_loaded_modules;
136 };
137 
138 //------------------------------------------------------------------
139 // NativeDebugDelegate
140 //------------------------------------------------------------------
142 public:
144 
145  void OnExitProcess(uint32_t exit_code) override {
146  m_process.OnExitProcess(exit_code);
147  }
148 
149  void OnDebuggerConnected(lldb::addr_t image_base) override {
150  m_process.OnDebuggerConnected(image_base);
151  }
152 
154  const ExceptionRecord &record) override {
155  return m_process.OnDebugException(first_chance, record);
156  }
157 
158  void OnCreateThread(const HostThread &thread) override {
159  m_process.OnCreateThread(thread);
160  }
161 
162  void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override {
163  m_process.OnExitThread(thread_id, exit_code);
164  }
165 
166  void OnLoadDll(const lldb_private::ModuleSpec &module_spec,
167  lldb::addr_t module_addr) override {
168  m_process.OnLoadDll(module_spec, module_addr);
169  }
170 
171  void OnUnloadDll(lldb::addr_t module_addr) override {
172  m_process.OnUnloadDll(module_addr);
173  }
174 
175  void OnDebugString(const std::string &string) override {
176  m_process.OnDebugString(string);
177  }
178 
179  void OnDebuggerError(const Status &error, uint32_t type) override {
180  return m_process.OnDebuggerError(error, type);
181  }
182 
183 private:
185 };
186 
187 } // namespace lldb_private
188 
189 #endif // #ifndef liblldb_NativeProcessWindows_h_
lldb_private::NativeDebugDelegate::OnCreateThread
void OnCreateThread(const HostThread &thread) override
Definition: NativeProcessWindows.h:158
lldb_private::NativeProcessWindows::OnLoadDll
void OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr) override
Definition: NativeProcessWindows.cpp:593
lldb_private::NativeProcessWindows::NativeProcessWindows
NativeProcessWindows(ProcessLaunchInfo &launch_info, NativeDelegate &delegate, llvm::Error &E)
Definition: NativeProcessWindows.cpp:47
lldb_private::NativeProcessProtocol::NativeDelegate
Definition: NativeProcessProtocol.h:236
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:135
lldb_private::NativeDebugDelegate::OnUnloadDll
void OnUnloadDll(lldb::addr_t module_addr) override
Definition: NativeProcessWindows.h:171
lldb_private::NativeDebugDelegate::OnDebugString
void OnDebugString(const std::string &string) override
Definition: NativeProcessWindows.h:175
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:418
IDebugDelegate.h
lldb_private::NativeDebugDelegate
Definition: NativeProcessWindows.h:141
lldb_private::NativeDebugDelegate::OnDebuggerError
void OnDebuggerError(const Status &error, uint32_t type) override
Definition: NativeProcessWindows.h:179
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:606
lldb_private::NativeProcessWindows::OnExitProcess
void OnExitProcess(uint32_t exit_code) override
Definition: NativeProcessWindows.cpp:404
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:162
lldb_private::NativeProcessWindows::StopThread
void StopThread(lldb::tid_t thread_id, lldb::StopReason reason, std::string description="")
Definition: NativeProcessWindows.cpp:267
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:366
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:600
lldb_private::NativeProcessWindows::GetFileLoadAddress
Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) override
Definition: NativeProcessWindows.cpp:385
lldb_private::NativeProcessWindows::GetSoftwareBreakpointTrapOpcode
llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint) override
Definition: NativeProcessWindows.cpp:292
lldb_private::NativeProcessWindows::Factory
Definition: NativeProcessWindows.h:34
lldb_private::ProcessDebugger::OnDebuggerError
virtual void OnDebuggerError(const Status &error, uint32_t type)
Definition: ProcessDebugger.cpp:535
ExceptionResult
ExceptionResult
Definition: ForwardDecl.h:16
lldb_private::NativeProcessWindows::GetAuxvData
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > GetAuxvData() const override
Definition: NativeProcessWindows.cpp:286
lldb_private::NativeProcessWindows::FindSoftwareBreakpoint
bool FindSoftwareBreakpoint(lldb::addr_t addr)
Definition: NativeProcessWindows.cpp:315
lldb_private::NativeProcessWindows::OnExitThread
void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override
Definition: NativeProcessWindows.cpp:577
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
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:619
lldb_private::NativeProcessWindows::SetBreakpoint
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
Definition: NativeProcessWindows.cpp:322
lldb_private::NativeProcessWindows::OnDebugException
ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) override
Definition: NativeProcessWindows.cpp:445
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:143
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:145
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:336
lldb_private::ModuleSpec
Definition: ModuleSpec.h:27
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:149
uint32_t
lldb_private::MainLoop
Definition: MainLoop.h:39
lldb_private::NativeProcessWindows::OnCreateThread
void OnCreateThread(const HostThread &thread) override
Definition: NativeProcessWindows.cpp:563
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::NativeProcessProtocol
Definition: NativeProcessProtocol.h:48
lldb_private::NativeProcessWindows::UpdateThreads
size_t UpdateThreads() override
Definition: NativeProcessWindows.cpp:283
lldb_private::NativeDebugDelegateSP
std::shared_ptr< NativeDebugDelegate > NativeDebugDelegateSP
Definition: NativeProcessWindows.h:23
lldb_private::NativeProcessWindows::m_arch
ArchSpec m_arch
Definition: NativeProcessWindows.h:126
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:533
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
lldb_private::NativeProcessWindows::GetSoftwareBreakpointPCOffset
size_t GetSoftwareBreakpointPCOffset() override
Return the offset of the PC relative to the software breakpoint that was hit.
Definition: NativeProcessWindows.cpp:309
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
ProcessDebugger.h
lldb_private::NativeProcessWindows::RemoveBreakpoint
Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false) override
Definition: NativeProcessWindows.cpp:329
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:153
lldb_private::NativeProcessWindows::GetSharedLibraryInfoAddress
lldb::addr_t GetSharedLibraryInfoAddress() override
Definition: NativeProcessWindows.cpp:233
lldb_private::NativeProcessProtocol::Factory
Definition: NativeProcessProtocol.h:274
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:184
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:166