https://github.com/JOE1994 created https://github.com/llvm/llvm-project/pull/108745
* Don't call raw_string_ostream::flush(), which is essentially a no-op. * Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection. >From 35f463d394ec57a38a4e940a61af5cd1f527a00d Mon Sep 17 00:00:00 2001 From: JOE1994 <joseph942...@gmail.com> Date: Sun, 15 Sep 2024 05:16:25 -0400 Subject: [PATCH] [lldb] Nits on uses of llvm::raw_string_ostream (NFC) * Don't call raw_string_ostream::flush(), which is essentially a no-op. * Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection. --- lldb/include/lldb/Utility/Instrumentation.h | 2 +- lldb/source/Breakpoint/Breakpoint.cpp | 2 +- lldb/source/Commands/CommandObjectLog.cpp | 8 ++++---- lldb/source/Commands/CommandObjectRegexCommand.cpp | 2 +- lldb/source/Core/Module.cpp | 4 ++-- lldb/source/Expression/IRExecutionUnit.cpp | 2 -- lldb/source/Expression/IRInterpreter.cpp | 4 ---- lldb/source/Host/windows/PipeWindows.cpp | 1 - lldb/source/Interpreter/Options.cpp | 2 +- .../Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp | 2 -- .../ExpressionParser/Clang/ClangExpressionParser.cpp | 2 -- .../ExpressionParser/Clang/ClangModulesDeclVendor.cpp | 1 - .../Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp | 3 --- .../Plugins/ExpressionParser/Clang/IRForTarget.cpp | 9 --------- .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 2 +- .../Process/Windows/Common/NativeProcessWindows.cpp | 2 +- .../Plugins/Process/Windows/Common/ProcessWindows.cpp | 6 +++--- .../Process/gdb-remote/GDBRemoteCommunicationClient.cpp | 5 +---- .../Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | 2 +- lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp | 4 ++-- .../Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp | 2 +- .../source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp | 2 +- .../Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp | 2 +- lldb/source/Symbol/Symtab.cpp | 2 +- lldb/source/Target/Statistics.cpp | 2 +- lldb/source/Target/Target.cpp | 2 +- lldb/source/Utility/LLDBAssert.cpp | 2 +- lldb/source/Utility/Log.cpp | 2 +- lldb/tools/lldb-dap/DAP.cpp | 6 ++---- lldb/tools/lldb-dap/JSONUtils.cpp | 1 - lldb/tools/lldb-dap/LLDBUtils.cpp | 1 - lldb/tools/lldb-dap/lldb-dap.cpp | 3 --- lldb/tools/lldb-instr/Instrument.cpp | 4 ++-- lldb/tools/lldb-server/LLDBServerUtilities.cpp | 2 +- lldb/tools/lldb-test/lldb-test.cpp | 2 +- lldb/unittests/Symbol/PostfixExpressionTest.cpp | 2 +- .../NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp | 2 +- 37 files changed, 35 insertions(+), 69 deletions(-) diff --git a/lldb/include/lldb/Utility/Instrumentation.h b/lldb/include/lldb/Utility/Instrumentation.h index 4a9ac810eb05e9..1a86bfb38654b5 100644 --- a/lldb/include/lldb/Utility/Instrumentation.h +++ b/lldb/include/lldb/Utility/Instrumentation.h @@ -70,7 +70,7 @@ template <typename... Ts> inline std::string stringify_args(const Ts &...ts) { std::string buffer; llvm::raw_string_ostream ss(buffer); stringify_helper(ss, ts...); - return ss.str(); + return buffer; } /// RAII object for instrumenting LLDB API functions. diff --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp index 3268ce0b6857da..54ebafc3f65b5c 100644 --- a/lldb/source/Breakpoint/Breakpoint.cpp +++ b/lldb/source/Breakpoint/Breakpoint.cpp @@ -1127,7 +1127,7 @@ json::Value Breakpoint::GetStatistics() { llvm::raw_string_ostream ss(buffer); json::OStream json_os(ss); bp_data_sp->Serialize(json_os); - if (auto expected_value = llvm::json::parse(ss.str())) { + if (auto expected_value = llvm::json::parse(buffer)) { bp.try_emplace("details", std::move(*expected_value)); } else { std::string details_error = toString(expected_value.takeError()); diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index 9eb68ddb73b6e9..5fb2dfaab8de03 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -204,7 +204,7 @@ class CommandObjectLogEnable : public CommandObjectParsed { channel, args.GetArgumentArrayRef(), log_file, m_options.log_options, m_options.buffer_size.GetCurrentValue(), m_options.handler, error_stream); - result.GetErrorStream() << error_stream.str(); + result.GetErrorStream() << error; if (success) result.SetStatus(eReturnStatusSuccessFinishNoResult); @@ -273,7 +273,7 @@ class CommandObjectLogDisable : public CommandObjectParsed { if (Log::DisableLogChannel(channel, args.GetArgumentArrayRef(), error_stream)) result.SetStatus(eReturnStatusSuccessFinishNoResult); - result.GetErrorStream() << error_stream.str(); + result.GetErrorStream() << error; } } }; @@ -313,7 +313,7 @@ class CommandObjectLogList : public CommandObjectParsed { if (success) result.SetStatus(eReturnStatusSuccessFinishResult); } - result.GetOutputStream() << output_stream.str(); + result.GetOutputStream() << output; } }; class CommandObjectLogDump : public CommandObjectParsed { @@ -404,7 +404,7 @@ class CommandObjectLogDump : public CommandObjectParsed { result.SetStatus(eReturnStatusSuccessFinishNoResult); } else { result.SetStatus(eReturnStatusFailed); - result.GetErrorStream() << error_stream.str(); + result.GetErrorStream() << error; } } diff --git a/lldb/source/Commands/CommandObjectRegexCommand.cpp b/lldb/source/Commands/CommandObjectRegexCommand.cpp index f638d707e17e78..7e27915aaaa469 100644 --- a/lldb/source/Commands/CommandObjectRegexCommand.cpp +++ b/lldb/source/Commands/CommandObjectRegexCommand.cpp @@ -51,7 +51,7 @@ llvm::Expected<std::string> CommandObjectRegexCommand::SubstituteVariables( output << part; } - return output.str(); + return buffer; } void CommandObjectRegexCommand::DoExecute(llvm::StringRef command, diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 8595a22175d98d..88cc957e91fac4 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -1626,7 +1626,7 @@ uint32_t Module::Hash() { const auto mtime = llvm::sys::toTimeT(m_object_mod_time); if (mtime > 0) id_strm << mtime; - return llvm::djbHash(id_strm.str()); + return llvm::djbHash(identifier); } std::string Module::GetCacheKey() { @@ -1636,7 +1636,7 @@ std::string Module::GetCacheKey() { if (m_object_name) strm << '(' << m_object_name << ')'; strm << '-' << llvm::format_hex(Hash(), 10); - return strm.str(); + return key; } DataFileCache *Module::GetIndexCache() { diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index d2f2ee26fd4307..15ca2ddbbae046 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -261,8 +261,6 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr, m_module->print(oss, nullptr); - oss.flush(); - LLDB_LOGF(log, "Module being sent to JIT: \n%s", s.c_str()); } diff --git a/lldb/source/Expression/IRInterpreter.cpp b/lldb/source/Expression/IRInterpreter.cpp index 593258f4407d58..4909310db7a6df 100644 --- a/lldb/source/Expression/IRInterpreter.cpp +++ b/lldb/source/Expression/IRInterpreter.cpp @@ -49,7 +49,6 @@ static std::string PrintValue(const Value *value, bool truncate = false) { std::string s; raw_string_ostream rso(s); value->print(rso); - rso.flush(); if (truncate) s.resize(s.length() - 1); @@ -66,7 +65,6 @@ static std::string PrintType(const Type *type, bool truncate = false) { std::string s; raw_string_ostream rso(s); type->print(rso); - rso.flush(); if (truncate) s.resize(s.length() - 1); return s; @@ -698,8 +696,6 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, module.print(oss, nullptr); - oss.flush(); - LLDB_LOGF(log, "Module as passed in to IRInterpreter::Interpret: \n\"%s\"", s.c_str()); } diff --git a/lldb/source/Host/windows/PipeWindows.cpp b/lldb/source/Host/windows/PipeWindows.cpp index d79dc3c2f82c90..21e30f0ae87384 100644 --- a/lldb/source/Host/windows/PipeWindows.cpp +++ b/lldb/source/Host/windows/PipeWindows.cpp @@ -74,7 +74,6 @@ Status PipeWindows::CreateNew(bool child_process_inherit) { std::string pipe_name; llvm::raw_string_ostream pipe_name_stream(pipe_name); pipe_name_stream << "lldb.pipe." << ::GetCurrentProcessId() << "." << serial; - pipe_name_stream.flush(); return CreateNew(pipe_name.c_str(), child_process_inherit); } diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index 27eda289109ebe..b8a3f68a49b1cf 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -923,7 +923,7 @@ static std::string BuildShortOptions(const Option *long_options) { } } } - return std::move(sstr.str()); + return storage; } llvm::Expected<Args> Options::ParseAlias(const Args &args, diff --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp index 1628107170e7b1..31edd8d46c444e 100644 --- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp +++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp @@ -1366,8 +1366,6 @@ void DisassemblerLLVMC::MCDisasmInstance::PrintMCInst( *m_subtarget_info_up, inst_stream); m_instr_printer_up->setCommentStream(llvm::nulls()); - comments_stream.flush(); - static std::string g_newlines("\r\n"); for (size_t newline_pos = 0; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index 90f26de939a478..2fe3c0460aa7f8 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -984,7 +984,6 @@ class CodeComplete : public CodeCompleteConsumer { ToInsert += "("; raw_string_ostream OS(Description); F->print(OS, m_desc_policy, false); - OS.flush(); } else if (const VarDecl *V = dyn_cast<VarDecl>(D)) { Description = V->getType().getAsString(m_desc_policy); } else if (const FieldDecl *F = dyn_cast<FieldDecl>(D)) { @@ -1358,7 +1357,6 @@ bool ClangExpressionParser::RewriteExpression( llvm::raw_string_ostream out_stream(fixed_expression); main_file_buffer.write(out_stream); - out_stream.flush(); diagnostic_manager.SetFixedExpression(fixed_expression); return true; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp index 024fc75a5dd590..a43701cba35374 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp @@ -147,7 +147,6 @@ void StoringDiagnosticConsumer::HandleDiagnostic( // Print the diagnostic to m_output. m_output.clear(); m_diag_printer->HandleDiagnostic(DiagLevel, info); - m_os->flush(); // Store the diagnostic for later. m_diagnostics.push_back(IDAndDiagnostic(DiagLevel, m_output)); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp index defd72bbd93106..45bdc7272936ca 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp @@ -94,7 +94,6 @@ static std::string PrintValue(llvm::Value *V, bool truncate = false) { std::string s; raw_string_ostream rso(s); V->print(rso); - rso.flush(); if (truncate) s.resize(s.length() - 1); return s; @@ -553,8 +552,6 @@ bool IRDynamicChecks::runOnModule(llvm::Module &M) { M.print(oss, nullptr); - oss.flush(); - LLDB_LOGF(log, "Module after dynamic checks: \n%s", s.c_str()); } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp index 34461da46dfc7b..3764668fb27e82 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp @@ -86,7 +86,6 @@ static std::string PrintValue(const Value *value, bool truncate = false) { if (value) { raw_string_ostream rso(s); value->print(rso); - rso.flush(); if (truncate) s.resize(s.length() - 1); } @@ -97,7 +96,6 @@ static std::string PrintType(const llvm::Type *type, bool truncate = false) { std::string s; raw_string_ostream rso(s); type->print(rso); - rso.flush(); if (truncate) s.resize(s.length() - 1); return s; @@ -244,7 +242,6 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) { std::string decl_desc_str; raw_string_ostream decl_desc_stream(decl_desc_str); result_decl->print(decl_desc_stream); - decl_desc_stream.flush(); LLDB_LOG(log, "Found result decl: \"{0}\"", decl_desc_str); } @@ -1616,8 +1613,6 @@ bool IRForTarget::runOnModule(Module &llvm_module) { m_module->print(oss, nullptr); - oss.flush(); - LLDB_LOG(log, "Module as passed in to IRForTarget: \n\"{0}\"", s); } @@ -1663,8 +1658,6 @@ bool IRForTarget::runOnModule(Module &llvm_module) { m_module->print(oss, nullptr); - oss.flush(); - LLDB_LOG(log, "Module after creating the result variable: \n\"{0}\"", s); } @@ -1762,8 +1755,6 @@ bool IRForTarget::runOnModule(Module &llvm_module) { m_module->print(oss, nullptr); - oss.flush(); - LLDB_LOG(log, "Module after preparing for execution: \n\"{0}\"", s); } diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index 0f153878423be7..41492ca836fac8 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -2685,7 +2685,7 @@ void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() { } os << ". This will likely reduce debugging performance.\n"; - Debugger::ReportWarning(os.str(), debugger.GetID(), + Debugger::ReportWarning(buffer, debugger.GetID(), &m_no_expanded_cache_warning); } diff --git a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp index 24c9aa6b32659d..9c330ff1186709 100644 --- a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp +++ b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp @@ -548,7 +548,7 @@ NativeProcessWindows::OnDebugException(bool first_chance, << " encountered at address " << llvm::format_hex(record.GetExceptionAddress(), 8); StopThread(record.GetThreadID(), StopReason::eStopReasonException, - desc_stream.str().c_str()); + desc.c_str()); SetState(eStateStopped, true); } diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp index b25068dda53ffe..703aa082f0476f 100644 --- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp +++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp @@ -492,10 +492,10 @@ void ProcessWindows::RefreshStateAfterStop() { << llvm::format_hex(active_exception->GetExceptionAddress(), 8); DumpAdditionalExceptionInformation(desc_stream, active_exception); - stop_info = StopInfo::CreateStopReasonWithException( - *stop_thread, desc_stream.str().c_str()); + stop_info = + StopInfo::CreateStopReasonWithException(*stop_thread, desc.c_str()); stop_thread->SetStopInfo(stop_info); - LLDB_LOG(log, "{0}", desc_stream.str()); + LLDB_LOG(log, "{0}", desc); return; } } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 23baa922227c1d..d005cf1e3d3c26 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -3668,7 +3668,6 @@ GDBRemoteCommunicationClient::SendTraceStop(const TraceStopRequest &request, std::string json_string; llvm::raw_string_ostream os(json_string); os << toJSON(request); - os.flush(); escaped_packet.PutEscapedBytes(json_string.c_str(), json_string.size()); @@ -3738,7 +3737,6 @@ GDBRemoteCommunicationClient::SendTraceGetState(llvm::StringRef type, std::string json_string; llvm::raw_string_ostream os(json_string); os << toJSON(TraceGetStateRequest{type.str()}); - os.flush(); escaped_packet.PutEscapedBytes(json_string.c_str(), json_string.size()); @@ -3772,7 +3770,6 @@ GDBRemoteCommunicationClient::SendTraceGetBinaryData( std::string json_string; llvm::raw_string_ostream os(json_string); os << toJSON(request); - os.flush(); escaped_packet.PutEscapedBytes(json_string.c_str(), json_string.size()); @@ -4045,7 +4042,7 @@ GDBRemoteCommunicationClient::ReadExtFeature(llvm::StringRef object, } } - return output_stream.str(); + return output; } // Notify the target that gdb is prepared to serve symbol lookup requests. diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 271ff61a7188a6..d5dfe79fd8862a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -5360,7 +5360,7 @@ std::string ProcessGDBRemote::HarmonizeThreadIdsForProfileData( output_stream << end_delimiter; m_thread_id_to_used_usec_map = new_thread_id_to_used_usec_map; - return output_stream.str(); + return output; } void ProcessGDBRemote::HandleStopReply() { diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp index 42cc9f02518b32..32ffba763c08e3 100644 --- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp +++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp @@ -289,8 +289,8 @@ void ProcessMinidump::RefreshStateAfterStop() { << " encountered at address " << llvm::format_hex( exception_stream.ExceptionRecord.ExceptionAddress, 8); - stop_info = StopInfo::CreateStopReasonWithException( - *stop_thread, desc_stream.str().c_str()); + stop_info = + StopInfo::CreateStopReasonWithException(*stop_thread, desc.c_str()); } stop_thread->SetStopInfo(stop_info); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index 32d8a92305aafa..373b3d9ed2eaa9 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -501,5 +501,5 @@ void DebugNamesDWARFIndex::Dump(Stream &s) { std::string data; llvm::raw_string_ostream os(data); m_debug_names_up->dump(os); - s.PutCString(os.str()); + s.PutCString(data); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp index d581d3773ab23e..887983de2e8516 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -697,7 +697,7 @@ std::string ManualDWARFIndex::GetCacheKey() { ObjectFile *objfile = m_dwarf->GetObjectFile(); strm << objfile->GetModule()->GetCacheKey() << "-dwarf-index-" << llvm::format_hex(objfile->GetCacheHash(), 10); - return strm.str(); + return key; } bool ManualDWARFIndex::LoadFromCache() { diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp index 1a9f6fe3050908..c00eebc823a8c7 100644 --- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp +++ b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp @@ -72,7 +72,7 @@ Error TraceIntelPTBundleLoader::CreateJSONError(json::Path::Root &root, root.printErrorContext(value, os); return createStringError( std::errc::invalid_argument, "%s\n\nContext:\n%s\n\nSchema:\n%s", - toString(root.getError()).c_str(), os.str().c_str(), GetSchema().data()); + toString(root.getError()).c_str(), err.c_str(), GetSchema().data()); } ThreadPostMortemTraceSP diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp index 5b5bf5c3f6f8c7..3c5075d9bb18ba 100644 --- a/lldb/source/Symbol/Symtab.cpp +++ b/lldb/source/Symbol/Symtab.cpp @@ -1179,7 +1179,7 @@ std::string Symtab::GetCacheKey() { // another object file in a separate symbol file. strm << m_objfile->GetModule()->GetCacheKey() << "-symtab-" << llvm::format_hex(m_objfile->GetCacheHash(), 10); - return strm.str(); + return key; } void Symtab::SaveToCache() { diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp index d619f92122cb9d..ae2f65ea4c4bdc 100644 --- a/lldb/source/Target/Statistics.cpp +++ b/lldb/source/Target/Statistics.cpp @@ -414,7 +414,7 @@ llvm::json::Value DebuggerStats::ReportStatistics( llvm::raw_string_ostream ss(buffer); json::OStream json_os(ss); transcript.Serialize(json_os); - if (auto json_transcript = llvm::json::parse(ss.str())) + if (auto json_transcript = llvm::json::parse(buffer)) global_stats.try_emplace("transcript", std::move(json_transcript.get())); } diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 3e7e7b7d784e90..f1659aae0800db 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -4603,7 +4603,7 @@ void TargetProperties::CheckJITObjectsDir() { std::optional<lldb::user_id_t> debugger_id; if (m_target) debugger_id = m_target->GetDebugger().GetID(); - Debugger::ReportError(os.str(), debugger_id); + Debugger::ReportError(buffer, debugger_id); } bool TargetProperties::GetEnableSyntheticValue() const { diff --git a/lldb/source/Utility/LLDBAssert.cpp b/lldb/source/Utility/LLDBAssert.cpp index 4ecd6043e8ea6f..b0c39a284910b1 100644 --- a/lldb/source/Utility/LLDBAssert.cpp +++ b/lldb/source/Utility/LLDBAssert.cpp @@ -54,7 +54,7 @@ void lldb_assert(bool expression, const char *expr_text, const char *func, llvm::formatv("Assertion failed: ({0}), function {1}, file {2}, line {3}", expr_text, func, file, line) .str(), - backtrace.str(), + buffer, "Please file a bug report against lldb reporting this failure log, and " "as many details as possible"); } diff --git a/lldb/source/Utility/Log.cpp b/lldb/source/Utility/Log.cpp index 6713a5bd758204..f6b1381f63ad1c 100644 --- a/lldb/source/Utility/Log.cpp +++ b/lldb/source/Utility/Log.cpp @@ -374,7 +374,7 @@ void Log::Format(llvm::StringRef file, llvm::StringRef function, llvm::raw_string_ostream message(message_string); WriteHeader(message, file, function); message << payload << "\n"; - WriteMessage(message.str()); + WriteMessage(message_string); } StreamLogHandler::StreamLogHandler(int fd, bool should_close, diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index 6012ee52110b73..fe1ca185778b8e 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -184,12 +184,11 @@ void DAP::SendJSON(const std::string &json_str) { // Serialize the JSON value into a string and send the JSON packet to // the "out" stream. void DAP::SendJSON(const llvm::json::Value &json) { - std::string s; - llvm::raw_string_ostream strm(s); + std::string json_str; + llvm::raw_string_ostream strm(json_str); strm << json; static std::mutex mutex; std::lock_guard<std::mutex> locker(mutex); - std::string json_str = strm.str(); SendJSON(json_str); if (log) { @@ -660,7 +659,6 @@ PacketStatus DAP::GetNextObject(llvm::json::Object &object) { std::string error_str; llvm::raw_string_ostream strm(error_str); strm << error; - strm.flush(); *log << "error: failed to parse JSON: " << error_str << std::endl << json << std::endl; } diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp index 342859adef214f..f175079c6f1fb5 100644 --- a/lldb/tools/lldb-dap/JSONUtils.cpp +++ b/lldb/tools/lldb-dap/JSONUtils.cpp @@ -1480,7 +1480,6 @@ std::string JSONToString(const llvm::json::Value &json) { std::string data; llvm::raw_string_ostream os(data); os << json; - os.flush(); return data; } diff --git a/lldb/tools/lldb-dap/LLDBUtils.cpp b/lldb/tools/lldb-dap/LLDBUtils.cpp index 2da107887604b4..ff6bea1b23eee8 100644 --- a/lldb/tools/lldb-dap/LLDBUtils.cpp +++ b/lldb/tools/lldb-dap/LLDBUtils.cpp @@ -84,7 +84,6 @@ std::string RunLLDBCommands(llvm::StringRef prefix, llvm::raw_string_ostream strm(s); required_command_failed = !RunLLDBCommands(prefix, commands, strm, parse_command_directives); - strm.flush(); return s; } diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index 51765cd28df8a6..c2ebc9a96a9a29 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -635,7 +635,6 @@ void SetSourceMapFromArguments(const llvm::json::Object &arguments) { // Do any source remapping needed before we create our targets strm << "\".\" \"" << sourcePath << "\""; } - strm.flush(); if (!sourceMapCommand.empty()) { g_dap.RunLLDBCommands("Setting source map:", {sourceMapCommand}); } @@ -4127,7 +4126,6 @@ void request_disassemble(const llvm::json::Object &request) { sb << llvm::format("%2.2x ", b); } } - sb.flush(); llvm::json::Object disassembled_inst{ {"address", "0x" + llvm::utohexstr(inst_addr)}, @@ -4158,7 +4156,6 @@ void request_disassemble(const llvm::json::Object &request) { if (c && c[0]) { si << " ; " << c; } - si.flush(); disassembled_inst.try_emplace("instruction", instruction); diff --git a/lldb/tools/lldb-instr/Instrument.cpp b/lldb/tools/lldb-instr/Instrument.cpp index d07ccf121bdf36..ba6f9a75b249fc 100644 --- a/lldb/tools/lldb-instr/Instrument.cpp +++ b/lldb/tools/lldb-instr/Instrument.cpp @@ -59,13 +59,13 @@ class SBVisitor : public RecursiveASTVisitor<SBVisitor> { if (C->getBeginLoc().isMacroID()) { CharSourceRange Range = MyRewriter.getSourceMgr().getExpansionRange(C->getSourceRange()); - MyRewriter.ReplaceText(Range, Macro.str()); + MyRewriter.ReplaceText(Range, Buffer); } else { Macro << ";"; SourceLocation InsertLoc = Lexer::getLocForEndOfToken( Body->getBeginLoc(), 0, MyRewriter.getSourceMgr(), MyRewriter.getLangOpts()); - MyRewriter.InsertTextAfter(InsertLoc, Macro.str()); + MyRewriter.InsertTextAfter(InsertLoc, Buffer); } break; } diff --git a/lldb/tools/lldb-server/LLDBServerUtilities.cpp b/lldb/tools/lldb-server/LLDBServerUtilities.cpp index 5facfbf3105e93..0891f0eb6a9760 100644 --- a/lldb/tools/lldb-server/LLDBServerUtilities.cpp +++ b/lldb/tools/lldb-server/LLDBServerUtilities.cpp @@ -73,7 +73,7 @@ bool LLDBServerUtilities::SetupLogging(const std::string &log_file, channel_then_categories.GetArgumentArrayRef(), error_stream); if (!success) { errs() << formatv("Unable to setup logging for channel \"{0}\": {1}", - channel, error_stream.str()); + channel, error); return false; } } diff --git a/lldb/tools/lldb-test/lldb-test.cpp b/lldb/tools/lldb-test/lldb-test.cpp index 535422a6d827be..ce21e3d4eda058 100644 --- a/lldb/tools/lldb-test/lldb-test.cpp +++ b/lldb/tools/lldb-test/lldb-test.cpp @@ -414,7 +414,7 @@ std::string opts::breakpoint::substitute(StringRef Cmd) { break; } } - return std::move(OS.str()); + return Result; } int opts::breakpoint::evaluateBreakpoints(Debugger &Dbg) { diff --git a/lldb/unittests/Symbol/PostfixExpressionTest.cpp b/lldb/unittests/Symbol/PostfixExpressionTest.cpp index 1f9b2af4ea7a71..d56df476ebaab6 100644 --- a/lldb/unittests/Symbol/PostfixExpressionTest.cpp +++ b/lldb/unittests/Symbol/PostfixExpressionTest.cpp @@ -161,7 +161,7 @@ static std::string ParseAndGenerateDWARF(llvm::StringRef expr) { llvm::raw_string_ostream os(result); llvm::DWARFExpression(extractor, addr_size, llvm::dwarf::DWARF32) .print(os, llvm::DIDumpOptions(), nullptr); - return std::move(os.str()); + return result; } TEST(PostfixExpression, ToDWARF) { diff --git a/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp b/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp index f074927194ec3d..efb8f720b56e18 100644 --- a/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp +++ b/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp @@ -43,7 +43,7 @@ CheckValidProgramTranslation(llvm::StringRef fpo_program, .print(os, llvm::DIDumpOptions(), nullptr); // actual check - ASSERT_EQ(expected_dwarf_expression, os.str()); + ASSERT_EQ(expected_dwarf_expression, result); } TEST(PDBFPOProgramToDWARFExpressionTests, SingleAssignmentRegisterRef) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits