[Lldb-commits] [lldb] [lldb-dap] Refactoring lldb-dap port listening mode to allow multiple connections. (PR #116392)
John Harrison via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 26 15:08:28 PST 2024
================
@@ -1196,6 +1202,62 @@ def terminate(self):
self.process.wait()
self.process = None
+ @classmethod
+ def launch(
+ cls, executable: str, /, connection=None, log_file=None, env=None
+ ) -> tuple[subprocess.Popen, str]:
+ adaptor_env = os.environ.copy()
+ if env:
+ adaptor_env.update(env)
+
+ if log_file:
+ adaptor_env["LLDBDAP_LOG"] = log_file
+
+ if os.uname().sysname == "Darwin":
+ adaptor_env["NSUnbufferedIO"] = "YES"
+
+ args = [executable]
+ if connection:
+ args.append("--connection")
+ args.append(connection)
+
+ proc = subprocess.Popen(
+ args,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=sys.stdout,
+ env=adaptor_env,
+ )
+
+ if connection:
+ # If a conneciton is specified, lldb-dap will print the listening
+ # address once the listener is made to stdout. The listener is
+ # formatted like `tcp://host:port` or `unix:///path`.
+ with selectors.DefaultSelector() as sel:
+ print("Reading stdout for the listening connection")
+ os.set_blocking(proc.stdout.fileno(), False)
+ stdout_key = sel.register(proc.stdout, selectors.EVENT_READ)
+ rdy_fds = sel.select(timeout=10.0)
----------------
ashgti wrote:
I refactored this to not use a select and instead adjusted the script to not buffer when using a connection. This lets us read a single line at a time without reaching EOF first.
https://github.com/llvm/llvm-project/pull/116392
More information about the lldb-commits
mailing list