aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/API/SBModule.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/SBModule.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/SBModule.cpp')
-rw-r--r--lldb/source/API/SBModule.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index e7c2b45..b865502 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -173,20 +173,20 @@ const uint8_t *SBModule::GetUUIDBytes() const {
const char *SBModule::GetUUIDString() const {
LLDB_INSTRUMENT_VA(this);
- const char *uuid_cstr = nullptr;
ModuleSP module_sp(GetSP());
- if (module_sp) {
- // We are going to return a "const char *" value through the public API, so
- // we need to constify it so it gets added permanently the string pool and
- // then we don't need to worry about the lifetime of the string as it will
- // never go away once it has been put into the ConstString string pool
- uuid_cstr = ConstString(module_sp->GetUUID().GetAsString()).GetCString();
- }
-
- if (uuid_cstr && uuid_cstr[0]) {
+ if (!module_sp)
+ return nullptr;
+
+ // We are going to return a "const char *" value through the public API, so
+ // we need to constify it so it gets added permanently the string pool and
+ // then we don't need to worry about the lifetime of the string as it will
+ // never go away once it has been put into the ConstString string pool
+ const char *uuid_cstr =
+ ConstString(module_sp->GetUUID().GetAsString()).GetCString();
+ // Note: SBModule::GetUUIDString's expected behavior is to return nullptr if
+ // the string we get is empty, so we must perform this check before returning.
+ if (uuid_cstr && uuid_cstr[0])
return uuid_cstr;
- }
-
return nullptr;
}
@@ -579,15 +579,15 @@ const char *SBModule::GetTriple() {
LLDB_INSTRUMENT_VA(this);
ModuleSP module_sp(GetSP());
- if (module_sp) {
- std::string triple(module_sp->GetArchitecture().GetTriple().str());
- // Unique the string so we don't run into ownership issues since the const
- // strings put the string into the string pool once and the strings never
- // comes out
- ConstString const_triple(triple.c_str());
- return const_triple.GetCString();
- }
- return nullptr;
+ if (!module_sp)
+ return nullptr;
+
+ std::string triple(module_sp->GetArchitecture().GetTriple().str());
+ // Unique the string so we don't run into ownership issues since the const
+ // strings put the string into the string pool once and the strings never
+ // comes out
+ ConstString const_triple(triple.c_str());
+ return const_triple.GetCString();
}
uint32_t SBModule::GetAddressByteSize() {