[Lldb-commits] [lldb] r185946 - Use shared pointers to hold the process in ProcessMonitor

Andrew Kaylor andrew.kaylor at intel.com
Tue Jul 9 09:44:28 PDT 2013


Author: akaylor
Date: Tue Jul  9 11:44:27 2013
New Revision: 185946

URL: http://llvm.org/viewvc/llvm-project?rev=185946&view=rev
Log:
Use shared pointers to hold the process in ProcessMonitor

Modified:
    lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
    lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h
    lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp
    lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h
    lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
    lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp?rev=185946&r1=185945&r2=185946&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp Tue Jul  9 11:44:27 2013
@@ -689,7 +689,7 @@ ProcessMonitor::AttachArgs::~AttachArgs(
 /// launching or attaching to the inferior process, and then 2) servicing
 /// operations such as register reads/writes, stepping, etc.  See the comments
 /// on the Operation class for more info as to why this is needed.
-ProcessMonitor::ProcessMonitor(ProcessPOSIX *process,
+ProcessMonitor::ProcessMonitor(ProcessPOSIXSP &process,
                                Module *module,
                                const char *argv[],
                                const char *envp[],
@@ -698,7 +698,7 @@ ProcessMonitor::ProcessMonitor(ProcessPO
                                const char *stderr_path,
                                const char *working_dir,
                                lldb_private::Error &error)
-    : m_process(static_cast<ProcessFreeBSD *>(process)),
+    : m_process(static_pointer_cast<ProcessFreeBSD>(process)),
       m_operation_thread(LLDB_INVALID_HOST_THREAD),
       m_monitor_thread(LLDB_INVALID_HOST_THREAD),
       m_pid(LLDB_INVALID_PROCESS_ID),
@@ -756,10 +756,10 @@ WAIT_AGAIN:
     }
 }
 
-ProcessMonitor::ProcessMonitor(ProcessPOSIX *process,
+ProcessMonitor::ProcessMonitor(ProcessPOSIXSP &process,
                                lldb::pid_t pid,
                                lldb_private::Error &error)
-    : m_process(static_cast<ProcessFreeBSD *>(process)),
+    : m_process(static_pointer_cast<ProcessFreeBSD>(process)),
       m_operation_thread(LLDB_INVALID_HOST_THREAD),
       m_monitor_thread(LLDB_INVALID_HOST_THREAD),
       m_pid(pid),
@@ -1102,7 +1102,7 @@ ProcessMonitor::MonitorCallback(void *ca
 {
     ProcessMessage message;
     ProcessMonitor *monitor = static_cast<ProcessMonitor*>(callback_baton);
-    ProcessFreeBSD *process = monitor->m_process;
+    ProcessFreeBSD *process = monitor->m_process.get();
     assert(process);
     bool stop_monitoring;
     siginfo_t info;

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h?rev=185946&r1=185945&r2=185946&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h Tue Jul  9 11:44:27 2013
@@ -47,7 +47,7 @@ public:
 
     /// Launches an inferior process ready for debugging.  Forms the
     /// implementation of Process::DoLaunch.
-    ProcessMonitor(ProcessPOSIX *process,
+    ProcessMonitor(ProcessPOSIXSP &process,
                    lldb_private::Module *module,
                    char const *argv[],
                    char const *envp[],
@@ -57,7 +57,7 @@ public:
                    const char *working_dir,
                    lldb_private::Error &error);
 
-    ProcessMonitor(ProcessPOSIX *process,
+    ProcessMonitor(ProcessPOSIXSP &process,
                    lldb::pid_t pid,
                    lldb_private::Error &error);
 
@@ -192,7 +192,7 @@ public:
 
 
 private:
-    ProcessFreeBSD *m_process;
+    std::shared_ptr<ProcessFreeBSD> m_process;
 
     lldb::thread_t m_operation_thread;
     lldb::thread_t m_monitor_thread;

Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp?rev=185946&r1=185945&r2=185946&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp Tue Jul  9 11:44:27 2013
@@ -923,7 +923,7 @@ ProcessMonitor::AttachArgs::~AttachArgs(
 /// launching or attaching to the inferior process, and then 2) servicing
 /// operations such as register reads/writes, stepping, etc.  See the comments
 /// on the Operation class for more info as to why this is needed.
-ProcessMonitor::ProcessMonitor(ProcessPOSIX *process,
+ProcessMonitor::ProcessMonitor(ProcessPOSIXSP &process,
                                Module *module,
                                const char *argv[],
                                const char *envp[],
@@ -932,7 +932,7 @@ ProcessMonitor::ProcessMonitor(ProcessPO
                                const char *stderr_path,
                                const char *working_dir,
                                lldb_private::Error &error)
-    : m_process(static_cast<ProcessLinux *>(process)),
+    : m_process(static_pointer_cast<ProcessLinux>(process)),
       m_operation_thread(LLDB_INVALID_HOST_THREAD),
       m_monitor_thread(LLDB_INVALID_HOST_THREAD),
       m_pid(LLDB_INVALID_PROCESS_ID),
@@ -988,10 +988,10 @@ WAIT_AGAIN:
     }
 }
 
-ProcessMonitor::ProcessMonitor(ProcessPOSIX *process,
+ProcessMonitor::ProcessMonitor(ProcessPOSIXSP &process,
                                lldb::pid_t pid,
                                lldb_private::Error &error)
-  : m_process(static_cast<ProcessLinux *>(process)),
+  : m_process(static_pointer_cast<ProcessLinux>(process)),
       m_operation_thread(LLDB_INVALID_HOST_THREAD),
       m_monitor_thread(LLDB_INVALID_HOST_THREAD),
       m_pid(LLDB_INVALID_PROCESS_ID),
@@ -1412,7 +1412,7 @@ ProcessMonitor::MonitorCallback(void *ca
 {
     ProcessMessage message;
     ProcessMonitor *monitor = static_cast<ProcessMonitor*>(callback_baton);
-    ProcessLinux *process = monitor->m_process;
+    ProcessLinux *process = monitor->m_process.get();
     assert(process);
     bool stop_monitoring;
     siginfo_t info;

Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h?rev=185946&r1=185945&r2=185946&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h Tue Jul  9 11:44:27 2013
@@ -47,7 +47,7 @@ public:
 
     /// Launches an inferior process ready for debugging.  Forms the
     /// implementation of Process::DoLaunch.
-    ProcessMonitor(ProcessPOSIX *process,
+    ProcessMonitor(ProcessPOSIXSP &process,
                    lldb_private::Module *module,
                    char const *argv[],
                    char const *envp[],
@@ -57,7 +57,7 @@ public:
                    const char *working_dir,
                    lldb_private::Error &error);
 
-    ProcessMonitor(ProcessPOSIX *process,
+    ProcessMonitor(ProcessPOSIXSP &process,
                    lldb::pid_t pid,
                    lldb_private::Error &error);
 
@@ -182,7 +182,7 @@ public:
     StopThread(lldb::tid_t tid);
 
 private:
-    ProcessLinux *m_process;
+    std::shared_ptr<ProcessLinux> m_process;
 
     lldb::thread_t m_operation_thread;
     lldb::thread_t m_monitor_thread;

Modified: lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp?rev=185946&r1=185945&r2=185946&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp Tue Jul  9 11:44:27 2013
@@ -115,7 +115,8 @@ ProcessPOSIX::DoAttachToProcessWithID(ll
     if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
         log->Printf ("ProcessPOSIX::%s(pid = %" PRIi64 ")", __FUNCTION__, GetID());
 
-    m_monitor = new ProcessMonitor(this, pid, error);
+    ProcessPOSIXSP process_sp(static_pointer_cast<ProcessPOSIX>(CalculateProcess()));
+    m_monitor = new ProcessMonitor(process_sp, pid, error);
 
     if (!error.Success())
         return error;
@@ -225,7 +226,8 @@ ProcessPOSIX::DoLaunch (Module *module,
     file_action = launch_info.GetFileActionForFD (STDERR_FILENO);
     stderr_path = GetFilePath(file_action, stderr_path);
 
-    m_monitor = new ProcessMonitor (this, 
+    ProcessPOSIXSP process_sp(static_pointer_cast<ProcessPOSIX>(CalculateProcess()));
+    m_monitor = new ProcessMonitor (process_sp,
                                     module,
                                     launch_info.GetArguments().GetConstArgumentVector(), 
                                     launch_info.GetEnvironmentEntries().GetConstArgumentVector(),

Modified: lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h?rev=185946&r1=185945&r2=185946&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h (original)
+++ lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h Tue Jul  9 11:44:27 2013
@@ -201,4 +201,6 @@ protected:
     ThreadStopSet m_seen_initial_stop;
 };
 
+typedef std::shared_ptr<ProcessPOSIX> ProcessPOSIXSP;
+
 #endif  // liblldb_MacOSXProcess_H_





More information about the lldb-commits mailing list