[Lldb-commits] [lldb] r124927 - in /lldb/trunk: include/lldb/Core/FileSpec.h include/lldb/Host/linux/Config.h include/lldb/Host/macosx/Config.h include/lldb/Host/mingw/Config.h source/Commands/CommandCompletions.cpp source/Core/FileSpec.cpp

Greg Clayton gclayton at apple.com
Fri Feb 4 18:27:52 PST 2011


Author: gclayton
Date: Fri Feb  4 20:27:52 2011
New Revision: 124927

URL: http://llvm.org/viewvc/llvm-project?rev=124927&view=rev
Log:
Added support for targets that don't support expanding "~/" or "~USERNAME".
Patch from Kirk Beitz.


Modified:
    lldb/trunk/include/lldb/Core/FileSpec.h
    lldb/trunk/include/lldb/Host/linux/Config.h
    lldb/trunk/include/lldb/Host/macosx/Config.h
    lldb/trunk/include/lldb/Host/mingw/Config.h
    lldb/trunk/source/Commands/CommandCompletions.cpp
    lldb/trunk/source/Core/FileSpec.cpp

Modified: lldb/trunk/include/lldb/Core/FileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=124927&r1=124926&r2=124927&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Core/FileSpec.h Fri Feb  4 20:27:52 2011
@@ -519,7 +519,10 @@
     //------------------------------------------------------------------
     static size_t
     Resolve (const char *src_path, char *dst_path, size_t dst_len);
-    
+
+#if LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+
+
     //------------------------------------------------------------------
     /// Resolves the user name at the beginning of \a src_path, and writes the output
     /// to \a dst_path.  Note, \a src_path can contain other path components after the
@@ -544,6 +547,8 @@
     static size_t
     ResolveUsername (const char *src_path, char *dst_path, size_t dst_len);
 
+#endif
+
     enum EnumerateDirectoryResult
     {
         eEnumerateDirectoryResultNext,  // Enumerate next entry in the current directory

Modified: lldb/trunk/include/lldb/Host/linux/Config.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/linux/Config.h?rev=124927&r1=124926&r2=124927&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/linux/Config.h (original)
+++ lldb/trunk/include/lldb/Host/linux/Config.h Fri Feb  4 20:27:52 2011
@@ -19,4 +19,6 @@
 
 #define LLDB_CONFIG_TERMIOS_SUPPORTED 1
 
-#endif // #ifndef liblldb_Platform_Config_h_
\ No newline at end of file
+#define LLDB_CONFIG_TILDE_RESOLVES_TO_USER 1
+
+#endif // #ifndef liblldb_Platform_Config_h_

Modified: lldb/trunk/include/lldb/Host/macosx/Config.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/macosx/Config.h?rev=124927&r1=124926&r2=124927&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/macosx/Config.h (original)
+++ lldb/trunk/include/lldb/Host/macosx/Config.h Fri Feb  4 20:27:52 2011
@@ -19,4 +19,7 @@
 
 #define LLDB_CONFIG_TERMIOS_SUPPORTED 1
 
-#endif // #ifndef liblldb_Platform_Config_h_
\ No newline at end of file
+#define LLDB_CONFIG_TILDE_RESOLVES_TO_USER 1
+ 1
+
+#endif // #ifndef liblldb_Platform_Config_h_

Modified: lldb/trunk/include/lldb/Host/mingw/Config.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/mingw/Config.h?rev=124927&r1=124926&r2=124927&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/mingw/Config.h (original)
+++ lldb/trunk/include/lldb/Host/mingw/Config.h Fri Feb  4 20:27:52 2011
@@ -19,4 +19,6 @@
 
 #define LLDB_CONFIG_TERMIOS_SUPPORTED 0
 
-#endif // #ifndef liblldb_Platform_Config_h_
\ No newline at end of file
+#define LLDB_CONFIG_TILDE_RESOLVES_TO_USER 0
+
+#endif // #ifndef liblldb_Platform_Config_h_

Modified: lldb/trunk/source/Commands/CommandCompletions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandCompletions.cpp?rev=124927&r1=124926&r2=124927&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandCompletions.cpp (original)
+++ lldb/trunk/source/Commands/CommandCompletions.cpp Fri Feb  4 20:27:52 2011
@@ -11,10 +11,9 @@
 // C Includes
 #include <sys/stat.h>
 #include <dirent.h>
-#include <libgen.h>
-#include <glob.h>
+#if defined(__APPLE__) || defined(__linux__)
 #include <pwd.h>
-#include <sys/types.h>
+#endif
 
 // C++ Includes
 // Other libraries and framework includes
@@ -154,6 +153,8 @@
     
     if (end_ptr == NULL)
     {
+#if LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+
         // There's no directory.  If the thing begins with a "~" then this is a bare
         // user name.
         if (*partial_name_copy == '~')
@@ -168,7 +169,7 @@
            // Not sure how this would happen, a username longer than PATH_MAX?  Still...
             if (resolved_username_len >= sizeof (resolved_username))
                 return matches.GetSize();
-            else if (resolved_username_len == 0)
+            if (resolved_username_len == 0)
             {
                 // The user name didn't resolve, let's look in the password database for matches.
                 // The user name database contains duplicates, and is not in alphabetical order, so
@@ -197,7 +198,6 @@
                 }
                 return matches.GetSize();
             }    
-            
             //The thing exists, put a '/' on the end, and return it...
             // FIXME: complete user names here:
             partial_name_copy[partial_name_len] = '/';
@@ -207,6 +207,8 @@
             return matches.GetSize();
         }
         else
+#endif // LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+
         {
             // The containing part is the CWD, and the whole string is the remainder.
             containing_part[0] = '.';
@@ -236,7 +238,8 @@
     
     // Look for a user name in the containing part, and if it's there, resolve it and stick the
     // result back into the containing_part:
-    
+
+#if LLDB_CONFIG_TILDE_RESOLVES_TO_USER
     if (*partial_name_copy == '~')
     {
         size_t resolved_username_len = FileSpec::ResolveUsername(containing_part, containing_part, sizeof (containing_part));
@@ -244,7 +247,8 @@
         if (resolved_username_len == 0 || resolved_username_len >= sizeof (containing_part))
             return matches.GetSize();
     }
-    
+#endif // #if LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+
     // Okay, containing_part is now the directory we want to open and look for files:
 
     lldb_utility::CleanUp <DIR *, int> dir_stream (opendir(containing_part), NULL, closedir);

Modified: lldb/trunk/source/Core/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FileSpec.cpp?rev=124927&r1=124926&r2=124927&view=diff
==============================================================================
--- lldb/trunk/source/Core/FileSpec.cpp (original)
+++ lldb/trunk/source/Core/FileSpec.cpp Fri Feb  4 20:27:52 2011
@@ -11,11 +11,11 @@
 #include <dirent.h>
 #include <fcntl.h>
 #include <libgen.h>
-#include <stdlib.h>
-#include <sys/param.h>
 #include <sys/stat.h>
-#include <sys/types.h>
+
+#if LLDB_CONFIG_TILDE_RESOLVES_TO_USER
 #include <pwd.h>
+#endif
 
 #include <fstream>
 
@@ -43,6 +43,8 @@
     return false;
 }
 
+#if LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+
 static const char*
 GetCachedGlobTildeSlash()
 {
@@ -131,6 +133,7 @@
     else 
         return ::snprintf (dst_path, dst_len, "%s%s", home_dir, remainder);
 }
+#endif // #if LLDB_CONFIG_TILDE_RESOLVES_TO_USER
 
 size_t
 FileSpec::Resolve (const char *src_path, char *dst_path, size_t dst_len)
@@ -140,6 +143,7 @@
 
     // Glob if needed for ~/, otherwise copy in case src_path is same as dst_path...
     char unglobbed_path[PATH_MAX];
+#if LLDB_CONFIG_TILDE_RESOLVES_TO_USER
     if (src_path[0] == '~')
     {
         size_t return_count = ResolveUsername(src_path, unglobbed_path, sizeof(unglobbed_path));
@@ -150,7 +154,10 @@
             ::snprintf (unglobbed_path, sizeof(unglobbed_path), "%s", src_path);
     }
     else
-        ::snprintf(unglobbed_path, sizeof(unglobbed_path), "%s", src_path);
+#endif // LLDB_CONFIG_TILDE_RESOLVES_TO_USER
+    {
+    	::snprintf(unglobbed_path, sizeof(unglobbed_path), "%s", src_path);
+    }
 
     // Now resolve the path if needed
     char resolved_path[PATH_MAX];





More information about the lldb-commits mailing list