19#include "llvm/Support/Errno.h"
23#include <sys/ptrace.h>
24#include <sys/sysctl.h>
41 process.GetArchitecture(), *this)),
42 m_stop_description() {}
77 const siginfo_t *info) {
79 LLDB_LOG(log,
"tid = {0} in called with signal {1}",
GetID(), signo);
120 std::ostringstream ostr;
167 const StateType new_state = StateType::eStateStopped;
173 m_state = StateType::eStateRunning;
178 m_state = StateType::eStateStepping;
185 std::vector<struct kinfo_proc> kp;
186 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD,
190 size_t len = kp.size() *
sizeof(
struct kinfo_proc);
191 void *ptr = len == 0 ? nullptr : kp.data();
192 int error = ::sysctl(mib, 4, ptr, &len,
nullptr, 0);
193 if (ptr ==
nullptr || (
error != 0 && errno == ENOMEM)) {
194 kp.resize(len /
sizeof(
struct kinfo_proc));
199 LLDB_LOG(log,
"tid = {0} in state {1} failed to get thread name: {2}",
202 kp.resize(len /
sizeof(
struct kinfo_proc));
206 for (
auto &procinfo : kp) {
207 if (procinfo.ki_tid ==
static_cast<lwpid_t
>(
GetID()))
208 return procinfo.ki_tdname;
217 std::string &description) {
239 LLDB_LOG(log,
"tid = {0} in state {1} cannot answer stop reason",
GetID(),
243 llvm_unreachable(
"unhandled StateType!");
252 uint32_t watch_flags,
bool hardware) {
255 return Status(
"not implemented");
262 return Status(
"Setting hardware watchpoint failed.");
271 uint32_t wp_index = wp->second;
275 return Status(
"Clearing hardware watchpoint failed.");
288 return Status(
"Setting hardware breakpoint failed.");
299 uint32_t bp_index = bp->second;
305 return Status(
"Clearing hardware breakpoint failed.");
323llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
327 struct ptrace_lwpinfo info;
329 PT_LWPINFO,
GetID(), &info,
sizeof(info));
330 if (siginfo_err.Fail()) {
331 LLDB_LOG(log,
"PT_LWPINFO failed {0}", siginfo_err);
332 return siginfo_err.ToError();
335 if (info.pl_event != PL_EVENT_SIGNAL)
336 return llvm::createStringError(llvm::inconvertibleErrorCode(),
337 "Thread not signaled");
338 if (!(info.pl_flags & PL_FLAG_SI))
339 return llvm::createStringError(llvm::inconvertibleErrorCode(),
340 "No siginfo for thread");
342 return llvm::MemoryBuffer::getMemBufferCopy(
343 llvm::StringRef(
reinterpret_cast<const char *
>(&info.pl_siginfo),
344 sizeof(info.pl_siginfo)));
static llvm::raw_ostream & error(Stream &strm)
std::string GetCrashReasonString(const siginfo_t &info)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
lldb::pid_t GetID() const
virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index)
virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index)
virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags)
virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
NativeProcessProtocol & m_process
lldb::tid_t GetID() const
void Clear()
Clear the object state.
ValueType GetError() const
Access the error value.
bool Success() const
Test for success condition.
Manages communication with the inferior (debugee) process.
static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr=nullptr, int data=0, int *result=nullptr)
virtual llvm::Error CopyHardwareWatchpointsFrom(NativeRegisterContextFreeBSD &source)=0
ThreadStopInfo m_stop_info
void SetStoppedByVForkDone()
Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override
llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > GetSiginfo() const override
NativeRegisterContextFreeBSD & GetRegisterContext() override
llvm::Error CopyWatchpointsFrom(NativeThreadFreeBSD &source)
void SetStoppedWithNoReason()
std::unique_ptr< NativeRegisterContextFreeBSD > m_reg_context_up
void SetStoppedByVFork(lldb::pid_t child_pid, lldb::tid_t child_tid)
NativeThreadFreeBSD(NativeProcessFreeBSD &process, lldb::tid_t tid)
NativeProcessFreeBSD & GetProcess()
std::string m_stop_description
WatchpointIndexMap m_hw_break_index_map
WatchpointIndexMap m_watchpoint_index_map
void SetStoppedByFork(lldb::pid_t child_pid, lldb::tid_t child_tid)
Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) override
void SetStoppedBySignal(uint32_t signo, const siginfo_t *info=nullptr)
void SetStoppedByWatchpoint(uint32_t wp_index)
lldb::StateType GetState() override
bool GetStopReason(ThreadStopInfo &stop_info, std::string &description) override
Status RemoveWatchpoint(lldb::addr_t addr) override
void SetStoppedByBreakpoint()
Status RemoveHardwareBreakpoint(lldb::addr_t addr) override
std::string GetName() override
#define LLDB_INVALID_INDEX32
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.
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
StateType
Process and Thread States.
@ eStateUnloaded
Process is object is valid, but not currently loaded.
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
@ 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.
@ eStateLaunching
Process is in the process of launching.
@ eStateAttaching
Process is currently trying to attach.
@ 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.
struct lldb_private::ThreadStopInfo::@11::@13 fork
union lldb_private::ThreadStopInfo::@11 details