LLDB mainline
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
lldb_private::process_gdb_remote::GDBRemoteCommunication Class Reference

#include <GDBRemoteCommunication.h>

Inheritance diagram for lldb_private::process_gdb_remote::GDBRemoteCommunication:
Inheritance graph
[legend]

Classes

class  ScopedTimeout
 

Public Types

enum class  PacketType { Invalid = 0 , Standard , Notify }
 
enum class  PacketResult {
  Success = 0 , ErrorSendFailed , ErrorSendAck , ErrorReplyFailed ,
  ErrorReplyTimeout , ErrorReplyInvalid , ErrorReplyAck , ErrorDisconnected ,
  ErrorNoSequenceLock
}
 

Public Member Functions

 GDBRemoteCommunication ()
 
 ~GDBRemoteCommunication () override
 
PacketResult GetAck ()
 
size_t SendAck ()
 
size_t SendNack ()
 
char CalculcateChecksum (llvm::StringRef payload)
 
PacketType CheckForPacket (const uint8_t *src, size_t src_len, StringExtractorGDBRemote &packet)
 
bool GetSendAcks ()
 
std::chrono::seconds SetPacketTimeout (std::chrono::seconds packet_timeout)
 
std::chrono::seconds GetPacketTimeout () const
 
Status StartDebugserverProcess (const char *url, Platform *platform, ProcessLaunchInfo &launch_info, uint16_t *port, const Args *inferior_args, int pass_comm_fd)
 
void DumpHistory (Stream &strm)
 
void SetPacketRecorder (repro::PacketRecorder *recorder)
 
- Public Member Functions inherited from lldb_private::Communication
 Communication ()
 Construct the Communication object.
 
virtual ~Communication ()
 Destructor.
 
virtual void Clear ()
 
lldb::ConnectionStatus Connect (const char *url, Status *error_ptr)
 Connect using the current connection by passing url to its connect function.
 
virtual lldb::ConnectionStatus Disconnect (Status *error_ptr=nullptr)
 Disconnect the communications connection if one is currently connected.
 
bool IsConnected () const
 Check if the connection is valid.
 
bool HasConnection () const
 
lldb_private::ConnectionGetConnection ()
 
virtual size_t Read (void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr)
 Read bytes from the current connection.
 
size_t Write (const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr)
 The actual write function that attempts to write to the communications protocol.
 
size_t WriteAll (const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr)
 Repeatedly attempt writing until either src_len bytes are written or a permanent failure occurs.
 
virtual void SetConnection (std::unique_ptr< Connection > connection)
 Sets the connection that it to be used by this class.
 
bool GetCloseOnEOF () const
 
void SetCloseOnEOF (bool b)
 

Static Public Member Functions

static llvm::Error ConnectLocally (GDBRemoteCommunication &client, GDBRemoteCommunication &server)
 
static std::string ExpandRLE (std::string)
 Expand GDB run-length encoding.
 
- Static Public Member Functions inherited from lldb_private::Communication
static std::string ConnectionStatusAsString (lldb::ConnectionStatus status)
 

Protected Member Functions

PacketResult SendPacketNoLock (llvm::StringRef payload)
 
PacketResult SendNotificationPacketNoLock (llvm::StringRef notify_type, std::deque< std::string > &queue, llvm::StringRef payload)
 
PacketResult SendRawPacketNoLock (llvm::StringRef payload, bool skip_ack=false)
 
PacketResult ReadPacket (StringExtractorGDBRemote &response, Timeout< std::micro > timeout, bool sync_on_timeout)
 
PacketResult WaitForPacketNoLock (StringExtractorGDBRemote &response, Timeout< std::micro > timeout, bool sync_on_timeout)
 
bool CompressionIsEnabled ()
 
bool DecompressPacket ()
 
Status StartListenThread (const char *hostname="127.0.0.1", uint16_t port=0)
 
bool JoinListenThread ()
 
lldb::thread_result_t ListenThread ()
 
- Protected Member Functions inherited from lldb_private::Communication
size_t ReadFromConnection (void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr)
 

Protected Attributes

std::chrono::seconds m_packet_timeout
 
uint32_t m_echo_number
 
LazyBool m_supports_qEcho
 
GDBRemoteCommunicationHistory m_history
 
bool m_send_acks
 
bool m_is_platform
 
std::string m_bytes
 
std::recursive_mutex m_bytes_mutex
 
CompressionType m_compression_type
 
- Protected Attributes inherited from lldb_private::Communication
lldb::ConnectionSP m_connection_sp
 The connection that is current in use by this communications class.
 
std::mutex m_write_mutex
 Don't let multiple threads write at the same time...
 
bool m_close_on_eof
 

Private Member Functions

 GDBRemoteCommunication (const GDBRemoteCommunication &)=delete
 
const GDBRemoteCommunicationoperator= (const GDBRemoteCommunication &)=delete
 

Private Attributes

std::promise< uint16_t > m_port_promise
 
HostThread m_listen_thread
 
std::string m_listen_url
 

Detailed Description

Definition at line 83 of file GDBRemoteCommunication.h.

Member Enumeration Documentation

◆ PacketResult

Enumerator
Success 
ErrorSendFailed 
ErrorSendAck 
ErrorReplyFailed 
ErrorReplyTimeout 
ErrorReplyInvalid 
ErrorReplyAck 
ErrorDisconnected 
ErrorNoSequenceLock 

Definition at line 87 of file GDBRemoteCommunication.h.

◆ PacketType

Enumerator
Invalid 
Standard 
Notify 

Definition at line 85 of file GDBRemoteCommunication.h.

Constructor & Destructor Documentation

◆ GDBRemoteCommunication() [1/2]

GDBRemoteCommunication::GDBRemoteCommunication ( )

Definition at line 59 of file GDBRemoteCommunication.cpp.

◆ ~GDBRemoteCommunication()

GDBRemoteCommunication::~GDBRemoteCommunication ( )
override

◆ GDBRemoteCommunication() [2/2]

lldb_private::process_gdb_remote::GDBRemoteCommunication::GDBRemoteCommunication ( const GDBRemoteCommunication )
privatedelete

Member Function Documentation

◆ CalculcateChecksum()

char GDBRemoteCommunication::CalculcateChecksum ( llvm::StringRef  payload)

◆ CheckForPacket()

GDBRemoteCommunication::PacketType GDBRemoteCommunication::CheckForPacket ( const uint8_t *  src,
size_t  src_len,
StringExtractorGDBRemote packet 
)

◆ CompressionIsEnabled()

bool lldb_private::process_gdb_remote::GDBRemoteCommunication::CompressionIsEnabled ( )
inlineprotected

◆ ConnectLocally()

llvm::Error GDBRemoteCommunication::ConnectLocally ( GDBRemoteCommunication client,
GDBRemoteCommunication server 
)
static

◆ DecompressPacket()

bool GDBRemoteCommunication::DecompressPacket ( )
protected

◆ DumpHistory()

void GDBRemoteCommunication::DumpHistory ( Stream strm)

◆ ExpandRLE()

std::string GDBRemoteCommunication::ExpandRLE ( std::string  packet)
static

Expand GDB run-length encoding.

Definition at line 1295 of file GDBRemoteCommunication.cpp.

Referenced by CheckForPacket().

◆ GetAck()

GDBRemoteCommunication::PacketResult GDBRemoteCommunication::GetAck ( )

◆ GetPacketTimeout()

std::chrono::seconds lldb_private::process_gdb_remote::GDBRemoteCommunication::GetPacketTimeout ( ) const
inline

◆ GetSendAcks()

bool lldb_private::process_gdb_remote::GDBRemoteCommunication::GetSendAcks ( )
inline

Definition at line 134 of file GDBRemoteCommunication.h.

References m_send_acks.

Referenced by CheckForPacket(), DecompressPacket(), and SendRawPacketNoLock().

◆ JoinListenThread()

bool GDBRemoteCommunication::JoinListenThread ( )
protected

◆ ListenThread()

lldb::thread_result_t GDBRemoteCommunication::ListenThread ( )
protected

◆ operator=()

const GDBRemoteCommunication & lldb_private::process_gdb_remote::GDBRemoteCommunication::operator= ( const GDBRemoteCommunication )
privatedelete

◆ ReadPacket()

GDBRemoteCommunication::PacketResult GDBRemoteCommunication::ReadPacket ( StringExtractorGDBRemote response,
Timeout< std::micro >  timeout,
bool  sync_on_timeout 
)
protected

◆ SendAck()

size_t GDBRemoteCommunication::SendAck ( )

◆ SendNack()

size_t GDBRemoteCommunication::SendNack ( )

◆ SendNotificationPacketNoLock()

GDBRemoteCommunication::PacketResult GDBRemoteCommunication::SendNotificationPacketNoLock ( llvm::StringRef  notify_type,
std::deque< std::string > &  queue,
llvm::StringRef  payload 
)
protected

◆ SendPacketNoLock()

GDBRemoteCommunication::PacketResult GDBRemoteCommunication::SendPacketNoLock ( llvm::StringRef  payload)
protected

Definition at line 113 of file GDBRemoteCommunication.cpp.

References CalculcateChecksum(), lldb::eByteOrderBig, lldb_private::StreamString::GetString(), lldb_private::Stream::PutChar(), lldb_private::Stream::PutHex8(), SendRawPacketNoLock(), and lldb_private::Stream::Write().

Referenced by lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle__M(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_g(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_jLLDBTraceGetBinaryData(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_jModulesInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerPlatform::Handle_jSignalsInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_jThreadsInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_memory_read(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_p(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qC(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerPlatform::Handle_qC(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qEcho(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qFileLoadAddress(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qGetWorkingDir(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerPlatform::Handle_qGetWorkingDir(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qGroupName(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qHostInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qLaunchSuccess(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qMemTags(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qModuleInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerPlatform::Handle_qPathComplete(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qPlatform_chmod(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qPlatform_mkdir(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qProcessInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerPlatform::Handle_qProcessInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qProcessInfoPID(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerPlatform::Handle_qQueryGDBServer(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qSaveCore(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_QSaveRegisterState(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qSpeedTest(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qsProcessInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qsThreadInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qSupported(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_qUserName(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qWatchpointSupportInfo(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qXfer(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_stop_reason(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_vCont_actions(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_Close(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_Exists(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_FStat(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_MD5(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_Mode(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_Open(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_pRead(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_Size(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_symlink(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::Handle_vFile_unlink(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::HandleNotificationAck(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServer::SendErrorResponse(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServer::SendOKResponse(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SendONotification(), lldb_private::process_gdb_remote::GDBRemoteClientBase::SendPacketAndReceiveResponseWithOutputSupport(), lldb_private::process_gdb_remote::GDBRemoteClientBase::SendPacketAndWaitForResponseNoLock(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServer::SendUnimplementedResponse(), lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SendWResponse(), and WaitForPacketNoLock().

◆ SendRawPacketNoLock()

GDBRemoteCommunication::PacketResult GDBRemoteCommunication::SendRawPacketNoLock ( llvm::StringRef  payload,
bool  skip_ack = false 
)
protected

◆ SetPacketRecorder()

void lldb_private::process_gdb_remote::GDBRemoteCommunication::SetPacketRecorder ( repro::PacketRecorder *  recorder)

◆ SetPacketTimeout()

std::chrono::seconds lldb_private::process_gdb_remote::GDBRemoteCommunication::SetPacketTimeout ( std::chrono::seconds  packet_timeout)
inline

◆ StartDebugserverProcess()

Status GDBRemoteCommunication::StartDebugserverProcess ( const char *  url,
Platform platform,
ProcessLaunchInfo launch_info,
uint16_t *  port,
const Args inferior_args,
int  pass_comm_fd 
)

Definition at line 882 of file GDBRemoteCommunication.cpp.

References lldb_private::Args::AppendArgument(), lldb_private::Args::AppendArguments(), lldb_private::ProcessLaunchInfo::AppendCloseFileAction(), lldb_private::ProcessLaunchInfo::AppendDuplicateFileAction(), lldb_private::FileSpec::AppendPathComponent(), lldb_private::ProcessLaunchInfo::AppendSuppressFileAction(), lldb_private::PipePosix::CanRead(), lldb_private::PipePosix::CanWrite(), lldb_private::Args::Clear(), lldb_private::FileSpec::Clear(), lldb_private::PipePosix::Close(), lldb_private::PipePosix::CloseWriteFileDescriptor(), lldb_private::PipePosix::CreateNew(), lldb_private::PipePosix::CreateWithUniqueName(), DEBUGSERVER_BASENAME, lldb_private::PipePosix::Delete(), lldb_private::ProcessInfo::Dump(), error(), lldb_private::FileSystem::Exists(), lldb_private::Args::GetArgumentCount(), lldb_private::ProcessInfo::GetArguments(), lldb_private::StreamString::GetData(), lldb_private::Host::GetEnvironment(), lldb_private::ProcessInfo::GetEnvironment(), lldb_private::ProcessInfo::GetExecutableFile(), lldb_private::ProcessLaunchInfo::GetLaunchInSeparateProcessGroup(), lldb_private::GetLog(), lldb_private::FileSpec::GetPath(), lldb_private::ProcessInfo::GetProcessID(), lldb_private::PipePosix::GetReadFileDescriptor(), lldb_private::StreamString::GetString(), lldb_private::PipePosix::GetWritePipe(), lldb_private::FileSystem::Instance(), JoinListenThread(), lldb_private::Host::LaunchProcess(), LLDB_INVALID_PROCESS_ID, LLDB_LOGF, lldb_private::Platform::LocateExecutable(), m_port_promise, lldb_private::PipePosix::OpenAsReader(), PATH_MAX, lldb_private::Stream::Printf(), lldb_private::process_gdb_remote::Process, lldb_private::PipePosix::ReadWithTimeout(), lldb_private::FileSpec::SetFile(), and StartListenThread().

Referenced by lldb_private::process_gdb_remote::ProcessGDBRemote::LaunchAndConnectToDebugserver(), and lldb_private::process_gdb_remote::GDBRemoteCommunicationServerPlatform::LaunchGDBServer().

◆ StartListenThread()

Status GDBRemoteCommunication::StartListenThread ( const char *  hostname = "127.0.0.1",
uint16_t  port = 0 
)
protected

◆ WaitForPacketNoLock()

GDBRemoteCommunication::PacketResult GDBRemoteCommunication::WaitForPacketNoLock ( StringExtractorGDBRemote response,
Timeout< std::micro >  timeout,
bool  sync_on_timeout 
)
protected

Sync the remote GDB server and make sure we get a response that corresponds to what we send.

Sends a "qEcho" packet and makes sure it gets the exact packet echoed back. If the qEcho packet isn't supported, we send a qC packet and make sure we get a valid thread ID back. We use the "qC" packet since its response if very unique: is responds with "QC%x" where x is the thread ID of the current thread. This makes the response unique enough from other packet responses to ensure we are back on track.

This packet is needed after we time out sending a packet so we can ensure that we are getting the response for the packet we are sending. There are no sequence IDs in the GDB remote protocol (there used to be, but they are not supported anymore) so if you timeout sending packet "abc", you might then send packet "cde" and get the response for the previous "abc" packet. Many responses are "OK" or "" (unsupported) or "EXX" (error) so many responses for packets can look like responses for other packets. So if we timeout, we need to ensure that we can get back on track. If we can't get back on track, we must disconnect.

Definition at line 241 of file GDBRemoteCommunication.cpp.

References CheckForPacket(), StringExtractor::Clear(), lldb_private::Communication::ConnectionStatusAsString(), lldb_private::Communication::Disconnect(), lldb::eConnectionStatusEndOfFile, lldb::eConnectionStatusError, lldb::eConnectionStatusInterrupted, lldb::eConnectionStatusLostConnection, lldb::eConnectionStatusNoConnection, lldb::eConnectionStatusSuccess, lldb::eConnectionStatusTimedOut, lldb_private::eLazyBoolYes, error(), ErrorDisconnected, ErrorReplyFailed, ErrorReplyTimeout, lldb_private::RegularExpression::Execute(), lldb_private::GetLog(), StringExtractor::GetStringRef(), Invalid, lldb_private::Communication::IsConnected(), LLDB_LOGV, m_echo_number, m_supports_qEcho, lldb_private::process_gdb_remote::Packets, lldb_private::Communication::Read(), SendPacketNoLock(), Success, and WaitForPacketNoLock().

Referenced by GetAck(), ReadPacket(), and WaitForPacketNoLock().

Member Data Documentation

◆ m_bytes

std::string lldb_private::process_gdb_remote::GDBRemoteCommunication::m_bytes
protected

Definition at line 179 of file GDBRemoteCommunication.h.

Referenced by CheckForPacket(), and DecompressPacket().

◆ m_bytes_mutex

std::recursive_mutex lldb_private::process_gdb_remote::GDBRemoteCommunication::m_bytes_mutex
protected

Definition at line 180 of file GDBRemoteCommunication.h.

Referenced by CheckForPacket().

◆ m_compression_type

CompressionType lldb_private::process_gdb_remote::GDBRemoteCommunication::m_compression_type
protected

◆ m_echo_number

uint32_t lldb_private::process_gdb_remote::GDBRemoteCommunication::m_echo_number
protected

Definition at line 171 of file GDBRemoteCommunication.h.

Referenced by WaitForPacketNoLock().

◆ m_history

GDBRemoteCommunicationHistory lldb_private::process_gdb_remote::GDBRemoteCommunication::m_history
protected

◆ m_is_platform

bool lldb_private::process_gdb_remote::GDBRemoteCommunication::m_is_platform
protected

Definition at line 175 of file GDBRemoteCommunication.h.

◆ m_listen_thread

HostThread lldb_private::process_gdb_remote::GDBRemoteCommunication::m_listen_thread
private

Definition at line 223 of file GDBRemoteCommunication.h.

Referenced by JoinListenThread(), and StartListenThread().

◆ m_listen_url

std::string lldb_private::process_gdb_remote::GDBRemoteCommunication::m_listen_url
private

Definition at line 224 of file GDBRemoteCommunication.h.

Referenced by ListenThread(), and StartListenThread().

◆ m_packet_timeout

std::chrono::seconds lldb_private::process_gdb_remote::GDBRemoteCommunication::m_packet_timeout
protected

Definition at line 170 of file GDBRemoteCommunication.h.

Referenced by GetPacketTimeout(), and SetPacketTimeout().

◆ m_port_promise

std::promise<uint16_t> lldb_private::process_gdb_remote::GDBRemoteCommunication::m_port_promise
private

Definition at line 221 of file GDBRemoteCommunication.h.

Referenced by StartDebugserverProcess().

◆ m_send_acks

bool lldb_private::process_gdb_remote::GDBRemoteCommunication::m_send_acks
protected

◆ m_supports_qEcho

LazyBool lldb_private::process_gdb_remote::GDBRemoteCommunication::m_supports_qEcho
protected

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