aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests/Host/SocketTest.cpp
diff options
context:
space:
mode:
authorAntonio Afonso <antonio.afonso@gmail.com>2019-05-28 23:26:32 +0000
committerAntonio Afonso <antonio.afonso@gmail.com>2019-05-28 23:26:32 +0000
commit3da8e5f92073519133086b0c2c972ba028819539 (patch)
tree391d02bd07aef08a6fd9e011cfa247d47cd07c4b /lldb/unittests/Host/SocketTest.cpp
parent902f649217efcf51ac852216ac9be54fccc3a9dc (diff)
downloadllvm-3da8e5f92073519133086b0c2c972ba028819539.zip
llvm-3da8e5f92073519133086b0c2c972ba028819539.tar.gz
llvm-3da8e5f92073519133086b0c2c972ba028819539.tar.bz2
Fix IPv6 support on lldb-server platform
Summary: This is a general fix for the ConnectionFileDescriptor class but my main motivation was to make lldb-server working with IPv6. The connect URI can use square brackets ([]) to wrap the interface part of the URI (e.g.: <scheme>://[<interface>]:<port>). For IPv6 addresses this is a must since its ip can include colons and it will overlap with the port colon otherwise. The URIParser class parses the square brackets correctly but the ConnectionFileDescriptor doesn't generate them for IPv6 addresses making it impossible to connect to the gdb server when using this protocol. How to reproduce the issue: ``` $ lldb-server p --server --listen [::1]:8080 ... $ lldb (lldb) platform select remote-macosx (lldb) platform connect connect://[::1]:8080 (lldb) platform process -p <pid> error: unable to launch a GDB server on 'computer' ``` The server was actually launched we were just not able to connect to it. With this fix lldb will correctly connect. I fixed this by wrapping the ip portion with []. Reviewers: labath Reviewed By: labath Subscribers: xiaobai, mgorny, jfb, lldb-commits, labath Tags: #lldb Differential Revision: https://reviews.llvm.org/D61833 llvm-svn: 361898
Diffstat (limited to 'lldb/unittests/Host/SocketTest.cpp')
-rw-r--r--lldb/unittests/Host/SocketTest.cpp94
1 files changed, 8 insertions, 86 deletions
diff --git a/lldb/unittests/Host/SocketTest.cpp b/lldb/unittests/Host/SocketTest.cpp
index 1192fa6..26a8bd7 100644
--- a/lldb/unittests/Host/SocketTest.cpp
+++ b/lldb/unittests/Host/SocketTest.cpp
@@ -6,24 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include <cstdio>
-#include <functional>
-#include <thread>
-
+#include "SocketTestUtilities.h"
#include "gtest/gtest.h"
-#include "lldb/Host/Config.h"
-#include "lldb/Host/Socket.h"
-#include "lldb/Host/common/TCPSocket.h"
-#include "lldb/Host/common/UDPSocket.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Testing/Support/Error.h"
-
-#ifndef LLDB_DISABLE_POSIX
-#include "lldb/Host/posix/DomainSocket.h"
-#endif
-
using namespace lldb_private;
class SocketTest : public testing::Test {
@@ -33,55 +18,6 @@ public:
}
void TearDown() override { Socket::Terminate(); }
-
-protected:
- static void AcceptThread(Socket *listen_socket,
- bool child_processes_inherit, Socket **accept_socket,
- Status *error) {
- *error = listen_socket->Accept(*accept_socket);
- }
-
- template <typename SocketType>
- void CreateConnectedSockets(
- llvm::StringRef listen_remote_address,
- const std::function<std::string(const SocketType &)> &get_connect_addr,
- std::unique_ptr<SocketType> *a_up, std::unique_ptr<SocketType> *b_up) {
- bool child_processes_inherit = false;
- Status error;
- std::unique_ptr<SocketType> listen_socket_up(
- new SocketType(true, child_processes_inherit));
- EXPECT_FALSE(error.Fail());
- error = listen_socket_up->Listen(listen_remote_address, 5);
- EXPECT_FALSE(error.Fail());
- EXPECT_TRUE(listen_socket_up->IsValid());
-
- Status accept_error;
- Socket *accept_socket;
- std::thread accept_thread(AcceptThread, listen_socket_up.get(),
- child_processes_inherit, &accept_socket,
- &accept_error);
-
- std::string connect_remote_address = get_connect_addr(*listen_socket_up);
- std::unique_ptr<SocketType> connect_socket_up(
- new SocketType(true, child_processes_inherit));
- EXPECT_FALSE(error.Fail());
- error = connect_socket_up->Connect(connect_remote_address);
- EXPECT_FALSE(error.Fail());
- EXPECT_TRUE(connect_socket_up->IsValid());
-
- a_up->swap(connect_socket_up);
- EXPECT_TRUE(error.Success());
- EXPECT_NE(nullptr, a_up->get());
- EXPECT_TRUE((*a_up)->IsValid());
-
- accept_thread.join();
- b_up->reset(static_cast<SocketType *>(accept_socket));
- EXPECT_TRUE(accept_error.Success());
- EXPECT_NE(nullptr, b_up->get());
- EXPECT_TRUE((*b_up)->IsValid());
-
- listen_socket_up.reset();
- }
};
TEST_F(SocketTest, DecodeHostAndPort) {
@@ -159,38 +95,24 @@ TEST_F(SocketTest, DomainListenConnectAccept) {
std::unique_ptr<DomainSocket> socket_a_up;
std::unique_ptr<DomainSocket> socket_b_up;
- CreateConnectedSockets<DomainSocket>(
- Path, [=](const DomainSocket &) { return Path.str().str(); },
- &socket_a_up, &socket_b_up);
+ CreateDomainConnectedSockets(Path, &socket_a_up, &socket_b_up);
}
#endif
TEST_F(SocketTest, TCPListen0ConnectAccept) {
std::unique_ptr<TCPSocket> socket_a_up;
std::unique_ptr<TCPSocket> socket_b_up;
- CreateConnectedSockets<TCPSocket>(
- "127.0.0.1:0",
- [=](const TCPSocket &s) {
- char connect_remote_address[64];
- snprintf(connect_remote_address, sizeof(connect_remote_address),
- "127.0.0.1:%u", s.GetLocalPortNumber());
- return std::string(connect_remote_address);
- },
- &socket_a_up, &socket_b_up);
+ CreateTCPConnectedSockets("127.0.0.1", &socket_a_up, &socket_b_up);
}
TEST_F(SocketTest, TCPGetAddress) {
std::unique_ptr<TCPSocket> socket_a_up;
std::unique_ptr<TCPSocket> socket_b_up;
- CreateConnectedSockets<TCPSocket>(
- "127.0.0.1:0",
- [=](const TCPSocket &s) {
- char connect_remote_address[64];
- snprintf(connect_remote_address, sizeof(connect_remote_address),
- "127.0.0.1:%u", s.GetLocalPortNumber());
- return std::string(connect_remote_address);
- },
- &socket_a_up, &socket_b_up);
+ if (!IsAddressFamilySupported("127.0.0.1")) {
+ GTEST_LOG_(WARNING) << "Skipping test due to missing IPv4 support.";
+ return;
+ }
+ CreateTCPConnectedSockets("127.0.0.1", &socket_a_up, &socket_b_up);
EXPECT_EQ(socket_a_up->GetLocalPortNumber(),
socket_b_up->GetRemotePortNumber());