<div dir="ltr">Hello,<div><br></div><div>This test doesn't work on OS X:<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><pre class="" style="white-space:pre-wrap;word-wrap:break-word;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);font-size:13px">======================================================================
FAIL: test_fd_leak_multitarget (TestFdLeak.AvoidsFdLeakTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/testuser/build/workspace/LLDB_master_release_OSX/llvm_master/tools/lldb/test/lldbtest.py", line 690, in wrapper
    func(*args, **kwargs)
  File "/Users/testuser/build/workspace/LLDB_master_release_OSX/llvm_master/tools/lldb/test/functionalities/avoids-fd-leak/TestFdLeak.py", line 52, in test_fd_leak_multitarget
    self.assertTrue(process1.GetState() == lldb.eStateStopped, "Process should have been stopped.")
AssertionError: False is not True : Process should have been stopped.
Config=x86_64-clang</pre></blockquote><div><br></div><div>Thanks,</div><div>Ilia </div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 9, 2015 at 2:37 PM, Pavel Labath <span dir="ltr"><<a href="mailto:labath@google.com" target="_blank">labath@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: labath<br>
Date: Mon Feb  9 05:37:56 2015<br>
New Revision: 228570<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=228570&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=228570&view=rev</a><br>
Log:<br>
Fix descriptor leak in multi-target debugging<br>
<br>
Summary:<br>
When debugging two targets concurrently, the pseude terminal master fd from the first one would<br>
leak into the second. This fixes the problem by setting O_CLOEXEC on the master fd. Test<br>
included.<br>
<br>
Reviewers: clayborg, vharron<br>
<br>
Subscribers: lldb-commits<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D7466" target="_blank">http://reviews.llvm.org/D7466</a><br>
<br>
Modified:<br>
    lldb/trunk/source/Utility/PseudoTerminal.cpp<br>
    lldb/trunk/test/functionalities/avoids-fd-leak/TestFdLeak.py<br>
<br>
Modified: lldb/trunk/source/Utility/PseudoTerminal.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/PseudoTerminal.cpp?rev=228570&r1=228569&r2=228570&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/PseudoTerminal.cpp?rev=228570&r1=228569&r2=228570&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Utility/PseudoTerminal.cpp (original)<br>
+++ lldb/trunk/source/Utility/PseudoTerminal.cpp Mon Feb  9 05:37:56 2015<br>
@@ -239,7 +239,7 @@ PseudoTerminal::Fork (char *error_str, s<br>
         error_str[0] = '\0';<br>
<br>
     pid_t pid = LLDB_INVALID_PROCESS_ID;<br>
-    if (OpenFirstAvailableMaster (O_RDWR, error_str, error_len))<br>
+    if (OpenFirstAvailableMaster (O_RDWR | O_CLOEXEC, error_str, error_len))<br>
     {<br>
         // Successfully opened our master pseudo terminal<br>
<br>
@@ -258,7 +258,8 @@ PseudoTerminal::Fork (char *error_str, s<br>
             if (OpenSlave (O_RDWR, error_str, error_len))<br>
             {<br>
                 // Successfully opened slave<br>
-                // We are done with the master in the child process so lets close it<br>
+<br>
+                // Master FD should have O_CLOEXEC set, but let's close it just in case...<br>
                 CloseMasterFileDescriptor ();<br>
<br>
 #if defined(TIOCSCTTY)<br>
<br>
Modified: lldb/trunk/test/functionalities/avoids-fd-leak/TestFdLeak.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/avoids-fd-leak/TestFdLeak.py?rev=228570&r1=228569&r2=228570&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/avoids-fd-leak/TestFdLeak.py?rev=228570&r1=228569&r2=228570&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/test/functionalities/avoids-fd-leak/TestFdLeak.py (original)<br>
+++ lldb/trunk/test/functionalities/avoids-fd-leak/TestFdLeak.py Mon Feb  9 05:37:56 2015<br>
@@ -36,6 +36,29 @@ class AvoidsFdLeakTestCase(TestBase):<br>
         self.assertTrue(process.GetExitStatus() == 0,<br>
                 "Process returned non-zero status. Were incorrect file descriptors passed?")<br>
<br>
+    @skipIfWindows # The check for descriptor leakage needs to be implemented differently here.<br>
+    def test_fd_leak_multitarget (self):<br>
+        self.buildDefault()<br>
+        exe = os.path.join (os.getcwd(), "a.out")<br>
+<br>
+        target = self.dbg.CreateTarget(exe)<br>
+<br>
+        listener = lldb.SBListener()<br>
+        error = lldb.SBError()<br>
+        process1 = target.Launch (listener, None, None, None, None, None,<br>
+                self.get_process_working_directory(), 0, True, # stop at entry<br>
+                error)<br>
+        self.assertTrue(process1, PROCESS_IS_VALID)<br>
+        self.assertTrue(process1.GetState() == lldb.eStateStopped, "Process should have been stopped.")<br>
+<br>
+        target2 = self.dbg.CreateTarget(exe)<br>
+        process2 = target2.LaunchSimple (None, None, self.get_process_working_directory())<br>
+        self.assertTrue(process2, PROCESS_IS_VALID)<br>
+<br>
+        self.assertTrue(process2.GetState() == lldb.eStateExited, "Process should have exited.")<br>
+        self.assertTrue(process2.GetExitStatus() == 0,<br>
+                "Process returned non-zero status. Were incorrect file descriptors passed?")<br>
+<br>
<br>
 if __name__ == '__main__':<br>
     import atexit<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br>
</blockquote></div><br></div>