summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/common/File.cpp
diff options
context:
space:
mode:
authorLawrence D'Anna <lawrence_danna@apple.com>2019-10-03 04:01:07 +0000
committerLawrence D'Anna <lawrence_danna@apple.com>2019-10-03 04:01:07 +0000
commit5750453020926ce270aee38bd5eb7f0ff3467237 (patch)
tree5e00ea3b2f67bdd77c02d67e409ed27e72fb52d9 /lldb/source/Host/common/File.cpp
parentf13b8d4fe962216cd0e1a7dc318709caa1c5b59a (diff)
downloadbcm5719-llvm-5750453020926ce270aee38bd5eb7f0ff3467237.tar.gz
bcm5719-llvm-5750453020926ce270aee38bd5eb7f0ff3467237.zip
new api class: SBFile
Summary: SBFile is a scripting API wrapper for lldb_private::File This is the first step in a project to enable arbitrary python io.IOBase file objects -- including those that override the read() and write() methods -- to be used as the main debugger IOStreams. Currently this is impossible because python file objects must first be converted into FILE* streams by SWIG in order to be passed into the debugger. full prototype: https://github.com/smoofra/llvm-project/tree/files Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath Reviewed By: labath Subscribers: labath, mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67793 llvm-svn: 373562
Diffstat (limited to 'lldb/source/Host/common/File.cpp')
-rw-r--r--lldb/source/Host/common/File.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp
index b79c00378c9..eff4197db64 100644
--- a/lldb/source/Host/common/File.cpp
+++ b/lldb/source/Host/common/File.cpp
@@ -68,6 +68,20 @@ static const char *GetStreamOpenModeFromOptions(uint32_t options) {
return nullptr;
}
+uint32_t File::GetOptionsFromMode(llvm::StringRef mode) {
+ return llvm::StringSwitch<uint32_t>(mode)
+ .Case("r", File::eOpenOptionRead)
+ .Case("w", File::eOpenOptionWrite)
+ .Case("a", File::eOpenOptionWrite | 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::eOpenOptionAppend | File::eOpenOptionCanCreate)
+ .Default(0);
+}
+
int File::kInvalidDescriptor = -1;
FILE *File::kInvalidStream = nullptr;
@@ -143,9 +157,14 @@ uint32_t File::GetPermissions(Status &error) const {
Status File::Close() {
Status error;
- if (StreamIsValid() && m_own_stream) {
- if (::fclose(m_stream) == EOF)
- error.SetErrorToErrno();
+ if (StreamIsValid()) {
+ if (m_own_stream) {
+ if (::fclose(m_stream) == EOF)
+ error.SetErrorToErrno();
+ } else {
+ if (::fflush(m_stream) == EOF)
+ error.SetErrorToErrno();
+ }
}
if (DescriptorIsValid() && m_own_descriptor) {
OpenPOWER on IntegriCloud