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

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

#include <ProcessMonitor.h>

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)
 

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 703 of file ProcessMonitor.cpp.

References GetPID(), lldb_private::Status::SetErrorString(), lldb_private::Status::SetErrorToErrno(), lldb_private::Status::SetErrorToGenericError(), and lldb_private::Status::Success().

◆ ProcessMonitor() [2/2]

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

◆ ~ProcessMonitor()

ProcessMonitor::~ProcessMonitor ( )

Member Function Documentation

◆ Detach()

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

◆ GetCurrentThreadIDs()

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

◆ 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 1351 of file ProcessMonitor.cpp.

Referenced by GetCurrentThreadIDs().

◆ 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 1336 of file ProcessMonitor.cpp.

Referenced by GetCurrentThreadIDs().

◆ 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 ~ProcessMonitor().

◆ 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.

References DupDescriptor().

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

◆ Kill()

bool ProcessMonitor::Kill ( )

Terminate the traced process.

Definition at line 1329 of file ProcessMonitor.cpp.

Referenced by ProcessFreeBSD::DoDestroy().

◆ 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 1242 of file ProcessMonitor.cpp.

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 1208 of file ProcessMonitor.cpp.

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 1274 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 1224 of file ProcessMonitor.cpp.

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 1298 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 1302 of file ProcessMonitor.cpp.

References lldb_private::GetLogIfAllCategoriesSet(), GetPID(), POSIX_LOG_PROCESS, and lldb_private::Log::Printf().

Referenced by FreeBSDThread::Resume().

◆ 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 1322 of file ProcessMonitor.cpp.

Referenced by FreeBSDThread::Resume().

◆ StopMonitor()

void ProcessMonitor::StopMonitor ( )

Definition at line 1389 of file ProcessMonitor.cpp.

Referenced by ProcessFreeBSD::Finalize(), and ~ProcessMonitor().

◆ ThreadSuspend()

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

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

Definition at line 1344 of file ProcessMonitor.cpp.

◆ WaitForInitialTIDStop()

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

Definition at line 1417 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 1251 of file ProcessMonitor.cpp.

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 1216 of file ProcessMonitor.cpp.

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 1293 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 1233 of file ProcessMonitor.cpp.

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


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