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

llvm-svn: 233129
This commit is contained in:
Chaoren Lin 2015-03-24 23:07:02 +00:00
parent c756b2dfac
commit f9e915ae10
5 changed files with 6 additions and 14 deletions

View File

@ -25,7 +25,6 @@ class HostInfoAndroid : public HostInfoLinux
protected:
static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64);
static bool ComputeSupportExeDirectory(FileSpec &file_spec);
};
} // end of namespace lldb_private

View File

@ -40,7 +40,7 @@ class HostInfoLinux : public HostInfoPosix
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);

View File

@ -30,13 +30,6 @@ HostInfoAndroid::ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arc
}
}
bool
HostInfoAndroid::ComputeSupportExeDirectory(FileSpec &file_spec)
{
file_spec.GetDirectory() = HostInfoLinux::GetProgramFileSpec().GetDirectory();
return (bool)file_spec.GetDirectory();
}
FileSpec
HostInfoAndroid::GetDefaultShell()
{

View File

@ -487,8 +487,6 @@ Host::GetModuleFileSpecForHostAddress (const void *host_addr)
if (info.dli_fname)
module_filespec.SetFile(info.dli_fname, true);
}
#else
assert(false && "dladdr() not supported on Android");
#endif
return module_filespec;
}

View File

@ -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