diff --git a/lldb/include/lldb/Target/UnixSignals.h b/lldb/include/lldb/Target/UnixSignals.h --- a/lldb/include/lldb/Target/UnixSignals.h +++ b/lldb/include/lldb/Target/UnixSignals.h @@ -30,7 +30,7 @@ virtual ~UnixSignals(); - const char *GetSignalAsCString(int32_t signo) const; + llvm::StringRef GetSignalAsStringRef(int32_t signo) const; std::string GetSignalDescription(int32_t signo, diff --git a/lldb/source/API/SBUnixSignals.cpp b/lldb/source/API/SBUnixSignals.cpp --- a/lldb/source/API/SBUnixSignals.cpp +++ b/lldb/source/API/SBUnixSignals.cpp @@ -66,7 +66,7 @@ LLDB_INSTRUMENT_VA(this, signo); if (auto signals_sp = GetSP()) - return ConstString(signals_sp->GetSignalAsCString(signo)).GetCString(); + return ConstString(signals_sp->GetSignalAsStringRef(signo)).GetCString(); return nullptr; } diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -1178,7 +1178,7 @@ UnixSignalsSP signals = m_exe_ctx.GetProcessPtr()->GetUnixSignals(); int signo = signals->GetFirstSignalNumber(); while (signo != LLDB_INVALID_SIGNAL_NUMBER) { - request.TryCompleteCurrentArg(signals->GetSignalAsCString(signo)); + request.TryCompleteCurrentArg(signals->GetSignalAsStringRef(signo)); signo = signals->GetNextSignalNumber(signo); } } @@ -1635,13 +1635,13 @@ str.Printf("=========== ===== ===== ======\n"); } - void PrintSignal(Stream &str, int32_t signo, const char *sig_name, + void PrintSignal(Stream &str, int32_t signo, llvm::StringRef sig_name, const UnixSignalsSP &signals_sp) { bool stop; bool suppress; bool notify; - str.Printf("%-11s ", sig_name); + str.Format("{0, -11} ", sig_name); if (signals_sp->GetSignalInfo(signo, suppress, stop, notify)) { bool pass = !suppress; str.Printf("%s %s %s", (pass ? "true " : "false"), @@ -1668,7 +1668,7 @@ { int32_t signo = signals_sp->GetFirstSignalNumber(); while (signo != LLDB_INVALID_SIGNAL_NUMBER) { - PrintSignal(str, signo, signals_sp->GetSignalAsCString(signo), + PrintSignal(str, signo, signals_sp->GetSignalAsStringRef(signo), signals_sp); signo = signals_sp->GetNextSignalNumber(signo); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp @@ -500,7 +500,7 @@ auto dictionary = std::make_shared(); dictionary->AddIntegerItem("signo", signo); - dictionary->AddStringItem("name", signals->GetSignalAsCString(signo)); + dictionary->AddStringItem("name", signals->GetSignalAsStringRef(signo)); bool suppress, stop, notify; signals->GetSignalInfo(signo, suppress, stop, notify); diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -3384,10 +3384,10 @@ stream.Format(DEBUGSERVER_BASENAME " died with an exit status of {0:x8}", exit_status); else { - const char *signal_name = - process_sp->GetUnixSignals()->GetSignalAsCString(signo); + llvm::StringRef signal_name = + process_sp->GetUnixSignals()->GetSignalAsStringRef(signo); const char *format_str = DEBUGSERVER_BASENAME " died with signal {0}"; - if (signal_name) + if (!signal_name.empty()) stream.Format(format_str, signal_name); else stream.Format(format_str, signo); diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -1125,11 +1125,9 @@ if (target_sp) { ProcessSP process_sp(target_sp->GetProcessSP()); if (process_sp) { - const char *signal_cstr = nullptr; - if (signo) - signal_cstr = process_sp->GetUnixSignals()->GetSignalAsCString(signo); - - process_sp->SetExitStatus(exit_status, signal_cstr); + llvm::StringRef signal_str = + process_sp->GetUnixSignals()->GetSignalAsStringRef(signo); + process_sp->SetExitStatus(exit_status, signal_str); } } return true; diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp --- a/lldb/source/Target/StopInfo.cpp +++ b/lldb/source/Target/StopInfo.cpp @@ -1067,9 +1067,9 @@ thread_sp->GetProcess()->GetUnixSignals()->GetShouldNotify(m_value); if (should_notify) { StreamString strm; - strm.Printf( - "thread %d received signal: %s", thread_sp->GetIndexID(), - thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString( + strm.Format( + "thread {0:d} received signal: {1}", thread_sp->GetIndexID(), + thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsStringRef( m_value)); Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData()); diff --git a/lldb/source/Target/UnixSignals.cpp b/lldb/source/Target/UnixSignals.cpp --- a/lldb/source/Target/UnixSignals.cpp +++ b/lldb/source/Target/UnixSignals.cpp @@ -131,12 +131,11 @@ ++m_version; } -const char *UnixSignals::GetSignalAsCString(int signo) const { - collection::const_iterator pos = m_signals.find(signo); +llvm::StringRef UnixSignals::GetSignalAsStringRef(int32_t signo) const { + const auto pos = m_signals.find(signo); if (pos == m_signals.end()) - return nullptr; - else - return pos->second.m_name.GetCString(); + return {}; + return pos->second.m_name.GetStringRef(); } std::string diff --git a/lldb/unittests/Signals/UnixSignalsTest.cpp b/lldb/unittests/Signals/UnixSignalsTest.cpp --- a/lldb/unittests/Signals/UnixSignalsTest.cpp +++ b/lldb/unittests/Signals/UnixSignalsTest.cpp @@ -84,7 +84,7 @@ bool should_suppress = false, should_stop = false, should_notify = false; int32_t signo = 4; - std::string name = + llvm::StringRef name = signals.GetSignalInfo(signo, should_suppress, should_stop, should_notify); EXPECT_EQ("SIG4", name); EXPECT_EQ(true, should_suppress); @@ -94,15 +94,14 @@ EXPECT_EQ(true, signals.GetShouldSuppress(signo)); EXPECT_EQ(false, signals.GetShouldStop(signo)); EXPECT_EQ(true, signals.GetShouldNotify(signo)); - EXPECT_EQ(name, signals.GetSignalAsCString(signo)); + EXPECT_EQ(name, signals.GetSignalAsStringRef(signo)); } -TEST(UnixSignalsTest, GetAsCString) { +TEST(UnixSignalsTest, GetAsStringRef) { TestSignals signals; - ASSERT_EQ(nullptr, signals.GetSignalAsCString(100)); - std::string name = signals.GetSignalAsCString(16); - ASSERT_EQ("SIG16", name); + ASSERT_EQ(llvm::StringRef(), signals.GetSignalAsStringRef(100)); + ASSERT_EQ("SIG16", signals.GetSignalAsStringRef(16)); } TEST(UnixSignalsTest, GetAsString) {