Index: lldb/trunk/include/lldb/Core/ConnectionMachPort.h =================================================================== --- lldb/trunk/include/lldb/Core/ConnectionMachPort.h +++ lldb/trunk/include/lldb/Core/ConnectionMachPort.h @@ -1,79 +0,0 @@ -//===-- ConnectionMachPort.h --------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#if defined(__APPLE__) - -#ifndef liblldb_ConnectionMachPort_h_ -#define liblldb_ConnectionMachPort_h_ - -// C Includes -#include -#include - -// C++ Includes -#include - -// Other libraries and framework includes -// Project includes -#include "lldb/Core/Connection.h" - -class ConnectionMachPort : public lldb_private::Connection { -public: - ConnectionMachPort(); - - virtual ~ConnectionMachPort(); - - virtual bool IsConnected() const; - - virtual lldb::ConnectionStatus BytesAvailable(uint32_t timeout_usec, - lldb_private::Error *error_ptr); - - virtual lldb::ConnectionStatus Connect(const char *s, - lldb_private::Error *error_ptr); - - virtual lldb::ConnectionStatus Disconnect(lldb_private::Error *error_ptr); - - virtual size_t Read(void *dst, size_t dst_len, uint32_t timeout_usec, - lldb::ConnectionStatus &status, - lldb_private::Error *error_ptr); - - virtual size_t Write(const void *src, size_t src_len, - lldb::ConnectionStatus &status, - lldb_private::Error *error_ptr); - - virtual std::string GetURI(); - - lldb::ConnectionStatus BootstrapCheckIn(const char *port_name, - lldb_private::Error *error_ptr); - - lldb::ConnectionStatus BootstrapLookup(const char *port_name, - lldb_private::Error *error_ptr); - - struct PayloadType { - uint32_t command; - uint32_t data_length; - uint8_t data[32]; - }; - - kern_return_t Send(const PayloadType &payload); - - kern_return_t Receive(PayloadType &payload); - -protected: - mach_port_t m_task; - mach_port_t m_port; - -private: - std::string m_uri; - - DISALLOW_COPY_AND_ASSIGN(ConnectionMachPort); -}; - -#endif // liblldb_ConnectionMachPort_h_ - -#endif // #if defined(__APPLE__) Index: lldb/trunk/lldb.xcodeproj/project.pbxproj =================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj +++ lldb/trunk/lldb.xcodeproj/project.pbxproj @@ -332,7 +332,6 @@ 266E82971B8CE3AC008FCA06 /* DWARFDIE.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 266E82961B8CE3AC008FCA06 /* DWARFDIE.cpp */; }; 266E829D1B8E542C008FCA06 /* DWARFAttribute.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 266E829C1B8E542C008FCA06 /* DWARFAttribute.cpp */; }; 2670F8121862B44A006B332C /* libncurses.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 2670F8111862B44A006B332C /* libncurses.dylib */; }; - 2671A0D013482601003A87BB /* ConnectionMachPort.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2671A0CF13482601003A87BB /* ConnectionMachPort.cpp */; }; 26744EF11338317700EF765A /* GDBRemoteCommunicationClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26744EED1338317700EF765A /* GDBRemoteCommunicationClient.cpp */; }; 26744EF31338317700EF765A /* GDBRemoteCommunicationServer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26744EEF1338317700EF765A /* GDBRemoteCommunicationServer.cpp */; }; 26780C611867C33D00234593 /* libncurses.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 2670F8111862B44A006B332C /* libncurses.dylib */; }; @@ -1838,8 +1837,6 @@ 266F5CBB12FC846200DFCE33 /* Config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Config.h; path = include/lldb/Host/Config.h; sourceTree = ""; }; 26709E311964A34000B94724 /* LaunchServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LaunchServices.framework; path = /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework; sourceTree = ""; }; 2670F8111862B44A006B332C /* libncurses.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libncurses.dylib; path = /usr/lib/libncurses.dylib; sourceTree = ""; }; - 2671A0CD134825F6003A87BB /* ConnectionMachPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConnectionMachPort.h; path = include/lldb/Core/ConnectionMachPort.h; sourceTree = ""; }; - 2671A0CF13482601003A87BB /* ConnectionMachPort.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConnectionMachPort.cpp; path = source/Core/ConnectionMachPort.cpp; sourceTree = ""; }; 2672D8461189055500FF4019 /* CommandObjectFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectFrame.cpp; path = source/Commands/CommandObjectFrame.cpp; sourceTree = ""; }; 2672D8471189055500FF4019 /* CommandObjectFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandObjectFrame.h; path = source/Commands/CommandObjectFrame.h; sourceTree = ""; }; 26744EED1338317700EF765A /* GDBRemoteCommunicationClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GDBRemoteCommunicationClient.cpp; sourceTree = ""; }; @@ -4660,8 +4657,6 @@ 26BC7E6E10F1B85900F91463 /* Communication.cpp */, 26BC7D5710F1B77400F91463 /* Connection.h */, 26BC7E6F10F1B85900F91463 /* Connection.cpp */, - 2671A0CD134825F6003A87BB /* ConnectionMachPort.h */, - 2671A0CF13482601003A87BB /* ConnectionMachPort.cpp */, 266603CC1345B5C0004DA8B6 /* ConnectionSharedMemory.h */, 266603C91345B5A8004DA8B6 /* ConnectionSharedMemory.cpp */, 26BC7D7C10F1B77400F91463 /* ConstString.h */, @@ -7469,7 +7464,6 @@ 26651A18133BF9E0005B64B7 /* Opcode.cpp in Sources */, 3FDFED0B19B7C8DE009756A7 /* HostThreadMacOSX.mm in Sources */, 266603CA1345B5A8004DA8B6 /* ConnectionSharedMemory.cpp in Sources */, - 2671A0D013482601003A87BB /* ConnectionMachPort.cpp in Sources */, 4CABA9E0134A8BCD00539BDD /* ValueObjectMemory.cpp in Sources */, 4CD0BD0F134BFADF00CB44D4 /* ValueObjectDynamicValue.cpp in Sources */, 946216C21A97C080006E19CC /* OptionValueLanguage.cpp in Sources */, Index: lldb/trunk/source/Core/CMakeLists.txt =================================================================== --- lldb/trunk/source/Core/CMakeLists.txt +++ lldb/trunk/source/Core/CMakeLists.txt @@ -9,7 +9,6 @@ Broadcaster.cpp Communication.cpp Connection.cpp - ConnectionMachPort.cpp ConnectionSharedMemory.cpp ConstString.cpp DataBufferHeap.cpp Index: lldb/trunk/source/Core/ConnectionMachPort.cpp =================================================================== --- lldb/trunk/source/Core/ConnectionMachPort.cpp +++ lldb/trunk/source/Core/ConnectionMachPort.cpp @@ -1,259 +0,0 @@ -//===-- ConnectionMachPort.cpp ----------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#if defined(__APPLE__) - -#include "lldb/Core/ConnectionMachPort.h" - -// C Includes -#include -#include - -// C++ Includes -// Other libraries and framework includes -// Project includes -#include "lldb/Core/Communication.h" -#include "lldb/Core/Log.h" - -using namespace lldb; -using namespace lldb_private; - -struct MessageType { - mach_msg_header_t head; - ConnectionMachPort::PayloadType payload; -}; - -ConnectionMachPort::ConnectionMachPort() - : Connection(), m_task(mach_task_self()), m_port(MACH_PORT_TYPE_NONE) {} - -ConnectionMachPort::~ConnectionMachPort() { Disconnect(NULL); } - -bool ConnectionMachPort::IsConnected() const { - return m_port != MACH_PORT_TYPE_NONE; -} - -ConnectionStatus ConnectionMachPort::Connect(const char *s, Error *error_ptr) { - if (IsConnected()) { - if (error_ptr) - error_ptr->SetErrorString("already connected"); - return eConnectionStatusError; - } - - if (s == NULL || s[0] == '\0') { - if (error_ptr) - error_ptr->SetErrorString("empty connect URL"); - return eConnectionStatusError; - } - - ConnectionStatus status = eConnectionStatusError; - - if (0 == strncmp(s, "bootstrap-checkin://", strlen("bootstrap-checkin://"))) { - s += strlen("bootstrap-checkin://"); - - if (*s) { - status = BootstrapCheckIn(s, error_ptr); - } else { - if (error_ptr) - error_ptr->SetErrorString("bootstrap port name is empty"); - } - } else if (0 == - strncmp(s, "bootstrap-lookup://", strlen("bootstrap-lookup://"))) { - s += strlen("bootstrap-lookup://"); - if (*s) { - status = BootstrapLookup(s, error_ptr); - } else { - if (error_ptr) - error_ptr->SetErrorString("bootstrap port name is empty"); - } - } else { - if (error_ptr) - error_ptr->SetErrorStringWithFormat("unsupported connection URL: '%s'", - s); - } - - if (status == eConnectionStatusSuccess) { - if (error_ptr) - error_ptr->Clear(); - m_uri.assign(s); - } else { - Disconnect(NULL); - } - - return status; -} - -ConnectionStatus ConnectionMachPort::BootstrapCheckIn(const char *port, - Error *error_ptr) { - mach_port_t bootstrap_port = MACH_PORT_TYPE_NONE; - - /* Getting bootstrap server port */ - kern_return_t kret = - task_get_bootstrap_port(mach_task_self(), &bootstrap_port); - if (kret == KERN_SUCCESS) { - name_t port_name; - int len = snprintf(port_name, sizeof(port_name), "%s", port); - if (static_cast(len) < sizeof(port_name)) { - kret = ::bootstrap_check_in(bootstrap_port, port_name, &m_port); - } else { - Disconnect(NULL); - if (error_ptr) - error_ptr->SetErrorString("bootstrap is too long"); - return eConnectionStatusError; - } - } - - if (kret != KERN_SUCCESS) { - Disconnect(NULL); - if (error_ptr) - error_ptr->SetError(kret, eErrorTypeMachKernel); - return eConnectionStatusError; - } - return eConnectionStatusSuccess; -} - -lldb::ConnectionStatus ConnectionMachPort::BootstrapLookup(const char *port, - Error *error_ptr) { - name_t port_name; - - if (port && port[0]) { - if (static_cast(::snprintf(port_name, sizeof(port_name), "%s", - port)) >= sizeof(port_name)) { - if (error_ptr) - error_ptr->SetErrorString("port netname is too long"); - return eConnectionStatusError; - } - } else { - if (error_ptr) - error_ptr->SetErrorString("empty port netname"); - return eConnectionStatusError; - } - - mach_port_t bootstrap_port = MACH_PORT_TYPE_NONE; - - /* Getting bootstrap server port */ - kern_return_t kret = - task_get_bootstrap_port(mach_task_self(), &bootstrap_port); - if (kret == KERN_SUCCESS) { - kret = ::bootstrap_look_up(bootstrap_port, port_name, &m_port); - } - - if (kret != KERN_SUCCESS) { - if (error_ptr) - error_ptr->SetError(kret, eErrorTypeMachKernel); - return eConnectionStatusError; - } - - return eConnectionStatusSuccess; -} - -ConnectionStatus ConnectionMachPort::Disconnect(Error *error_ptr) { - kern_return_t kret; - - // TODO: verify if we need to netname_check_out for - // either or both - if (m_port != MACH_PORT_TYPE_NONE) { - kret = ::mach_port_deallocate(m_task, m_port); - if (error_ptr) - error_ptr->SetError(kret, eErrorTypeMachKernel); - m_port = MACH_PORT_TYPE_NONE; - } - m_uri.clear(); - - return eConnectionStatusSuccess; -} - -size_t ConnectionMachPort::Read(void *dst, size_t dst_len, - uint32_t timeout_usec, ConnectionStatus &status, - Error *error_ptr) { - PayloadType payload; - - kern_return_t kret = Receive(payload); - if (kret == KERN_SUCCESS) { - memcpy(dst, payload.data, payload.data_length); - status = eConnectionStatusSuccess; - return payload.data_length; - } - - if (error_ptr) - error_ptr->SetError(kret, eErrorTypeMachKernel); - status = eConnectionStatusError; - return 0; -} - -size_t ConnectionMachPort::Write(const void *src, size_t src_len, - ConnectionStatus &status, Error *error_ptr) { - PayloadType payload; - payload.command = 0; - payload.data_length = src_len; - const size_t max_payload_size = sizeof(payload.data); - if (src_len > max_payload_size) - payload.data_length = max_payload_size; - memcpy(payload.data, src, payload.data_length); - - if (Send(payload) == KERN_SUCCESS) { - status = eConnectionStatusSuccess; - return payload.data_length; - } - status = eConnectionStatusError; - return 0; -} - -std::string ConnectionMachPort::GetURI() { return m_uri; } - -ConnectionStatus ConnectionMachPort::BytesAvailable(uint32_t timeout_usec, - Error *error_ptr) { - return eConnectionStatusLostConnection; -} - -kern_return_t ConnectionMachPort::Send(const PayloadType &payload) { - struct MessageType message; - - /* (i) Form the message : */ - - /* (i.a) Fill the header fields : */ - message.head.msgh_bits = MACH_MSGH_BITS_REMOTE(MACH_MSG_TYPE_MAKE_SEND) | - MACH_MSGH_BITS_OTHER(MACH_MSGH_BITS_COMPLEX); - message.head.msgh_size = sizeof(MessageType); - message.head.msgh_local_port = MACH_PORT_NULL; - message.head.msgh_remote_port = m_port; - - /* (i.b) Explain the message type ( an integer ) */ - // message.type.msgt_name = MACH_MSG_TYPE_INTEGER_32; - // message.type.msgt_size = 32; - // message.type.msgt_number = 1; - // message.type.msgt_inline = TRUE; - // message.type.msgt_longform = FALSE; - // message.type.msgt_deallocate = FALSE; - /* message.type.msgt_unused = 0; */ /* not needed, I think */ - - /* (i.c) Fill the message with the given integer : */ - message.payload = payload; - - /* (ii) Send the message : */ - kern_return_t kret = - ::mach_msg(&message.head, MACH_SEND_MSG, message.head.msgh_size, 0, - MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); - - return kret; -} - -kern_return_t ConnectionMachPort::Receive(PayloadType &payload) { - MessageType message; - message.head.msgh_size = sizeof(MessageType); - - kern_return_t kret = - ::mach_msg(&message.head, MACH_RCV_MSG, 0, sizeof(MessageType), m_port, - MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); - - if (kret == KERN_SUCCESS) - payload = message.payload; - - return kret; -} - -#endif // #if defined(__APPLE__)