[Lldb-commits] [lldb] r113575 - in /lldb/trunk: include/lldb/API/SBFileSpec.h include/lldb/Core/FileSpec.h include/lldb/Host/Host.h source/API/SBFileSpec.cpp source/Commands/CommandObjectFile.cpp source/Core/FileSpec.cpp source/Host/common/Host.cpp source/Target/TargetList.cpp tools/driver/Driver.cpp

Caroline Tice ctice at apple.com
Fri Sep 10 11:31:03 PDT 2010


I was unaware of that function in llvm;  I will change my lldb stuff to use it.

-- Caroline

On Sep 9, 2010, at 10:28 PM, Chris Lattner wrote:

> 
> On Sep 9, 2010, at 9:48 PM, Caroline Tice wrote:
> 
>> Author: ctice
>> Date: Thu Sep  9 23:48:55 2010
>> New Revision: 113575
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=113575&view=rev
>> Log:
>> If the file the user specifies can't be found in the current directory,
>> and the user didn't specify a particular directory, search for the file 
>> using the $PATH environment variable.
> 
> Cool, thanks for doing this Caroline.  Did you consider using llvm::sys::Program::FindProgramByName?  It already handles this, as well as handling the other annoying cases on windows.  In general, we should aim to reuse existing support stuff that LLVM provides rather than reinvent it.  The corresponding header is "llvm/System/Program.h".
> 
> -Chris
> 
>> 
>> 
>> Modified:
>>   lldb/trunk/include/lldb/API/SBFileSpec.h
>>   lldb/trunk/include/lldb/Core/FileSpec.h
>>   lldb/trunk/include/lldb/Host/Host.h
>>   lldb/trunk/source/API/SBFileSpec.cpp
>>   lldb/trunk/source/Commands/CommandObjectFile.cpp
>>   lldb/trunk/source/Core/FileSpec.cpp
>>   lldb/trunk/source/Host/common/Host.cpp
>>   lldb/trunk/source/Target/TargetList.cpp
>>   lldb/trunk/tools/driver/Driver.cpp
>> 
>> Modified: lldb/trunk/include/lldb/API/SBFileSpec.h
>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFileSpec.h?rev=113575&r1=113574&r2=113575&view=diff
>> ==============================================================================
>> --- lldb/trunk/include/lldb/API/SBFileSpec.h (original)
>> +++ lldb/trunk/include/lldb/API/SBFileSpec.h Thu Sep  9 23:48:55 2010
>> @@ -36,6 +36,9 @@
>>    bool
>>    Exists () const;
>> 
>> +    bool
>> +    ResolveExecutableLocation ();
>> +
>>    const char *
>>    GetFilename() const;
>> 
>> 
>> Modified: lldb/trunk/include/lldb/Core/FileSpec.h
>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileSpec.h?rev=113575&r1=113574&r2=113575&view=diff
>> ==============================================================================
>> --- lldb/trunk/include/lldb/Core/FileSpec.h (original)
>> +++ lldb/trunk/include/lldb/Core/FileSpec.h Thu Sep  9 23:48:55 2010
>> @@ -261,6 +261,21 @@
>>    bool
>>    Exists () const;
>> 
>> +     
>> +    //------------------------------------------------------------------
>> +    /// Expanded existence test.
>> +    ///
>> +    /// Call into the Host to see if it can help find the file (e.g. by
>> +    /// searching paths set in the environment, etc.).
>> +    ///
>> +    /// If found, sets the value of m_directory to the directory where the file was found.
>> +    ///
>> +    /// @return
>> +    ///     \b true if was able to find the file using expanded search methods, \b false otherwise.
>> +    //------------------------------------------------------------------
>> +    bool
>> +    ResolveExecutableLocation ();
>> +
>>    uint64_t
>>    GetByteSize() const;
>> 
>> 
>> Modified: lldb/trunk/include/lldb/Host/Host.h
>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=113575&r1=113574&r2=113575&view=diff
>> ==============================================================================
>> --- lldb/trunk/include/lldb/Host/Host.h (original)
>> +++ lldb/trunk/include/lldb/Host/Host.h Thu Sep  9 23:48:55 2010
>> @@ -258,6 +258,9 @@
>> 
>>    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/API/SBFileSpec.cpp
>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFileSpec.cpp?rev=113575&r1=113574&r2=113575&view=diff
>> ==============================================================================
>> --- lldb/trunk/source/API/SBFileSpec.cpp (original)
>> +++ lldb/trunk/source/API/SBFileSpec.cpp Thu Sep  9 23:48:55 2010
>> @@ -61,6 +61,13 @@
>>    return false;
>> }
>> 
>> +bool
>> +SBFileSpec::ResolveExecutableLocation ()
>> +{
>> +    if (m_opaque_ap.get())
>> +        return m_opaque_ap->ResolveExecutableLocation ();
>> +    return false;
>> +}
>> 
>> int
>> SBFileSpec::ResolvePath (const char *src_path, char *dst_path, size_t dst_len)
>> 
>> Modified: lldb/trunk/source/Commands/CommandObjectFile.cpp
>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFile.cpp?rev=113575&r1=113574&r2=113575&view=diff
>> ==============================================================================
>> --- lldb/trunk/source/Commands/CommandObjectFile.cpp (original)
>> +++ lldb/trunk/source/Commands/CommandObjectFile.cpp Thu Sep  9 23:48:55 2010
>> @@ -117,7 +117,7 @@
>>    {
>>        FileSpec file_spec (file_path);
>> 
>> -        if (! file_spec.Exists())
>> +        if (! file_spec.Exists() && !file_spec.ResolveExecutableLocation())
>>        {
>>            result.AppendErrorWithFormat ("File '%s' does not exist.\n", file_path);
>>            result.SetStatus (eReturnStatusFailed);
>> 
>> Modified: lldb/trunk/source/Core/FileSpec.cpp
>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FileSpec.cpp?rev=113575&r1=113574&r2=113575&view=diff
>> ==============================================================================
>> --- lldb/trunk/source/Core/FileSpec.cpp (original)
>> +++ lldb/trunk/source/Core/FileSpec.cpp Thu Sep  9 23:48:55 2010
>> @@ -22,6 +22,7 @@
>> #include "lldb/Core/DataBufferHeap.h"
>> #include "lldb/Core/DataBufferMemoryMap.h"
>> #include "lldb/Core/Stream.h"
>> +#include "lldb/Host/Host.h"
>> 
>> using namespace lldb;
>> using namespace lldb_private;
>> @@ -414,6 +415,12 @@
>>    return GetFileStats (this, &file_stats);
>> }
>> 
>> +bool
>> +FileSpec::ResolveExecutableLocation ()
>> +{
>> +    return Host::ResolveExecutableLocation (m_directory, m_filename);
>> +}
>> +
>> uint64_t
>> FileSpec::GetByteSize() const
>> {
>> 
>> Modified: lldb/trunk/source/Host/common/Host.cpp
>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=113575&r1=113574&r2=113575&view=diff
>> ==============================================================================
>> --- lldb/trunk/source/Host/common/Host.cpp (original)
>> +++ lldb/trunk/source/Host/common/Host.cpp Thu Sep  9 23:48:55 2010
>> @@ -727,3 +727,59 @@
>>    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;
>> +}
>> 
>> Modified: lldb/trunk/source/Target/TargetList.cpp
>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/TargetList.cpp?rev=113575&r1=113574&r2=113575&view=diff
>> ==============================================================================
>> --- lldb/trunk/source/Target/TargetList.cpp (original)
>> +++ lldb/trunk/source/Target/TargetList.cpp Thu Sep  9 23:48:55 2010
>> @@ -71,6 +71,10 @@
>>    {
>>        ModuleSP exe_module_sp;
>>        FileSpec resolved_file(file);
>> +        
>> +        if (!resolved_file.Exists())
>> +            resolved_file.ResolveExecutableLocation ();
>> +            
>>        if (!Host::ResolveExecutableInBundle (&resolved_file))
>>            resolved_file = file;
>> 
>> 
>> Modified: lldb/trunk/tools/driver/Driver.cpp
>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=113575&r1=113574&r2=113575&view=diff
>> ==============================================================================
>> --- lldb/trunk/tools/driver/Driver.cpp (original)
>> +++ lldb/trunk/tools/driver/Driver.cpp Thu Sep  9 23:48:55 2010
>> @@ -527,6 +527,13 @@
>>                            SBFileSpec file(optarg);
>>                            if (file.Exists())
>>                                m_option_data.m_filename = optarg;
>> +                            else if (file.ResolveExecutableLocation())
>> +                            {
>> +                                char path[PATH_MAX];
>> +                                int path_len;
>> +                                file.GetPath (path, path_len);
>> +                                m_option_data.m_filename = path;
>> +                            }
>>                            else
>>                                error.SetErrorStringWithFormat("file specified in --file (-f) option doesn't exist: '%s'", optarg);
>>                        }
>> @@ -550,6 +557,14 @@
>>                            SBFileSpec file(optarg);
>>                            if (file.Exists())
>>                                m_option_data.m_source_command_files.push_back (optarg);
>> +                            else if (file.ResolveExecutableLocation())
>> +                            {
>> +                                char final_path[PATH_MAX];
>> +                                size_t path_len;
>> +                                file.GetPath (final_path, path_len);
>> +                                std::string path_str (final_path);
>> +                                m_option_data.m_source_command_files.push_back (path_str);
>> +                            }
>>                            else
>>                                error.SetErrorStringWithFormat("file specified in --source (-s) option doesn't exist: '%s'", optarg);
>>                        }
>> 
>> 
>> _______________________________________________
>> lldb-commits mailing list
>> lldb-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
> 





More information about the lldb-commits mailing list