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 @@ -48,19 +48,19 @@ state = process->GetState(); if (process->IsAlive() && state != eStateConnected) { - char message[1024]; + std::string message; if (process->GetState() == eStateAttaching) - ::snprintf(message, sizeof(message), - "There is a pending attach, abort it and %s?", - m_new_process_action.c_str()); + message = + llvm::formatv("There is a pending attach, abort it and {0}?", + m_new_process_action); else if (process->GetShouldDetach()) - ::snprintf(message, sizeof(message), - "There is a running process, detach from it and %s?", - m_new_process_action.c_str()); + message = llvm::formatv( + "There is a running process, detach from it and {0}?", + m_new_process_action); else - ::snprintf(message, sizeof(message), - "There is a running process, kill it and %s?", - m_new_process_action.c_str()); + message = + llvm::formatv("There is a running process, kill it and {0}?", + m_new_process_action); if (!m_interpreter.Confirm(message, true)) { result.SetStatus(eReturnStatusFailed); 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 @@ -199,9 +199,8 @@ LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION), "{0} Communication::StartReadThread ()", this); - char thread_name[1024]; - snprintf(thread_name, sizeof(thread_name), "", - GetBroadcasterName().AsCString()); + const std::string thread_name = + llvm::formatv("", GetBroadcasterName()); m_read_thread_enabled = true; m_read_thread_did_exit = false; diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -666,9 +666,7 @@ m_event_handler_thread(), m_io_handler_thread(), m_sync_broadcaster(nullptr, "lldb.debugger.sync"), m_forward_listener_sp(), m_clear_once() { - char instance_cstr[256]; - snprintf(instance_cstr, sizeof(instance_cstr), "debugger_%d", (int)GetID()); - m_instance_name.SetCString(instance_cstr); + m_instance_name.SetString(llvm::formatv("debugger_{0}", GetID()).str()); if (log_callback) m_log_callback_stream_sp = std::make_shared(log_callback, baton); diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp --- a/lldb/source/Core/SourceManager.cpp +++ b/lldb/source/Core/SourceManager.cpp @@ -183,14 +183,14 @@ break; } - char prefix[32] = ""; + std::string prefix; if (bp_locs) { uint32_t bp_count = bp_locs->NumLineEntriesWithLine(line); if (bp_count > 0) - ::snprintf(prefix, sizeof(prefix), "[%u] ", bp_count); + prefix = llvm::formatv("[{0}]", bp_count); else - ::snprintf(prefix, sizeof(prefix), " "); + prefix = " "; } char buffer[3]; @@ -206,7 +206,8 @@ .str()); } - s->Printf("%s%s %-4u\t", prefix, current_line_highlight.c_str(), line); + s->Printf("%s%s %-4u\t", prefix.c_str(), current_line_highlight.c_str(), + line); // So far we treated column 0 as a special 'no column value', but // DisplaySourceLines starts counting columns from 0 (and no column is diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1702,8 +1702,7 @@ bool can_create) { ValueObjectSP synthetic_child_sp; if (IsPointerType() || IsArrayType()) { - char index_str[64]; - snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index); + std::string index_str = llvm::formatv("[{0}]", index); ConstString index_const_str(index_str); // Check if we have already created a synthetic array member in this valid // object. If we have we will re-use it. @@ -1730,8 +1729,7 @@ bool can_create) { ValueObjectSP synthetic_child_sp; if (IsScalarType()) { - char index_str[64]; - snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); + std::string index_str = llvm::formatv("[{0}-{1}]", from, to); ConstString index_const_str(index_str); // Check if we have already created a synthetic array member in this valid // object. If we have we will re-use it. @@ -1768,9 +1766,7 @@ ValueObjectSP synthetic_child_sp; if (name_const_str.IsEmpty()) { - char name_str[64]; - snprintf(name_str, sizeof(name_str), "@%i", offset); - name_const_str.SetCString(name_str); + name_const_str.SetString("@" + std::to_string(offset)); } // Check if we have already created a synthetic array member in this valid diff --git a/lldb/source/Core/ValueObjectChild.cpp b/lldb/source/Core/ValueObjectChild.cpp --- a/lldb/source/Core/ValueObjectChild.cpp +++ b/lldb/source/Core/ValueObjectChild.cpp @@ -57,15 +57,8 @@ static void AdjustForBitfieldness(ConstString &name, uint8_t bitfield_bit_size) { - if (name && bitfield_bit_size) { - const char *compiler_type_name = name.AsCString(); - if (compiler_type_name) { - std::vector bitfield_type_name(strlen(compiler_type_name) + 32, 0); - ::snprintf(&bitfield_type_name.front(), bitfield_type_name.size(), - "%s:%u", compiler_type_name, bitfield_bit_size); - name.SetCString(&bitfield_type_name.front()); - } - } + if (name && bitfield_bit_size) + name.SetString(llvm::formatv("{0}:{1}", name, bitfield_bit_size).str()); } ConstString ValueObjectChild::GetTypeName() { diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1987,10 +1987,7 @@ if (value_type != OptionParser::eOptionalArgument) new_args.AppendArgument(value); else { - char buffer[255]; - ::snprintf(buffer, sizeof(buffer), "%s%s", option.c_str(), - value.c_str()); - new_args.AppendArgument(llvm::StringRef(buffer)); + new_args.AppendArgument(option + value); } } else if (static_cast(index) >= cmd_args.GetArgumentCount()) { @@ -2012,10 +2009,7 @@ if (value_type != OptionParser::eOptionalArgument) new_args.AppendArgument(cmd_args.GetArgumentAtIndex(index)); else { - char buffer[255]; - ::snprintf(buffer, sizeof(buffer), "%s%s", option.c_str(), - cmd_args.GetArgumentAtIndex(index)); - new_args.AppendArgument(buffer); + new_args.AppendArgument(option + cmd_args.GetArgumentAtIndex(index)); } used[index] = true; }