Skip to content

Commit

Permalink
[ExpressionParser] Implement ComputeClangResourceDir for Windows
Browse files Browse the repository at this point in the history
Summary: This function is useful for expression evaluation, especially when doing swift debugging on windows.

Reviewers: aprantl, labath

Reviewed By: labath

Subscribers: teemperor, jdoerfert, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D59072

llvm-svn: 355631
  • Loading branch information
bulbazord committed Mar 7, 2019
1 parent 47f0bf8 commit 53954b5
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 55 deletions.
3 changes: 3 additions & 0 deletions lldb/include/lldb/Host/HostInfoBase.h
Expand Up @@ -99,6 +99,9 @@ class HostInfoBase {
//---------------------------------------------------------------------------
static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);

static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
llvm::StringRef dir);

protected:
static bool ComputeSharedLibraryDirectory(FileSpec &file_spec);
static bool ComputeSupportExeDirectory(FileSpec &file_spec);
Expand Down
3 changes: 0 additions & 3 deletions lldb/include/lldb/Host/posix/HostInfoPosix.h
Expand Up @@ -32,9 +32,6 @@ class HostInfoPosix : public HostInfoBase {

static bool GetEnvironmentVar(const std::string &var_name, std::string &var);

static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
llvm::StringRef dir);

static UserIDResolver &GetUserIDResolver();

protected:
Expand Down
32 changes: 32 additions & 0 deletions lldb/source/Host/common/HostInfoBase.cpp
Expand Up @@ -214,6 +214,38 @@ ArchSpec HostInfoBase::GetAugmentedArchSpec(llvm::StringRef triple) {
return ArchSpec(normalized_triple);
}

bool HostInfoBase::ComputePathRelativeToLibrary(FileSpec &file_spec,
llvm::StringRef dir) {
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);

FileSpec lldb_file_spec = GetShlibDir();
if (!lldb_file_spec)
return false;

std::string raw_path = lldb_file_spec.GetPath();
if (log)
log->Printf("HostInfo::%s() attempting to "
"derive the path %s relative to liblldb install path: %s",
__FUNCTION__, dir.data(), raw_path.c_str());

// Drop bin (windows) or lib
llvm::StringRef parent_path = llvm::sys::path::parent_path(raw_path);
if (parent_path.empty()) {
if (log)
log->Printf("HostInfo::%s() failed to find liblldb within the shared "
"lib path",
__FUNCTION__);
return false;
}

raw_path = (parent_path + dir).str();
if (log)
log->Printf("HostInfo::%s() derived the path as: %s", __FUNCTION__,
raw_path.c_str());
file_spec.GetDirectory().SetString(raw_path);
return (bool)file_spec.GetDirectory();
}

bool HostInfoBase::ComputeSharedLibraryDirectory(FileSpec &file_spec) {
// To get paths related to LLDB we get the path to the executable that
// contains this function. On MacOSX this will be "LLDB.framework/.../LLDB".
Expand Down
37 changes: 0 additions & 37 deletions lldb/source/Host/posix/HostInfoPosix.cpp
Expand Up @@ -120,43 +120,6 @@ uint32_t HostInfoPosix::GetEffectiveGroupID() { return getegid(); }

FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh"); }

bool HostInfoPosix::ComputePathRelativeToLibrary(FileSpec &file_spec,
llvm::StringRef dir) {
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);

FileSpec lldb_file_spec = GetShlibDir();
if (!lldb_file_spec)
return false;

std::string raw_path = lldb_file_spec.GetPath();
// drop library directory
llvm::StringRef parent_path = llvm::sys::path::parent_path(raw_path);

// Most Posix systems (e.g. Linux/*BSD) will attempt to replace a */lib with
// */bin as the base directory for helper exe programs. This will fail if
// the /lib and /bin directories are rooted in entirely different trees.
if (log)
log->Printf("HostInfoPosix::ComputePathRelativeToLibrary() attempting to "
"derive the %s path from this path: %s",
dir.data(), raw_path.c_str());

if (!parent_path.empty()) {
// Now write in bin in place of lib.
raw_path = (parent_path + dir).str();

if (log)
log->Printf("Host::%s() derived the bin path as: %s", __FUNCTION__,
raw_path.c_str());
} else {
if (log)
log->Printf("Host::%s() failed to find /lib/liblldb within the shared "
"lib path, bailing on bin path construction",
__FUNCTION__);
}
file_spec.GetDirectory().SetString(raw_path);
return (bool)file_spec.GetDirectory();
}

bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
return ComputePathRelativeToLibrary(file_spec, "/bin");
}
Expand Down
12 changes: 1 addition & 11 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
Expand Up @@ -18,22 +18,13 @@

#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
#if !defined(_WIN32)
#include "lldb/Host/posix/HostInfoPosix.h"
#endif
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"

#include <string>

using namespace lldb_private;

#if defined(_WIN32)
static bool ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec,
FileSpec &file_spec, bool verify) {
return false;
}
#else
static bool VerifyClangPath(const llvm::Twine &clang_path) {
if (FileSystem::Instance().IsDirectory(clang_path))
return true;
Expand Down Expand Up @@ -67,7 +58,7 @@ static bool DefaultComputeClangResourceDirectory(FileSpec &lldb_shlib_spec,
return true;
}

return HostInfoPosix::ComputePathRelativeToLibrary(file_spec, relative_path);
return HostInfo::ComputePathRelativeToLibrary(file_spec, relative_path);
}

bool lldb_private::ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec,
Expand Down Expand Up @@ -141,7 +132,6 @@ bool lldb_private::ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec,
return true;
#endif // __APPLE__
}
#endif // _WIN32

FileSpec lldb_private::GetClangResourceDir() {
static FileSpec g_cached_resource_dir;
Expand Down
2 changes: 0 additions & 2 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangHost.h
Expand Up @@ -13,10 +13,8 @@ namespace lldb_private {

class FileSpec;

#if !defined(_WIN32)
bool ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec,
FileSpec &file_spec, bool verify);
#endif

FileSpec GetClangResourceDir();

Expand Down
7 changes: 5 additions & 2 deletions lldb/unittests/Expression/ClangParserTest.cpp
Expand Up @@ -31,7 +31,6 @@ struct ClangHostTest : public testing::Test {
};
} // namespace

#if !defined(_WIN32)
static std::string ComputeClangResourceDir(std::string lldb_shlib_path,
bool verify = false) {
FileSpec clang_dir;
Expand All @@ -41,8 +40,13 @@ static std::string ComputeClangResourceDir(std::string lldb_shlib_path,
}

TEST_F(ClangHostTest, ComputeClangResourceDirectory) {
#if !defined(_WIN32)
std::string path_to_liblldb = "/foo/bar/lib/";
std::string path_to_clang_dir = "/foo/bar/lib/clang/" CLANG_VERSION_STRING;
#else
std::string path_to_liblldb = "C:\\foo\\bar\\lib";
std::string path_to_clang_dir = "C:\\foo\\bar\\lib\\clang\\" CLANG_VERSION_STRING;
#endif
EXPECT_EQ(ComputeClangResourceDir(path_to_liblldb), path_to_clang_dir);

// The path doesn't really exist, so setting verify to true should make
Expand Down Expand Up @@ -91,4 +95,3 @@ TEST_F(ClangHostTest, MacOSX) {
ComputeClangResourceDir(GetInputFilePath(xcode)));
}
#endif // __APPLE__
#endif // !_WIN32

0 comments on commit 53954b5

Please sign in to comment.