Skip to content

Commit

Permalink
ComputeSupportExeDirectory for Linux
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chaoren committed Mar 24, 2015
1 parent c756b2d commit f9e915a
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
1 change: 0 additions & 1 deletion lldb/include/lldb/Host/android/HostInfoAndroid.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Host/linux/HostInfoLinux.h
Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions lldb/source/Host/android/HostInfoAndroid.cpp
Expand Up @@ -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()
{
Expand Down
2 changes: 0 additions & 2 deletions lldb/source/Host/common/Host.cpp
Expand Up @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions lldb/source/Host/linux/HostInfoLinux.cpp
Expand Up @@ -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
Expand Down

0 comments on commit f9e915a

Please sign in to comment.