Author: chaoren Date: Tue Mar 24 18:07:02 2015 New Revision: 233129 URL: http://llvm.org/viewvc/llvm-project?rev=233129&view=rev Log: ComputeSupportExeDirectory for Linux
Summary: Fixes http://reviews.llvm.org/D8511 The original method of using dladdr() could return the incorrect relative path if not dynamically linked against liblldb and the working directory has changed. This is not a problem when built with python, since ScriptInterpreterPython::InitializePrivate calls HostInfo::GetLLDBPath(ePathTypeLLDBShlibDir, ...) and caches the correct path before any changes to the working directory. The /proc/self/exe approach fails if run using Python, but works for all other cases (including for android, which doesn't have dladdr()). So if we combine the two, we should reasonably cover all corner cases. Reviewers: vharron, ovyalov, clayborg Reviewed By: ovyalov, clayborg Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D8570 Modified: lldb/trunk/include/lldb/Host/android/HostInfoAndroid.h lldb/trunk/include/lldb/Host/linux/HostInfoLinux.h lldb/trunk/source/Host/android/HostInfoAndroid.cpp lldb/trunk/source/Host/common/Host.cpp lldb/trunk/source/Host/linux/HostInfoLinux.cpp Modified: lldb/trunk/include/lldb/Host/android/HostInfoAndroid.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/android/HostInfoAndroid.h?rev=233129&r1=233128&r2=233129&view=diff ============================================================================== --- lldb/trunk/include/lldb/Host/android/HostInfoAndroid.h (original) +++ lldb/trunk/include/lldb/Host/android/HostInfoAndroid.h Tue Mar 24 18:07:02 2015 @@ -25,7 +25,6 @@ class HostInfoAndroid : public HostInfoL protected: static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64); - static bool ComputeSupportExeDirectory(FileSpec &file_spec); }; } // end of namespace lldb_private Modified: lldb/trunk/include/lldb/Host/linux/HostInfoLinux.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/linux/HostInfoLinux.h?rev=233129&r1=233128&r2=233129&view=diff ============================================================================== --- lldb/trunk/include/lldb/Host/linux/HostInfoLinux.h (original) +++ lldb/trunk/include/lldb/Host/linux/HostInfoLinux.h Tue Mar 24 18:07:02 2015 @@ -40,7 +40,7 @@ class HostInfoLinux : public HostInfoPos static FileSpec GetProgramFileSpec(); protected: - static bool ComputeSharedLibraryDirectory(FileSpec &file_spec); + static bool ComputeSupportExeDirectory(FileSpec &file_spec); static bool ComputeSystemPluginsDirectory(FileSpec &file_spec); static bool ComputeUserPluginsDirectory(FileSpec &file_spec); static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64); Modified: lldb/trunk/source/Host/android/HostInfoAndroid.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/android/HostInfoAndroid.cpp?rev=233129&r1=233128&r2=233129&view=diff ============================================================================== --- lldb/trunk/source/Host/android/HostInfoAndroid.cpp (original) +++ lldb/trunk/source/Host/android/HostInfoAndroid.cpp Tue Mar 24 18:07:02 2015 @@ -30,13 +30,6 @@ HostInfoAndroid::ComputeHostArchitecture } } -bool -HostInfoAndroid::ComputeSupportExeDirectory(FileSpec &file_spec) -{ - file_spec.GetDirectory() = HostInfoLinux::GetProgramFileSpec().GetDirectory(); - return (bool)file_spec.GetDirectory(); -} - FileSpec HostInfoAndroid::GetDefaultShell() { Modified: lldb/trunk/source/Host/common/Host.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=233129&r1=233128&r2=233129&view=diff ============================================================================== --- lldb/trunk/source/Host/common/Host.cpp (original) +++ lldb/trunk/source/Host/common/Host.cpp Tue Mar 24 18:07:02 2015 @@ -487,8 +487,6 @@ Host::GetModuleFileSpecForHostAddress (c if (info.dli_fname) module_filespec.SetFile(info.dli_fname, true); } -#else - assert(false && "dladdr() not supported on Android"); #endif return module_filespec; } Modified: lldb/trunk/source/Host/linux/HostInfoLinux.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/HostInfoLinux.cpp?rev=233129&r1=233128&r2=233129&view=diff ============================================================================== --- lldb/trunk/source/Host/linux/HostInfoLinux.cpp (original) +++ lldb/trunk/source/Host/linux/HostInfoLinux.cpp Tue Mar 24 18:07:02 2015 @@ -222,12 +222,14 @@ HostInfoLinux::GetProgramFileSpec() } bool -HostInfoLinux::ComputeSharedLibraryDirectory(FileSpec &file_spec) +HostInfoLinux::ComputeSupportExeDirectory(FileSpec &file_spec) { - if (HostInfoPosix::ComputeSharedLibraryDirectory(file_spec)) + if (HostInfoPosix::ComputeSupportExeDirectory(file_spec) && + !file_spec.IsRelativeToCurrentWorkingDirectory() && + file_spec.Exists()) return true; file_spec.GetDirectory() = GetProgramFileSpec().GetDirectory(); - return (bool)file_spec.GetDirectory(); + return !file_spec.GetDirectory().IsEmpty(); } bool _______________________________________________ lldb-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
