Go to the documentation of this file.
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"
37 #pragma warning(disable : 4005)
51 launch_info.GetPTY().ReleasePrimaryFileDescriptor(),
54 ErrorAsOutParameter EOut(&E);
67 ErrorAsOutParameter EOut(&E);
79 E = createStringError(inconvertibleErrorCode(),
80 "Cannot get process information");
89 llvm::sys::ScopedLock lock(
m_mutex);
93 LLDB_LOG(log,
"process {0} is in state {1}. Resuming...",
102 if (action ==
nullptr)
105 switch (action->
state) {
112 "Trying to resume thread at index {0}, but failed with "
120 llvm_unreachable(
"Unexpected state");
124 "NativeProcessWindows::%s (): unexpected state %s specified "
125 "for pid %" PRIu64
", tid %" PRIu64,
132 error.SetErrorString(
"NativeProcessWindows::DoResume failed");
140 if (active_exception) {
148 LLDB_LOG(log,
"error: process {0} is in state {1}. Returning...",
162 bool caused_stop =
false;
180 error.SetErrorStringWithFormatv(
"error: process {0} in state = {1}, but "
181 "cannot detach it in this state.",
190 error.SetErrorString(
"Windows does not support sending signals to processes");
211 size_t size,
size_t &bytes_read) {
216 size_t size,
size_t &bytes_written) {
220 llvm::Expected<lldb::addr_t>
255 stop_info.
reason = reason;
286 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
289 return llvm::errc::not_supported;
292 llvm::Expected<llvm::ArrayRef<uint8_t>>
294 static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x3e, 0xd4};
295 static const uint8_t g_thumb_opcode[] = {0xfe, 0xde};
298 case llvm::Triple::aarch64:
299 return llvm::makeArrayRef(g_aarch64_opcode);
301 case llvm::Triple::arm:
302 case llvm::Triple::thumb:
303 return llvm::makeArrayRef(g_thumb_opcode);
343 AutoHandle snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,
GetID()));
346 me.dwSize =
sizeof(MODULEENTRY32W);
347 if (Module32FirstW(snapshot.
get(), &me)) {
350 if (!llvm::convertWideToUTF8(me.szExePath, path))
356 }
while (Module32Next(snapshot.
get(), &me));
373 FileSpec module_file_spec(module_path);
376 if (it.first == module_file_spec) {
377 file_spec = it.first;
381 return Status(
"Module (%s) not found in process %" PRIu64
"!",
396 if (it.first == file_spec) {
397 load_addr = it.second;
401 return Status(
"Can't get loaded address of file (%s) in process %" PRIu64
"!",
407 LLDB_LOG(log,
"Process {0} exited with code {1}",
GetID(), exit_code);
421 LLDB_LOG(log,
"Debugger connected to process {0}. Image base = {1:x}",
432 LLDB_LOG(log,
"Cannot get process information during debugger connecting "
441 m_threads.push_back(std::make_unique<NativeThreadWindows>(
449 llvm::sys::ScopedLock lock(
m_mutex);
454 static bool initial_stop =
false;
461 case DWORD(STATUS_SINGLE_STEP):
462 case STATUS_WX86_SINGLE_STEP: {
470 "received error while checking for watchpoint hits, pid = "
472 thread->GetID(),
error);
477 formatv(
"{0} {1} {2}", wp_addr, wp_id, wp_hit_addr).str();
490 case DWORD(STATUS_BREAKPOINT):
493 LLDB_LOG(log,
"Hit non-loader breakpoint at address {0:x}.",
500 auto ®ister_context = stop_thread->GetRegisterContext();
503 uint64_t
pc = register_context.GetPC() - breakpoint_size;
504 register_context.SetPC(
pc);
514 "Hit loader breakpoint at address {0:x}, setting initial stop "
535 "Debugger thread reported exception {0:x} at address {1:x} "
536 "(first_chance={2})",
542 llvm::raw_string_ostream desc_stream(desc);
543 desc_stream <<
"Exception "
545 <<
" encountered at address "
548 desc_stream.str().c_str());
565 llvm::sys::ScopedLock lock(
m_mutex);
567 auto thread = std::make_unique<NativeThreadWindows>(*
this, new_thread);
568 thread->GetRegisterContext().ClearAllHardwareWatchpoints();
580 llvm::sys::ScopedLock lock(
m_mutex);
586 if ((*t)->GetID() == thread_id) {
606 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
611 Error E = Error::success();
612 auto process_up = std::unique_ptr<NativeProcessWindows>(
616 return std::move(process_up);
619 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
623 Error E = Error::success();
625 auto process_up = std::unique_ptr<NativeProcessWindows>(
629 return std::move(process_up);
Status SetSoftwareBreakpoint(lldb::addr_t addr, uint32_t size_hint)
void OnLoadDll(const ModuleSpec &module_spec, lldb::addr_t module_addr) override
lldb::pid_t GetDebuggedProcessId() const
void SetStopReason(ThreadStopInfo stop_info, std::string description)
NativeProcessWindows(ProcessLaunchInfo &launch_info, NativeDelegate &delegate, llvm::Error &E)
lldb::tid_t GetThreadID() const
virtual Status GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr)
#define LLDB_INVALID_PROCESS_ID
std::map< lldb_private::FileSpec, lldb::addr_t > m_loaded_modules
virtual Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
bool IsAlive() const override
void SetState(lldb::StateType state, bool notify_delegates=true)
void OnDebuggerConnected(lldb::addr_t image_base) override
NativeThreadProtocol * GetThreadByID(lldb::tid_t tid)
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
#define STATUS_WX86_BREAKPOINT
std::unordered_map< lldb::addr_t, SoftwareBreakpoint > m_software_breakpoints
virtual bool SetExitStatus(WaitStatus status, bool bNotifyStateChange)
StopReason
Thread stop reasons.
union lldb_private::ThreadStopInfo::@13 details
Status IgnoreSignals(llvm::ArrayRef< int > signals) override
void SetProcessID(lldb::pid_t pid)
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read)
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate, MainLoop &mainloop) const override
Launch a process for debugging.
@ eErrorTypeWin32
Standard Win32 error codes.
Status DestroyProcess(lldb::StateType process_state)
void OnExitProcess(uint32_t exit_code) override
@ eStateExited
Process has exited and can't be examined.
Status Interrupt() override
Tells a process to interrupt all operations as if by a Ctrl-C.
const char * GetCString(bool denormalize=true) const
const ResumeAction * GetActionForThread(lldb::tid_t tid, bool default_ok) const
@ eStateStopped
Process or thread is stopped and can be examined.
void SetCurrentThreadID(lldb::tid_t tid)
virtual llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint)
Status AttachProcess(lldb::pid_t pid, const ProcessAttachInfo &attach_info, DebugDelegateSP delegate)
static llvm::raw_ostream & error(Stream &strm)
bool Success() const
Test for success condition.
@ eStateCrashed
Process or thread has crashed and can be examined.
void StopThread(lldb::tid_t thread_id, lldb::StopReason reason, std::string description="")
llvm::Error DeallocateMemory(lldb::addr_t addr) override
Status GetLoadedModuleFileSpec(const char *module_path, FileSpec &file_spec) override
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) override
Status RemoveSoftwareBreakpoint(lldb::addr_t addr)
virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index)
void OnUnloadDll(lldb::addr_t module_addr) override
Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) override
llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint) override
bool Fail() const
Test for error condition.
void SetID(lldb::pid_t pid)
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > GetAuxvData() const override
lldb::pid_t GetID() const
Status LaunchProcess(ProcessLaunchInfo &launch_info, DebugDelegateSP delegate)
DWORD GetExceptionCode() const
bool FindSoftwareBreakpoint(lldb::addr_t addr)
void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override
@ eStateDetached
Process has been detached and can't be examined.
struct lldb_private::ThreadStopInfo::@13::@15 exception
std::shared_ptr< IDebugDelegate > DebugDelegateSP
string(SUBSTRING ${p} 10 -1 pStripped) if($
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
struct lldb_private::ThreadStopInfo::@13::@14 signal
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Attach(lldb::pid_t pid, NativeDelegate &native_delegate, MainLoop &mainloop) const override
Attach to an existing process.
@ eStateUnloaded
Process is object is valid, but not currently loaded.
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
std::vector< std::unique_ptr< NativeThreadProtocol > > m_threads
ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) override
lldb::addr_t GetExceptionAddress() const
const ArchSpec & GetArchitecture() const override
Status DeallocateMemory(lldb::addr_t addr)
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
void SetArchitecture(const ArchSpec &arch_spec)
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
void SetStopReasonForThread(NativeThreadWindows &thread, lldb::StopReason reason, std::string description="")
Status CacheLoadedModules()
Status Signal(int signo) override
Sends a process a UNIX signal signal.
void OnCreateThread(const HostThread &thread) override
virtual Status RemoveHardwareBreakpoint(lldb::addr_t addr)
lldb::tid_t GetID() const
size_t UpdateThreads() override
static bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
lldb::StateType GetState() const
#define LLDB_INVALID_ADDRESS
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
static FileSystem & Instance()
llvm::Expected< lldb::addr_t > AllocateMemory(size_t size, uint32_t permissions) override
virtual ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record)
ArchSpec & GetArchitecture()
Status HaltProcess(bool &caused_stop)
A class that represents a running process on the host machine.
size_t GetSoftwareBreakpointPCOffset() override
Return the offset of the PC relative to the software breakpoint that was hit.
Status AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr)
virtual const NativeWatchpointList::WatchpointMap & GetWatchpointMap() const
Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false) override
llvm::Error ToError() const
Status Resume(const ResumeActionList &resume_actions) override
#define LLDB_INVALID_INDEX32
StateType
Process and Thread States.
lldb::addr_t GetSharedLibraryInfoAddress() override
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< ExceptionRecord > ExceptionRecordSP
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written)
@ eStateRunning
Process or thread is running and can't be examined.
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override
std::unique_ptr< ProcessWindowsData > m_session_data
virtual void OnExitProcess(uint32_t exit_code)
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index)
NativeThreadWindows * GetThreadByID(lldb::tid_t thread_id)