[lldb-vscode] correctly use Windows macros
@mstorsjo found a mistake that I made when trying to fix some Windows
compilation errors encountered by @stella.stamenova.
I was incorrectly using the LLVM_ON_UNIX macro. In any case, proper use
of
#if defined(_WIN32)
should be the actual fix.
Differential Revision: https://reviews.llvm.org/D96060
GitOrigin-RevId: 36496cc2992d6fa26e6024971efcfc7d15f69888
diff --git a/tools/lldb-vscode/FifoFiles.cpp b/tools/lldb-vscode/FifoFiles.cpp
index d56f880..e37f202 100644
--- a/tools/lldb-vscode/FifoFiles.cpp
+++ b/tools/lldb-vscode/FifoFiles.cpp
@@ -8,7 +8,7 @@
#include "FifoFiles.h"
-#if LLVM_ON_UNIX
+#if !defined(_WIN32)
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -30,13 +30,13 @@
FifoFile::FifoFile(StringRef path) : m_path(path) {}
FifoFile::~FifoFile() {
-#if LLVM_ON_UNIX
+#if !defined(_WIN32)
unlink(m_path.c_str());
#endif
}
Expected<std::shared_ptr<FifoFile>> CreateFifoFile(StringRef path) {
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
return createStringError(inconvertibleErrorCode(), "Unimplemented");
#else
if (int err = mkfifo(path.data(), 0600))
diff --git a/tools/lldb-vscode/IOStream.cpp b/tools/lldb-vscode/IOStream.cpp
index fdbfb55..cd22d90 100644
--- a/tools/lldb-vscode/IOStream.cpp
+++ b/tools/lldb-vscode/IOStream.cpp
@@ -8,7 +8,7 @@
#include "IOStream.h"
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
#include <io.h>
#else
#include <netinet/in.h>
@@ -33,7 +33,7 @@
return;
if (m_is_socket)
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
::closesocket(m_socket);
#else
::close(m_socket);
@@ -108,7 +108,7 @@
}
if (bytes_read < 0) {
int reason = 0;
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
if (descriptor.m_is_socket)
reason = WSAGetLastError();
else
diff --git a/tools/lldb-vscode/IOStream.h b/tools/lldb-vscode/IOStream.h
index 1ec7ac3..0eb9b6f 100644
--- a/tools/lldb-vscode/IOStream.h
+++ b/tools/lldb-vscode/IOStream.h
@@ -11,7 +11,7 @@
#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
// We need to #define NOMINMAX in order to skip `min()` and `max()` macro
// definitions that conflict with other system headers.
// We also need to #undef GetObject (which is defined to GetObjectW) because
diff --git a/tools/lldb-vscode/RunInTerminal.cpp b/tools/lldb-vscode/RunInTerminal.cpp
index 29edf5c..2126563 100644
--- a/tools/lldb-vscode/RunInTerminal.cpp
+++ b/tools/lldb-vscode/RunInTerminal.cpp
@@ -8,7 +8,7 @@
#include "RunInTerminal.h"
-#if LLVM_ON_UNIX
+#if !defined(_WIN32)
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
diff --git a/tools/lldb-vscode/VSCode.cpp b/tools/lldb-vscode/VSCode.cpp
index 4d0e281..e9fdc17 100644
--- a/tools/lldb-vscode/VSCode.cpp
+++ b/tools/lldb-vscode/VSCode.cpp
@@ -14,7 +14,7 @@
#include "VSCode.h"
#include "llvm/Support/FormatVariadic.h"
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
#define NOMINMAX
#include <fcntl.h>
#include <io.h>
@@ -41,7 +41,7 @@
stop_at_entry(false), is_attach(false),
reverse_request_seq(0), waiting_for_run_in_terminal(false) {
const char *log_file_path = getenv("LLDBVSCODE_LOG");
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
// Windows opens stdout and stdin in text mode which converts \n to 13,10
// while the value is just 10 on Darwin/Linux. Setting the file mode to binary
// fixes this.
diff --git a/tools/lldb-vscode/lldb-vscode.cpp b/tools/lldb-vscode/lldb-vscode.cpp
index b7f39cb..9469690 100644
--- a/tools/lldb-vscode/lldb-vscode.cpp
+++ b/tools/lldb-vscode/lldb-vscode.cpp
@@ -16,7 +16,7 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
// We need to #define NOMINMAX in order to skip `min()` and `max()` macro
// definitions that conflict with other system headers.
// We also need to #undef GetObject (which is defined to GetObjectW) because
@@ -55,7 +55,7 @@
#include "JSONUtils.h"
#include "LLDBUtils.h"
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
#ifndef PATH_MAX
#define PATH_MAX MAX_PATH
#endif
@@ -132,7 +132,7 @@
*g_vsc.log << "error: accept (" << strerror(errno) << ")"
<< std::endl;
}
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
closesocket(sockfd);
#else
close(sockfd);
@@ -3003,7 +3003,7 @@
// emitted to the debug adaptor.
void LaunchRunInTerminalTarget(llvm::opt::Arg &target_arg,
llvm::StringRef comm_file, char *argv[]) {
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
llvm::errs() << "runInTerminal is only supported on POSIX systems\n";
exit(EXIT_FAILURE);
#else
@@ -3085,7 +3085,7 @@
}
}
-#if LLVM_ON_UNIX
+#if !defined(_WIN32)
if (input_args.hasArg(OPT_wait_for_debugger)) {
printf("Paused waiting for debugger to attach (pid = %i)...\n", getpid());
pause();