[Lldb-commits] [lldb] 8422836 - [lldb/ScriptInterpreter] Let the IORedirect factory handle IO being disabled.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 25 09:55:53 PDT 2020


Author: Jonas Devlieghere
Date: 2020-06-25T09:55:46-07:00
New Revision: 842283652eb89e7c207ecfdac5e546472332f02b

URL: https://github.com/llvm/llvm-project/commit/842283652eb89e7c207ecfdac5e546472332f02b
DIFF: https://github.com/llvm/llvm-project/commit/842283652eb89e7c207ecfdac5e546472332f02b.diff

LOG: [lldb/ScriptInterpreter] Let the IORedirect factory handle IO being disabled.

Have one factory method that decides how to initialize the
ScriptInterpreterIORedirect object based on whether IO is enabled or
disabled.

Added: 
    

Modified: 
    lldb/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/source/Interpreter/ScriptInterpreter.cpp
    lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 8086886149f8..491923e6a6c4 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -36,13 +36,11 @@ class ScriptInterpreterLocker {
 
 class ScriptInterpreterIORedirect {
 public:
-  /// Create an IO redirect with /dev/null as input, output and error file.
-  static llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>> Create();
-
-  /// Create an IO redirect that redirects the output to the command return
-  /// object if set or to the debugger otherwise.
+  /// Create an IO redirect. If IO is enabled, this will redirects the output
+  /// to the command return object if set or to the debugger otherwise. If IO
+  /// is disabled, it will redirect all IO to /dev/null.
   static llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>>
-  Create(Debugger &debugger, CommandReturnObject *result);
+  Create(bool enable_io, Debugger &debugger, CommandReturnObject *result);
 
   ~ScriptInterpreterIORedirect();
 

diff  --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp
index d46a104fa25c..967c22819313 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -119,7 +119,12 @@ static void ReadThreadBytesReceived(void *baton, const void *src,
 }
 
 llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>>
-ScriptInterpreterIORedirect::Create() {
+ScriptInterpreterIORedirect::Create(bool enable_io, Debugger &debugger,
+                                    CommandReturnObject *result) {
+  if (enable_io)
+    return std::unique_ptr<ScriptInterpreterIORedirect>(
+        new ScriptInterpreterIORedirect(debugger, result));
+
   auto nullin = FileSystem::Instance().Open(FileSpec(FileSystem::DEV_NULL),
                                             File::eOpenOptionRead);
   if (!nullin)
@@ -134,13 +139,6 @@ ScriptInterpreterIORedirect::Create() {
       new ScriptInterpreterIORedirect(std::move(*nullin), std::move(*nullout)));
 }
 
-llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>>
-ScriptInterpreterIORedirect::Create(Debugger &debugger,
-                                    CommandReturnObject *result) {
-  return std::unique_ptr<ScriptInterpreterIORedirect>(
-      new ScriptInterpreterIORedirect(debugger, result));
-}
-
 ScriptInterpreterIORedirect::ScriptInterpreterIORedirect(
     std::unique_ptr<File> input, std::unique_ptr<File> output)
     : m_input_file_sp(std::move(input)),

diff  --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 40ce7d997800..d7f2fc659cf6 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -912,10 +912,8 @@ bool ScriptInterpreterPythonImpl::ExecuteOneLine(
     // we use the following more complicated method to pass the command string
     // directly down to Python.
     llvm::Expected<std::unique_ptr<ScriptInterpreterIORedirect>>
-        io_redirect_or_error =
-            options.GetEnableIO()
-                ? ScriptInterpreterIORedirect::Create(m_debugger, result)
-                : ScriptInterpreterIORedirect::Create();
+        io_redirect_or_error = ScriptInterpreterIORedirect::Create(
+            options.GetEnableIO(), m_debugger, result);
     if (!io_redirect_or_error) {
       if (result)
         result->AppendErrorWithFormatv(


        


More information about the lldb-commits mailing list