323 changes: 236 additions & 87 deletions lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions lldb/source/Plugins/Platform/Linux/PlatformLinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,19 @@ namespace lldb_private {
GetSoftwareBreakpointTrapOpcode (Target &target,
BreakpointSite *bp_site) override;

lldb_private::Error
LaunchProcess (lldb_private::ProcessLaunchInfo &launch_info) override;

lldb::ProcessSP
Attach(ProcessAttachInfo &attach_info, Debugger &debugger,
Target *target, Listener &listener, Error &error) override;
int32_t
GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info) override;

bool
CanDebugProcess () override;

lldb::ProcessSP
DebugProcess (ProcessLaunchInfo &launch_info,
Debugger &debugger,
Target *target,
Listener &listener,
Error &error) override;

void
CalculateTrapHandlerSymbolNames () override;

Expand All @@ -113,6 +116,9 @@ namespace lldb_private {
lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate,
NativeProcessProtocolSP &process_sp) override;

static bool
UseLlgsForLocalDebugging ();

private:
DISALLOW_COPY_AND_ASSIGN (PlatformLinux);
};
Expand Down
70 changes: 0 additions & 70 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,76 +672,6 @@ PlatformDarwin::FindProcesses (const ProcessInstanceInfoMatch &match_info,
return match_count;
}

Error
PlatformDarwin::LaunchProcess (ProcessLaunchInfo &launch_info)
{
Error error;

if (IsHost())
{
error = Platform::LaunchProcess (launch_info);
}
else
{
if (m_remote_platform_sp)
error = m_remote_platform_sp->LaunchProcess (launch_info);
else
error.SetErrorString ("the platform is not currently connected");
}
return error;
}

lldb::ProcessSP
PlatformDarwin::Attach (ProcessAttachInfo &attach_info,
Debugger &debugger,
Target *target,
Listener &listener,
Error &error)
{
lldb::ProcessSP process_sp;

if (IsHost())
{
if (target == NULL)
{
TargetSP new_target_sp;

error = debugger.GetTargetList().CreateTarget (debugger,
NULL,
NULL,
false,
NULL,
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(), NULL);

if (process_sp)
{
ListenerSP listener_sp (new Listener("lldb.PlatformDarwin.attach.hijack"));
attach_info.SetHijackListener(listener_sp);
process_sp->HijackProcessEvents(listener_sp.get());
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;
}

bool
PlatformDarwin::ModuleIsExcludedForNonModuleSpecificSearches (lldb_private::Target &target, const lldb::ModuleSP &module_sp)
{
Expand Down
10 changes: 0 additions & 10 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ class PlatformDarwin : public PlatformPOSIX
FindProcesses (const lldb_private::ProcessInstanceInfoMatch &match_info,
lldb_private::ProcessInstanceInfoList &process_infos);

virtual lldb_private::Error
LaunchProcess (lldb_private::ProcessLaunchInfo &launch_info);

virtual lldb::ProcessSP
Attach (lldb_private::ProcessAttachInfo &attach_info,
lldb_private::Debugger &debugger,
lldb_private::Target *target, // Can be NULL, if NULL create a new target, else use existing one
lldb_private::Listener &listener,
lldb_private::Error &error);

virtual bool
ModuleIsExcludedForNonModuleSpecificSearches (lldb_private::Target &target, const lldb::ModuleSP &module_sp);

Expand Down
90 changes: 90 additions & 0 deletions lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// Project includes

#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Host/File.h"
#include "lldb/Host/FileCache.h"
Expand Down Expand Up @@ -769,6 +771,94 @@ PlatformPOSIX::DisconnectRemote ()
return error;
}

Error
PlatformPOSIX::LaunchProcess (ProcessLaunchInfo &launch_info)
{
Error error;

if (IsHost())
{
error = Platform::LaunchProcess (launch_info);
}
else
{
if (m_remote_platform_sp)
error = m_remote_platform_sp->LaunchProcess (launch_info);
else
error.SetErrorString ("the platform is not currently connected");
}
return error;
}

lldb::ProcessSP
PlatformPOSIX::Attach (ProcessAttachInfo &attach_info,
Debugger &debugger,
Target *target,
Listener &listener,
Error &error)
{
lldb::ProcessSP process_sp;
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));

if (IsHost())
{
if (target == NULL)
{
TargetSP new_target_sp;

error = debugger.GetTargetList().CreateTarget (debugger,
NULL,
NULL,
false,
NULL,
new_target_sp);
target = new_target_sp.get();
if (log)
log->Printf ("PlatformPOSIX::%s created new target", __FUNCTION__);
}
else
{
error.Clear();
if (log)
log->Printf ("PlatformPOSIX::%s target already existed, setting target", __FUNCTION__);
}

if (target && error.Success())
{
debugger.GetTargetList().SetSelectedTarget(target);
if (log)
{
ModuleSP exe_module_sp = target->GetExecutableModule ();
log->Printf ("PlatformPOSIX::%s set selected target to %p %s", __FUNCTION__,
target,
exe_module_sp ? exe_module_sp->GetFileSpec().GetPath().c_str () : "<null>" );
}


process_sp = target->CreateProcess (listener, attach_info.GetProcessPluginName(), NULL);

if (process_sp)
{
// Set UnixSignals appropriately.
process_sp->SetUnixSignals (Host::GetUnixSignals ());

ListenerSP listener_sp (new Listener("lldb.PlatformPOSIX.attach.hijack"));
attach_info.SetHijackListener(listener_sp);
process_sp->HijackProcessEvents(listener_sp.get());
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;
}

lldb::ProcessSP
PlatformPOSIX::DebugProcess (ProcessLaunchInfo &launch_info,
Debugger &debugger,
Expand Down
10 changes: 10 additions & 0 deletions lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ class PlatformPOSIX : public lldb_private::Platform
virtual lldb_private::Error
Unlink (const char *path);

lldb_private::Error
LaunchProcess (lldb_private::ProcessLaunchInfo &launch_info) override;

lldb::ProcessSP
Attach (lldb_private::ProcessAttachInfo &attach_info,
lldb_private::Debugger &debugger,
lldb_private::Target *target, // Can be NULL, if NULL create a new target, else use existing one
lldb_private::Listener &listener,
lldb_private::Error &error) override;

lldb::ProcessSP
DebugProcess (lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Debugger &debugger,
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Plugins/Process/Linux/ProcessLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "lldb/Target/Target.h"

#include "ProcessLinux.h"
#include "Plugins/Platform/Linux/PlatformLinux.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
#include "Plugins/Process/Utility/LinuxSignals.h"
Expand Down Expand Up @@ -229,6 +230,11 @@ ProcessLinux::CanDebug(Target &target, bool plugin_specified_by_name)
if (m_core_file)
return false;

// If we're using llgs for local debugging, we must not say that this process
// is used for debugging.
if (PlatformLinux::UseLlgsForLocalDebugging ())
return false;

return ProcessPOSIX::CanDebug(target, plugin_specified_by_name);
}

22 changes: 22 additions & 0 deletions lldb/source/Target/FileAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "lldb/Host/Windows/win32.h" // For O_NOCTTY
#endif

#include "lldb/Core/Stream.h"
#include "lldb/Target/FileAction.h"

using namespace lldb_private;
Expand Down Expand Up @@ -93,3 +94,24 @@ FileAction::Duplicate(int fd, int dup_fd)
}
return m_fd >= 0;
}

void
FileAction::Dump(Stream &stream) const
{
stream.PutCString("file action: ");
switch (m_action)
{
case eFileActionClose:
stream.Printf("close fd %d", m_fd);
break;
case eFileActionDuplicate:
stream.Printf("duplicate fd %d to %d", m_fd, m_arg);
break;
case eFileActionNone:
stream.PutCString("no action");
break;
case eFileActionOpen:
stream.Printf("open fd %d with '%s', OFLAGS = 0x%x", m_fd, m_path.c_str(), m_arg);
break;
}
}