2015-02-12 18:13:44 +00:00
|
|
|
//===-- PlatformAndroid.cpp -------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Core/PluginManager.h"
|
2015-02-16 10:34:30 +00:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
2015-05-01 16:49:28 +00:00
|
|
|
#include "Utility/UriParser.h"
|
2015-02-12 18:13:44 +00:00
|
|
|
|
|
|
|
// Project includes
|
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"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
2015-03-31 09:52:22 +00:00
|
|
|
using namespace lldb_private::platform_android;
|
2015-02-12 18:13:44 +00:00
|
|
|
|
|
|
|
static uint32_t g_initialize_count = 0;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
2015-03-31 09:52:22 +00:00
|
|
|
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_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>";
|
|
|
|
|
|
|
|
log->Printf ("PlatformAndroid::%s(force=%s, arch={%s,%s})", __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool create = force;
|
|
|
|
if (create == false && arch && arch->IsValid())
|
|
|
|
{
|
|
|
|
const llvm::Triple &triple = arch->GetTriple();
|
|
|
|
switch (triple.getVendor())
|
|
|
|
{
|
|
|
|
case llvm::Triple::PC:
|
|
|
|
create = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
// Only accept "unknown" for the vendor if the host is android and
|
|
|
|
// it "unknown" wasn't specified (it was just returned because it
|
|
|
|
// was NOT specified_
|
|
|
|
case llvm::Triple::VendorType::UnknownVendor:
|
|
|
|
create = !arch->TripleVendorWasSpecified();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (create)
|
|
|
|
{
|
|
|
|
switch (triple.getOS())
|
|
|
|
{
|
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__)
|
|
|
|
// 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)
|
|
|
|
case llvm::Triple::OSType::UnknownOS:
|
|
|
|
create = !arch->TripleOSWasSpecified();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
create = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (create)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf ("PlatformAndroid::%s() creating remote-android platform", __FUNCTION__);
|
2015-02-16 10:34:30 +00:00
|
|
|
return PlatformSP(new PlatformAndroid(false));
|
2015-02-12 18:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf ("PlatformAndroid::%s() aborting creation of remote-android platform", __FUNCTION__);
|
|
|
|
|
|
|
|
return PlatformSP();
|
|
|
|
}
|
|
|
|
|
2015-02-16 10:34:30 +00:00
|
|
|
PlatformAndroid::PlatformAndroid (bool is_host) :
|
|
|
|
PlatformLinux(is_host)
|
2015-02-12 18:13:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PlatformAndroid::~PlatformAndroid()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-31 09:52:22 +00:00
|
|
|
ConstString
|
2015-02-16 10:34:30 +00:00
|
|
|
PlatformAndroid::GetPluginNameStatic (bool is_host)
|
2015-02-12 18:13:44 +00:00
|
|
|
{
|
2015-02-16 10:34:30 +00:00
|
|
|
if (is_host)
|
|
|
|
{
|
|
|
|
static ConstString g_host_name(Platform::GetHostPlatformName ());
|
|
|
|
return g_host_name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static ConstString g_remote_name("remote-android");
|
|
|
|
return g_remote_name;
|
|
|
|
}
|
2015-02-12 18:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2015-02-16 10:34:30 +00:00
|
|
|
PlatformAndroid::GetPluginDescriptionStatic (bool is_host)
|
2015-02-12 18:13:44 +00:00
|
|
|
{
|
2015-02-16 10:34:30 +00:00
|
|
|
if (is_host)
|
|
|
|
return "Local Android user platform plug-in.";
|
|
|
|
else
|
|
|
|
return "Remote Android user platform plug-in.";
|
2015-02-12 18:13:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 09:52:22 +00:00
|
|
|
ConstString
|
2015-02-12 18:13:44 +00:00
|
|
|
PlatformAndroid::GetPluginName()
|
|
|
|
{
|
2015-02-16 10:34:30 +00:00
|
|
|
return GetPluginNameStatic(IsHost());
|
2015-02-12 18:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
2015-05-01 16:49:28 +00:00
|
|
|
PlatformAndroid::ConnectRemote(Args& args)
|
2015-02-12 18:13:44 +00:00
|
|
|
{
|
2015-05-01 16:49:28 +00:00
|
|
|
m_device_id.clear();
|
2015-03-25 17:58:13 +00:00
|
|
|
|
2015-02-16 10:34:30 +00:00
|
|
|
if (IsHost())
|
|
|
|
{
|
|
|
|
return Error ("can't connect to the host platform '%s', always connected", GetPluginName().GetCString());
|
|
|
|
}
|
|
|
|
|
2015-02-12 18:13:44 +00:00
|
|
|
if (!m_remote_platform_sp)
|
|
|
|
m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
|
2015-03-25 17:58:13 +00:00
|
|
|
|
2015-05-01 16:49:28 +00:00
|
|
|
int port;
|
|
|
|
std::string scheme, host, path;
|
|
|
|
const char *url = args.GetArgumentAtIndex(0);
|
|
|
|
if (!url)
|
|
|
|
return Error("URL is null.");
|
|
|
|
if (!UriParser::Parse(url, scheme, host, port, path))
|
|
|
|
return Error("Invalid URL: %s", url);
|
|
|
|
if (scheme == "adb")
|
|
|
|
m_device_id = host;
|
|
|
|
|
|
|
|
auto error = PlatformLinux::ConnectRemote(args);
|
|
|
|
if (error.Success())
|
2015-03-25 17:58:13 +00:00
|
|
|
{
|
|
|
|
AdbClient adb;
|
2015-05-01 16:49:28 +00:00
|
|
|
error = AdbClient::CreateByDeviceID(m_device_id, adb);
|
|
|
|
if (error.Fail())
|
2015-03-25 17:58:13 +00:00
|
|
|
return error;
|
|
|
|
|
2015-05-01 16:49:28 +00:00
|
|
|
m_device_id = adb.GetDeviceID();
|
2015-03-25 17:58:13 +00:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
PlatformAndroid::GetCacheHostname ()
|
|
|
|
{
|
|
|
|
return m_device_id.c_str ();
|
2015-02-12 18:13:44 +00:00
|
|
|
}
|
2015-05-18 23:44:06 +00:00
|
|
|
|
|
|
|
Error
|
|
|
|
PlatformAndroid::DownloadModuleSlice (const FileSpec &src_file_spec,
|
|
|
|
const uint64_t src_offset,
|
|
|
|
const uint64_t src_size,
|
|
|
|
const FileSpec &dst_file_spec)
|
|
|
|
{
|
|
|
|
if (src_offset != 0)
|
|
|
|
return Error ("Invalid offset - %" PRIu64, src_offset);
|
|
|
|
|
|
|
|
AdbClient adb (m_device_id);
|
|
|
|
return adb.PullFile (src_file_spec.GetPath (false).c_str (), dst_file_spec.GetPath ().c_str ());
|
|
|
|
}
|