Tamas Berghammer | 00e305d | 2015-02-12 18:13:44 +0000 | [diff] [blame] | 1 | //===-- HostInfoAndroid.cpp -------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Host/android/HostInfoAndroid.h" |
Jonas Devlieghere | 60cf3f8 | 2018-11-01 17:35:31 +0000 | [diff] [blame] | 11 | #include "lldb/Host/FileSystem.h" |
Tamas Berghammer | 00e305d | 2015-02-12 18:13:44 +0000 | [diff] [blame] | 12 | #include "lldb/Host/linux/HostInfoLinux.h" |
Tamas Berghammer | dad4db7 | 2015-03-13 11:16:08 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/SmallVector.h" |
| 14 | #include "llvm/ADT/StringRef.h" |
Tamas Berghammer | 00e305d | 2015-02-12 18:13:44 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace lldb_private; |
Tamas Berghammer | dad4db7 | 2015-03-13 11:16:08 +0000 | [diff] [blame] | 17 | using namespace llvm; |
Tamas Berghammer | 00e305d | 2015-02-12 18:13:44 +0000 | [diff] [blame] | 18 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | void HostInfoAndroid::ComputeHostArchitectureSupport(ArchSpec &arch_32, |
| 20 | ArchSpec &arch_64) { |
| 21 | HostInfoLinux::ComputeHostArchitectureSupport(arch_32, arch_64); |
Tamas Berghammer | 00e305d | 2015-02-12 18:13:44 +0000 | [diff] [blame] | 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | if (arch_32.IsValid()) { |
| 24 | arch_32.GetTriple().setEnvironment(llvm::Triple::Android); |
| 25 | } |
| 26 | if (arch_64.IsValid()) { |
| 27 | arch_64.GetTriple().setEnvironment(llvm::Triple::Android); |
| 28 | } |
Tamas Berghammer | 00e305d | 2015-02-12 18:13:44 +0000 | [diff] [blame] | 29 | } |
Oleksiy Vyalov | fb9015d | 2015-02-26 02:50:14 +0000 | [diff] [blame] | 30 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | FileSpec HostInfoAndroid::GetDefaultShell() { |
Jonas Devlieghere | 99f2b99 | 2018-11-01 21:18:25 +0000 | [diff] [blame] | 32 | return FileSpec("/system/bin/sh"); |
Tamas Berghammer | bd05108 | 2015-03-03 12:14:45 +0000 | [diff] [blame] | 33 | } |
Tamas Berghammer | dad4db7 | 2015-03-13 11:16:08 +0000 | [diff] [blame] | 34 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | FileSpec HostInfoAndroid::ResolveLibraryPath(const std::string &module_path, |
| 36 | const ArchSpec &arch) { |
| 37 | static const char *const ld_library_path_separator = ":"; |
| 38 | static const char *const default_lib32_path[] = {"/vendor/lib", "/system/lib", |
| 39 | nullptr}; |
| 40 | static const char *const default_lib64_path[] = {"/vendor/lib64", |
| 41 | "/system/lib64", nullptr}; |
Tamas Berghammer | dad4db7 | 2015-03-13 11:16:08 +0000 | [diff] [blame] | 42 | |
Jonas Devlieghere | 7010ef3 | 2018-11-08 23:21:00 +0000 | [diff] [blame] | 43 | if (module_path.empty() || module_path[0] == '/') { |
| 44 | FileSpec file_spec(module_path.c_str()); |
| 45 | FileSystem::Instance().Resolve(file_spec); |
| 46 | return file_spec; |
| 47 | } |
Tamas Berghammer | dad4db7 | 2015-03-13 11:16:08 +0000 | [diff] [blame] | 48 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | SmallVector<StringRef, 4> ld_paths; |
Tamas Berghammer | dad4db7 | 2015-03-13 11:16:08 +0000 | [diff] [blame] | 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | if (const char *ld_library_path = ::getenv("LD_LIBRARY_PATH")) |
| 52 | StringRef(ld_library_path) |
| 53 | .split(ld_paths, StringRef(ld_library_path_separator), -1, false); |
Tamas Berghammer | dad4db7 | 2015-03-13 11:16:08 +0000 | [diff] [blame] | 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | const char *const *default_lib_path = nullptr; |
| 56 | switch (arch.GetAddressByteSize()) { |
| 57 | case 4: |
| 58 | default_lib_path = default_lib32_path; |
| 59 | break; |
| 60 | case 8: |
| 61 | default_lib_path = default_lib64_path; |
| 62 | break; |
| 63 | default: |
| 64 | assert(false && "Unknown address byte size"); |
Tamas Berghammer | dad4db7 | 2015-03-13 11:16:08 +0000 | [diff] [blame] | 65 | return FileSpec(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | for (const char *const *it = default_lib_path; *it; ++it) |
| 69 | ld_paths.push_back(StringRef(*it)); |
| 70 | |
| 71 | for (const StringRef &path : ld_paths) { |
Jonas Devlieghere | 99f2b99 | 2018-11-01 21:18:25 +0000 | [diff] [blame] | 72 | FileSpec file_candidate(path.str().c_str()); |
| 73 | FileSystem::Instance().Resolve(file_candidate); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | file_candidate.AppendPathComponent(module_path.c_str()); |
| 75 | |
Jonas Devlieghere | 60cf3f8 | 2018-11-01 17:35:31 +0000 | [diff] [blame] | 76 | if (FileSystem::Instance().Exists(file_candidate)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | return file_candidate; |
| 78 | } |
| 79 | |
| 80 | return FileSpec(); |
Tamas Berghammer | dad4db7 | 2015-03-13 11:16:08 +0000 | [diff] [blame] | 81 | } |
Tamas Berghammer | f3a2432 | 2015-05-08 12:46:26 +0000 | [diff] [blame] | 82 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 83 | bool HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec &file_spec) { |
| 84 | bool success = HostInfoLinux::ComputeTempFileBaseDirectory(file_spec); |
Tamas Berghammer | f3a2432 | 2015-05-08 12:46:26 +0000 | [diff] [blame] | 85 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 86 | // On Android, there is no path which is guaranteed to be writable. If the |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 87 | // user has not provided a path via an environment variable, the generic |
| 88 | // algorithm will deduce /tmp, which is plain wrong. In that case we have an |
| 89 | // invalid directory, we substitute the path with /data/local/tmp, which is |
| 90 | // correct at least in some cases (i.e., when running as shell user). |
Jonas Devlieghere | 60cf3f8 | 2018-11-01 17:35:31 +0000 | [diff] [blame] | 91 | if (!success || !FileSystem::Instance().Exists(file_spec)) |
Jonas Devlieghere | 99f2b99 | 2018-11-01 21:18:25 +0000 | [diff] [blame] | 92 | file_spec = FileSpec("/data/local/tmp"); |
Pavel Labath | 3318314 | 2015-10-16 09:32:05 +0000 | [diff] [blame] | 93 | |
Jonas Devlieghere | 60cf3f8 | 2018-11-01 17:35:31 +0000 | [diff] [blame] | 94 | return FileSystem::Instance().Exists(file_spec); |
Tamas Berghammer | f3a2432 | 2015-05-08 12:46:26 +0000 | [diff] [blame] | 95 | } |