Skip to content

Commit 9aa6a47

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
1 parent 4a31af8 commit 9aa6a47

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
@@ -23,13 +23,22 @@ class ConnectionFileDescriptorTest : public testing::Test {
2323
std::unique_ptr<TCPSocket> socket_a_up;
2424
std::unique_ptr<TCPSocket> socket_b_up;
2525
CreateTCPConnectedSockets(ip, &socket_a_up, &socket_b_up);
26-
auto socket = socket_a_up.release();
26+
auto *socket = socket_a_up.release();
2727
ConnectionFileDescriptor connection_file_descriptor(socket);
2828

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

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

0 commit comments

Comments
 (0)