[Lldb-commits] [lldb] r250331 - Make uses of /dev/null portable across OSes.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 14 14:37:36 PDT 2015


Author: zturner
Date: Wed Oct 14 16:37:36 2015
New Revision: 250331

URL: http://llvm.org/viewvc/llvm-project?rev=250331&view=rev
Log:
Make uses of /dev/null portable across OSes.

Most platforms have "/dev/null".  Windows has "nul".  Instead of
hardcoding the string /dev/null at various places, make a constant
that contains the correct value depending on the platform, and use
that everywhere instead.

Modified:
    lldb/trunk/include/lldb/Host/FileSystem.h
    lldb/trunk/source/Host/posix/FileSystem.cpp
    lldb/trunk/source/Host/windows/FileSystem.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/source/Target/ProcessLaunchInfo.cpp

Modified: lldb/trunk/include/lldb/Host/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=250331&r1=250330&r2=250331&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)
+++ lldb/trunk/include/lldb/Host/FileSystem.h Wed Oct 14 16:37:36 2015
@@ -22,6 +22,8 @@ namespace lldb_private
 class FileSystem
 {
   public:
+    static const char *DEV_NULL;
+
     static FileSpec::PathSyntax GetNativePathSyntax();
 
     static Error MakeDirectory(const FileSpec &file_spec, uint32_t mode);

Modified: lldb/trunk/source/Host/posix/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/FileSystem.cpp?rev=250331&r1=250330&r2=250331&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/posix/FileSystem.cpp Wed Oct 14 16:37:36 2015
@@ -32,6 +32,9 @@
 using namespace lldb;
 using namespace lldb_private;
 
+const char *
+FileSystem::DEV_NULL = "/dev/null";
+
 FileSpec::PathSyntax
 FileSystem::GetNativePathSyntax()
 {

Modified: lldb/trunk/source/Host/windows/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/FileSystem.cpp?rev=250331&r1=250330&r2=250331&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/windows/FileSystem.cpp Wed Oct 14 16:37:36 2015
@@ -19,6 +19,9 @@
 
 using namespace lldb_private;
 
+const char *
+FileSystem::DEV_NULL = "nul";
+
 FileSpec::PathSyntax
 FileSystem::GetNativePathSyntax()
 {

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=250331&r1=250330&r2=250331&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Wed Oct 14 16:37:36 2015
@@ -40,6 +40,7 @@
 #include "lldb/Core/Timer.h"
 #include "lldb/Core/Value.h"
 #include "lldb/DataFormatters/FormatManager.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostThread.h"
 #include "lldb/Host/StringConvert.h"
 #include "lldb/Host/Symbols.h"
@@ -1004,11 +1005,11 @@ ProcessGDBRemote::DoLaunch (Module *exe_
             {
                 // set to /dev/null unless redirected to a file above
                 if (!stdin_file_spec)
-                    stdin_file_spec.SetFile("/dev/null", false);
+                    stdin_file_spec.SetFile(FileSystem::DEV_NULL, false);
                 if (!stdout_file_spec)
-                    stdout_file_spec.SetFile("/dev/null", false);
+                    stdout_file_spec.SetFile(FileSystem::DEV_NULL, false);
                 if (!stderr_file_spec)
-                    stderr_file_spec.SetFile("/dev/null", false);
+                    stderr_file_spec.SetFile(FileSystem::DEV_NULL, false);
             }
             else if (platform_sp && platform_sp->IsHost())
             {

Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp?rev=250331&r1=250330&r2=250331&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp Wed Oct 14 16:37:36 2015
@@ -34,6 +34,7 @@
 #include "lldb/Core/ValueObject.h"
 #include "lldb/DataFormatters/TypeSummary.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Host/Pipe.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
@@ -809,9 +810,9 @@ ScriptInterpreterPython::ExecuteOneLine
         else
         {
             input_file_sp.reset (new StreamFile ());
-            input_file_sp->GetFile().Open("/dev/null", File::eOpenOptionRead);
+            input_file_sp->GetFile().Open(FileSystem::DEV_NULL, File::eOpenOptionRead);
             output_file_sp.reset (new StreamFile ());
-            output_file_sp->GetFile().Open("/dev/null", File::eOpenOptionWrite);
+            output_file_sp->GetFile().Open(FileSystem::DEV_NULL, File::eOpenOptionWrite);
             error_file_sp = output_file_sp;
         }
 

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=250331&r1=250330&r2=250331&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed Oct 14 16:37:36 2015
@@ -21,6 +21,7 @@
 #include "lldb/Expression/UserExpression.h"
 #include "lldb/Expression/IRDynamicChecks.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Host/Pipe.h"
@@ -478,7 +479,7 @@ ProcessLaunchCommandOptions::SetOptionVa
         case 'n':   // Disable STDIO
         {
             FileAction action;
-            const FileSpec dev_null{"/dev/null", false};
+            const FileSpec dev_null{FileSystem::DEV_NULL, false};
             if (action.Open(STDIN_FILENO, dev_null, true, false))
                 launch_info.AppendFileAction (action);
             if (action.Open(STDOUT_FILENO, dev_null, false, true))

Modified: lldb/trunk/source/Target/ProcessLaunchInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ProcessLaunchInfo.cpp?rev=250331&r1=250330&r2=250331&view=diff
==============================================================================
--- lldb/trunk/source/Target/ProcessLaunchInfo.cpp (original)
+++ lldb/trunk/source/Target/ProcessLaunchInfo.cpp Wed Oct 14 16:37:36 2015
@@ -11,6 +11,7 @@
 
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/Log.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Target/ProcessLaunchInfo.h"
 #include "lldb/Target/FileAction.h"
 #include "lldb/Target/Target.h"
@@ -129,7 +130,7 @@ bool
 ProcessLaunchInfo::AppendSuppressFileAction (int fd, bool read, bool write)
 {
     FileAction file_action;
-    if (file_action.Open(fd, FileSpec{"/dev/null", false}, read, write))
+    if (file_action.Open(fd, FileSpec{FileSystem::DEV_NULL, false}, read, write))
     {
         AppendFileAction (file_action);
         return true;




More information about the lldb-commits mailing list