[Lldb-commits] [lldb] [lldb-dap] Refactoring lldb-dap port listening mode to allow multiple connections. (PR #116392)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 29 01:12:32 PST 2025
================
@@ -1167,21 +1168,61 @@ def __init__(
if log_file:
adaptor_env["LLDBDAP_LOG"] = log_file
+ args = [executable]
+
+ if connection is not None:
+ args.append("--connection")
+ args.append(connection)
+
self.process = subprocess.Popen(
- [executable],
+ args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=adaptor_env,
)
+
+ if connection is not None:
+ # If the process was also launched, parse the connection from the
+ # resolved connection. For example, if the connection
+ # `connection://localhost:0` was specified then the OS would pick a
+ # random port for listening and lldb-dap would print the listening
+ # port to stdout.
+ if self.process is not None:
+ # lldb-dap will print the listening address once the listener is
+ # made to stdout. The listener is formatted like
+ # `connection://host:port` or `unix-connection:///path`.
+ expected_prefix = "Listening for: "
+ out = self.process.stdout.readline().decode()
+ if not out.startswith(expected_prefix):
+ self.process.kill()
+ raise ValueError(
+ "lldb-dap failed to print listening address, expected '{}', got '{}'".format(
+ expected_prefix, out
+ )
+ )
+
+ # If the listener expanded into multiple addresses, use the first.
+ connection = (
+ out.removeprefix(expected_prefix).rstrip("\r\n").split(",", 1)[0]
+ )
+
+ if connection.startswith("unix-connect://"): # unix-connect:///path
----------------
labath wrote:
How about something like:
```suggestion
scheme, address = connection.split("://")
if connection == "unix-connect": # unix-connect:///path
# etc.
```
https://github.com/llvm/llvm-project/pull/116392
More information about the lldb-commits
mailing list