28using namespace std::chrono;
34#define LLDB_PROPERTIES_android
35#include "PlatformAndroidProperties.inc"
38#define LLDB_PROPERTIES_android
39#include "PlatformAndroidPropertiesEnum.inc"
45 m_collection_sp = std::make_shared<OptionValueProperties>(
47 m_collection_sp->Initialize(g_android_properties);
52 static PluginProperties g_settings;
57const unsigned int g_android_default_cache_size =
63 PlatformLinux::Initialize();
66#if defined(__ANDROID__)
68 default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
85 PlatformLinux::Terminate();
91 const char *arch_name;
97 const char *triple_cstr =
98 arch ? arch->
GetTriple().getTriple().c_str() :
"<null>";
100 LLDB_LOGF(log,
"PlatformAndroid::%s(force=%s, arch={%s,%s})", __FUNCTION__,
101 force ?
"true" :
"false", arch_name, triple_cstr);
105 if (!create && arch && arch->
IsValid()) {
106 const llvm::Triple &triple = arch->
GetTriple();
107 switch (triple.getVendor()) {
108 case llvm::Triple::PC:
112#if defined(__ANDROID__)
116 case llvm::Triple::VendorType::UnknownVendor:
125 switch (triple.getEnvironment()) {
126 case llvm::Triple::Android:
129#if defined(__ANDROID__)
133 case llvm::Triple::EnvironmentType::UnknownEnvironment:
145 LLDB_LOGF(log,
"PlatformAndroid::%s() creating remote-android platform",
151 log,
"PlatformAndroid::%s() aborting creation of remote-android platform",
162 "Properties for the Android platform plugin.",
168 : PlatformLinux(is_host), m_sdk_version(0) {}
172 return "Local Android user platform plug-in.";
173 return "Remote Android user platform plug-in.";
180 return Status(
"can't connect to the host platform, always connected");
187 return Status(
"URL is null.");
188 std::optional<URI> parsed_url =
URI::Parse(url);
190 return Status(
"Invalid URL: %s", url);
191 if (parsed_url->hostname !=
"localhost")
194 auto error = PlatformLinux::ConnectRemote(args);
195 if (
error.Success()) {
209 return PlatformLinux::GetFile(source, destination);
221 uint32_t mode = 0, size = 0, mtime = 0;
222 error = sync_service->Stat(source_spec, mode, size, mtime);
227 return sync_service->PullFile(source_spec, destination);
229 std::string source_file = source_spec.
GetPath(
false);
232 LLDB_LOGF(log,
"Got mode == 0 on '%s': try to get file via 'shell cat'",
233 source_file.c_str());
235 if (strchr(source_file.c_str(),
'\'') !=
nullptr)
236 return Status(
"Doesn't support single-quotes in filenames");
245 snprintf(cmd,
sizeof(cmd),
"%scat '%s'",
GetRunAs().c_str(),
246 source_file.c_str());
248 return adb->ShellToFile(cmd, minutes(1), destination);
252 const FileSpec &destination, uint32_t uid,
255 return PlatformLinux::PutFile(source, destination, uid, gid);
257 FileSpec destination_spec(destination.
GetPath(
false), FileSpec::Style::posix);
260 destination_spec.
GetPath(
false));
267 return sync_service->PushFile(source, destination_spec);
273 const uint64_t src_offset,
274 const uint64_t src_size,
279 return GetFile(src_file_spec, dst_file_spec);
281 std::string source_file = src_file_spec.
GetPath(
false);
282 if (source_file.find(
'\'') != std::string::npos)
283 return Status(
"Doesn't support single-quotes in filenames");
287 static constexpr llvm::StringLiteral k_zip_separator(
"!/");
288 size_t pos = source_file.find(k_zip_separator);
289 if (pos != std::string::npos)
290 source_file.resize(pos);
299 snprintf(cmd,
sizeof(cmd),
300 "%sdd if='%s' iflag=skip_bytes,count_bytes "
301 "skip=%" PRIu64
" count=%" PRIu64
" status=none",
302 GetRunAs().c_str(), source_file.c_str(), src_offset, src_size);
304 return adb->ShellToFile(cmd, minutes(1), dst_file_spec);
309 if (
error.Success()) {
317 return g_android_default_cache_size;
327 std::string version_string;
333 adb->Shell(
"getprop ro.build.version.sdk", seconds(5), &version_string);
334 version_string = llvm::StringRef(version_string).trim().str();
336 if (
error.Fail() || version_string.empty()) {
338 LLDB_LOGF(log,
"Get SDK version failed. (error: %s, output: %s)",
339 error.AsCString(), version_string.c_str());
351 llvm::StringRef extension = module_sp->GetFileSpec().GetFileNameExtension();
352 if (extension !=
".oat" && extension !=
".odex")
354 "Symbol file downloading only supported for oat and odex files");
357 if (!module_sp->GetPlatformFileSpec())
358 return Status(
"No platform file specified");
362 return Status(
"Symbol file generation only supported on SDK 23+");
365 if (module_sp->GetSectionList()->FindSectionByName(
ConstString(
".symtab")) !=
367 return Status(
"Symtab already available in the module");
374 error = adb->Shell(
"mktemp --directory --tmpdir /data/local/tmp", seconds(5),
376 if (
error.Fail() || tmpdir.empty())
377 return Status(
"Failed to generate temporary directory on the device (%s)",
379 tmpdir = llvm::StringRef(tmpdir).trim().str();
382 std::unique_ptr<std::string, std::function<void(std::string *)>>
383 tmpdir_remover(&tmpdir, [&adb](std::string *s) {
385 command.
Printf(
"rm -rf %s", s->c_str());
389 if (log &&
error.Fail())
390 LLDB_LOGF(log,
"Failed to remove temp directory: %s",
394 FileSpec symfile_platform_filespec(tmpdir);
395 symfile_platform_filespec.AppendPathComponent(
"symbolized.oat");
399 command.
Printf(
"oatdump --symbolize=%s --output=%s",
400 module_sp->GetPlatformFileSpec().GetPath(
false).c_str(),
401 symfile_platform_filespec.GetPath(
false).c_str());
402 error = adb->Shell(command.
GetData(), minutes(1),
nullptr);
404 return Status(
"Oatdump failed: %s",
error.AsCString());
407 return GetFile(symfile_platform_filespec, dst_file_spec);
418 std::vector<const char *> dl_open_names = {
"__dl_dlopen",
"dlopen"};
419 const char *dl_open_name =
nullptr;
421 for (
auto name : dl_open_names) {
423 ConstString(name), eFunctionNameTypeFull, matching_symbols);
424 if (matching_symbols.
GetSize()) {
430 if (dl_open_name == dl_open_names[0])
432 extern "C" void* dlopen(const char*, int) asm("__dl_dlopen");
433 extern "C" void* dlsym(void*, const char*) asm("__dl_dlsym");
434 extern "C" int dlclose(void*) asm("__dl_dlclose");
435 extern "C" char* dlerror(void) asm("__dl_dlerror");
452 ePropertyPlatformPackageName,
"");
457 if (!run_as.empty()) {
466 return std::string(
"run-as '") + run_as.str() +
"' ";
static llvm::raw_ostream & error(Stream &strm)
static DynamicLoaderDarwinKernelProperties & GetGlobalProperties()
#define LLDB_LOGF(log,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool TripleEnvironmentWasSpecified() const
bool TripleVendorWasSpecified() const
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
A command line argument class.
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
A class to manage flag bits.
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
bool IsRelative() const
Returns true if the filespec represents a relative path.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
ConstString GetPathAsConstString(bool denormalize=true) const
Get the full path as a ConstString.
void FindFunctionSymbols(ConstString name, lldb::FunctionNameType name_type_mask, SymbolContextList &sc_list)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static lldb::OptionValuePropertiesSP GetSettingForPlatformPlugin(Debugger &debugger, llvm::StringRef setting_name)
static bool CreateSettingForPlatformPlugin(Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
Target & GetTarget()
Get the target object pointer for this module.
T GetPropertyAtIndexAs(uint32_t idx, T default_value, const ExecutionContext *exe_ctx=nullptr) const
const char * GetData() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
const ModuleList & GetImages() const
Get accessor for the images for this process.
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Module > ModuleSP
static std::optional< URI > Parse(llvm::StringRef uri)