@@ -1172,14 +1172,13 @@ def __init__(
1172
1172
)
1173
1173
1174
1174
if connection :
1175
- print ("attempting connection" , connection )
1176
- if connection .startswith ("unix://" ): # unix:///path
1175
+ if connection .startswith ("unix-connect://" ): # unix-connect:///path
1177
1176
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 )
1181
1180
# 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 )))
1183
1182
else :
1184
1183
raise ValueError ("invalid connection: {}" .format (connection ))
1185
1184
DebugCommunication .__init__ (
@@ -1213,16 +1212,16 @@ def launch(
1213
1212
if log_file :
1214
1213
adaptor_env ["LLDBDAP_LOG" ] = log_file
1215
1214
1216
- if os .uname ().sysname == "Darwin" :
1217
- adaptor_env ["NSUnbufferedIO" ] = "YES"
1218
-
1219
1215
args = [executable ]
1216
+ bufsize = - 1
1220
1217
if connection :
1218
+ bufsize = 0
1221
1219
args .append ("--connection" )
1222
1220
args .append (connection )
1223
1221
1224
1222
proc = subprocess .Popen (
1225
1223
args ,
1224
+ bufsize = bufsize ,
1226
1225
stdin = subprocess .PIPE ,
1227
1226
stdout = subprocess .PIPE ,
1228
1227
stderr = sys .stdout ,
@@ -1233,29 +1232,20 @@ def launch(
1233
1232
# If a conneciton is specified, lldb-dap will print the listening
1234
1233
# address once the listener is made to stdout. The listener is
1235
1234
# 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 ):
1254
1238
proc .kill ()
1255
1239
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
+ )
1257
1243
)
1258
1244
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
+
1259
1249
return proc , None
1260
1250
1261
1251
0 commit comments