Skip to content

Commit ee11eac

Browse files
committed
[lldb] Fix crash when launching in terminal
This patch fixes a crash when using process launch -t to launch the inferior from a TTY. The issue is that on Darwin, Host.mm is calling ConnectionFileDescriptor::Connect without a socket_id_callback_type. The overload passes nullptr as the function ref, which gets called unconditionally as the socket_id_callback. One potential way to fix this is to change all the lambdas to include a null check, but instead I went with an empty lambda. Differential revision: https://reviews.llvm.org/D124535 (cherry picked from commit 9aa6a47)
1 parent 0b028d5 commit ee11eac

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ bool ConnectionFileDescriptor::IsConnected() const {
122122

123123
ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path,
124124
Status *error_ptr) {
125-
return Connect(path, nullptr, error_ptr);
125+
return Connect(
126+
path, [](llvm::StringRef) {}, error_ptr);
126127
}
127128

128129
ConnectionStatus

lldb/unittests/Host/ConnectionFileDescriptorTest.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,22 @@ class ConnectionFileDescriptorTest : public testing::Test {
2222
std::unique_ptr<TCPSocket> socket_a_up;
2323
std::unique_ptr<TCPSocket> socket_b_up;
2424
CreateTCPConnectedSockets(ip, &socket_a_up, &socket_b_up);
25-
auto socket = socket_a_up.release();
25+
auto *socket = socket_a_up.release();
2626
ConnectionFileDescriptor connection_file_descriptor(socket);
2727

2828
std::string uri(connection_file_descriptor.GetURI());
2929
EXPECT_EQ((URI{"connect", ip, socket->GetRemotePortNumber(), "/"}),
3030
URI::Parse(uri).value());
3131
}
32+
33+
void TestConnect(std::string ip, std::string path) {
34+
std::unique_ptr<TCPSocket> socket_a_up;
35+
std::unique_ptr<TCPSocket> socket_b_up;
36+
CreateTCPConnectedSockets(ip, &socket_a_up, &socket_b_up);
37+
auto *socket = socket_a_up.release();
38+
ConnectionFileDescriptor connection_file_descriptor(socket);
39+
connection_file_descriptor.Connect(path, nullptr);
40+
}
3241
};
3342

3443
TEST_F(ConnectionFileDescriptorTest, TCPGetURIv4) {
@@ -42,3 +51,15 @@ TEST_F(ConnectionFileDescriptorTest, TCPGetURIv6) {
4251
return;
4352
TestGetURI("::1");
4453
}
54+
55+
TEST_F(ConnectionFileDescriptorTest, Connectv4) {
56+
if (!HostSupportsIPv4())
57+
return;
58+
TestConnect("127.0.0.1", "accept://127.0.0.1");
59+
}
60+
61+
TEST_F(ConnectionFileDescriptorTest, Connectv6) {
62+
if (!HostSupportsIPv6())
63+
return;
64+
TestConnect("::1", "accept://::1");
65+
}

0 commit comments

Comments
 (0)