Skip to content

Commit

Permalink
Enable process launching on android from lldb-gdbserver
Browse files Browse the repository at this point in the history
Currently it is uses the same code used on linux. Will be replaced with
android specific code if needed.

Differential Revision: http://reviews.llvm.org/D7613

llvm-svn: 229371
  • Loading branch information
Tamas Berghammer committed Feb 16, 2015
1 parent d17094f commit 1c6a1ea
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
48 changes: 35 additions & 13 deletions lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// Other libraries and framework includes
#include "lldb/Core/Log.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/HostInfo.h"

// Project includes
#include "PlatformAndroid.h"
Expand All @@ -29,8 +30,13 @@ PlatformAndroid::Initialize ()

if (g_initialize_count++ == 0)
{
PluginManager::RegisterPlugin (PlatformAndroid::GetPluginNameStatic(),
PlatformAndroid::GetPluginDescriptionStatic(),
#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),
PlatformAndroid::CreateInstance);
}
}
Expand Down Expand Up @@ -92,9 +98,9 @@ PlatformAndroid::CreateInstance (bool force, const ArchSpec *arch)
{
switch (triple.getOS())
{
case llvm::Triple::Linux:
case llvm::Triple::Android:
break;

#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
Expand All @@ -114,7 +120,7 @@ PlatformAndroid::CreateInstance (bool force, const ArchSpec *arch)
{
if (log)
log->Printf ("PlatformAndroid::%s() creating remote-android platform", __FUNCTION__);
return PlatformSP(new PlatformAndroid());
return PlatformSP(new PlatformAndroid(false));
}

if (log)
Expand All @@ -123,8 +129,8 @@ PlatformAndroid::CreateInstance (bool force, const ArchSpec *arch)
return PlatformSP();
}

PlatformAndroid::PlatformAndroid () :
PlatformLinux(false) // Platform android is always a remote target
PlatformAndroid::PlatformAndroid (bool is_host) :
PlatformLinux(is_host)
{
}

Expand All @@ -133,27 +139,43 @@ PlatformAndroid::~PlatformAndroid()
}

lldb_private::ConstString
PlatformAndroid::GetPluginNameStatic ()
PlatformAndroid::GetPluginNameStatic (bool is_host)
{
static ConstString g_remote_name("remote-android");
return g_remote_name;
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;
}
}

const char *
PlatformAndroid::GetPluginDescriptionStatic ()
PlatformAndroid::GetPluginDescriptionStatic (bool is_host)
{
return "Remote Android user platform plug-in.";
if (is_host)
return "Local Android user platform plug-in.";
else
return "Remote Android user platform plug-in.";
}

lldb_private::ConstString
PlatformAndroid::GetPluginName()
{
return GetPluginNameStatic();
return GetPluginNameStatic(IsHost());
}

Error
PlatformAndroid::ConnectRemote (Args& args)
{
if (IsHost())
{
return Error ("can't connect to the host platform '%s', always connected", GetPluginName().GetCString());
}

if (!m_remote_platform_sp)
m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
return PlatformLinux::ConnectRemote (args);
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/Platform/Android/PlatformAndroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace lldb_private {

static void
Terminate ();
PlatformAndroid ();

PlatformAndroid (bool is_host);

virtual
~PlatformAndroid();
Expand All @@ -39,10 +39,10 @@ namespace lldb_private {
CreateInstance (bool force, const lldb_private::ArchSpec *arch);

static lldb_private::ConstString
GetPluginNameStatic ();
GetPluginNameStatic (bool is_host);

static const char *
GetPluginDescriptionStatic ();
GetPluginDescriptionStatic (bool is_host);

lldb_private::ConstString
GetPluginName() override;
Expand Down
10 changes: 1 addition & 9 deletions lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ PlatformLinux::Initialize ()

if (g_initialize_count++ == 0)
{
#if defined(__linux__)
#if defined(__linux__) && !defined(__ANDROID__)
PlatformSP default_platform_sp (new PlatformLinux(true));
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
Platform::SetHostPlatform (default_platform_sp);
Expand Down Expand Up @@ -853,9 +853,6 @@ PlatformLinux::LaunchNativeProcess (
lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate,
NativeProcessProtocolSP &process_sp)
{
#if !defined(__linux__) || defined(__ANDROID_NDK__)
return Error("only implemented on Linux hosts");
#else
if (!IsHost ())
return Error("PlatformLinux::%s (): cannot launch a debug process when not the host", __FUNCTION__);

Expand All @@ -882,21 +879,16 @@ PlatformLinux::LaunchNativeProcess (
process_sp);

return error;
#endif
}

Error
PlatformLinux::AttachNativeProcess (lldb::pid_t pid,
lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate,
NativeProcessProtocolSP &process_sp)
{
#if !defined(__linux__) || defined(__ANDROID_NDK__)
return Error("only implemented on Linux hosts");
#else
if (!IsHost ())
return Error("PlatformLinux::%s (): cannot attach to a debug process when not the host", __FUNCTION__);

// Launch it for debugging
return NativeProcessLinux::AttachToProcess (pid, native_delegate, process_sp);
#endif
}
3 changes: 1 addition & 2 deletions lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,8 @@ NativeThreadLinux::GetRegisterContext ()
break;
}
#endif
#if 0

case llvm::Triple::x86:
#endif
case llvm::Triple::x86_64:
{
const uint32_t concrete_frame_idx = 0;
Expand Down

0 comments on commit 1c6a1ea

Please sign in to comment.