diff options
author | Lawrence D'Anna <lawrence_danna@apple.com> | 2019-09-27 14:33:35 +0000 |
---|---|---|
committer | Lawrence D'Anna <lawrence_danna@apple.com> | 2019-09-27 14:33:35 +0000 |
commit | 7ca15ba73f67f1d3b6652cb19bbf78731e3b128d (patch) | |
tree | 0465ddf922beeeafd09260e5e7b47f55ab0b7e99 /lldb/source/Interpreter/CommandInterpreter.cpp | |
parent | eb4c98ca3d2590bad9f6542afbf3a7824d2b53fa (diff) | |
download | llvm-7ca15ba73f67f1d3b6652cb19bbf78731e3b128d.zip llvm-7ca15ba73f67f1d3b6652cb19bbf78731e3b128d.tar.gz llvm-7ca15ba73f67f1d3b6652cb19bbf78731e3b128d.tar.bz2 |
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
llvm-svn: 373090
Diffstat (limited to 'lldb/source/Interpreter/CommandInterpreter.cpp')
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 6c97391..0c059096 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/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(), |