[Lldb-commits] [lldb] r214093 - Use llvm Support functions to get the user's home directory.

Zachary Turner zturner at google.com
Mon Jul 28 09:45:06 PDT 2014


Author: zturner
Date: Mon Jul 28 11:45:05 2014
New Revision: 214093

URL: http://llvm.org/viewvc/llvm-project?rev=214093&view=rev
Log:
Use llvm Support functions to get the user's home directory.

Assuming that the user's home directory is at ~ is incorrect on
Windows.  This patch delegates the request to LLVM's support
library, which already provides a cross-platform implementation
of this function.

Differential Revision: http://reviews.llvm.org/D4674

Modified:
    lldb/trunk/include/lldb/Host/Host.h
    lldb/trunk/include/lldb/Host/windows/win32.h
    lldb/trunk/source/Host/common/Host.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Modified: lldb/trunk/include/lldb/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=214093&r1=214092&r2=214093&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Host.h (original)
+++ lldb/trunk/include/lldb/Host/Host.h Mon Jul 28 11:45:05 2014
@@ -19,6 +19,7 @@
 #include "lldb/lldb-private.h"
 #include "lldb/Core/StringList.h"
 #include "lldb/Host/File.h"
+#include "lldb/Host/FileSpec.h"
 
 namespace lldb_private {
 
@@ -361,6 +362,17 @@ public:
     SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name, size_t len);
 
     //------------------------------------------------------------------
+    /// Gets the FileSpec of the user profile directory.  On Posix-platforms
+    /// this is ~, and on windows this is generally something like
+    /// C:\Users\Alice.
+    ///
+    /// @return
+    ///     \b A file spec with the path to the user's home directory.
+    //------------------------------------------------------------------
+    static FileSpec
+    GetUserProfileFileSpec ();
+
+    //------------------------------------------------------------------
     /// Gets the FileSpec of the current process (the process that
     /// that is running the LLDB code).
     ///

Modified: lldb/trunk/include/lldb/Host/windows/win32.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/win32.h?rev=214093&r1=214092&r2=214093&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/windows/win32.h (original)
+++ lldb/trunk/include/lldb/Host/windows/win32.h Mon Jul 28 11:45:05 2014
@@ -19,7 +19,7 @@ char * strcasestr(const char *s, const c
 char* realpath(const char * name, char * resolved);
 
 #ifndef PATH_MAX
-#define PATH_MAX MAX_PATH
+#define PATH_MAX 32768
 #endif
 
 #define O_NOCTTY    0

Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=214093&r1=214092&r2=214093&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Mon Jul 28 11:45:05 2014
@@ -75,6 +75,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Host.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
 #if defined (__APPLE__)
@@ -828,6 +829,19 @@ Host::SetShortThreadName (lldb::pid_t pi
 #endif
 
 FileSpec
+Host::GetUserProfileFileSpec ()
+{
+    static FileSpec g_profile_filespec;
+    if (!g_profile_filespec)
+    {
+        llvm::SmallString<64> path;
+        llvm::sys::path::home_directory(path);
+        return FileSpec(path.c_str(), false);
+    }
+    return g_profile_filespec;
+}
+
+FileSpec
 Host::GetProgramFileSpec ()
 {
     static FileSpec g_program_filespec;
@@ -867,6 +881,10 @@ Host::GetProgramFileSpec ()
                 g_program_filespec.SetFile(exe_path, false);
             delete[] exe_path;
         }
+#elif defined(_WIN32)
+        std::vector<char> buffer(PATH_MAX);
+        ::GetModuleFileName(NULL, &buffer[0], buffer.size());
+        g_program_filespec.SetFile(&buffer[0], false, FileSpec::ePathSyntaxWindows);
 #endif
     }
     return g_program_filespec;

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=214093&r1=214092&r2=214093&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Mon Jul 28 11:45:05 2014
@@ -2381,7 +2381,9 @@ CommandInterpreter::SourceInitFile (bool
         // "-" and the name of the program. If this file doesn't exist, we fall
         // back to just the "~/.lldbinit" file. We also obey any requests to not
         // load the init files.
-        const char *init_file_path = "~/.lldbinit";
+        FileSpec profilePath = Host::GetUserProfileFileSpec();
+        profilePath.AppendPathComponent(".lldbinit");
+        std::string init_file_path = profilePath.GetPath();
 
         if (m_skip_app_init_files == false)
         {
@@ -2391,7 +2393,7 @@ CommandInterpreter::SourceInitFile (bool
             if (program_name)
             {
                 char program_init_file_name[PATH_MAX];
-                ::snprintf (program_init_file_name, sizeof(program_init_file_name), "%s-%s", init_file_path, program_name);
+                ::snprintf (program_init_file_name, sizeof(program_init_file_name), "%s-%s", init_file_path.c_str(), program_name);
                 init_file.SetFile (program_init_file_name, true);
                 if (!init_file.Exists())
                     init_file.Clear();
@@ -2399,7 +2401,7 @@ CommandInterpreter::SourceInitFile (bool
         }
         
         if (!init_file && !m_skip_lldbinit_files)
-			init_file.SetFile (init_file_path, true);
+			init_file.SetFile (init_file_path.c_str(), false);
     }
 
     // If the file exists, tell HandleCommand to 'source' it; this will do the actual broadcasting





More information about the lldb-commits mailing list