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. 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: 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(reinterpret_cast(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();