Skip to content

[lldb] Nits on uses of llvm::raw_string_ostream (NFC) #108745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lldb/include/lldb/Utility/Instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/Breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Commands/CommandObjectLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -404,7 +404,7 @@ class CommandObjectLogDump : public CommandObjectParsed {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
result.SetStatus(eReturnStatusFailed);
result.GetErrorStream() << error_stream.str();
result.GetErrorStream() << error;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectRegexCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ llvm::Expected<std::string> CommandObjectRegexCommand::SubstituteVariables(
output << part;
}

return output.str();
return buffer;
}

void CommandObjectRegexCommand::DoExecute(llvm::StringRef command,
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Core/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
2 changes: 0 additions & 2 deletions lldb/source/Expression/IRExecutionUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Expression/IRInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
1 change: 0 additions & 1 deletion lldb/source/Host/windows/PipeWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

Expand Down
9 changes: 0 additions & 9 deletions lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Symbol/Symtab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Utility/LLDBAssert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Utility/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading