diff options
author | Enrico Granata <egranata@apple.com> | 2016-01-13 18:11:45 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2016-01-13 18:11:45 +0000 |
commit | 744959b9c9d7700a567926a4829f2e8cc6dc3cec (patch) | |
tree | 9236c8d51dbc00abc4f8cf758de375500760d3b9 /lldb/source/Plugins/ScriptInterpreter/Python | |
parent | c5d29aa7c4cb5fe4c5b424c88f5ab6de5a8c4ad2 (diff) | |
download | bcm5719-llvm-744959b9c9d7700a567926a4829f2e8cc6dc3cec.tar.gz bcm5719-llvm-744959b9c9d7700a567926a4829f2e8cc6dc3cec.zip |
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
llvm-svn: 257644
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | 20 | ||||
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h | 2 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index 23bacc932c0..f0db8a67ff7 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -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 *mode) #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) const // 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(); } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h index 06264b66c28..6d5a11bd7d9 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h @@ -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; }; |