apolyakov added inline comments.

================
Comment at: lit/tools/lldb-mi/target/inputs/target-select-so-path.py:8-11
+def get_free_port():
+    s = socket.socket()
+    s.bind(('', 0))
+    return s.getsockname()[1]
----------------
labath wrote:
> apolyakov wrote:
> > labath wrote:
> > > This is still racy, because the port can be snatched from under you 
> > > between the time you get the free port and the time when lldb-server 
> > > binds to it.  If this was the only test doing it then it might be fine, 
> > > but since this is going to be running concurrently with other tests, all 
> > > of which are fetching free ports, the chances of that happening add up.
> > > 
> > > (Also, binding to the wildcard address will trigger a firewall popup on 
> > > some machines.)
> > There is a problem with getting port from lldb-server. If we run 
> > `lldb-server gdbserver --pipe 0 ocalhost:0`, it'll print port number to its 
> > stdout, but we can't get it using pipes since to do this we need to wait 
> > until lldb-server finishes that isn't what we want.
> Aha, I see. lldb-server does not really expect you to pass std file 
> descriptor as the --pipe argument. Normally you would create a separate fd 
> and pass that instead. Doing that from python is a bit icky, but doable:
> ```
> (r, w) = os.pipe()
> kwargs = {}
> if sys.version_info >= (3,0):
>   kwargs["pass_fds"] = [w]
> llgs = subprocess.Popen(["lldb-server", "gdbserver", "--pipe", str(w), ...], 
> **kwargs)
> port_bytes = os.read(r, 10)
> port = int(port_bytes.decode("utf-8").strip('\x00'))
> ```
> 
> Alternatively, we could modify lldb-server to print the port number to stdout 
> in addition to any --pipe arguments (sounds like a good addition anyway, as 
> it enables easy free port selection for a shell user), and then you can sniff 
> that text from here.
`--pipe 0` prints port number exactly to stdout, so there will not be a 
difference for us. It's not so simple to get port from lldb-server's stdout in 
python, so I don't think it will save us.


https://reviews.llvm.org/D49739



_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to