[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:23:27 +01:00
|
|
|
//===-- PlatformAndroid.cpp -----------------------------------------------===//
|
2015-02-12 18:13:44 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-02-12 18:13:44 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-08-12 11:10:25 +00:00
|
|
|
#include "lldb/Core/Module.h"
|
2015-02-12 18:13:44 +00:00
|
|
|
#include "lldb/Core/PluginManager.h"
|
2015-08-12 11:10:25 +00:00
|
|
|
#include "lldb/Core/Section.h"
|
2015-12-02 11:58:51 +00:00
|
|
|
#include "lldb/Core/ValueObject.h"
|
2015-02-16 10:34:30 +00:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
2022-02-03 13:26:10 +01:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2017-03-03 20:56:28 +00:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-08-07 11:07:21 +00:00
|
|
|
#include "lldb/Utility/Scalar.h"
|
2017-02-10 12:21:22 +00:00
|
|
|
#include "lldb/Utility/UriParser.h"
|
2015-02-12 18:13:44 +00:00
|
|
|
|
2015-03-25 17:58:13 +00:00
|
|
|
#include "AdbClient.h"
|
2015-02-12 18:13:44 +00:00
|
|
|
#include "PlatformAndroid.h"
|
|
|
|
#include "PlatformAndroidRemoteGDBServer.h"
|
2017-08-14 16:39:16 +00:00
|
|
|
#include "lldb/Target/Target.h"
|
2015-02-12 18:13:44 +00:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
2015-03-31 09:52:22 +00:00
|
|
|
using namespace lldb_private::platform_android;
|
2016-11-24 14:11:47 +00:00
|
|
|
using namespace std::chrono;
|
2015-02-12 18:13:44 +00:00
|
|
|
|
2020-02-14 09:46:02 -08:00
|
|
|
LLDB_PLUGIN_DEFINE(PlatformAndroid)
|
2020-02-07 14:58:18 -08:00
|
|
|
|
2015-02-12 18:13:44 +00:00
|
|
|
static uint32_t g_initialize_count = 0;
|
2015-10-20 10:33:17 +00:00
|
|
|
static const unsigned int g_android_default_cache_size =
|
|
|
|
2048; // Fits inside 4k adb packet.
|
2015-02-12 18:13:44 +00:00
|
|
|
|
|
|
|
void PlatformAndroid::Initialize() {
|
2015-02-12 18:18:27 +00:00
|
|
|
PlatformLinux::Initialize();
|
|
|
|
|
2015-02-12 18:13:44 +00:00
|
|
|
if (g_initialize_count++ == 0) {
|
2015-02-16 10:34:30 +00:00
|
|
|
#if defined(__ANDROID__)
|
|
|
|
PlatformSP default_platform_sp(new PlatformAndroid(true));
|
|
|
|
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
|
|
|
|
Platform::SetHostPlatform(default_platform_sp);
|
|
|
|
#endif
|
|
|
|
PluginManager::RegisterPlugin(
|
|
|
|
PlatformAndroid::GetPluginNameStatic(false),
|
|
|
|
PlatformAndroid::GetPluginDescriptionStatic(false),
|
2015-02-12 18:13:44 +00:00
|
|
|
PlatformAndroid::CreateInstance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlatformAndroid::Terminate() {
|
|
|
|
if (g_initialize_count > 0) {
|
|
|
|
if (--g_initialize_count == 0) {
|
|
|
|
PluginManager::UnregisterPlugin(PlatformAndroid::CreateInstance);
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-02-12 18:18:27 +00:00
|
|
|
|
|
|
|
PlatformLinux::Terminate();
|
2015-02-12 18:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PlatformSP PlatformAndroid::CreateInstance(bool force, const ArchSpec *arch) {
|
2022-01-31 15:57:48 +01:00
|
|
|
Log *log = GetLog(LLDBLog::Platform);
|
2015-02-12 18:13:44 +00:00
|
|
|
if (log) {
|
|
|
|
const char *arch_name;
|
|
|
|
if (arch && arch->GetArchitectureName())
|
|
|
|
arch_name = arch->GetArchitectureName();
|
|
|
|
else
|
|
|
|
arch_name = "<null>";
|
|
|
|
|
|
|
|
const char *triple_cstr =
|
|
|
|
arch ? arch->GetTriple().getTriple().c_str() : "<null>";
|
|
|
|
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "PlatformAndroid::%s(force=%s, arch={%s,%s})", __FUNCTION__,
|
|
|
|
force ? "true" : "false", arch_name, triple_cstr);
|
2015-02-12 18:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool create = force;
|
2018-12-15 00:15:33 +00:00
|
|
|
if (!create && arch && arch->IsValid()) {
|
2015-02-12 18:13:44 +00:00
|
|
|
const llvm::Triple &triple = arch->GetTriple();
|
|
|
|
switch (triple.getVendor()) {
|
|
|
|
case llvm::Triple::PC:
|
|
|
|
create = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if defined(__ANDROID__)
|
2018-07-31 23:53:24 +00:00
|
|
|
// Only accept "unknown" for the vendor if the host is android and if
|
2018-04-30 16:49:04 +00:00
|
|
|
// "unknown" wasn't specified (it was just returned because it was NOT
|
2018-07-31 23:53:24 +00:00
|
|
|
// specified).
|
2015-02-12 18:13:44 +00:00
|
|
|
case llvm::Triple::VendorType::UnknownVendor:
|
|
|
|
create = !arch->TripleVendorWasSpecified();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-02-12 18:13:44 +00:00
|
|
|
if (create) {
|
2018-07-31 23:53:24 +00:00
|
|
|
switch (triple.getEnvironment()) {
|
2015-02-16 10:34:30 +00:00
|
|
|
case llvm::Triple::Android:
|
2015-02-12 18:13:44 +00:00
|
|
|
break;
|
2015-02-16 10:34:30 +00:00
|
|
|
|
2015-02-12 18:13:44 +00:00
|
|
|
#if defined(__ANDROID__)
|
2018-04-30 16:49:04 +00:00
|
|
|
// Only accept "unknown" for the OS if the host is android and it
|
|
|
|
// "unknown" wasn't specified (it was just returned because it was NOT
|
|
|
|
// specified)
|
2018-07-31 23:53:24 +00:00
|
|
|
case llvm::Triple::EnvironmentType::UnknownEnvironment:
|
|
|
|
create = !arch->TripleEnvironmentWasSpecified();
|
2015-02-12 18:13:44 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
create = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-02-12 18:13:44 +00:00
|
|
|
|
|
|
|
if (create) {
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "PlatformAndroid::%s() creating remote-android platform",
|
|
|
|
__FUNCTION__);
|
2015-02-12 18:13:44 +00:00
|
|
|
return PlatformSP(new PlatformAndroid(false));
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-02-12 18:13:44 +00:00
|
|
|
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(
|
|
|
|
log, "PlatformAndroid::%s() aborting creation of remote-android platform",
|
|
|
|
__FUNCTION__);
|
2015-02-12 18:13:44 +00:00
|
|
|
|
2015-08-12 11:10:19 +00:00
|
|
|
return PlatformSP();
|
2015-02-12 18:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PlatformAndroid::PlatformAndroid(bool is_host)
|
|
|
|
: PlatformLinux(is_host), m_sdk_version(0) {}
|
|
|
|
|
2021-10-21 21:00:33 +02:00
|
|
|
llvm::StringRef PlatformAndroid::GetPluginDescriptionStatic(bool is_host) {
|
2015-02-16 10:34:30 +00:00
|
|
|
if (is_host)
|
|
|
|
return "Local Android user platform plug-in.";
|
2021-10-21 21:00:33 +02:00
|
|
|
return "Remote Android user platform plug-in.";
|
2015-02-12 18:13:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status PlatformAndroid::ConnectRemote(Args &args) {
|
2015-08-12 11:10:19 +00:00
|
|
|
m_device_id.clear();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-10-15 13:07:39 +02:00
|
|
|
if (IsHost())
|
|
|
|
return Status("can't connect to the host platform, always connected");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-02-12 18:13:44 +00:00
|
|
|
if (!m_remote_platform_sp)
|
|
|
|
m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-05-01 16:49:28 +00:00
|
|
|
const char *url = args.GetArgumentAtIndex(0);
|
|
|
|
if (!url)
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("URL is null.");
|
2021-10-22 15:34:54 +02:00
|
|
|
llvm::Optional<URI> parsed_url = URI::Parse(url);
|
|
|
|
if (!parsed_url)
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Invalid URL: %s", url);
|
2021-10-22 15:34:54 +02:00
|
|
|
if (parsed_url->hostname != "localhost")
|
|
|
|
m_device_id = parsed_url->hostname.str();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-05-01 16:49:28 +00:00
|
|
|
auto error = PlatformLinux::ConnectRemote(args);
|
|
|
|
if (error.Success()) {
|
2016-07-06 17:02:42 +00:00
|
|
|
AdbClient adb;
|
|
|
|
error = AdbClient::CreateByDeviceID(m_device_id, adb);
|
2015-05-01 16:49:28 +00:00
|
|
|
if (error.Fail())
|
2015-03-25 17:58:13 +00:00
|
|
|
return error;
|
2015-02-16 10:34:30 +00:00
|
|
|
|
2015-10-22 19:17:32 +00:00
|
|
|
m_device_id = adb.GetDeviceID();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-03-25 17:58:13 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status PlatformAndroid::GetFile(const FileSpec &source,
|
|
|
|
const FileSpec &destination) {
|
2015-05-29 20:02:07 +00:00
|
|
|
if (IsHost() || !m_remote_platform_sp)
|
|
|
|
return PlatformLinux::GetFile(source, destination);
|
|
|
|
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSpec source_spec(source.GetPath(false), FileSpec::Style::posix);
|
2015-06-09 17:54:27 +00:00
|
|
|
if (source_spec.IsRelative())
|
2015-05-29 22:54:45 +00:00
|
|
|
source_spec = GetRemoteWorkingDirectory().CopyByAppendingPathComponent(
|
2022-07-25 23:29:30 -07:00
|
|
|
source_spec.GetPathAsConstString(false).GetStringRef());
|
2015-05-29 20:02:07 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2016-07-06 17:02:42 +00:00
|
|
|
auto sync_service = GetSyncService(error);
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
2016-07-08 17:45:37 +00:00
|
|
|
uint32_t mode = 0, size = 0, mtime = 0;
|
|
|
|
error = sync_service->Stat(source_spec, mode, size, mtime);
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if (mode != 0)
|
|
|
|
return sync_service->PullFile(source_spec, destination);
|
|
|
|
|
2022-07-25 23:29:30 -07:00
|
|
|
std::string source_file = source_spec.GetPath(false);
|
2016-07-08 17:45:37 +00:00
|
|
|
|
2022-01-31 15:57:48 +01:00
|
|
|
Log *log = GetLog(LLDBLog::Platform);
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "Got mode == 0 on '%s': try to get file via 'shell cat'",
|
2022-07-25 23:29:30 -07:00
|
|
|
source_file.c_str());
|
2016-07-08 17:45:37 +00:00
|
|
|
|
2022-07-25 23:29:30 -07:00
|
|
|
if (strchr(source_file.c_str(), '\'') != nullptr)
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Doesn't support single-quotes in filenames");
|
2016-07-08 17:45:37 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// mode == 0 can signify that adbd cannot access the file due security
|
|
|
|
// constraints - try "cat ..." as a fallback.
|
2016-07-08 17:45:37 +00:00
|
|
|
AdbClient adb(m_device_id);
|
|
|
|
|
|
|
|
char cmd[PATH_MAX];
|
2022-07-25 23:29:30 -07:00
|
|
|
snprintf(cmd, sizeof(cmd), "cat '%s'", source_file.c_str());
|
2016-07-08 17:45:37 +00:00
|
|
|
|
2016-11-24 14:11:47 +00:00
|
|
|
return adb.ShellToFile(cmd, minutes(1), destination);
|
2015-05-28 17:42:48 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status PlatformAndroid::PutFile(const FileSpec &source,
|
|
|
|
const FileSpec &destination, uint32_t uid,
|
|
|
|
uint32_t gid) {
|
2015-06-02 19:29:48 +00:00
|
|
|
if (IsHost() || !m_remote_platform_sp)
|
|
|
|
return PlatformLinux::PutFile(source, destination, uid, gid);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSpec destination_spec(destination.GetPath(false), FileSpec::Style::posix);
|
2015-06-09 17:54:27 +00:00
|
|
|
if (destination_spec.IsRelative())
|
2015-06-02 19:29:48 +00:00
|
|
|
destination_spec = GetRemoteWorkingDirectory().CopyByAppendingPathComponent(
|
2022-07-25 23:29:30 -07:00
|
|
|
destination_spec.GetPath(false));
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-06-02 19:29:48 +00:00
|
|
|
// TODO: Set correct uid and gid on remote file.
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2016-07-06 17:02:42 +00:00
|
|
|
auto sync_service = GetSyncService(error);
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
return sync_service->PushFile(source, destination_spec);
|
2015-05-27 02:18:50 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:58:13 +00:00
|
|
|
const char *PlatformAndroid::GetCacheHostname() { return m_device_id.c_str(); }
|
2015-05-18 23:44:06 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status PlatformAndroid::DownloadModuleSlice(const FileSpec &src_file_spec,
|
|
|
|
const uint64_t src_offset,
|
|
|
|
const uint64_t src_size,
|
|
|
|
const FileSpec &dst_file_spec) {
|
2015-05-18 23:44:06 +00:00
|
|
|
if (src_offset != 0)
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Invalid offset - %" PRIu64, src_offset);
|
2015-05-18 23:44:06 +00:00
|
|
|
|
2015-05-28 17:42:48 +00:00
|
|
|
return GetFile(src_file_spec, dst_file_spec);
|
2015-05-18 23:44:06 +00:00
|
|
|
}
|
2015-08-12 11:10:19 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status PlatformAndroid::DisconnectRemote() {
|
|
|
|
Status error = PlatformLinux::DisconnectRemote();
|
2015-08-12 11:10:19 +00:00
|
|
|
if (error.Success()) {
|
|
|
|
m_device_id.clear();
|
|
|
|
m_sdk_version = 0;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-10-20 10:33:17 +00:00
|
|
|
uint32_t PlatformAndroid::GetDefaultMemoryCacheLineSize() {
|
|
|
|
return g_android_default_cache_size;
|
|
|
|
}
|
|
|
|
|
2015-08-12 11:10:19 +00:00
|
|
|
uint32_t PlatformAndroid::GetSdkVersion() {
|
|
|
|
if (!IsConnected())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (m_sdk_version != 0)
|
|
|
|
return m_sdk_version;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-12 11:10:19 +00:00
|
|
|
std::string version_string;
|
2016-07-06 17:02:42 +00:00
|
|
|
AdbClient adb(m_device_id);
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error =
|
2016-11-24 14:11:47 +00:00
|
|
|
adb.Shell("getprop ro.build.version.sdk", seconds(5), &version_string);
|
2015-10-01 13:58:01 +00:00
|
|
|
version_string = llvm::StringRef(version_string).trim().str();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-10-01 13:58:01 +00:00
|
|
|
if (error.Fail() || version_string.empty()) {
|
2022-01-31 15:57:48 +01:00
|
|
|
Log *log = GetLog(LLDBLog::Platform);
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "Get SDK version failed. (error: %s, output: %s)",
|
|
|
|
error.AsCString(), version_string.c_str());
|
2015-08-12 11:10:19 +00:00
|
|
|
return 0;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 23:36:49 +02:00
|
|
|
// FIXME: improve error handling
|
|
|
|
llvm::to_integer(version_string, m_sdk_version);
|
2015-08-12 11:10:19 +00:00
|
|
|
return m_sdk_version;
|
|
|
|
}
|
2015-08-12 11:10:25 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
|
|
|
|
const FileSpec &dst_file_spec) {
|
2015-08-12 11:10:25 +00:00
|
|
|
// For oat file we can try to fetch additional debug info from the device
|
2016-07-06 16:40:09 +00:00
|
|
|
ConstString extension = module_sp->GetFileSpec().GetFileNameExtension();
|
Allow direct comparison of ConstString against StringRef
Summary:
When we want to compare a ConstString against a string literal (or any other non-ConstString),
we currently have to explicitly turn the other string into a ConstString. This makes sense as
comparing ConstStrings against each other is only a fast pointer comparison.
However, currently we (rather incorrectly) use in several places in LLDB temporary ConstStrings when
we just want to compare a given ConstString against a hardcoded value, for example like this:
```
if (extension != ConstString(".oat") && extension != ConstString(".odex"))
```
Obviously this kind of defeats the point of ConstStrings. In the comparison above we would
construct two temporary ConstStrings every time we hit the given code. Constructing a
ConstString is relatively expensive: we need to go to the StringPool, take a read and possibly
an exclusive write-lock and then look up our temporary string in the string map of the pool.
So we do a lot of heavy work for essentially just comparing a <6 characters in two strings.
I initially wanted to just fix these issues by turning the temporary ConstString in static variables/
members, but that made the code much less readable. Instead I propose to add a new overload
for the ConstString comparison operator that takes a StringRef. This comparison operator directly
compares the ConstString content against the given StringRef without turning the StringRef into
a ConstString.
This means that the example above can look like this now:
```
if (extension != ".oat" && extension != ".odex")
```
It also no longer has to unlock/lock two locks and call multiple functions in other TUs for constructing
the temporary ConstString instances. Instead this should end up just being a direct string comparison
of the two given strings on most compilers.
This patch also directly updates all uses of temporary and short ConstStrings in LLDB to use this new
comparison operator. It also adds a some unit tests for the new and old comparison operator.
Reviewers: #lldb, JDevlieghere, espindola, amccarth
Reviewed By: JDevlieghere, amccarth
Subscribers: amccarth, clayborg, JDevlieghere, emaste, arichardson, MaskRay, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D60667
llvm-svn: 359281
2019-04-26 07:21:36 +00:00
|
|
|
if (extension != ".oat" && extension != ".odex")
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status(
|
2016-07-06 16:40:09 +00:00
|
|
|
"Symbol file downloading only supported for oat and odex files");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-12 11:10:25 +00:00
|
|
|
// If we have no information about the platform file we can't execute oatdump
|
|
|
|
if (!module_sp->GetPlatformFileSpec())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("No platform file specified");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-12 11:10:25 +00:00
|
|
|
// Symbolizer isn't available before SDK version 23
|
|
|
|
if (GetSdkVersion() < 23)
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Symbol file generation only supported on SDK 23+");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-12 11:10:25 +00:00
|
|
|
// If we already have symtab then we don't have to try and generate one
|
|
|
|
if (module_sp->GetSectionList()->FindSectionByName(ConstString(".symtab")) !=
|
|
|
|
nullptr)
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Symtab already available in the module");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-07-06 17:02:42 +00:00
|
|
|
AdbClient adb(m_device_id);
|
2015-09-29 11:04:18 +00:00
|
|
|
std::string tmpdir;
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error = adb.Shell("mktemp --directory --tmpdir /data/local/tmp",
|
|
|
|
seconds(5), &tmpdir);
|
2015-08-12 11:10:25 +00:00
|
|
|
if (error.Fail() || tmpdir.empty())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Failed to generate temporary directory on the device (%s)",
|
|
|
|
error.AsCString());
|
2015-08-12 11:10:25 +00:00
|
|
|
tmpdir = llvm::StringRef(tmpdir).trim().str();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-12 11:10:25 +00:00
|
|
|
// Create file remover for the temporary directory created on the device
|
|
|
|
std::unique_ptr<std::string, std::function<void(std::string *)>>
|
2017-03-02 00:05:25 +00:00
|
|
|
tmpdir_remover(&tmpdir, [&adb](std::string *s) {
|
2015-09-29 11:04:18 +00:00
|
|
|
StreamString command;
|
2015-08-12 11:10:25 +00:00
|
|
|
command.Printf("rm -rf %s", s->c_str());
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error = adb.Shell(command.GetData(), seconds(5), nullptr);
|
2015-08-12 11:10:25 +00:00
|
|
|
|
2022-01-31 15:57:48 +01:00
|
|
|
Log *log = GetLog(LLDBLog::Platform);
|
2016-07-21 17:03:25 +00:00
|
|
|
if (log && error.Fail())
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "Failed to remove temp directory: %s", error.AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
});
|
|
|
|
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSpec symfile_platform_filespec(tmpdir);
|
2015-08-12 11:10:25 +00:00
|
|
|
symfile_platform_filespec.AppendPathComponent("symbolized.oat");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-12 11:10:25 +00:00
|
|
|
// Execute oatdump on the remote device to generate a file with symtab
|
|
|
|
StreamString command;
|
|
|
|
command.Printf("oatdump --symbolize=%s --output=%s",
|
2022-07-25 23:29:30 -07:00
|
|
|
module_sp->GetPlatformFileSpec().GetPath(false).c_str(),
|
|
|
|
symfile_platform_filespec.GetPath(false).c_str());
|
2016-11-24 14:11:47 +00:00
|
|
|
error = adb.Shell(command.GetData(), minutes(1), nullptr);
|
2015-09-29 11:04:18 +00:00
|
|
|
if (error.Fail())
|
2017-05-12 04:51:55 +00:00
|
|
|
return Status("Oatdump failed: %s", error.AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-12 11:10:25 +00:00
|
|
|
// Download the symbolfile from the remote device
|
|
|
|
return GetFile(symfile_platform_filespec, dst_file_spec);
|
|
|
|
}
|
2015-10-01 13:57:54 +00:00
|
|
|
|
|
|
|
bool PlatformAndroid::GetRemoteOSVersion() {
|
2018-06-18 15:02:23 +00:00
|
|
|
m_os_version = llvm::VersionTuple(GetSdkVersion());
|
|
|
|
return !m_os_version.empty();
|
2015-10-01 13:57:54 +00:00
|
|
|
}
|
2015-12-02 11:58:51 +00:00
|
|
|
|
2017-08-14 16:39:16 +00:00
|
|
|
llvm::StringRef
|
|
|
|
PlatformAndroid::GetLibdlFunctionDeclarations(lldb_private::Process *process) {
|
|
|
|
SymbolContextList matching_symbols;
|
|
|
|
std::vector<const char *> dl_open_names = { "__dl_dlopen", "dlopen" };
|
|
|
|
const char *dl_open_name = nullptr;
|
|
|
|
Target &target = process->GetTarget();
|
|
|
|
for (auto name: dl_open_names) {
|
2019-10-17 19:56:40 +00:00
|
|
|
target.GetImages().FindFunctionSymbols(
|
|
|
|
ConstString(name), eFunctionNameTypeFull, matching_symbols);
|
|
|
|
if (matching_symbols.GetSize()) {
|
2017-08-14 16:39:16 +00:00
|
|
|
dl_open_name = name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-05 14:54:41 +00:00
|
|
|
// Older platform versions have the dl function symbols mangled
|
2017-08-14 16:39:16 +00:00
|
|
|
if (dl_open_name == dl_open_names[0])
|
2017-07-05 14:54:41 +00:00
|
|
|
return R"(
|
2015-12-03 12:58:03 +00:00
|
|
|
extern "C" void* dlopen(const char*, int) asm("__dl_dlopen");
|
|
|
|
extern "C" void* dlsym(void*, const char*) asm("__dl_dlsym");
|
|
|
|
extern "C" int dlclose(void*) asm("__dl_dlclose");
|
|
|
|
extern "C" char* dlerror(void) asm("__dl_dlerror");
|
|
|
|
)";
|
2017-07-05 14:54:41 +00:00
|
|
|
|
2017-08-14 16:39:16 +00:00
|
|
|
return PlatformPOSIX::GetLibdlFunctionDeclarations(process);
|
2015-12-02 11:58:51 +00:00
|
|
|
}
|
2016-07-06 17:02:42 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
AdbClient::SyncService *PlatformAndroid::GetSyncService(Status &error) {
|
2016-07-06 17:02:42 +00:00
|
|
|
if (m_adb_sync_svc && m_adb_sync_svc->IsConnected())
|
|
|
|
return m_adb_sync_svc.get();
|
|
|
|
|
|
|
|
AdbClient adb(m_device_id);
|
|
|
|
m_adb_sync_svc = adb.GetSyncService(error);
|
|
|
|
return (error.Success()) ? m_adb_sync_svc.get() : nullptr;
|
|
|
|
}
|