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);
80 "Cannot get process information");
89 llvm::sys::ScopedLock lock(
m_mutex);
93 LLDB_LOG(log,
"process {0} is in state {1}. Resuming...",
98 for (uint32_t i = 0; i <
m_threads.size(); ++i) {
102 if (action ==
nullptr)
105 switch (action->
state) {
112 "Trying to resume thread at index {0}, but failed with "
124 "NativeProcessWindows::%s (): unexpected state %s specified "
125 "for pid %" PRIu64
", tid %" PRIu64,
140 if (active_exception) {
148 LLDB_LOG(log,
"error: process {0} is in state {1}. Returning...",
162 bool caused_stop =
false;
181 "error: process {0} in state = {1}, but "
182 "cannot detach it in this state.",
192 "Windows does not support sending signals to processes");
213 size_t size,
size_t &bytes_read) {
218 size_t size,
size_t &bytes_written) {
222llvm::Expected<lldb::addr_t>
253 std::string description) {
257 stop_info.
reason = reason;
266 thread.SetStopReason(stop_info, description);
271 std::string description) {
276 for (uint32_t i = 0; i <
m_threads.size(); ++i) {
287llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
290 return llvm::errc::not_supported;
293llvm::Expected<llvm::ArrayRef<uint8_t>>
295 static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x3e,
297 static const uint8_t g_thumb_opcode[] = {0xfe, 0xde};
300 case llvm::Triple::aarch64:
301 return llvm::ArrayRef(g_aarch64_opcode);
303 case llvm::Triple::arm:
304 case llvm::Triple::thumb:
305 return llvm::ArrayRef(g_thumb_opcode);
345 AutoHandle snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,
GetID()));
348 me.dwSize =
sizeof(MODULEENTRY32W);
349 if (Module32FirstW(snapshot.
get(), &me)) {
352 if (!llvm::convertWideToUTF8(me.szExePath, path))
358 }
while (Module32Next(snapshot.
get(), &me));
375 FileSpec module_file_spec(module_path);
378 if (it.first == module_file_spec) {
379 file_spec = it.first;
384 "Module (%s) not found in process %" PRIu64
"!",
399 if (it.first == file_spec) {
400 load_addr = it.second;
405 "Can't get loaded address of file (%s) in process %" PRIu64
"!",
411 LLDB_LOG(log,
"Process {0} exited with code {1}",
GetID(), exit_code);
425 LLDB_LOG(log,
"Debugger connected to process {0}. Image base = {1:x}",
436 LLDB_LOG(log,
"Cannot get process information during debugger connecting "
445 m_threads.push_back(std::make_unique<NativeThreadWindows>(
453 llvm::sys::ScopedLock lock(
m_mutex);
458 static bool initial_stop =
false;
465 case DWORD(STATUS_SINGLE_STEP):
466 case STATUS_WX86_SINGLE_STEP: {
475 "received error while checking for watchpoint hits, pid = "
477 thread->GetID(),
error);
482 formatv(
"{0} {1} {2}", wp_addr, wp_id, wp_hit_addr).str();
496 case DWORD(STATUS_BREAKPOINT):
501 auto ®_ctx = stop_thread->GetRegisterContext();
506 LLDB_LOG(log,
"Hit non-loader breakpoint at address {0:x}.",
522 if (args.size() >= 2) {
524 Status error = reg_ctx.GetWatchpointHitIndex(hw_id, args[1]);
527 "received error while checking for watchpoint hits, pid = "
533 formatv(
"{0} {1} {2}", reg_ctx.GetWatchpointAddress(hw_id),
534 hw_id, exception_addr)
547 "Hit loader breakpoint at address {0:x}, setting initial stop "
568 "Debugger thread reported exception {0:x} at address {1:x} "
569 "(first_chance={2})",
575 llvm::raw_string_ostream desc_stream(desc);
576 desc_stream <<
"Exception "
578 <<
" encountered at address "
598 llvm::sys::ScopedLock lock(
m_mutex);
600 auto thread = std::make_unique<NativeThreadWindows>(*
this, new_thread);
601 thread->GetRegisterContext().ClearAllHardwareWatchpoints();
612 uint32_t exit_code) {
613 llvm::sys::ScopedLock lock(
m_mutex);
619 if ((*t)->GetID() == thread_id) {
639llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
643 Error E = Error::success();
644 auto process_up = std::unique_ptr<NativeProcessWindows>(
648 return std::move(process_up);
651llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
654 Error E = Error::success();
656 auto process_up = std::unique_ptr<NativeProcessWindows>(
660 return std::move(process_up);
static llvm::raw_ostream & error(Stream &strm)
#define STATUS_WX86_BREAKPOINT
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
static llvm::Error createStringError(const char *format, Args &&...args)
lldb::tid_t GetThreadID() const
DWORD GetExceptionCode() const
const std::vector< ULONG_PTR > & GetExceptionArguments() const
lldb::addr_t GetExceptionAddress() const
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
static FileSystem & Instance()
static bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
NativeProcessProtocol(lldb::pid_t pid, int terminal_fd, NativeDelegate &delegate)
lldb::pid_t GetID() const
Status SetSoftwareBreakpoint(lldb::addr_t addr, uint32_t size_hint)
virtual const NativeWatchpointList::WatchpointMap & GetWatchpointMap() const
lldb::StateType GetState() const
void SetState(lldb::StateType state, bool notify_delegates=true)
NativeThreadProtocol * GetThreadByID(lldb::tid_t tid)
void SetCurrentThreadID(lldb::tid_t tid)
std::vector< std::unique_ptr< NativeThreadProtocol > > m_threads
virtual bool SetExitStatus(WaitStatus status, bool bNotifyStateChange)
void SetID(lldb::pid_t pid)
Status RemoveSoftwareBreakpoint(lldb::addr_t addr)
virtual Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
virtual llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint)
virtual Status RemoveHardwareBreakpoint(lldb::addr_t addr)
std::unordered_map< lldb::addr_t, SoftwareBreakpoint > m_software_breakpoints
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.
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) override
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
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)
bool IsAlive() const override
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
Status CacheLoadedModules()
void SetArchitecture(const ArchSpec &arch_spec)
ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record) override
size_t GetSoftwareBreakpointPCOffset() override
Return the offset of the PC relative to the software breakpoint that was hit.
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
bool FindSoftwareBreakpoint(lldb::addr_t addr)
void StopThread(lldb::tid_t thread_id, lldb::StopReason reason, std::string description="")
size_t UpdateThreads() override
lldb::addr_t GetSharedLibraryInfoAddress() override
Status IgnoreSignals(llvm::ArrayRef< int > signals) override
std::map< lldb_private::FileSpec, lldb::addr_t > m_loaded_modules
virtual Status GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr)
virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index)
virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index)
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written)
Status DestroyProcess(lldb::StateType process_state)
Status LaunchProcess(ProcessLaunchInfo &launch_info, DebugDelegateSP delegate)
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
std::unique_ptr< ProcessWindowsData > m_session_data
Status AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr)
virtual ExceptionResult OnDebugException(bool first_chance, const ExceptionRecord &record)
Status AttachProcess(lldb::pid_t pid, const ProcessAttachInfo &attach_info, DebugDelegateSP delegate)
lldb::pid_t GetDebuggedProcessId() const
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read)
virtual void OnExitProcess(uint32_t exit_code)
Status HaltProcess(bool &caused_stop)
Status DeallocateMemory(lldb::addr_t addr)
void SetProcessID(lldb::pid_t pid)
ArchSpec & GetArchitecture()
const ResumeAction * GetActionForThread(lldb::tid_t tid, bool default_ok) const
llvm::Error ToError() const
FIXME: Replace all uses with takeError() instead.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
bool Fail() const
Test for error condition.
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
bool Success() const
Test for success condition.
#define LLDB_INVALID_INDEX32
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< ExceptionRecord > ExceptionRecordSP
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
std::shared_ptr< IDebugDelegate > DebugDelegateSP
StateType
Process and Thread States.
@ eStateUnloaded
Process is object is valid, but not currently loaded.
@ eStateDetached
Process has been detached and can't be examined.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
@ eStateRunning
Process or thread is running and can't be examined.
@ eStateExited
Process has exited and can't be examined.
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
@ eStateCrashed
Process or thread has crashed and can be examined.
@ eErrorTypeWin32
Standard Win32 error codes.
StopReason
Thread stop reasons.
struct lldb_private::ThreadStopInfo::@150217207351365026144342340310063367220052123157::@063112131000362061214367311025355347052261351334 exception
union lldb_private::ThreadStopInfo::@150217207351365026144342340310063367220052123157 details