Hi apepper, sbest, clayborg,

Closing std handles (but without redirecting them) allows kernel to "reuse" 
0,1, 2 file handle ids for subsequent file handle open operations.
This issue may lead to junk data sent over TCP connection from lldb-gdbserver 
to lldb because stderr file handle might be assigned to the socket handle:

int fd = connection_up->GetReadObject()->GetWaitableHandle();
assert(fd == STDERR_FILENO);  // llgs doesn't crash on such assertion without 
this code change in.

By redirecting std handles to /dev/null we prevent OS from such std handles 
reuse.

http://reviews.llvm.org/D6105

Files:
  source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -863,11 +863,15 @@
             }
         } while (has_env_var);
 
-        // Close STDIN, STDOUT and STDERR. We might need to redirect them
-        // to "/dev/null" if we run into any problems.
+        // Close STDIN, STDOUT and STDERR.
         launch_info.AppendCloseFileAction (STDIN_FILENO);
         launch_info.AppendCloseFileAction (STDOUT_FILENO);
         launch_info.AppendCloseFileAction (STDERR_FILENO);
+
+        // Redirect STDIN, STDOUT and STDERR to "/dev/null".
+        launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
+        launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true);
+        launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true);
         
         error = Host::LaunchProcess(launch_info);
         
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to