Revert "[lldb][windows] use Windows APIs to print to the console (#149493)"#154423
Merged
charles-zablit merged 1 commit intollvm:mainfrom Aug 20, 2025
Merged
Conversation
Member
|
@llvm/pr-subscribers-lldb Author: Charles Zablit (charles-zablit) ChangesThis reverts commit f55dc08 in order to fix the issue reported here. Full diff: https://github.com/llvm/llvm-project/pull/154423.diff 2 Files Affected:
diff --git a/lldb/include/lldb/Host/File.h b/lldb/include/lldb/Host/File.h
index 7402a2231735a..9e2d0abe0b1af 100644
--- a/lldb/include/lldb/Host/File.h
+++ b/lldb/include/lldb/Host/File.h
@@ -382,11 +382,15 @@ class NativeFile : public File {
Unowned = false,
};
- NativeFile();
+ NativeFile() : m_descriptor(kInvalidDescriptor), m_stream(kInvalidStream) {}
- NativeFile(FILE *fh, bool transfer_ownership);
+ NativeFile(FILE *fh, bool transfer_ownership)
+ : m_descriptor(kInvalidDescriptor), m_own_descriptor(false), m_stream(fh),
+ m_options(), m_own_stream(transfer_ownership) {}
- NativeFile(int fd, OpenOptions options, bool transfer_ownership);
+ NativeFile(int fd, OpenOptions options, bool transfer_ownership)
+ : m_descriptor(fd), m_own_descriptor(transfer_ownership),
+ m_stream(kInvalidStream), m_options(options), m_own_stream(false) {}
~NativeFile() override { Close(); }
@@ -440,19 +444,17 @@ class NativeFile : public File {
return ValueGuard(m_stream_mutex, StreamIsValidUnlocked());
}
- int m_descriptor = kInvalidDescriptor;
+ int m_descriptor;
bool m_own_descriptor = false;
mutable std::mutex m_descriptor_mutex;
- FILE *m_stream = kInvalidStream;
+ FILE *m_stream;
mutable std::mutex m_stream_mutex;
OpenOptions m_options{};
bool m_own_stream = false;
std::mutex offset_access_mutex;
- bool is_windows_console = false;
-
private:
NativeFile(const NativeFile &) = delete;
const NativeFile &operator=(const NativeFile &) = delete;
diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp
index 8cbbd7a5e14c7..23b6dc9fe850d 100644
--- a/lldb/source/Host/common/File.cpp
+++ b/lldb/source/Host/common/File.cpp
@@ -36,7 +36,6 @@
#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Process.h"
-#include "llvm/Support/raw_ostream.h"
using namespace lldb;
using namespace lldb_private;
@@ -248,32 +247,6 @@ uint32_t File::GetPermissions(Status &error) const {
return file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
}
-NativeFile::NativeFile() = default;
-
-NativeFile::NativeFile(FILE *fh, bool transfer_ownership)
- : m_stream(fh), m_own_stream(transfer_ownership) {
-#ifdef _WIN32
- // In order to properly display non ASCII characters in Windows, we need to
- // use Windows APIs to print to the console. This is only required if the
- // stream outputs to a console.
- int fd = _fileno(fh);
- is_windows_console =
- ::GetFileType((HANDLE)::_get_osfhandle(fd)) == FILE_TYPE_CHAR;
-#endif
-}
-
-NativeFile::NativeFile(int fd, OpenOptions options, bool transfer_ownership)
- : m_descriptor(fd), m_own_descriptor(transfer_ownership),
- m_options(options) {
-#ifdef _WIN32
- // In order to properly display non ASCII characters in Windows, we need to
- // use Windows APIs to print to the console. This is only required if the
- // file outputs to a console.
- is_windows_console =
- ::GetFileType((HANDLE)::_get_osfhandle(fd)) == FILE_TYPE_CHAR;
-#endif
-}
-
bool NativeFile::IsValid() const {
std::scoped_lock<std::mutex, std::mutex> lock(m_descriptor_mutex, m_stream_mutex);
return DescriptorIsValidUnlocked() || StreamIsValidUnlocked();
@@ -645,12 +618,6 @@ Status NativeFile::Write(const void *buf, size_t &num_bytes) {
ssize_t bytes_written = -1;
if (ValueGuard descriptor_guard = DescriptorIsValid()) {
-#ifdef _WIN32
- if (is_windows_console) {
- llvm::raw_fd_ostream(m_descriptor, false).write((char *)buf, num_bytes);
- return error;
- }
-#endif
bytes_written =
llvm::sys::RetryAfterSignal(-1, ::write, m_descriptor, buf, num_bytes);
if (bytes_written == -1) {
@@ -662,13 +629,6 @@ Status NativeFile::Write(const void *buf, size_t &num_bytes) {
}
if (ValueGuard stream_guard = StreamIsValid()) {
-#ifdef _WIN32
- if (is_windows_console) {
- llvm::raw_fd_ostream(_fileno(m_stream), false)
- .write((char *)buf, num_bytes);
- return error;
- }
-#endif
bytes_written = ::fwrite(buf, 1, num_bytes, m_stream);
if (bytes_written == 0) {
|
Michael137
approved these changes
Aug 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This reverts commit f55dc08 in order to fix the issue reported here.