[lldb-dap] Make connection URLs match lldb - #144770
Merged
Merged
Conversation
Member
|
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesUse the same scheme as ConnectionFileDescriptor::Connect and use "listen" and "accept". Addresses feedback from a Pavel in a different PR [1]. Full diff: https://github.com/llvm/llvm-project/pull/144770.diff 5 Files Affected:
diff --git a/lldb/include/lldb/Host/Socket.h b/lldb/include/lldb/Host/Socket.h
index 4585eac12efb9..9af0e6f3fef08 100644
--- a/lldb/include/lldb/Host/Socket.h
+++ b/lldb/include/lldb/Host/Socket.h
@@ -74,6 +74,11 @@ class Socket : public IOObject {
ProtocolUnixAbstract
};
+ enum SocketMode {
+ ModeAccept,
+ ModeConnect,
+ };
+
struct HostAndPort {
std::string hostname;
uint16_t port;
@@ -83,6 +88,10 @@ class Socket : public IOObject {
}
};
+ using ProtocolModePair = std::pair<SocketProtocol, SocketMode>;
+ static llvm::Expected<ProtocolModePair>
+ GetProtocolAndMode(llvm::StringRef scheme);
+
static const NativeSocket kInvalidSocketValue;
~Socket() override;
diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp
index 76f74401ac4d0..373e700c490ab 100644
--- a/lldb/source/Host/common/Socket.cpp
+++ b/lldb/source/Host/common/Socket.cpp
@@ -476,3 +476,28 @@ llvm::raw_ostream &lldb_private::operator<<(llvm::raw_ostream &OS,
const Socket::HostAndPort &HP) {
return OS << '[' << HP.hostname << ']' << ':' << HP.port;
}
+
+llvm::Expected<Socket::ProtocolModePair>
+Socket::GetProtocolAndMode(llvm::StringRef scheme) {
+ // Keep in sync with ConnectionFileDescriptor::Connect.
+ return llvm::StringSwitch<llvm::Expected<ProtocolModePair>>(scheme)
+ .Case("listen", ProtocolModePair{SocketProtocol::ProtocolTcp,
+ SocketMode::ModeAccept})
+ .Cases("accept", "unix-accept",
+ ProtocolModePair{SocketProtocol::ProtocolUnixDomain,
+ SocketMode::ModeAccept})
+ .Case("unix-abstract-accept",
+ ProtocolModePair{SocketProtocol::ProtocolUnixAbstract,
+ SocketMode::ModeAccept})
+ .Cases("connect", "tcp-connect",
+ ProtocolModePair{SocketProtocol::ProtocolTcp,
+ SocketMode::ModeConnect})
+ .Case("udp", ProtocolModePair{SocketProtocol::ProtocolTcp,
+ SocketMode::ModeConnect})
+ .Case("unix-connect", ProtocolModePair{SocketProtocol::ProtocolUnixDomain,
+ SocketMode::ModeConnect})
+ .Case("unix-abstract-connect",
+ ProtocolModePair{SocketProtocol::ProtocolUnixAbstract,
+ SocketMode::ModeConnect})
+ .Default(llvm::createStringError("unsupported scheme"));
+}
diff --git a/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py b/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
index ed17044a220d4..592a4cfb0a88b 100644
--- a/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
+++ b/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
@@ -54,7 +54,7 @@ def test_server_port(self):
Test launching a binary with a lldb-dap in server mode on a specific port.
"""
self.build()
- (_, connection) = self.start_server(connection="tcp://localhost:0")
+ (_, connection) = self.start_server(connection="listen://localhost:0")
self.run_debug_session(connection, "Alice")
self.run_debug_session(connection, "Bob")
@@ -72,7 +72,7 @@ def cleanup():
self.addTearDownHook(cleanup)
self.build()
- (_, connection) = self.start_server(connection="unix://" + name)
+ (_, connection) = self.start_server(connection="accept://" + name)
self.run_debug_session(connection, "Alice")
self.run_debug_session(connection, "Bob")
@@ -82,7 +82,7 @@ def test_server_interrupt(self):
Test launching a binary with lldb-dap in server mode and shutting down the server while the debug session is still active.
"""
self.build()
- (process, connection) = self.start_server(connection="tcp://localhost:0")
+ (process, connection) = self.start_server(connection="listen://localhost:0")
self.dap_server = dap_server.DebugAdapterServer(
connection=connection,
)
diff --git a/lldb/tools/lldb-dap/Options.td b/lldb/tools/lldb-dap/Options.td
index aecf91797ac70..867753e9294a6 100644
--- a/lldb/tools/lldb-dap/Options.td
+++ b/lldb/tools/lldb-dap/Options.td
@@ -28,8 +28,8 @@ def connection
MetaVarName<"<connection>">,
HelpText<
"Communicate with the lldb-dap tool over the specified connection. "
- "Connections are specified like 'tcp://[host]:port' or "
- "'unix:///path'.">;
+ "Connections are specified like 'listen://[host]:port' or "
+ "'accept:///path'.">;
def launch_target: S<"launch-target">,
MetaVarName<"<target>">,
diff --git a/lldb/tools/lldb-dap/tool/lldb-dap.cpp b/lldb/tools/lldb-dap/tool/lldb-dap.cpp
index 9b9de5e21a742..026eaf946ddad 100644
--- a/lldb/tools/lldb-dap/tool/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/tool/lldb-dap.cpp
@@ -226,23 +226,34 @@ static llvm::Expected<std::pair<Socket::SocketProtocol, std::string>>
validateConnection(llvm::StringRef conn) {
auto uri = lldb_private::URI::Parse(conn);
- if (uri && (uri->scheme == "tcp" || uri->scheme == "connect" ||
- !uri->hostname.empty() || uri->port)) {
+ auto make_error = [conn]() -> llvm::Error {
+ return llvm::createStringError(
+ "Unsupported connection specifier, expected 'accept:///path' or "
+ "'listen://[host]:port', got '%s'.",
+ conn.str().c_str());
+ };
+
+ if (!uri)
+ return make_error();
+
+ llvm::Expected<Socket::ProtocolModePair> protocol_and_mode =
+ Socket::GetProtocolAndMode(uri->scheme);
+ if (!protocol_and_mode)
+ return protocol_and_mode.takeError();
+ if (protocol_and_mode->second != Socket::ModeAccept)
+ return make_error();
+
+ if (protocol_and_mode->first == Socket::ProtocolTcp) {
return std::make_pair(
Socket::ProtocolTcp,
formatv("[{0}]:{1}", uri->hostname.empty() ? "0.0.0.0" : uri->hostname,
uri->port.value_or(0)));
}
- if (uri && (uri->scheme == "unix" || uri->scheme == "unix-connect" ||
- uri->path != "/")) {
+ if (protocol_and_mode->first == Socket::ProtocolUnixDomain)
return std::make_pair(Socket::ProtocolUnixDomain, uri->path.str());
- }
- return llvm::createStringError(
- "Unsupported connection specifier, expected 'unix-connect:///path' or "
- "'connect://[host]:port', got '%s'.",
- conn.str().c_str());
+ return make_error();
}
static llvm::Error
|
Use the same scheme as ConnectionFileDescriptor::Connect and use "listen" and "accept". Addresses feedback from a Pavel in a different PR [1]. [1] llvm#143628 (comment)
JDevlieghere
force-pushed
the
lldb-dap-connect-scheme
branch
from
June 18, 2025 18:40
ef08bad to
adea12f
Compare
ashgti
reviewed
Jun 18, 2025
ashgti
approved these changes
Jun 18, 2025
JDevlieghere
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Jul 31, 2025
Use the same scheme as ConnectionFileDescriptor::Connect and use "listen" and "accept". Addresses feedback from a Pavel in a different PR [1]. [1] llvm#143628 (comment) (cherry picked from commit 4f991cc)
JDevlieghere
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Aug 19, 2025
Use the same scheme as ConnectionFileDescriptor::Connect and use "listen" and "accept". Addresses feedback from a Pavel in a different PR [1]. [1] llvm#143628 (comment) (cherry picked from commit 4f991cc)
imyixinw
pushed a commit
to imyixinw/llvm-project
that referenced
this pull request
Sep 5, 2025
Summary: The commit [[lldb-dap] Make connection URLs match lldb (llvm#144770)](llvm@4f991cc) **once again made intrusive and backward incompatible changes** on how to connect to lldb-dap. It changed "tcp" and "unix" to "listen" and "accept". So I put the necessary changes into this diff so we don't need to revert 2 diffs when we pull upstream. Test Plan: Made sure lldb-dap test passed for RL/Android ``` [wanyi@devvm24062.cln0 ~/fbsource]$ ek start [wanyi@devvm24062.cln0 ~/fbsource]$ export LLDB_INSTALL_FOLDER=/home/wanyi/llvm-sand/install/Prod/usr [wanyi@devvm24062.cln0 ~/fbsource]$ buck2 run fbcode//sand/tests/lldb_e2e:lldb_android_test ``` https://www.internalfb.com/buck2/1bd6429b-d915-4683-8435-959bdd39e66d ``` [wanyi@devvm24062.cln0 ~/llvm-sand]$ make DESTDIR=$PWD/install/Debug/usr BuildType=Debug toolchain ``` NOTE: Due to VSCode devmate restriction, we can only use this with lldb cli atm Then start the lldb cli ``` [wanyi@devvm24062.cln0 ~/llvm-sand]$ ./build/Debug/fbcode-x86_64/toolchain/bin/lldb (lldb) protocol-server start MCP tcp://localhost:4567 MCP server started with connection listeners: connection://[::1]:4567, connection://[127.0.0.1]:4567 (lldb) file ~/tmp/hello Current executable set to '/home/wanyi/tmp/hello' (x86_64). ``` {F1979695189} On your machine, create file `~/.devmate/mcp.json` with following content: ``` { "mcpServers": { "lldb": { "command": "/usr/bin/nc", "args": ["localhost", "4567"], "env": {} } } } ``` Then restart VSCode or reload window to make devmate init with the config above. From OUTPUT --> Metamate We can see the command being picked up {F1979687414} Open devmate prompt, we can ask devmate to set breakpoint at `main()` **(Notice I have already created a target in the cli)** {F1979687445} Rollback Plan: Reviewers: alexandreperez, #lldb_team, hyubo Reviewed By: alexandreperez Subscribers: pdepetro, #lldb_team Differential Revision: https://phabricator.intern.facebook.com/D77191008
youngd007
pushed a commit
to youngd007/llvm-project
that referenced
this pull request
Mar 13, 2026
Summary: WARNING: This diff is auto generated by rebaser while rebasing. The original diff is D77191008. Do NOT land before the entire stack is approved The commit [[lldb-dap] Make connection URLs match lldb (llvm#144770)](llvm@4f991cc) **once again made intrusive and backward incompatible changes** on how to connect to lldb-dap. It changed "tcp" and "unix" to "listen" and "accept". So I put the necessary changes into this diff so we don't need to revert 2 diffs when we pull upstream. Test Plan: Made sure lldb-dap test passed for RL/Android ``` [wanyi@devvm24062.cln0 ~/fbsource]$ ek start [wanyi@devvm24062.cln0 ~/fbsource]$ export LLDB_INSTALL_FOLDER=/home/wanyi/llvm-sand/install/Prod/usr [wanyi@devvm24062.cln0 ~/fbsource]$ buck2 run fbcode//sand/tests/lldb_e2e:lldb_android_test ``` https://www.internalfb.com/buck2/1bd6429b-d915-4683-8435-959bdd39e66d ``` [wanyi@devvm24062.cln0 ~/llvm-sand]$ make DESTDIR=$PWD/install/Debug/usr BuildType=Debug toolchain ``` NOTE: Due to VSCode devmate restriction, we can only use this with lldb cli atm Then start the lldb cli ``` [wanyi@devvm24062.cln0 ~/llvm-sand]$ ./build/Debug/fbcode-x86_64/toolchain/bin/lldb (lldb) protocol-server start MCP tcp://localhost:4567 MCP server started with connection listeners: connection://[::1]:4567, connection://[127.0.0.1]:4567 (lldb) file ~/tmp/hello Current executable set to '/home/wanyi/tmp/hello' (x86_64). ``` {F1979695189} On your machine, create file `~/.devmate/mcp.json` with following content: ``` { "mcpServers": { "lldb": { "command": "/usr/bin/nc", "args": ["localhost", "4567"], "env": {} } } } ``` Then restart VSCode or reload window to make devmate init with the config above. From OUTPUT --> Metamate We can see the command being picked up {F1979687414} Open devmate prompt, we can ask devmate to set breakpoint at `main()` **(Notice I have already created a target in the cli)** {F1979687445} Rollback Plan: Reviewers: royshi, wanyi, #lldb_team, hyubo, satyajanga, toyang Reviewed By: royshi Subscribers: pdepetro, #lldb_team Differential Revision: https://phabricator.intern.facebook.com/D87103357
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use the same scheme as ConnectionFileDescriptor::Connect and use "listen" and "accept". Addresses feedback from a Pavel in a different PR [1].
[1] #143628 (comment)