@@ -1172,14 +1172,13 @@ def __init__(
11721172 )
11731173
11741174 if connection :
1175- print ("attempting connection" , connection )
1176- if connection .startswith ("unix://" ): # unix:///path
1175+ if connection .startswith ("unix-connect://" ): # unix-connect:///path
11771176 s = socket .socket (socket .AF_UNIX , socket .SOCK_STREAM )
1178- s .connect (connection .removeprefix ("unix://" ))
1179- elif connection .startswith ("tcp ://" ): # tcp ://host:port
1180- host , port = connection .removeprefix ("tcp ://" ).split (":" , 1 )
1177+ s .connect (connection .removeprefix ("unix-connect ://" ))
1178+ elif connection .startswith ("connection ://" ): # connection ://[ host] :port
1179+ host , port = connection .removeprefix ("connection ://" ).rsplit (":" , 1 )
11811180 # create_connection with try both ipv4 and ipv6.
1182- s = socket .create_connection ((host , int (port )))
1181+ s = socket .create_connection ((host . strip ( "[]" ) , int (port )))
11831182 else :
11841183 raise ValueError ("invalid connection: {}" .format (connection ))
11851184 DebugCommunication .__init__ (
@@ -1213,16 +1212,16 @@ def launch(
12131212 if log_file :
12141213 adaptor_env ["LLDBDAP_LOG" ] = log_file
12151214
1216- if os .uname ().sysname == "Darwin" :
1217- adaptor_env ["NSUnbufferedIO" ] = "YES"
1218-
12191215 args = [executable ]
1216+ bufsize = - 1
12201217 if connection :
1218+ bufsize = 0
12211219 args .append ("--connection" )
12221220 args .append (connection )
12231221
12241222 proc = subprocess .Popen (
12251223 args ,
1224+ bufsize = bufsize ,
12261225 stdin = subprocess .PIPE ,
12271226 stdout = subprocess .PIPE ,
12281227 stderr = sys .stdout ,
@@ -1233,29 +1232,20 @@ def launch(
12331232 # If a conneciton is specified, lldb-dap will print the listening
12341233 # address once the listener is made to stdout. The listener is
12351234 # formatted like `tcp://host:port` or `unix:///path`.
1236- with selectors .DefaultSelector () as sel :
1237- print ("Reading stdout for the listening connection" )
1238- os .set_blocking (proc .stdout .fileno (), False )
1239- stdout_key = sel .register (proc .stdout , selectors .EVENT_READ )
1240- rdy_fds = sel .select (timeout = 10.0 )
1241- for key , _ in rdy_fds :
1242- if key != stdout_key :
1243- continue
1244-
1245- outs = proc .stdout .read (1024 ).decode ()
1246- os .set_blocking (proc .stdout .fileno (), True )
1247- for line in outs .split ("\n " ):
1248- if not line .startswith ("Listening for: " ):
1249- continue
1250- # If the listener expanded into multiple addresses, use the first.
1251- connection = line .removeprefix ("Listening for: " ).split ("," )[0 ]
1252- print ("" )
1253- return proc , connection
1235+ expected_prefix = "Listening for: "
1236+ out = proc .stdout .readline ().decode ()
1237+ if not out .startswith (expected_prefix ):
12541238 proc .kill ()
12551239 raise ValueError (
1256- "lldb-dap started with a connection but failed to write the listening address to stdout."
1240+ "lldb-dap failed to print listening address, expected '{}', got '{}'" .format (
1241+ expected_prefix , out
1242+ )
12571243 )
12581244
1245+ # If the listener expanded into multiple addresses, use the first.
1246+ connection = out .removeprefix (expected_prefix ).rstrip ("\r \n " )
1247+ return proc , connection
1248+
12591249 return proc , None
12601250
12611251
0 commit comments