[llvm-branch-commits] [lldb] r196598 - Merging r196397:

Bill Wendling isanbard at gmail.com
Fri Dec 6 11:14:36 PST 2013


Author: void
Date: Fri Dec  6 13:14:36 2013
New Revision: 196598

URL: http://llvm.org/viewvc/llvm-project?rev=196598&view=rev
Log:
Merging r196397:
------------------------------------------------------------------------
r196397 | gclayton | 2013-12-04 10:53:50 -0800 (Wed, 04 Dec 2013) | 7 lines

Added a new directory type for the "bool Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)" function: ePathTypeLLDBTempSystemDir

This will get the temporary directory on the current system.

Removed a call to tmpnam() and replaced it with a call to mktemp() using a template that will be in the temp directory.


------------------------------------------------------------------------

Modified:
    lldb/branches/release_34/   (props changed)
    lldb/branches/release_34/include/lldb/lldb-private-enumerations.h
    lldb/branches/release_34/source/Host/common/Host.cpp

Propchange: lldb/branches/release_34/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Dec  6 13:14:36 2013
@@ -1 +1,2 @@
 /lldb/branches/apple/python-GIL:156467-162159
+/lldb/trunk:196397

Modified: lldb/branches/release_34/include/lldb/lldb-private-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/release_34/include/lldb/lldb-private-enumerations.h?rev=196598&r1=196597&r2=196598&view=diff
==============================================================================
--- lldb/branches/release_34/include/lldb/lldb-private-enumerations.h (original)
+++ lldb/branches/release_34/include/lldb/lldb-private-enumerations.h Fri Dec  6 13:14:36 2013
@@ -117,7 +117,9 @@ typedef enum PathType
     ePathTypeHeaderDir,             // Find LLDB header file directory
     ePathTypePythonDir,             // Find Python modules (PYTHONPATH) directory
     ePathTypeLLDBSystemPlugins,     // System plug-ins directory
-    ePathTypeLLDBUserPlugins        // User plug-ins directory
+    ePathTypeLLDBUserPlugins,       // User plug-ins directory
+    ePathTypeLLDBTempSystemDir      // The LLDB temp directory for this system
+
 } PathType;
 
 

Modified: lldb/branches/release_34/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/release_34/source/Host/common/Host.cpp?rev=196598&r1=196597&r2=196598&view=diff
==============================================================================
--- lldb/branches/release_34/source/Host/common/Host.cpp (original)
+++ lldb/branches/release_34/source/Host/common/Host.cpp Fri Dec  6 13:14:36 2013
@@ -13,6 +13,7 @@
 #include <errno.h>
 #include <limits.h>
 #include <sys/types.h>
+#include <unistd.h>
 #ifdef _WIN32
 #include "lldb/Host/windows/windows.h"
 #include <winsock2.h>
@@ -1201,6 +1202,29 @@ Host::GetLLDBPath (PathType path_type, F
             // TODO: where would user LLDB plug-ins be located on other systems?
             return false;
         }
+            
+    case ePathTypeLLDBTempSystemDir:
+        {
+            static ConstString g_lldb_tmp_dir;
+            if (!g_lldb_tmp_dir)
+            {
+                const char *tmpdir_cstr = getenv("TMPDIR");
+                if (tmpdir_cstr == NULL)
+                {
+                    tmpdir_cstr = getenv("TMP");
+                    if (tmpdir_cstr == NULL)
+                        tmpdir_cstr = getenv("TEMP");
+                }
+                if (tmpdir_cstr)
+                {
+                    g_lldb_tmp_dir.SetCString(tmpdir_cstr);
+                    if (log)
+                        log->Printf("Host::GetLLDBPath(ePathTypeLLDBTempSystemDir) => '%s'", g_lldb_tmp_dir.GetCString());
+                }
+            }
+            file_spec.GetDirectory() = g_lldb_tmp_dir;
+            return (bool)file_spec.GetDirectory();
+        }
     }
 
     return false;
@@ -1450,21 +1474,36 @@ Host::RunShellCommand (const char *comma
     
     if (working_dir)
         launch_info.SetWorkingDirectory(working_dir);
-    char output_file_path_buffer[L_tmpnam];
+    char output_file_path_buffer[PATH_MAX];
     const char *output_file_path = NULL;
+    
     if (command_output_ptr)
     {
         // Create a temporary file to get the stdout/stderr and redirect the
         // output of the command into this file. We will later read this file
         // if all goes well and fill the data into "command_output_ptr"
-        output_file_path = ::tmpnam(output_file_path_buffer);
-        launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
+        FileSpec tmpdir_file_spec;
+        if (Host::GetLLDBPath (ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
+        {
+            tmpdir_file_spec.GetFilename().SetCString("lldb-shell-output.XXXXXX");
+            strncpy(output_file_path_buffer, tmpdir_file_spec.GetPath().c_str(), sizeof(output_file_path_buffer));
+        }
+        else
+        {
+            strncpy(output_file_path_buffer, "/tmp/lldb-shell-output.XXXXXX", sizeof(output_file_path_buffer));
+        }
+        
+        output_file_path = ::mktemp(output_file_path_buffer);
+    }
+    
+    launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
+    if (output_file_path)
+    {
         launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_path, false, true);
         launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO);
     }
     else
     {
-        launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
         launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true);
         launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true);
     }





More information about the llvm-branch-commits mailing list