1 //===-- HostInfoAndroid.cpp -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Host/android/HostInfoAndroid.h"
11 #include "lldb/Host/linux/HostInfoLinux.h"
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/StringRef.h"
15 using namespace lldb_private;
19 HostInfoAndroid::ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
21 HostInfoLinux::ComputeHostArchitectureSupport(arch_32, arch_64);
23 if (arch_32.IsValid())
25 arch_32.GetTriple().setEnvironment(llvm::Triple::Android);
27 if (arch_64.IsValid())
29 arch_64.GetTriple().setEnvironment(llvm::Triple::Android);
34 HostInfoAndroid::GetDefaultShell()
36 return FileSpec("/system/bin/sh", false);
40 HostInfoAndroid::ResolveLibraryPath(const std::string& module_path, const ArchSpec& arch)
42 static const char* const ld_library_path_separator = ":";
43 static const char* const default_lib32_path[] = {
48 static const char* const default_lib64_path[] = {
54 if (module_path.empty() || module_path[0] == '/')
55 return FileSpec(module_path.c_str(), true);
57 SmallVector<StringRef, 4> ld_paths;
59 if (const char* ld_library_path = ::getenv("LD_LIBRARY_PATH"))
60 StringRef(ld_library_path).split(ld_paths, StringRef(ld_library_path_separator), -1, false);
62 const char* const* default_lib_path = nullptr;
63 switch (arch.GetAddressByteSize())
66 default_lib_path = default_lib32_path;
69 default_lib_path = default_lib64_path;
72 assert(false && "Unknown address byte size");
76 for(const char* const* it = default_lib_path; *it; ++it)
77 ld_paths.push_back(StringRef(*it));
79 for (const StringRef& path : ld_paths)
81 FileSpec file_candidate(path.str().c_str(), true);
82 file_candidate.AppendPathComponent(module_path.c_str());
84 if (file_candidate.Exists())
85 return file_candidate;
92 HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec &file_spec)
94 bool success = HostInfoLinux::ComputeTempFileBaseDirectory(file_spec);
96 // On Android, there is no path which is guaranteed to be writable. If the user has not
97 // provided a path via an environment variable, the generic algorithm will deduce /tmp, which
98 // is plain wrong. In that case we have an invalid directory, we substitute the path with
99 // /data/local/tmp, which is correct at least in some cases (i.e., when running as shell user).
100 if (!success || !file_spec.Exists())
101 file_spec = FileSpec("/data/local/tmp", false);
103 return file_spec.Exists();