From 4ccd99541bfc8f4f475dbacd1d17dc9817e92b1e Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 27 Jun 2017 10:33:14 +0000 Subject: [PATCH] Move Connection and IOObject interfaces to Utility module Summary: These interfaces have no dependencies, so it makes sense for them to be in the lowest level modules, to make sure that other parts of the codebase can use them without introducing loops. The only exception here is the Connection::CreateDefaultConnection method, which I've moved to Host, as it instantiates concrete implementations, and that's where the implementations live. Reviewers: jingham, zturner Subscribers: lldb-commits, mgorny Differential Revision: https://reviews.llvm.org/D34400 llvm-svn: 306391 --- lldb/include/lldb/Host/File.h | 2 +- lldb/include/lldb/Host/Host.h | 3 ++ lldb/include/lldb/Host/MainLoopBase.h | 8 ++--- lldb/include/lldb/Host/Socket.h | 2 +- .../posix/ConnectionFileDescriptorPosix.h | 4 +-- .../windows/ConnectionGenericFileWindows.h | 2 +- .../lldb/{Core => Utility}/Connection.h | 6 ++-- .../include/lldb/{Host => Utility}/IOObject.h | 4 +-- lldb/source/API/SBCommunication.cpp | 3 +- lldb/source/Core/CMakeLists.txt | 1 - lldb/source/Core/Communication.cpp | 2 +- lldb/source/Core/Connection.cpp | 32 ------------------- lldb/source/Host/CMakeLists.txt | 1 - lldb/source/Host/common/Host.cpp | 10 ++++++ .../posix/ConnectionFileDescriptorPosix.cpp | 3 +- lldb/source/Utility/CMakeLists.txt | 2 ++ lldb/source/Utility/Connection.cpp | 14 ++++++++ .../{Host/common => Utility}/IOObject.cpp | 3 +- lldb/tools/lldb-server/Acceptor.h | 2 +- 19 files changed, 48 insertions(+), 56 deletions(-) rename lldb/include/lldb/{Core => Utility}/Connection.h (98%) rename lldb/include/lldb/{Host => Utility}/IOObject.h (96%) delete mode 100644 lldb/source/Core/Connection.cpp create mode 100644 lldb/source/Utility/Connection.cpp rename lldb/source/{Host/common => Utility}/IOObject.cpp (86%) diff --git a/lldb/include/lldb/Host/File.h b/lldb/include/lldb/Host/File.h index 560a655237f3..1dfa12ea593d 100644 --- a/lldb/include/lldb/Host/File.h +++ b/lldb/include/lldb/Host/File.h @@ -10,8 +10,8 @@ #ifndef liblldb_File_h_ #define liblldb_File_h_ -#include "lldb/Host/IOObject.h" #include "lldb/Host/PosixApi.h" +#include "lldb/Utility/IOObject.h" #include "lldb/Utility/Status.h" #include "lldb/lldb-private.h" diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h index bf48e207f1f2..c41e4796f532 100644 --- a/lldb/include/lldb/Host/Host.h +++ b/lldb/include/lldb/Host/Host.h @@ -238,6 +238,9 @@ public: uint32_t line_no); static size_t GetEnvironment(StringList &env); + + static std::unique_ptr + CreateDefaultConnection(llvm::StringRef url); }; } // namespace lldb_private diff --git a/lldb/include/lldb/Host/MainLoopBase.h b/lldb/include/lldb/Host/MainLoopBase.h index 39ca9a0f0c9e..a87d262e9452 100644 --- a/lldb/include/lldb/Host/MainLoopBase.h +++ b/lldb/include/lldb/Host/MainLoopBase.h @@ -10,12 +10,10 @@ #ifndef lldb_Host_posix_MainLoopBase_h_ #define lldb_Host_posix_MainLoopBase_h_ -#include - -#include "llvm/Support/ErrorHandling.h" - -#include "lldb/Host/IOObject.h" +#include "lldb/Utility/IOObject.h" #include "lldb/Utility/Status.h" +#include "llvm/Support/ErrorHandling.h" +#include namespace lldb_private { diff --git a/lldb/include/lldb/Host/Socket.h b/lldb/include/lldb/Host/Socket.h index c4233a233a89..37f468f23ce0 100644 --- a/lldb/include/lldb/Host/Socket.h +++ b/lldb/include/lldb/Host/Socket.h @@ -15,9 +15,9 @@ #include "lldb/lldb-private.h" -#include "lldb/Host/IOObject.h" #include "lldb/Host/Predicate.h" #include "lldb/Host/SocketAddress.h" +#include "lldb/Utility/IOObject.h" #include "lldb/Utility/Status.h" #ifdef _WIN32 diff --git a/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h b/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h index f57c93684002..b7e08eb33af7 100644 --- a/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h +++ b/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h @@ -19,10 +19,10 @@ // Other libraries and framework includes // Project includes -#include "lldb/Core/Connection.h" -#include "lldb/Host/IOObject.h" #include "lldb/Host/Pipe.h" #include "lldb/Host/Predicate.h" +#include "lldb/Utility/Connection.h" +#include "lldb/Utility/IOObject.h" namespace lldb_private { diff --git a/lldb/include/lldb/Host/windows/ConnectionGenericFileWindows.h b/lldb/include/lldb/Host/windows/ConnectionGenericFileWindows.h index 9309288b8c0a..5468009a41cd 100644 --- a/lldb/include/lldb/Host/windows/ConnectionGenericFileWindows.h +++ b/lldb/include/lldb/Host/windows/ConnectionGenericFileWindows.h @@ -10,7 +10,7 @@ #ifndef liblldb_Host_windows_ConnectionGenericFileWindows_h_ #define liblldb_Host_windows_ConnectionGenericFileWindows_h_ -#include "lldb/Core/Connection.h" +#include "lldb/Host/Connection.h" #include "lldb/Host/windows/windows.h" #include "lldb/lldb-types.h" diff --git a/lldb/include/lldb/Core/Connection.h b/lldb/include/lldb/Utility/Connection.h similarity index 98% rename from lldb/include/lldb/Core/Connection.h rename to lldb/include/lldb/Utility/Connection.h index 27757b2f77e7..be5641d5fa63 100644 --- a/lldb/include/lldb/Core/Connection.h +++ b/lldb/include/lldb/Utility/Connection.h @@ -31,7 +31,7 @@ template class Timeout; namespace lldb_private { //---------------------------------------------------------------------- -/// @class Connection Connection.h "lldb/Core/Connection.h" +/// @class Connection Connection.h "lldb/Utility/Connection.h" /// @brief A communication connection class. /// /// A class that implements that actual communication functions for @@ -48,7 +48,7 @@ public: //------------------------------------------------------------------ /// Default constructor //------------------------------------------------------------------ - Connection(); + Connection() = default; //------------------------------------------------------------------ /// Virtual destructor since this class gets subclassed and handed @@ -56,8 +56,6 @@ public: //------------------------------------------------------------------ virtual ~Connection(); - static Connection *CreateDefaultConnection(const char *url); - //------------------------------------------------------------------ /// Connect using the connect string \a url. /// diff --git a/lldb/include/lldb/Host/IOObject.h b/lldb/include/lldb/Utility/IOObject.h similarity index 96% rename from lldb/include/lldb/Host/IOObject.h rename to lldb/include/lldb/Utility/IOObject.h index 98ad5056de74..61f288183850 100644 --- a/lldb/include/lldb/Host/IOObject.h +++ b/lldb/include/lldb/Utility/IOObject.h @@ -32,7 +32,7 @@ public: IOObject(FDType type, bool should_close) : m_fd_type(type), m_should_close_fd(should_close) {} - virtual ~IOObject() {} + virtual ~IOObject(); virtual Status Read(void *buf, size_t &num_bytes) = 0; virtual Status Write(const void *buf, size_t &num_bytes) = 0; @@ -51,6 +51,6 @@ protected: private: DISALLOW_COPY_AND_ASSIGN(IOObject); }; -} +} // namespace lldb_private #endif diff --git a/lldb/source/API/SBCommunication.cpp b/lldb/source/API/SBCommunication.cpp index 8ebc33ca26a6..63b672efe3c0 100644 --- a/lldb/source/API/SBCommunication.cpp +++ b/lldb/source/API/SBCommunication.cpp @@ -11,6 +11,7 @@ #include "lldb/API/SBBroadcaster.h" #include "lldb/Core/Communication.h" #include "lldb/Host/ConnectionFileDescriptor.h" +#include "lldb/Host/Host.h" #include "lldb/Utility/Log.h" using namespace lldb; @@ -51,7 +52,7 @@ void SBCommunication::SetCloseOnEOF(bool b) { ConnectionStatus SBCommunication::Connect(const char *url) { if (m_opaque) { if (!m_opaque->HasConnection()) - m_opaque->SetConnection(Connection::CreateDefaultConnection(url)); + m_opaque->SetConnection(Host::CreateDefaultConnection(url).release()); return m_opaque->Connect(url, NULL); } return eConnectionStatusNoConnection; diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index 806227793f24..6c3233df6df2 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -7,7 +7,6 @@ add_lldb_library(lldbCore ArchSpec.cpp Broadcaster.cpp Communication.cpp - Connection.cpp Debugger.cpp Disassembler.cpp DumpDataExtractor.cpp diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp index 72873a9510b5..38ab902ab4b7 100644 --- a/lldb/source/Core/Communication.cpp +++ b/lldb/source/Core/Communication.cpp @@ -9,11 +9,11 @@ #include "lldb/Core/Communication.h" -#include "lldb/Core/Connection.h" #include "lldb/Core/Event.h" #include "lldb/Core/Listener.h" #include "lldb/Host/HostThread.h" #include "lldb/Host/ThreadLauncher.h" +#include "lldb/Utility/Connection.h" #include "lldb/Utility/ConstString.h" // for ConstString #include "lldb/Utility/Log.h" #include "lldb/Utility/Logging.h" // for LogIfAnyCategoriesSet, LIBLLDB... diff --git a/lldb/source/Core/Connection.cpp b/lldb/source/Core/Connection.cpp deleted file mode 100644 index 60d1221c160c..000000000000 --- a/lldb/source/Core/Connection.cpp +++ /dev/null @@ -1,32 +0,0 @@ -//===-- Connection.cpp ------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "lldb/Core/Connection.h" - -#if defined(_WIN32) -#include "lldb/Host/windows/ConnectionGenericFileWindows.h" -#endif - -#include "lldb/Host/ConnectionFileDescriptor.h" - -#include // for strstr - -using namespace lldb_private; - -Connection::Connection() {} - -Connection::~Connection() {} - -Connection *Connection::CreateDefaultConnection(const char *url) { -#if defined(_WIN32) - if (strstr(url, "file://") == url) - return new ConnectionGenericFile(); -#endif - return new ConnectionFileDescriptor(); -} diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index b9079ce26a2c..73d030e198af 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -13,7 +13,6 @@ add_host_subdirectory(common common/HostNativeThreadBase.cpp common/HostProcess.cpp common/HostThread.cpp - common/IOObject.cpp common/LockFileBase.cpp common/MainLoop.cpp common/MonitoringProcessLauncher.cpp diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index af0b57248922..29e5991d31aa 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -58,6 +58,7 @@ #include "lldb/Host/Predicate.h" #include "lldb/Host/ProcessLauncher.h" #include "lldb/Host/ThreadLauncher.h" +#include "lldb/Host/posix/ConnectionFileDescriptorPosix.h" #include "lldb/Target/FileAction.h" #include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Target/UnixSignals.h" @@ -73,6 +74,7 @@ #include "llvm/Support/FileSystem.h" #if defined(_WIN32) +#include "lldb/Host/windows/ConnectionGenericFileWindows.h" #include "lldb/Host/windows/ProcessLauncherWindows.h" #else #include "lldb/Host/posix/ProcessLauncherPosixFork.h" @@ -624,6 +626,14 @@ const UnixSignalsSP &Host::GetUnixSignals() { return s_unix_signals_sp; } +std::unique_ptr Host::CreateDefaultConnection(llvm::StringRef url) { +#if defined(_WIN32) + if (url.startswith("file://")) + return std::unique_ptr(new ConnectionGenericFile()); +#endif + return std::unique_ptr(new ConnectionFileDescriptor()); +} + #if defined(LLVM_ON_UNIX) WaitStatus WaitStatus::Decode(int wstatus) { if (WIFEXITED(wstatus)) diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp index c3b237a87302..cc434f43855c 100644 --- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -16,10 +16,10 @@ #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h" #include "lldb/Host/Config.h" -#include "lldb/Host/IOObject.h" #include "lldb/Host/Socket.h" #include "lldb/Host/SocketAddress.h" #include "lldb/Utility/SelectHelper.h" +#include "lldb/Utility/Timeout.h" // C Includes #include @@ -42,7 +42,6 @@ #include "llvm/ADT/SmallVector.h" #endif // Project includes -#include "lldb/Core/Communication.h" #include "lldb/Core/Timer.h" #include "lldb/Host/Host.h" #include "lldb/Host/Socket.h" diff --git a/lldb/source/Utility/CMakeLists.txt b/lldb/source/Utility/CMakeLists.txt index 31b14acda962..cff601884bc8 100644 --- a/lldb/source/Utility/CMakeLists.txt +++ b/lldb/source/Utility/CMakeLists.txt @@ -1,5 +1,6 @@ add_lldb_library(lldbUtility Baton.cpp + Connection.cpp ConstString.cpp DataBufferHeap.cpp DataBufferLLVM.cpp @@ -8,6 +9,7 @@ add_lldb_library(lldbUtility FastDemangle.cpp FileSpec.cpp History.cpp + IOObject.cpp JSON.cpp LLDBAssert.cpp Log.cpp diff --git a/lldb/source/Utility/Connection.cpp b/lldb/source/Utility/Connection.cpp new file mode 100644 index 000000000000..9f6114f6ed5d --- /dev/null +++ b/lldb/source/Utility/Connection.cpp @@ -0,0 +1,14 @@ +//===-- Connection.cpp ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Utility/Connection.h" + +using namespace lldb_private; + +Connection::~Connection() = default; diff --git a/lldb/source/Host/common/IOObject.cpp b/lldb/source/Utility/IOObject.cpp similarity index 86% rename from lldb/source/Host/common/IOObject.cpp rename to lldb/source/Utility/IOObject.cpp index 6f7de442be1d..df7929c4f911 100644 --- a/lldb/source/Host/common/IOObject.cpp +++ b/lldb/source/Utility/IOObject.cpp @@ -7,8 +7,9 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Host/IOObject.h" +#include "lldb/Utility/IOObject.h" using namespace lldb_private; const IOObject::WaitableHandle IOObject::kInvalidHandleValue = -1; +IOObject::~IOObject() = default; diff --git a/lldb/tools/lldb-server/Acceptor.h b/lldb/tools/lldb-server/Acceptor.h index 207bb4d973a5..7d1a5695a364 100644 --- a/lldb/tools/lldb-server/Acceptor.h +++ b/lldb/tools/lldb-server/Acceptor.h @@ -9,8 +9,8 @@ #ifndef lldb_server_Acceptor_h_ #define lldb_server_Acceptor_h_ -#include "lldb/Core/Connection.h" #include "lldb/Host/Socket.h" +#include "lldb/Utility/Connection.h" #include "lldb/Utility/Status.h" #include