[Lldb-commits] [lldb] r113709 - in /lldb/trunk: include/lldb/Host/Host.h source/Core/FileSpec.cpp source/Host/common/Host.cpp

Caroline Tice ctice at apple.com
Sat Sep 11 17:10:52 PDT 2010


Author: ctice
Date: Sat Sep 11 19:10:52 2010
New Revision: 113709

URL: http://llvm.org/viewvc/llvm-project?rev=113709&view=rev
Log:
Remove Host::ResolveExecutableLocation (very recent addition); replace use of
it with llvm::sys::Program::FindProgramByName.


Modified:
    lldb/trunk/include/lldb/Host/Host.h
    lldb/trunk/source/Core/FileSpec.cpp
    lldb/trunk/source/Host/common/Host.cpp

Modified: lldb/trunk/include/lldb/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=113709&r1=113708&r2=113709&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Host.h (original)
+++ lldb/trunk/include/lldb/Host/Host.h Sat Sep 11 19:10:52 2010
@@ -259,9 +259,6 @@
     static bool
     ResolveExecutableInBundle (FileSpec *file);
 
-    static bool
-    ResolveExecutableLocation (ConstString &directory_name, const ConstString &filename);
-    
     static uint32_t
     ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids);
     

Modified: lldb/trunk/source/Core/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FileSpec.cpp?rev=113709&r1=113708&r2=113709&view=diff
==============================================================================
--- lldb/trunk/source/Core/FileSpec.cpp (original)
+++ lldb/trunk/source/Core/FileSpec.cpp Sat Sep 11 19:10:52 2010
@@ -18,6 +18,10 @@
 
 #include <fstream>
 
+#include "llvm/ADT/StringRef.h"
+#include "llvm/System/Path.h"
+#include "llvm/System/Program.h"
+
 #include "lldb/Core/FileSpec.h"
 #include "lldb/Core/DataBufferHeap.h"
 #include "lldb/Core/DataBufferMemoryMap.h"
@@ -418,7 +422,35 @@
 bool
 FileSpec::ResolveExecutableLocation ()
 {
-    return Host::ResolveExecutableLocation (m_directory, m_filename);
+    if (m_directory.GetLength() == 0)
+    {
+        const std::string file_str (m_filename.AsCString());
+        llvm::sys::Path path = llvm::sys::Program::FindProgramByName (file_str);
+        llvm::StringRef dir_ref = path.getDirname();
+        if (! dir_ref.empty())
+        {
+            // FindProgramByName returns "." if it can't find the file.
+            if (strcmp (".", dir_ref.data()) == 0)
+                return false;
+
+            m_directory.SetCString (dir_ref.data());
+            if (Exists())
+                return true;
+            else
+            {
+                // If FindProgramByName found the file, it returns the directory + filename in its return results.
+                // We need to separate them.
+                FileSpec tmp_file (dir_ref.data());
+                if (tmp_file.Exists())
+                {
+                    m_directory = tmp_file.m_directory;
+                    return true;
+                }
+            }
+        }
+    }
+    
+    return false;
 }
 
 uint64_t

Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=113709&r1=113708&r2=113709&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Sat Sep 11 19:10:52 2010
@@ -727,59 +727,3 @@
     return false;
 }
 #endif
-
-bool
-Host::ResolveExecutableLocation (ConstString &directory_name, const ConstString &filename)
-{
-    // If the user specified just a plain filename, there may be additional ways to find the
-    // file, such as searching the PATH environment variable on UNIX systems.  This is the location
-    // to implement such additional searches.
-
-    // For now the only search we are implementing is search $PATH, which makes no sense if
-    // the user already specified a directory.
-
-    if (directory_name.GetLength() > 0)
-        return false;
-
-    std::string search_path (getenv ("PATH"));
-    char dir_separator = ':';
-
-    bool done = false;
-    bool found = false;
-    size_t start = 0;
-    while (!done && !found)
-    {
-        size_t end = search_path.find (dir_separator, start);
-        size_t length;
-        if (end == std::string::npos)
-        {
-            done = true;
-            length = search_path.length() - start;
-        }
-        else
-            length = end - start;
-
-        std::string directory_str = search_path.substr (start, length);
-
-        if (directory_str.length() > 0)
-        {
-            StreamString tmp_full_path_name;
-            if (directory_str[directory_str.length()-1] == '/')
-                tmp_full_path_name.Printf ("%s%s", directory_str.c_str(), filename.AsCString());
-            else
-                tmp_full_path_name.Printf ("%s/%s", directory_str.c_str(), filename.AsCString());
-
-            struct stat sb;
-
-            if (::stat (tmp_full_path_name.GetData(), &sb) == 0)
-            {
-                found = true;
-                directory_name.SetCString (directory_str.c_str());
-            }
-        }
-            
-        if (!done)
-          start = end + 1;
-    }
-    return found;
-}





More information about the lldb-commits mailing list