summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp')
-rw-r--r--lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp205
1 files changed, 164 insertions, 41 deletions
diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
index a9e390c99d0..2eb333b88e4 100644
--- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -17,6 +17,7 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Error.h"
+#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/PluginManager.h"
@@ -29,10 +30,12 @@
using namespace lldb;
using namespace lldb_private;
+static uint32_t g_initialize_count = 0;
+
Platform *
PlatformLinux::CreateInstance ()
{
- return new PlatformLinux();
+ return new PlatformLinux(true);
}
const char *
@@ -42,33 +45,51 @@ PlatformLinux::GetPluginNameStatic()
}
const char *
-PlatformLinux::GetPluginDescriptionStatic()
+PlatformLinux::GetShortPluginNameStatic (bool is_host)
+{
+ if (is_host)
+ return Platform::GetHostPlatformName ();
+ else
+ return "remote-linux";
+}
+
+const char *
+PlatformLinux::GetPluginDescriptionStatic (bool is_host)
{
- return "Default platform plugin for Linux";
+ if (is_host)
+ return "Local Linux user platform plug-in.";
+ else
+ return "Remote Linux user platform plug-in.";
}
void
PlatformLinux::Initialize ()
{
- static bool g_initialized = false;
-
- if (!g_initialized)
+ if (g_initialize_count++ == 0)
{
- PlatformSP default_platform_sp (CreateInstance());
+#if defined(__linux__)
+ PlatformSP default_platform_sp (new PlatformLinux(true));
+ default_platform_sp->SetSystemArchitecture (Host::GetArchitecture());
Platform::SetDefaultPlatform (default_platform_sp);
- PluginManager::RegisterPlugin(GetPluginNameStatic(),
- GetPluginDescriptionStatic(),
- CreateInstance);
- g_initialized = true;
+#endif
+ PluginManager::RegisterPlugin(PlatformLinux::GetShortPluginNameStatic(false),
+ PlatformLinux::GetPluginDescriptionStatic(false),
+ PlatformLinux::CreateInstance);
}
}
void
PlatformLinux::Terminate ()
{
+ if (g_initialize_count > 0)
+ {
+ if (--g_initialize_count == 0)
+ {
+ PluginManager::UnregisterPlugin (PlatformLinux::CreateInstance);
+ }
+ }
}
-
Error
PlatformLinux::ResolveExecutable (const FileSpec &exe_file,
const ArchSpec &exe_arch,
@@ -77,17 +98,50 @@ PlatformLinux::ResolveExecutable (const FileSpec &exe_file,
Error error;
// Nothing special to do here, just use the actual file and architecture
+ char exe_path[PATH_MAX];
FileSpec resolved_exe_file (exe_file);
- // If we have "ls" as the exe_file, resolve the executable loation based on
- // the current path variables
- if (!resolved_exe_file.Exists())
- resolved_exe_file.ResolveExecutableLocation ();
+ if (IsHost())
+ {
+ // If we have "ls" as the exe_file, resolve the executable location based on
+ // the current path variables
+ if (!resolved_exe_file.Exists())
+ {
+ exe_file.GetPath(exe_path, sizeof(exe_path));
+ resolved_exe_file.SetFile(exe_path, true);
+ }
- // Resolve any executable within a bundle on MacOSX
- Host::ResolveExecutableInBundle (resolved_exe_file);
+ if (!resolved_exe_file.Exists())
+ resolved_exe_file.ResolveExecutableLocation ();
- if (resolved_exe_file.Exists())
+ if (resolved_exe_file.Exists())
+ error.Clear();
+ else
+ {
+ exe_file.GetPath(exe_path, sizeof(exe_path));
+ error.SetErrorStringWithFormat("unable to find executable for '%s'", exe_path);
+ }
+ }
+ else
+ {
+ if (m_remote_platform_sp)
+ {
+ error = m_remote_platform_sp->ResolveExecutable (exe_file,
+ exe_arch,
+ exe_module_sp);
+ }
+ else
+ {
+ // We may connect to a process and use the provided executable (Don't use local $PATH).
+
+ if (resolved_exe_file.Exists())
+ error.Clear();
+ else
+ error.SetErrorStringWithFormat("the platform is not currently connected, and '%s' doesn't exist in the system root.", exe_path);
+ }
+ }
+
+ if (error.Success())
{
if (exe_arch.IsValid())
{
@@ -152,21 +206,20 @@ PlatformLinux::ResolveExecutable (const FileSpec &exe_file,
}
}
}
- else
- {
- error.SetErrorStringWithFormat ("'%s%s%s' does not exist",
- exe_file.GetDirectory().AsCString(""),
- exe_file.GetDirectory() ? "/" : "",
- exe_file.GetFilename().AsCString(""));
- }
return error;
}
Error
PlatformLinux::GetFile (const FileSpec &platform_file,
- const UUID *uuid, FileSpec &local_file)
+ const UUID *uuid_ptr, FileSpec &local_file)
{
+ if (IsRemote())
+ {
+ if (m_remote_platform_sp)
+ return m_remote_platform_sp->GetFile (platform_file, uuid_ptr, local_file);
+ }
+
// Default to the local case
local_file = platform_file;
return Error();
@@ -176,8 +229,9 @@ PlatformLinux::GetFile (const FileSpec &platform_file,
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
-PlatformLinux::PlatformLinux () :
- Platform(true)
+PlatformLinux::PlatformLinux (bool is_host) :
+ Platform(is_host), // This is the local host platform
+ m_remote_platform_sp ()
{
}
@@ -194,7 +248,17 @@ PlatformLinux::~PlatformLinux()
bool
PlatformLinux::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
{
- return Host::GetProcessInfo (pid, process_info);
+ bool success = false;
+ if (IsHost())
+ {
+ success = Platform::GetProcessInfo (pid, process_info);
+ }
+ else
+ {
+ if (m_remote_platform_sp)
+ success = m_remote_platform_sp->GetProcessInfo (pid, process_info);
+ }
+ return success;
}
bool
@@ -225,11 +289,9 @@ size_t
PlatformLinux::GetSoftwareBreakpointTrapOpcode (Target &target,
BreakpointSite *bp_site)
{
- static const uint8_t g_i386_opcode[] = { 0xCC };
-
ArchSpec arch = target.GetArchitecture();
- const uint8_t *opcode = NULL;
- size_t opcode_size = 0;
+ const uint8_t *trap_opcode = NULL;
+ size_t trap_opcode_size = 0;
switch (arch.GetCore())
{
@@ -239,13 +301,39 @@ PlatformLinux::GetSoftwareBreakpointTrapOpcode (Target &target,
case ArchSpec::eCore_x86_32_i386:
case ArchSpec::eCore_x86_64_x86_64:
- opcode = g_i386_opcode;
- opcode_size = sizeof(g_i386_opcode);
+ {
+ static const uint8_t g_i386_breakpoint_opcode[] = { 0xCC };
+ trap_opcode = g_i386_breakpoint_opcode;
+ trap_opcode_size = sizeof(g_i386_breakpoint_opcode);
+ }
break;
}
- bp_site->SetTrapOpcode(opcode, opcode_size);
- return opcode_size;
+ if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
+ return trap_opcode_size;
+ return 0;
+}
+
+Error
+PlatformLinux::LaunchProcess (ProcessLaunchInfo &launch_info)
+{
+ Error error;
+
+ if (IsHost())
+ {
+ if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell))
+ {
+ const bool is_localhost = true;
+ if (!launch_info.ConvertArgumentsForLaunchingInShell (error, is_localhost))
+ return error;
+ }
+ error = Platform::LaunchProcess (launch_info);
+ }
+ else
+ {
+ error.SetErrorString ("the platform is not currently connected");
+ }
+ return error;
}
lldb::ProcessSP
@@ -255,7 +343,42 @@ PlatformLinux::Attach(ProcessAttachInfo &attach_info,
Listener &listener,
Error &error)
{
- ProcessSP processSP;
- assert(!"Not implemented yet!");
- return processSP;
+ lldb::ProcessSP process_sp;
+ if (IsHost())
+ {
+ if (target == NULL)
+ {
+ TargetSP new_target_sp;
+ FileSpec emptyFileSpec;
+ ArchSpec emptyArchSpec;
+
+ error = debugger.GetTargetList().CreateTarget (debugger,
+ emptyFileSpec,
+ emptyArchSpec,
+ false,
+ m_remote_platform_sp,
+ new_target_sp);
+ target = new_target_sp.get();
+ }
+ else
+ error.Clear();
+
+ if (target && error.Success())
+ {
+ debugger.GetTargetList().SetSelectedTarget(target);
+
+ process_sp = target->CreateProcess (listener, attach_info.GetProcessPluginName());
+
+ if (process_sp)
+ error = process_sp->Attach (attach_info);
+ }
+ }
+ else
+ {
+ if (m_remote_platform_sp)
+ process_sp = m_remote_platform_sp->Attach (attach_info, debugger, target, listener, error);
+ else
+ error.SetErrorString ("the platform is not currently connected");
+ }
+ return process_sp;
}
OpenPOWER on IntegriCloud