[Lldb-commits] [lldb] r152102 - in /lldb/trunk: include/lldb/Target/Process.h source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp source/Target/Process.cpp tools/debugserver/source/MacOSX/MachProcess.cpp

Greg Clayton gclayton at apple.com
Mon Mar 5 20:01:05 PST 2012


Author: gclayton
Date: Mon Mar  5 22:01:04 2012
New Revision: 152102

URL: http://llvm.org/viewvc/llvm-project?rev=152102&view=rev
Log:
<rdar://problem/10840355>

Fixed STDERR to not be opened as readable. Also cleaned up some of the code that implemented the file actions as some of the code was using the wrong variables, they now use the right ones (in for stdin, out for stdout, err for stderr).


Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=152102&r1=152101&r2=152102&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Mon Mar  5 22:01:04 2012
@@ -520,12 +520,12 @@
         m_monitor_callback_baton (NULL),
         m_monitor_signals (false)
     {
-        if (stderr_path)
+        if (stdin_path)
         {
             ProcessLaunchInfo::FileAction file_action;
             const bool read = true;
-            const bool write = true;
-            if (file_action.Open(STDERR_FILENO, stderr_path, read, write))
+            const bool write = false;
+            if (file_action.Open(STDIN_FILENO, stdin_path, read, write))
                 AppendFileAction (file_action);
         }
         if (stdout_path)
@@ -536,12 +536,12 @@
             if (file_action.Open(STDOUT_FILENO, stdout_path, read, write))
                 AppendFileAction (file_action);
         }
-        if (stdin_path)
+        if (stderr_path)
         {
             ProcessLaunchInfo::FileAction file_action;
-            const bool read = true;
-            const bool write = false;
-            if (file_action.Open(STDIN_FILENO, stdin_path, read, write))
+            const bool read = false;
+            const bool write = true;
+            if (file_action.Open(STDERR_FILENO, stderr_path, read, write))
                 AppendFileAction (file_action);
         }
         if (working_directory)

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=152102&r1=152101&r2=152102&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Mon Mar  5 22:01:04 2012
@@ -815,7 +815,7 @@
     std::string path;
     packet.GetHexByteString(path);
     const bool read = true;
-    const bool write = true;
+    const bool write = false;
     if (file_action.Open(STDERR_FILENO, path.c_str(), read, write))
     {
         m_process_launch_info.AppendFileAction(file_action);

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=152102&r1=152101&r2=152102&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon Mar  5 22:01:04 2012
@@ -259,9 +259,9 @@
     {
         if (m_flags.Test(eLaunchFlagDisableSTDIO))
         {
-            AppendSuppressFileAction (STDERR_FILENO, true , true );
-            AppendSuppressFileAction (STDIN_FILENO , true , false);
-            AppendSuppressFileAction (STDOUT_FILENO, false, true );
+            AppendSuppressFileAction (STDIN_FILENO , true, false);
+            AppendSuppressFileAction (STDOUT_FILENO, false, true);
+            AppendSuppressFileAction (STDERR_FILENO, false, true);
         }
         else
         {
@@ -274,9 +274,9 @@
             const char *err_path = NULL;
             if (target)
             {
-                in_path = target->GetStandardErrorPath();
-                out_path = target->GetStandardInputPath();
-                err_path = target->GetStandardOutputPath();
+                in_path = target->GetStandardInputPath();
+                out_path = target->GetStandardOutputPath();
+                err_path = target->GetStandardErrorPath();
             }
             
             if (default_to_use_pty && (!in_path && !out_path && !err_path))
@@ -288,13 +288,14 @@
             }
 
             if (in_path)
-                AppendOpenFileAction(STDERR_FILENO, in_path, true, true);
-
+                AppendOpenFileAction(STDIN_FILENO, in_path, true, false);
+            
             if (out_path)
-                AppendOpenFileAction(STDIN_FILENO, out_path, true, false);
+                AppendOpenFileAction(STDOUT_FILENO, out_path, false, true);
 
             if (err_path)
-                AppendOpenFileAction(STDOUT_FILENO, err_path, false, true);            
+                AppendOpenFileAction(STDERR_FILENO, err_path, false, true);
+
         }
     }
 }
@@ -518,30 +519,31 @@
             launch_info.GetFlags().Set (eLaunchFlagStopAtEntry); 
             break;
             
-        case 'e':   // STDERR for read + write
+        case 'i':   // STDIN for read only
             {   
                 ProcessLaunchInfo::FileAction action;
-                if (action.Open(STDERR_FILENO, option_arg, true, true))
+                if (action.Open (STDIN_FILENO, option_arg, true, false))
                     launch_info.AppendFileAction (action);
             }
             break;
             
-        case 'i':   // STDIN for read only
+        case 'o':   // Open STDOUT for write only
             {   
                 ProcessLaunchInfo::FileAction action;
-                if (action.Open(STDIN_FILENO, option_arg, true, false))
+                if (action.Open (STDOUT_FILENO, option_arg, false, true))
                     launch_info.AppendFileAction (action);
             }
             break;
-            
-        case 'o':   // Open STDOUT for write only
+
+        case 'e':   // STDERR for write only
             {   
                 ProcessLaunchInfo::FileAction action;
-                if (action.Open(STDOUT_FILENO, option_arg, false, true))
+                if (action.Open (STDERR_FILENO, option_arg, false, true))
                     launch_info.AppendFileAction (action);
             }
             break;
             
+
         case 'p':   // Process plug-in name
             launch_info.SetProcessPluginName (option_arg);    
             break;
@@ -549,11 +551,11 @@
         case 'n':   // Disable STDIO
             {
                 ProcessLaunchInfo::FileAction action;
-                if (action.Open(STDERR_FILENO, "/dev/null", true, true))
+                if (action.Open (STDIN_FILENO, "/dev/null", true, false))
                     launch_info.AppendFileAction (action);
-                if (action.Open(STDOUT_FILENO, "/dev/null", false, true))
+                if (action.Open (STDOUT_FILENO, "/dev/null", false, true))
                     launch_info.AppendFileAction (action);
-                if (action.Open(STDIN_FILENO, "/dev/null", true, false))
+                if (action.Open (STDERR_FILENO, "/dev/null", false, true))
                     launch_info.AppendFileAction (action);
             }
             break;

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=152102&r1=152101&r2=152102&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Mon Mar  5 22:01:04 2012
@@ -1723,7 +1723,7 @@
                 err.LogThreaded ("::posix_spawn_file_actions_addopen (&file_actions, filedes=STDOUT_FILENO, path=/dev/null)");
             
             err.SetError( ::posix_spawn_file_actions_addopen (&file_actions, STDERR_FILENO, "/dev/null", 
-                                                              O_RDWR | O_NOCTTY, 0), DNBError::POSIX);
+                                                              O_WRONLY | O_NOCTTY, 0), DNBError::POSIX);
             if (err.Fail() || DNBLogCheckLogBit (LOG_PROCESS))
                 err.LogThreaded ("::posix_spawn_file_actions_addopen (&file_actions, filedes=STDERR_FILENO, path=/dev/null)");
         }
@@ -1733,9 +1733,9 @@
             if (stdout_path == NULL) stdout_path = "/dev/null";
             if (stderr_path == NULL) stderr_path = "/dev/null";
             
-            int slave_fd_err = open (stderr_path, O_NOCTTY | O_CREAT | O_RDWR   , 0640);
-            int slave_fd_in  = open (stdin_path , O_NOCTTY | O_RDONLY);
-            int slave_fd_out = open (stdout_path, O_NOCTTY | O_CREAT | O_WRONLY , 0640);
+            const int slave_fd_in  = open (stdin_path , O_NOCTTY | O_RDONLY);
+            const int slave_fd_out = open (stdout_path, O_NOCTTY | O_CREAT | O_WRONLY , 0640);
+            const int slave_fd_err = open (stderr_path, O_NOCTTY | O_CREAT | O_WRONLY , 0640);
 
             err.SetError( ::posix_spawn_file_actions_adddup2(&file_actions, slave_fd_err, STDERR_FILENO), DNBError::POSIX);
             if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS))





More information about the lldb-commits mailing list