LLDB  mainline
NativeProcessWindows.cpp
Go to the documentation of this file.
1 //===-- NativeProcessWindows.cpp ------------------------------------------===//
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 
10 #include <psapi.h>
11 
12 #include "NativeProcessWindows.h"
13 #include "NativeThreadWindows.h"
14 #include "lldb/Host/FileSystem.h"
16 #include "lldb/Host/HostProcess.h"
22 #include "lldb/Target/Process.h"
23 #include "lldb/Utility/State.h"
24 #include "llvm/Support/ConvertUTF.h"
25 #include "llvm/Support/Errc.h"
26 #include "llvm/Support/Error.h"
27 #include "llvm/Support/Format.h"
28 #include "llvm/Support/Threading.h"
29 #include "llvm/Support/raw_ostream.h"
30 
31 #include "DebuggerThread.h"
32 #include "ExceptionRecord.h"
33 #include "ProcessWindowsLog.h"
34 
35 #include <tlhelp32.h>
36 
37 #pragma warning(disable : 4005)
38 #include "winternl.h"
39 #include <ntstatus.h>
40 
41 using namespace lldb;
42 using namespace lldb_private;
43 using namespace llvm;
44 
45 namespace lldb_private {
46 
47 NativeProcessWindows::NativeProcessWindows(ProcessLaunchInfo &launch_info,
48  NativeDelegate &delegate,
49  llvm::Error &E)
51  launch_info.GetPTY().ReleasePrimaryFileDescriptor(),
52  delegate),
53  ProcessDebugger(), m_arch(launch_info.GetArchitecture()) {
54  ErrorAsOutParameter EOut(&E);
55  DebugDelegateSP delegate_sp(new NativeDebugDelegate(*this));
56  E = LaunchProcess(launch_info, delegate_sp).ToError();
57  if (E)
58  return;
59 
61 }
62 
64  NativeDelegate &delegate,
65  llvm::Error &E)
66  : NativeProcessProtocol(pid, terminal_fd, delegate), ProcessDebugger() {
67  ErrorAsOutParameter EOut(&E);
68  DebugDelegateSP delegate_sp(new NativeDebugDelegate(*this));
69  ProcessAttachInfo attach_info;
70  attach_info.SetProcessID(pid);
71  E = AttachProcess(pid, attach_info, delegate_sp).ToError();
72  if (E)
73  return;
74 
76 
78  if (!Host::GetProcessInfo(pid, info)) {
79  E = createStringError(inconvertibleErrorCode(),
80  "Cannot get process information");
81  return;
82  }
83  m_arch = info.GetArchitecture();
84 }
85 
88  Status error;
89  llvm::sys::ScopedLock lock(m_mutex);
90 
91  StateType state = GetState();
92  if (state == eStateStopped || state == eStateCrashed) {
93  LLDB_LOG(log, "process {0} is in state {1}. Resuming...",
94  GetDebuggedProcessId(), state);
95  LLDB_LOG(log, "resuming {0} threads.", m_threads.size());
96 
97  bool failed = false;
98  for (uint32_t i = 0; i < m_threads.size(); ++i) {
99  auto thread = static_cast<NativeThreadWindows *>(m_threads[i].get());
100  const ResumeAction *const action =
101  resume_actions.GetActionForThread(thread->GetID(), true);
102  if (action == nullptr)
103  continue;
104 
105  switch (action->state) {
106  case eStateRunning:
107  case eStateStepping: {
108  Status result = thread->DoResume(action->state);
109  if (result.Fail()) {
110  failed = true;
111  LLDB_LOG(log,
112  "Trying to resume thread at index {0}, but failed with "
113  "error {1}.",
114  i, result);
115  }
116  break;
117  }
118  case eStateSuspended:
119  case eStateStopped:
120  llvm_unreachable("Unexpected state");
121 
122  default:
123  return Status(
124  "NativeProcessWindows::%s (): unexpected state %s specified "
125  "for pid %" PRIu64 ", tid %" PRIu64,
126  __FUNCTION__, StateAsCString(action->state), GetID(),
127  thread->GetID());
128  }
129  }
130 
131  if (failed) {
132  error.SetErrorString("NativeProcessWindows::DoResume failed");
133  } else {
135  }
136 
137  // Resume the debug loop.
138  ExceptionRecordSP active_exception =
139  m_session_data->m_debugger->GetActiveException().lock();
140  if (active_exception) {
141  // Resume the process and continue processing debug events. Mask the
142  // exception so that from the process's view, there is no indication that
143  // anything happened.
144  m_session_data->m_debugger->ContinueAsyncException(
146  }
147  } else {
148  LLDB_LOG(log, "error: process {0} is in state {1}. Returning...",
150  }
151 
152  return error;
153 }
154 
157  return static_cast<NativeThreadWindows *>(
159 }
160 
162  bool caused_stop = false;
163  StateType state = GetState();
164  if (state != eStateStopped)
165  return HaltProcess(caused_stop);
166  return Status();
167 }
168 
170  Status error;
172  StateType state = GetState();
173  if (state != eStateExited && state != eStateDetached) {
174  error = DetachProcess();
175  if (error.Success())
177  else
178  LLDB_LOG(log, "Detaching process error: {0}", error);
179  } else {
180  error.SetErrorStringWithFormatv("error: process {0} in state = {1}, but "
181  "cannot detach it in this state.",
182  GetID(), state);
183  LLDB_LOG(log, "error: {0}", error);
184  }
185  return error;
186 }
187 
189  Status error;
190  error.SetErrorString("Windows does not support sending signals to processes");
191  return error;
192 }
193 
195 
197  StateType state = GetState();
198  return DestroyProcess(state);
199 }
200 
201 Status NativeProcessWindows::IgnoreSignals(llvm::ArrayRef<int> signals) {
202  return Status();
203 }
204 
206  MemoryRegionInfo &range_info) {
207  return ProcessDebugger::GetMemoryRegionInfo(load_addr, range_info);
208 }
209 
211  size_t size, size_t &bytes_read) {
212  return ProcessDebugger::ReadMemory(addr, buf, size, bytes_read);
213 }
214 
216  size_t size, size_t &bytes_written) {
217  return ProcessDebugger::WriteMemory(addr, buf, size, bytes_written);
218 }
219 
220 llvm::Expected<lldb::addr_t>
222  lldb::addr_t addr;
223  Status ST = ProcessDebugger::AllocateMemory(size, permissions, addr);
224  if (ST.Success())
225  return addr;
226  return ST.ToError();
227 }
228 
231 }
232 
234 
236  StateType state = GetState();
237  switch (state) {
238  case eStateCrashed:
239  case eStateDetached:
240  case eStateExited:
241  case eStateInvalid:
242  case eStateUnloaded:
243  return false;
244  default:
245  return true;
246  }
247 }
248 
250  lldb::StopReason reason,
251  std::string description) {
252  SetCurrentThreadID(thread.GetID());
253 
254  ThreadStopInfo stop_info;
255  stop_info.reason = reason;
256 
257  // No signal support on Windows but required to provide a 'valid' signum.
258  if (reason == StopReason::eStopReasonException) {
259  stop_info.details.exception.type = 0;
260  stop_info.details.exception.data_count = 0;
261  } else {
262  stop_info.details.signal.signo = SIGTRAP;
263  }
264 
265  thread.SetStopReason(stop_info, description);
266 }
267 
269  lldb::StopReason reason,
270  std::string description) {
271  NativeThreadWindows *thread = GetThreadByID(thread_id);
272  if (!thread)
273  return;
274 
275  for (uint32_t i = 0; i < m_threads.size(); ++i) {
276  auto t = static_cast<NativeThreadWindows *>(m_threads[i].get());
277  Status error = t->DoStop();
278  if (error.Fail())
279  exit(1);
280  }
281  SetStopReasonForThread(*thread, reason, description);
282 }
283 
285 
286 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
288  // Not available on this target.
289  return llvm::errc::not_supported;
290 }
291 
292 llvm::Expected<llvm::ArrayRef<uint8_t>>
294  static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x3e, 0xd4}; // brk #0xf000
295  static const uint8_t g_thumb_opcode[] = {0xfe, 0xde}; // udf #0xfe
296 
297  switch (GetArchitecture().GetMachine()) {
298  case llvm::Triple::aarch64:
299  return llvm::makeArrayRef(g_aarch64_opcode);
300 
301  case llvm::Triple::arm:
302  case llvm::Triple::thumb:
303  return llvm::makeArrayRef(g_thumb_opcode);
304 
305  default:
307  }
308 }
309 
311  // Windows always reports an incremented PC after a breakpoint is hit,
312  // even on ARM.
313  return cantFail(GetSoftwareBreakpointTrapOpcode(0)).size();
314 }
315 
317  auto it = m_software_breakpoints.find(addr);
318  if (it == m_software_breakpoints.end())
319  return false;
320  return true;
321 }
322 
324  bool hardware) {
325  if (hardware)
326  return SetHardwareBreakpoint(addr, size);
327  return SetSoftwareBreakpoint(addr, size);
328 }
329 
331  bool hardware) {
332  if (hardware)
333  return RemoveHardwareBreakpoint(addr);
334  return RemoveSoftwareBreakpoint(addr);
335 }
336 
338  Status error;
339  if (!m_loaded_modules.empty())
340  return Status();
341 
342  // Retrieve loaded modules by a Target/Module free implemenation.
343  AutoHandle snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetID()));
344  if (snapshot.IsValid()) {
345  MODULEENTRY32W me;
346  me.dwSize = sizeof(MODULEENTRY32W);
347  if (Module32FirstW(snapshot.get(), &me)) {
348  do {
349  std::string path;
350  if (!llvm::convertWideToUTF8(me.szExePath, path))
351  continue;
352 
353  FileSpec file_spec(path);
354  FileSystem::Instance().Resolve(file_spec);
355  m_loaded_modules[file_spec] = (addr_t)me.modBaseAddr;
356  } while (Module32Next(snapshot.get(), &me));
357  }
358 
359  if (!m_loaded_modules.empty())
360  return Status();
361  }
362 
363  error.SetError(::GetLastError(), lldb::ErrorType::eErrorTypeWin32);
364  return error;
365 }
366 
368  FileSpec &file_spec) {
370  if (error.Fail())
371  return error;
372 
373  FileSpec module_file_spec(module_path);
374  FileSystem::Instance().Resolve(module_file_spec);
375  for (auto &it : m_loaded_modules) {
376  if (it.first == module_file_spec) {
377  file_spec = it.first;
378  return Status();
379  }
380  }
381  return Status("Module (%s) not found in process %" PRIu64 "!",
382  module_file_spec.GetCString(), GetID());
383 }
384 
385 Status
386 NativeProcessWindows::GetFileLoadAddress(const llvm::StringRef &file_name,
387  lldb::addr_t &load_addr) {
389  if (error.Fail())
390  return error;
391 
392  load_addr = LLDB_INVALID_ADDRESS;
393  FileSpec file_spec(file_name);
394  FileSystem::Instance().Resolve(file_spec);
395  for (auto &it : m_loaded_modules) {
396  if (it.first == file_spec) {
397  load_addr = it.second;
398  return Status();
399  }
400  }
401  return Status("Can't get loaded address of file (%s) in process %" PRIu64 "!",
402  file_spec.GetCString(), GetID());
403 }
404 
407  LLDB_LOG(log, "Process {0} exited with code {1}", GetID(), exit_code);
408 
410 
411  // No signal involved. It is just an exit event.
412  WaitStatus wait_status(WaitStatus::Exit, exit_code);
413  SetExitStatus(wait_status, true);
414 
415  // Notify the native delegate.
416  SetState(eStateExited, true);
417 }
418 
421  LLDB_LOG(log, "Debugger connected to process {0}. Image base = {1:x}",
422  GetDebuggedProcessId(), image_base);
423 
424  // This is the earliest chance we can resolve the process ID and
425  // architecture if we don't know them yet.
428 
429  if (GetArchitecture().GetMachine() == llvm::Triple::UnknownArch) {
430  ProcessInstanceInfo process_info;
431  if (!Host::GetProcessInfo(GetDebuggedProcessId(), process_info)) {
432  LLDB_LOG(log, "Cannot get process information during debugger connecting "
433  "to process");
434  return;
435  }
436  SetArchitecture(process_info.GetArchitecture());
437  }
438 
439  // The very first one shall always be the main thread.
440  assert(m_threads.empty());
441  m_threads.push_back(std::make_unique<NativeThreadWindows>(
442  *this, m_session_data->m_debugger->GetMainThread()));
443 }
444 
447  const ExceptionRecord &record) {
449  llvm::sys::ScopedLock lock(m_mutex);
450 
451  // Let the debugger establish the internal status.
452  ProcessDebugger::OnDebugException(first_chance, record);
453 
454  static bool initial_stop = false;
455  if (!first_chance) {
456  SetState(eStateStopped, false);
457  }
458 
460  switch (record.GetExceptionCode()) {
461  case DWORD(STATUS_SINGLE_STEP):
462  case STATUS_WX86_SINGLE_STEP: {
464  if (NativeThreadWindows *thread = GetThreadByID(record.GetThreadID())) {
465  NativeRegisterContextWindows &reg_ctx = thread->GetRegisterContext();
466  Status error =
467  reg_ctx.GetWatchpointHitIndex(wp_id, record.GetExceptionAddress());
468  if (error.Fail())
469  LLDB_LOG(log,
470  "received error while checking for watchpoint hits, pid = "
471  "{0}, error = {1}",
472  thread->GetID(), error);
473  if (wp_id != LLDB_INVALID_INDEX32) {
474  addr_t wp_addr = reg_ctx.GetWatchpointAddress(wp_id);
475  addr_t wp_hit_addr = reg_ctx.GetWatchpointHitAddress(wp_id);
476  std::string desc =
477  formatv("{0} {1} {2}", wp_addr, wp_id, wp_hit_addr).str();
479  desc);
480  }
481  }
482  if (wp_id == LLDB_INVALID_INDEX32)
484 
485  SetState(eStateStopped, true);
486 
487  // Continue the debugger.
489  }
490  case DWORD(STATUS_BREAKPOINT):
493  LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
494  record.GetExceptionAddress());
495 
497 
498  if (NativeThreadWindows *stop_thread =
499  GetThreadByID(record.GetThreadID())) {
500  auto &register_context = stop_thread->GetRegisterContext();
501  uint32_t breakpoint_size = GetSoftwareBreakpointPCOffset();
502  // The current PC is AFTER the BP opcode, on all architectures.
503  uint64_t pc = register_context.GetPC() - breakpoint_size;
504  register_context.SetPC(pc);
505  }
506 
507  SetState(eStateStopped, true);
509  }
510 
511  if (!initial_stop) {
512  initial_stop = true;
513  LLDB_LOG(log,
514  "Hit loader breakpoint at address {0:x}, setting initial stop "
515  "event.",
516  record.GetExceptionAddress());
517 
518  // We are required to report the reason for the first stop after
519  // launching or being attached.
520  if (NativeThreadWindows *thread = GetThreadByID(record.GetThreadID()))
522 
523  // Do not notify the native delegate (e.g. llgs) since at this moment
524  // the program hasn't returned from Factory::Launch() and the delegate
525  // might not have an valid native process to operate on.
526  SetState(eStateStopped, false);
527 
528  // Hit the initial stop. Continue the application.
530  }
531 
532  LLVM_FALLTHROUGH;
533  default:
534  LLDB_LOG(log,
535  "Debugger thread reported exception {0:x} at address {1:x} "
536  "(first_chance={2})",
537  record.GetExceptionCode(), record.GetExceptionAddress(),
538  first_chance);
539 
540  {
541  std::string desc;
542  llvm::raw_string_ostream desc_stream(desc);
543  desc_stream << "Exception "
544  << llvm::format_hex(record.GetExceptionCode(), 8)
545  << " encountered at address "
546  << llvm::format_hex(record.GetExceptionAddress(), 8);
548  desc_stream.str().c_str());
549 
550  SetState(eStateStopped, true);
551  }
552 
553  // For non-breakpoints, give the application a chance to handle the
554  // exception first.
555  if (first_chance)
557  else
559  }
560 
561  return result;
562 }
563 
565  llvm::sys::ScopedLock lock(m_mutex);
566 
567  auto thread = std::make_unique<NativeThreadWindows>(*this, new_thread);
568  thread->GetRegisterContext().ClearAllHardwareWatchpoints();
569  for (const auto &pair : GetWatchpointMap()) {
570  const NativeWatchpoint &wp = pair.second;
571  thread->SetWatchpoint(wp.m_addr, wp.m_size, wp.m_watch_flags,
572  wp.m_hardware);
573  }
574 
575  m_threads.push_back(std::move(thread));
576 }
577 
579  uint32_t exit_code) {
580  llvm::sys::ScopedLock lock(m_mutex);
581  NativeThreadWindows *thread = GetThreadByID(thread_id);
582  if (!thread)
583  return;
584 
585  for (auto t = m_threads.begin(); t != m_threads.end();) {
586  if ((*t)->GetID() == thread_id) {
587  t = m_threads.erase(t);
588  } else {
589  ++t;
590  }
591  }
592 }
593 
595  lldb::addr_t module_addr) {
596  // Simply invalidate the cached loaded modules.
597  if (!m_loaded_modules.empty())
598  m_loaded_modules.clear();
599 }
600 
602  if (!m_loaded_modules.empty())
603  m_loaded_modules.clear();
604 }
605 
606 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
608  ProcessLaunchInfo &launch_info,
609  NativeProcessProtocol::NativeDelegate &native_delegate,
610  MainLoop &mainloop) const {
611  Error E = Error::success();
612  auto process_up = std::unique_ptr<NativeProcessWindows>(
613  new NativeProcessWindows(launch_info, native_delegate, E));
614  if (E)
615  return std::move(E);
616  return std::move(process_up);
617 }
618 
619 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
622  MainLoop &mainloop) const {
623  Error E = Error::success();
624  // Set pty master fd invalid since it is not available.
625  auto process_up = std::unique_ptr<NativeProcessWindows>(
626  new NativeProcessWindows(pid, -1, native_delegate, E));
627  if (E)
628  return std::move(E);
629  return std::move(process_up);
630 }
631 } // namespace lldb_private
lldb_private::NativeProcessProtocol::SetSoftwareBreakpoint
Status SetSoftwareBreakpoint(lldb::addr_t addr, uint32_t size_hint)
Definition: NativeProcessProtocol.cpp:326
lldb_private::NativeWatchpoint::m_watch_flags
uint32_t m_watch_flags
Definition: NativeWatchpointList.h:21
WINDOWS_LOG_PROCESS
#define WINDOWS_LOG_PROCESS
Definition: ProcessWindowsLog.h:14
lldb_private::NativeProcessWindows::OnLoadDll
void OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr) override
Definition: NativeProcessWindows.cpp:594
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:108
lldb_private::ProcessDebugger::GetDebuggedProcessId
lldb::pid_t GetDebuggedProcessId() const
Definition: ProcessDebugger.cpp:68
lldb_private::NativeWatchpoint::m_addr
lldb::addr_t m_addr
Definition: NativeWatchpointList.h:19
lldb_private::NativeThreadWindows::SetStopReason
void SetStopReason(ThreadStopInfo stop_info, std::string description)
Definition: NativeThreadWindows.cpp:112
llvm
Definition: Debugger.h:49
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::ExceptionRecord::GetThreadID
lldb::tid_t GetThreadID() const
Definition: ExceptionRecord.h:65
lldb_private::NativeProcessWindows::Halt
Status Halt() override
Definition: NativeProcessWindows.cpp:161
ExceptionResult::BreakInDebugger
@ BreakInDebugger
FileSystem.h
lldb_private::NativeRegisterContext::GetWatchpointHitIndex
virtual Status GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr)
Definition: NativeRegisterContext.cpp:294
lldb_private::NativeThreadWindows
Definition: NativeThreadWindows.h:22
LLDB_INVALID_PROCESS_ID
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:93
lldb_private::NativeProcessWindows::m_loaded_modules
std::map< lldb_private::FileSpec, lldb::addr_t > m_loaded_modules
Definition: NativeProcessWindows.h:135
lldb_private::NativeProcessProtocol::SetHardwareBreakpoint
virtual Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
Definition: NativeProcessProtocol.cpp:234
lldb_private::HostThread
Definition: HostThread.h:29
lldb_private::NativeProcessWindows::Kill
Status Kill() override
Definition: NativeProcessWindows.cpp:196
lldb_private::AutoHandle
Definition: AutoHandle.h:16
lldb_private::AutoHandle::get
HANDLE get() const
Definition: AutoHandle.h:28
lldb_private::NativeProcessWindows::IsAlive
bool IsAlive() const override
Definition: NativeProcessWindows.cpp:235
ExceptionResult::MaskException
@ MaskException
lldb_private::NativeProcessProtocol::SetState
void SetState(lldb::StateType state, bool notify_delegates=true)
Definition: NativeProcessProtocol.cpp:698
ProcessLaunchInfo.h
lldb_private::NativeProcessWindows::OnDebuggerConnected
void OnDebuggerConnected(lldb::addr_t image_base) override
Definition: NativeProcessWindows.cpp:419
HostProcess.h
lldb_private::NativeDebugDelegate
Definition: NativeProcessWindows.h:141
lldb_private::NativeProcessProtocol::GetThreadByID
NativeThreadProtocol * GetThreadByID(lldb::tid_t tid)
Definition: NativeProcessProtocol.cpp:114
lldb_private::StateAsCString
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
lldb_private::NativeWatchpoint::m_size
size_t m_size
Definition: NativeWatchpointList.h:20
STATUS_WX86_BREAKPOINT
#define STATUS_WX86_BREAKPOINT
Definition: DebuggerThread.cpp:33
lldb_private::NativeProcessProtocol::m_software_breakpoints
std::unordered_map< lldb::addr_t, SoftwareBreakpoint > m_software_breakpoints
Definition: NativeProcessProtocol.h:393
lldb_private::NativeProcessProtocol::SetExitStatus
virtual bool SetExitStatus(WaitStatus status, bool bNotifyStateChange)
Definition: NativeProcessProtocol.cpp:75
lldb::StopReason
StopReason
Thread stop reasons.
Definition: lldb-enumerations.h:239
lldb_private::ResumeAction
Definition: Debug.h:19
lldb::eStopReasonException
@ eStopReasonException
Definition: lldb-enumerations.h:246
lldb_private::ThreadStopInfo::details
union lldb_private::ThreadStopInfo::@13 details
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb_private::NativeProcessWindows::IgnoreSignals
Status IgnoreSignals(llvm::ArrayRef< int > signals) override
Definition: NativeProcessWindows.cpp:201
lldb_private::ProcessDebugger::m_mutex
llvm::sys::Mutex m_mutex
Definition: ProcessDebugger.h:97
lldb_private::ProcessInfo::SetProcessID
void SetProcessID(lldb::pid_t pid)
Definition: ProcessInfo.h:69
lldb_private::ProcessDebugger::ReadMemory
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read)
Definition: ProcessDebugger.cpp:262
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
pc
@ pc
Definition: CompactUnwindInfo.cpp:1250
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:607
lldb::eStopReasonTrace
@ eStopReasonTrace
Definition: lldb-enumerations.h:242
lldb::eErrorTypeWin32
@ eErrorTypeWin32
Standard Win32 error codes.
Definition: lldb-enumerations.h:312
AutoHandle.h
lldb_private::ProcessDebugger::DestroyProcess
Status DestroyProcess(lldb::StateType process_state)
Definition: ProcessDebugger.cpp:211
lldb_private::NativeProcessWindows::OnExitProcess
void OnExitProcess(uint32_t exit_code) override
Definition: NativeProcessWindows.cpp:405
lldb::eStateExited
@ eStateExited
Process has exited and can't be examined.
Definition: lldb-enumerations.h:90
lldb_private::ProcessDebugger::DetachProcess
Status DetachProcess()
Definition: ProcessDebugger.cpp:74
Process.h
lldb_private::WaitStatus
Definition: Host.h:34
ProcessWindowsLog.h
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::GetCString
const char * GetCString(bool denormalize=true) const
Definition: FileSpec.cpp:364
lldb_private::ResumeActionList::GetActionForThread
const ResumeAction * GetActionForThread(lldb::tid_t tid, bool default_ok) const
Definition: Debug.h:76
lldb::eStateStopped
@ eStateStopped
Process or thread is stopped and can be examined.
Definition: lldb-enumerations.h:84
lldb_private::NativeProcessProtocol::SetCurrentThreadID
void SetCurrentThreadID(lldb::tid_t tid)
Definition: NativeProcessProtocol.h:205
lldb_private::NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode
virtual llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint)
Definition: NativeProcessProtocol.cpp:487
lldb_private::ProcessDebugger::AttachProcess
Status AttachProcess(lldb::pid_t pid, const ProcessAttachInfo &attach_info, DebugDelegateSP delegate)
Definition: ProcessDebugger.cpp:171
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::Status::Success
bool Success() const
Test for success condition.
Definition: Status.cpp:288
lldb::eStateCrashed
@ eStateCrashed
Process or thread has crashed and can be examined.
Definition: lldb-enumerations.h:88
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:367
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::NativeProcessProtocol::RemoveSoftwareBreakpoint
Status RemoveSoftwareBreakpoint(lldb::addr_t addr)
Definition: NativeProcessProtocol.cpp:344
lldb_private::NativeRegisterContext::GetWatchpointHitAddress
virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index)
Definition: NativeRegisterContext.cpp:310
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb_private::NativeProcessWindows::OnUnloadDll
void OnUnloadDll(lldb::addr_t module_addr) override
Definition: NativeProcessWindows.cpp:601
lldb_private::ResumeAction::state
lldb::StateType state
Definition: Debug.h:23
MemoryRegionInfo.h
lldb_private::NativeProcessWindows::GetFileLoadAddress
Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) override
Definition: NativeProcessWindows.cpp:386
lldb::eStopReasonWatchpoint
@ eStopReasonWatchpoint
Definition: lldb-enumerations.h:244
HostNativeProcessBase.h
lldb_private::NativeProcessWindows::GetSoftwareBreakpointTrapOpcode
llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint) override
Definition: NativeProcessWindows.cpp:293
lldb_private::Status::Fail
bool Fail() const
Test for error condition.
Definition: Status.cpp:182
SIGTRAP
#define SIGTRAP
Definition: windows/PosixApi.h:30
ExceptionResult
ExceptionResult
Definition: ForwardDecl.h:16
lldb_private::ThreadStopInfo::reason
lldb::StopReason reason
Definition: Debug.h:134
lldb_private::NativeProcessProtocol::SetID
void SetID(lldb::pid_t pid)
Definition: NativeProcessProtocol.h:425
lldb_private::NativeProcessWindows::GetAuxvData
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > GetAuxvData() const override
Definition: NativeProcessWindows.cpp:287
lldb_private::NativeProcessProtocol::GetID
lldb::pid_t GetID() const
Definition: NativeProcessProtocol.h:172
lldb_private::NativeRegisterContextWindows
Definition: NativeRegisterContextWindows.h:20
WINDOWS_LOG_EXCEPTION
#define WINDOWS_LOG_EXCEPTION
Definition: ProcessWindowsLog.h:15
lldb_private::ProcessDebugger::LaunchProcess
Status LaunchProcess(ProcessLaunchInfo &launch_info, DebugDelegateSP delegate)
Definition: ProcessDebugger.cpp:105
lldb_private::ExceptionRecord::GetExceptionCode
DWORD GetExceptionCode() const
Definition: ExceptionRecord.h:58
lldb_private::NativeProcessWindows::FindSoftwareBreakpoint
bool FindSoftwareBreakpoint(lldb::addr_t addr)
Definition: NativeProcessWindows.cpp:316
lldb_private::NativeWatchpoint::m_hardware
bool m_hardware
Definition: NativeWatchpointList.h:22
lldb_private::NativeProcessWindows::OnExitThread
void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override
Definition: NativeProcessWindows.cpp:578
lldb::eStateDetached
@ eStateDetached
Process has been detached and can't be examined.
Definition: lldb-enumerations.h:89
ExceptionResult::SendToApplication
@ SendToApplication
lldb_private::ThreadStopInfo::exception
struct lldb_private::ThreadStopInfo::@13::@15 exception
lldb_private::DebugDelegateSP
std::shared_ptr< IDebugDelegate > DebugDelegateSP
Definition: ForwardDecl.h:33
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::FileSystem::Resolve
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
Definition: common/FileSystem.cpp:255
lldb_private::ThreadStopInfo::signal
struct lldb_private::ThreadStopInfo::@13::@14 signal
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:620
ExceptionRecord.h
lldb::eStateUnloaded
@ eStateUnloaded
Process is object is valid, but not currently loaded.
Definition: lldb-enumerations.h:75
lldb_private::NativeProcessWindows::SetBreakpoint
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
Definition: NativeProcessWindows.cpp:323
lldb_private::NativeProcessProtocol::m_threads
std::vector< std::unique_ptr< NativeThreadProtocol > > m_threads
Definition: NativeProcessProtocol.h:396
lldb_private::NativeProcessWindows::OnDebugException
ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) override
Definition: NativeProcessWindows.cpp:446
lldb_private::ThreadStopInfo
Definition: Debug.h:133
lldb_private::ProcessAttachInfo
Definition: Process.h:113
lldb_private::ExceptionRecord::GetExceptionAddress
lldb::addr_t GetExceptionAddress() const
Definition: ExceptionRecord.h:63
lldb_private::NativeProcessWindows::GetArchitecture
const ArchSpec & GetArchitecture() const override
Definition: NativeProcessWindows.h:79
DebuggerThread.h
lldb_private::ProcessDebugger::DeallocateMemory
Status DeallocateMemory(lldb::addr_t addr)
Definition: ProcessDebugger.cpp:355
lldb::eStateStepping
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
Definition: lldb-enumerations.h:86
lldb_private::AutoHandle::IsValid
bool IsValid() const
Definition: AutoHandle.h:26
lldb_private::NativeProcessWindows::SetArchitecture
void SetArchitecture(const ArchSpec &arch_spec)
Definition: NativeProcessWindows.h:81
lldb::eStateSuspended
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
Definition: lldb-enumerations.h:91
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:337
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
uint32_t
NativeProcessWindows.h
ProcessLauncherWindows.h
lldb_private::MainLoop
Definition: MainLoop.h:38
lldb_private::NativeProcessWindows::OnCreateThread
void OnCreateThread(const HostThread &thread) override
Definition: NativeProcessWindows.cpp:564
lldb_private::NativeProcessProtocol::RemoveHardwareBreakpoint
virtual Status RemoveHardwareBreakpoint(lldb::addr_t addr)
Definition: NativeProcessProtocol.cpp:291
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::NativeProcessProtocol
Definition: NativeProcessProtocol.h:47
lldb_private::NativeThreadProtocol::GetID
lldb::tid_t GetID() const
Definition: NativeThreadProtocol.h:35
lldb_private::NativeProcessWindows::UpdateThreads
size_t UpdateThreads() override
Definition: NativeProcessWindows.cpp:284
lldb_private::Host::GetProcessInfo
static bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
Definition: freebsd/Host.cpp:230
lldb_private::NativeProcessProtocol::GetState
lldb::StateType GetState() const
Definition: NativeProcessProtocol.cpp:693
lldb_private::ProcessWindowsLog::GetLogIfAny
static Log * GetLogIfAny(uint32_t mask)
Definition: ProcessWindowsLog.h:31
lldb_private::NativeWatchpoint
Definition: NativeWatchpointList.h:18
windows.h
lldb::eStopReasonBreakpoint
@ eStopReasonBreakpoint
Definition: lldb-enumerations.h:243
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::NativeProcessWindows::m_arch
ArchSpec m_arch
Definition: NativeProcessWindows.h:126
lldb_private::NativeProcessWindows::Detach
Status Detach() override
Definition: NativeProcessWindows.cpp:169
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:242
lldb_private::FileSystem::Instance
static FileSystem & Instance()
Definition: common/FileSystem.cpp:45
lldb_private::NativeProcessWindows::AllocateMemory
llvm::Expected< lldb::addr_t > AllocateMemory(size_t size, uint32_t permissions) override
Definition: NativeProcessWindows.cpp:221
lldb_private::ProcessDebugger::OnDebugException
virtual ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record)
Definition: ProcessDebugger.cpp:485
lldb_private::ProcessInfo::GetArchitecture
ArchSpec & GetArchitecture()
Definition: ProcessInfo.h:61
lldb_private::ResumeActionList
Definition: Debug.h:33
lldb_private::ProcessDebugger::HaltProcess
Status HaltProcess(bool &caused_stop)
Definition: ProcessDebugger.cpp:247
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:310
lldb_private::ProcessDebugger::AllocateMemory
Status AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr)
Definition: ProcessDebugger.cpp:326
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:29
lldb_private::NativeProcessProtocol::GetWatchpointMap
virtual const NativeWatchpointList::WatchpointMap & GetWatchpointMap() const
Definition: NativeProcessProtocol.cpp:125
lldb::eStateInvalid
@ eStateInvalid
Definition: lldb-enumerations.h:74
lldb_private::NativeProcessWindows::RemoveBreakpoint
Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false) override
Definition: NativeProcessWindows.cpp:330
lldb_private::Status::ToError
llvm::Error ToError() const
Definition: Status.cpp:90
lldb_private::NativeProcessWindows::Resume
Status Resume(const ResumeActionList &resume_actions) override
Definition: NativeProcessWindows.cpp:86
State.h
LLDB_INVALID_INDEX32
#define LLDB_INVALID_INDEX32
Definition: lldb-defines.h:87
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
lldb_private::Log
Definition: Log.h:49
lldb_private::NativeProcessWindows::GetSharedLibraryInfoAddress
lldb::addr_t GetSharedLibraryInfoAddress() override
Definition: NativeProcessWindows.cpp:233
lldb_private::ExceptionRecordSP
std::shared_ptr< ExceptionRecord > ExceptionRecordSP
Definition: ForwardDecl.h:37
lldb
Definition: SBAddress.h:15
lldb_private::ProcessDebugger::WriteMemory
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written)
Definition: ProcessDebugger.cpp:296
lldb::eStateRunning
@ eStateRunning
Process or thread is running and can't be examined.
Definition: lldb-enumerations.h:85
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::WaitStatus::Exit
@ Exit
Definition: Host.h:36
lldb_private::ProcessDebugger::m_session_data
std::unique_ptr< ProcessWindowsData > m_session_data
Definition: ProcessDebugger.h:98
lldb_private::ProcessDebugger::OnExitProcess
virtual void OnExitProcess(uint32_t exit_code)
Definition: ProcessDebugger.cpp:472
HostThreadWindows.h
lldb_private::ProcessDebugger::GetMemoryRegionInfo
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
Definition: ProcessDebugger.cpp:380
lldb_private::ExceptionRecord
Definition: ExceptionRecord.h:25
lldb_private::NativeRegisterContext::GetWatchpointAddress
virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index)
Definition: NativeRegisterContext.cpp:306
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
NativeThreadWindows.h