diff options
Diffstat (limited to 'lldb')
| -rw-r--r-- | lldb/include/lldb/API/SBProcess.h | 30 | ||||
| -rw-r--r-- | lldb/include/lldb/Target/Process.h | 7 | ||||
| -rw-r--r-- | lldb/scripts/Python/interface/SBProcess.i | 9 | ||||
| -rw-r--r-- | lldb/source/API/SBProcess.cpp | 13 | ||||
| -rw-r--r-- | lldb/source/Target/Process.cpp | 18 |
5 files changed, 73 insertions, 4 deletions
diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index c65957a9e64..caf9fd88227 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -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; diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 502be1d47f1..a2fc51a8b6c 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -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. diff --git a/lldb/scripts/Python/interface/SBProcess.i b/lldb/scripts/Python/interface/SBProcess.i index a7ebb0a33c5..684d2aae0aa 100644 --- a/lldb/scripts/Python/interface/SBProcess.i +++ b/lldb/scripts/Python/interface/SBProcess.i @@ -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; diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index 1d24e431cbd..6c128b7325f 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -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 { diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 18493de1e63..fc527e2fe00 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -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), |

