diff options
author | Michał Górny <mgorny@moritz.systems> | 2021-10-23 11:15:00 +0200 |
---|---|---|
committer | Michał Górny <mgorny@moritz.systems> | 2021-10-26 13:53:08 +0200 |
commit | 4373f3595f8e37f6183d9880ee5b4eb59cba3852 (patch) | |
tree | a5a18ae224257a8c71ccf667e461b428e56a96f7 /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | |
parent | 487f15603e7394658423ab0a0c9afd3d51cd068d (diff) | |
download | llvm-4373f3595f8e37f6183d9880ee5b4eb59cba3852.zip llvm-4373f3595f8e37f6183d9880ee5b4eb59cba3852.tar.gz llvm-4373f3595f8e37f6183d9880ee5b4eb59cba3852.tar.bz2 |
[lldb] [Host] Move port predicate-related logic to gdb-remote
Remove the port predicate from Socket and ConnectionFileDescriptor,
and move it to gdb-remote. It is specifically relevant to the threading
used inside gdb-remote and with the new port callback API, we can
reliably move it there. While at it, switch from the custom Predicate
to std::promise/std::future.
Differential Revision: https://reviews.llvm.org/D112357
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index ae2141d..4ce79da 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -893,8 +893,13 @@ GDBRemoteCommunication::ListenThread(lldb::thread_arg_t arg) { if (connection) { // Do the listen on another thread so we can continue on... - if (connection->Connect(comm->m_listen_url.c_str(), &error) != - eConnectionStatusSuccess) + if (connection->Connect( + comm->m_listen_url.c_str(), [comm](llvm::StringRef port_str) { + uint16_t port = 0; + llvm::to_integer(port_str, port, 10); + comm->m_port_promise.set_value(port); + }, + &error) != eConnectionStatusSuccess) comm->SetConnection(nullptr); } return {}; @@ -1056,10 +1061,12 @@ Status GDBRemoteCommunication::StartDebugserverProcess( return error; } - ConnectionFileDescriptor *connection = - (ConnectionFileDescriptor *)GetConnection(); // Wait for 10 seconds to resolve the bound port - uint16_t port_ = connection->GetListeningPort(std::chrono::seconds(10)); + std::future<uint16_t> port_future = m_port_promise.get_future(); + uint16_t port_ = port_future.wait_for(std::chrono::seconds(10)) == + std::future_status::ready + ? port_future.get() + : 0; if (port_ > 0) { char port_cstr[32]; snprintf(port_cstr, sizeof(port_cstr), "127.0.0.1:%i", port_); |