Skip to content

Commit b2f1fb2

Browse files
committed
MingW compilation (windows). Includes various refactoring to improve portability.
llvm-svn: 189107
1 parent fcfa0af commit b2f1fb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1761
-296
lines changed

lldb/CMakeLists.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
7171
endif()
7272
endif()
7373

74+
if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
75+
add_definitions( -DLLDB_DISABLE_PYTHON )
76+
endif ()
77+
7478
macro(add_lldb_definitions)
7579
# We don't want no semicolons on LLDB_DEFINITIONS:
7680
foreach(arg ${ARGN})
@@ -182,7 +186,7 @@ macro(add_lldb_library name)
182186
#endif()
183187

184188
if(LLDB_USED_LIBS)
185-
if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
189+
if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "Windows")
186190
target_link_libraries(${name} -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group)
187191
else()
188192
target_link_libraries(${name} ${LLDB_USED_LIBS})
@@ -260,7 +264,9 @@ endif()
260264

261265
#add_subdirectory(include)
262266
add_subdirectory(docs)
263-
add_subdirectory(scripts)
267+
if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
268+
add_subdirectory(scripts)
269+
endif()
264270
add_subdirectory(source)
265271
add_subdirectory(test)
266272
add_subdirectory(tools)

lldb/Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@ LEVEL := $(LLDB_LEVEL)/../..
2828
# Include LLVM common makefile.
2929
include $(LEVEL)/Makefile.common
3030

31-
# Set Python include directory
32-
PYTHON_INC_DIR = $(shell python-config --includes)
3331
# Set common LLDB build flags.
3432
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/include
3533
CPP.Flags += -I$(PROJ_OBJ_DIR)/$(LLDB_LEVEL)/include
3634
CPP.Flags += -I$(LLVM_SRC_ROOT)/tools/clang/include
3735
CPP.Flags += -I$(LLVM_OBJ_ROOT)/tools/clang/include
38-
CPP.Flags += $(PYTHON_INC_DIR)
3936
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/source
4037
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/source/Utility
4138
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/source/Plugins/Process/Utility
4239
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/source/Plugins/Process/POSIX
40+
41+
ifeq (,$(findstring -DLLDB_DISABLE_PYTHON,$(CXXFLAGS)))
42+
# Set Python include directory
43+
PYTHON_INC_DIR = $(shell python-config --includes)
44+
CPP.Flags += $(PYTHON_INC_DIR)
45+
endif
46+
4347
ifeq ($(HOST_OS),Darwin)
4448
CPP.Flags += -F/System/Library/Frameworks -F/System/Library/PrivateFrameworks
4549
CPP.Flags += -I/usr/include/libxml2

lldb/include/lldb/API/SBHostOS.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SBHostOS
3030

3131
static lldb::thread_t
3232
ThreadCreate (const char *name,
33-
void *(*thread_function)(void *),
33+
thread_func_t thread_function,
3434
void *thread_arg,
3535
lldb::SBError *err);
3636

@@ -43,7 +43,7 @@ class SBHostOS
4343
lldb::SBError *err);
4444
static bool
4545
ThreadJoin (lldb::thread_t thread,
46-
void **result,
46+
thread_result_t *result,
4747
lldb::SBError *err);
4848

4949

lldb/include/lldb/Core/ConnectionFileDescriptor.h

+4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
#define liblldb_ConnectionFileDescriptor_h_
1212

1313
// C Includes
14+
#ifdef _WIN32
15+
typedef unsigned short in_port_t;
16+
#else
1417
#include <sys/socket.h>
1518
#include <sys/types.h>
1619
#include <netinet/in.h>
20+
#endif
1721

1822
// C++ Includes
1923
// Other libraries and framework includes

lldb/include/lldb/Core/RegularExpression.h

+29
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,36 @@
1111
#define liblldb_DBRegex_h_
1212
#if defined(__cplusplus)
1313

14+
#ifdef _WIN32
15+
#include "../lib/Support/regex_impl.h"
16+
17+
typedef llvm_regmatch_t regmatch_t;
18+
typedef llvm_regex_t regex_t;
19+
20+
inline int regcomp(llvm_regex_t * a, const char *b, int c)
21+
{
22+
return llvm_regcomp(a, b, c);
23+
}
24+
25+
inline size_t regerror(int a, const llvm_regex_t *b, char *c, size_t d)
26+
{
27+
return llvm_regerror(a, b, c, d);
28+
}
29+
30+
inline int regexec(const llvm_regex_t * a, const char * b, size_t c,
31+
llvm_regmatch_t d [], int e)
32+
{
33+
return llvm_regexec(a, b, c, d, e);
34+
}
35+
36+
inline void regfree(llvm_regex_t * a)
37+
{
38+
llvm_regfree(a);
39+
}
40+
41+
#else
1442
#include <regex.h>
43+
#endif
1544
#include <stdint.h>
1645

1746
#include <string>

lldb/include/lldb/Core/Value.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Value
114114
#if defined (ENABLE_128_BIT_SUPPORT)
115115
else if (length >= 16) scalar = *(const __uint128_t *)bytes;
116116
#else
117-
else if (length >= 16) scalar = *(const __uint64_t *)bytes;
117+
else if (length >= 16) scalar = *(const uint64_t *)bytes;
118118
#endif
119119
}
120120
return scalar;

lldb/include/lldb/Host/Condition.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#if defined(__cplusplus)
1313

1414

15-
#include <pthread.h>
15+
#include "lldb/lldb-types.h"
1616
#include "lldb/Host/Mutex.h"
1717

1818
namespace lldb_private {
@@ -105,15 +105,15 @@ class Condition
105105
//------------------------------------------------------------------
106106
// Member variables
107107
//------------------------------------------------------------------
108-
pthread_cond_t m_condition; ///< The condition variable.
108+
lldb::condition_t m_condition; ///< The condition variable.
109109

110110
//------------------------------------------------------------------
111111
/// Get accessor to the pthread condition object.
112112
///
113113
/// @return
114114
/// A pointer to the condition variable owned by this object.
115115
//------------------------------------------------------------------
116-
pthread_cond_t *
116+
lldb::condition_t *
117117
GetCondition ();
118118
};
119119

lldb/include/lldb/Host/Host.h

+14
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ class Host
209209
static lldb::pid_t
210210
GetCurrentProcessID ();
211211

212+
static void
213+
Kill(lldb::pid_t pid, int signo);
214+
212215
//------------------------------------------------------------------
213216
/// Get the thread ID for the calling thread in the current process.
214217
///
@@ -264,6 +267,17 @@ class Host
264267
lldb::thread_result_t *thread_result_ptr,
265268
Error *error);
266269

270+
typedef void (*ThreadLocalStorageCleanupCallback) (void *p);
271+
272+
static lldb::thread_key_t
273+
ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback);
274+
275+
static void*
276+
ThreadLocalStorageGet(lldb::thread_key_t key);
277+
278+
static void
279+
ThreadLocalStorageSet(lldb::thread_key_t key, void *value);
280+
267281
//------------------------------------------------------------------
268282
/// Gets the name of a thread in a process.
269283
///

lldb/include/lldb/Host/Mutex.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define liblldb_Mutex_h_
1212
#if defined(__cplusplus)
1313

14-
#include <pthread.h>
14+
#include "lldb/lldb-types.h"
1515
#include <assert.h>
1616

1717
#ifdef LLDB_CONFIGURATION_DEBUG
@@ -238,7 +238,7 @@ class Mutex
238238
//------------------------------------------------------------------
239239
// TODO: Hide the mutex in the implementation file in case we ever need to port to an
240240
// architecture that doesn't have pthread mutexes.
241-
pthread_mutex_t m_mutex; ///< The pthread mutex object.
241+
lldb::mutex_t m_mutex; ///< The OS mutex object.
242242

243243
private:
244244
//------------------------------------------------------------------
@@ -247,7 +247,7 @@ class Mutex
247247
/// @return
248248
/// A pointer to the pthread mutex object owned by this object.
249249
//------------------------------------------------------------------
250-
pthread_mutex_t *
250+
lldb::mutex_t *
251251
GetMutex();
252252

253253
Mutex(const Mutex&);

lldb/include/lldb/Host/ProcessRunLock.h

+10-71
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#define liblldb_ProcessRunLock_h_
1212
#if defined(__cplusplus)
1313

14+
#include "lldb/lldb-defines.h"
1415
#include "lldb/Host/Mutex.h"
1516
#include "lldb/Host/Condition.h"
16-
#include <pthread.h>
1717
#include <stdint.h>
1818
#include <time.h>
1919

@@ -32,75 +32,14 @@ namespace lldb_private {
3232
class ProcessRunLock
3333
{
3434
public:
35-
ProcessRunLock () :
36-
m_rwlock(),
37-
m_running(false)
38-
{
39-
int err = ::pthread_rwlock_init(&m_rwlock, NULL); (void)err;
40-
//#if LLDB_CONFIGURATION_DEBUG
41-
// assert(err == 0);
42-
//#endif
43-
}
44-
45-
~ProcessRunLock ()
46-
{
47-
int err = ::pthread_rwlock_destroy (&m_rwlock); (void)err;
48-
//#if LLDB_CONFIGURATION_DEBUG
49-
// assert(err == 0);
50-
//#endif
51-
}
52-
53-
bool
54-
ReadTryLock ()
55-
{
56-
::pthread_rwlock_rdlock (&m_rwlock);
57-
if (m_running == false)
58-
{
59-
return true;
60-
}
61-
::pthread_rwlock_unlock (&m_rwlock);
62-
return false;
63-
}
64-
65-
bool
66-
ReadUnlock ()
67-
{
68-
return ::pthread_rwlock_unlock (&m_rwlock) == 0;
69-
}
70-
71-
bool
72-
SetRunning()
73-
{
74-
::pthread_rwlock_wrlock (&m_rwlock);
75-
m_running = true;
76-
::pthread_rwlock_unlock (&m_rwlock);
77-
return true;
78-
}
79-
80-
bool
81-
TrySetRunning()
82-
{
83-
bool r;
84-
85-
if (::pthread_rwlock_trywrlock (&m_rwlock) == 0)
86-
{
87-
r = !m_running;
88-
m_running = true;
89-
::pthread_rwlock_unlock (&m_rwlock);
90-
return r;
91-
}
92-
return false;
93-
}
94-
95-
bool
96-
SetStopped ()
97-
{
98-
::pthread_rwlock_wrlock (&m_rwlock);
99-
m_running = false;
100-
::pthread_rwlock_unlock (&m_rwlock);
101-
return true;
102-
}
103-
35+
ProcessRunLock();
36+
~ProcessRunLock();
37+
bool ReadTryLock ();
38+
bool ReadUnlock ();
39+
bool SetRunning ();
40+
bool TrySetRunning ();
41+
bool SetStopped ();
42+
public:
10443
class ProcessRunLocker
10544
{
10645
public:
@@ -153,7 +92,7 @@ class ProcessRunLock
15392
};
15493

15594
protected:
156-
pthread_rwlock_t m_rwlock;
95+
lldb::rwlock_t m_rwlock;
15796
bool m_running;
15897
private:
15998
DISALLOW_COPY_AND_ASSIGN(ProcessRunLock);

lldb/include/lldb/Host/SocketAddress.h

+9
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@
1212

1313
// C Includes
1414
#include <stdint.h>
15+
16+
#ifdef _WIN32
17+
#include "lldb/Host/windows/windows.h"
18+
#include <winsock2.h>
19+
#include <WS2tcpip.h>
20+
typedef ADDRESS_FAMILY sa_family_t;
21+
typedef USHORT in_port_t;
22+
#else
1523
#include <sys/socket.h>
1624
#include <netdb.h>
1725
#include <netinet/in.h>
26+
#endif
1827

1928
#if defined(__FreeBSD__)
2029
#include <sys/types.h>

lldb/include/lldb/Host/Terminal.h

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#if defined(__cplusplus)
1313

1414
#include "lldb/lldb-private.h"
15+
#include "lldb/Host/Config.h"
1516

1617
struct termios;
1718

@@ -173,7 +174,9 @@ class TerminalState
173174
//------------------------------------------------------------------
174175
Terminal m_tty; ///< A terminal
175176
int m_tflags; ///< Cached tflags information.
177+
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
176178
std::unique_ptr<struct termios> m_termios_ap; ///< Cached terminal state information.
179+
#endif
177180
lldb::pid_t m_process_group;///< Cached process group information.
178181

179182
};

lldb/include/lldb/Host/mingw/Config.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef liblldb_Platform_Config_h_
1818
#define liblldb_Platform_Config_h_
1919

20+
#define LLDB_DISABLE_POSIX
21+
2022
//#define LLDB_CONFIG_TERMIOS_SUPPORTED 1
2123

2224
//#define LLDB_CONFIG_TILDE_RESOLVES_TO_USER 1
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===-- lldb-win32.h --------------------------------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLDB_lldb_win32_h_
11+
#define LLDB_lldb_win32_h_
12+
13+
#include <stdarg.h>
14+
15+
// posix utilities
16+
int vasprintf(char **ret, const char *fmt, va_list ap);
17+
char * strcasestr(const char *s, const char* find);
18+
char* realpath(const char * name, char * resolved);
19+
20+
#define PATH_MAX MAX_PATH
21+
22+
#define O_NOCTTY 0
23+
#define SIGTRAP 5
24+
#define SIGKILL 9
25+
#define SIGSTOP 20
26+
27+
#endif // LLDB_lldb_win32_h_

0 commit comments

Comments
 (0)