<div dir="ltr">Any time there's something involving windows, even if you're just #ifdef'ing out a code path, I would prefer if you could wait until I or someone else who works on Windows has a chance to comment before committing.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Sep 18, 2015 at 2:40 PM Sean Callanan via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: spyffe<br>
Date: Fri Sep 18 16:39:31 2015<br>
New Revision: 248048<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=248048&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=248048&view=rev</a><br>
Log:<br>
Added support for resolving symbolic links to FileSpec.<br>
<br>
We use the symbolic link to resolver to find the target of the LLDB shlib<br>
symlink if there is a symlink.  This allows us to find shlib-relative  resources<br>
even when running under the testsuite, where _lldb.so is a symlink in the Python<br>
resource directory.<br>
<br>
Also changed a comment to be slightly more clear about what resolve_path in the<br>
constructor for FileSpec means, since if we were actually using realpath() this<br>
code wouldn't have been necessary.<br>
<br>
<a href="http://reviews.llvm.org/D12984" rel="noreferrer" target="_blank">http://reviews.llvm.org/D12984</a><br>
<br>
Modified:<br>
    lldb/trunk/include/lldb/Host/FileSpec.h<br>
    lldb/trunk/source/Host/common/FileSpec.cpp<br>
    lldb/trunk/source/Host/common/HostInfoBase.cpp<br>
<br>
Modified: lldb/trunk/include/lldb/Host/FileSpec.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSpec.h?rev=248048&r1=248047&r2=248048&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSpec.h?rev=248048&r1=248047&r2=248048&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Host/FileSpec.h (original)<br>
+++ lldb/trunk/include/lldb/Host/FileSpec.h Fri Sep 18 16:39:31 2015<br>
@@ -73,7 +73,7 @@ public:<br>
     ///     The full or partial path to a file.<br>
     ///<br>
     /// @param[in] resolve_path<br>
-    ///     If \b true, then we resolve the path with realpath,<br>
+    ///     If \b true, then we resolve the path, removing stray ../.. and so forth,<br>
     ///     if \b false we trust the path is in canonical form already.<br>
     ///<br>
     /// @see FileSpec::SetFile (const char *path, bool resolve)<br>
@@ -511,6 +511,9 @@ public:<br>
<br>
     bool<br>
     IsSymbolicLink () const;<br>
+<br>
+    FileSpec<br>
+    ResolveSymbolicLink () const;<br>
<br>
     //------------------------------------------------------------------<br>
     /// Get the memory cost of this object.<br>
<br>
Modified: lldb/trunk/source/Host/common/FileSpec.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=248048&r1=248047&r2=248048&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=248048&r1=248047&r2=248048&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)<br>
+++ lldb/trunk/source/Host/common/FileSpec.cpp Fri Sep 18 16:39:31 2015<br>
@@ -811,6 +811,32 @@ FileSpec::IsSymbolicLink () const<br>
 #endif<br>
 }<br>
<br>
+FileSpec<br>
+FileSpec::ResolveSymbolicLink () const {<br>
+    if (!IsSymbolicLink())<br>
+    {<br>
+        return *this;<br>
+    }<br>
+<br>
+    char resolved_path[PATH_MAX];<br>
+    if (!GetPath (resolved_path, sizeof (resolved_path)))<br>
+    {<br>
+        return *this;<br>
+    }<br>
+<br>
+#ifdef _WIN32<br>
+    return *this; // TODO make this work on win32<br>
+#else<br>
+    char real_path[PATH_MAX + 1];<br>
+    if (realpath(resolved_path, real_path) == nullptr)<br>
+    {<br>
+        return *this;<br>
+    }<br>
+<br>
+    return FileSpec(real_path, false);<br>
+#endif<br>
+}<br>
+<br>
 uint32_t<br>
 FileSpec::GetPermissions () const<br>
 {<br>
<br>
Modified: lldb/trunk/source/Host/common/HostInfoBase.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostInfoBase.cpp?rev=248048&r1=248047&r2=248048&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostInfoBase.cpp?rev=248048&r1=248047&r2=248048&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Host/common/HostInfoBase.cpp (original)<br>
+++ lldb/trunk/source/Host/common/HostInfoBase.cpp Fri Sep 18 16:39:31 2015<br>
@@ -306,7 +306,10 @@ HostInfoBase::ComputeSharedLibraryDirect<br>
<br>
     FileSpec lldb_file_spec(<br>
         Host::GetModuleFileSpecForHostAddress(reinterpret_cast<void *>(reinterpret_cast<intptr_t>(HostInfoBase::GetLLDBPath))));<br>
-<br>
+<br>
+    // This is necessary because when running the testsuite the shlib might be a symbolic link inside the Python resource dir.<br>
+    lldb_file_spec = lldb_file_spec.ResolveSymbolicLink();<br>
+<br>
     // Remove the filename so that this FileSpec only represents the directory.<br>
     file_spec.GetDirectory() = lldb_file_spec.GetDirectory();<br>
<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>