[Lldb-commits] [lldb] r144882 - in /lldb/trunk: include/lldb/Target/Process.h source/Core/Debugger.cpp source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp source/Target/Platform.cpp source/Target/Process.cpp
Greg Clayton
gclayton at apple.com
Wed Nov 16 20:46:03 PST 2011
Author: gclayton
Date: Wed Nov 16 22:46:02 2011
New Revision: 144882
URL: http://llvm.org/viewvc/llvm-project?rev=144882&view=rev
Log:
Fixed the issue that was causing our monitor process threads to crash, it
turned out to be unitialized data in the ProcessLaunchInfo default constructor.
Turning on MallocScribble in the environment helped track this down.
When we launch and attach using the host layer, we now inform the process that
it shouldn't detach when by calling an accessor.
Modified:
lldb/trunk/include/lldb/Target/Process.h
lldb/trunk/source/Core/Debugger.cpp
lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/trunk/source/Target/Platform.cpp
lldb/trunk/source/Target/Process.cpp
Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=144882&r1=144881&r2=144882&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Wed Nov 16 22:46:02 2011
@@ -491,7 +491,15 @@
ProcessLaunchInfo () :
ProcessInfo(),
- m_flags ()
+ m_working_dir (),
+ m_plugin_name (),
+ m_shell (),
+ m_flags (0),
+ m_file_actions (),
+ m_resume_count (0),
+ m_monitor_callback (NULL),
+ m_monitor_callback_baton (NULL),
+ m_monitor_signals (false)
{
}
@@ -1508,11 +1516,17 @@
ConnectRemote (const char *remote_url);
bool
- AttachedToProcess() const
+ GetShouldDetach () const
{
- return m_attached_to_process;
+ return m_should_detach;
}
-
+
+ void
+ SetShouldDetach (bool b)
+ {
+ m_should_detach = b;
+ }
+
//------------------------------------------------------------------
/// Get the image information address for the current process.
///
@@ -2944,7 +2958,7 @@
std::string m_stderr_data;
MemoryCache m_memory_cache;
AllocatedMemoryCache m_allocated_memory_cache;
- bool m_attached_to_process; /// Did we launch the process or attach to it?
+ bool m_should_detach; /// Should we detach if the process object goes away with an explicit call to Kill or Detach?
typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP> LanguageRuntimeCollection;
LanguageRuntimeCollection m_language_runtimes;
Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=144882&r1=144881&r2=144882&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Nov 16 22:46:02 2011
@@ -272,7 +272,7 @@
ProcessSP process_sp (m_target_list.GetTargetAtIndex (i)->GetProcessSP());
if (process_sp)
{
- if (process_sp->AttachedToProcess())
+ if (process_sp->GetShouldDetach())
process_sp->Detach();
else
process_sp->Destroy();
Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp?rev=144882&r1=144881&r2=144882&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp Wed Nov 16 22:46:02 2011
@@ -97,6 +97,11 @@
ProcessKDP::~ProcessKDP()
{
Clear();
+ // We need to call finalize on the process before destroying ourselves
+ // to make sure all of the broadcaster cleanup goes as planned. If we
+ // destruct this class, then Process::~Process() might have problems
+ // trying to fully destroy the broadcaster.
+ Finalize();
}
//----------------------------------------------------------------------
@@ -620,7 +625,6 @@
void
ProcessKDP::Clear()
{
- Mutex::Locker locker (m_thread_list.GetMutex ());
m_thread_list.Clear();
}
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=144882&r1=144881&r2=144882&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Wed Nov 16 22:46:02 2011
@@ -1171,6 +1171,9 @@
{
// thread in big endian hex
tid = Args::StringToUInt32 (value.c_str(), 0, 16);
+ // m_thread_list does have its own mutex, but we need to
+ // hold onto the mutex between the call to m_thread_list.FindThreadByID(...)
+ // and the m_thread_list.AddThread(...) so it doesn't change on us
Mutex::Locker locker (m_thread_list.GetMutex ());
thread_sp = m_thread_list.FindThreadByID(tid, false);
if (!thread_sp)
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=144882&r1=144881&r2=144882&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Wed Nov 16 22:46:02 2011
@@ -581,6 +581,14 @@
{
ProcessAttachInfo attach_info (launch_info);
process_sp = Attach (attach_info, debugger, target, listener, error);
+ if (process_sp)
+ {
+ // Since we attached to the process, it will think it needs to detach
+ // if the process object just goes away without an explicit call to
+ // Process::Kill() or Process::Detach(), so let it know to kill the
+ // process if this happens.
+ process_sp->SetShouldDetach (false);
+ }
}
}
return process_sp;
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=144882&r1=144881&r2=144882&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed Nov 16 22:46:02 2011
@@ -774,7 +774,7 @@
m_stderr_data (),
m_memory_cache (*this),
m_allocated_memory_cache (*this),
- m_attached_to_process (false),
+ m_should_detach (false),
m_next_event_action_ap(),
m_can_jit(eCanJITYes)
{
@@ -818,6 +818,29 @@
void
Process::Finalize()
{
+ switch (GetPrivateState())
+ {
+ case eStateConnected:
+ case eStateAttaching:
+ case eStateLaunching:
+ case eStateStopped:
+ case eStateRunning:
+ case eStateStepping:
+ case eStateCrashed:
+ case eStateSuspended:
+ if (GetShouldDetach())
+ Detach();
+ else
+ Destroy();
+ break;
+
+ case eStateInvalid:
+ case eStateUnloaded:
+ case eStateDetached:
+ case eStateExited:
+ break;
+ }
+
// Clear our broadcaster before we proceed with destroying
Broadcaster::Clear();
@@ -1183,6 +1206,9 @@
if (StateIsStoppedState (state, true))
{
Mutex::Locker locker (m_thread_list.GetMutex ());
+ // m_thread_list does have its own mutex, but we need to
+ // hold onto the mutex between the call to UpdateThreadList(...)
+ // and the os->UpdateThreadList(...) so it doesn't change on us
ThreadList new_thread_list(this);
// Always update the thread list with the protocol specific
// thread list
@@ -2209,6 +2235,7 @@
if (error.Success())
{
SetPublicState (eStateLaunching);
+ m_should_detach = false;
// Now launch using these arguments.
error = DoLaunch (exe_module, launch_info);
@@ -2351,6 +2378,8 @@
error = WillAttachToProcessWithName(process_name, wait_for_launch);
if (error.Success())
{
+ m_should_detach = true;
+
SetPublicState (eStateAttaching);
error = DoAttachToProcessWithName (process_name, wait_for_launch);
if (error.Fail())
@@ -2416,6 +2445,7 @@
error = WillAttachToProcessWithID(attach_pid);
if (error.Success())
{
+ m_should_detach = true;
SetPublicState (eStateAttaching);
error = DoAttachToProcessWithID (attach_pid);
@@ -2516,7 +2546,6 @@
{
// Let the process subclass figure out at much as it can about the process
// before we go looking for a dynamic loader plug-in.
- m_attached_to_process = true;
DidAttach();
// We just attached. If we have a platform, ask it for the process architecture, and if it isn't
More information about the lldb-commits
mailing list