forked from OSchip/llvm-project
Fix temporary directory computation on linux (pr25147)
On linux, the environment variables for temp directories that lldb checks for are generally not defined, and the temp directory computation failed. This caused expression evaluation to fall back to creating "/tmp/lldb-*.expr" debugging files instead of the usual "$TMP/lldb/pid/lldb-*.expr". Crucially, these files were not cleaned up on lldb exit, which caused clutter in the /tmp folder, especially on long-running machines (e.g. builtbots). This commit fixes lldb to use llvm::sys::path::system_temp_directory, which does the same environment variable dance, but (!) also falls back to the P_tmpdir macro, which is how the temp directory is defined on linux. Since the linux temp path computation now succeeds, I needed to also modify Android path computation to check for actual directory existence, rather then checking whether the operation failed. llvm-svn: 250409
This commit is contained in:
parent
90428328ee
commit
33ef8acbbd
|
@ -91,11 +91,14 @@ HostInfoAndroid::ResolveLibraryPath(const std::string& module_path, const ArchSp
|
||||||
bool
|
bool
|
||||||
HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec &file_spec)
|
HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec &file_spec)
|
||||||
{
|
{
|
||||||
if (HostInfoLinux::ComputeTempFileBaseDirectory(file_spec))
|
bool success = HostInfoLinux::ComputeTempFileBaseDirectory(file_spec);
|
||||||
return true;
|
|
||||||
|
|
||||||
// If the default mechanism for computing the temp directory failed then
|
// On Android, there is no path which is guaranteed to be writable. If the user has not
|
||||||
// fall back to /data/local/tmp
|
// provided a path via an environment variable, the generic algorithm will deduce /tmp, which
|
||||||
file_spec = FileSpec("/data/local/tmp", false);
|
// is plain wrong. In that case we have an invalid directory, we substitute the path with
|
||||||
return true;
|
// /data/local/tmp, which is correct at least in some cases (i.e., when running as shell user).
|
||||||
|
if (!success || !file_spec.Exists())
|
||||||
|
file_spec = FileSpec("/data/local/tmp", false);
|
||||||
|
|
||||||
|
return file_spec.Exists();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "llvm/ADT/Triple.h"
|
#include "llvm/ADT/Triple.h"
|
||||||
#include "llvm/ADT/StringExtras.h"
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/Support/Host.h"
|
#include "llvm/Support/Host.h"
|
||||||
|
#include "llvm/Support/Path.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
@ -344,19 +345,9 @@ HostInfoBase::ComputeProcessTempFileDirectory(FileSpec &file_spec)
|
||||||
bool
|
bool
|
||||||
HostInfoBase::ComputeTempFileBaseDirectory(FileSpec &file_spec)
|
HostInfoBase::ComputeTempFileBaseDirectory(FileSpec &file_spec)
|
||||||
{
|
{
|
||||||
file_spec.Clear();
|
llvm::SmallVector<char, 16> tmpdir;
|
||||||
|
llvm::sys::path::system_temp_directory(/*ErasedOnReboot*/ true, tmpdir);
|
||||||
const char *tmpdir_cstr = getenv("TMPDIR");
|
file_spec = FileSpec(std::string(tmpdir.data(), tmpdir.size()), true);
|
||||||
if (tmpdir_cstr == nullptr)
|
|
||||||
{
|
|
||||||
tmpdir_cstr = getenv("TMP");
|
|
||||||
if (tmpdir_cstr == nullptr)
|
|
||||||
tmpdir_cstr = getenv("TEMP");
|
|
||||||
}
|
|
||||||
if (!tmpdir_cstr)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
file_spec = FileSpec(tmpdir_cstr, false);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue