aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/API/SBThread.cpp
diff options
context:
space:
mode:
authorAlex Langford <alangford@apple.com>2023-05-17 10:44:38 -0700
committerAlex Langford <alangford@apple.com>2023-05-18 15:13:36 -0700
commit41714c959d65ff1dd842bc0a0d44f90b06440c39 (patch)
treeb3a07e61238e2ab7ec0679a870fb6578bb0ba0a3 /lldb/source/API/SBThread.cpp
parent6abd8e30f443b9b17935c40e4451cbc63e3bd49d (diff)
downloadllvm-41714c959d65ff1dd842bc0a0d44f90b06440c39.zip
llvm-41714c959d65ff1dd842bc0a0d44f90b06440c39.tar.gz
llvm-41714c959d65ff1dd842bc0a0d44f90b06440c39.tar.bz2
[lldb] Guarantee the lifetimes of all strings returned from SBAPI
LLDB should guarantee that the strings returned by SBAPI methods live forever. I went through every method that returns a string and made sure that it was added to the ConstString StringPool before returning if it wasn't obvious that it was already doing so. I've also updated the docs to document this behavior. Differential Revision: https://reviews.llvm.org/D150804
Diffstat (limited to 'lldb/source/API/SBThread.cpp')
-rw-r--r--lldb/source/API/SBThread.cpp30
1 files changed, 14 insertions, 16 deletions
diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp
index 35cc45d..bdd9311 100644
--- a/lldb/source/API/SBThread.cpp
+++ b/lldb/source/API/SBThread.cpp
@@ -394,35 +394,33 @@ uint32_t SBThread::GetIndexID() const {
const char *SBThread::GetName() const {
LLDB_INSTRUMENT_VA(this);
- const char *name = nullptr;
std::unique_lock<std::recursive_mutex> lock;
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
- if (exe_ctx.HasThreadScope()) {
- Process::StopLocker stop_locker;
- if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
- name = exe_ctx.GetThreadPtr()->GetName();
- }
- }
+ if (!exe_ctx.HasThreadScope())
+ return nullptr;
+
+ Process::StopLocker stop_locker;
+ if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+ return ConstString(exe_ctx.GetThreadPtr()->GetName()).GetCString();
- return name;
+ return nullptr;
}
const char *SBThread::GetQueueName() const {
LLDB_INSTRUMENT_VA(this);
- const char *name = nullptr;
std::unique_lock<std::recursive_mutex> lock;
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
- if (exe_ctx.HasThreadScope()) {
- Process::StopLocker stop_locker;
- if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock())) {
- name = exe_ctx.GetThreadPtr()->GetQueueName();
- }
- }
+ if (!exe_ctx.HasThreadScope())
+ return nullptr;
+
+ Process::StopLocker stop_locker;
+ if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+ return ConstString(exe_ctx.GetThreadPtr()->GetQueueName()).GetCString();
- return name;
+ return nullptr;
}
lldb::queue_id_t SBThread::GetQueueID() const {