From b07823f3e2da9b1c6f1866bf1725cfff5eea5b48 Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna Date: Wed, 16 Oct 2019 01:58:15 +0000 Subject: update ScriptInterpreterPython to use File, not FILE* Summary: ScriptInterpreterPython needs to save and restore sys.stdout and friends when LLDB runs a python script. It currently does this using FILE*, which is not optimal. If whatever was in sys.stdout can not be represented as a FILE*, then it will not be restored correctly when the script is finished. It also means that if the debugger's own output stream is not representable as a file, ScriptInterpreterPython will not be able to redirect python's output correctly. This patch updates ScriptInterpreterPython to represent files with lldb_private::File, and to represent whatever the user had in sys.stdout as simply a PythonObject. This will make lldb interoperate better with other scripts or programs that need to manipulate sys.stdout. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68962 llvm-svn: 374964 --- lldb/source/Core/Debugger.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'lldb/source/Core') diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 6a3604c098d..18397d00dca 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -973,34 +973,31 @@ void Debugger::AdoptTopIOHandlerFilesIfInvalid(FileSP &in, StreamFileSP &out, std::lock_guard guard(m_input_reader_stack.GetMutex()); IOHandlerSP top_reader_sp(m_input_reader_stack.Top()); // If no STDIN has been set, then set it appropriately - if (!in) { + if (!in || !in->IsValid()) { if (top_reader_sp) in = top_reader_sp->GetInputFileSP(); else in = GetInputFileSP(); - // If there is nothing, use stdin if (!in) in = std::make_shared(stdin, false); } // If no STDOUT has been set, then set it appropriately - if (!out) { + if (!out || !out->GetFile().IsValid()) { if (top_reader_sp) out = top_reader_sp->GetOutputStreamFileSP(); else out = GetOutputStreamSP(); - // If there is nothing, use stdout if (!out) out = std::make_shared(stdout, false); } // If no STDERR has been set, then set it appropriately - if (!err) { + if (!err || !err->GetFile().IsValid()) { if (top_reader_sp) err = top_reader_sp->GetErrorStreamFileSP(); else err = GetErrorStreamSP(); - // If there is nothing, use stderr if (!err) err = std::make_shared(stderr, false); -- cgit v1.2.3