[Lldb-commits] [lldb] r172628 - in /lldb/trunk: include/lldb/API/SBProcess.h include/lldb/Target/Process.h scripts/Python/interface/SBProcess.i source/API/SBProcess.cpp source/Target/Process.cpp

Greg Clayton gclayton at apple.com
Wed Jan 16 09:29:04 PST 2013


Author: gclayton
Date: Wed Jan 16 11:29:04 2013
New Revision: 172628

URL: http://llvm.org/viewvc/llvm-project?rev=172628&view=rev
Log:
<rdar://problem/13009943>

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.




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

Modified: lldb/trunk/include/lldb/API/SBProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=172628&r1=172627&r2=172628&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBProcess.h (original)
+++ lldb/trunk/include/lldb/API/SBProcess.h Wed Jan 16 11:29:04 2013
@@ -144,9 +144,39 @@
     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;
 

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=172628&r1=172627&r2=172628&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Wed Jan 16 11:29:04 2013
@@ -1392,6 +1392,7 @@
         return GetStaticBroadcasterClass();
     }
 
+    
     //------------------------------------------------------------------
     /// A notification structure that can be used by clients to listen
     /// for changes in a process's lifetime.
@@ -1580,6 +1581,11 @@
     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 @@
     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.

Modified: lldb/trunk/scripts/Python/interface/SBProcess.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBProcess.i?rev=172628&r1=172627&r2=172628&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBProcess.i (original)
+++ lldb/trunk/scripts/Python/interface/SBProcess.i Wed Jan 16 11:29:04 2013
@@ -186,8 +186,17 @@
     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;

Modified: lldb/trunk/source/API/SBProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=172628&r1=172627&r2=172628&view=diff
==============================================================================
--- lldb/trunk/source/API/SBProcess.cpp (original)
+++ lldb/trunk/source/API/SBProcess.cpp Wed Jan 16 11:29:04 2013
@@ -596,6 +596,19 @@
     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
 {

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=172628&r1=172627&r2=172628&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed Jan 16 11:29:04 2013
@@ -914,6 +914,8 @@
 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_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_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 @@
     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),





More information about the lldb-commits mailing list