I'm using lldb as a lib and I need to redirect inferior stdin/out/err to my own 
pts. 
However, I find that, if the path matches with "/dev/pts/", it will be changed 
to NULL.
One workaround is to make symbolic link sto my dev/pts/x to bypass the problem. 

The attached patch provides a fix for the issue.

http://reviews.llvm.org/D5135

Files:
  source/Plugins/Process/POSIX/ProcessPOSIX.cpp
  source/Plugins/Process/POSIX/ProcessPOSIX.h
Index: source/Plugins/Process/POSIX/ProcessPOSIX.cpp
===================================================================
--- source/Plugins/Process/POSIX/ProcessPOSIX.cpp
+++ source/Plugins/Process/POSIX/ProcessPOSIX.cpp
@@ -176,9 +176,9 @@
 }
 
 const char *
-ProcessPOSIX::GetFilePath(const lldb_private::FileAction *file_action, const char *default_path)
+ProcessPOSIX::GetFilePath(const lldb_private::FileAction *file_action, const char *default_path,
+                          const char *dbg_pts_path)
 {
-    const char *pts_name = "/dev/pts/";
     const char *path = NULL;
 
     if (file_action)
@@ -190,11 +190,11 @@
             // (/dev/pts). If so, convert to using a different default path
             // instead to redirect I/O to the debugger console. This should
             //  also handle user overrides to /dev/null or a different file.
-            if (!path || ::strncmp(path, pts_name, ::strlen(pts_name)) == 0)
+            if (!path || (dbg_pts_path &&
+                          ::strncmp(path, dbg_pts_path, ::strlen(dbg_pts_path))) == 0)
                 path = default_path;
         }
     }
-
     return path;
 }
 
@@ -224,14 +224,16 @@
     const char *stdout_path = NULL;
     const char *stderr_path = NULL;
 
+    const char * dbg_pts_path = launch_info.GetPTY().GetSlaveName(NULL,0);
+
     file_action = launch_info.GetFileActionForFD (STDIN_FILENO);
-    stdin_path = GetFilePath(file_action, stdin_path);
+    stdin_path = GetFilePath(file_action, stdin_path, dbg_pts_path);
 
     file_action = launch_info.GetFileActionForFD (STDOUT_FILENO);
-    stdout_path = GetFilePath(file_action, stdout_path);
+    stdout_path = GetFilePath(file_action, stdout_path, dbg_pts_path);
 
     file_action = launch_info.GetFileActionForFD (STDERR_FILENO);
-    stderr_path = GetFilePath(file_action, stderr_path);
+    stderr_path = GetFilePath(file_action, stderr_path, dbg_pts_path);
 
     m_monitor = new ProcessMonitor (this, 
                                     module,
Index: source/Plugins/Process/POSIX/ProcessPOSIX.h
===================================================================
--- source/Plugins/Process/POSIX/ProcessPOSIX.h
+++ source/Plugins/Process/POSIX/ProcessPOSIX.h
@@ -157,7 +157,8 @@
     lldb_private::UnixSignals &
     GetUnixSignals();
 
-    const char *GetFilePath(const lldb_private::FileAction *file_action, const char *default_path);
+    const char *GetFilePath(const lldb_private::FileAction *file_action, const char *default_path,
+                            const char *dbg_pts_path);
 
     /// Stops all threads in the process.
     /// The \p stop_tid parameter indicates the thread which initiated the stop.
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to