Skip to content

Commit 36496cc

Browse files
[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
1 parent 63dc264 commit 36496cc

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

lldb/tools/lldb-vscode/FifoFiles.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "FifoFiles.h"
1010

11-
#if LLVM_ON_UNIX
11+
#if !defined(_WIN32)
1212
#include <sys/stat.h>
1313
#include <sys/types.h>
1414
#include <unistd.h>
@@ -30,13 +30,13 @@ namespace lldb_vscode {
3030
FifoFile::FifoFile(StringRef path) : m_path(path) {}
3131

3232
FifoFile::~FifoFile() {
33-
#if LLVM_ON_UNIX
33+
#if !defined(_WIN32)
3434
unlink(m_path.c_str());
3535
#endif
3636
}
3737

3838
Expected<std::shared_ptr<FifoFile>> CreateFifoFile(StringRef path) {
39-
#if !LLVM_ON_UNIX
39+
#if defined(_WIN32)
4040
return createStringError(inconvertibleErrorCode(), "Unimplemented");
4141
#else
4242
if (int err = mkfifo(path.data(), 0600))

lldb/tools/lldb-vscode/IOStream.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "IOStream.h"
1010

11-
#if !LLVM_ON_UNIX
11+
#if defined(_WIN32)
1212
#include <io.h>
1313
#else
1414
#include <netinet/in.h>
@@ -33,7 +33,7 @@ StreamDescriptor::~StreamDescriptor() {
3333
return;
3434

3535
if (m_is_socket)
36-
#if !LLVM_ON_UNIX
36+
#if defined(_WIN32)
3737
::closesocket(m_socket);
3838
#else
3939
::close(m_socket);
@@ -108,7 +108,7 @@ bool InputStream::read_full(std::ofstream *log, size_t length,
108108
}
109109
if (bytes_read < 0) {
110110
int reason = 0;
111-
#if !LLVM_ON_UNIX
111+
#if defined(_WIN32)
112112
if (descriptor.m_is_socket)
113113
reason = WSAGetLastError();
114114
else

lldb/tools/lldb-vscode/IOStream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
1313

14-
#if !LLVM_ON_UNIX
14+
#if defined(_WIN32)
1515
// We need to #define NOMINMAX in order to skip `min()` and `max()` macro
1616
// definitions that conflict with other system headers.
1717
// We also need to #undef GetObject (which is defined to GetObjectW) because

lldb/tools/lldb-vscode/RunInTerminal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "RunInTerminal.h"
1010

11-
#if LLVM_ON_UNIX
11+
#if !defined(_WIN32)
1212
#include <sys/stat.h>
1313
#include <sys/types.h>
1414
#include <unistd.h>

lldb/tools/lldb-vscode/VSCode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "VSCode.h"
1515
#include "llvm/Support/FormatVariadic.h"
1616

17-
#if !LLVM_ON_UNIX
17+
#if defined(_WIN32)
1818
#define NOMINMAX
1919
#include <fcntl.h>
2020
#include <io.h>
@@ -41,7 +41,7 @@ VSCode::VSCode()
4141
stop_at_entry(false), is_attach(false),
4242
reverse_request_seq(0), waiting_for_run_in_terminal(false) {
4343
const char *log_file_path = getenv("LLDBVSCODE_LOG");
44-
#if !LLVM_ON_UNIX
44+
#if defined(_WIN32)
4545
// Windows opens stdout and stdin in text mode which converts \n to 13,10
4646
// while the value is just 10 on Darwin/Linux. Setting the file mode to binary
4747
// fixes this.

lldb/tools/lldb-vscode/lldb-vscode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <string.h>
1717
#include <sys/stat.h>
1818
#include <sys/types.h>
19-
#if !LLVM_ON_UNIX
19+
#if defined(_WIN32)
2020
// We need to #define NOMINMAX in order to skip `min()` and `max()` macro
2121
// definitions that conflict with other system headers.
2222
// We also need to #undef GetObject (which is defined to GetObjectW) because
@@ -55,7 +55,7 @@
5555
#include "JSONUtils.h"
5656
#include "LLDBUtils.h"
5757

58-
#if !LLVM_ON_UNIX
58+
#if defined(_WIN32)
5959
#ifndef PATH_MAX
6060
#define PATH_MAX MAX_PATH
6161
#endif
@@ -132,7 +132,7 @@ SOCKET AcceptConnection(int portno) {
132132
*g_vsc.log << "error: accept (" << strerror(errno) << ")"
133133
<< std::endl;
134134
}
135-
#if !LLVM_ON_UNIX
135+
#if defined(_WIN32)
136136
closesocket(sockfd);
137137
#else
138138
close(sockfd);
@@ -3003,7 +3003,7 @@ static void printHelp(LLDBVSCodeOptTable &table, llvm::StringRef tool_name) {
30033003
// emitted to the debug adaptor.
30043004
void LaunchRunInTerminalTarget(llvm::opt::Arg &target_arg,
30053005
llvm::StringRef comm_file, char *argv[]) {
3006-
#if !LLVM_ON_UNIX
3006+
#if defined(_WIN32)
30073007
llvm::errs() << "runInTerminal is only supported on POSIX systems\n";
30083008
exit(EXIT_FAILURE);
30093009
#else
@@ -3085,7 +3085,7 @@ int main(int argc, char *argv[]) {
30853085
}
30863086
}
30873087

3088-
#if LLVM_ON_UNIX
3088+
#if !defined(_WIN32)
30893089
if (input_args.hasArg(OPT_wait_for_debugger)) {
30903090
printf("Paused waiting for debugger to attach (pid = %i)...\n", getpid());
30913091
pause();

0 commit comments

Comments
 (0)