mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 18:56:06 +00:00
[lldb] Store StreamAsynchronousIO in a unique_ptr (NFC) (#127961)
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.
This commit is contained in:
parent
6d84fae60e
commit
78d82d3ae7
@ -156,9 +156,9 @@ public:
|
||||
|
||||
void RestoreInputTerminalState();
|
||||
|
||||
lldb::StreamSP GetAsyncOutputStream();
|
||||
lldb::StreamUP GetAsyncOutputStream();
|
||||
|
||||
lldb::StreamSP GetAsyncErrorStream();
|
||||
lldb::StreamUP GetAsyncErrorStream();
|
||||
|
||||
CommandInterpreter &GetCommandInterpreter() {
|
||||
assert(m_command_interpreter_up.get());
|
||||
|
@ -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>
|
||||
|
@ -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);
|
||||
|
@ -815,10 +815,9 @@ protected:
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
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);
|
||||
// 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 {
|
||||
|
@ -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());
|
||||
|
@ -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 =
|
||||
|
@ -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 =
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -5495,8 +5495,7 @@ public:
|
||||
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 =
|
||||
|
@ -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
|
||||
|
@ -1016,11 +1016,9 @@ protected:
|
||||
wp_sp->CaptureWatchedValue(exe_ctx);
|
||||
|
||||
Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
|
||||
StreamSP output_sp = debugger.GetAsyncOutputStream();
|
||||
if (wp_sp->DumpSnapshots(output_sp.get())) {
|
||||
output_sp->EOL();
|
||||
output_sp->Flush();
|
||||
}
|
||||
StreamUP output_up = debugger.GetAsyncOutputStream();
|
||||
if (wp_sp->DumpSnapshots(output_up.get()))
|
||||
output_up->EOL();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user