LLDB  mainline
Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ProcessMonitor Class Reference

Manages communication with the inferior (debugee) process. More...

#include <ProcessMonitor.h>

Collaboration diagram for ProcessMonitor:
Collaboration graph
[legend]

Classes

struct  AttachArgs
 
struct  LaunchArgs
 
struct  OperationArgs
 

Public Member Functions

 ProcessMonitor (ProcessFreeBSD *process, lldb_private::Module *module, char const *argv[], lldb_private::Environment env, const lldb_private::FileSpec &stdin_file_spec, const lldb_private::FileSpec &stdout_file_spec, const lldb_private::FileSpec &stderr_file_spec, const lldb_private::FileSpec &working_dir, const lldb_private::ProcessLaunchInfo &launch_info, lldb_private::Status &error)
 Launches an inferior process ready for debugging. More...
 
 ProcessMonitor (ProcessFreeBSD *process, lldb::pid_t pid, lldb_private::Status &error)
 
 ~ProcessMonitor ()
 
lldb::pid_t GetPID () const
 Provides the process number of debugee. More...
 
ProcessFreeBSDGetProcess ()
 Returns the process associated with this ProcessMonitor. More...
 
int GetTerminalFD () const
 Returns a file descriptor to the controlling terminal of the inferior process. More...
 
size_t ReadMemory (lldb::addr_t vm_addr, void *buf, size_t size, lldb_private::Status &error)
 Reads size bytes from address in the inferior process address space. More...
 
size_t WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, lldb_private::Status &error)
 Writes size bytes from address vm_adder in the inferior process address space. More...
 
bool ReadRegisterValue (lldb::tid_t tid, unsigned offset, const char *reg_name, unsigned size, lldb_private::RegisterValue &value)
 Reads the contents from the register identified by the given (architecture dependent) offset. More...
 
bool WriteRegisterValue (lldb::tid_t tid, unsigned offset, const char *reg_name, const lldb_private::RegisterValue &value)
 Writes the given value to the register identified by the given (architecture dependent) offset. More...
 
bool ReadDebugRegisterValue (lldb::tid_t tid, unsigned offset, const char *reg_name, unsigned size, lldb_private::RegisterValue &value)
 Reads the contents from the debug register identified by the given (architecture dependent) offset. More...
 
bool WriteDebugRegisterValue (lldb::tid_t tid, unsigned offset, const char *reg_name, const lldb_private::RegisterValue &value)
 Writes the given value to the debug register identified by the given (architecture dependent) offset. More...
 
bool ReadGPR (lldb::tid_t tid, void *buf, size_t buf_size)
 Reads all general purpose registers into the specified buffer. More...
 
bool ReadFPR (lldb::tid_t tid, void *buf, size_t buf_size)
 Reads all floating point registers into the specified buffer. More...
 
bool ReadRegisterSet (lldb::tid_t tid, void *buf, size_t buf_size, unsigned int regset)
 Reads the specified register set into the specified buffer. More...
 
bool WriteGPR (lldb::tid_t tid, void *buf, size_t buf_size)
 Writes all general purpose registers into the specified buffer. More...
 
bool WriteFPR (lldb::tid_t tid, void *buf, size_t buf_size)
 Writes all floating point registers into the specified buffer. More...
 
bool WriteRegisterSet (lldb::tid_t tid, void *buf, size_t buf_size, unsigned int regset)
 Writes the specified register set into the specified buffer. More...
 
bool ReadThreadPointer (lldb::tid_t tid, lldb::addr_t &value)
 Reads the value of the thread-specific pointer for a given thread ID. More...
 
size_t GetCurrentThreadIDs (std::vector< lldb::tid_t > &thread_ids)
 Returns current thread IDs in process. More...
 
bool GetLwpInfo (lldb::tid_t tid, void *lwpinfo, int &error_no)
 Writes a ptrace_lwpinfo structure corresponding to the given thread ID to the memory region pointed to by lwpinfo. More...
 
bool ThreadSuspend (lldb::tid_t tid, bool suspend)
 Suspends or unsuspends a thread prior to process resume or step. More...
 
bool GetEventMessage (lldb::tid_t tid, unsigned long *message)
 Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG) corresponding to the given thread IDto the memory pointed to by message. More...
 
bool Resume (lldb::tid_t unused, uint32_t signo)
 Resumes the process. More...
 
bool SingleStep (lldb::tid_t unused, uint32_t signo)
 Single steps the process. More...
 
bool Kill ()
 Terminate the traced process. More...
 
lldb_private::Status Detach (lldb::tid_t tid)
 
void StopMonitor ()
 
bool WaitForInitialTIDStop (lldb::tid_t tid)
 

Private Member Functions

void StartLaunchOpThread (LaunchArgs *args, lldb_private::Status &error)
 
void StartAttachOpThread (AttachArgs *args, lldb_private::Status &error)
 
void DoOperation (Operation *op)
 
void StopMonitoringChildProcess ()
 Stops the child monitor thread. More...
 
void StopOpThread ()
 Stops the operation thread used to attach/launch a process. More...
 

Static Private Member Functions

static void * LaunchOpThread (void *arg)
 
static bool Launch (LaunchArgs *args)
 
static void * AttachOpThread (void *args)
 
static void Attach (AttachArgs *args)
 
static void ServeOperation (OperationArgs *args)
 
static bool DupDescriptor (const lldb_private::FileSpec &file_spec, int fd, int flags)
 
static bool MonitorCallback (ProcessMonitor *monitor, lldb::pid_t pid, bool exited, int signal, int status)
 
static ProcessMessage MonitorSIGTRAP (ProcessMonitor *monitor, const siginfo_t *info, lldb::pid_t pid)
 
static ProcessMessage MonitorSignal (ProcessMonitor *monitor, const siginfo_t *info, lldb::pid_t pid)
 

Private Attributes

ProcessFreeBSDm_process
 
llvm::Optional< lldb_private::HostThreadm_operation_thread
 
llvm::Optional< lldb_private::HostThreadm_monitor_thread
 
lldb::pid_t m_pid
 
int m_terminal_fd
 
Operationm_operation
 
std::mutex m_operation_mutex
 
sem_t m_operation_pending
 
sem_t m_operation_done
 

Detailed Description

Manages communication with the inferior (debugee) process.

Upon construction, this class prepares and launches an inferior process for debugging.

Changes in the inferior process state are propagated to the associated ProcessFreeBSD instance by calling ProcessFreeBSD::SendMessage with the appropriate ProcessMessage events.

A purposely minimal set of operations are provided to interrogate and change the inferior process state.

Definition at line 42 of file ProcessMonitor.h.

Constructor & Destructor Documentation

◆ ProcessMonitor() [1/2]

ProcessMonitor::ProcessMonitor ( ProcessFreeBSD process,
lldb_private::Module module,
char const *  argv[],
lldb_private::Environment  env,
const lldb_private::FileSpec stdin_file_spec,
const lldb_private::FileSpec stdout_file_spec,
const lldb_private::FileSpec stderr_file_spec,
const lldb_private::FileSpec working_dir,
const lldb_private::ProcessLaunchInfo launch_info,
lldb_private::Status error 
)

Launches an inferior process ready for debugging.

The basic design of the ProcessMonitor is built around two threads.

Forms the implementation of Process::DoLaunch.

One thread (

See also
SignalThread) simply blocks on a call to waitpid() looking for changes in the debugee state. When a change is detected a ProcessMessage is sent to the associated ProcessFreeBSD instance. This thread "drives" state changes in the debugger.

The second thread (

See also
OperationThread) is responsible for two things 1) launching or attaching to the inferior process, and then 2) servicing operations such as register reads/writes, stepping, etc. See the comments on the Operation class for more info as to why this is needed.

Definition at line 698 of file ProcessMonitor.cpp.

References error(), GetPID(), m_monitor_thread, m_operation_done, m_operation_pending, MonitorCallback(), lldb_private::Status::SetErrorString(), lldb_private::Status::SetErrorToErrno(), lldb_private::Status::SetErrorToGenericError(), StartLaunchOpThread(), StopOpThread(), and lldb_private::Status::Success().

◆ ProcessMonitor() [2/2]

ProcessMonitor::ProcessMonitor ( ProcessFreeBSD process,
lldb::pid_t  pid,
lldb_private::Status error 
)

◆ ~ProcessMonitor()

ProcessMonitor::~ProcessMonitor ( )

Definition at line 785 of file ProcessMonitor.cpp.

References StopMonitor().

Member Function Documentation

◆ Attach()

void ProcessMonitor::Attach ( AttachArgs args)
staticprivate

◆ AttachOpThread()

void * ProcessMonitor::AttachOpThread ( void *  args)
staticprivate

Definition at line 972 of file ProcessMonitor.cpp.

References Attach(), NULL, and ServeOperation().

Referenced by StartAttachOpThread().

◆ Detach()

lldb_private::Status ProcessMonitor::Detach ( lldb::tid_t  tid)

Definition at line 1360 of file ProcessMonitor.cpp.

References DoOperation(), error(), and LLDB_INVALID_THREAD_ID.

◆ DoOperation()

void ProcessMonitor::DoOperation ( Operation op)
private

◆ DupDescriptor()

bool ProcessMonitor::DupDescriptor ( const lldb_private::FileSpec file_spec,
int  fd,
int  flags 
)
staticprivate

Definition at line 1369 of file ProcessMonitor.cpp.

References lldb_private::FileSpec::GetCString().

Referenced by Launch().

◆ GetCurrentThreadIDs()

size_t ProcessMonitor::GetCurrentThreadIDs ( std::vector< lldb::tid_t > &  thread_ids)

Returns current thread IDs in process.

Definition at line 1009 of file ProcessMonitor.cpp.

References m_pid, NULL, and PTRACE.

◆ GetEventMessage()

bool ProcessMonitor::GetEventMessage ( lldb::tid_t  tid,
unsigned long *  message 
)

Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG) corresponding to the given thread IDto the memory pointed to by message.

Definition at line 1353 of file ProcessMonitor.cpp.

References DoOperation().

Referenced by MonitorSIGTRAP().

◆ GetLwpInfo()

bool ProcessMonitor::GetLwpInfo ( lldb::tid_t  tid,
void *  lwpinfo,
int &  error_no 
)

Writes a ptrace_lwpinfo structure corresponding to the given thread ID to the memory region pointed to by lwpinfo.

Definition at line 1338 of file ProcessMonitor.cpp.

References DoOperation().

Referenced by MonitorCallback().

◆ GetPID()

lldb::pid_t ProcessMonitor::GetPID ( ) const
inline

◆ GetProcess()

ProcessFreeBSD& ProcessMonitor::GetProcess ( )
inline

Returns the process associated with this ProcessMonitor.

Definition at line 64 of file ProcessMonitor.h.

Referenced by Attach(), and Launch().

◆ GetTerminalFD()

int ProcessMonitor::GetTerminalFD ( ) const
inline

Returns a file descriptor to the controlling terminal of the inferior process.

Reads from this file descriptor yield both the standard output and standard error of this debugee. Even if stderr and stdout were redirected on launch it may still happen that data is available on this descriptor (if the inferior process opens /dev/tty, for example). This descriptor is closed after a call to StopMonitor().

If this monitor was attached to an existing process this method returns -1.

Definition at line 77 of file ProcessMonitor.h.

Referenced by ProcessFreeBSD::DoAttachToProcessWithID(), ProcessFreeBSD::DoLaunch(), and ProcessFreeBSD::PutSTDIN().

◆ Kill()

bool ProcessMonitor::Kill ( )

Terminate the traced process.

Definition at line 1331 of file ProcessMonitor.cpp.

References DoOperation().

Referenced by ProcessFreeBSD::DoDestroy().

◆ Launch()

bool ProcessMonitor::Launch ( LaunchArgs args)
staticprivate

◆ LaunchOpThread()

void * ProcessMonitor::LaunchOpThread ( void *  arg)
staticprivate

◆ MonitorCallback()

bool ProcessMonitor::MonitorCallback ( ProcessMonitor monitor,
lldb::pid_t  pid,
bool  exited,
int  signal,
int  status 
)
staticprivate

◆ MonitorSignal()

ProcessMessage ProcessMonitor::MonitorSignal ( ProcessMonitor monitor,
const siginfo_t *  info,
lldb::pid_t  pid 
)
staticprivate

◆ MonitorSIGTRAP()

ProcessMessage ProcessMonitor::MonitorSIGTRAP ( ProcessMonitor monitor,
const siginfo_t *  info,
lldb::pid_t  pid 
)
staticprivate

◆ ReadDebugRegisterValue()

bool ProcessMonitor::ReadDebugRegisterValue ( lldb::tid_t  tid,
unsigned  offset,
const char *  reg_name,
unsigned  size,
lldb_private::RegisterValue value 
)

Reads the contents from the debug register identified by the given (architecture dependent) offset.

This method is provided for use by RegisterContextFreeBSD derivatives.

Definition at line 1244 of file ProcessMonitor.cpp.

References DoOperation().

Referenced by RegisterContextPOSIXProcessMonitor_x86_64::ReadRegister().

◆ ReadFPR()

bool ProcessMonitor::ReadFPR ( lldb::tid_t  tid,
void *  buf,
size_t  buf_size 
)

◆ ReadGPR()

bool ProcessMonitor::ReadGPR ( lldb::tid_t  tid,
void *  buf,
size_t  buf_size 
)

◆ ReadMemory()

size_t ProcessMonitor::ReadMemory ( lldb::addr_t  vm_addr,
void *  buf,
size_t  size,
lldb_private::Status error 
)

Reads size bytes from address in the inferior process address space.

This method is provided to implement Process::DoReadMemory.

Definition at line 1210 of file ProcessMonitor.cpp.

References DoOperation().

Referenced by ProcessFreeBSD::DoReadMemory().

◆ ReadRegisterSet()

bool ProcessMonitor::ReadRegisterSet ( lldb::tid_t  tid,
void *  buf,
size_t  buf_size,
unsigned int  regset 
)

Reads the specified register set into the specified buffer.

This method is provided for use by RegisterContextFreeBSD derivatives.

Definition at line 1276 of file ProcessMonitor.cpp.

Referenced by RegisterContextPOSIXProcessMonitor_x86_64::ReadFPR().

◆ ReadRegisterValue()

bool ProcessMonitor::ReadRegisterValue ( lldb::tid_t  tid,
unsigned  offset,
const char *  reg_name,
unsigned  size,
lldb_private::RegisterValue value 
)

Reads the contents from the register identified by the given (architecture dependent) offset.

This method is provided for use by RegisterContextFreeBSD derivatives.

Definition at line 1226 of file ProcessMonitor.cpp.

References DoOperation().

Referenced by RegisterContextPOSIXProcessMonitor_arm::ReadRegister(), RegisterContextPOSIXProcessMonitor_arm64::ReadRegister(), RegisterContextPOSIXProcessMonitor_x86_64::ReadRegister(), RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(), and RegisterContextPOSIXProcessMonitor_powerpc::ReadRegister().

◆ ReadThreadPointer()

bool ProcessMonitor::ReadThreadPointer ( lldb::tid_t  tid,
lldb::addr_t value 
)

Reads the value of the thread-specific pointer for a given thread ID.

Definition at line 1300 of file ProcessMonitor.cpp.

Referenced by FreeBSDThread::GetThreadPointer().

◆ Resume()

bool ProcessMonitor::Resume ( lldb::tid_t  unused,
uint32_t  signo 
)

Resumes the process.

If signo is anything but LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the process.

Definition at line 1304 of file ProcessMonitor.cpp.

References DoOperation(), lldb_private::GetLogIfAllCategoriesSet(), GetPID(), lldb_private::Process::GetUnixSignals(), LLDB_LOGF, m_process, and POSIX_LOG_PROCESS.

Referenced by FreeBSDThread::Resume().

◆ ServeOperation()

void ProcessMonitor::ServeOperation ( OperationArgs args)
staticprivate

◆ SingleStep()

bool ProcessMonitor::SingleStep ( lldb::tid_t  unused,
uint32_t  signo 
)

Single steps the process.

If signo is anything but LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the process.

Definition at line 1324 of file ProcessMonitor.cpp.

References DoOperation().

Referenced by FreeBSDThread::Resume().

◆ StartAttachOpThread()

void ProcessMonitor::StartAttachOpThread ( AttachArgs args,
lldb_private::Status error 
)
private

Definition at line 957 of file ProcessMonitor.cpp.

References AttachOpThread(), and m_operation_thread.

Referenced by ProcessMonitor().

◆ StartLaunchOpThread()

void ProcessMonitor::StartLaunchOpThread ( LaunchArgs args,
lldb_private::Status error 
)
private

Definition at line 788 of file ProcessMonitor.cpp.

References LaunchOpThread(), and m_operation_thread.

Referenced by ProcessMonitor().

◆ StopMonitor()

void ProcessMonitor::StopMonitor ( )

◆ StopMonitoringChildProcess()

void ProcessMonitor::StopMonitoringChildProcess ( )
private

Stops the child monitor thread.

Definition at line 1383 of file ProcessMonitor.cpp.

References m_monitor_thread.

Referenced by StopMonitor().

◆ StopOpThread()

void ProcessMonitor::StopOpThread ( )
private

Stops the operation thread used to attach/launch a process.

Definition at line 1421 of file ProcessMonitor.cpp.

References m_operation_thread.

Referenced by ProcessMonitor(), and StopMonitor().

◆ ThreadSuspend()

bool ProcessMonitor::ThreadSuspend ( lldb::tid_t  tid,
bool  suspend 
)

Suspends or unsuspends a thread prior to process resume or step.

Definition at line 1346 of file ProcessMonitor.cpp.

References DoOperation().

◆ WaitForInitialTIDStop()

bool ProcessMonitor::WaitForInitialTIDStop ( lldb::tid_t  tid)

Definition at line 1419 of file ProcessMonitor.cpp.

◆ WriteDebugRegisterValue()

bool ProcessMonitor::WriteDebugRegisterValue ( lldb::tid_t  tid,
unsigned  offset,
const char *  reg_name,
const lldb_private::RegisterValue value 
)

Writes the given value to the debug register identified by the given (architecture dependent) offset.

This method is provided for use by RegisterContextFreeBSD derivatives.

Definition at line 1253 of file ProcessMonitor.cpp.

References DoOperation().

Referenced by RegisterContextPOSIXProcessMonitor_x86_64::WriteRegister().

◆ WriteFPR()

bool ProcessMonitor::WriteFPR ( lldb::tid_t  tid,
void *  buf,
size_t  buf_size 
)

◆ WriteGPR()

bool ProcessMonitor::WriteGPR ( lldb::tid_t  tid,
void *  buf,
size_t  buf_size 
)

◆ WriteMemory()

size_t ProcessMonitor::WriteMemory ( lldb::addr_t  vm_addr,
const void *  buf,
size_t  size,
lldb_private::Status error 
)

Writes size bytes from address vm_adder in the inferior process address space.

This method is provided to implement Process::DoWriteMemory.

Definition at line 1218 of file ProcessMonitor.cpp.

References DoOperation().

Referenced by ProcessFreeBSD::DoWriteMemory().

◆ WriteRegisterSet()

bool ProcessMonitor::WriteRegisterSet ( lldb::tid_t  tid,
void *  buf,
size_t  buf_size,
unsigned int  regset 
)

Writes the specified register set into the specified buffer.

This method is provided for use by RegisterContextFreeBSD derivatives.

Definition at line 1295 of file ProcessMonitor.cpp.

Referenced by RegisterContextPOSIXProcessMonitor_x86_64::WriteFPR().

◆ WriteRegisterValue()

bool ProcessMonitor::WriteRegisterValue ( lldb::tid_t  tid,
unsigned  offset,
const char *  reg_name,
const lldb_private::RegisterValue value 
)

Writes the given value to the register identified by the given (architecture dependent) offset.

This method is provided for use by RegisterContextFreeBSD derivatives.

Definition at line 1235 of file ProcessMonitor.cpp.

References DoOperation().

Referenced by RegisterContextPOSIXProcessMonitor_arm::WriteRegister(), RegisterContextPOSIXProcessMonitor_arm64::WriteRegister(), RegisterContextPOSIXProcessMonitor_x86_64::WriteRegister(), RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(), and RegisterContextPOSIXProcessMonitor_powerpc::WriteRegister().

Member Data Documentation

◆ m_monitor_thread

llvm::Optional<lldb_private::HostThread> ProcessMonitor::m_monitor_thread
private

Definition at line 187 of file ProcessMonitor.h.

Referenced by ProcessMonitor(), and StopMonitoringChildProcess().

◆ m_operation

Operation* ProcessMonitor::m_operation
private

Definition at line 193 of file ProcessMonitor.h.

Referenced by DoOperation(), and ServeOperation().

◆ m_operation_done

sem_t ProcessMonitor::m_operation_done
private

Definition at line 199 of file ProcessMonitor.h.

Referenced by DoOperation(), ProcessMonitor(), ServeOperation(), and StopMonitor().

◆ m_operation_mutex

std::mutex ProcessMonitor::m_operation_mutex
private

Definition at line 194 of file ProcessMonitor.h.

Referenced by DoOperation().

◆ m_operation_pending

sem_t ProcessMonitor::m_operation_pending
private

Definition at line 198 of file ProcessMonitor.h.

Referenced by DoOperation(), ProcessMonitor(), ServeOperation(), and StopMonitor().

◆ m_operation_thread

llvm::Optional<lldb_private::HostThread> ProcessMonitor::m_operation_thread
private

Definition at line 186 of file ProcessMonitor.h.

Referenced by StartAttachOpThread(), StartLaunchOpThread(), and StopOpThread().

◆ m_pid

lldb::pid_t ProcessMonitor::m_pid
private

Definition at line 188 of file ProcessMonitor.h.

Referenced by GetCurrentThreadIDs(), and Launch().

◆ m_process

ProcessFreeBSD* ProcessMonitor::m_process
private

Definition at line 184 of file ProcessMonitor.h.

Referenced by MonitorCallback(), MonitorSignal(), MonitorSIGTRAP(), and Resume().

◆ m_terminal_fd

int ProcessMonitor::m_terminal_fd
private

Definition at line 190 of file ProcessMonitor.h.

Referenced by Launch(), and StopMonitor().


The documentation for this class was generated from the following files: