blob: a5695f686a339e69573d6703a04e08c219f402fc [file] [log] [blame]
Tamas Berghammer00e305d2015-02-12 18:13:44 +00001//===-- 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"
11#include "lldb/Host/linux/HostInfoLinux.h"
Tamas Berghammerdad4db72015-03-13 11:16:08 +000012#include "llvm/ADT/SmallVector.h"
13#include "llvm/ADT/StringRef.h"
Tamas Berghammer00e305d2015-02-12 18:13:44 +000014
15using namespace lldb_private;
Tamas Berghammerdad4db72015-03-13 11:16:08 +000016using namespace llvm;
Tamas Berghammer00e305d2015-02-12 18:13:44 +000017
18void
19HostInfoAndroid::ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
20{
21 HostInfoLinux::ComputeHostArchitectureSupport(arch_32, arch_64);
22
23 if (arch_32.IsValid())
24 {
25 arch_32.GetTriple().setEnvironment(llvm::Triple::Android);
26 }
27 if (arch_64.IsValid())
28 {
29 arch_64.GetTriple().setEnvironment(llvm::Triple::Android);
30 }
31}
Oleksiy Vyalovfb9015d2015-02-26 02:50:14 +000032
Tamas Berghammerbd051082015-03-03 12:14:45 +000033FileSpec
34HostInfoAndroid::GetDefaultShell()
35{
36 return FileSpec("/system/bin/sh", false);
37}
Tamas Berghammerdad4db72015-03-13 11:16:08 +000038
39FileSpec
40HostInfoAndroid::ResolveLibraryPath(const std::string& module_path, const ArchSpec& arch)
41{
42 static const char* const ld_library_path_separator = ":";
43 static const char* const default_lib32_path[] = {
44 "/vendor/lib",
45 "/system/lib",
46 nullptr
47 };
48 static const char* const default_lib64_path[] = {
49 "/vendor/lib64",
50 "/system/lib64",
51 nullptr
52 };
53
54 if (module_path.empty() || module_path[0] == '/')
55 return FileSpec(module_path.c_str(), true);
56
57 SmallVector<StringRef, 4> ld_paths;
58
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);
61
62 const char* const* default_lib_path = nullptr;
63 switch (arch.GetAddressByteSize())
64 {
65 case 4:
66 default_lib_path = default_lib32_path;
67 break;
68 case 8:
69 default_lib_path = default_lib64_path;
70 break;
71 default:
72 assert(false && "Unknown address byte size");
73 return FileSpec();
74 }
75
76 for(const char* const* it = default_lib_path; *it; ++it)
77 ld_paths.push_back(StringRef(*it));
78
79 for (const StringRef& path : ld_paths)
80 {
81 FileSpec file_candidate(path.str().c_str(), true);
82 file_candidate.AppendPathComponent(module_path.c_str());
83
84 if (file_candidate.Exists())
85 return file_candidate;
86 }
87
88 return FileSpec();
89}
Tamas Berghammerf3a24322015-05-08 12:46:26 +000090
91bool
92HostInfoAndroid::ComputeTempFileBaseDirectory(FileSpec &file_spec)
93{
94 if (HostInfoLinux::ComputeTempFileBaseDirectory(file_spec))
95 return true;
96
97 // If the default mechanism for computing the temp directory failed then
98 // fall back to /data/local/tmp
99 file_spec = FileSpec("/data/local/tmp", false);
100 return true;
101}