[Lldb-commits] [lldb] 41714c9 - [lldb] Guarantee the lifetimes of all strings returned from SBAPI
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Thu May 18 15:18:21 PDT 2023
Author: Alex Langford
Date: 2023-05-18T15:13:36-07:00
New Revision: 41714c959d65ff1dd842bc0a0d44f90b06440c39
URL: https://github.com/llvm/llvm-project/commit/41714c959d65ff1dd842bc0a0d44f90b06440c39
DIFF: https://github.com/llvm/llvm-project/commit/41714c959d65ff1dd842bc0a0d44f90b06440c39.diff
LOG: [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
Added:
Modified:
lldb/docs/design/sbapi.rst
lldb/source/API/SBAttachInfo.cpp
lldb/source/API/SBBreakpoint.cpp
lldb/source/API/SBBreakpointLocation.cpp
lldb/source/API/SBBreakpointName.cpp
lldb/source/API/SBCommandInterpreter.cpp
lldb/source/API/SBData.cpp
lldb/source/API/SBEvent.cpp
lldb/source/API/SBExpressionOptions.cpp
lldb/source/API/SBFrame.cpp
lldb/source/API/SBFunction.cpp
lldb/source/API/SBInstruction.cpp
lldb/source/API/SBLaunchInfo.cpp
lldb/source/API/SBModule.cpp
lldb/source/API/SBPlatform.cpp
lldb/source/API/SBProcess.cpp
lldb/source/API/SBProcessInfo.cpp
lldb/source/API/SBQueue.cpp
lldb/source/API/SBStream.cpp
lldb/source/API/SBStringList.cpp
lldb/source/API/SBTarget.cpp
lldb/source/API/SBThread.cpp
lldb/source/API/SBTrace.cpp
lldb/source/API/SBTraceCursor.cpp
lldb/source/API/SBType.cpp
lldb/source/API/SBTypeCategory.cpp
lldb/source/API/SBTypeFilter.cpp
lldb/source/API/SBTypeNameSpecifier.cpp
lldb/source/API/SBTypeSummary.cpp
lldb/source/API/SBTypeSynthetic.cpp
lldb/source/API/SBUnixSignals.cpp
lldb/source/API/SBValue.cpp
lldb/source/API/SBWatchpoint.cpp
Removed:
################################################################################
diff --git a/lldb/docs/design/sbapi.rst b/lldb/docs/design/sbapi.rst
index f2de0e7ae60ca..cf32cc6c81558 100644
--- a/lldb/docs/design/sbapi.rst
+++ b/lldb/docs/design/sbapi.rst
@@ -72,6 +72,15 @@ building the LLDB framework for macOS, the headers are processed with
``unifdef`` prior to being copied into the framework bundle to remove macros
involving SWIG.
+Lifetime
+--------
+Many SB API methods will return strings in the form of ``const char *`` values.
+Once created, these strings are guaranteed to live until the end of the
+debugging session. LLDB owns these strings, clients should not attempt to free
+them. Doing so may cause LLDB to crash.
+Note that this only affects the C++ API as scripting languages usually
+will usually create native string types from the ``const char *`` value.
+
API Instrumentation
-------------------
diff --git a/lldb/source/API/SBAttachInfo.cpp b/lldb/source/API/SBAttachInfo.cpp
index 1cd1146f5d317..8ce1f1d65c496 100644
--- a/lldb/source/API/SBAttachInfo.cpp
+++ b/lldb/source/API/SBAttachInfo.cpp
@@ -94,7 +94,7 @@ void SBAttachInfo::SetResumeCount(uint32_t c) {
const char *SBAttachInfo::GetProcessPluginName() {
LLDB_INSTRUMENT_VA(this);
- return m_opaque_sp->GetProcessPluginName();
+ return ConstString(m_opaque_sp->GetProcessPluginName()).GetCString();
}
void SBAttachInfo::SetProcessPluginName(const char *plugin_name) {
diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp
index c83fe8c13752e..6631afb1483fb 100644
--- a/lldb/source/API/SBBreakpoint.cpp
+++ b/lldb/source/API/SBBreakpoint.cpp
@@ -284,12 +284,12 @@ const char *SBBreakpoint::GetCondition() {
LLDB_INSTRUMENT_VA(this);
BreakpointSP bkpt_sp = GetSP();
- if (bkpt_sp) {
- std::lock_guard<std::recursive_mutex> guard(
- bkpt_sp->GetTarget().GetAPIMutex());
- return bkpt_sp->GetConditionText();
- }
- return nullptr;
+ if (!bkpt_sp)
+ return nullptr;
+
+ std::lock_guard<std::recursive_mutex> guard(
+ bkpt_sp->GetTarget().GetAPIMutex());
+ return ConstString(bkpt_sp->GetConditionText()).GetCString();
}
void SBBreakpoint::SetAutoContinue(bool auto_continue) {
@@ -411,18 +411,17 @@ void SBBreakpoint::SetThreadName(const char *thread_name) {
const char *SBBreakpoint::GetThreadName() const {
LLDB_INSTRUMENT_VA(this);
- const char *name = nullptr;
BreakpointSP bkpt_sp = GetSP();
- if (bkpt_sp) {
- std::lock_guard<std::recursive_mutex> guard(
- bkpt_sp->GetTarget().GetAPIMutex());
- const ThreadSpec *thread_spec =
- bkpt_sp->GetOptions().GetThreadSpecNoCreate();
- if (thread_spec != nullptr)
- name = thread_spec->GetName();
- }
+ if (!bkpt_sp)
+ return nullptr;
+
+ std::lock_guard<std::recursive_mutex> guard(
+ bkpt_sp->GetTarget().GetAPIMutex());
+ if (const ThreadSpec *thread_spec =
+ bkpt_sp->GetOptions().GetThreadSpecNoCreate())
+ return ConstString(thread_spec->GetName()).GetCString();
- return name;
+ return nullptr;
}
void SBBreakpoint::SetQueueName(const char *queue_name) {
@@ -439,18 +438,17 @@ void SBBreakpoint::SetQueueName(const char *queue_name) {
const char *SBBreakpoint::GetQueueName() const {
LLDB_INSTRUMENT_VA(this);
- const char *name = nullptr;
BreakpointSP bkpt_sp = GetSP();
- if (bkpt_sp) {
- std::lock_guard<std::recursive_mutex> guard(
- bkpt_sp->GetTarget().GetAPIMutex());
- const ThreadSpec *thread_spec =
- bkpt_sp->GetOptions().GetThreadSpecNoCreate();
- if (thread_spec)
- name = thread_spec->GetQueueName();
- }
+ if (!bkpt_sp)
+ return nullptr;
- return name;
+ std::lock_guard<std::recursive_mutex> guard(
+ bkpt_sp->GetTarget().GetAPIMutex());
+ if (const ThreadSpec *thread_spec =
+ bkpt_sp->GetOptions().GetThreadSpecNoCreate())
+ return ConstString(thread_spec->GetQueueName()).GetCString();
+
+ return nullptr;
}
size_t SBBreakpoint::GetNumResolvedLocations() const {
diff --git a/lldb/source/API/SBBreakpointLocation.cpp b/lldb/source/API/SBBreakpointLocation.cpp
index 58b51d0832d91..3c4aab6175c6f 100644
--- a/lldb/source/API/SBBreakpointLocation.cpp
+++ b/lldb/source/API/SBBreakpointLocation.cpp
@@ -169,12 +169,12 @@ const char *SBBreakpointLocation::GetCondition() {
LLDB_INSTRUMENT_VA(this);
BreakpointLocationSP loc_sp = GetSP();
- if (loc_sp) {
- std::lock_guard<std::recursive_mutex> guard(
- loc_sp->GetTarget().GetAPIMutex());
- return loc_sp->GetConditionText();
- }
- return nullptr;
+ if (!loc_sp)
+ return nullptr;
+
+ std::lock_guard<std::recursive_mutex> guard(
+ loc_sp->GetTarget().GetAPIMutex());
+ return ConstString(loc_sp->GetConditionText()).GetCString();
}
void SBBreakpointLocation::SetAutoContinue(bool auto_continue) {
@@ -366,12 +366,12 @@ const char *SBBreakpointLocation::GetThreadName() const {
LLDB_INSTRUMENT_VA(this);
BreakpointLocationSP loc_sp = GetSP();
- if (loc_sp) {
- std::lock_guard<std::recursive_mutex> guard(
- loc_sp->GetTarget().GetAPIMutex());
- return loc_sp->GetThreadName();
- }
- return nullptr;
+ if (!loc_sp)
+ return nullptr;
+
+ std::lock_guard<std::recursive_mutex> guard(
+ loc_sp->GetTarget().GetAPIMutex());
+ return ConstString(loc_sp->GetThreadName()).GetCString();
}
void SBBreakpointLocation::SetQueueName(const char *queue_name) {
@@ -389,12 +389,12 @@ const char *SBBreakpointLocation::GetQueueName() const {
LLDB_INSTRUMENT_VA(this);
BreakpointLocationSP loc_sp = GetSP();
- if (loc_sp) {
- std::lock_guard<std::recursive_mutex> guard(
- loc_sp->GetTarget().GetAPIMutex());
- return loc_sp->GetQueueName();
- }
- return nullptr;
+ if (!loc_sp)
+ return nullptr;
+
+ std::lock_guard<std::recursive_mutex> guard(
+ loc_sp->GetTarget().GetAPIMutex());
+ return ConstString(loc_sp->GetQueueName()).GetCString();
}
bool SBBreakpointLocation::IsResolved() {
diff --git a/lldb/source/API/SBBreakpointName.cpp b/lldb/source/API/SBBreakpointName.cpp
index 372238a6685e5..7f63aaf6fa7d5 100644
--- a/lldb/source/API/SBBreakpointName.cpp
+++ b/lldb/source/API/SBBreakpointName.cpp
@@ -199,7 +199,7 @@ const char *SBBreakpointName::GetName() const {
if (!m_impl_up)
return "<Invalid Breakpoint Name Object>";
- return m_impl_up->GetName();
+ return ConstString(m_impl_up->GetName()).GetCString();
}
void SBBreakpointName::SetEnabled(bool enable) {
@@ -315,9 +315,9 @@ const char *SBBreakpointName::GetCondition() {
return nullptr;
std::lock_guard<std::recursive_mutex> guard(
- m_impl_up->GetTarget()->GetAPIMutex());
+ m_impl_up->GetTarget()->GetAPIMutex());
- return bp_name->GetOptions().GetConditionText();
+ return ConstString(bp_name->GetOptions().GetConditionText()).GetCString();
}
void SBBreakpointName::SetAutoContinue(bool auto_continue) {
@@ -423,9 +423,10 @@ const char *SBBreakpointName::GetThreadName() const {
return nullptr;
std::lock_guard<std::recursive_mutex> guard(
- m_impl_up->GetTarget()->GetAPIMutex());
+ m_impl_up->GetTarget()->GetAPIMutex());
- return bp_name->GetOptions().GetThreadSpec()->GetName();
+ return ConstString(bp_name->GetOptions().GetThreadSpec()->GetName())
+ .GetCString();
}
void SBBreakpointName::SetQueueName(const char *queue_name) {
@@ -450,9 +451,10 @@ const char *SBBreakpointName::GetQueueName() const {
return nullptr;
std::lock_guard<std::recursive_mutex> guard(
- m_impl_up->GetTarget()->GetAPIMutex());
+ m_impl_up->GetTarget()->GetAPIMutex());
- return bp_name->GetOptions().GetThreadSpec()->GetQueueName();
+ return ConstString(bp_name->GetOptions().GetThreadSpec()->GetQueueName())
+ .GetCString();
}
void SBBreakpointName::SetCommandLineCommands(SBStringList &commands) {
@@ -496,7 +498,7 @@ const char *SBBreakpointName::GetHelpString() const {
if (!bp_name)
return "";
- return bp_name->GetHelp();
+ return ConstString(bp_name->GetHelp()).GetCString();
}
void SBBreakpointName::SetHelpString(const char *help_string) {
diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp
index d081665b31efe..9ea72007c71bd 100644
--- a/lldb/source/API/SBCommandInterpreter.cpp
+++ b/lldb/source/API/SBCommandInterpreter.cpp
@@ -516,14 +516,16 @@ const char *SBCommandInterpreter::GetArgumentTypeAsCString(
const lldb::CommandArgumentType arg_type) {
LLDB_INSTRUMENT_VA(arg_type);
- return CommandObject::GetArgumentTypeAsCString(arg_type);
+ return ConstString(CommandObject::GetArgumentTypeAsCString(arg_type))
+ .GetCString();
}
const char *SBCommandInterpreter::GetArgumentDescriptionAsCString(
const lldb::CommandArgumentType arg_type) {
LLDB_INSTRUMENT_VA(arg_type);
- return CommandObject::GetArgumentDescriptionAsCString(arg_type);
+ return ConstString(CommandObject::GetArgumentDescriptionAsCString(arg_type))
+ .GetCString();
}
bool SBCommandInterpreter::EventIsCommandInterpreterEvent(
diff --git a/lldb/source/API/SBData.cpp b/lldb/source/API/SBData.cpp
index 5232bdde1dedd..924a4cdb93bfb 100644
--- a/lldb/source/API/SBData.cpp
+++ b/lldb/source/API/SBData.cpp
@@ -297,16 +297,19 @@ int64_t SBData::GetSignedInt64(lldb::SBError &error, lldb::offset_t offset) {
const char *SBData::GetString(lldb::SBError &error, lldb::offset_t offset) {
LLDB_INSTRUMENT_VA(this, error, offset);
- const char *value = nullptr;
- if (!m_opaque_sp.get()) {
+ if (!m_opaque_sp) {
error.SetErrorString("no value to read from");
- } else {
- uint32_t old_offset = offset;
- value = m_opaque_sp->GetCStr(&offset);
- if (offset == old_offset || (value == nullptr))
- error.SetErrorString("unable to read data");
+ return nullptr;
}
- return value;
+
+ lldb::offset_t old_offset = offset;
+ const char *value = m_opaque_sp->GetCStr(&offset);
+ if (offset == old_offset || value == nullptr) {
+ error.SetErrorString("unable to read data");
+ return nullptr;
+ }
+
+ return ConstString(value).GetCString();
}
bool SBData::GetDescription(lldb::SBStream &description,
diff --git a/lldb/source/API/SBEvent.cpp b/lldb/source/API/SBEvent.cpp
index d4ea0430f163e..13ed148e77371 100644
--- a/lldb/source/API/SBEvent.cpp
+++ b/lldb/source/API/SBEvent.cpp
@@ -63,7 +63,7 @@ const char *SBEvent::GetDataFlavor() {
if (lldb_event) {
EventData *event_data = lldb_event->GetData();
if (event_data)
- return lldb_event->GetData()->GetFlavor().data();
+ return ConstString(lldb_event->GetData()->GetFlavor()).GetCString();
}
return nullptr;
}
@@ -166,8 +166,9 @@ SBEvent::operator bool() const {
const char *SBEvent::GetCStringFromEvent(const SBEvent &event) {
LLDB_INSTRUMENT_VA(event);
- return static_cast<const char *>(
- EventDataBytes::GetBytesFromEvent(event.get()));
+ return ConstString(static_cast<const char *>(
+ EventDataBytes::GetBytesFromEvent(event.get())))
+ .GetCString();
}
bool SBEvent::GetDescription(SBStream &description) {
diff --git a/lldb/source/API/SBExpressionOptions.cpp b/lldb/source/API/SBExpressionOptions.cpp
index 5f1d8d9ddba56..bd81a04596b10 100644
--- a/lldb/source/API/SBExpressionOptions.cpp
+++ b/lldb/source/API/SBExpressionOptions.cpp
@@ -190,7 +190,7 @@ void SBExpressionOptions::SetSuppressPersistentResult(bool b) {
const char *SBExpressionOptions::GetPrefix() const {
LLDB_INSTRUMENT_VA(this);
- return m_opaque_up->GetPrefix();
+ return ConstString(m_opaque_up->GetPrefix()).GetCString();
}
void SBExpressionOptions::SetPrefix(const char *prefix) {
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 4cb086ed40ab4..285469c1063b3 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -708,24 +708,20 @@ SBThread SBFrame::GetThread() const {
const char *SBFrame::Disassemble() const {
LLDB_INSTRUMENT_VA(this);
- const char *disassembly = nullptr;
std::unique_lock<std::recursive_mutex> lock;
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
-
- StackFrame *frame = nullptr;
Target *target = exe_ctx.GetTargetPtr();
Process *process = exe_ctx.GetProcessPtr();
- if (target && process) {
- Process::StopLocker stop_locker;
- if (stop_locker.TryLock(&process->GetRunLock())) {
- frame = exe_ctx.GetFramePtr();
- if (frame) {
- disassembly = frame->Disassemble();
- }
- }
+ if (!target || !process)
+ return nullptr;
+
+ Process::StopLocker stop_locker;
+ if (stop_locker.TryLock(&process->GetRunLock())) {
+ if (auto *frame = exe_ctx.GetFramePtr())
+ return ConstString(frame->Disassemble()).GetCString();
}
- return disassembly;
+ return nullptr;
}
SBValueList SBFrame::GetVariables(bool arguments, bool locals, bool statics,
diff --git a/lldb/source/API/SBFunction.cpp b/lldb/source/API/SBFunction.cpp
index 562cae4e89069..a01c7f79bbd31 100644
--- a/lldb/source/API/SBFunction.cpp
+++ b/lldb/source/API/SBFunction.cpp
@@ -54,30 +54,27 @@ SBFunction::operator bool() const {
const char *SBFunction::GetName() const {
LLDB_INSTRUMENT_VA(this);
- const char *cstr = nullptr;
if (m_opaque_ptr)
- cstr = m_opaque_ptr->GetName().AsCString();
+ return m_opaque_ptr->GetName().AsCString();
- return cstr;
+ return nullptr;
}
const char *SBFunction::GetDisplayName() const {
LLDB_INSTRUMENT_VA(this);
- const char *cstr = nullptr;
if (m_opaque_ptr)
- cstr = m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
+ return m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
- return cstr;
+ return nullptr;
}
const char *SBFunction::GetMangledName() const {
LLDB_INSTRUMENT_VA(this);
- const char *cstr = nullptr;
if (m_opaque_ptr)
- cstr = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
- return cstr;
+ return m_opaque_ptr->GetMangled().GetMangledName().AsCString();
+ return nullptr;
}
bool SBFunction::operator==(const SBFunction &rhs) const {
@@ -166,19 +163,22 @@ SBAddress SBFunction::GetEndAddress() {
const char *SBFunction::GetArgumentName(uint32_t arg_idx) {
LLDB_INSTRUMENT_VA(this, arg_idx);
- if (m_opaque_ptr) {
- Block &block = m_opaque_ptr->GetBlock(true);
- VariableListSP variable_list_sp = block.GetBlockVariableList(true);
- if (variable_list_sp) {
- VariableList arguments;
- variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,
- arguments, true);
- lldb::VariableSP variable_sp = arguments.GetVariableAtIndex(arg_idx);
- if (variable_sp)
- return variable_sp->GetName().GetCString();
- }
- }
- return nullptr;
+ if (!m_opaque_ptr)
+ return nullptr;
+
+ Block &block = m_opaque_ptr->GetBlock(true);
+ VariableListSP variable_list_sp = block.GetBlockVariableList(true);
+ if (!variable_list_sp)
+ return nullptr;
+
+ VariableList arguments;
+ variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,
+ arguments, true);
+ lldb::VariableSP variable_sp = arguments.GetVariableAtIndex(arg_idx);
+ if (!variable_sp)
+ return nullptr;
+
+ return variable_sp->GetName().GetCString();
}
uint32_t SBFunction::GetPrologueByteSize() {
diff --git a/lldb/source/API/SBInstruction.cpp b/lldb/source/API/SBInstruction.cpp
index b03d8f73d66eb..46da6e18b6b2b 100644
--- a/lldb/source/API/SBInstruction.cpp
+++ b/lldb/source/API/SBInstruction.cpp
@@ -111,57 +111,57 @@ const char *SBInstruction::GetMnemonic(SBTarget target) {
LLDB_INSTRUMENT_VA(this, target);
lldb::InstructionSP inst_sp(GetOpaque());
- if (inst_sp) {
- ExecutionContext exe_ctx;
- TargetSP target_sp(target.GetSP());
- std::unique_lock<std::recursive_mutex> lock;
- if (target_sp) {
- lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
+ if (!inst_sp)
+ return nullptr;
- target_sp->CalculateExecutionContext(exe_ctx);
- exe_ctx.SetProcessSP(target_sp->GetProcessSP());
- }
- return inst_sp->GetMnemonic(&exe_ctx);
+ ExecutionContext exe_ctx;
+ TargetSP target_sp(target.GetSP());
+ std::unique_lock<std::recursive_mutex> lock;
+ if (target_sp) {
+ lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
+
+ target_sp->CalculateExecutionContext(exe_ctx);
+ exe_ctx.SetProcessSP(target_sp->GetProcessSP());
}
- return nullptr;
+ return ConstString(inst_sp->GetMnemonic(&exe_ctx)).GetCString();
}
const char *SBInstruction::GetOperands(SBTarget target) {
LLDB_INSTRUMENT_VA(this, target);
lldb::InstructionSP inst_sp(GetOpaque());
- if (inst_sp) {
- ExecutionContext exe_ctx;
- TargetSP target_sp(target.GetSP());
- std::unique_lock<std::recursive_mutex> lock;
- if (target_sp) {
- lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
+ if (!inst_sp)
+ return nullptr;
- target_sp->CalculateExecutionContext(exe_ctx);
- exe_ctx.SetProcessSP(target_sp->GetProcessSP());
- }
- return inst_sp->GetOperands(&exe_ctx);
+ ExecutionContext exe_ctx;
+ TargetSP target_sp(target.GetSP());
+ std::unique_lock<std::recursive_mutex> lock;
+ if (target_sp) {
+ lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
+
+ target_sp->CalculateExecutionContext(exe_ctx);
+ exe_ctx.SetProcessSP(target_sp->GetProcessSP());
}
- return nullptr;
+ return ConstString(inst_sp->GetOperands(&exe_ctx)).GetCString();
}
const char *SBInstruction::GetComment(SBTarget target) {
LLDB_INSTRUMENT_VA(this, target);
lldb::InstructionSP inst_sp(GetOpaque());
- if (inst_sp) {
- ExecutionContext exe_ctx;
- TargetSP target_sp(target.GetSP());
- std::unique_lock<std::recursive_mutex> lock;
- if (target_sp) {
- lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
+ if (!inst_sp)
+ return nullptr;
- target_sp->CalculateExecutionContext(exe_ctx);
- exe_ctx.SetProcessSP(target_sp->GetProcessSP());
- }
- return inst_sp->GetComment(&exe_ctx);
+ ExecutionContext exe_ctx;
+ TargetSP target_sp(target.GetSP());
+ std::unique_lock<std::recursive_mutex> lock;
+ if (target_sp) {
+ lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
+
+ target_sp->CalculateExecutionContext(exe_ctx);
+ exe_ctx.SetProcessSP(target_sp->GetProcessSP());
}
- return nullptr;
+ return ConstString(inst_sp->GetComment(&exe_ctx)).GetCString();
}
lldb::InstructionControlFlowKind SBInstruction::GetControlFlowKind(lldb::SBTarget target) {
diff --git a/lldb/source/API/SBLaunchInfo.cpp b/lldb/source/API/SBLaunchInfo.cpp
index b3ed1b3ac2e60..d5f935083e6c1 100644
--- a/lldb/source/API/SBLaunchInfo.cpp
+++ b/lldb/source/API/SBLaunchInfo.cpp
@@ -148,7 +148,8 @@ uint32_t SBLaunchInfo::GetNumArguments() {
const char *SBLaunchInfo::GetArgumentAtIndex(uint32_t idx) {
LLDB_INSTRUMENT_VA(this, idx);
- return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
+ return ConstString(m_opaque_sp->GetArguments().GetArgumentAtIndex(idx))
+ .GetCString();
}
void SBLaunchInfo::SetArguments(const char **argv, bool append) {
@@ -176,7 +177,7 @@ const char *SBLaunchInfo::GetEnvironmentEntryAtIndex(uint32_t idx) {
if (idx > GetNumEnvironmentEntries())
return nullptr;
- return m_opaque_sp->GetEnvp()[idx];
+ return ConstString(m_opaque_sp->GetEnvp()[idx]).GetCString();
}
void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
@@ -233,7 +234,7 @@ void SBLaunchInfo::SetLaunchFlags(uint32_t flags) {
const char *SBLaunchInfo::GetProcessPluginName() {
LLDB_INSTRUMENT_VA(this);
- return m_opaque_sp->GetProcessPluginName();
+ return ConstString(m_opaque_sp->GetProcessPluginName()).GetCString();
}
void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
@@ -315,7 +316,7 @@ void SBLaunchInfo::SetLaunchEventData(const char *data) {
const char *SBLaunchInfo::GetLaunchEventData() const {
LLDB_INSTRUMENT_VA(this);
- return m_opaque_sp->GetLaunchEventData();
+ return ConstString(m_opaque_sp->GetLaunchEventData()).GetCString();
}
void SBLaunchInfo::SetDetachOnError(bool enable) {
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index e7c2b451eb9d5..b865502228e0a 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() {
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index 807d0085c7bcb..c678edcd810da 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -100,7 +100,7 @@ const char *SBPlatformConnectOptions::GetURL() {
if (m_opaque_ptr->m_url.empty())
return nullptr;
- return m_opaque_ptr->m_url.c_str();
+ return ConstString(m_opaque_ptr->m_url.c_str()).GetCString();
}
void SBPlatformConnectOptions::SetURL(const char *url) {
@@ -203,7 +203,7 @@ const char *SBPlatformShellCommand::GetShell() {
if (m_opaque_ptr->m_shell.empty())
return nullptr;
- return m_opaque_ptr->m_shell.c_str();
+ return ConstString(m_opaque_ptr->m_shell.c_str()).GetCString();
}
void SBPlatformShellCommand::SetShell(const char *shell_interpreter) {
@@ -220,7 +220,7 @@ const char *SBPlatformShellCommand::GetCommand() {
if (m_opaque_ptr->m_command.empty())
return nullptr;
- return m_opaque_ptr->m_command.c_str();
+ return ConstString(m_opaque_ptr->m_command.c_str()).GetCString();
}
void SBPlatformShellCommand::SetCommand(const char *shell_command) {
@@ -237,7 +237,7 @@ const char *SBPlatformShellCommand::GetWorkingDirectory() {
if (m_opaque_ptr->m_working_dir.empty())
return nullptr;
- return m_opaque_ptr->m_working_dir.c_str();
+ return ConstString(m_opaque_ptr->m_working_dir.c_str()).GetCString();
}
void SBPlatformShellCommand::SetWorkingDirectory(const char *path) {
@@ -283,7 +283,7 @@ const char *SBPlatformShellCommand::GetOutput() {
if (m_opaque_ptr->m_output.empty())
return nullptr;
- return m_opaque_ptr->m_output.c_str();
+ return ConstString(m_opaque_ptr->m_output.c_str()).GetCString();
}
// SBPlatform
@@ -454,7 +454,7 @@ const char *SBPlatform::GetHostname() {
PlatformSP platform_sp(GetSP());
if (platform_sp)
- return platform_sp->GetHostname();
+ return ConstString(platform_sp->GetHostname()).GetCString();
return nullptr;
}
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index 4af1a983fe20f..a5491c6fa6997 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -507,14 +507,13 @@ int SBProcess::GetExitStatus() {
const char *SBProcess::GetExitDescription() {
LLDB_INSTRUMENT_VA(this);
- const char *exit_desc = nullptr;
ProcessSP process_sp(GetSP());
- if (process_sp) {
- std::lock_guard<std::recursive_mutex> guard(
- process_sp->GetTarget().GetAPIMutex());
- exit_desc = process_sp->GetExitDescription();
- }
- return exit_desc;
+ if (!process_sp)
+ return nullptr;
+
+ std::lock_guard<std::recursive_mutex> guard(
+ process_sp->GetTarget().GetAPIMutex());
+ return ConstString(process_sp->GetExitDescription()).GetCString();
}
lldb::pid_t SBProcess::GetProcessID() {
@@ -747,7 +746,9 @@ SBProcess::GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event,
size_t idx) {
LLDB_INSTRUMENT_VA(event, idx);
- return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx);
+ return ConstString(Process::ProcessEventData::GetRestartedReasonAtIndex(
+ event.get(), idx))
+ .GetCString();
}
SBProcess SBProcess::GetProcessFromEvent(const SBEvent &event) {
diff --git a/lldb/source/API/SBProcessInfo.cpp b/lldb/source/API/SBProcessInfo.cpp
index da3db75ff47ee..895fba95afbae 100644
--- a/lldb/source/API/SBProcessInfo.cpp
+++ b/lldb/source/API/SBProcessInfo.cpp
@@ -57,11 +57,10 @@ SBProcessInfo::operator bool() const {
const char *SBProcessInfo::GetName() {
LLDB_INSTRUMENT_VA(this);
- const char *name = nullptr;
- if (m_opaque_up) {
- name = m_opaque_up->GetName();
- }
- return name;
+ if (!m_opaque_up)
+ return nullptr;
+
+ return ConstString(m_opaque_up->GetName()).GetCString();
}
SBFileSpec SBProcessInfo::GetExecutableFile() {
@@ -177,14 +176,12 @@ lldb::pid_t SBProcessInfo::GetParentProcessID() {
const char *SBProcessInfo::GetTriple() {
LLDB_INSTRUMENT_VA(this);
- const char *triple = nullptr;
- if (m_opaque_up) {
- const auto &arch = m_opaque_up->GetArchitecture();
- if (arch.IsValid()) {
- // Const-ify the string so we don't need to worry about the lifetime of
- // the string
- triple = ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
- }
- }
- return triple;
+ if (!m_opaque_up)
+ return nullptr;
+
+ const auto &arch = m_opaque_up->GetArchitecture();
+ if (!arch.IsValid())
+ return nullptr;
+
+ return ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
}
diff --git a/lldb/source/API/SBQueue.cpp b/lldb/source/API/SBQueue.cpp
index b97da3ef02edd..968d3b77538c8 100644
--- a/lldb/source/API/SBQueue.cpp
+++ b/lldb/source/API/SBQueue.cpp
@@ -77,12 +77,10 @@ class QueueImpl {
}
const char *GetName() const {
- const char *name = nullptr;
lldb::QueueSP queue_sp = m_queue_wp.lock();
- if (queue_sp.get()) {
- name = queue_sp->GetName();
- }
- return name;
+ if (!queue_sp)
+ return nullptr;
+ return ConstString(queue_sp->GetName()).GetCString();
}
void FetchThreads() {
diff --git a/lldb/source/API/SBStream.cpp b/lldb/source/API/SBStream.cpp
index 870cbb9e14d51..9275a02bb62c6 100644
--- a/lldb/source/API/SBStream.cpp
+++ b/lldb/source/API/SBStream.cpp
@@ -47,7 +47,8 @@ const char *SBStream::GetData() {
if (m_is_file || m_opaque_up == nullptr)
return nullptr;
- return static_cast<StreamString *>(m_opaque_up.get())->GetData();
+ return ConstString(static_cast<StreamString *>(m_opaque_up.get())->GetData())
+ .GetCString();
}
// If this stream is not redirected to a file, it will maintain a local cache
diff --git a/lldb/source/API/SBStringList.cpp b/lldb/source/API/SBStringList.cpp
index dfb77b1ab32fb..27799c744184c 100644
--- a/lldb/source/API/SBStringList.cpp
+++ b/lldb/source/API/SBStringList.cpp
@@ -106,7 +106,7 @@ const char *SBStringList::GetStringAtIndex(size_t idx) {
LLDB_INSTRUMENT_VA(this, idx);
if (IsValid()) {
- return m_opaque_up->GetStringAtIndex(idx);
+ return ConstString(m_opaque_up->GetStringAtIndex(idx)).GetCString();
}
return nullptr;
}
@@ -115,7 +115,7 @@ const char *SBStringList::GetStringAtIndex(size_t idx) const {
LLDB_INSTRUMENT_VA(this, idx);
if (IsValid()) {
- return m_opaque_up->GetStringAtIndex(idx);
+ return ConstString(m_opaque_up->GetStringAtIndex(idx)).GetCString();
}
return nullptr;
}
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 301602c543f2a..980cb7788bf51 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1578,27 +1578,27 @@ const char *SBTarget::GetTriple() {
LLDB_INSTRUMENT_VA(this);
TargetSP target_sp(GetSP());
- if (target_sp) {
- std::string triple(target_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 (!target_sp)
+ return nullptr;
+
+ std::string triple(target_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();
}
const char *SBTarget::GetABIName() {
LLDB_INSTRUMENT_VA(this);
TargetSP target_sp(GetSP());
- if (target_sp) {
- std::string abi_name(target_sp->GetABIName().str());
- ConstString const_name(abi_name.c_str());
- return const_name.GetCString();
- }
- return nullptr;
+ if (!target_sp)
+ return nullptr;
+
+ std::string abi_name(target_sp->GetABIName().str());
+ ConstString const_name(abi_name.c_str());
+ return const_name.GetCString();
}
uint32_t SBTarget::GetDataByteSize() {
diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp
index 35cc45d79c57a..bdd93112b26cd 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 {
diff --git a/lldb/source/API/SBTrace.cpp b/lldb/source/API/SBTrace.cpp
index 5e9d53e3d1863..da31d173425ea 100644
--- a/lldb/source/API/SBTrace.cpp
+++ b/lldb/source/API/SBTrace.cpp
@@ -84,7 +84,10 @@ SBFileSpec SBTrace::SaveToDisk(SBError &error, const SBFileSpec &bundle_dir,
const char *SBTrace::GetStartConfigurationHelp() {
LLDB_INSTRUMENT_VA(this);
- return m_opaque_sp ? m_opaque_sp->GetStartConfigurationHelp() : nullptr;
+ if (!m_opaque_sp)
+ return nullptr;
+
+ return ConstString(m_opaque_sp->GetStartConfigurationHelp()).GetCString();
}
SBError SBTrace::Start(const SBStructuredData &configuration) {
diff --git a/lldb/source/API/SBTraceCursor.cpp b/lldb/source/API/SBTraceCursor.cpp
index f4ae31f616af2..c3dacd0d4b3de 100644
--- a/lldb/source/API/SBTraceCursor.cpp
+++ b/lldb/source/API/SBTraceCursor.cpp
@@ -85,7 +85,7 @@ bool SBTraceCursor::IsError() const {
const char *SBTraceCursor::GetError() const {
LLDB_INSTRUMENT_VA(this);
- return m_opaque_sp->GetError();
+ return ConstString(m_opaque_sp->GetError()).GetCString();
}
bool SBTraceCursor::IsEvent() const {
@@ -103,7 +103,7 @@ lldb::TraceEvent SBTraceCursor::GetEventType() const {
const char *SBTraceCursor::GetEventTypeAsString() const {
LLDB_INSTRUMENT_VA(this);
- return m_opaque_sp->GetEventTypeAsString();
+ return ConstString(m_opaque_sp->GetEventTypeAsString()).GetCString();
}
bool SBTraceCursor::IsInstruction() const {
diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp
index 1ccc3b0c2dc9d..ee5b644742809 100644
--- a/lldb/source/API/SBType.cpp
+++ b/lldb/source/API/SBType.cpp
@@ -809,14 +809,15 @@ const char *SBTypeMemberFunction::GetName() {
const char *SBTypeMemberFunction::GetDemangledName() {
LLDB_INSTRUMENT_VA(this);
- if (m_opaque_sp) {
- ConstString mangled_str = m_opaque_sp->GetMangledName();
- if (mangled_str) {
- Mangled mangled(mangled_str);
- return mangled.GetDemangledName().GetCString();
- }
- }
- return nullptr;
+ if (!m_opaque_sp)
+ return nullptr;
+
+ ConstString mangled_str = m_opaque_sp->GetMangledName();
+ if (!mangled_str)
+ return nullptr;
+
+ Mangled mangled(mangled_str);
+ return mangled.GetDemangledName().GetCString();
}
const char *SBTypeMemberFunction::GetMangledName() {
diff --git a/lldb/source/API/SBTypeCategory.cpp b/lldb/source/API/SBTypeCategory.cpp
index e2911a4c50f68..3521a30c64c5b 100644
--- a/lldb/source/API/SBTypeCategory.cpp
+++ b/lldb/source/API/SBTypeCategory.cpp
@@ -73,7 +73,7 @@ const char *SBTypeCategory::GetName() {
if (!IsValid())
return nullptr;
- return m_opaque_sp->GetName();
+ return ConstString(m_opaque_sp->GetName()).GetCString();
}
lldb::LanguageType SBTypeCategory::GetLanguageAtIndex(uint32_t idx) {
diff --git a/lldb/source/API/SBTypeFilter.cpp b/lldb/source/API/SBTypeFilter.cpp
index 94f222b254b22..8bbf3a8b526f6 100644
--- a/lldb/source/API/SBTypeFilter.cpp
+++ b/lldb/source/API/SBTypeFilter.cpp
@@ -85,13 +85,13 @@ uint32_t SBTypeFilter::GetNumberOfExpressionPaths() {
const char *SBTypeFilter::GetExpressionPathAtIndex(uint32_t i) {
LLDB_INSTRUMENT_VA(this, i);
- if (IsValid()) {
- const char *item = m_opaque_sp->GetExpressionPathAtIndex(i);
- if (item && *item == '.')
- item++;
- return item;
- }
- return nullptr;
+ if (!IsValid())
+ return nullptr;
+
+ const char *item = m_opaque_sp->GetExpressionPathAtIndex(i);
+ if (item && *item == '.')
+ item++;
+ return ConstString(item).GetCString();
}
bool SBTypeFilter::ReplaceExpressionPathAtIndex(uint32_t i, const char *item) {
diff --git a/lldb/source/API/SBTypeNameSpecifier.cpp b/lldb/source/API/SBTypeNameSpecifier.cpp
index 8a6eb086a9b15..308b1cd6b2bec 100644
--- a/lldb/source/API/SBTypeNameSpecifier.cpp
+++ b/lldb/source/API/SBTypeNameSpecifier.cpp
@@ -65,7 +65,7 @@ const char *SBTypeNameSpecifier::GetName() {
if (!IsValid())
return nullptr;
- return m_opaque_sp->GetName();
+ return ConstString(m_opaque_sp->GetName()).GetCString();
}
SBType SBTypeNameSpecifier::GetType() {
diff --git a/lldb/source/API/SBTypeSummary.cpp b/lldb/source/API/SBTypeSummary.cpp
index a65dfc987ad21..be43aeb482614 100644
--- a/lldb/source/API/SBTypeSummary.cpp
+++ b/lldb/source/API/SBTypeSummary.cpp
@@ -222,11 +222,11 @@ const char *SBTypeSummary::GetData() {
const char *fname = script_summary_ptr->GetFunctionName();
const char *ftext = script_summary_ptr->GetPythonScript();
if (ftext && *ftext)
- return ftext;
- return fname;
+ return ConstString(ftext).GetCString();
+ return ConstString(fname).GetCString();
} else if (StringSummaryFormat *string_summary_ptr =
llvm::dyn_cast<StringSummaryFormat>(m_opaque_sp.get()))
- return string_summary_ptr->GetSummaryString();
+ return ConstString(string_summary_ptr->GetSummaryString()).GetCString();
return nullptr;
}
diff --git a/lldb/source/API/SBTypeSynthetic.cpp b/lldb/source/API/SBTypeSynthetic.cpp
index 7258ff04745de..e2441eea7e10f 100644
--- a/lldb/source/API/SBTypeSynthetic.cpp
+++ b/lldb/source/API/SBTypeSynthetic.cpp
@@ -78,9 +78,9 @@ const char *SBTypeSynthetic::GetData() {
if (!IsValid())
return nullptr;
if (IsClassCode())
- return m_opaque_sp->GetPythonCode();
- else
- return m_opaque_sp->GetPythonClassName();
+ return ConstString(m_opaque_sp->GetPythonCode()).GetCString();
+
+ return ConstString(m_opaque_sp->GetPythonClassName()).GetCString();
}
void SBTypeSynthetic::SetClassName(const char *data) {
diff --git a/lldb/source/API/SBUnixSignals.cpp b/lldb/source/API/SBUnixSignals.cpp
index dc7a68255d131..7cccbaff1d2fe 100644
--- a/lldb/source/API/SBUnixSignals.cpp
+++ b/lldb/source/API/SBUnixSignals.cpp
@@ -66,7 +66,7 @@ const char *SBUnixSignals::GetSignalAsCString(int32_t signo) const {
LLDB_INSTRUMENT_VA(this, signo);
if (auto signals_sp = GetSP())
- return signals_sp->GetSignalAsCString(signo);
+ return ConstString(signals_sp->GetSignalAsCString(signo)).GetCString();
return nullptr;
}
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index ecd16ccf83a8f..f52041b4144d2 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -291,39 +291,34 @@ user_id_t SBValue::GetID() {
const char *SBValue::GetName() {
LLDB_INSTRUMENT_VA(this);
- const char *name = nullptr;
ValueLocker locker;
lldb::ValueObjectSP value_sp(GetSP(locker));
- if (value_sp)
- name = value_sp->GetName().GetCString();
+ if (!value_sp)
+ return nullptr;
- return name;
+ return value_sp->GetName().GetCString();
}
const char *SBValue::GetTypeName() {
LLDB_INSTRUMENT_VA(this);
- const char *name = nullptr;
ValueLocker locker;
lldb::ValueObjectSP value_sp(GetSP(locker));
- if (value_sp) {
- name = value_sp->GetQualifiedTypeName().GetCString();
- }
+ if (!value_sp)
+ return nullptr;
- return name;
+ return value_sp->GetQualifiedTypeName().GetCString();
}
const char *SBValue::GetDisplayTypeName() {
LLDB_INSTRUMENT_VA(this);
- const char *name = nullptr;
ValueLocker locker;
lldb::ValueObjectSP value_sp(GetSP(locker));
- if (value_sp) {
- name = value_sp->GetDisplayTypeName().GetCString();
- }
+ if (!value_sp)
+ return nullptr;
- return name;
+ return value_sp->GetDisplayTypeName().GetCString();
}
size_t SBValue::GetByteSize() {
@@ -357,14 +352,11 @@ bool SBValue::IsInScope() {
const char *SBValue::GetValue() {
LLDB_INSTRUMENT_VA(this);
- const char *cstr = nullptr;
ValueLocker locker;
lldb::ValueObjectSP value_sp(GetSP(locker));
- if (value_sp) {
- cstr = value_sp->GetValueAsCString();
- }
-
- return cstr;
+ if (!value_sp)
+ return nullptr;
+ return ConstString(value_sp->GetValueAsCString()).GetCString();
}
ValueType SBValue::GetValueType() {
@@ -382,14 +374,12 @@ ValueType SBValue::GetValueType() {
const char *SBValue::GetObjectDescription() {
LLDB_INSTRUMENT_VA(this);
- const char *cstr = nullptr;
ValueLocker locker;
lldb::ValueObjectSP value_sp(GetSP(locker));
- if (value_sp) {
- cstr = value_sp->GetObjectDescription();
- }
+ if (!value_sp)
+ return nullptr;
- return cstr;
+ return ConstString(value_sp->GetObjectDescription()).GetCString();
}
SBType SBValue::GetType() {
@@ -424,14 +414,12 @@ bool SBValue::GetValueDidChange() {
const char *SBValue::GetSummary() {
LLDB_INSTRUMENT_VA(this);
- const char *cstr = nullptr;
ValueLocker locker;
lldb::ValueObjectSP value_sp(GetSP(locker));
- if (value_sp) {
- cstr = value_sp->GetSummaryAsCString();
- }
+ if (!value_sp)
+ return nullptr;
- return cstr;
+ return ConstString(value_sp->GetSummaryAsCString()).GetCString();
}
const char *SBValue::GetSummary(lldb::SBStream &stream,
@@ -445,20 +433,18 @@ const char *SBValue::GetSummary(lldb::SBStream &stream,
if (value_sp->GetSummaryAsCString(buffer, options.ref()) && !buffer.empty())
stream.Printf("%s", buffer.c_str());
}
- const char *cstr = stream.GetData();
- return cstr;
+ return ConstString(stream.GetData()).GetCString();
}
const char *SBValue::GetLocation() {
LLDB_INSTRUMENT_VA(this);
- const char *cstr = nullptr;
ValueLocker locker;
lldb::ValueObjectSP value_sp(GetSP(locker));
- if (value_sp) {
- cstr = value_sp->GetLocationAsCString();
- }
- return cstr;
+ if (!value_sp)
+ return nullptr;
+
+ return ConstString(value_sp->GetLocationAsCString()).GetCString();
}
// Deprecated - use the one that takes an lldb::SBError
diff --git a/lldb/source/API/SBWatchpoint.cpp b/lldb/source/API/SBWatchpoint.cpp
index 77efd88366028..f5a7f53a8b302 100644
--- a/lldb/source/API/SBWatchpoint.cpp
+++ b/lldb/source/API/SBWatchpoint.cpp
@@ -210,12 +210,12 @@ const char *SBWatchpoint::GetCondition() {
LLDB_INSTRUMENT_VA(this);
lldb::WatchpointSP watchpoint_sp(GetSP());
- if (watchpoint_sp) {
- std::lock_guard<std::recursive_mutex> guard(
- watchpoint_sp->GetTarget().GetAPIMutex());
- return watchpoint_sp->GetConditionText();
- }
- return nullptr;
+ if (!watchpoint_sp)
+ return nullptr;
+
+ std::lock_guard<std::recursive_mutex> guard(
+ watchpoint_sp->GetTarget().GetAPIMutex());
+ return ConstString(watchpoint_sp->GetConditionText()).GetCString();
}
void SBWatchpoint::SetCondition(const char *condition) {
@@ -323,16 +323,16 @@ const char *SBWatchpoint::GetWatchSpec() {
LLDB_INSTRUMENT_VA(this);
lldb::WatchpointSP watchpoint_sp(GetSP());
- if (watchpoint_sp) {
- std::lock_guard<std::recursive_mutex> guard(
- watchpoint_sp->GetTarget().GetAPIMutex());
- // Store the result of `GetWatchSpec()` as a ConstString
- // so that the C string we return has a sufficiently long
- // lifetime. Note this a memory leak but should be fairly
- // low impact.
- return ConstString(watchpoint_sp->GetWatchSpec()).AsCString();
- }
- return nullptr;
+ if (!watchpoint_sp)
+ return nullptr;
+
+ std::lock_guard<std::recursive_mutex> guard(
+ watchpoint_sp->GetTarget().GetAPIMutex());
+ // Store the result of `GetWatchSpec()` as a ConstString
+ // so that the C string we return has a sufficiently long
+ // lifetime. Note this a memory leak but should be fairly
+ // low impact.
+ return ConstString(watchpoint_sp->GetWatchSpec()).AsCString();
}
bool SBWatchpoint::IsWatchingReads() {
More information about the lldb-commits
mailing list