[Lldb-commits] [lldb] r257644 - Fix an issue where scripted commands would not actually print any of their output if an immediate output file was set in the result object via a Python file object
Enrico Granata via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 13 10:11:45 PST 2016
Author: enrico
Date: Wed Jan 13 12:11:45 2016
New Revision: 257644
URL: http://llvm.org/viewvc/llvm-project?rev=257644&view=rev
Log:
Fix an issue where scripted commands would not actually print any of their output if an immediate output file was set in the result object via a Python file object
Fixes rdar://24130303
Added:
lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/
lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py
lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py
Modified:
lldb/trunk/include/lldb/Host/File.h
lldb/trunk/scripts/Python/python-typemaps.swig
lldb/trunk/source/Host/common/File.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
Modified: lldb/trunk/include/lldb/Host/File.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/File.h?rev=257644&r1=257643&r2=257644&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/File.h (original)
+++ lldb/trunk/include/lldb/Host/File.h Wed Jan 13 12:11:45 2016
@@ -223,6 +223,9 @@ public:
Error
Close() override;
+ void
+ Clear ();
+
Error
Duplicate (const File &rhs);
Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py?rev=257644&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py Wed Jan 13 12:11:45 2016
@@ -0,0 +1,37 @@
+"""
+Test that LLDB correctly allows scripted commands to set an immediate output file
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.lldbpexpect import *
+
+class CommandScriptImmediateOutputTestCase (PExpectTest):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ PExpectTest.setUp(self)
+
+ @skipIfRemote # test not remote-ready llvm.org/pr24813
+ @expectedFlakeyFreeBSD("llvm.org/pr25172 fails rarely on the buildbot")
+ @expectedFlakeyLinux("llvm.org/pr25172")
+ @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
+ def test_command_script_immediate_output (self):
+ """Test that LLDB correctly allows scripted commands to set an immediate output file."""
+ self.launch(timeout=5)
+
+ script = os.path.join(os.getcwd(), 'custom_command.py')
+ prompt = "(lldb)"
+
+ self.sendline('command script import %s' % script, patterns=[prompt])
+ self.sendline('command script add -f custom_command.command_function mycommand', patterns=[prompt])
+ self.sendline('mycommand', patterns='this is a test string, just a test string')
+ self.sendline('command script delete mycommand', patterns=[prompt])
+ self.quit(gracefully=False)
Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py?rev=257644&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py Wed Jan 13 12:11:45 2016
@@ -0,0 +1,8 @@
+from __future__ import print_function
+
+import sys
+
+def command_function(debugger, command, exe_ctx, result, internal_dict):
+ result.SetImmediateOutputFile(sys.__stdout__)
+ print('this is a test string, just a test string', file=result)
+
Modified: lldb/trunk/scripts/Python/python-typemaps.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-typemaps.swig?rev=257644&r1=257643&r2=257644&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-typemaps.swig (original)
+++ lldb/trunk/scripts/Python/python-typemaps.swig Wed Jan 13 12:11:45 2016
@@ -545,7 +545,9 @@
return nullptr;
$1 = file.GetStream();
- }
+ if ($1)
+ file.Clear();
+ }
}
%typemap(out) FILE * {
Modified: lldb/trunk/source/Host/common/File.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/File.cpp?rev=257644&r1=257643&r2=257644&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/File.cpp (original)
+++ lldb/trunk/source/Host/common/File.cpp Wed Jan 13 12:11:45 2016
@@ -399,6 +399,15 @@ File::Close ()
return error;
}
+void
+File::Clear ()
+{
+ m_stream = nullptr;
+ m_descriptor = -1;
+ m_options = 0;
+ m_own_stream = false;
+ m_is_interactive = m_supports_colors = m_is_real_terminal = eLazyBoolCalculate;
+}
Error
File::GetFileSpec (FileSpec &file_spec) const
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp?rev=257644&r1=257643&r2=257644&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp Wed Jan 13 12:11:45 2016
@@ -23,6 +23,8 @@
#include <stdio.h>
+#include "llvm/ADT/StringSwitch.h"
+
using namespace lldb_private;
using namespace lldb;
@@ -1156,6 +1158,22 @@ PythonFile::Reset(File &file, const char
#endif
}
+uint32_t
+PythonFile::GetOptionsFromMode(llvm::StringRef mode)
+{
+ if (mode.empty())
+ return 0;
+
+ return llvm::StringSwitch<uint32_t>(mode.str().c_str())
+ .Case("r", File::eOpenOptionRead)
+ .Case("w", File::eOpenOptionWrite)
+ .Case("a", File::eOpenOptionAppend|File::eOpenOptionCanCreate)
+ .Case("r+", File::eOpenOptionRead|File::eOpenOptionWrite)
+ .Case("w+", File::eOpenOptionRead|File::eOpenOptionWrite|File::eOpenOptionCanCreate|File::eOpenOptionTruncate)
+ .Case("a+", File::eOpenOptionRead|File::eOpenOptionWrite|File::eOpenOptionCanCreate)
+ .Default(0);
+}
+
bool
PythonFile::GetUnderlyingFile(File &file) const
{
@@ -1166,6 +1184,8 @@ PythonFile::GetUnderlyingFile(File &file
// We don't own the file descriptor returned by this function, make sure the
// File object knows about that.
file.SetDescriptor(PyObject_AsFileDescriptor(m_py_obj), false);
+ PythonString py_mode = GetAttributeValue("mode").AsType<PythonString>();
+ file.SetOptions(PythonFile::GetOptionsFromMode(py_mode.GetString()));
return file.IsValid();
}
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h?rev=257644&r1=257643&r2=257644&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h Wed Jan 13 12:11:45 2016
@@ -525,6 +525,8 @@ class PythonFile : public PythonObject
void Reset(PyRefType type, PyObject *py_obj) override;
void Reset(File &file, const char *mode);
+ static uint32_t GetOptionsFromMode(llvm::StringRef mode);
+
bool GetUnderlyingFile(File &file) const;
};
More information about the lldb-commits
mailing list