aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawrence D'Anna <lawrence_danna@apple.com>2019-09-27 14:33:35 +0000
committerLawrence D'Anna <lawrence_danna@apple.com>2019-09-27 14:33:35 +0000
commit4c7cb59e629cbeeaa9ecca131cb74932f276d219 (patch)
tree0b134eb6bcd0a05b22e37d8f1afd1c55fda3ed06
parent6bed7b214eefc2e68f70a229ae9af38b7c09ed01 (diff)
downloadlldb-4c7cb59e629cbeeaa9ecca131cb74932f276d219.tar.gz
remove File::SetStream(), make new files instead.
Summary: This patch removes File::SetStream() and File::SetDescriptor(), and replaces most direct uses of File with pointers to File. Instead of calling SetStream() on a file, we make a new file and replace it. My ultimate goal here is to introduce a new API class SBFile, which has full support for python io.IOStream file objects. These can redirect read() and write() to python code, so lldb::Files will need a way to dispatch those methods. Additionally it will need some form of sharing and assigning files, as a SBFile will be passed in and assigned to the main IO streams of the debugger. In my prototype patch queue, I make File itself copyable and add a secondary class FileOps to manage the sharing and dispatch. In that case SBFile was a unique_ptr<File>. (here: https://github.com/smoofra/llvm-project/tree/files) However in review, Pavel Labath suggested that it be shared_ptr instead. (here: https://reviews.llvm.org/D67793) In order for SBFile to use shared_ptr<File>, everything else should as well. If this patch is accepted, I will make SBFile use a shared_ptr I will remove FileOps from future patches and use subclasses of File instead. Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67891 git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@373090 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/lldb/Core/Debugger.h26
-rw-r--r--include/lldb/Core/IOHandler.h15
-rw-r--r--include/lldb/Host/File.h4
-rw-r--r--source/API/SBDebugger.cpp15
-rw-r--r--source/Commands/CommandObjectBreakpointCommand.cpp2
-rw-r--r--source/Commands/CommandObjectCommands.cpp6
-rw-r--r--source/Commands/CommandObjectExpression.cpp6
-rw-r--r--source/Commands/CommandObjectGUI.cpp5
-rw-r--r--source/Commands/CommandObjectTarget.cpp6
-rw-r--r--source/Commands/CommandObjectType.cpp8
-rw-r--r--source/Commands/CommandObjectWatchpointCommand.cpp2
-rw-r--r--source/Core/Debugger.cpp94
-rw-r--r--source/Core/IOHandler.cpp30
-rw-r--r--source/Expression/REPL.cpp16
-rw-r--r--source/Host/common/File.cpp15
-rw-r--r--source/Interpreter/CommandInterpreter.cpp27
-rw-r--r--source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp114
-rw-r--r--source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp6
-rw-r--r--source/Plugins/InstrumentationRuntime/ASan/ASanRuntime.cpp2
-rw-r--r--source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.cpp12
-rw-r--r--source/Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.cpp2
-rw-r--r--source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp2
-rw-r--r--source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp4
-rw-r--r--source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp25
-rw-r--r--source/Target/Platform.cpp7
-rw-r--r--source/Target/Process.cpp6
-rw-r--r--source/Target/Target.cpp6
-rw-r--r--source/Target/ThreadPlanTracer.cpp2
28 files changed, 210 insertions, 255 deletions
diff --git a/include/lldb/Core/Debugger.h b/include/lldb/Core/Debugger.h
index 2b5bf5136..90eefe115 100644
--- a/include/lldb/Core/Debugger.h
+++ b/include/lldb/Core/Debugger.h
@@ -17,6 +17,7 @@
#include "lldb/Core/FormatEntity.h"
#include "lldb/Core/IOHandler.h"
#include "lldb/Core/SourceManager.h"
+#include "lldb/Core/StreamFile.h"
#include "lldb/Core/UserSettingsController.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/Terminal.h"
@@ -113,11 +114,21 @@ public:
void SetAsyncExecution(bool async);
- lldb::StreamFileSP GetInputFile() { return m_input_file_sp; }
+ lldb::FileSP GetInputFileSP() { return m_input_file_sp; }
- lldb::StreamFileSP GetOutputFile() { return m_output_file_sp; }
+ lldb::StreamFileSP GetOutputStreamSP() { return m_output_stream_sp; }
- lldb::StreamFileSP GetErrorFile() { return m_error_file_sp; }
+ lldb::StreamFileSP GetErrorStreamSP() { return m_error_stream_sp; }
+
+ File &GetInputFile() { return *m_input_file_sp; }
+
+ File &GetOutputFile() { return m_output_stream_sp->GetFile(); }
+
+ File &GetErrorFile() { return m_error_stream_sp->GetFile(); }
+
+ StreamFile &GetOutputStream() { return *m_output_stream_sp; }
+
+ StreamFile &GetErrorStream() { return *m_error_stream_sp; }
repro::DataRecorder *GetInputRecorder();
@@ -174,7 +185,7 @@ public:
// If any of the streams are not set, set them to the in/out/err stream of
// the top most input reader to ensure they at least have something
- void AdoptTopIOHandlerFilesIfInvalid(lldb::StreamFileSP &in,
+ void AdoptTopIOHandlerFilesIfInvalid(lldb::FileSP &in,
lldb::StreamFileSP &out,
lldb::StreamFileSP &err);
@@ -356,9 +367,10 @@ protected:
void InstanceInitialize();
- lldb::StreamFileSP m_input_file_sp;
- lldb::StreamFileSP m_output_file_sp;
- lldb::StreamFileSP m_error_file_sp;
+ // these should never be NULL
+ lldb::FileSP m_input_file_sp;
+ lldb::StreamFileSP m_output_stream_sp;
+ lldb::StreamFileSP m_error_stream_sp;
/// Used for shadowing the input file when capturing a reproducer.
repro::DataRecorder *m_input_recorder;
diff --git a/include/lldb/Core/IOHandler.h b/include/lldb/Core/IOHandler.h
index 3a7761583..0c50a2d80 100644
--- a/include/lldb/Core/IOHandler.h
+++ b/include/lldb/Core/IOHandler.h
@@ -58,8 +58,7 @@ public:
IOHandler(Debugger &debugger, IOHandler::Type type);
IOHandler(Debugger &debugger, IOHandler::Type type,
- const lldb::StreamFileSP &input_sp,
- const lldb::StreamFileSP &output_sp,
+ const lldb::FileSP &input_sp, const lldb::StreamFileSP &output_sp,
const lldb::StreamFileSP &error_sp, uint32_t flags,
repro::DataRecorder *data_recorder);
@@ -123,11 +122,11 @@ public:
FILE *GetErrorFILE();
- lldb::StreamFileSP &GetInputStreamFile();
+ lldb::FileSP &GetInputFileSP();
- lldb::StreamFileSP &GetOutputStreamFile();
+ lldb::StreamFileSP &GetOutputStreamFileSP();
- lldb::StreamFileSP &GetErrorStreamFile();
+ lldb::StreamFileSP &GetErrorStreamFileSP();
Debugger &GetDebugger() { return m_debugger; }
@@ -165,7 +164,7 @@ public:
protected:
Debugger &m_debugger;
- lldb::StreamFileSP m_input_sp;
+ lldb::FileSP m_input_sp;
lldb::StreamFileSP m_output_sp;
lldb::StreamFileSP m_error_sp;
repro::DataRecorder *m_data_recorder;
@@ -333,7 +332,7 @@ public:
repro::DataRecorder *data_recorder);
IOHandlerEditline(Debugger &debugger, IOHandler::Type type,
- const lldb::StreamFileSP &input_sp,
+ const lldb::FileSP &input_sp,
const lldb::StreamFileSP &output_sp,
const lldb::StreamFileSP &error_sp, uint32_t flags,
const char *editline_name, // Used for saving history files
@@ -349,7 +348,7 @@ public:
const char *, bool, bool, uint32_t,
IOHandlerDelegate &) = delete;
- IOHandlerEditline(Debugger &, IOHandler::Type, const lldb::StreamFileSP &,
+ IOHandlerEditline(Debugger &, IOHandler::Type, const lldb::FileSP &,
const lldb::StreamFileSP &, const lldb::StreamFileSP &,
uint32_t, const char *, const char *, const char *, bool,
bool, uint32_t, IOHandlerDelegate &) = delete;
diff --git a/include/lldb/Host/File.h b/include/lldb/Host/File.h
index be6c93161..612266f0a 100644
--- a/include/lldb/Host/File.h
+++ b/include/lldb/Host/File.h
@@ -125,12 +125,8 @@ public:
WaitableHandle GetWaitableHandle() override;
- void SetDescriptor(int fd, uint32_t options, bool transfer_ownership);
-
FILE *GetStream();
- void SetStream(FILE *fh, bool transfer_ownership);
-
/// Read bytes from a file from the current file position.
///
/// NOTE: This function is NOT thread safe. Use the read function
diff --git a/source/API/SBDebugger.cpp b/source/API/SBDebugger.cpp
index dcc3e83cc..893ede5e4 100644
--- a/source/API/SBDebugger.cpp
+++ b/source/API/SBDebugger.cpp
@@ -329,9 +329,8 @@ FILE *SBDebugger::GetInputFileHandle() {
LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetInputFileHandle);
if (m_opaque_sp) {
- StreamFileSP stream_file_sp(m_opaque_sp->GetInputFile());
- if (stream_file_sp)
- return LLDB_RECORD_RESULT(stream_file_sp->GetFile().GetStream());
+ File &file_sp = m_opaque_sp->GetInputFile();
+ return LLDB_RECORD_RESULT(file_sp.GetStream());
}
return nullptr;
}
@@ -340,9 +339,8 @@ FILE *SBDebugger::GetOutputFileHandle() {
LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetOutputFileHandle);
if (m_opaque_sp) {
- StreamFileSP stream_file_sp(m_opaque_sp->GetOutputFile());
- if (stream_file_sp)
- return LLDB_RECORD_RESULT(stream_file_sp->GetFile().GetStream());
+ StreamFile &stream_file = m_opaque_sp->GetOutputStream();
+ return LLDB_RECORD_RESULT(stream_file.GetFile().GetStream());
}
return nullptr;
}
@@ -351,9 +349,8 @@ FILE *SBDebugger::GetErrorFileHandle() {
LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetErrorFileHandle);
if (m_opaque_sp) {
- StreamFileSP stream_file_sp(m_opaque_sp->GetErrorFile());
- if (stream_file_sp)
- return LLDB_RECORD_RESULT(stream_file_sp->GetFile().GetStream());
+ StreamFile &stream_file = m_opaque_sp->GetErrorStream();
+ return LLDB_RECORD_RESULT(stream_file.GetFile().GetStream());
}
return nullptr;
}
diff --git a/source/Commands/CommandObjectBreakpointCommand.cpp b/source/Commands/CommandObjectBreakpointCommand.cpp
index 11fdb85e8..a6bcd1d8d 100644
--- a/source/Commands/CommandObjectBreakpointCommand.cpp
+++ b/source/Commands/CommandObjectBreakpointCommand.cpp
@@ -221,7 +221,7 @@ are no syntax errors may indicate that a function was declared but never called.
Options *GetOptions() override { return &m_options; }
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString(g_reader_instructions);
output_sp->Flush();
diff --git a/source/Commands/CommandObjectCommands.cpp b/source/Commands/CommandObjectCommands.cpp
index c20c624ab..259affbe6 100644
--- a/source/Commands/CommandObjectCommands.cpp
+++ b/source/Commands/CommandObjectCommands.cpp
@@ -945,7 +945,7 @@ a number follows 'f':"
protected:
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString("Enter one or more sed substitution commands in "
"the form: 's/<regex>/<subst>/'.\nTerminate the "
@@ -1585,7 +1585,7 @@ protected:
};
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString(g_python_command_instructions);
output_sp->Flush();
@@ -1594,7 +1594,7 @@ protected:
void IOHandlerInputComplete(IOHandler &io_handler,
std::string &data) override {
- StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+ StreamFileSP error_sp = io_handler.GetErrorStreamFileSP();
ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
if (interpreter) {
diff --git a/source/Commands/CommandObjectExpression.cpp b/source/Commands/CommandObjectExpression.cpp
index e8e865609..9bafdc149 100644
--- a/source/Commands/CommandObjectExpression.cpp
+++ b/source/Commands/CommandObjectExpression.cpp
@@ -498,8 +498,8 @@ void CommandObjectExpression::IOHandlerInputComplete(IOHandler &io_handler,
// StreamSP output_stream =
// io_handler.GetDebugger().GetAsyncOutputStream();
// StreamSP error_stream = io_handler.GetDebugger().GetAsyncErrorStream();
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
- StreamFileSP error_sp(io_handler.GetErrorStreamFile());
+ StreamFileSP output_sp = io_handler.GetOutputStreamFileSP();
+ StreamFileSP error_sp = io_handler.GetErrorStreamFileSP();
EvaluateExpression(line.c_str(), output_sp.get(), error_sp.get());
if (output_sp)
@@ -537,7 +537,7 @@ void CommandObjectExpression::GetMultilineExpression() {
1, // Show line numbers starting at 1
*this, nullptr));
- StreamFileSP output_sp(io_handler_sp->GetOutputStreamFile());
+ StreamFileSP output_sp = io_handler_sp->GetOutputStreamFileSP();
if (output_sp) {
output_sp->PutCString(
"Enter expressions, then terminate with an empty line to evaluate:\n");
diff --git a/source/Commands/CommandObjectGUI.cpp b/source/Commands/CommandObjectGUI.cpp
index 21ed510d1..09cb685a4 100644
--- a/source/Commands/CommandObjectGUI.cpp
+++ b/source/Commands/CommandObjectGUI.cpp
@@ -28,9 +28,8 @@ bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) {
if (args.GetArgumentCount() == 0) {
Debugger &debugger = GetDebugger();
- lldb::StreamFileSP input_sp = debugger.GetInputFile();
- if (input_sp && input_sp->GetFile().GetIsRealTerminal() &&
- input_sp->GetFile().GetIsInteractive()) {
+ File &input = debugger.GetInputFile();
+ if (input.GetIsRealTerminal() && input.GetIsInteractive()) {
IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger));
if (io_handler_sp)
debugger.PushIOHandler(io_handler_sp);
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index 37e61ecf0..b813b13ba 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -4555,7 +4555,7 @@ public:
protected:
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString(
"Enter your stop hook command(s). Type 'DONE' to end.\n");
@@ -4567,7 +4567,7 @@ protected:
std::string &line) override {
if (m_stop_hook_sp) {
if (line.empty()) {
- StreamFileSP error_sp(io_handler.GetErrorStreamFile());
+ StreamFileSP error_sp(io_handler.GetErrorStreamFileSP());
if (error_sp) {
error_sp->Printf("error: stop hook #%" PRIu64
" aborted, no commands.\n",
@@ -4579,7 +4579,7 @@ protected:
target->RemoveStopHookByID(m_stop_hook_sp->GetID());
} else {
m_stop_hook_sp->GetCommandPointer()->SplitIntoLines(line);
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp) {
output_sp->Printf("Stop hook #%" PRIu64 " added.\n",
m_stop_hook_sp->GetID());
diff --git a/source/Commands/CommandObjectType.cpp b/source/Commands/CommandObjectType.cpp
index fe4cb57ef..5e31fd5e8 100644
--- a/source/Commands/CommandObjectType.cpp
+++ b/source/Commands/CommandObjectType.cpp
@@ -151,7 +151,7 @@ public:
"for\n"
" internal_dict: an LLDB support object not to be used\"\"\"\n";
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString(g_summary_addreader_instructions);
output_sp->Flush();
@@ -160,7 +160,7 @@ public:
void IOHandlerInputComplete(IOHandler &io_handler,
std::string &data) override {
- StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+ StreamFileSP error_sp = io_handler.GetErrorStreamFileSP();
#ifndef LLDB_DISABLE_PYTHON
ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
@@ -383,7 +383,7 @@ protected:
}
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString(g_synth_addreader_instructions);
output_sp->Flush();
@@ -392,7 +392,7 @@ protected:
void IOHandlerInputComplete(IOHandler &io_handler,
std::string &data) override {
- StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+ StreamFileSP error_sp = io_handler.GetErrorStreamFileSP();
#ifndef LLDB_DISABLE_PYTHON
ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter();
diff --git a/source/Commands/CommandObjectWatchpointCommand.cpp b/source/Commands/CommandObjectWatchpointCommand.cpp
index 4e46abac9..5683381ef 100644
--- a/source/Commands/CommandObjectWatchpointCommand.cpp
+++ b/source/Commands/CommandObjectWatchpointCommand.cpp
@@ -207,7 +207,7 @@ are no syntax errors may indicate that a function was declared but never called.
Options *GetOptions() override { return &m_options; }
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString(
"Enter your debugger command(s). Type 'DONE' to end.\n");
diff --git a/source/Core/Debugger.cpp b/source/Core/Debugger.cpp
index 5938c5cfc..fe2815029 100644
--- a/source/Core/Debugger.cpp
+++ b/source/Core/Debugger.cpp
@@ -297,14 +297,12 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
std::list<Status> errors;
StreamString feedback_stream;
if (!target_sp->LoadScriptingResources(errors, &feedback_stream)) {
- StreamFileSP stream_sp(GetErrorFile());
- if (stream_sp) {
- for (auto error : errors) {
- stream_sp->Printf("%s\n", error.AsCString());
- }
- if (feedback_stream.GetSize())
- stream_sp->PutCString(feedback_stream.GetString());
+ Stream &s = GetErrorStream();
+ for (auto error : errors) {
+ s.Printf("%s\n", error.AsCString());
}
+ if (feedback_stream.GetSize())
+ s.PutCString(feedback_stream.GetString());
}
}
}
@@ -700,9 +698,9 @@ TargetSP Debugger::FindTargetWithProcess(Process *process) {
Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
: UserID(g_unique_id++),
Properties(std::make_shared<OptionValueProperties>()),
- m_input_file_sp(std::make_shared<StreamFile>(stdin, false)),
- m_output_file_sp(std::make_shared<StreamFile>(stdout, false)),
- m_error_file_sp(std::make_shared<StreamFile>(stderr, false)),
+ m_input_file_sp(std::make_shared<File>(stdin, false)),
+ m_output_stream_sp(std::make_shared<StreamFile>(stdout, false)),
+ m_error_stream_sp(std::make_shared<StreamFile>(stderr, false)),
m_input_recorder(nullptr),
m_broadcaster_manager_sp(BroadcasterManager::MakeBroadcasterManager()),
m_terminal_state(), m_target_list(*this), m_platform_list(),
@@ -757,7 +755,7 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
if (term && !strcmp(term, "dumb"))
SetUseColor(false);
// Turn off use-color if we don't write to a terminal with color support.
- if (!m_output_file_sp->GetFile().GetIsTerminalWithColors())
+ if (!GetOutputFile().GetIsTerminalWithColors())
SetUseColor(false);
#if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
@@ -798,8 +796,7 @@ void Debugger::Clear() {
// Close the input file _before_ we close the input read communications
// class as it does NOT own the input file, our m_input_file does.
m_terminal_state.Clear();
- if (m_input_file_sp)
- m_input_file_sp->GetFile().Close();
+ GetInputFile().Close();
m_command_interpreter_up->Clear();
});
@@ -827,14 +824,10 @@ repro::DataRecorder *Debugger::GetInputRecorder() { return m_input_recorder; }
void Debugger::SetInputFileHandle(FILE *fh, bool tranfer_ownership,
repro::DataRecorder *recorder) {
m_input_recorder = recorder;
- if (m_input_file_sp)
- m_input_file_sp->GetFile().SetStream(fh, tranfer_ownership);
- else
- m_input_file_sp = std::make_shared<StreamFile>(fh, tranfer_ownership);
- File &in_file = m_input_file_sp->GetFile();
- if (!in_file.IsValid())
- in_file.SetStream(stdin, true);
+ m_input_file_sp = std::make_shared<File>(fh, tranfer_ownership);
+ if (!m_input_file_sp->IsValid())
+ m_input_file_sp = std::make_shared<File>(stdin, false);
// Save away the terminal state if that is relevant, so that we can restore
// it in RestoreInputState.
@@ -842,34 +835,24 @@ void Debugger::SetInputFileHandle(FILE *fh, bool tranfer_ownership,
}
void Debugger::SetOutputFileHandle(FILE *fh, bool tranfer_ownership) {
- if (m_output_file_sp)
- m_output_file_sp->GetFile().SetStream(fh, tranfer_ownership);
- else
- m_output_file_sp = std::make_shared<StreamFile>(fh, tranfer_ownership);
-
- File &out_file = m_output_file_sp->GetFile();
- if (!out_file.IsValid())
- out_file.SetStream(stdout, false);
+ FileSP file_sp = std::make_shared<File>(fh, tranfer_ownership);
+ if (!file_sp->IsValid())
+ file_sp = std::make_shared<File>(stdout, false);
+ m_output_stream_sp = std::make_shared<StreamFile>(file_sp);
}
void Debugger::SetErrorFileHandle(FILE *fh, bool tranfer_ownership) {
- if (m_error_file_sp)
- m_error_file_sp->GetFile().SetStream(fh, tranfer_ownership);
- else
- m_error_file_sp = std::make_shared<StreamFile>(fh, tranfer_ownership);
-
- File &err_file = m_error_file_sp->GetFile();
- if (!err_file.IsValid())
- err_file.SetStream(stderr, false);
+ FileSP file_sp = std::make_shared<File>(fh, tranfer_ownership);
+ if (!file_sp->IsValid())
+ file_sp = std::make_shared<File>(stderr, false);
+ m_error_stream_sp = std::make_shared<StreamFile>(file_sp);
}
void Debugger::SaveInputTerminalState() {
- if (m_input_file_sp) {
- File &in_file = m_input_file_sp->GetFile();
- if (in_file.GetDescriptor() != File::kInvalidDescriptor)
- m_terminal_state.Save(in_file.GetDescriptor(), true);
- }
+ int fd = GetInputFile().GetDescriptor();
+ if (fd != File::kInvalidDescriptor)
+ m_terminal_state.Save(fd, true);
}
void Debugger::RestoreInputTerminalState() { m_terminal_state.Restore(); }
@@ -950,8 +933,9 @@ bool Debugger::CheckTopIOHandlerTypes(IOHandler::Type top_type,
}
void Debugger::PrintAsync(const char *s, size_t len, bool is_stdout) {
- lldb::StreamFileSP stream = is_stdout ? GetOutputFile() : GetErrorFile();
- m_input_reader_stack.PrintAsync(stream.get(), s, len);
+ lldb_private::StreamFile &stream =
+ is_stdout ? GetOutputStream() : GetErrorStream();
+ m_input_reader_stack.PrintAsync(&stream, s, len);
}
ConstString Debugger::GetTopIOHandlerControlSequence(char ch) {
@@ -988,8 +972,7 @@ void Debugger::RunIOHandler(const IOHandlerSP &reader_sp) {
}
}
-void Debugger::AdoptTopIOHandlerFilesIfInvalid(StreamFileSP &in,
- StreamFileSP &out,
+void Debugger::AdoptTopIOHandlerFilesIfInvalid(FileSP &in, StreamFileSP &out,
StreamFileSP &err) {
// Before an IOHandler runs, it must have in/out/err streams. This function
// is called when one ore more of the streams are nullptr. We use the top
@@ -1001,20 +984,20 @@ void Debugger::AdoptTopIOHandlerFilesIfInvalid(StreamFileSP &in,
// If no STDIN has been set, then set it appropriately
if (!in) {
if (top_reader_sp)
- in = top_reader_sp->GetInputStreamFile();
+ in = top_reader_sp->GetInputFileSP();
else
- in = GetInputFile();
+ in = GetInputFileSP();
// If there is nothing, use stdin
if (!in)
- in = std::make_shared<StreamFile>(stdin, false);
+ in = std::make_shared<File>(stdin, false);
}
// If no STDOUT has been set, then set it appropriately
if (!out) {
if (top_reader_sp)
- out = top_reader_sp->GetOutputStreamFile();
+ out = top_reader_sp->GetOutputStreamFileSP();
else
- out = GetOutputFile();
+ out = GetOutputStreamSP();
// If there is nothing, use stdout
if (!out)
@@ -1023,13 +1006,13 @@ void Debugger::AdoptTopIOHandlerFilesIfInvalid(StreamFileSP &in,
// If no STDERR has been set, then set it appropriately
if (!err) {
if (top_reader_sp)
- err = top_reader_sp->GetErrorStreamFile();
+ err = top_reader_sp->GetErrorStreamFileSP();
else
- err = GetErrorFile();
+ err = GetErrorStreamSP();
// If there is nothing, use stderr
if (!err)
- err = std::make_shared<StreamFile>(stdout, false);
+ err = std::make_shared<StreamFile>(stderr, false);
}
}
@@ -1197,7 +1180,7 @@ bool Debugger::EnableLog(llvm::StringRef channel,
LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
} else if (log_file.empty()) {
log_stream_sp = std::make_shared<llvm::raw_fd_ostream>(
- GetOutputFile()->GetFile().GetDescriptor(), !should_close, unbuffered);
+ GetOutputFile().GetDescriptor(), !should_close, unbuffered);
} else {
auto pos = m_log_streams.find(log_file);
if (pos != m_log_streams.end())
@@ -1592,8 +1575,7 @@ bool Debugger::StartIOHandlerThread() {
void Debugger::StopIOHandlerThread() {
if (m_io_handler_thread.IsJoinable()) {
- if (m_input_file_sp)
- m_input_file_sp->GetFile().Close();
+ GetInputFile().Close();
m_io_handler_thread.Join(nullptr);
}
}
diff --git a/source/Core/IOHandler.cpp b/source/Core/IOHandler.cpp
index f65442828..6f4b1df6a 100644
--- a/source/Core/IOHandler.cpp
+++ b/source/Core/IOHandler.cpp
@@ -73,7 +73,7 @@ using namespace lldb_private;
IOHandler::IOHandler(Debugger &debugger, IOHandler::Type type)
: IOHandler(debugger, type,
- StreamFileSP(), // Adopt STDIN from top input reader
+ FileSP(), // Adopt STDIN from top input reader
StreamFileSP(), // Adopt STDOUT from top input reader
StreamFileSP(), // Adopt STDERR from top input reader
0, // Flags
@@ -81,7 +81,7 @@ IOHandler::IOHandler(Debugger &debugger, IOHandler::Type type)
) {}
IOHandler::IOHandler(Debugger &debugger, IOHandler::Type type,
- const lldb::StreamFileSP &input_sp,
+ const lldb::FileSP &input_sp,
const lldb::StreamFileSP &output_sp,
const lldb::StreamFileSP &error_sp, uint32_t flags,
repro::DataRecorder *data_recorder)
@@ -98,7 +98,7 @@ IOHandler::IOHandler(Debugger &debugger, IOHandler::Type type,
IOHandler::~IOHandler() = default;
int IOHandler::GetInputFD() {
- return (m_input_sp ? m_input_sp->GetFile().GetDescriptor() : -1);
+ return (m_input_sp ? m_input_sp->GetDescriptor() : -1);
}
int IOHandler::GetOutputFD() {
@@ -110,7 +110,7 @@ int IOHandler::GetErrorFD() {
}
FILE *IOHandler::GetInputFILE() {
- return (m_input_sp ? m_input_sp->GetFile().GetStream() : nullptr);
+ return (m_input_sp ? m_input_sp->GetStream() : nullptr);
}
FILE *IOHandler::GetOutputFILE() {
@@ -121,18 +121,18 @@ FILE *IOHandler::GetErrorFILE() {
return (m_error_sp ? m_error_sp->GetFile().GetStream() : nullptr);
}
-StreamFileSP &IOHandler::GetInputStreamFile() { return m_input_sp; }
+FileSP &IOHandler::GetInputFileSP() { return m_input_sp; }
-StreamFileSP &IOHandler::GetOutputStreamFile() { return m_output_sp; }
+StreamFileSP &IOHandler::GetOutputStreamFileSP() { return m_output_sp; }
-StreamFileSP &IOHandler::GetErrorStreamFile() { return m_error_sp; }
+StreamFileSP &IOHandler::GetErrorStreamFileSP() { return m_error_sp; }
bool IOHandler::GetIsInteractive() {
- return GetInputStreamFile()->GetFile().GetIsInteractive();
+ return GetInputFileSP() ? GetInputFileSP()->GetIsInteractive() : false;
}
bool IOHandler::GetIsRealTerminal() {
- return GetInputStreamFile()->GetFile().GetIsRealTerminal();
+ return GetInputFileSP() ? GetInputFileSP()->GetIsRealTerminal() : false;
}
void IOHandler::SetPopped(bool b) { m_popped.SetValue(b, eBroadcastOnChange); }
@@ -235,7 +235,7 @@ IOHandlerEditline::IOHandlerEditline(
bool multi_line, bool color_prompts, uint32_t line_number_start,
IOHandlerDelegate &delegate, repro::DataRecorder *data_recorder)
: IOHandlerEditline(debugger, type,
- StreamFileSP(), // Inherit input from top input reader
+ FileSP(), // Inherit input from top input reader
StreamFileSP(), // Inherit output from top input reader
StreamFileSP(), // Inherit error from top input reader
0, // Flags
@@ -244,9 +244,9 @@ IOHandlerEditline::IOHandlerEditline(
line_number_start, delegate, data_recorder) {}
IOHandlerEditline::IOHandlerEditline(
- Debugger &debugger, IOHandler::Type type,
- const lldb::StreamFileSP &input_sp, const lldb::StreamFileSP &output_sp,
- const lldb::StreamFileSP &error_sp, uint32_t flags,
+ Debugger &debugger, IOHandler::Type type, const lldb::FileSP &input_sp,
+ const lldb::StreamFileSP &output_sp, const lldb::StreamFileSP &error_sp,
+ uint32_t flags,
const char *editline_name, // Used for saving history files
llvm::StringRef prompt, llvm::StringRef continuation_prompt,
bool multi_line, bool color_prompts, uint32_t line_number_start,
@@ -266,7 +266,7 @@ IOHandlerEditline::IOHandlerEditline(
#ifndef LLDB_DISABLE_LIBEDIT
bool use_editline = false;
- use_editline = m_input_sp->GetFile().GetIsRealTerminal();
+ use_editline = m_input_sp && m_input_sp->GetIsRealTerminal();
if (use_editline) {
m_editline_up.reset(new Editline(editline_name, GetInputFILE(),
@@ -596,7 +596,7 @@ void IOHandlerEditline::PrintAsync(Stream *stream, const char *s, size_t len) {
IOHandler::PrintAsync(stream, s, len);
#ifdef _WIN32
if (prompt)
- IOHandler::PrintAsync(GetOutputStreamFile().get(), prompt,
+ IOHandler::PrintAsync(GetOutputStreamFileSP().get(), prompt,
strlen(prompt));
#endif
}
diff --git a/source/Expression/REPL.cpp b/source/Expression/REPL.cpp
index cfa520981..78e468810 100644
--- a/source/Expression/REPL.cpp
+++ b/source/Expression/REPL.cpp
@@ -96,7 +96,7 @@ void REPL::IOHandlerActivated(IOHandler &io_handler, bool interactive) {
lldb::ProcessSP process_sp = m_target.GetProcessSP();
if (process_sp && process_sp->IsAlive())
return;
- lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFile());
+ lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFileSP());
error_sp->Printf("REPL requires a running target process.\n");
io_handler.SetIsDone(true);
}
@@ -180,8 +180,8 @@ int REPL::IOHandlerFixIndentation(IOHandler &io_handler,
}
void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
- lldb::StreamFileSP output_sp(io_handler.GetOutputStreamFile());
- lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFile());
+ lldb::StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
+ lldb::StreamFileSP error_sp(io_handler.GetErrorStreamFileSP());
bool extra_line = false;
bool did_quit = false;
@@ -398,11 +398,11 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
// Update our code on disk
if (!m_repl_source_path.empty()) {
- auto file = FileSystem::Instance().Open(FileSpec(m_repl_source_path),
- File::eOpenOptionWrite |
- File::eOpenOptionTruncate |
- File::eOpenOptionCanCreate,
- lldb::eFilePermissionsFileDefault);
+ auto file = FileSystem::Instance().Open(
+ FileSpec(m_repl_source_path),
+ File::eOpenOptionWrite | File::eOpenOptionTruncate |
+ File::eOpenOptionCanCreate,
+ lldb::eFilePermissionsFileDefault);
if (file) {
std::string code(m_code.CopyList());
code.append(1, '\n');
diff --git a/source/Host/common/File.cpp b/source/Host/common/File.cpp
index 824f08843..7560f1d27 100644
--- a/source/Host/common/File.cpp
+++ b/source/Host/common/File.cpp
@@ -93,14 +93,6 @@ int File::GetDescriptor() const {
IOObject::WaitableHandle File::GetWaitableHandle() { return GetDescriptor(); }
-void File::SetDescriptor(int fd, uint32_t options, bool transfer_ownership) {
- if (IsValid())
- Close();
- m_descriptor = fd;
- m_should_close_fd = transfer_ownership;
- m_options = options;
-}
-
FILE *File::GetStream() {
if (!StreamIsValid()) {
if (DescriptorIsValid()) {
@@ -133,13 +125,6 @@ FILE *File::GetStream() {
return m_stream;
}
-void File::SetStream(FILE *fh, bool transfer_ownership) {
- if (IsValid())
- Close();
- m_stream = fh;
- m_own_stream = transfer_ownership;
-}
-
uint32_t File::GetPermissions(Status &error) const {
int fd = GetDescriptor();
if (fd != kInvalidDescriptor) {
diff --git a/source/Interpreter/CommandInterpreter.cpp b/source/Interpreter/CommandInterpreter.cpp
index 6c97391a6..0c059096c 100644
--- a/source/Interpreter/CommandInterpreter.cpp
+++ b/source/Interpreter/CommandInterpreter.cpp
@@ -2339,16 +2339,17 @@ void CommandInterpreter::HandleCommandsFromFile(
}
std::string cmd_file_path = cmd_file.GetPath();
-
- auto file = FileSystem::Instance().Open(cmd_file, File::eOpenOptionRead);
- if (!file) {
+ auto input_file_up =
+ FileSystem::Instance().Open(cmd_file, File::eOpenOptionRead);
+ if (!input_file_up) {
+ std::string error = llvm::toString(input_file_up.takeError());
result.AppendErrorWithFormatv(
"error: an error occurred read file '{0}': {1}\n", cmd_file_path,
- llvm::fmt_consume(file.takeError()));
+ llvm::fmt_consume(input_file_up.takeError()));
result.SetStatus(eReturnStatusFailed);
return;
}
- auto input_file_sp = std::make_shared<StreamFile>(std::move(file.get()));
+ FileSP input_file_sp = FileSP(std::move(input_file_up.get()));
Debugger &debugger = GetDebugger();
@@ -2434,8 +2435,8 @@ void CommandInterpreter::HandleCommandsFromFile(
}
if (flags & eHandleCommandFlagPrintResult) {
- debugger.GetOutputFile()->Printf("Executing commands in '%s'.\n",
- cmd_file_path.c_str());
+ debugger.GetOutputFile().Printf("Executing commands in '%s'.\n",
+ cmd_file_path.c_str());
}
// Used for inheriting the right settings when "command source" might
@@ -2735,8 +2736,8 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler,
// from a file) we need to echo the command out so we don't just see the
// command output and no command...
if (EchoCommandNonInteractive(line, io_handler.GetFlags()))
- io_handler.GetOutputStreamFile()->Printf("%s%s\n", io_handler.GetPrompt(),
- line.c_str());
+ io_handler.GetOutputStreamFileSP()->Printf(
+ "%s%s\n", io_handler.GetPrompt(), line.c_str());
}
StartHandlingCommand();
@@ -2753,13 +2754,13 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler,
if (!result.GetImmediateOutputStream()) {
llvm::StringRef output = result.GetOutputData();
- PrintCommandOutput(*io_handler.GetOutputStreamFile(), output);
+ PrintCommandOutput(*io_handler.GetOutputStreamFileSP(), output);
}
// Now emit the command error text from the command we just executed
if (!result.GetImmediateErrorStream()) {
llvm::StringRef error = result.GetErrorData();
- PrintCommandOutput(*io_handler.GetErrorStreamFile(), error);
+ PrintCommandOutput(*io_handler.GetErrorStreamFileSP(), error);
}
}
@@ -2909,8 +2910,8 @@ CommandInterpreter::GetIOHandler(bool force_create,
m_command_io_handler_sp = std::make_shared<IOHandlerEditline>(
m_debugger, IOHandler::Type::CommandInterpreter,
- m_debugger.GetInputFile(), m_debugger.GetOutputFile(),
- m_debugger.GetErrorFile(), flags, "lldb", m_debugger.GetPrompt(),
+ m_debugger.GetInputFileSP(), m_debugger.GetOutputStreamSP(),
+ m_debugger.GetErrorStreamSP(), flags, "lldb", m_debugger.GetPrompt(),
llvm::StringRef(), // Continuation prompt
false, // Don't enable multiple line input, just single line commands
m_debugger.GetUseColor(),
diff --git a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 790e78665..0c212735b 100644
--- a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -773,12 +773,9 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
}
if (IsKernel() && m_uuid.IsValid()) {
- Stream *s = target.GetDebugger().GetOutputFile().get();
- if (s) {
- s->Printf("Kernel UUID: %s\n",
- m_uuid.GetAsString().c_str());
- s->Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
- }
+ Stream &s = target.GetDebugger().GetOutputStream();
+ s.Printf("Kernel UUID: %s\n", m_uuid.GetAsString().c_str());
+ s.Printf("Load Address: 0x%" PRIx64 "\n", m_load_address);
}
if (!m_module_sp) {
@@ -839,11 +836,9 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
}
if (IsKernel() && !m_module_sp) {
- Stream *s = target.GetDebugger().GetOutputFile().get();
- if (s) {
- s->Printf("WARNING: Unable to locate kernel binary on the debugger "
- "system.\n");
- }
+ Stream &s = target.GetDebugger().GetOutputStream();
+ s.Printf("WARNING: Unable to locate kernel binary on the debugger "
+ "system.\n");
}
}
@@ -932,25 +927,24 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
bool is_loaded = IsLoaded();
if (is_loaded && m_module_sp && IsKernel()) {
- Stream *s = target.GetDebugger().GetOutputFile().get();
- if (s) {
- ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
- if (kernel_object_file) {
- addr_t file_address =
- kernel_object_file->GetBaseAddress().GetFileAddress();
- if (m_load_address != LLDB_INVALID_ADDRESS &&
- file_address != LLDB_INVALID_ADDRESS) {
- s->Printf("Kernel slid 0x%" PRIx64 " in memory.\n",
- m_load_address - file_address);
- }
+ Stream &s = target.GetDebugger().GetOutputStream();
+ ObjectFile *kernel_object_file = m_module_sp->GetObjectFile();
+ if (kernel_object_file) {
+ addr_t file_address =
+ kernel_object_file->GetBaseAddress().GetFileAddress();
+ if (m_load_address != LLDB_INVALID_ADDRESS &&
+ file_address != LLDB_INVALID_ADDRESS) {
+ s.Printf("Kernel slid 0x%" PRIx64 " in memory.\n",
+ m_load_address - file_address);
}
- {
- s->Printf("Loaded kernel file %s\n",
- m_module_sp->GetFileSpec().GetPath().c_str());
- }
- s->Flush();
}
+ {
+ s.Printf("Loaded kernel file %s\n",
+ m_module_sp->GetFileSpec().GetPath().c_str());
+ }
+ s.Flush();
}
+
return is_loaded;
}
@@ -1109,11 +1103,10 @@ bool DynamicLoaderDarwinKernel::ReadKextSummaryHeader() {
lldb::offset_t offset = 0;
m_kext_summary_header.version = data.GetU32(&offset);
if (m_kext_summary_header.version > 128) {
- Stream *s =
- m_process->GetTarget().GetDebugger().GetOutputFile().get();
- s->Printf("WARNING: Unable to read kext summary header, got "
- "improbable version number %u\n",
- m_kext_summary_header.version);
+ Stream &s = m_process->GetTarget().GetDebugger().GetOutputStream();
+ s.Printf("WARNING: Unable to read kext summary header, got "
+ "improbable version number %u\n",
+ m_kext_summary_header.version);
// If we get an improbably large version number, we're probably
// getting bad memory.
m_kext_summary_header_addr.Clear();
@@ -1124,11 +1117,11 @@ bool DynamicLoaderDarwinKernel::ReadKextSummaryHeader() {
if (m_kext_summary_header.entry_size > 4096) {
// If we get an improbably large entry_size, we're probably
// getting bad memory.
- Stream *s =
- m_process->GetTarget().GetDebugger().GetOutputFile().get();
- s->Printf("WARNING: Unable to read kext summary header, got "
- "improbable entry_size %u\n",
- m_kext_summary_header.entry_size);
+ Stream &s =
+ m_process->GetTarget().GetDebugger().GetOutputStream();
+ s.Printf("WARNING: Unable to read kext summary header, got "
+ "improbable entry_size %u\n",
+ m_kext_summary_header.entry_size);
m_kext_summary_header_addr.Clear();
return false;
}
@@ -1142,11 +1135,10 @@ bool DynamicLoaderDarwinKernel::ReadKextSummaryHeader() {
if (m_kext_summary_header.entry_count > 10000) {
// If we get an improbably large number of kexts, we're probably
// getting bad memory.
- Stream *s =
- m_process->GetTarget().GetDebugger().GetOutputFile().get();
- s->Printf("WARNING: Unable to read kext summary header, got "
- "improbable number of kexts %u\n",
- m_kext_summary_header.entry_count);
+ Stream &s = m_process->GetTarget().GetDebugger().GetOutputStream();
+ s.Printf("WARNING: Unable to read kext summary header, got "
+ "improbable number of kexts %u\n",
+ m_kext_summary_header.entry_count);
m_kext_summary_header_addr.Clear();
return false;
}
@@ -1247,18 +1239,17 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries(
number_of_old_kexts_being_removed == 0)
return true;
- Stream *s = m_process->GetTarget().GetDebugger().GetOutputFile().get();
- if (s && load_kexts) {
+ Stream &s = m_process->GetTarget().GetDebugger().GetOutputStream();
+ if (load_kexts) {
if (number_of_new_kexts_being_added > 0 &&
number_of_old_kexts_being_removed > 0) {
- s->Printf("Loading %d kext modules and unloading %d kext modules ",
- number_of_new_kexts_being_added,
- number_of_old_kexts_being_removed);
+ s.Printf("Loading %d kext modules and unloading %d kext modules ",
+ number_of_new_kexts_being_added,
+ number_of_old_kexts_being_removed);
} else if (number_of_new_kexts_being_added > 0) {
- s->Printf("Loading %d kext modules ", number_of_new_kexts_being_added);
+ s.Printf("Loading %d kext modules ", number_of_new_kexts_being_added);
} else if (number_of_old_kexts_being_removed > 0) {
- s->Printf("Unloading %d kext modules ",
- number_of_old_kexts_being_removed);
+ s.Printf("Unloading %d kext modules ", number_of_old_kexts_being_removed);
}
}
@@ -1304,11 +1295,11 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries(
m_process->GetStopID() == image_info.GetProcessStopId())
loaded_module_list.AppendIfNeeded(image_info.GetModule());
- if (s && load_kexts) {
+ if (load_kexts) {
if (kext_successfully_added)
- s->Printf(".");
+ s.Printf(".");
else
- s->Printf("-");
+ s.Printf("-");
}
if (log)
@@ -1330,8 +1321,7 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries(
if (image_info.GetModule()) {
unloaded_module_list.AppendIfNeeded(image_info.GetModule());
}
- if (s)
- s->Printf(".");
+ s.Printf(".");
image_info.Clear();
// should pull it out of the KextImageInfos vector but that would
// mutate the list and invalidate the to_be_removed bool vector;
@@ -1342,12 +1332,12 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries(
}
}
- if (s && load_kexts) {
- s->Printf(" done.\n");
+ if (load_kexts) {
+ s.Printf(" done.\n");
if (kexts_failed_to_load.size() > 0 && number_of_new_kexts_being_added > 0) {
- s->Printf("Failed to load %d of %d kexts:\n",
- (int)kexts_failed_to_load.size(),
- number_of_new_kexts_being_added);
+ s.Printf("Failed to load %d of %d kexts:\n",
+ (int)kexts_failed_to_load.size(),
+ number_of_new_kexts_being_added);
// print a sorted list of <kext-name, uuid> kexts which failed to load
unsigned longest_name = 0;
std::sort(kexts_failed_to_load.begin(), kexts_failed_to_load.end());
@@ -1359,10 +1349,10 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries(
std::string uuid;
if (ku.second.IsValid())
uuid = ku.second.GetAsString();
- s->Printf (" %-*s %s\n", longest_name, ku.first.c_str(), uuid.c_str());
+ s.Printf(" %-*s %s\n", longest_name, ku.first.c_str(), uuid.c_str());
}
}
- s->Flush();
+ s.Flush();
}
return true;
diff --git a/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 593348fbe..d632805a9 100644
--- a/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -1223,12 +1223,10 @@ lldb_private::Status ClangExpressionParser::PrepareForExecution(
type_system_helper->DeclMap(); // result can be NULL
if (decl_map) {
- Stream *error_stream = nullptr;
Target *target = exe_ctx.GetTargetPtr();
- error_stream = target->GetDebugger().GetErrorFile().get();
-
+ auto &error_stream = target->GetDebugger().GetErrorStream();
IRForTarget ir_for_target(decl_map, m_expr.NeedsVariableResolution(),
- *execution_unit_sp, *error_stream,
+ *execution_unit_sp, error_stream,
function_name.AsCString());
bool ir_can_run =
diff --git a/source/Plugins/InstrumentationRuntime/ASan/ASanRuntime.cpp b/source/Plugins/InstrumentationRuntime/ASan/ASanRuntime.cpp
index c8ac04641..2e5dd5989 100644
--- a/source/Plugins/InstrumentationRuntime/ASan/ASanRuntime.cpp
+++ b/source/Plugins/InstrumentationRuntime/ASan/ASanRuntime.cpp
@@ -264,7 +264,7 @@ bool AddressSanitizerRuntime::NotifyBreakpointHit(
*thread_sp, description, report));
StreamFileSP stream_sp(
- process_sp->GetTarget().GetDebugger().GetOutputFile());
+ process_sp->GetTarget().GetDebugger().GetOutputStreamSP());
if (stream_sp) {
stream_sp->Printf("AddressSanitizer report breakpoint hit. Use 'thread "
"info -s' to get extended information about the "
diff --git a/source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.cpp b/source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.cpp
index 89f2139db..45a3aeeb2 100644
--- a/source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.cpp
+++ b/source/Plugins/InstrumentationRuntime/TSan/TSanRuntime.cpp
@@ -863,13 +863,11 @@ bool ThreadSanitizerRuntime::NotifyBreakpointHit(
CreateStopReasonWithInstrumentationData(
*thread_sp, stop_reason_description, report));
- StreamFileSP stream_sp(
- process_sp->GetTarget().GetDebugger().GetOutputFile());
- if (stream_sp) {
- stream_sp->Printf("ThreadSanitizer report breakpoint hit. Use 'thread "
- "info -s' to get extended information about the "
- "report.\n");
- }
+ StreamFile &s = process_sp->GetTarget().GetDebugger().GetOutputStream();
+ s.Printf("ThreadSanitizer report breakpoint hit. Use 'thread "
+ "info -s' to get extended information about the "
+ "report.\n");
+
return true; // Return true to stop the target
} else
return false; // Let target run
diff --git a/source/Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.cpp b/source/Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.cpp
index 367098bb4..50f1d48d0 100644
--- a/source/Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.cpp
+++ b/source/Plugins/InstrumentationRuntime/UBSan/UBSanRuntime.cpp
@@ -124,7 +124,7 @@ StructuredData::ObjectSP UndefinedBehaviorSanitizerRuntime::RetrieveReportData(
if (!frame_sp)
return StructuredData::ObjectSP();
- StreamFileSP Stream(target.GetDebugger().GetOutputFile());
+ StreamFileSP Stream = target.GetDebugger().GetOutputStreamSP();
EvaluateExpressionOptions options;
options.SetUnwindOnError(true);
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
index 3be07937e..379ef3dca 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
@@ -704,7 +704,7 @@ AppleObjCTrampolineHandler::AppleObjCTrampolineHandler(
// step through any method dispatches. Warn to that effect and get out of
// here.
if (process_sp->CanJIT()) {
- process_sp->GetTarget().GetDebugger().GetErrorFile()->Printf(
+ process_sp->GetTarget().GetDebugger().GetErrorStream().Printf(
"Could not find implementation lookup function \"%s\""
" step in through ObjC method dispatch will not work.\n",
get_impl_name.AsCString());
diff --git a/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp b/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
index 7b9598379..3517f8319 100644
--- a/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
+++ b/source/Plugins/ScriptInterpreter/None/ScriptInterpreterNone.cpp
@@ -28,13 +28,13 @@ ScriptInterpreterNone::~ScriptInterpreterNone() {}
bool ScriptInterpreterNone::ExecuteOneLine(llvm::StringRef command,
CommandReturnObject *,
const ExecuteScriptOptions &) {
- m_debugger.GetErrorFile()->PutCString(
+ m_debugger.GetErrorStream().PutCString(
"error: there is no embedded script interpreter in this mode.\n");
return false;
}
void ScriptInterpreterNone::ExecuteInterpreterLoop() {
- m_debugger.GetErrorFile()->PutCString(
+ m_debugger.GetErrorStream().PutCString(
"error: there is no embedded script interpreter in this mode.\n");
}
diff --git a/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 1d1306728..4019a572f 100644
--- a/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -536,7 +536,7 @@ def function (frame, bp_loc, internal_dict):
}
if (instructions) {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString(instructions);
output_sp->Flush();
@@ -572,7 +572,7 @@ void ScriptInterpreterPythonImpl::IOHandlerInputComplete(IOHandler &io_handler,
bp_options->SetCallback(
ScriptInterpreterPythonImpl::BreakpointCallbackFunction, baton_sp);
} else if (!batch_mode) {
- StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+ StreamFileSP error_sp = io_handler.GetErrorStreamFileSP();
if (error_sp) {
error_sp->Printf("Warning: No command attached to breakpoint.\n");
error_sp->Flush();
@@ -594,7 +594,7 @@ void ScriptInterpreterPythonImpl::IOHandlerInputComplete(IOHandler &io_handler,
wp_options->SetCallback(
ScriptInterpreterPythonImpl::WatchpointCallbackFunction, baton_sp);
} else if (!batch_mode) {
- StreamFileSP error_sp = io_handler.GetErrorStreamFile();
+ StreamFileSP error_sp = io_handler.GetErrorStreamFileSP();
if (error_sp) {
error_sp->Printf("Warning: No command attached to breakpoint.\n");
error_sp->Flush();
@@ -723,7 +723,7 @@ bool ScriptInterpreterPythonImpl::EnterSession(uint16_t on_entry_flags,
File out_file(out, false);
File err_file(err, false);
- lldb::StreamFileSP in_sp;
+ lldb::FileSP in_sp;
lldb::StreamFileSP out_sp;
lldb::StreamFileSP err_sp;
if (!in_file.IsValid() || !out_file.IsValid() || !err_file.IsValid())
@@ -734,7 +734,7 @@ bool ScriptInterpreterPythonImpl::EnterSession(uint16_t on_entry_flags,
} else {
if (!SetStdHandle(in_file, "stdin", m_saved_stdin, "r")) {
if (in_sp)
- SetStdHandle(in_sp->GetFile(), "stdin", m_saved_stdin, "r");
+ SetStdHandle(*in_sp, "stdin", m_saved_stdin, "r");
}
}
@@ -853,7 +853,7 @@ bool ScriptInterpreterPythonImpl::ExecuteOneLine(
// directly down to Python.
Debugger &debugger = m_debugger;
- StreamFileSP input_file_sp;
+ FileSP input_file_sp;
StreamFileSP output_file_sp;
StreamFileSP error_file_sp;
Communication output_comm(
@@ -861,7 +861,7 @@ bool ScriptInterpreterPythonImpl::ExecuteOneLine(
bool join_read_thread = false;
if (options.GetEnableIO()) {
if (result) {
- input_file_sp = debugger.GetInputFile();
+ input_file_sp = debugger.GetInputFileSP();
// Set output to a temporary file so we can forward the results on to
// the result object
@@ -892,9 +892,8 @@ bool ScriptInterpreterPythonImpl::ExecuteOneLine(
::setbuf(outfile_handle, nullptr);
result->SetImmediateOutputFile(
- debugger.GetOutputFile()->GetFile().GetStream());
- result->SetImmediateErrorFile(
- debugger.GetErrorFile()->GetFile().GetStream());
+ debugger.GetOutputFile().GetStream());
+ result->SetImmediateErrorFile(debugger.GetErrorFile().GetStream());
}
}
}
@@ -918,11 +917,11 @@ bool ScriptInterpreterPythonImpl::ExecuteOneLine(
llvm::fmt_consume(nullout.takeError()));
return false;
}
- input_file_sp = std::make_shared<StreamFile>(std::move(nullin.get()));
+ input_file_sp = std::move(nullin.get());
error_file_sp = output_file_sp = std::make_shared<StreamFile>(std::move(nullout.get()));
}
- FILE *in_file = input_file_sp->GetFile().GetStream();
+ FILE *in_file = input_file_sp->GetStream();
FILE *out_file = output_file_sp->GetFile().GetStream();
FILE *err_file = error_file_sp->GetFile().GetStream();
bool success = false;
@@ -1013,7 +1012,7 @@ void ScriptInterpreterPythonImpl::ExecuteInterpreterLoop() {
// a running interpreter loop inside the already running Python interpreter
// loop, so we won't do it.
- if (!debugger.GetInputFile()->GetFile().IsValid())
+ if (!debugger.GetInputFile().IsValid())
return;
IOHandlerSP io_handler_sp(new IOHandlerPythonInterpreter(debugger, this));
diff --git a/source/Target/Platform.cpp b/source/Target/Platform.cpp
index 482c8b503..00af75438 100644
--- a/source/Target/Platform.cpp
+++ b/source/Target/Platform.cpp
@@ -1226,8 +1226,8 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination,
if (fs::is_symlink_file(source.GetPath()))
source_open_options |= File::eOpenOptionDontFollowSymlinks;
- auto source_file = FileSystem::Instance().Open(
- source, source_open_options, lldb::eFilePermissionsUserRW);
+ auto source_file = FileSystem::Instance().Open(source, source_open_options,
+ lldb::eFilePermissionsUserRW);
if (!source_file)
return Status(source_file.takeError());
Status error;
@@ -1796,8 +1796,7 @@ lldb::ProcessSP Platform::ConnectProcess(llvm::StringRef connect_url,
if (!process_sp)
return nullptr;
- error =
- process_sp->ConnectRemote(debugger.GetOutputFile().get(), connect_url);
+ error = process_sp->ConnectRemote(&debugger.GetOutputStream(), connect_url);
if (error.Fail())
return nullptr;
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index cf0cdc00b..40482e715 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -1649,7 +1649,7 @@ Process::CreateBreakpointSite(const BreakpointLocationSP &owner,
Address symbol_address = symbol->GetAddress();
load_addr = ResolveIndirectFunction(&symbol_address, error);
if (!error.Success() && show_error) {
- GetTarget().GetDebugger().GetErrorFile()->Printf(
+ GetTarget().GetDebugger().GetErrorStream().Printf(
"warning: failed to resolve indirect function at 0x%" PRIx64
" for breakpoint %i.%i: %s\n",
symbol->GetLoadAddress(&GetTarget()),
@@ -1688,7 +1688,7 @@ Process::CreateBreakpointSite(const BreakpointLocationSP &owner,
} else {
if (show_error || use_hardware) {
// Report error for setting breakpoint...
- GetTarget().GetDebugger().GetErrorFile()->Printf(
+ GetTarget().GetDebugger().GetErrorStream().Printf(
"warning: failed to set breakpoint site at 0x%" PRIx64
" for breakpoint %i.%i: %s\n",
load_addr, owner->GetBreakpoint().GetID(), owner->GetID(),
@@ -4300,9 +4300,9 @@ public:
: IOHandler(process->GetTarget().GetDebugger(),
IOHandler::Type::ProcessIO),
m_process(process),
+ m_read_file(GetInputFD(), File::eOpenOptionRead, false),
m_write_file(write_fd, File::eOpenOptionWrite, false) {
m_pipe.CreateNew(false);
- m_read_file.SetDescriptor(GetInputFD(), File::eOpenOptionRead, false);
}
~IOHandlerProcessSTDIO() override = default;
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index c92d63882..90ce85f14 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -1358,15 +1358,15 @@ static void LoadScriptingResourceForModule(const ModuleSP &module_sp,
if (module_sp && !module_sp->LoadScriptingResourceInTarget(
target, error, &feedback_stream)) {
if (error.AsCString())
- target->GetDebugger().GetErrorFile()->Printf(
+ target->GetDebugger().GetErrorStream().Printf(
"unable to load scripting data for module %s - error reported was "
"%s\n",
module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
error.AsCString());
}
if (feedback_stream.GetSize())
- target->GetDebugger().GetErrorFile()->Printf("%s\n",
- feedback_stream.GetData());
+ target->GetDebugger().GetErrorStream().Printf("%s\n",
+ feedback_stream.GetData());
}
void Target::ClearModules(bool delete_locations) {
diff --git a/source/Target/ThreadPlanTracer.cpp b/source/Target/ThreadPlanTracer.cpp
index ed4e17840..5782fe8e6 100644
--- a/source/Target/ThreadPlanTracer.cpp
+++ b/source/Target/ThreadPlanTracer.cpp
@@ -46,7 +46,7 @@ Stream *ThreadPlanTracer::GetLogStream() {
else {
TargetSP target_sp(m_thread.CalculateTarget());
if (target_sp)
- return target_sp->GetDebugger().GetOutputFile().get();
+ return &(target_sp->GetDebugger().GetOutputStream());
}
return nullptr;
}