-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Store StreamAsynchronousIO in a unique_ptr (NFC) #127961
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
Conversation
Make StreamAsynchronousIO an unique_ptr instead of a shared_ptr. I tried passing the class by value, but the llvm::raw_ostream forwarded stored in the Stream parent class isn't movable and I don't think it's worth changing that. Additionally, there's a few places that expect a StreamSP, which are easily created from a StreamUP.
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesMake StreamAsynchronousIO an unique_ptr instead of a shared_ptr. I tried passing the class by value, but the llvm::raw_ostream forwarder stored in the Stream parent class isn't movable and I don't think it's worth changing that. Additionally, there's a few places that expect a StreamSP, which are easily created from a StreamUP. Patch is 20.81 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/127961.diff 14 Files Affected:
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index 9c8a9623fe689..6ebc6147800e1 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -156,9 +156,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
void RestoreInputTerminalState();
- lldb::StreamSP GetAsyncOutputStream();
+ lldb::StreamUP GetAsyncOutputStream();
- lldb::StreamSP GetAsyncErrorStream();
+ lldb::StreamUP GetAsyncErrorStream();
CommandInterpreter &GetCommandInterpreter() {
assert(m_command_interpreter_up.get());
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index cda55ef06e549..c664d1398f74d 100644
--- a/lldb/include/lldb/lldb-forward.h
+++ b/lldb/include/lldb/lldb-forward.h
@@ -432,6 +432,7 @@ typedef std::unique_ptr<lldb_private::StackFrameRecognizerManager>
StackFrameRecognizerManagerUP;
typedef std::shared_ptr<lldb_private::StopInfo> StopInfoSP;
typedef std::shared_ptr<lldb_private::Stream> StreamSP;
+typedef std::unique_ptr<lldb_private::Stream> StreamUP;
typedef std::shared_ptr<lldb_private::StreamFile> StreamFileSP;
typedef std::shared_ptr<lldb_private::LockableStreamFile> LockableStreamFileSP;
typedef std::shared_ptr<lldb_private::StringSummaryFormat>
diff --git a/lldb/source/Breakpoint/BreakpointOptions.cpp b/lldb/source/Breakpoint/BreakpointOptions.cpp
index 09abcf5e081d2..242b5b30168c5 100644
--- a/lldb/source/Breakpoint/BreakpointOptions.cpp
+++ b/lldb/source/Breakpoint/BreakpointOptions.cpp
@@ -620,10 +620,8 @@ bool BreakpointOptions::BreakpointOptionsCallbackFunction(
// Rig up the results secondary output stream to the debugger's, so the
// output will come out synchronously if the debugger is set up that way.
- StreamSP output_stream(debugger.GetAsyncOutputStream());
- StreamSP error_stream(debugger.GetAsyncErrorStream());
- result.SetImmediateOutputStream(output_stream);
- result.SetImmediateErrorStream(error_stream);
+ result.SetImmediateOutputStream(debugger.GetAsyncOutputStream());
+ result.SetImmediateErrorStream(debugger.GetAsyncErrorStream());
CommandInterpreterRunOptions options;
options.SetStopOnContinue(true);
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index dd841cb5cb4cc..9510cf4d14467 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -815,10 +815,9 @@ a number follows 'f':"
for (const std::string &line : lines) {
Status error = AppendRegexSubstitution(line, check_only);
if (error.Fail()) {
- if (!GetDebugger().GetCommandInterpreter().GetBatchCommandMode()) {
- StreamSP out_stream = GetDebugger().GetAsyncOutputStream();
- out_stream->Printf("error: %s\n", error.AsCString());
- }
+ if (!GetDebugger().GetCommandInterpreter().GetBatchCommandMode())
+ GetDebugger().GetAsyncOutputStream()->Printf("error: %s\n",
+ error.AsCString());
}
}
}
diff --git a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp
index 507ef3fbe4759..32cb80b421fd6 100644
--- a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp
+++ b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp
@@ -252,10 +252,8 @@ are no syntax errors may indicate that a function was declared but never called.
// Rig up the results secondary output stream to the debugger's, so the
// output will come out synchronously if the debugger is set up that
// way.
- StreamSP output_stream(debugger.GetAsyncOutputStream());
- StreamSP error_stream(debugger.GetAsyncErrorStream());
- result.SetImmediateOutputStream(output_stream);
- result.SetImmediateErrorStream(error_stream);
+ result.SetImmediateOutputStream(debugger.GetAsyncOutputStream());
+ result.SetImmediateErrorStream(debugger.GetAsyncErrorStream());
CommandInterpreterRunOptions options;
options.SetStopOnContinue(true);
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 242ef1c8a4596..585138535203d 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -257,7 +257,7 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
std::list<Status> errors;
StreamString feedback_stream;
if (!target_sp->LoadScriptingResources(errors, feedback_stream)) {
- lldb::StreamSP s = GetAsyncErrorStream();
+ lldb::StreamUP s = GetAsyncErrorStream();
for (auto &error : errors)
s->Printf("%s\n", error.AsCString());
if (feedback_stream.GetSize())
@@ -1328,13 +1328,13 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
return true;
}
-StreamSP Debugger::GetAsyncOutputStream() {
- return std::make_shared<StreamAsynchronousIO>(*this,
+StreamUP Debugger::GetAsyncOutputStream() {
+ return std::make_unique<StreamAsynchronousIO>(*this,
StreamAsynchronousIO::STDOUT);
}
-StreamSP Debugger::GetAsyncErrorStream() {
- return std::make_shared<StreamAsynchronousIO>(*this,
+StreamUP Debugger::GetAsyncErrorStream() {
+ return std::make_unique<StreamAsynchronousIO>(*this,
StreamAsynchronousIO::STDERR);
}
@@ -1577,8 +1577,7 @@ static void PrivateReportDiagnostic(Debugger &debugger, Severity severity,
// diagnostic directly to the debugger's error stream.
DiagnosticEventData event_data(severity, std::move(message),
debugger_specific);
- StreamSP stream = debugger.GetAsyncErrorStream();
- event_data.Dump(stream.get());
+ event_data.Dump(debugger.GetAsyncErrorStream().get());
return;
}
EventSP event_sp = std::make_shared<Event>(
@@ -1774,12 +1773,11 @@ void Debugger::HandleBreakpointEvent(const EventSP &event_sp) {
if (num_new_locations > 0) {
BreakpointSP breakpoint =
Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp);
- StreamSP output_sp(GetAsyncOutputStream());
- if (output_sp) {
- output_sp->Printf("%d location%s added to breakpoint %d\n",
+ if (StreamUP output_up = GetAsyncOutputStream()) {
+ output_up->Printf("%d location%s added to breakpoint %d\n",
num_new_locations, num_new_locations == 1 ? "" : "s",
breakpoint->GetID());
- output_sp->Flush();
+ output_up->Flush();
}
}
}
@@ -1823,8 +1821,8 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
? EventDataStructuredData::GetProcessFromEvent(event_sp.get())
: Process::ProcessEventData::GetProcessFromEvent(event_sp.get());
- StreamSP output_stream_sp = GetAsyncOutputStream();
- StreamSP error_stream_sp = GetAsyncErrorStream();
+ StreamUP output_stream_up = GetAsyncOutputStream();
+ StreamUP error_stream_up = GetAsyncErrorStream();
const bool gui_enabled = IsForwardingEvents();
if (!gui_enabled) {
@@ -1849,7 +1847,7 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
if (got_state_changed && !state_is_stopped) {
// This is a public stop which we are going to announce to the user, so
// we should force the most relevant frame selection here.
- Process::HandleProcessStateChangedEvent(event_sp, output_stream_sp.get(),
+ Process::HandleProcessStateChangedEvent(event_sp, output_stream_up.get(),
SelectMostRelevantFrame,
pop_process_io_handler);
}
@@ -1865,37 +1863,35 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
if (plugin_sp) {
auto structured_data_sp =
EventDataStructuredData::GetObjectFromEvent(event_sp.get());
- if (output_stream_sp) {
- StreamString content_stream;
- Status error =
- plugin_sp->GetDescription(structured_data_sp, content_stream);
- if (error.Success()) {
- if (!content_stream.GetString().empty()) {
- // Add newline.
- content_stream.PutChar('\n');
- content_stream.Flush();
-
- // Print it.
- output_stream_sp->PutCString(content_stream.GetString());
- }
- } else {
- error_stream_sp->Format("Failed to print structured "
- "data with plugin {0}: {1}",
- plugin_sp->GetPluginName(), error);
+ StreamString content_stream;
+ Status error =
+ plugin_sp->GetDescription(structured_data_sp, content_stream);
+ if (error.Success()) {
+ if (!content_stream.GetString().empty()) {
+ // Add newline.
+ content_stream.PutChar('\n');
+ content_stream.Flush();
+
+ // Print it.
+ output_stream_up->PutCString(content_stream.GetString());
}
+ } else {
+ error_stream_up->Format("Failed to print structured "
+ "data with plugin {0}: {1}",
+ plugin_sp->GetPluginName(), error);
}
}
}
// Now display any stopped state changes after any STDIO
if (got_state_changed && state_is_stopped) {
- Process::HandleProcessStateChangedEvent(event_sp, output_stream_sp.get(),
+ Process::HandleProcessStateChangedEvent(event_sp, output_stream_up.get(),
SelectMostRelevantFrame,
pop_process_io_handler);
}
- output_stream_sp->Flush();
- error_stream_sp->Flush();
+ output_stream_up->Flush();
+ error_stream_up->Flush();
if (pop_process_io_handler)
process_sp->PopProcessIOHandler();
@@ -1995,22 +1991,18 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
const char *data = static_cast<const char *>(
EventDataBytes::GetBytesFromEvent(event_sp.get()));
if (data && data[0]) {
- StreamSP error_sp(GetAsyncErrorStream());
- if (error_sp) {
- error_sp->PutCString(data);
- error_sp->Flush();
- }
+ StreamUP error_up = GetAsyncErrorStream();
+ error_up->PutCString(data);
+ error_up->Flush();
}
} else if (event_type & CommandInterpreter::
eBroadcastBitAsynchronousOutputData) {
const char *data = static_cast<const char *>(
EventDataBytes::GetBytesFromEvent(event_sp.get()));
if (data && data[0]) {
- StreamSP output_sp(GetAsyncOutputStream());
- if (output_sp) {
- output_sp->PutCString(data);
- output_sp->Flush();
- }
+ StreamUP output_up = GetAsyncOutputStream();
+ output_up->PutCString(data);
+ output_up->Flush();
}
}
} else if (broadcaster == &m_broadcaster) {
@@ -2125,7 +2117,7 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
if (!file_sp->GetIsInteractive() || !file_sp->GetIsTerminalWithColors())
return;
- StreamSP output = GetAsyncOutputStream();
+ StreamUP output = GetAsyncOutputStream();
// Print over previous line, if any.
output->Printf("\r");
@@ -2175,8 +2167,7 @@ void Debugger::HandleDiagnosticEvent(const lldb::EventSP &event_sp) {
if (!data)
return;
- StreamSP stream = GetAsyncErrorStream();
- data->Dump(stream.get());
+ data->Dump(GetAsyncErrorStream().get());
}
bool Debugger::HasIOHandlerThread() const {
diff --git a/lldb/source/Core/DynamicLoader.cpp b/lldb/source/Core/DynamicLoader.cpp
index 9c6ca1e5f910c..76c71d2a49a48 100644
--- a/lldb/source/Core/DynamicLoader.cpp
+++ b/lldb/source/Core/DynamicLoader.cpp
@@ -328,7 +328,7 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
}
} else {
if (force_symbol_search) {
- lldb::StreamSP s = target.GetDebugger().GetAsyncErrorStream();
+ lldb::StreamUP s = target.GetDebugger().GetAsyncErrorStream();
s->Printf("Unable to find file");
if (!name.empty())
s->Printf(" %s", name.str().c_str());
diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 1d4cda6c046b7..60724f3900ae7 100644
--- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -738,7 +738,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
}
if (IsKernel() && m_uuid.IsValid()) {
- lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
+ lldb::StreamUP s = target.GetDebugger().GetAsyncOutputStream();
s->Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
s->Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
@@ -830,7 +830,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
}
if (IsKernel() && !m_module_sp) {
- lldb::StreamSP s = target.GetDebugger().GetAsyncErrorStream();
+ lldb::StreamUP s = target.GetDebugger().GetAsyncErrorStream();
s->Printf("WARNING: Unable to locate kernel binary on the debugger "
"system.\n");
if (kernel_search_error.Fail() && kernel_search_error.AsCString("") &&
@@ -974,7 +974,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
bool is_loaded = IsLoaded();
if (is_loaded && m_module_sp && IsKernel()) {
- lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
+ lldb::StreamUP s = target.GetDebugger().GetAsyncOutputStream();
ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
if (kernel_object_file) {
addr_t file_address =
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index 3bf0a46de57af..a23ba3ad5c545 100644
--- a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -327,7 +327,7 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
Target &target = process->GetTarget();
if (IsKernel() && m_uuid.IsValid()) {
- lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
+ lldb::StreamUP s = target.GetDebugger().GetAsyncOutputStream();
s->Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
s->Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
}
@@ -355,9 +355,9 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
if (!m_module_sp)
m_module_sp = target.GetOrCreateModule(module_spec, true);
if (IsKernel() && !m_module_sp) {
- lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
- s->Printf("WARNING: Unable to locate kernel binary on the debugger "
- "system.\n");
+ target.GetDebugger().GetAsyncOutputStream()->Printf(
+ "WARNING: Unable to locate kernel binary on the debugger "
+ "system.\n");
}
}
@@ -464,7 +464,7 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
}
if (IsLoaded() && m_module_sp && IsKernel()) {
- lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
+ lldb::StreamUP s = target.GetDebugger().GetAsyncOutputStream();
ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
if (kernel_object_file) {
addr_t file_address =
diff --git a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
index 9b2907c680996..406e1d45dc39a 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
@@ -321,20 +321,10 @@ Status ProcessKDP::DoConnectRemote(llvm::StringRef remote_url) {
SetID(1);
GetThreadList();
SetPrivateState(eStateStopped);
- StreamSP async_strm_sp(target.GetDebugger().GetAsyncOutputStream());
- if (async_strm_sp) {
- const char *cstr;
- if ((cstr = m_comm.GetKernelVersion()) != NULL) {
- async_strm_sp->Printf("Version: %s\n", cstr);
- async_strm_sp->Flush();
- }
- // if ((cstr = m_comm.GetImagePath ()) != NULL)
- // {
- // async_strm_sp->Printf ("Image Path:
- // %s\n", cstr);
- // async_strm_sp->Flush();
- // }
- }
+ const char *cstr;
+ if ((cstr = m_comm.GetKernelVersion()) != NULL)
+ target.GetDebugger().GetAsyncOutputStream()->Printf("Version: %s\n",
+ cstr);
} else {
return Status::FromErrorString("KDP_REATTACH failed");
}
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index f36595145e035..8a8c0f92fbbc2 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -5495,8 +5495,7 @@ class CommandObjectProcessGDBRemoteSpeedTest : public CommandObjectParsed {
if (process) {
StreamSP output_stream_sp = result.GetImmediateOutputStream();
if (!output_stream_sp)
- output_stream_sp =
- StreamSP(m_interpreter.GetDebugger().GetAsyncOutputStream());
+ output_stream_sp = m_interpreter.GetDebugger().GetAsyncOutputStream();
result.SetImmediateOutputStream(output_stream_sp);
const uint32_t num_packets =
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 0041c8f2b2db2..6db582096155f 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -2743,10 +2743,9 @@ Status Process::LaunchPrivate(ProcessLaunchInfo &launch_info, StateType &state,
// Now that we know the process type, update its signal responses from the
// ones stored in the Target:
- if (m_unix_signals_sp) {
- StreamSP warning_strm = GetTarget().GetDebugger().GetAsyncErrorStream();
- GetTarget().UpdateSignalsFromDummy(m_unix_signals_sp, warning_strm);
- }
+ if (m_unix_signals_sp)
+ GetTarget().UpdateSignalsFromDummy(
+ m_unix_signals_sp, GetTarget().GetDebugger().GetAsyncErrorStream());
DynamicLoader *dyld = GetDynamicLoader();
if (dyld)
@@ -3131,10 +3130,9 @@ void Process::CompleteAttach() {
}
// Now that we know the process type, update its signal responses from the
// ones stored in the Target:
- if (m_unix_signals_sp) {
- StreamSP warning_strm = GetTarget().GetDebugger().GetAsyncErrorStream();
- GetTarget().UpdateSignalsFromDummy(m_unix_signals_sp, warning_strm);
- }
+ if (m_unix_signals_sp)
+ GetTarget().UpdateSignalsFromDummy(
+ m_unix_signals_sp, GetTarget().GetDebugger().GetAsyncErrorStream());
// We have completed the attach, now it is time to find the dynamic loader
// plug-in
diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp
index 092d78d87a2b1..1c9ecbfe70c3c 100644
--- a/lldb/source/Target/StopInfo.cpp
+++ b/lldb/source/Target/StopInfo.cpp
@@ -1016,11 +1016,9 @@ class StopInfoWatchpoint : public StopInfo {
wp_sp->CaptureWatchedValue(exe_ctx);
Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
- St...
[truncated]
|
Make StreamAsynchronousIO an unique_ptr instead of a shared_ptr. I tried passing the class by value, but the llvm::raw_ostream forwarder stored in the Stream parent class isn't movable and I don't think it's worth changing that. Additionally, there's a few places that expect a StreamSP, which are easily created from a StreamUP. (cherry picked from commit 78d82d3)
Make StreamAsynchronousIO an unique_ptr instead of a shared_ptr. I tried passing the class by value, but the llvm::raw_ostream forwarder stored in the Stream parent class isn't movable and I don't think it's worth changing that. Additionally, there's a few places that expect a StreamSP, which are easily created from a StreamUP. (cherry picked from commit 78d82d3)
Make StreamAsynchronousIO an unique_ptr instead of a shared_ptr. I tried passing the class by value, but the llvm::raw_ostream forwarder stored in the Stream parent class isn't movable and I don't think it's worth changing that. Additionally, there's a few places that expect a StreamSP, which are easily created from a StreamUP.