diff options
| author | Alex Langford <alangford@apple.com> | 2023-05-17 10:44:38 -0700 |
|---|---|---|
| committer | Alex Langford <alangford@apple.com> | 2023-05-18 15:13:36 -0700 |
| commit | 41714c959d65ff1dd842bc0a0d44f90b06440c39 (patch) | |
| tree | b3a07e61238e2ab7ec0679a870fb6578bb0ba0a3 /lldb/source/API/SBProcess.cpp | |
| parent | 6abd8e30f443b9b17935c40e4451cbc63e3bd49d (diff) | |
[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/SBProcess.cpp')
| -rw-r--r-- | lldb/source/API/SBProcess.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index 4af1a983fe20..a5491c6fa699 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) { |
