diff options
| author | Sean Callanan <scallanan@apple.com> | 2015-09-18 21:39:31 +0000 |
|---|---|---|
| committer | Sean Callanan <scallanan@apple.com> | 2015-09-18 21:39:31 +0000 |
| commit | db7d8083cd1f32dc7ffd699ac66ae5bbef7405f0 (patch) | |
| tree | cb2111794c3654ed669700de75da47cd41d392e7 | |
| parent | c021abfaffc48f561022645888e84d79ef2e5e5d (diff) | |
| download | bcm5719-llvm-db7d8083cd1f32dc7ffd699ac66ae5bbef7405f0.tar.gz bcm5719-llvm-db7d8083cd1f32dc7ffd699ac66ae5bbef7405f0.zip | |
Added support for resolving symbolic links to FileSpec.
We use the symbolic link to resolver to find the target of the LLDB shlib
symlink if there is a symlink. This allows us to find shlib-relative resources
even when running under the testsuite, where _lldb.so is a symlink in the Python
resource directory.
Also changed a comment to be slightly more clear about what resolve_path in the
constructor for FileSpec means, since if we were actually using realpath() this
code wouldn't have been necessary.
http://reviews.llvm.org/D12984
llvm-svn: 248048
| -rw-r--r-- | lldb/include/lldb/Host/FileSpec.h | 5 | ||||
| -rw-r--r-- | lldb/source/Host/common/FileSpec.cpp | 26 | ||||
| -rw-r--r-- | lldb/source/Host/common/HostInfoBase.cpp | 5 |
3 files changed, 34 insertions, 2 deletions
diff --git a/lldb/include/lldb/Host/FileSpec.h b/lldb/include/lldb/Host/FileSpec.h index dd6da59f4ce..d8eb49f0ec1 100644 --- a/lldb/include/lldb/Host/FileSpec.h +++ b/lldb/include/lldb/Host/FileSpec.h @@ -73,7 +73,7 @@ public: /// The full or partial path to a file. /// /// @param[in] resolve_path - /// If \b true, then we resolve the path with realpath, + /// If \b true, then we resolve the path, removing stray ../.. and so forth, /// if \b false we trust the path is in canonical form already. /// /// @see FileSpec::SetFile (const char *path, bool resolve) @@ -511,6 +511,9 @@ public: bool IsSymbolicLink () const; + + FileSpec + ResolveSymbolicLink () const; //------------------------------------------------------------------ /// Get the memory cost of this object. diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp index 9efdacb010b..f7225a4b0bc 100644 --- a/lldb/source/Host/common/FileSpec.cpp +++ b/lldb/source/Host/common/FileSpec.cpp @@ -811,6 +811,32 @@ FileSpec::IsSymbolicLink () const #endif } +FileSpec +FileSpec::ResolveSymbolicLink () const { + if (!IsSymbolicLink()) + { + return *this; + } + + char resolved_path[PATH_MAX]; + if (!GetPath (resolved_path, sizeof (resolved_path))) + { + return *this; + } + +#ifdef _WIN32 + return *this; // TODO make this work on win32 +#else + char real_path[PATH_MAX + 1]; + if (realpath(resolved_path, real_path) == nullptr) + { + return *this; + } + + return FileSpec(real_path, false); +#endif +} + uint32_t FileSpec::GetPermissions () const { diff --git a/lldb/source/Host/common/HostInfoBase.cpp b/lldb/source/Host/common/HostInfoBase.cpp index 7a6ea0c2b84..e7340c538f3 100644 --- a/lldb/source/Host/common/HostInfoBase.cpp +++ b/lldb/source/Host/common/HostInfoBase.cpp @@ -306,7 +306,10 @@ HostInfoBase::ComputeSharedLibraryDirectory(FileSpec &file_spec) FileSpec lldb_file_spec( Host::GetModuleFileSpecForHostAddress(reinterpret_cast<void *>(reinterpret_cast<intptr_t>(HostInfoBase::GetLLDBPath)))); - + + // This is necessary because when running the testsuite the shlib might be a symbolic link inside the Python resource dir. + lldb_file_spec = lldb_file_spec.ResolveSymbolicLink(); + // Remove the filename so that this FileSpec only represents the directory. file_spec.GetDirectory() = lldb_file_spec.GetDirectory(); |

