<rdar://problem/13009943>
authorGreg Clayton <gclayton@apple.com>
Wed, 16 Jan 2013 17:29:04 +0000 (17:29 +0000)
committerGreg Clayton <gclayton@apple.com>
Wed, 16 Jan 2013 17:29:04 +0000 (17:29 +0000)
Added a unique integer identifier to processes. Some systems, like JTAG or other simulators, might always assign the same process ID (pid) to the processes that are being debugged. In order for scripts and the APIs to uniquely identify the processes, there needs to be another ID. Now the SBProcess class has:

uint32_t SBProcess::GetUniqueID();

This integer ID will help to truly uniquely identify a process and help with appropriate caching that can be associated with a SBProcess object.

llvm-svn: 172628

lldb/include/lldb/API/SBProcess.h
lldb/include/lldb/Target/Process.h
lldb/scripts/Python/interface/SBProcess.i
lldb/source/API/SBProcess.cpp
lldb/source/Target/Process.cpp

index c65957a9e64c5986bada69772bf10dca08aa7c1b..caf9fd882272a2a18ac2a2bae7fc2b508f8c857a 100644 (file)
@@ -144,9 +144,39 @@ public:
     const char *
     GetExitDescription ();
 
+    //------------------------------------------------------------------
+    /// Gets the process ID
+    ///
+    /// Returns the process identifier for the process as it is known
+    /// on the system on which the process is running. For unix systems
+    /// this is typically the same as if you called "getpid()" in the
+    /// process.
+    ///
+    /// @return
+    ///     Returns LLDB_INVALID_PROCESS_ID if this object does not
+    ///     contain a valid process object, or if the process has not
+    ///     been launched. Returns a valid process ID if the process is
+    ///     valid.
+    //------------------------------------------------------------------
     lldb::pid_t
     GetProcessID ();
 
+    //------------------------------------------------------------------
+    /// Gets the unique ID associated with this process object
+    ///
+    /// Unique IDs start at 1 and increment up with each new process
+    /// instance. Since starting a process on a system might always
+    /// create a process with the same process ID, there needs to be a
+    /// way to tell two process instances apart.
+    ///
+    /// @return
+    ///     Returns a non-zero integer ID if this object contains a
+    ///     valid process object, zero if this object does not contain
+    ///     a valid process object.
+    //------------------------------------------------------------------
+    uint32_t
+    GetUniqueID();
+
     uint32_t
     GetAddressByteSize() const;
 
index 502be1d47f193ca48c5e88b028f499a161c42160..a2fc51a8b6c8875f8f680a404839cb2eac5fab4a 100644 (file)
@@ -1392,6 +1392,7 @@ public:
         return GetStaticBroadcasterClass();
     }
 
+    
     //------------------------------------------------------------------
     /// A notification structure that can be used by clients to listen
     /// for changes in a process's lifetime.
@@ -1580,6 +1581,11 @@ public:
     uint32_t
     GetAddressByteSize () const;
 
+    uint32_t
+    GetUniqueID() const
+    {
+        return m_process_unique_id;
+    }
     //------------------------------------------------------------------
     /// Check if a plug-in instance can debug the file in \a module.
     ///
@@ -3499,6 +3505,7 @@ protected:
     Predicate<bool>             m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete.
     lldb::thread_t              m_private_state_thread;  // Thread ID for the thread that watches interal state events
     ProcessModID                m_mod_id;               ///< Tracks the state of the process over stops and other alterations.
+    uint32_t                    m_process_unique_id;    ///< Each lldb_private::Process class that is created gets a unique integer ID that increments with each new instance
     uint32_t                    m_thread_index_id;      ///< Each thread is created with a 1 based index that won't get re-used.
     std::map<uint64_t, uint32_t> m_thread_id_to_index_id_map;
     int                         m_exit_status;          ///< The exit status of the process, or -1 if not set.
index a7ebb0a33c53300c06afe8b159e30eae734477db..684d2aae0aab4a28e242ad6b81c803ff237bc46f 100644 (file)
@@ -186,8 +186,17 @@ public:
     const char *
     GetExitDescription ();
 
+    %feature("autodoc", "
+    Returns the process ID of the process.
+    ") GetProcessID;
     lldb::pid_t
     GetProcessID ();
+    
+    %feature("autodoc", "
+    Returns an integer ID that is guaranteed to be unique across all process instances. This is not the process ID, just a unique integer for comparison and caching purposes.
+    ") GetUniqueID;
+    uint32_t
+    GetUniqueID();
 
     uint32_t
     GetAddressByteSize() const;
index 1d24e431cbd89eb27b3b90d31bf7a8c94b99212d..6c128b7325f89ee1c5a7175d264d45aaab414db9 100644 (file)
@@ -596,6 +596,19 @@ SBProcess::GetProcessID ()
     return ret_val;
 }
 
+uint32_t
+SBProcess::GetUniqueID()
+{
+    uint32_t ret_val = 0;
+    ProcessSP process_sp(GetSP());
+    if (process_sp)
+        ret_val = process_sp->GetUniqueID();
+    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    if (log)
+        log->Printf ("SBProcess(%p)::GetUniqueID () => %" PRIu32, process_sp.get(), ret_val);
+    return ret_val;
+}
+
 ByteOrder
 SBProcess::GetByteOrder () const
 {
index 18493de1e63eca842e80b98bf1e290270434136e..fc527e2fe00c77d451e81d3fc6f8c7e8319d3915 100644 (file)
@@ -914,6 +914,8 @@ ProcessInstanceInfoMatch::Clear()
 ProcessSP
 Process::FindPlugin (Target &target, const char *plugin_name, Listener &listener, const FileSpec *crash_file_path)
 {
+    static uint32_t g_process_unique_id = 0;
+
     ProcessSP process_sp;
     ProcessCreateInstance create_callback = NULL;
     if (plugin_name)
@@ -924,7 +926,11 @@ Process::FindPlugin (Target &target, const char *plugin_name, Listener &listener
             process_sp = create_callback(target, listener, crash_file_path);
             if (process_sp)
             {
-                if (!process_sp->CanDebug(target, true))
+                if (process_sp->CanDebug(target, true))
+                {
+                    process_sp->m_process_unique_id = ++g_process_unique_id;
+                }
+                else
                     process_sp.reset();
             }
         }
@@ -936,10 +942,13 @@ Process::FindPlugin (Target &target, const char *plugin_name, Listener &listener
             process_sp = create_callback(target, listener, crash_file_path);
             if (process_sp)
             {
-                if (!process_sp->CanDebug(target, false))
-                    process_sp.reset();
-                else
+                if (process_sp->CanDebug(target, false))
+                {
+                    process_sp->m_process_unique_id = ++g_process_unique_id;
                     break;
+                }
+                else
+                    process_sp.reset();
             }
         }
     }
@@ -969,6 +978,7 @@ Process::Process(Target &target, Listener &listener) :
     m_private_state_control_wait(),
     m_private_state_thread (LLDB_INVALID_HOST_THREAD),
     m_mod_id (),
+    m_process_unique_id(0),
     m_thread_index_id (0),
     m_thread_id_to_index_id_map (),
     m_exit_status (-1),