[Lldb-commits] [PATCH] D12984: Resolve symlinks when looking for the LLDB shlib
Sean Callanan via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 18 14:23:46 PDT 2015
spyffe created this revision.
spyffe added a reviewer: clayborg.
spyffe added a subscriber: lldb-commits.
When running the testsuite, the LLDB shlib is a symlink to its actual location, so finding shlib-relative resources can be problematic. This patch fixes that by resolving symlinks.
http://reviews.llvm.org/D12984
Files:
include/lldb/Host/FileSpec.h
source/Host/common/FileSpec.cpp
source/Host/common/HostInfoBase.cpp
Index: source/Host/common/HostInfoBase.cpp
===================================================================
--- source/Host/common/HostInfoBase.cpp
+++ source/Host/common/HostInfoBase.cpp
@@ -306,7 +306,11 @@
FileSpec lldb_file_spec(
Host::GetModuleFileSpecForHostAddress(reinterpret_cast<void *>(reinterpret_cast<intptr_t>(HostInfoBase::GetLLDBPath))));
-
+
+ if (lldb_file_spec.IsSymbolicLink()) {
+ lldb_file_spec = lldb_file_spec.GetSymbolicLinkTarget();
+ }
+
// Remove the filename so that this FileSpec only represents the directory.
file_spec.GetDirectory() = lldb_file_spec.GetDirectory();
Index: source/Host/common/FileSpec.cpp
===================================================================
--- source/Host/common/FileSpec.cpp
+++ source/Host/common/FileSpec.cpp
@@ -811,6 +811,32 @@
#endif
}
+FileSpec
+FileSpec::GetSymbolicLinkTarget () const {
+ if (!IsSymbolicLink())
+ {
+ return FileSpec();
+ }
+
+ char resolved_path[PATH_MAX];
+ if (!GetPath (resolved_path, sizeof (resolved_path)))
+ {
+ return FileSpec();
+ }
+
+#ifdef _WIN32
+ return FileSpec(); // TODO make this work on win32
+#else
+ char real_path[PATH_MAX + 1];
+ if (realpath(resolved_path, real_path) == nullptr)
+ {
+ return FileSpec();
+ }
+
+ return FileSpec(real_path, false);
+#endif
+}
+
uint32_t
FileSpec::GetPermissions () const
{
Index: include/lldb/Host/FileSpec.h
===================================================================
--- include/lldb/Host/FileSpec.h
+++ include/lldb/Host/FileSpec.h
@@ -73,7 +73,7 @@
/// 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 @@
bool
IsSymbolicLink () const;
+
+ FileSpec
+ GetSymbolicLinkTarget () const;
//------------------------------------------------------------------
/// Get the memory cost of this object.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12984.35135.patch
Type: text/x-patch
Size: 2279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150918/30b20523/attachment.bin>
More information about the lldb-commits
mailing list