Skip to content

Commit 988195d

Browse files
committed
[lldb] Store StreamAsynchronousIO in a unique_ptr (NFC) (llvm#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. (cherry picked from commit 78d82d3)
1 parent c91bc30 commit 988195d

File tree

13 files changed

+71
-99
lines changed

13 files changed

+71
-99
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
156156

157157
void RestoreInputTerminalState();
158158

159-
lldb::StreamSP GetAsyncOutputStream();
159+
lldb::StreamUP GetAsyncOutputStream();
160160

161-
lldb::StreamSP GetAsyncErrorStream();
161+
lldb::StreamUP GetAsyncErrorStream();
162162

163163
CommandInterpreter &GetCommandInterpreter() {
164164
assert(m_command_interpreter_up.get());

lldb/include/lldb/lldb-forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ typedef std::unique_ptr<lldb_private::StackFrameRecognizerManager>
428428
StackFrameRecognizerManagerUP;
429429
typedef std::shared_ptr<lldb_private::StopInfo> StopInfoSP;
430430
typedef std::shared_ptr<lldb_private::Stream> StreamSP;
431+
typedef std::unique_ptr<lldb_private::Stream> StreamUP;
431432
typedef std::shared_ptr<lldb_private::StreamFile> StreamFileSP;
432433
typedef std::shared_ptr<lldb_private::LockableStreamFile> LockableStreamFileSP;
433434
typedef std::shared_ptr<lldb_private::StringSummaryFormat>

lldb/source/Breakpoint/BreakpointOptions.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,8 @@ bool BreakpointOptions::BreakpointOptionsCallbackFunction(
620620

621621
// Rig up the results secondary output stream to the debugger's, so the
622622
// output will come out synchronously if the debugger is set up that way.
623-
StreamSP output_stream(debugger.GetAsyncOutputStream());
624-
StreamSP error_stream(debugger.GetAsyncErrorStream());
625-
result.SetImmediateOutputStream(output_stream);
626-
result.SetImmediateErrorStream(error_stream);
623+
result.SetImmediateOutputStream(debugger.GetAsyncOutputStream());
624+
result.SetImmediateErrorStream(debugger.GetAsyncErrorStream());
627625

628626
CommandInterpreterRunOptions options;
629627
options.SetStopOnContinue(true);

lldb/source/Commands/CommandObjectCommands.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,9 @@ a number follows 'f':"
815815
for (const std::string &line : lines) {
816816
Status error = AppendRegexSubstitution(line, check_only);
817817
if (error.Fail()) {
818-
if (!GetDebugger().GetCommandInterpreter().GetBatchCommandMode()) {
819-
StreamSP out_stream = GetDebugger().GetAsyncOutputStream();
820-
out_stream->Printf("error: %s\n", error.AsCString());
821-
}
818+
if (!GetDebugger().GetCommandInterpreter().GetBatchCommandMode())
819+
GetDebugger().GetAsyncOutputStream()->Printf("error: %s\n",
820+
error.AsCString());
822821
}
823822
}
824823
}

lldb/source/Commands/CommandObjectWatchpointCommand.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,8 @@ are no syntax errors may indicate that a function was declared but never called.
252252
// Rig up the results secondary output stream to the debugger's, so the
253253
// output will come out synchronously if the debugger is set up that
254254
// way.
255-
StreamSP output_stream(debugger.GetAsyncOutputStream());
256-
StreamSP error_stream(debugger.GetAsyncErrorStream());
257-
result.SetImmediateOutputStream(output_stream);
258-
result.SetImmediateErrorStream(error_stream);
255+
result.SetImmediateOutputStream(debugger.GetAsyncOutputStream());
256+
result.SetImmediateErrorStream(debugger.GetAsyncErrorStream());
259257

260258
CommandInterpreterRunOptions options;
261259
options.SetStopOnContinue(true);

lldb/source/Core/Debugger.cpp

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
257257
std::list<Status> errors;
258258
StreamString feedback_stream;
259259
if (!target_sp->LoadScriptingResources(errors, feedback_stream)) {
260-
lldb::StreamSP s = GetAsyncErrorStream();
260+
lldb::StreamUP s = GetAsyncErrorStream();
261261
for (auto &error : errors)
262262
s->Printf("%s\n", error.AsCString());
263263
if (feedback_stream.GetSize())
@@ -1367,13 +1367,13 @@ bool Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp) {
13671367
return true;
13681368
}
13691369

1370-
StreamSP Debugger::GetAsyncOutputStream() {
1371-
return std::make_shared<StreamAsynchronousIO>(*this,
1370+
StreamUP Debugger::GetAsyncOutputStream() {
1371+
return std::make_unique<StreamAsynchronousIO>(*this,
13721372
StreamAsynchronousIO::STDOUT);
13731373
}
13741374

1375-
StreamSP Debugger::GetAsyncErrorStream() {
1376-
return std::make_shared<StreamAsynchronousIO>(*this,
1375+
StreamUP Debugger::GetAsyncErrorStream() {
1376+
return std::make_unique<StreamAsynchronousIO>(*this,
13771377
StreamAsynchronousIO::STDERR);
13781378
}
13791379

@@ -1616,8 +1616,7 @@ static void PrivateReportDiagnostic(Debugger &debugger, Severity severity,
16161616
// diagnostic directly to the debugger's error stream.
16171617
DiagnosticEventData event_data(severity, std::move(message),
16181618
debugger_specific);
1619-
StreamSP stream = debugger.GetAsyncErrorStream();
1620-
event_data.Dump(stream.get());
1619+
event_data.Dump(debugger.GetAsyncErrorStream().get());
16211620
return;
16221621
}
16231622
EventSP event_sp = std::make_shared<Event>(
@@ -1813,12 +1812,11 @@ void Debugger::HandleBreakpointEvent(const EventSP &event_sp) {
18131812
if (num_new_locations > 0) {
18141813
BreakpointSP breakpoint =
18151814
Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event_sp);
1816-
StreamSP output_sp(GetAsyncOutputStream());
1817-
if (output_sp) {
1818-
output_sp->Printf("%d location%s added to breakpoint %d\n",
1815+
if (StreamUP output_up = GetAsyncOutputStream()) {
1816+
output_up->Printf("%d location%s added to breakpoint %d\n",
18191817
num_new_locations, num_new_locations == 1 ? "" : "s",
18201818
breakpoint->GetID());
1821-
output_sp->Flush();
1819+
output_up->Flush();
18221820
}
18231821
}
18241822
}
@@ -1862,8 +1860,8 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
18621860
? EventDataStructuredData::GetProcessFromEvent(event_sp.get())
18631861
: Process::ProcessEventData::GetProcessFromEvent(event_sp.get());
18641862

1865-
StreamSP output_stream_sp = GetAsyncOutputStream();
1866-
StreamSP error_stream_sp = GetAsyncErrorStream();
1863+
StreamUP output_stream_up = GetAsyncOutputStream();
1864+
StreamUP error_stream_up = GetAsyncErrorStream();
18671865
const bool gui_enabled = IsForwardingEvents();
18681866

18691867
if (!gui_enabled) {
@@ -1891,7 +1889,7 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
18911889
if (got_state_changed && !state_is_stopped) {
18921890
// This is a public stop which we are going to announce to the user, so
18931891
// we should force the most relevant frame selection here.
1894-
Process::HandleProcessStateChangedEvent(event_sp, output_stream_sp.get(),
1892+
Process::HandleProcessStateChangedEvent(event_sp, output_stream_up.get(),
18951893
SelectMostRelevantFrame,
18961894
pop_process_io_handler,
18971895
// BEGIN SWIFT
@@ -1911,31 +1909,29 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
19111909
if (plugin_sp) {
19121910
auto structured_data_sp =
19131911
EventDataStructuredData::GetObjectFromEvent(event_sp.get());
1914-
if (output_stream_sp) {
1915-
StreamString content_stream;
1916-
Status error =
1917-
plugin_sp->GetDescription(structured_data_sp, content_stream);
1918-
if (error.Success()) {
1919-
if (!content_stream.GetString().empty()) {
1920-
// Add newline.
1921-
content_stream.PutChar('\n');
1922-
content_stream.Flush();
1923-
1924-
// Print it.
1925-
output_stream_sp->PutCString(content_stream.GetString());
1926-
}
1927-
} else {
1928-
error_stream_sp->Format("Failed to print structured "
1929-
"data with plugin {0}: {1}",
1930-
plugin_sp->GetPluginName(), error);
1912+
StreamString content_stream;
1913+
Status error =
1914+
plugin_sp->GetDescription(structured_data_sp, content_stream);
1915+
if (error.Success()) {
1916+
if (!content_stream.GetString().empty()) {
1917+
// Add newline.
1918+
content_stream.PutChar('\n');
1919+
content_stream.Flush();
1920+
1921+
// Print it.
1922+
output_stream_up->PutCString(content_stream.GetString());
19311923
}
1924+
} else {
1925+
error_stream_up->Format("Failed to print structured "
1926+
"data with plugin {0}: {1}",
1927+
plugin_sp->GetPluginName(), error);
19321928
}
19331929
}
19341930
}
19351931

19361932
// Now display any stopped state changes after any STDIO
19371933
if (got_state_changed && state_is_stopped) {
1938-
Process::HandleProcessStateChangedEvent(event_sp, output_stream_sp.get(),
1934+
Process::HandleProcessStateChangedEvent(event_sp, output_stream_up.get(),
19391935
SelectMostRelevantFrame,
19401936
pop_process_io_handler,
19411937
// BEGIN SWIFT
@@ -1944,8 +1940,8 @@ void Debugger::HandleProcessEvent(const EventSP &event_sp) {
19441940
);
19451941
}
19461942

1947-
output_stream_sp->Flush();
1948-
error_stream_sp->Flush();
1943+
output_stream_up->Flush();
1944+
error_stream_up->Flush();
19491945

19501946
if (pop_process_io_handler)
19511947
// BEGIN SWIFT
@@ -2047,22 +2043,18 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
20472043
const char *data = static_cast<const char *>(
20482044
EventDataBytes::GetBytesFromEvent(event_sp.get()));
20492045
if (data && data[0]) {
2050-
StreamSP error_sp(GetAsyncErrorStream());
2051-
if (error_sp) {
2052-
error_sp->PutCString(data);
2053-
error_sp->Flush();
2054-
}
2046+
StreamUP error_up = GetAsyncErrorStream();
2047+
error_up->PutCString(data);
2048+
error_up->Flush();
20552049
}
20562050
} else if (event_type & CommandInterpreter::
20572051
eBroadcastBitAsynchronousOutputData) {
20582052
const char *data = static_cast<const char *>(
20592053
EventDataBytes::GetBytesFromEvent(event_sp.get()));
20602054
if (data && data[0]) {
2061-
StreamSP output_sp(GetAsyncOutputStream());
2062-
if (output_sp) {
2063-
output_sp->PutCString(data);
2064-
output_sp->Flush();
2065-
}
2055+
StreamUP output_up = GetAsyncOutputStream();
2056+
output_up->PutCString(data);
2057+
output_up->Flush();
20662058
}
20672059
}
20682060
} else if (broadcaster == &m_broadcaster) {
@@ -2177,7 +2169,7 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
21772169
if (!file_sp->GetIsInteractive() || !file_sp->GetIsTerminalWithColors())
21782170
return;
21792171

2180-
StreamSP output = GetAsyncOutputStream();
2172+
StreamUP output = GetAsyncOutputStream();
21812173

21822174
// Print over previous line, if any.
21832175
output->Printf("\r");
@@ -2227,8 +2219,7 @@ void Debugger::HandleDiagnosticEvent(const lldb::EventSP &event_sp) {
22272219
if (!data)
22282220
return;
22292221

2230-
StreamSP stream = GetAsyncErrorStream();
2231-
data->Dump(stream.get());
2222+
data->Dump(GetAsyncErrorStream().get());
22322223
}
22332224

22342225
bool Debugger::HasIOHandlerThread() const {

lldb/source/Core/DynamicLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
320320
}
321321
} else {
322322
if (force_symbol_search) {
323-
lldb::StreamSP s = target.GetDebugger().GetAsyncErrorStream();
323+
lldb::StreamUP s = target.GetDebugger().GetAsyncErrorStream();
324324
s->Printf("Unable to find file");
325325
if (!name.empty())
326326
s->Printf(" %s", name.str().c_str());

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
736736
}
737737

738738
if (IsKernel() && m_uuid.IsValid()) {
739-
lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
739+
lldb::StreamUP s = target.GetDebugger().GetAsyncOutputStream();
740740
s->Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
741741
s->Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
742742

@@ -828,7 +828,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
828828
}
829829

830830
if (IsKernel() && !m_module_sp) {
831-
lldb::StreamSP s = target.GetDebugger().GetAsyncErrorStream();
831+
lldb::StreamUP s = target.GetDebugger().GetAsyncErrorStream();
832832
s->Printf("WARNING: Unable to locate kernel binary on the debugger "
833833
"system.\n");
834834
if (kernel_search_error.Fail() && kernel_search_error.AsCString("") &&
@@ -972,7 +972,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
972972
bool is_loaded = IsLoaded();
973973

974974
if (is_loaded && m_module_sp && IsKernel()) {
975-
lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
975+
lldb::StreamUP s = target.GetDebugger().GetAsyncOutputStream();
976976
ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
977977
if (kernel_object_file) {
978978
addr_t file_address =

lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
327327
Target &target = process->GetTarget();
328328

329329
if (IsKernel() && m_uuid.IsValid()) {
330-
lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
330+
lldb::StreamUP s = target.GetDebugger().GetAsyncOutputStream();
331331
s->Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
332332
s->Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
333333
}
@@ -355,9 +355,9 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
355355
if (!m_module_sp)
356356
m_module_sp = target.GetOrCreateModule(module_spec, true);
357357
if (IsKernel() && !m_module_sp) {
358-
lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
359-
s->Printf("WARNING: Unable to locate kernel binary on the debugger "
360-
"system.\n");
358+
target.GetDebugger().GetAsyncOutputStream()->Printf(
359+
"WARNING: Unable to locate kernel binary on the debugger "
360+
"system.\n");
361361
}
362362
}
363363

@@ -464,7 +464,7 @@ bool DynamicLoaderFreeBSDKernel::KModImageInfo::LoadImageUsingMemoryModule(
464464
}
465465

466466
if (IsLoaded() && m_module_sp && IsKernel()) {
467-
lldb::StreamSP s = target.GetDebugger().GetAsyncOutputStream();
467+
lldb::StreamUP s = target.GetDebugger().GetAsyncOutputStream();
468468
ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
469469
if (kernel_object_file) {
470470
addr_t file_address =

lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -321,20 +321,10 @@ Status ProcessKDP::DoConnectRemote(llvm::StringRef remote_url) {
321321
SetID(1);
322322
GetThreadList();
323323
SetPrivateState(eStateStopped);
324-
StreamSP async_strm_sp(target.GetDebugger().GetAsyncOutputStream());
325-
if (async_strm_sp) {
326-
const char *cstr;
327-
if ((cstr = m_comm.GetKernelVersion()) != NULL) {
328-
async_strm_sp->Printf("Version: %s\n", cstr);
329-
async_strm_sp->Flush();
330-
}
331-
// if ((cstr = m_comm.GetImagePath ()) != NULL)
332-
// {
333-
// async_strm_sp->Printf ("Image Path:
334-
// %s\n", cstr);
335-
// async_strm_sp->Flush();
336-
// }
337-
}
324+
const char *cstr;
325+
if ((cstr = m_comm.GetKernelVersion()) != NULL)
326+
target.GetDebugger().GetAsyncOutputStream()->Printf("Version: %s\n",
327+
cstr);
338328
} else {
339329
return Status::FromErrorString("KDP_REATTACH failed");
340330
}

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5468,8 +5468,7 @@ class CommandObjectProcessGDBRemoteSpeedTest : public CommandObjectParsed {
54685468
if (process) {
54695469
StreamSP output_stream_sp = result.GetImmediateOutputStream();
54705470
if (!output_stream_sp)
5471-
output_stream_sp =
5472-
StreamSP(m_interpreter.GetDebugger().GetAsyncOutputStream());
5471+
output_stream_sp = m_interpreter.GetDebugger().GetAsyncOutputStream();
54735472
result.SetImmediateOutputStream(output_stream_sp);
54745473

54755474
const uint32_t num_packets =

lldb/source/Target/Process.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,10 +2888,9 @@ Status Process::LaunchPrivate(ProcessLaunchInfo &launch_info, StateType &state,
28882888

28892889
// Now that we know the process type, update its signal responses from the
28902890
// ones stored in the Target:
2891-
if (m_unix_signals_sp) {
2892-
StreamSP warning_strm = GetTarget().GetDebugger().GetAsyncErrorStream();
2893-
GetTarget().UpdateSignalsFromDummy(m_unix_signals_sp, warning_strm);
2894-
}
2891+
if (m_unix_signals_sp)
2892+
GetTarget().UpdateSignalsFromDummy(
2893+
m_unix_signals_sp, GetTarget().GetDebugger().GetAsyncErrorStream());
28952894

28962895
DynamicLoader *dyld = GetDynamicLoader();
28972896
if (dyld)
@@ -3276,10 +3275,9 @@ void Process::CompleteAttach() {
32763275
}
32773276
// Now that we know the process type, update its signal responses from the
32783277
// ones stored in the Target:
3279-
if (m_unix_signals_sp) {
3280-
StreamSP warning_strm = GetTarget().GetDebugger().GetAsyncErrorStream();
3281-
GetTarget().UpdateSignalsFromDummy(m_unix_signals_sp, warning_strm);
3282-
}
3278+
if (m_unix_signals_sp)
3279+
GetTarget().UpdateSignalsFromDummy(
3280+
m_unix_signals_sp, GetTarget().GetDebugger().GetAsyncErrorStream());
32833281

32843282
// We have completed the attach, now it is time to find the dynamic loader
32853283
// plug-in

lldb/source/Target/StopInfo.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,11 +1016,9 @@ class StopInfoWatchpoint : public StopInfo {
10161016
wp_sp->CaptureWatchedValue(exe_ctx);
10171017

10181018
Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
1019-
StreamSP output_sp = debugger.GetAsyncOutputStream();
1020-
if (wp_sp->DumpSnapshots(output_sp.get())) {
1021-
output_sp->EOL();
1022-
output_sp->Flush();
1023-
}
1019+
StreamUP output_up = debugger.GetAsyncOutputStream();
1020+
if (wp_sp->DumpSnapshots(output_up.get()))
1021+
output_up->EOL();
10241022
}
10251023

10261024
} else {

0 commit comments

Comments
 (0)