Files
llvm/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
Greg Clayton 4df8ddfc97 Completed more work on the KDP darwin kernel debugging Process plug-in.
Implemented connect, disconnect, reattach, version, and hostinfo.

Modified the ConnectionFileDescriptor class to be able to handle UDP. 

Added a new Stream subclass called StreamBuffer that is backed by a
llvm::SmallVector for better efficiency.

Modified the DataExtractor class to have a static function that can
dump hex bytes into a stream. This is currently being used to dump incoming
binary packet data in the KDP plug-in.

llvm-svn: 135338
2011-07-16 03:19:08 +00:00

238 lines
6.9 KiB
C++

//===-- CommunicationKDP.h --------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_CommunicationKDP_h_
#define liblldb_CommunicationKDP_h_
// C Includes
// C++ Includes
#include <list>
#include <string>
// Other libraries and framework includes
// Project includes
#include "lldb/lldb-private.h"
#include "lldb/Core/Communication.h"
#include "lldb/Core/Listener.h"
#include "lldb/Core/StreamBuffer.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Host/Predicate.h"
#include "lldb/Host/TimeValue.h"
class CommunicationKDP : public lldb_private::Communication
{
public:
enum
{
eBroadcastBitRunPacketSent = kLoUserBroadcastBit
};
const static uint32_t kMaxPacketSize = 1200;
const static uint32_t kMaxDataSize = 1024;
typedef lldb_private::StreamBuffer<1024> PacketStreamType;
typedef enum
{
eCommandTypeConnect = 0u,
eCommandTypeDisconnect,
eCommandTypeHostInfo,
eCommandTypeVersion,
eCommandTypeMaxBytes,
eCommandTypeReadMemory,
eCommandTypeWriteMemory,
eCommandTypeReadRegisters,
eCommandTypeWriteRegisters,
eCommandTypeLoad,
eCommandTypeImagePath,
eCommandTypeSuspend,
eCommandTypeResume,
eCommandTypeException,
eCommandTypeTermination,
eCommandTypeBreakpointSet,
eCommandTypeBreakpointRemove,
eCommandTypeRegions,
eCommandTypeReattach,
eCommandTypeHostReboot,
eCommandTypeReadMemory64,
eCommandTypeWriteMemory64,
eCommandTypeBreakpointSet64,
eCommandTypeBreakpointRemove64,
eCommandTypeKernelVersion
} CommandType;
typedef enum
{
KDP_PROTERR_SUCCESS = 0,
KDP_PROTERR_ALREADY_CONNECTED,
KDP_PROTERR_BAD_NBYTES,
KDP_PROTERR_BADFLAVOR
} KDPError;
typedef enum
{
ePacketTypeRequest = 0x00u,
ePacketTypeReply = 0x80u,
ePacketTypeMask = 0x80u,
eCommandTypeMask = 0x7fu
} PacketType;
//------------------------------------------------------------------
// Constructors and Destructors
//------------------------------------------------------------------
CommunicationKDP (const char *comm_name);
virtual
~CommunicationKDP();
bool
SendRequestPacket (const PacketStreamType &request_packet);
// Wait for a packet within 'nsec' seconds
size_t
WaitForPacketWithTimeoutMicroSeconds (lldb_private::DataExtractor &response,
uint32_t usec);
bool
GetSequenceMutex(lldb_private::Mutex::Locker& locker);
bool
CheckForPacket (const uint8_t *src,
size_t src_len,
lldb_private::DataExtractor &packet);
bool
IsRunning() const
{
return m_public_is_running.GetValue();
}
//------------------------------------------------------------------
// Set the global packet timeout.
//
// For clients, this is the timeout that gets used when sending
// packets and waiting for responses. For servers, this might not
// get used, and if it doesn't this should be moved to the
// CommunicationKDPClient.
//------------------------------------------------------------------
uint32_t
SetPacketTimeout (uint32_t packet_timeout)
{
const uint32_t old_packet_timeout = m_packet_timeout;
m_packet_timeout = packet_timeout;
return old_packet_timeout;
}
uint32_t
GetPacketTimeoutInMicroSeconds () const
{
return m_packet_timeout * lldb_private::TimeValue::MicroSecPerSec;
}
//------------------------------------------------------------------
// Start a debugserver instance on the current host using the
// supplied connection URL.
//------------------------------------------------------------------
lldb_private::Error
StartDebugserverProcess (const char *connect_url,
const char *unix_socket_name,
lldb_private::ProcessLaunchInfo &launch_info);
bool
Connect (uint16_t reply_port,
uint16_t exc_port,
const char *greeting);
bool
Reattach (uint16_t reply_port);
bool
Disconnect ();
uint32_t
GetVersion ();
uint32_t
GetFeatureFlags ();
uint32_t
GetCPUMask ();
uint32_t
GetCPUType ();
uint32_t
GetCPUSubtype ();
protected:
typedef std::list<std::string> packet_collection;
bool
SendRequestPacketNoLock (const PacketStreamType &request_packet);
size_t
WaitForPacketWithTimeoutMicroSecondsNoLock (lldb_private::DataExtractor &response,
uint32_t timeout_usec);
bool
WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr);
void
MakeRequestPacketHeader (CommandType request_type,
PacketStreamType &request_packet,
uint16_t request_length);
bool
SendRequestVersion ();
bool
VersionIsValid() const
{
return m_kdp_version_version != 0;
}
bool
HostInfoIsValid() const
{
return m_kdp_hostinfo_cpu_type != 0;
}
bool
SendRequestHostInfo ();
void
ClearKDPSettings ();
bool
SendRequestAndGetReply (const CommandType command,
const uint8_t request_sequence_id,
const PacketStreamType &request_packet,
lldb_private::DataExtractor &reply_packet);
//------------------------------------------------------------------
// Classes that inherit from CommunicationKDP can see and modify these
//------------------------------------------------------------------
lldb::ByteOrder m_byte_order;
uint32_t m_packet_timeout;
lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time
lldb_private::Predicate<bool> m_public_is_running;
lldb_private::Predicate<bool> m_private_is_running;
uint32_t m_session_key;
uint8_t m_request_sequence_id;
uint8_t m_exception_sequence_id;
uint32_t m_kdp_version_version;
uint32_t m_kdp_version_feature;
uint32_t m_kdp_hostinfo_cpu_mask;
uint32_t m_kdp_hostinfo_cpu_type;
uint32_t m_kdp_hostinfo_cpu_subtype;
private:
//------------------------------------------------------------------
// For CommunicationKDP only
//------------------------------------------------------------------
DISALLOW_COPY_AND_ASSIGN (CommunicationKDP);
};
#endif // liblldb_CommunicationKDP_h_