blob: b819f92e95fcdbdffbc3a19f5157fe71899710c6 [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
33bool
34HostInfoAndroid::ComputeSupportExeDirectory(FileSpec &file_spec)
35{
36 file_spec.GetDirectory() = HostInfoLinux::GetProgramFileSpec().GetDirectory();
37 return (bool)file_spec.GetDirectory();
38}
Tamas Berghammerbd051082015-03-03 12:14:45 +000039
40FileSpec
41HostInfoAndroid::GetDefaultShell()
42{
43 return FileSpec("/system/bin/sh", false);
44}
Tamas Berghammerdad4db72015-03-13 11:16:08 +000045
46FileSpec
47HostInfoAndroid::ResolveLibraryPath(const std::string& module_path, const ArchSpec& arch)
48{
49 static const char* const ld_library_path_separator = ":";
50 static const char* const default_lib32_path[] = {
51 "/vendor/lib",
52 "/system/lib",
53 nullptr
54 };
55 static const char* const default_lib64_path[] = {
56 "/vendor/lib64",
57 "/system/lib64",
58 nullptr
59 };
60
61 if (module_path.empty() || module_path[0] == '/')
62 return FileSpec(module_path.c_str(), true);
63
64 SmallVector<StringRef, 4> ld_paths;
65
66 if (const char* ld_library_path = ::getenv("LD_LIBRARY_PATH"))
67 StringRef(ld_library_path).split(ld_paths, StringRef(ld_library_path_separator), -1, false);
68
69 const char* const* default_lib_path = nullptr;
70 switch (arch.GetAddressByteSize())
71 {
72 case 4:
73 default_lib_path = default_lib32_path;
74 break;
75 case 8:
76 default_lib_path = default_lib64_path;
77 break;
78 default:
79 assert(false && "Unknown address byte size");
80 return FileSpec();
81 }
82
83 for(const char* const* it = default_lib_path; *it; ++it)
84 ld_paths.push_back(StringRef(*it));
85
86 for (const StringRef& path : ld_paths)
87 {
88 FileSpec file_candidate(path.str().c_str(), true);
89 file_candidate.AppendPathComponent(module_path.c_str());
90
91 if (file_candidate.Exists())
92 return file_candidate;
93 }
94
95 return FileSpec();
96}