[Lldb-commits] [lldb] 36496cc - [lldb-vscode] correctly use Windows macros

Walter Erquinigo via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 4 11:03:43 PST 2021


Author: Walter Erquinigo
Date: 2021-02-04T11:03:33-08:00
New Revision: 36496cc2992d6fa26e6024971efcfc7d15f69888

URL: https://github.com/llvm/llvm-project/commit/36496cc2992d6fa26e6024971efcfc7d15f69888
DIFF: https://github.com/llvm/llvm-project/commit/36496cc2992d6fa26e6024971efcfc7d15f69888.diff

LOG: [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

Added: 
    

Modified: 
    lldb/tools/lldb-vscode/FifoFiles.cpp
    lldb/tools/lldb-vscode/IOStream.cpp
    lldb/tools/lldb-vscode/IOStream.h
    lldb/tools/lldb-vscode/RunInTerminal.cpp
    lldb/tools/lldb-vscode/VSCode.cpp
    lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/tools/lldb-vscode/FifoFiles.cpp b/lldb/tools/lldb-vscode/FifoFiles.cpp
index d56f88085abd..e37f2020d8f1 100644
--- a/lldb/tools/lldb-vscode/FifoFiles.cpp
+++ b/lldb/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 @@ namespace lldb_vscode {
 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/lldb/tools/lldb-vscode/IOStream.cpp b/lldb/tools/lldb-vscode/IOStream.cpp
index fdbfb554aedb..cd22d906c14c 100644
--- a/lldb/tools/lldb-vscode/IOStream.cpp
+++ b/lldb/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 @@ StreamDescriptor::~StreamDescriptor() {
     return;
 
   if (m_is_socket)
-#if !LLVM_ON_UNIX
+#if defined(_WIN32)
     ::closesocket(m_socket);
 #else
     ::close(m_socket);
@@ -108,7 +108,7 @@ bool InputStream::read_full(std::ofstream *log, size_t length,
     }
     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/lldb/tools/lldb-vscode/IOStream.h b/lldb/tools/lldb-vscode/IOStream.h
index 1ec7ac3ed0f9..0eb9b6fefb0d 100644
--- a/lldb/tools/lldb-vscode/IOStream.h
+++ b/lldb/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/lldb/tools/lldb-vscode/RunInTerminal.cpp b/lldb/tools/lldb-vscode/RunInTerminal.cpp
index 29edf5ca381d..2126563d9e96 100644
--- a/lldb/tools/lldb-vscode/RunInTerminal.cpp
+++ b/lldb/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/lldb/tools/lldb-vscode/VSCode.cpp b/lldb/tools/lldb-vscode/VSCode.cpp
index 4d0e281c1b8d..e9fdc17f4147 100644
--- a/lldb/tools/lldb-vscode/VSCode.cpp
+++ b/lldb/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 @@ VSCode::VSCode()
       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/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index b7f39cbb1cb5..9469690cd7db 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/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 @@ SOCKET AcceptConnection(int portno) {
           *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 @@ static void printHelp(LLDBVSCodeOptTable &table, llvm::StringRef tool_name) {
 // 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 @@ int main(int argc, char *argv[]) {
     }
   }
 
-#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();


        


More information about the lldb-commits mailing list