From 3165945a419e4882b94f73f005f9ea4d3d10a985 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Thu, 17 Nov 2016 21:15:14 +0000 Subject: [PATCH] Convert Platform, Process, and Connection functions to StringRef. All tests pass on Linux and Windows. llvm-svn: 287259 --- lldb/include/lldb/Core/Connection.h | 3 +- lldb/include/lldb/Core/ConnectionSharedMemory.h | 2 +- .../Host/posix/ConnectionFileDescriptorPosix.h | 14 ++-- .../Host/windows/ConnectionGenericFileWindows.h | 2 +- lldb/include/lldb/Target/Platform.h | 4 +- lldb/include/lldb/Target/Process.h | 6 +- lldb/include/lldb/Target/Target.h | 2 +- lldb/source/API/SBTarget.cpp | 2 +- lldb/source/Commands/CommandObjectTarget.cpp | 2 +- lldb/source/Core/ConnectionSharedMemory.cpp | 2 +- .../Host/posix/ConnectionFileDescriptorPosix.cpp | 87 +++++++++++----------- .../Host/windows/ConnectionGenericFileWindows.cpp | 19 ++--- .../Android/PlatformAndroidRemoteGDBServer.cpp | 9 ++- .../Android/PlatformAndroidRemoteGDBServer.h | 4 +- .../Plugins/Platform/POSIX/PlatformPOSIX.cpp | 4 +- lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h | 4 +- .../gdb-server/PlatformRemoteGDBServer.cpp | 5 +- .../Platform/gdb-server/PlatformRemoteGDBServer.h | 4 +- .../Process/gdb-remote/ProcessGDBRemote.cpp | 21 +++--- .../Plugins/Process/gdb-remote/ProcessGDBRemote.h | 4 +- lldb/source/Target/Platform.cpp | 4 +- lldb/source/Target/Process.cpp | 10 +-- lldb/source/Target/Target.cpp | 2 +- 23 files changed, 108 insertions(+), 108 deletions(-) diff --git a/lldb/include/lldb/Core/Connection.h b/lldb/include/lldb/Core/Connection.h index f4c488f..729d433 100644 --- a/lldb/include/lldb/Core/Connection.h +++ b/lldb/include/lldb/Core/Connection.h @@ -66,7 +66,8 @@ public: /// /// @see Error& Communication::GetError (); //------------------------------------------------------------------ - virtual lldb::ConnectionStatus Connect(const char *url, Error *error_ptr) = 0; + virtual lldb::ConnectionStatus Connect(llvm::StringRef url, + Error *error_ptr) = 0; //------------------------------------------------------------------ /// Disconnect the communications connection if one is currently diff --git a/lldb/include/lldb/Core/ConnectionSharedMemory.h b/lldb/include/lldb/Core/ConnectionSharedMemory.h index af1cbe3..878d749 100644 --- a/lldb/include/lldb/Core/ConnectionSharedMemory.h +++ b/lldb/include/lldb/Core/ConnectionSharedMemory.h @@ -32,7 +32,7 @@ public: virtual lldb::ConnectionStatus BytesAvailable(uint32_t timeout_usec, Error *error_ptr); - lldb::ConnectionStatus Connect(const char *s, Error *error_ptr) override; + lldb::ConnectionStatus Connect(llvm::StringRef s, Error *error_ptr) override; lldb::ConnectionStatus Disconnect(Error *error_ptr) override; diff --git a/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h b/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h index d29ad2d..ae33daa 100644 --- a/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h +++ b/lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h @@ -53,7 +53,7 @@ public: bool IsConnected() const override; - lldb::ConnectionStatus Connect(const char *s, Error *error_ptr) override; + lldb::ConnectionStatus Connect(llvm::StringRef s, Error *error_ptr) override; lldb::ConnectionStatus Disconnect(Error *error_ptr) override; @@ -82,21 +82,21 @@ protected: void CloseCommandPipe(); - lldb::ConnectionStatus SocketListenAndAccept(const char *host_and_port, + lldb::ConnectionStatus SocketListenAndAccept(llvm::StringRef host_and_port, Error *error_ptr); - lldb::ConnectionStatus ConnectTCP(const char *host_and_port, + lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port, Error *error_ptr); - lldb::ConnectionStatus ConnectUDP(const char *args, Error *error_ptr); + lldb::ConnectionStatus ConnectUDP(llvm::StringRef args, Error *error_ptr); - lldb::ConnectionStatus NamedSocketConnect(const char *socket_name, + lldb::ConnectionStatus NamedSocketConnect(llvm::StringRef socket_name, Error *error_ptr); - lldb::ConnectionStatus NamedSocketAccept(const char *socket_name, + lldb::ConnectionStatus NamedSocketAccept(llvm::StringRef socket_name, Error *error_ptr); - lldb::ConnectionStatus UnixAbstractSocketConnect(const char *socket_name, + lldb::ConnectionStatus UnixAbstractSocketConnect(llvm::StringRef socket_name, Error *error_ptr); lldb::IOObjectSP m_read_sp; diff --git a/lldb/include/lldb/Host/windows/ConnectionGenericFileWindows.h b/lldb/include/lldb/Host/windows/ConnectionGenericFileWindows.h index da19065..eceecf7 100644 --- a/lldb/include/lldb/Host/windows/ConnectionGenericFileWindows.h +++ b/lldb/include/lldb/Host/windows/ConnectionGenericFileWindows.h @@ -28,7 +28,7 @@ public: bool IsConnected() const override; - lldb::ConnectionStatus Connect(const char *s, Error *error_ptr) override; + lldb::ConnectionStatus Connect(llvm::StringRef s, Error *error_ptr) override; lldb::ConnectionStatus Disconnect(Error *error_ptr) override; diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 2948f7b..9707093 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -413,8 +413,8 @@ public: // target, else use existing one Error &error); - virtual lldb::ProcessSP ConnectProcess(const char *connect_url, - const char *plugin_name, + virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, + llvm::StringRef plugin_name, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Error &error); diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 55c0835..7bcabdd 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -691,7 +691,7 @@ public: /// @see Process::CanDebug () //------------------------------------------------------------------ static lldb::ProcessSP FindPlugin(lldb::TargetSP target_sp, - const char *plugin_name, + llvm::StringRef plugin_name, lldb::ListenerSP listener_sp, const FileSpec *crash_file_path); @@ -882,7 +882,7 @@ public: /// @return /// Returns an error object. //------------------------------------------------------------------ - virtual Error ConnectRemote(Stream *strm, const char *remote_url); + virtual Error ConnectRemote(Stream *strm, llvm::StringRef remote_url); bool GetShouldDetach() const { return m_should_detach; } @@ -1107,7 +1107,7 @@ public: /// @return /// Returns an error object. //------------------------------------------------------------------ - virtual Error DoConnectRemote(Stream *strm, const char *remote_url) { + virtual Error DoConnectRemote(Stream *strm, llvm::StringRef remote_url) { Error error; error.SetErrorString("remote connections are not supported"); return error; diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index d1a67ed..224af6f 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -512,7 +512,7 @@ public: void Dump(Stream *s, lldb::DescriptionLevel description_level); const lldb::ProcessSP &CreateProcess(lldb::ListenerSP listener, - const char *plugin_name, + llvm::StringRef plugin_name, const FileSpec *crash_file); const lldb::ProcessSP &GetProcessSP() const; diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index fa58e72..a620f6f 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -186,7 +186,7 @@ SBProcess SBTarget::LoadCore(const char *core_file) { if (target_sp) { FileSpec filespec(core_file, true); ProcessSP process_sp(target_sp->CreateProcess( - target_sp->GetDebugger().GetListener(), NULL, &filespec)); + target_sp->GetDebugger().GetListener(), "", &filespec)); if (process_sp) { process_sp->LoadCore(); sb_process.SetSP(process_sp); diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index a695589..d36adb4 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -377,7 +377,7 @@ protected: target_sp->GetExecutableSearchPaths().Append(core_file_dir); ProcessSP process_sp(target_sp->CreateProcess( - m_interpreter.GetDebugger().GetListener(), nullptr, + m_interpreter.GetDebugger().GetListener(), llvm::StringRef(), &core_file)); if (process_sp) { diff --git a/lldb/source/Core/ConnectionSharedMemory.cpp b/lldb/source/Core/ConnectionSharedMemory.cpp index 74487b0..05dec48 100644 --- a/lldb/source/Core/ConnectionSharedMemory.cpp +++ b/lldb/source/Core/ConnectionSharedMemory.cpp @@ -44,7 +44,7 @@ ConnectionSharedMemory::~ConnectionSharedMemory() { Disconnect(nullptr); } bool ConnectionSharedMemory::IsConnected() const { return m_fd >= 0; } -ConnectionStatus ConnectionSharedMemory::Connect(const char *s, +ConnectionStatus ConnectionSharedMemory::Connect(llvm::StringRef s, Error *error_ptr) { // if (s && s[0]) // { diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp index 1e65a1e..c1a6284 100644 --- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -68,12 +68,13 @@ const char *ConnectionFileDescriptor::FILE_SCHEME = "file"; namespace { -const char *GetURLAddress(const char *url, const char *scheme) { - const auto prefix = std::string(scheme) + "://"; - if (strstr(url, prefix.c_str()) != url) - return nullptr; - - return url + prefix.size(); +llvm::Optional GetURLAddress(llvm::StringRef url, + llvm::StringRef scheme) { + if (!url.consume_front(scheme)) + return llvm::None; + if (!url.consume_front("://")) + return llvm::None; + return url; } } @@ -153,48 +154,47 @@ bool ConnectionFileDescriptor::IsConnected() const { (m_write_sp && m_write_sp->IsValid()); } -ConnectionStatus ConnectionFileDescriptor::Connect(const char *s, +ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path, Error *error_ptr) { std::lock_guard guard(m_mutex); Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); if (log) log->Printf("%p ConnectionFileDescriptor::Connect (url = '%s')", - static_cast(this), s); + static_cast(this), path.str().c_str()); OpenCommandPipe(); - if (s && s[0]) { - const char *addr = nullptr; - if ((addr = GetURLAddress(s, LISTEN_SCHEME))) { + if (!path.empty()) { + llvm::Optional addr; + if ((addr = GetURLAddress(path, LISTEN_SCHEME))) { // listen://HOST:PORT - return SocketListenAndAccept(addr, error_ptr); - } else if ((addr = GetURLAddress(s, ACCEPT_SCHEME))) { + return SocketListenAndAccept(*addr, error_ptr); + } else if ((addr = GetURLAddress(path, ACCEPT_SCHEME))) { // unix://SOCKNAME - return NamedSocketAccept(addr, error_ptr); - } else if ((addr = GetURLAddress(s, UNIX_ACCEPT_SCHEME))) { + return NamedSocketAccept(*addr, error_ptr); + } else if ((addr = GetURLAddress(path, UNIX_ACCEPT_SCHEME))) { // unix://SOCKNAME - return NamedSocketAccept(addr, error_ptr); - } else if ((addr = GetURLAddress(s, CONNECT_SCHEME))) { - return ConnectTCP(addr, error_ptr); - } else if ((addr = GetURLAddress(s, TCP_CONNECT_SCHEME))) { - return ConnectTCP(addr, error_ptr); - } else if ((addr = GetURLAddress(s, UDP_SCHEME))) { - return ConnectUDP(addr, error_ptr); - } else if ((addr = GetURLAddress(s, UNIX_CONNECT_SCHEME))) { + return NamedSocketAccept(*addr, error_ptr); + } else if ((addr = GetURLAddress(path, CONNECT_SCHEME))) { + return ConnectTCP(*addr, error_ptr); + } else if ((addr = GetURLAddress(path, TCP_CONNECT_SCHEME))) { + return ConnectTCP(*addr, error_ptr); + } else if ((addr = GetURLAddress(path, UDP_SCHEME))) { + return ConnectUDP(*addr, error_ptr); + } else if ((addr = GetURLAddress(path, UNIX_CONNECT_SCHEME))) { // unix-connect://SOCKNAME - return NamedSocketConnect(addr, error_ptr); - } else if ((addr = GetURLAddress(s, UNIX_ABSTRACT_CONNECT_SCHEME))) { + return NamedSocketConnect(*addr, error_ptr); + } else if ((addr = GetURLAddress(path, UNIX_ABSTRACT_CONNECT_SCHEME))) { // unix-abstract-connect://SOCKNAME - return UnixAbstractSocketConnect(addr, error_ptr); + return UnixAbstractSocketConnect(*addr, error_ptr); } #ifndef LLDB_DISABLE_POSIX - else if ((addr = GetURLAddress(s, FD_SCHEME))) { + else if ((addr = GetURLAddress(path, FD_SCHEME))) { // Just passing a native file descriptor within this current process // that is already opened (possibly from a service or other source). - bool success = false; - int fd = StringConvert::ToSInt32(addr, -1, 0, &success); + int fd = -1; - if (success) { + if (!addr->getAsInteger(0, fd)) { // We have what looks to be a valid file descriptor, but we // should make sure it is. We currently are doing this by trying to // get the flags from the file descriptor and making sure it @@ -203,7 +203,8 @@ ConnectionStatus ConnectionFileDescriptor::Connect(const char *s, int flags = ::fcntl(fd, F_GETFL, 0); if (flags == -1 || errno == EBADF) { if (error_ptr) - error_ptr->SetErrorStringWithFormat("stale file descriptor: %s", s); + error_ptr->SetErrorStringWithFormat("stale file descriptor: %s", + path.str().c_str()); m_read_sp.reset(); m_write_sp.reset(); return eConnectionStatusError; @@ -232,23 +233,23 @@ ConnectionStatus ConnectionFileDescriptor::Connect(const char *s, m_read_sp.reset(new File(fd, false)); m_write_sp.reset(new File(fd, false)); } - m_uri.assign(addr); + m_uri = *addr; return eConnectionStatusSuccess; } } if (error_ptr) error_ptr->SetErrorStringWithFormat("invalid file descriptor: \"%s\"", - s); + path.str().c_str()); m_read_sp.reset(); m_write_sp.reset(); return eConnectionStatusError; - } else if ((addr = GetURLAddress(s, FILE_SCHEME))) { + } else if ((addr = GetURLAddress(path, FILE_SCHEME))) { + std::string addr_str = addr->str(); // file:///PATH - const char *path = addr; int fd = -1; do { - fd = ::open(path, O_RDWR); + fd = ::open(addr_str.c_str(), O_RDWR); } while (fd == -1 && errno == EINTR); if (fd == -1) { @@ -290,7 +291,7 @@ ConnectionStatus ConnectionFileDescriptor::Connect(const char *s, #endif if (error_ptr) error_ptr->SetErrorStringWithFormat("unsupported connection URL: '%s'", - s); + path.str().c_str()); return eConnectionStatusError; } if (error_ptr) @@ -655,7 +656,7 @@ ConnectionStatus ConnectionFileDescriptor::BytesAvailable(uint32_t timeout_usec, } ConnectionStatus -ConnectionFileDescriptor::NamedSocketAccept(const char *socket_name, +ConnectionFileDescriptor::NamedSocketAccept(llvm::StringRef socket_name, Error *error_ptr) { Socket *socket = nullptr; Error error = @@ -672,7 +673,7 @@ ConnectionFileDescriptor::NamedSocketAccept(const char *socket_name, } ConnectionStatus -ConnectionFileDescriptor::NamedSocketConnect(const char *socket_name, +ConnectionFileDescriptor::NamedSocketConnect(llvm::StringRef socket_name, Error *error_ptr) { Socket *socket = nullptr; Error error = @@ -689,7 +690,7 @@ ConnectionFileDescriptor::NamedSocketConnect(const char *socket_name, } lldb::ConnectionStatus -ConnectionFileDescriptor::UnixAbstractSocketConnect(const char *socket_name, +ConnectionFileDescriptor::UnixAbstractSocketConnect(llvm::StringRef socket_name, Error *error_ptr) { Socket *socket = nullptr; Error error = Socket::UnixAbstractConnect(socket_name, @@ -706,7 +707,7 @@ ConnectionFileDescriptor::UnixAbstractSocketConnect(const char *socket_name, } ConnectionStatus -ConnectionFileDescriptor::SocketListenAndAccept(const char *s, +ConnectionFileDescriptor::SocketListenAndAccept(llvm::StringRef s, Error *error_ptr) { m_port_predicate.SetValue(0, eBroadcastNever); @@ -734,7 +735,7 @@ ConnectionFileDescriptor::SocketListenAndAccept(const char *s, return eConnectionStatusSuccess; } -ConnectionStatus ConnectionFileDescriptor::ConnectTCP(const char *s, +ConnectionStatus ConnectionFileDescriptor::ConnectTCP(llvm::StringRef s, Error *error_ptr) { Socket *socket = nullptr; Error error = Socket::TcpConnect(s, m_child_processes_inherit, socket); @@ -749,7 +750,7 @@ ConnectionStatus ConnectionFileDescriptor::ConnectTCP(const char *s, return eConnectionStatusSuccess; } -ConnectionStatus ConnectionFileDescriptor::ConnectUDP(const char *s, +ConnectionStatus ConnectionFileDescriptor::ConnectUDP(llvm::StringRef s, Error *error_ptr) { Socket *send_socket = nullptr; Socket *recv_socket = nullptr; diff --git a/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp b/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp index 5a6637d..d13eb10 100644 --- a/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp +++ b/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp @@ -92,17 +92,17 @@ bool ConnectionGenericFile::IsConnected() const { return m_file && (m_file != INVALID_HANDLE_VALUE); } -lldb::ConnectionStatus ConnectionGenericFile::Connect(const char *s, +lldb::ConnectionStatus ConnectionGenericFile::Connect(llvm::StringRef path, Error *error_ptr) { Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); if (log) log->Printf("%p ConnectionGenericFile::Connect (url = '%s')", - static_cast(this), s); + static_cast(this), path.str().c_str()); - if (strstr(s, "file://") != s) { + if (!path.consume_front("file://")) { if (error_ptr) error_ptr->SetErrorStringWithFormat("unsupported connection URL: '%s'", - s); + path.str().c_str()); return eConnectionStatusError; } @@ -112,13 +112,10 @@ lldb::ConnectionStatus ConnectionGenericFile::Connect(const char *s, return status; } - // file://PATH - const char *path = s + strlen("file://"); // Open the file for overlapped access. If it does not exist, create it. We - // open it overlapped - // so that we can issue asynchronous reads and then use WaitForMultipleObjects - // to allow the read - // to be interrupted by an event object. + // open it overlapped so that we can issue asynchronous reads and then use + // WaitForMultipleObjects to allow the read to be interrupted by an event + // object. std::wstring wpath; if (!llvm::ConvertUTF8toWide(path, wpath)) { if (error_ptr) @@ -135,7 +132,7 @@ lldb::ConnectionStatus ConnectionGenericFile::Connect(const char *s, } m_owns_file = true; - m_uri.assign(s); + m_uri.assign(path); return eConnectionStatusSuccess; } diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp index 288accf..cabb3ff 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp @@ -203,7 +203,7 @@ Error PlatformAndroidRemoteGDBServer::MakeConnectURL( } lldb::ProcessSP PlatformAndroidRemoteGDBServer::ConnectProcess( - const char *connect_url, const char *plugin_name, + llvm::StringRef connect_url, llvm::StringRef plugin_name, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Error &error) { // We don't have the pid of the remote gdbserver when it isn't started by us @@ -216,7 +216,8 @@ lldb::ProcessSP PlatformAndroidRemoteGDBServer::ConnectProcess( int remote_port; llvm::StringRef scheme, host, path; if (!UriParser::Parse(connect_url, scheme, host, remote_port, path)) { - error.SetErrorStringWithFormat("Invalid URL: %s", connect_url); + error.SetErrorStringWithFormat("Invalid URL: %s", + connect_url.str().c_str()); return nullptr; } @@ -227,6 +228,6 @@ lldb::ProcessSP PlatformAndroidRemoteGDBServer::ConnectProcess( if (error.Fail()) return nullptr; - return PlatformRemoteGDBServer::ConnectProcess( - new_connect_url.c_str(), plugin_name, debugger, target, error); + return PlatformRemoteGDBServer::ConnectProcess(new_connect_url, plugin_name, + debugger, target, error); } diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h index f9593fa..6d5bfec 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h @@ -37,8 +37,8 @@ public: Error DisconnectRemote() override; - lldb::ProcessSP ConnectProcess(const char *connect_url, - const char *plugin_name, + lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, + llvm::StringRef plugin_name, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Error &error) override; diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp index 482e183..569a862 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -836,8 +836,8 @@ Error PlatformPOSIX::UnloadImage(lldb_private::Process *process, return Error(); } -lldb::ProcessSP PlatformPOSIX::ConnectProcess(const char *connect_url, - const char *plugin_name, +lldb::ProcessSP PlatformPOSIX::ConnectProcess(llvm::StringRef connect_url, + llvm::StringRef plugin_name, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Error &error) { diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h index 98df91b..93213b2 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h @@ -156,8 +156,8 @@ public: lldb_private::Error UnloadImage(lldb_private::Process *process, uint32_t image_token) override; - lldb::ProcessSP ConnectProcess(const char *connect_url, - const char *plugin_name, + lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, + llvm::StringRef plugin_name, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Error &error) override; diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index ccc7301..7962ca8 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -852,7 +852,7 @@ std::string PlatformRemoteGDBServer::MakeUrl(const char *scheme, } lldb::ProcessSP PlatformRemoteGDBServer::ConnectProcess( - const char *connect_url, const char *plugin_name, + llvm::StringRef connect_url, llvm::StringRef plugin_name, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Error &error) { if (!IsRemote() || !IsConnected()) { @@ -869,8 +869,7 @@ size_t PlatformRemoteGDBServer::ConnectToWaitingProcesses(Debugger &debugger, GetPendingGdbServerList(connection_urls); for (size_t i = 0; i < connection_urls.size(); ++i) { - ConnectProcess(connection_urls[i].c_str(), nullptr, debugger, nullptr, - error); + ConnectProcess(connection_urls[i].c_str(), "", debugger, nullptr, error); if (error.Fail()) return i; // We already connected to i process succsessfully } diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h index 6df3792..edc223a 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h @@ -162,8 +162,8 @@ public: const lldb::UnixSignalsSP &GetRemoteUnixSignals() override; - lldb::ProcessSP ConnectProcess(const char *connect_url, - const char *plugin_name, + lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, + llvm::StringRef plugin_name, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Error &error) override; diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 3761f06..876af4f 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -651,7 +651,8 @@ Error ProcessGDBRemote::WillAttachToProcessWithName(const char *process_name, return WillLaunchOrAttach(); } -Error ProcessGDBRemote::DoConnectRemote(Stream *strm, const char *remote_url) { +Error ProcessGDBRemote::DoConnectRemote(Stream *strm, + llvm::StringRef remote_url) { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); Error error(WillLaunchOrAttach()); @@ -695,15 +696,15 @@ Error ProcessGDBRemote::DoConnectRemote(Stream *strm, const char *remote_url) { if (state != eStateInvalid) { SetPrivateState(state); } else - error.SetErrorStringWithFormat("Process %" PRIu64 - " was reported after connecting to " - "'%s', but state was not stopped: %s", - pid, remote_url, StateAsCString(state)); + error.SetErrorStringWithFormat( + "Process %" PRIu64 " was reported after connecting to " + "'%s', but state was not stopped: %s", + pid, remote_url.str().c_str(), StateAsCString(state)); } else error.SetErrorStringWithFormat("Process %" PRIu64 " was reported after connecting to '%s', " "but no stop reply packet was received", - pid, remote_url); + pid, remote_url.str().c_str()); } if (log) @@ -963,15 +964,15 @@ Error ProcessGDBRemote::DoLaunch(Module *exe_module, return error; } -Error ProcessGDBRemote::ConnectToDebugserver(const char *connect_url) { +Error ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) { Error error; // Only connect if we have a valid connect URL Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); - if (connect_url && connect_url[0]) { + if (!connect_url.empty()) { if (log) log->Printf("ProcessGDBRemote::%s Connecting to %s", __FUNCTION__, - connect_url); + connect_url.str().c_str()); std::unique_ptr conn_ap( new ConnectionFileDescriptor()); if (conn_ap.get()) { @@ -3353,7 +3354,7 @@ Error ProcessGDBRemote::LaunchAndConnectToDebugserver( if (m_gdb_comm.IsConnected()) { // Finish the connection process by doing the handshake without connecting // (send NULL URL) - ConnectToDebugserver(NULL); + ConnectToDebugserver(""); } else { error.SetErrorString("connection failed"); } diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index d607d35..6423abc 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -89,7 +89,7 @@ public: Error WillAttachToProcessWithName(const char *process_name, bool wait_for_launch) override; - Error DoConnectRemote(Stream *strm, const char *remote_url) override; + Error DoConnectRemote(Stream *strm, llvm::StringRef remote_url) override; Error WillLaunchOrAttach(); @@ -379,7 +379,7 @@ protected: void DidLaunchOrAttach(ArchSpec &process_arch); - Error ConnectToDebugserver(const char *host_port); + Error ConnectToDebugserver(llvm::StringRef host_port); const char *GetDispatchQueueNameForThread(lldb::addr_t thread_dispatch_qaddr, std::string &dispatch_queue_name); diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 270400a..d25c3b2 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -1758,8 +1758,8 @@ Error Platform::UnloadImage(lldb_private::Process *process, return Error("UnloadImage is not supported on the current platform"); } -lldb::ProcessSP Platform::ConnectProcess(const char *connect_url, - const char *plugin_name, +lldb::ProcessSP Platform::ConnectProcess(llvm::StringRef connect_url, + llvm::StringRef plugin_name, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Error &error) { diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 2a61763..f5a5d47 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -662,14 +662,15 @@ void ProcessInstanceInfoMatch::Clear() { m_match_all_users = false; } -ProcessSP Process::FindPlugin(lldb::TargetSP target_sp, const char *plugin_name, +ProcessSP Process::FindPlugin(lldb::TargetSP target_sp, + llvm::StringRef plugin_name, ListenerSP listener_sp, const FileSpec *crash_file_path) { static uint32_t g_process_unique_id = 0; ProcessSP process_sp; ProcessCreateInstance create_callback = nullptr; - if (plugin_name) { + if (!plugin_name.empty()) { ConstString const_plugin_name(plugin_name); create_callback = PluginManager::GetProcessCreateCallbackForPluginName(const_plugin_name); @@ -3245,13 +3246,12 @@ void Process::CompleteAttach() { m_stop_info_override_callback = process_arch.GetStopInfoOverrideCallback(); } -Error Process::ConnectRemote(Stream *strm, const char *remote_url) { +Error Process::ConnectRemote(Stream *strm, llvm::StringRef remote_url) { m_abi_sp.reset(); m_process_input_reader.reset(); // Find the process and its architecture. Make sure it matches the - // architecture - // of the current Target, and if not adjust it. + // architecture of the current Target, and if not adjust it. Error error(DoConnectRemote(strm, remote_url)); if (error.Success()) { diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index fb43c40..e517d6c 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -170,7 +170,7 @@ void Target::DeleteCurrentProcess() { } const lldb::ProcessSP &Target::CreateProcess(ListenerSP listener_sp, - const char *plugin_name, + llvm::StringRef plugin_name, const FileSpec *crash_file) { DeleteCurrentProcess(); m_process_sp = Process::FindPlugin(shared_from_this(), plugin_name, -- 2.7.4