From 0c74e78d633181698f22b95871e141af39111260 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Fri, 24 Jun 2011 03:21:43 +0000 Subject: Fixed SBTarget attach calls to properly deal with being connected to a remotely connected process connection. Also added support for more kinds of continue packet when multiple threads need to continue where some want to continue with signals. llvm-svn: 133785 --- lldb/source/API/SBTarget.cpp | 78 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 7 deletions(-) (limited to 'lldb/source/API/SBTarget.cpp') diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 8ed525e3d4d..c1278e023a5 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -282,11 +282,43 @@ SBTarget::AttachToProcessWithID if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - if (listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref())); + + StateType state = eStateInvalid; + sb_process.SetProcess (m_opaque_sp->GetProcessSP()); + if (sb_process.IsValid()) + { + state = sb_process->GetState(); + + if (sb_process->IsAlive() && state != eStateConnected) + { + if (state == eStateAttaching) + error.SetErrorString ("process attach is in progress"); + else + error.SetErrorString ("a process is already being debugged"); + sb_process.Clear(); + return sb_process; + } + } + + if (state == eStateConnected) + { + // If we are already connected, then we have already specified the + // listener, so if a valid listener is supplied, we need to error out + // to let the client know. + if (listener.IsValid()) + { + error.SetErrorString ("process is connected and already has a listener, pass empty listener"); + sb_process.Clear(); + return sb_process; + } + } else - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); - + { + if (listener.IsValid()) + sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref())); + else + sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + } if (sb_process.IsValid()) { @@ -323,10 +355,42 @@ SBTarget::AttachToProcessWithName { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - if (listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref())); + StateType state = eStateInvalid; + sb_process.SetProcess (m_opaque_sp->GetProcessSP()); + if (sb_process.IsValid()) + { + state = sb_process->GetState(); + + if (sb_process->IsAlive() && state != eStateConnected) + { + if (state == eStateAttaching) + error.SetErrorString ("process attach is in progress"); + else + error.SetErrorString ("a process is already being debugged"); + sb_process.Clear(); + return sb_process; + } + } + + if (state == eStateConnected) + { + // If we are already connected, then we have already specified the + // listener, so if a valid listener is supplied, we need to error out + // to let the client know. + if (listener.IsValid()) + { + error.SetErrorString ("process is connected and already has a listener, pass empty listener"); + sb_process.Clear(); + return sb_process; + } + } else - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + { + if (listener.IsValid()) + sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref())); + else + sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + } if (sb_process.IsValid()) { -- cgit v1.2.3