diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -103,7 +103,22 @@ FILE *File::GetStream() { if (!StreamIsValid()) { if (DescriptorIsValid()) { - const char *mode = GetStreamOpenModeFromOptions(m_options); + const char *mode = nullptr; + if (m_options) { + mode = GetStreamOpenModeFromOptions(m_options); + } else { + int fdflags = ::fcntl(m_descriptor, F_GETFL); + if (fdflags >= 0) { + if (fdflags & O_RDWR) { + mode = "r+"; + } else if (fdflags & O_WRONLY) { + mode = "w"; + } else { + mode = "r"; + } + } + } + if (mode) { if (!m_should_close_fd) { // We must duplicate the file descriptor if we don't own it because when you