LLDB mainline
HostInfoAndroid.cpp
Go to the documentation of this file.
1//===-- HostInfoAndroid.cpp -----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
12#include "llvm/ADT/SmallVector.h"
13#include "llvm/ADT/StringRef.h"
14
15using namespace lldb_private;
16using namespace llvm;
17
19 ArchSpec &arch_64) {
21
22 if (arch_32.IsValid()) {
23 arch_32.GetTriple().setEnvironment(llvm::Triple::Android);
24 }
25 if (arch_64.IsValid()) {
26 arch_64.GetTriple().setEnvironment(llvm::Triple::Android);
27 }
28}
29
31 return FileSpec("/system/bin/sh");
32}
33
34FileSpec HostInfoAndroid::ResolveLibraryPath(const std::string &module_path,
35 const ArchSpec &arch) {
36 static const char *const ld_library_path_separator = ":";
37 static const char *const default_lib32_path[] = {"/vendor/lib", "/system/lib",
38 nullptr};
39 static const char *const default_lib64_path[] = {"/vendor/lib64",
40 "/system/lib64", nullptr};
41
42 if (module_path.empty() || module_path[0] == '/') {
43 FileSpec file_spec(module_path.c_str());
44 FileSystem::Instance().Resolve(file_spec);
45 return file_spec;
46 }
47
48 SmallVector<StringRef, 4> ld_paths;
49
50 if (const char *ld_library_path = ::getenv("LD_LIBRARY_PATH"))
51 StringRef(ld_library_path)
52 .split(ld_paths, StringRef(ld_library_path_separator), -1, false);
53
54 const char *const *default_lib_path = nullptr;
55 switch (arch.GetAddressByteSize()) {
56 case 4:
57 default_lib_path = default_lib32_path;
58 break;
59 case 8:
60 default_lib_path = default_lib64_path;
61 break;
62 default:
63 assert(false && "Unknown address byte size");
64 return FileSpec();
65 }
66
67 for (const char *const *it = default_lib_path; *it; ++it)
68 ld_paths.push_back(StringRef(*it));
69
70 for (const StringRef &path : ld_paths) {
71 FileSpec file_candidate(path.str().c_str());
72 FileSystem::Instance().Resolve(file_candidate);
73 file_candidate.AppendPathComponent(module_path.c_str());
74
75 if (FileSystem::Instance().Exists(file_candidate))
76 return file_candidate;
77 }
78
79 return FileSpec();
80}
81
83 bool success = HostInfoLinux::ComputeTempFileBaseDirectory(file_spec);
84
85 // On Android, there is no path which is guaranteed to be writable. If the
86 // user has not provided a path via an environment variable, the generic
87 // algorithm will deduce /tmp, which is plain wrong. In that case we have an
88 // invalid directory, we substitute the path with /data/local/tmp, which is
89 // correct at least in some cases (i.e., when running as shell user).
90 if (!success || !FileSystem::Instance().Exists(file_spec))
91 file_spec = FileSpec("/data/local/tmp");
92
93 return FileSystem::Instance().Exists(file_spec);
94}
An architecture specification class.
Definition: ArchSpec.h:31
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:691
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:348
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:450
A file utility class.
Definition: FileSpec.h:56
void AppendPathComponent(llvm::StringRef component)
Definition: FileSpec.cpp:447
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
static bool ComputeTempFileBaseDirectory(FileSpec &file_spec)
static FileSpec ResolveLibraryPath(const std::string &path, const ArchSpec &arch)
static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
static bool ComputeTempFileBaseDirectory(FileSpec &file_spec)
static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: Debugger.h:53