diff --git a/lldb/include/lldb/Core/Communication.h b/lldb/include/lldb/Core/Communication.h --- a/lldb/include/lldb/Core/Communication.h +++ b/lldb/include/lldb/Core/Communication.h @@ -285,7 +285,7 @@ /// void SynchronizeWithReadThread(); - static const char *ConnectionStatusAsCString(lldb::ConnectionStatus status); + static std::string ConnectionStatusAsString(lldb::ConnectionStatus status); bool GetCloseOnEOF() const { return m_close_on_eof; } diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h --- a/lldb/include/lldb/Target/Thread.h +++ b/lldb/include/lldb/Target/Thread.h @@ -253,9 +253,9 @@ bool ThreadStoppedForAReason(); - static const char *RunModeAsCString(lldb::RunMode mode); + static std::string RunModeAsString(lldb::RunMode mode); - static const char *StopReasonAsCString(lldb::StopReason reason); + static std::string StopReasonAsString(lldb::StopReason reason); virtual const char *GetInfo() { return nullptr; } diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp --- a/lldb/source/Core/Communication.cpp +++ b/lldb/source/Core/Communication.cpp @@ -339,7 +339,7 @@ } if (error.Fail()) LLDB_LOG(log, "error: {0}, status = {1}", error, - Communication::ConnectionStatusAsCString(status)); + Communication::ConnectionStatusAsString(status)); break; case eConnectionStatusInterrupted: // Synchronization signal from // SynchronizeWithReadThread() @@ -355,7 +355,7 @@ case eConnectionStatusTimedOut: // Request timed out if (error.Fail()) LLDB_LOG(log, "error: {0}, status = {1}", error, - Communication::ConnectionStatusAsCString(status)); + Communication::ConnectionStatusAsString(status)); break; } } @@ -416,8 +416,8 @@ m_connection_sp = std::move(connection); } -const char * -Communication::ConnectionStatusAsCString(lldb::ConnectionStatus status) { +std::string +Communication::ConnectionStatusAsString(lldb::ConnectionStatus status) { switch (status) { case eConnectionStatusSuccess: return "success"; @@ -435,8 +435,5 @@ return "interrupted"; } - static char unknown_state_string[64]; - snprintf(unknown_state_string, sizeof(unknown_state_string), - "ConnectionStatus = %i", status); - return unknown_state_string; + return "@" + std::to_string(status); } diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp --- a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp +++ b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp @@ -194,12 +194,11 @@ : std::chrono::microseconds(timeout_usec), status, &error); - LLDB_LOGV(log, - "Read (buffer, sizeof(buffer), timeout_usec = 0x{0:x}, " - "status = {1}, error = {2}) => bytes_read = {4}", - timeout_usec, - Communication::ConnectionStatusAsCString(status), - error, bytes_read); + LLDB_LOGV(log, + "Read (buffer, sizeof(buffer), timeout_usec = 0x{0:x}, " + "status = {1}, error = {2}) => bytes_read = {4}", + timeout_usec, Communication::ConnectionStatusAsString(status), + error, bytes_read); if (bytes_read > 0) { if (CheckForPacket(buffer, bytes_read, packet)) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -284,7 +284,7 @@ LLDB_LOGV(log, "Read(buffer, sizeof(buffer), timeout = {0}, " "status = {1}, error = {2}) => bytes_read = {3}", - timeout, Communication::ConnectionStatusAsCString(status), error, + timeout, Communication::ConnectionStatusAsString(status), error, bytes_read); if (bytes_read > 0) { diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp --- a/lldb/source/Target/Thread.cpp +++ b/lldb/source/Target/Thread.cpp @@ -1661,7 +1661,7 @@ return GetStackFrameList()->GetStackFrameSPForStackFramePtr(stack_frame_ptr); } -const char *Thread::StopReasonAsCString(lldb::StopReason reason) { +std::string Thread::StopReasonAsString(lldb::StopReason reason) { switch (reason) { case eStopReasonInvalid: return "invalid"; @@ -1687,13 +1687,10 @@ return "instrumentation break"; } - static char unknown_state_string[64]; - snprintf(unknown_state_string, sizeof(unknown_state_string), - "StopReason = %i", reason); - return unknown_state_string; + return "StopReason = " + std::to_string(reason); } -const char *Thread::RunModeAsCString(lldb::RunMode mode) { +std::string Thread::RunModeAsString(lldb::RunMode mode) { switch (mode) { case eOnlyThisThread: return "only this thread"; @@ -1703,10 +1700,7 @@ return "only during stepping"; } - static char unknown_state_string[64]; - snprintf(unknown_state_string, sizeof(unknown_state_string), "RunMode = %i", - mode); - return unknown_state_string; + return "RunMode = " + std::to_string(mode); } size_t Thread::GetStatus(Stream &strm, uint32_t start_frame, diff --git a/lldb/source/Target/ThreadPlanCallFunction.cpp b/lldb/source/Target/ThreadPlanCallFunction.cpp --- a/lldb/source/Target/ThreadPlanCallFunction.cpp +++ b/lldb/source/Target/ThreadPlanCallFunction.cpp @@ -260,9 +260,9 @@ stop_reason = eStopReasonNone; else stop_reason = m_real_stop_info_sp->GetStopReason(); - LLDB_LOGF(log, - "ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.", - Thread::StopReasonAsCString(stop_reason)); + LLDB_LOG(log, + "ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - {0}.", + Thread::StopReasonAsString(stop_reason)); if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop()) return true; diff --git a/lldb/source/Target/ThreadPlanStepOverBreakpoint.cpp b/lldb/source/Target/ThreadPlanStepOverBreakpoint.cpp --- a/lldb/source/Target/ThreadPlanStepOverBreakpoint.cpp +++ b/lldb/source/Target/ThreadPlanStepOverBreakpoint.cpp @@ -62,8 +62,8 @@ StopReason reason = stop_info_sp->GetStopReason(); Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); - LLDB_LOGF(log, "Step over breakpoint stopped for reason: %s.", - Thread::StopReasonAsCString(reason)); + LLDB_LOG(log, "Step over breakpoint stopped for reason: {0}.", + Thread::StopReasonAsString(reason)); switch (reason) { case eStopReasonTrace: