Replace HostInfo::GetLLDBPath with specific functions

Summary:
Instead of a function taking an enum value determining which path to
return, we now have a suite of functions, each returning a single path
kind. This makes it easy to move the python-path function into a
specific plugin in a follow-up commit.

All the users of GetLLDBPath were converted to call specific functions
instead. Most of them were hard-coding the enum value anyway, so this
conversion was simple. The only exception was SBHostOS, which I've
changed to use a switch on the incoming enum value.

Reviewers: clayborg, zturner

Subscribers: lldb-commits

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

llvm-svn: 335052
This commit is contained in:
Pavel Labath
2018-06-19 15:09:07 +00:00
parent 7bbedb8023
commit 60f028ff03
21 changed files with 203 additions and 227 deletions

View File

@@ -63,25 +63,39 @@ public:
static llvm::Optional<ArchitectureKind> ParseArchitectureKind(llvm::StringRef kind);
//------------------------------------------------------------------
/// Find a resource files that are related to LLDB.
///
/// Operating systems have different ways of storing shared
/// libraries and related resources. This function abstracts the
/// access to these paths.
///
/// @param[in] path_type
/// The type of LLDB resource path you are looking for. If the
/// enumeration ends with "Dir", then only the \a file_spec's
/// directory member gets filled in.
///
/// @param[in] file_spec
/// A file spec that gets filled in with the appropriate path.
///
/// @return
/// \b true if \a resource_path was resolved, \a false otherwise.
//------------------------------------------------------------------
static bool GetLLDBPath(lldb::PathType type, FileSpec &file_spec);
/// Returns the directory containing the lldb shared library. Only the
/// directory member of the FileSpec is filled in.
static FileSpec GetShlibDir();
/// Returns the directory containing the support executables (debugserver,
/// ...). Only the directory member of the FileSpec is filled in.
static FileSpec GetSupportExeDir();
/// Returns the directory containing the lldb headers. Only the directory
/// member of the FileSpec is filled in.
static FileSpec GetHeaderDir();
/// Returns the directory containing the python modules. Only the directory
/// member of the FileSpec is filled in.
static FileSpec GetPythonDir();
/// Returns the directory containing the system plugins. Only the directory
/// member of the FileSpec is filled in.
static FileSpec GetSystemPluginDir();
/// Returns the directory containing the user plugins. Only the directory
/// member of the FileSpec is filled in.
static FileSpec GetUserPluginDir();
/// Returns the proces temporary directory. This directory will be cleaned up
/// when this process exits. Only the directory member of the FileSpec is
/// filled in.
static FileSpec GetProcessTempDir();
/// Returns the global temporary directory. This directory will **not** be
/// cleaned up when this process exits. Only the directory member of the
/// FileSpec is filled in.
static FileSpec GetGlobalTempDir();
//---------------------------------------------------------------------------
/// If the triple does not specify the vendor, os, and environment parts, we

View File

@@ -32,24 +32,43 @@ SBFileSpec SBHostOS::GetProgramFileSpec() {
}
SBFileSpec SBHostOS::GetLLDBPythonPath() {
SBFileSpec sb_lldb_python_filespec;
FileSpec lldb_python_spec;
if (HostInfo::GetLLDBPath(ePathTypePythonDir, lldb_python_spec)) {
sb_lldb_python_filespec.SetFileSpec(lldb_python_spec);
}
return sb_lldb_python_filespec;
return GetLLDBPath(ePathTypePythonDir);
}
SBFileSpec SBHostOS::GetLLDBPath(lldb::PathType path_type) {
SBFileSpec sb_fspec;
FileSpec fspec;
bool Success = true;
if (path_type == ePathTypeClangDir)
switch (path_type) {
case ePathTypeLLDBShlibDir:
fspec = HostInfo::GetShlibDir();
break;
case ePathTypeSupportExecutableDir:
fspec = HostInfo::GetSupportExeDir();
break;
case ePathTypeHeaderDir:
fspec = HostInfo::GetHeaderDir();
break;
case ePathTypePythonDir:
fspec = HostInfo::GetPythonDir();
break;
case ePathTypeLLDBSystemPlugins:
fspec = HostInfo::GetSystemPluginDir();
break;
case ePathTypeLLDBUserPlugins:
fspec = HostInfo::GetUserPluginDir();
break;
case ePathTypeLLDBTempSystemDir:
fspec = HostInfo::GetProcessTempDir();
break;
case ePathTypeGlobalLLDBTempSystemDir:
fspec = HostInfo::GetGlobalTempDir();
break;
case ePathTypeClangDir:
fspec = GetClangResourceDir();
else
Success = HostInfo::GetLLDBPath(path_type, fspec);
if (Success)
sb_fspec.SetFileSpec(fspec);
break;
}
SBFileSpec sb_fspec;
sb_fspec.SetFileSpec(fspec);
return sb_fspec;
}

View File

@@ -646,19 +646,18 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft,
}
void Debugger::InstanceInitialize() {
FileSpec dir_spec;
const bool find_directories = true;
const bool find_files = true;
const bool find_other = true;
char dir_path[PATH_MAX];
if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec)) {
if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
find_other, LoadPluginCallback, this);
}
}
if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec)) {
if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
find_other, LoadPluginCallback, this);

View File

@@ -157,19 +157,18 @@ LoadPluginCallback(void *baton, llvm::sys::fs::file_type ft,
void PluginManager::Initialize() {
#if 1
FileSpec dir_spec;
const bool find_directories = true;
const bool find_files = true;
const bool find_other = true;
char dir_path[PATH_MAX];
if (HostInfo::GetLLDBPath(ePathTypeLLDBSystemPlugins, dir_spec)) {
if (FileSpec dir_spec = HostInfo::GetSystemPluginDir()) {
if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
find_other, LoadPluginCallback, nullptr);
}
}
if (HostInfo::GetLLDBPath(ePathTypeLLDBUserPlugins, dir_spec)) {
if (FileSpec dir_spec = HostInfo::GetUserPluginDir()) {
if (dir_spec.Exists() && dir_spec.GetPath(dir_path, sizeof(dir_path))) {
FileSpec::EnumerateDirectory(dir_path, find_directories, find_files,
find_other, LoadPluginCallback, nullptr);

View File

@@ -61,10 +61,8 @@ lldb::REPLSP REPL::Create(Status &err, lldb::LanguageType language,
std::string REPL::GetSourcePath() {
ConstString file_basename = GetSourceFileBasename();
FileSpec tmpdir_file_spec;
if (HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir,
tmpdir_file_spec)) {
FileSpec tmpdir_file_spec = HostInfo::GetProcessTempDir();
if (tmpdir_file_spec) {
tmpdir_file_spec.GetFilename().SetCString(file_basename.AsCString());
m_repl_source_path = tmpdir_file_spec.GetPath();
} else {

View File

@@ -500,8 +500,7 @@ Status Host::RunShellCommand(const Args &args, const FileSpec &working_dir,
// Create a temporary file to get the stdout/stderr and redirect the output
// of the command into this file. We will later read this file if all goes
// well and fill the data into "command_output_ptr"
FileSpec tmpdir_file_spec;
if (HostInfo::GetLLDBPath(ePathTypeLLDBTempSystemDir, tmpdir_file_spec)) {
if (FileSpec tmpdir_file_spec = HostInfo::GetProcessTempDir()) {
tmpdir_file_spec.AppendPathComponent("lldb-shell-output.%%%%%%");
llvm::sys::fs::createUniqueFile(tmpdir_file_spec.GetPath(),
output_file_path);

View File

@@ -111,141 +111,99 @@ llvm::Optional<HostInfoBase::ArchitectureKind> HostInfoBase::ParseArchitectureKi
.Default(llvm::None);
}
bool HostInfoBase::GetLLDBPath(lldb::PathType type, FileSpec &file_spec) {
file_spec.Clear();
FileSpec HostInfoBase::GetShlibDir() {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeSharedLibraryDirectory(g_fields->m_lldb_so_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
LLDB_LOG(log, "shlib dir -> `{0}`", g_fields->m_lldb_so_dir);
});
return success ? g_fields->m_lldb_so_dir : FileSpec();
}
assert(type != lldb::ePathTypeClangDir);
FileSpec HostInfoBase::GetSupportExeDir() {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success =
HostInfo::ComputeSupportExeDirectory(g_fields->m_lldb_support_exe_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
LLDB_LOG(log, "support exe dir -> `{0}`", g_fields->m_lldb_support_exe_dir);
});
return success ? g_fields->m_lldb_support_exe_dir : FileSpec();
}
#if defined(LLDB_DISABLE_PYTHON)
if (type == lldb::ePathTypePythonDir)
return false;
#endif
FileSpec HostInfoBase::GetHeaderDir() {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeHeaderDirectory(g_fields->m_lldb_headers_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
LLDB_LOG(log, "header dir -> `{0}`", g_fields->m_lldb_headers_dir);
});
return success ? g_fields->m_lldb_headers_dir : FileSpec();
}
FileSpec *result = nullptr;
switch (type) {
case lldb::ePathTypeLLDBShlibDir: {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success =
HostInfo::ComputeSharedLibraryDirectory(g_fields->m_lldb_so_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
if (log)
log->Printf("HostInfoBase::GetLLDBPath(ePathTypeLLDBShlibDir) => '%s'",
g_fields->m_lldb_so_dir.GetPath().c_str());
});
if (success)
result = &g_fields->m_lldb_so_dir;
} break;
case lldb::ePathTypeSupportExecutableDir: {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeSupportExeDirectory(
g_fields->m_lldb_support_exe_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
if (log)
log->Printf(
"HostInfoBase::GetLLDBPath(ePathTypeSupportExecutableDir) => '%s'",
g_fields->m_lldb_support_exe_dir.GetPath().c_str());
});
if (success)
result = &g_fields->m_lldb_support_exe_dir;
} break;
case lldb::ePathTypeHeaderDir: {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeHeaderDirectory(g_fields->m_lldb_headers_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
if (log)
log->Printf("HostInfoBase::GetLLDBPath(ePathTypeHeaderDir) => '%s'",
g_fields->m_lldb_headers_dir.GetPath().c_str());
});
if (success)
result = &g_fields->m_lldb_headers_dir;
} break;
case lldb::ePathTypePythonDir: {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputePythonDirectory(g_fields->m_lldb_python_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
if (log)
log->Printf("HostInfoBase::GetLLDBPath(ePathTypePythonDir) => '%s'",
g_fields->m_lldb_python_dir.GetPath().c_str());
});
if (success)
result = &g_fields->m_lldb_python_dir;
} break;
case lldb::ePathTypeLLDBSystemPlugins: {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeSystemPluginsDirectory(
g_fields->m_lldb_system_plugin_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
if (log)
log->Printf(
"HostInfoBase::GetLLDBPath(ePathTypeLLDBSystemPlugins) => '%s'",
g_fields->m_lldb_system_plugin_dir.GetPath().c_str());
});
if (success)
result = &g_fields->m_lldb_system_plugin_dir;
} break;
case lldb::ePathTypeLLDBUserPlugins: {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeUserPluginsDirectory(
g_fields->m_lldb_user_plugin_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
if (log)
log->Printf(
"HostInfoBase::GetLLDBPath(ePathTypeLLDBUserPlugins) => '%s'",
g_fields->m_lldb_user_plugin_dir.GetPath().c_str());
});
if (success)
result = &g_fields->m_lldb_user_plugin_dir;
} break;
case lldb::ePathTypeLLDBTempSystemDir: {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeProcessTempFileDirectory(
g_fields->m_lldb_process_tmp_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
if (log)
log->Printf(
"HostInfoBase::GetLLDBPath(ePathTypeLLDBTempSystemDir) => '%s'",
g_fields->m_lldb_process_tmp_dir.GetPath().c_str());
});
if (success)
result = &g_fields->m_lldb_process_tmp_dir;
} break;
case lldb::ePathTypeGlobalLLDBTempSystemDir: {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeGlobalTempFileDirectory(
g_fields->m_lldb_global_tmp_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
if (log)
log->Printf("HostInfoBase::GetLLDBPath("
"ePathTypeGlobalLLDBTempSystemDir) => '%s'",
g_fields->m_lldb_global_tmp_dir.GetPath().c_str());
});
if (success)
result = &g_fields->m_lldb_global_tmp_dir;
} break;
default:
llvm_unreachable("Unreachable!");
}
FileSpec HostInfoBase::GetPythonDir() {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputePythonDirectory(g_fields->m_lldb_python_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
LLDB_LOG(log, "python dir -> `{0}`", g_fields->m_lldb_python_dir);
});
return success ? g_fields->m_lldb_python_dir : FileSpec();
}
if (!result)
return false;
file_spec = *result;
return true;
FileSpec HostInfoBase::GetSystemPluginDir() {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeSystemPluginsDirectory(
g_fields->m_lldb_system_plugin_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
LLDB_LOG(log, "system plugin dir -> `{0}`",
g_fields->m_lldb_system_plugin_dir);
});
return success ? g_fields->m_lldb_system_plugin_dir : FileSpec();
}
FileSpec HostInfoBase::GetUserPluginDir() {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success =
HostInfo::ComputeUserPluginsDirectory(g_fields->m_lldb_user_plugin_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
LLDB_LOG(log, "user plugin dir -> `{0}`", g_fields->m_lldb_user_plugin_dir);
});
return success ? g_fields->m_lldb_user_plugin_dir : FileSpec();
}
FileSpec HostInfoBase::GetProcessTempDir() {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeProcessTempFileDirectory(
g_fields->m_lldb_process_tmp_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
LLDB_LOG(log, "process temp dir -> `{0}`",
g_fields->m_lldb_process_tmp_dir);
});
return success ? g_fields->m_lldb_process_tmp_dir : FileSpec();
}
FileSpec HostInfoBase::GetGlobalTempDir() {
static llvm::once_flag g_once_flag;
static bool success = false;
llvm::call_once(g_once_flag, []() {
success = HostInfo::ComputeGlobalTempFileDirectory(
g_fields->m_lldb_global_tmp_dir);
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
LLDB_LOG(log, "global temp dir -> `{0}`", g_fields->m_lldb_global_tmp_dir);
});
return success ? g_fields->m_lldb_global_tmp_dir : FileSpec();
}
ArchSpec HostInfoBase::GetAugmentedArchSpec(llvm::StringRef triple) {
@@ -274,9 +232,9 @@ bool HostInfoBase::ComputeSharedLibraryDirectory(FileSpec &file_spec) {
// contains this function. On MacOSX this will be "LLDB.framework/.../LLDB".
// On other posix systems, we will get .../lib(64|32)?/liblldb.so.
FileSpec lldb_file_spec(
Host::GetModuleFileSpecForHostAddress(reinterpret_cast<void *>(
reinterpret_cast<intptr_t>(HostInfoBase::GetLLDBPath))));
FileSpec lldb_file_spec(Host::GetModuleFileSpecForHostAddress(
reinterpret_cast<void *>(reinterpret_cast<intptr_t>(
HostInfoBase::ComputeSharedLibraryDirectory))));
// This is necessary because when running the testsuite the shlib might be a
// symbolic link inside the Python resource dir.
@@ -289,7 +247,8 @@ bool HostInfoBase::ComputeSharedLibraryDirectory(FileSpec &file_spec) {
}
bool HostInfoBase::ComputeSupportExeDirectory(FileSpec &file_spec) {
return GetLLDBPath(lldb::ePathTypeLLDBShlibDir, file_spec);
file_spec = GetShlibDir();
return bool(file_spec);
}
bool HostInfoBase::ComputeProcessTempFileDirectory(FileSpec &file_spec) {

View File

@@ -217,9 +217,8 @@ LaunchInNewTerminalWithAppleScript(const char *exe_path,
}
StreamString command;
FileSpec darwin_debug_file_spec;
if (!HostInfo::GetLLDBPath(ePathTypeSupportExecutableDir,
darwin_debug_file_spec)) {
FileSpec darwin_debug_file_spec = HostInfo::GetSupportExeDir();
if (!darwin_debug_file_spec) {
error.SetErrorString("can't locate the 'darwin-debug' executable");
return error;
}
@@ -1331,9 +1330,8 @@ Status Host::LaunchProcess(ProcessLaunchInfo &launch_info) {
Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
Status error;
if (launch_info.GetFlags().Test(eLaunchFlagShellExpandArguments)) {
FileSpec expand_tool_spec;
if (!HostInfo::GetLLDBPath(lldb::ePathTypeSupportExecutableDir,
expand_tool_spec)) {
FileSpec expand_tool_spec = HostInfo::GetSupportExeDir();
if (!expand_tool_spec) {
error.SetErrorString(
"could not get support executable directory for lldb-argdumper tool");
return error;

View File

@@ -118,8 +118,8 @@ FileSpec HostInfoMacOSX::GetProgramFileSpec() {
}
bool HostInfoMacOSX::ComputeSupportExeDirectory(FileSpec &file_spec) {
FileSpec lldb_file_spec;
if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
FileSpec lldb_file_spec = GetShlibDir();
if (!lldb_file_spec)
return false;
std::string raw_path = lldb_file_spec.GetPath();
@@ -171,8 +171,8 @@ bool HostInfoMacOSX::ComputeSupportExeDirectory(FileSpec &file_spec) {
}
bool HostInfoMacOSX::ComputeHeaderDirectory(FileSpec &file_spec) {
FileSpec lldb_file_spec;
if (!HostInfo::GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
FileSpec lldb_file_spec = GetShlibDir();
if (!lldb_file_spec)
return false;
std::string raw_path = lldb_file_spec.GetPath();
@@ -190,8 +190,8 @@ bool HostInfoMacOSX::ComputeHeaderDirectory(FileSpec &file_spec) {
bool HostInfoMacOSX::ComputePythonDirectory(FileSpec &file_spec) {
#ifndef LLDB_DISABLE_PYTHON
FileSpec lldb_file_spec;
if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
FileSpec lldb_file_spec = GetShlibDir();
if (!lldb_file_spec)
return false;
std::string raw_path = lldb_file_spec.GetPath();
@@ -219,8 +219,8 @@ bool HostInfoMacOSX::ComputePythonDirectory(FileSpec &file_spec) {
}
bool HostInfoMacOSX::ComputeSystemPluginsDirectory(FileSpec &file_spec) {
FileSpec lldb_file_spec;
if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
FileSpec lldb_file_spec = GetShlibDir();
if (!lldb_file_spec)
return false;
std::string raw_path = lldb_file_spec.GetPath();

View File

@@ -129,8 +129,8 @@ bool HostInfoPosix::ComputePathRelativeToLibrary(FileSpec &file_spec,
llvm::StringRef dir) {
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
FileSpec lldb_file_spec;
if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
FileSpec lldb_file_spec = GetShlibDir();
if (!lldb_file_spec)
return false;
std::string raw_path = lldb_file_spec.GetPath();
@@ -174,8 +174,8 @@ bool HostInfoPosix::ComputeHeaderDirectory(FileSpec &file_spec) {
bool HostInfoPosix::ComputePythonDirectory(FileSpec &file_spec) {
#ifndef LLDB_DISABLE_PYTHON
FileSpec lldb_file_spec;
if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
FileSpec lldb_file_spec = GetShlibDir();
if (!lldb_file_spec)
return false;
char raw_path[PATH_MAX];

View File

@@ -127,14 +127,10 @@ Status PipePosix::CreateWithUniqueName(llvm::StringRef prefix,
llvm::SmallVectorImpl<char> &name) {
llvm::SmallString<PATH_MAX> named_pipe_path;
llvm::SmallString<PATH_MAX> pipe_spec((prefix + ".%%%%%%").str());
FileSpec tmpdir_file_spec;
tmpdir_file_spec.Clear();
if (HostInfo::GetLLDBPath(ePathTypeLLDBTempSystemDir, tmpdir_file_spec)) {
tmpdir_file_spec.AppendPathComponent(pipe_spec.c_str());
} else {
FileSpec tmpdir_file_spec = HostInfo::GetProcessTempDir();
if (!tmpdir_file_spec)
tmpdir_file_spec.AppendPathComponent("/tmp");
tmpdir_file_spec.AppendPathComponent(pipe_spec.c_str());
}
tmpdir_file_spec.AppendPathComponent(pipe_spec);
// It's possible that another process creates the target path after we've
// verified it's available but before we create it, in which case we should

View File

@@ -182,9 +182,8 @@ HostThread Host::StartMonitoringChildProcess(
Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
Status error;
if (launch_info.GetFlags().Test(eLaunchFlagShellExpandArguments)) {
FileSpec expand_tool_spec;
if (!HostInfo::GetLLDBPath(lldb::ePathTypeSupportExecutableDir,
expand_tool_spec)) {
FileSpec expand_tool_spec = HostInfo::GetSupportExeDir();
if (!expand_tool_spec) {
error.SetErrorString("could not find support executable directory for "
"the lldb-argdumper tool");
return error;

View File

@@ -104,8 +104,8 @@ FileSpec HostInfoWindows::GetDefaultShell() {
}
bool HostInfoWindows::ComputePythonDirectory(FileSpec &file_spec) {
FileSpec lldb_file_spec;
if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
FileSpec lldb_file_spec = GetShlibDir();
if (!lldb_file_spec)
return false;
llvm::SmallString<64> path(lldb_file_spec.GetDirectory().AsCString());
llvm::sys::path::remove_filename(path);

View File

@@ -561,9 +561,7 @@ unsigned ClangExpressionParser::Parse(DiagnosticManager &diagnostic_manager) {
codegenoptions::FullDebugInfo) {
int temp_fd = -1;
llvm::SmallString<PATH_MAX> result_path;
FileSpec tmpdir_file_spec;
if (HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir,
tmpdir_file_spec)) {
if (FileSpec tmpdir_file_spec = HostInfo::GetProcessTempDir()) {
tmpdir_file_spec.AppendPathComponent("lldb-%%%%%%.expr");
std::string temp_source_path = tmpdir_file_spec.GetPath();
llvm::sys::fs::createUniqueFile(temp_source_path, temp_fd, result_path);

View File

@@ -115,10 +115,9 @@ bool lldb_private::ComputeClangDirectory(FileSpec &lldb_shlib_spec,
}
static bool ComputeClangDirectory(FileSpec &file_spec) {
FileSpec lldb_file_spec;
if (!HostInfo::GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
return false;
return ComputeClangDirectory(lldb_file_spec, file_spec, true);
if (FileSpec lldb_file_spec = HostInfo::GetShlibDir())
return ComputeClangDirectory(lldb_file_spec, file_spec, true);
return false;
}
#else // __APPLE__

View File

@@ -1132,11 +1132,11 @@ const char *PlatformDarwin::GetDeveloperDirectory() {
if (m_developer_directory.empty()) {
bool developer_dir_path_valid = false;
char developer_dir_path[PATH_MAX];
FileSpec temp_file_spec;
// Get the lldb framework's file path, and if it exists, truncate some
// components to only the developer directory path.
if (HostInfo::GetLLDBPath(ePathTypeLLDBShlibDir, temp_file_spec)) {
FileSpec temp_file_spec = HostInfo::GetShlibDir();
if (temp_file_spec) {
if (temp_file_spec.GetPath(developer_dir_path,
sizeof(developer_dir_path))) {
// e.g.

View File

@@ -173,7 +173,8 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
FileSpec fspec;
uint32_t versions[2];
if (objfile->GetSDKVersion(versions, sizeof(versions))) {
if (HostInfo::GetLLDBPath(ePathTypeLLDBShlibDir, fspec)) {
fspec = HostInfo::GetShlibDir();
if (fspec) {
std::string path;
xcode_contents_path = fspec.GetPath();
size_t pos = xcode_contents_path.find("/Xcode.app/Contents/");

View File

@@ -1008,8 +1008,8 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
bool debugserver_exists = debugserver_file_spec.Exists();
if (!debugserver_exists) {
// The debugserver binary is in the LLDB.framework/Resources directory.
if (HostInfo::GetLLDBPath(ePathTypeSupportExecutableDir,
debugserver_file_spec)) {
debugserver_file_spec = HostInfo::GetSupportExeDir();
if (debugserver_file_spec) {
debugserver_file_spec.AppendPathComponent(DEBUGSERVER_BASENAME);
debugserver_exists = debugserver_file_spec.Exists();
if (debugserver_exists) {

View File

@@ -534,7 +534,7 @@ const FileSpec &GDBRemoteCommunicationServerPlatform::GetDomainSocketDir() {
if (domainsocket_dir_env != nullptr)
g_domainsocket_dir = FileSpec(domainsocket_dir_env, false);
else
HostInfo::GetLLDBPath(ePathTypeLLDBTempSystemDir, g_domainsocket_dir);
g_domainsocket_dir = HostInfo::GetProcessTempDir();
});
return g_domainsocket_dir;

View File

@@ -3094,14 +3094,13 @@ void ScriptInterpreterPython::InitializePrivate() {
PyRun_SimpleString("import sys");
AddToSysPath(AddLocation::End, ".");
FileSpec file_spec;
// Don't denormalize paths when calling file_spec.GetPath(). On platforms
// that use a backslash as the path separator, this will result in executing
// python code containing paths with unescaped backslashes. But Python also
// accepts forward slashes, so to make life easier we just use that.
if (HostInfo::GetLLDBPath(ePathTypePythonDir, file_spec))
if (FileSpec file_spec = HostInfo::GetPythonDir())
AddToSysPath(AddLocation::Beginning, file_spec.GetPath(false));
if (HostInfo::GetLLDBPath(ePathTypeLLDBShlibDir, file_spec))
if (FileSpec file_spec = HostInfo::GetShlibDir())
AddToSysPath(AddLocation::Beginning, file_spec.GetPath(false));
PyRun_SimpleString("sys.dont_write_bytecode = 1; import "

View File

@@ -68,8 +68,7 @@ void ModuleCacheTest::SetUpTestCase() {
HostInfo::Initialize();
ObjectFileELF::Initialize();
FileSpec tmpdir_spec;
HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir, s_cache_dir);
s_cache_dir = HostInfo::GetProcessTempDir();
s_test_executable = GetInputFilePath(module_name);
}