summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/CMakeLists.txt10
-rw-r--r--lldb/Makefile10
-rw-r--r--lldb/include/lldb/API/SBHostOS.h4
-rw-r--r--lldb/include/lldb/Core/ConnectionFileDescriptor.h4
-rw-r--r--lldb/include/lldb/Core/RegularExpression.h29
-rw-r--r--lldb/include/lldb/Core/Value.h2
-rw-r--r--lldb/include/lldb/Host/Condition.h6
-rw-r--r--lldb/include/lldb/Host/Host.h14
-rw-r--r--lldb/include/lldb/Host/Mutex.h6
-rw-r--r--lldb/include/lldb/Host/ProcessRunLock.h81
-rw-r--r--lldb/include/lldb/Host/SocketAddress.h9
-rw-r--r--lldb/include/lldb/Host/Terminal.h3
-rw-r--r--lldb/include/lldb/Host/mingw/Config.h2
-rw-r--r--lldb/include/lldb/Host/windows/win32.h27
-rw-r--r--lldb/include/lldb/Host/windows/windows.h26
-rw-r--r--lldb/include/lldb/Target/Process.h10
-rw-r--r--lldb/include/lldb/lldb-private.h4
-rw-r--r--lldb/include/lldb/lldb-types.h40
-rw-r--r--lldb/lib/Makefile4
-rw-r--r--lldb/source/API/SBDebugger.cpp2
-rw-r--r--lldb/source/API/SBHostOS.cpp4
-rw-r--r--lldb/source/CMakeLists.txt31
-rw-r--r--lldb/source/Commands/CommandCompletions.cpp129
-rw-r--r--lldb/source/Core/CMakeLists.txt1
-rw-r--r--lldb/source/Core/Communication.cpp4
-rw-r--r--lldb/source/Core/ConnectionFileDescriptor.cpp62
-rw-r--r--lldb/source/Core/ConnectionSharedMemory.cpp21
-rw-r--r--lldb/source/Core/DataBufferMemoryMap.cpp45
-rw-r--r--lldb/source/Core/Log.cpp1
-rw-r--r--lldb/source/Core/Timer.cpp12
-rw-r--r--lldb/source/DataFormatters/CXXFormatterFunctions.cpp2
-rw-r--r--lldb/source/Expression/IRMemoryMap.cpp6
-rw-r--r--lldb/source/Host/CMakeLists.txt4
-rw-r--r--lldb/source/Host/Makefile4
-rw-r--r--lldb/source/Host/common/CMakeLists.txt1
-rw-r--r--lldb/source/Host/common/Condition.cpp27
-rw-r--r--lldb/source/Host/common/File.cpp41
-rw-r--r--lldb/source/Host/common/FileSpec.cpp98
-rw-r--r--lldb/source/Host/common/Host.cpp157
-rw-r--r--lldb/source/Host/common/Mutex.cpp25
-rw-r--r--lldb/source/Host/common/ProcessRunLock.cpp71
-rw-r--r--lldb/source/Host/common/Terminal.cpp20
-rw-r--r--lldb/source/Host/common/TimeValue.cpp3
-rw-r--r--lldb/source/Host/windows/CMakeLists.txt9
-rw-r--r--lldb/source/Host/windows/Condition.cpp95
-rw-r--r--lldb/source/Host/windows/Host.cpp245
-rw-r--r--lldb/source/Host/windows/Makefile14
-rw-r--r--lldb/source/Host/windows/Mutex.cpp106
-rw-r--r--lldb/source/Host/windows/ProcessRunLock.cpp240
-rw-r--r--lldb/source/Host/windows/Windows.cpp146
-rw-r--r--lldb/source/Interpreter/Args.cpp3
-rw-r--r--lldb/source/Interpreter/Makefile2
-rw-r--r--lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp25
-rw-r--r--lldb/source/Plugins/Makefile4
-rw-r--r--lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp17
-rw-r--r--lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp2
-rw-r--r--lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp6
-rw-r--r--lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp9
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp3
-rw-r--r--lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp3
-rw-r--r--lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp11
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp5
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp5
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp9
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h2
-rw-r--r--lldb/source/Symbol/ObjectFile.cpp2
-rw-r--r--lldb/source/Target/Process.cpp8
-rw-r--r--lldb/source/Utility/PseudoTerminal.cpp15
-rw-r--r--lldb/tools/CMakeLists.txt5
-rw-r--r--lldb/tools/Makefile4
70 files changed, 1761 insertions, 296 deletions
diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index d0ccbe84ab9..0253a1d876d 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -71,6 +71,10 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif()
endif()
+if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
+ add_definitions( -DLLDB_DISABLE_PYTHON )
+endif ()
+
macro(add_lldb_definitions)
# We don't want no semicolons on LLDB_DEFINITIONS:
foreach(arg ${ARGN})
@@ -182,7 +186,7 @@ macro(add_lldb_library name)
#endif()
if(LLDB_USED_LIBS)
- if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "Windows")
target_link_libraries(${name} -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group)
else()
target_link_libraries(${name} ${LLDB_USED_LIBS})
@@ -260,7 +264,9 @@ endif()
#add_subdirectory(include)
add_subdirectory(docs)
-add_subdirectory(scripts)
+if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
+ add_subdirectory(scripts)
+endif()
add_subdirectory(source)
add_subdirectory(test)
add_subdirectory(tools)
diff --git a/lldb/Makefile b/lldb/Makefile
index a26ef917149..cb372368bf5 100644
--- a/lldb/Makefile
+++ b/lldb/Makefile
@@ -28,18 +28,22 @@ LEVEL := $(LLDB_LEVEL)/../..
# Include LLVM common makefile.
include $(LEVEL)/Makefile.common
-# Set Python include directory
-PYTHON_INC_DIR = $(shell python-config --includes)
# Set common LLDB build flags.
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/include
CPP.Flags += -I$(PROJ_OBJ_DIR)/$(LLDB_LEVEL)/include
CPP.Flags += -I$(LLVM_SRC_ROOT)/tools/clang/include
CPP.Flags += -I$(LLVM_OBJ_ROOT)/tools/clang/include
-CPP.Flags += $(PYTHON_INC_DIR)
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/source
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/source/Utility
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/source/Plugins/Process/Utility
CPP.Flags += -I$(PROJ_SRC_DIR)/$(LLDB_LEVEL)/source/Plugins/Process/POSIX
+
+ifeq (,$(findstring -DLLDB_DISABLE_PYTHON,$(CXXFLAGS)))
+# Set Python include directory
+PYTHON_INC_DIR = $(shell python-config --includes)
+CPP.Flags += $(PYTHON_INC_DIR)
+endif
+
ifeq ($(HOST_OS),Darwin)
CPP.Flags += -F/System/Library/Frameworks -F/System/Library/PrivateFrameworks
CPP.Flags += -I/usr/include/libxml2
diff --git a/lldb/include/lldb/API/SBHostOS.h b/lldb/include/lldb/API/SBHostOS.h
index 52754ea4e82..e5fab6fe784 100644
--- a/lldb/include/lldb/API/SBHostOS.h
+++ b/lldb/include/lldb/API/SBHostOS.h
@@ -30,7 +30,7 @@ public:
static lldb::thread_t
ThreadCreate (const char *name,
- void *(*thread_function)(void *),
+ thread_func_t thread_function,
void *thread_arg,
lldb::SBError *err);
@@ -43,7 +43,7 @@ public:
lldb::SBError *err);
static bool
ThreadJoin (lldb::thread_t thread,
- void **result,
+ thread_result_t *result,
lldb::SBError *err);
diff --git a/lldb/include/lldb/Core/ConnectionFileDescriptor.h b/lldb/include/lldb/Core/ConnectionFileDescriptor.h
index fe704d4cadf..e80473669a5 100644
--- a/lldb/include/lldb/Core/ConnectionFileDescriptor.h
+++ b/lldb/include/lldb/Core/ConnectionFileDescriptor.h
@@ -11,9 +11,13 @@
#define liblldb_ConnectionFileDescriptor_h_
// C Includes
+#ifdef _WIN32
+typedef unsigned short in_port_t;
+#else
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
+#endif
// C++ Includes
// Other libraries and framework includes
diff --git a/lldb/include/lldb/Core/RegularExpression.h b/lldb/include/lldb/Core/RegularExpression.h
index eeeb914bfa9..c116d439b94 100644
--- a/lldb/include/lldb/Core/RegularExpression.h
+++ b/lldb/include/lldb/Core/RegularExpression.h
@@ -11,7 +11,36 @@
#define liblldb_DBRegex_h_
#if defined(__cplusplus)
+#ifdef _WIN32
+#include "../lib/Support/regex_impl.h"
+
+typedef llvm_regmatch_t regmatch_t;
+typedef llvm_regex_t regex_t;
+
+inline int regcomp(llvm_regex_t * a, const char *b, int c)
+{
+ return llvm_regcomp(a, b, c);
+}
+
+inline size_t regerror(int a, const llvm_regex_t *b, char *c, size_t d)
+{
+ return llvm_regerror(a, b, c, d);
+}
+
+inline int regexec(const llvm_regex_t * a, const char * b, size_t c,
+ llvm_regmatch_t d [], int e)
+{
+ return llvm_regexec(a, b, c, d, e);
+}
+
+inline void regfree(llvm_regex_t * a)
+{
+ llvm_regfree(a);
+}
+
+#else
#include <regex.h>
+#endif
#include <stdint.h>
#include <string>
diff --git a/lldb/include/lldb/Core/Value.h b/lldb/include/lldb/Core/Value.h
index 5461ca73d08..c7d44322333 100644
--- a/lldb/include/lldb/Core/Value.h
+++ b/lldb/include/lldb/Core/Value.h
@@ -114,7 +114,7 @@ public:
#if defined (ENABLE_128_BIT_SUPPORT)
else if (length >= 16) scalar = *(const __uint128_t *)bytes;
#else
- else if (length >= 16) scalar = *(const __uint64_t *)bytes;
+ else if (length >= 16) scalar = *(const uint64_t *)bytes;
#endif
}
return scalar;
diff --git a/lldb/include/lldb/Host/Condition.h b/lldb/include/lldb/Host/Condition.h
index 98439ee2ebd..2f1858b75a5 100644
--- a/lldb/include/lldb/Host/Condition.h
+++ b/lldb/include/lldb/Host/Condition.h
@@ -12,7 +12,7 @@
#if defined(__cplusplus)
-#include <pthread.h>
+#include "lldb/lldb-types.h"
#include "lldb/Host/Mutex.h"
namespace lldb_private {
@@ -105,7 +105,7 @@ protected:
//------------------------------------------------------------------
// Member variables
//------------------------------------------------------------------
- pthread_cond_t m_condition; ///< The condition variable.
+ lldb::condition_t m_condition; ///< The condition variable.
//------------------------------------------------------------------
/// Get accessor to the pthread condition object.
@@ -113,7 +113,7 @@ protected:
/// @return
/// A pointer to the condition variable owned by this object.
//------------------------------------------------------------------
- pthread_cond_t *
+ lldb::condition_t *
GetCondition ();
};
diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h
index 547bdd5d637..bb3bc4a495e 100644
--- a/lldb/include/lldb/Host/Host.h
+++ b/lldb/include/lldb/Host/Host.h
@@ -209,6 +209,9 @@ public:
static lldb::pid_t
GetCurrentProcessID ();
+ static void
+ Kill(lldb::pid_t pid, int signo);
+
//------------------------------------------------------------------
/// Get the thread ID for the calling thread in the current process.
///
@@ -264,6 +267,17 @@ public:
lldb::thread_result_t *thread_result_ptr,
Error *error);
+ typedef void (*ThreadLocalStorageCleanupCallback) (void *p);
+
+ static lldb::thread_key_t
+ ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback);
+
+ static void*
+ ThreadLocalStorageGet(lldb::thread_key_t key);
+
+ static void
+ ThreadLocalStorageSet(lldb::thread_key_t key, void *value);
+
//------------------------------------------------------------------
/// Gets the name of a thread in a process.
///
diff --git a/lldb/include/lldb/Host/Mutex.h b/lldb/include/lldb/Host/Mutex.h
index 63f759efe36..496dd0496c1 100644
--- a/lldb/include/lldb/Host/Mutex.h
+++ b/lldb/include/lldb/Host/Mutex.h
@@ -11,7 +11,7 @@
#define liblldb_Mutex_h_
#if defined(__cplusplus)
-#include <pthread.h>
+#include "lldb/lldb-types.h"
#include <assert.h>
#ifdef LLDB_CONFIGURATION_DEBUG
@@ -238,7 +238,7 @@ protected:
//------------------------------------------------------------------
// TODO: Hide the mutex in the implementation file in case we ever need to port to an
// architecture that doesn't have pthread mutexes.
- pthread_mutex_t m_mutex; ///< The pthread mutex object.
+ lldb::mutex_t m_mutex; ///< The OS mutex object.
private:
//------------------------------------------------------------------
@@ -247,7 +247,7 @@ private:
/// @return
/// A pointer to the pthread mutex object owned by this object.
//------------------------------------------------------------------
- pthread_mutex_t *
+ lldb::mutex_t *
GetMutex();
Mutex(const Mutex&);
diff --git a/lldb/include/lldb/Host/ProcessRunLock.h b/lldb/include/lldb/Host/ProcessRunLock.h
index f563be73fce..eca1ad375fc 100644
--- a/lldb/include/lldb/Host/ProcessRunLock.h
+++ b/lldb/include/lldb/Host/ProcessRunLock.h
@@ -11,9 +11,9 @@
#define liblldb_ProcessRunLock_h_
#if defined(__cplusplus)
+#include "lldb/lldb-defines.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Host/Condition.h"
-#include <pthread.h>
#include <stdint.h>
#include <time.h>
@@ -32,75 +32,14 @@ namespace lldb_private {
class ProcessRunLock
{
public:
- ProcessRunLock () :
- m_rwlock(),
- m_running(false)
- {
- int err = ::pthread_rwlock_init(&m_rwlock, NULL); (void)err;
-//#if LLDB_CONFIGURATION_DEBUG
-// assert(err == 0);
-//#endif
- }
-
- ~ProcessRunLock ()
- {
- int err = ::pthread_rwlock_destroy (&m_rwlock); (void)err;
-//#if LLDB_CONFIGURATION_DEBUG
-// assert(err == 0);
-//#endif
- }
-
- bool
- ReadTryLock ()
- {
- ::pthread_rwlock_rdlock (&m_rwlock);
- if (m_running == false)
- {
- return true;
- }
- ::pthread_rwlock_unlock (&m_rwlock);
- return false;
- }
-
- bool
- ReadUnlock ()
- {
- return ::pthread_rwlock_unlock (&m_rwlock) == 0;
- }
-
- bool
- SetRunning()
- {
- ::pthread_rwlock_wrlock (&m_rwlock);
- m_running = true;
- ::pthread_rwlock_unlock (&m_rwlock);
- return true;
- }
-
- bool
- TrySetRunning()
- {
- bool r;
-
- if (::pthread_rwlock_trywrlock (&m_rwlock) == 0)
- {
- r = !m_running;
- m_running = true;
- ::pthread_rwlock_unlock (&m_rwlock);
- return r;
- }
- return false;
- }
-
- bool
- SetStopped ()
- {
- ::pthread_rwlock_wrlock (&m_rwlock);
- m_running = false;
- ::pthread_rwlock_unlock (&m_rwlock);
- return true;
- }
-
+ ProcessRunLock();
+ ~ProcessRunLock();
+ bool ReadTryLock ();
+ bool ReadUnlock ();
+ bool SetRunning ();
+ bool TrySetRunning ();
+ bool SetStopped ();
+public:
class ProcessRunLocker
{
public:
@@ -153,7 +92,7 @@ public:
};
protected:
- pthread_rwlock_t m_rwlock;
+ lldb::rwlock_t m_rwlock;
bool m_running;
private:
DISALLOW_COPY_AND_ASSIGN(ProcessRunLock);
diff --git a/lldb/include/lldb/Host/SocketAddress.h b/lldb/include/lldb/Host/SocketAddress.h
index e63b238c799..5e79e94fa9e 100644
--- a/lldb/include/lldb/Host/SocketAddress.h
+++ b/lldb/include/lldb/Host/SocketAddress.h
@@ -12,9 +12,18 @@
// C Includes
#include <stdint.h>
+
+#ifdef _WIN32
+#include "lldb/Host/windows/windows.h"
+#include <winsock2.h>
+#include <WS2tcpip.h>
+typedef ADDRESS_FAMILY sa_family_t;
+typedef USHORT in_port_t;
+#else
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
+#endif
#if defined(__FreeBSD__)
#include <sys/types.h>
diff --git a/lldb/include/lldb/Host/Terminal.h b/lldb/include/lldb/Host/Terminal.h
index b334717c796..5ea88c51563 100644
--- a/lldb/include/lldb/Host/Terminal.h
+++ b/lldb/include/lldb/Host/Terminal.h
@@ -12,6 +12,7 @@
#if defined(__cplusplus)
#include "lldb/lldb-private.h"
+#include "lldb/Host/Config.h"
struct termios;
@@ -173,7 +174,9 @@ protected:
//------------------------------------------------------------------
Terminal m_tty; ///< A terminal
int m_tflags; ///< Cached tflags information.
+#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
std::unique_ptr<struct termios> m_termios_ap; ///< Cached terminal state information.
+#endif
lldb::pid_t m_process_group;///< Cached process group information.
};
diff --git a/lldb/include/lldb/Host/mingw/Config.h b/lldb/include/lldb/Host/mingw/Config.h
index a0a0fdff3ce..cdf6f21e098 100644
--- a/lldb/include/lldb/Host/mingw/Config.h
+++ b/lldb/include/lldb/Host/mingw/Config.h
@@ -17,6 +17,8 @@
#ifndef liblldb_Platform_Config_h_
#define liblldb_Platform_Config_h_
+#define LLDB_DISABLE_POSIX
+
//#define LLDB_CONFIG_TERMIOS_SUPPORTED 1
//#define LLDB_CONFIG_TILDE_RESOLVES_TO_USER 1
diff --git a/lldb/include/lldb/Host/windows/win32.h b/lldb/include/lldb/Host/windows/win32.h
new file mode 100644
index 00000000000..3daa6bc0a13
--- /dev/null
+++ b/lldb/include/lldb/Host/windows/win32.h
@@ -0,0 +1,27 @@
+//===-- lldb-win32.h --------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_lldb_win32_h_
+#define LLDB_lldb_win32_h_
+
+#include <stdarg.h>
+
+// posix utilities
+int vasprintf(char **ret, const char *fmt, va_list ap);
+char * strcasestr(const char *s, const char* find);
+char* realpath(const char * name, char * resolved);
+
+#define PATH_MAX MAX_PATH
+
+#define O_NOCTTY 0
+#define SIGTRAP 5
+#define SIGKILL 9
+#define SIGSTOP 20
+
+#endif // LLDB_lldb_win32_h_
diff --git a/lldb/include/lldb/Host/windows/windows.h b/lldb/include/lldb/Host/windows/windows.h
new file mode 100644
index 00000000000..de6d9b8fc4d
--- /dev/null
+++ b/lldb/include/lldb/Host/windows/windows.h
@@ -0,0 +1,26 @@
+//===-- lldb-windows.h ------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_lldb_windows_h_
+#define LLDB_lldb_windows_h_
+
+#define NTDDI_VERSION NTDDI_VISTA
+#define _WIN32_WINNT _WIN32_WINNT_VISTA
+#define WIN32_LEAN_AND_MEAN
+#define NOGDI
+#define NOMINMAX
+#include <Windows.h>
+#undef GetUserName
+#undef LoadImage
+#undef CreateProcess
+#undef LoadImage
+#undef GetUserName
+#undef far
+
+#endif // LLDB_lldb_windows_h_
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index ef89a1eb141..a76228c1e17 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -10,9 +10,13 @@
#ifndef liblldb_Process_h_
#define liblldb_Process_h_
+#include "lldb/Host/Config.h"
+
// C Includes
#include <limits.h>
+#ifndef LLDB_DISABLE_POSIX
#include <spawn.h>
+#endif
// C++ Includes
#include <list>
@@ -475,11 +479,13 @@ public:
bool
Open (int fd, const char *path, bool read, bool write);
+#ifndef LLDB_DISABLE_POSIX
static bool
AddPosixSpawnFileAction (posix_spawn_file_actions_t *file_actions,
const FileAction *info,
Log *log,
Error& error);
+#endif
int
GetFD () const
@@ -3711,10 +3717,10 @@ protected:
void
ResumePrivateStateThread ();
- static void *
+ static lldb::thread_result_t
PrivateStateThread (void *arg);
- void *
+ lldb::thread_result_t
RunPrivateStateThread ();
void
diff --git a/lldb/include/lldb/lldb-private.h b/lldb/include/lldb/lldb-private.h
index 90590601d94..05b2c4fd638 100644
--- a/lldb/include/lldb/lldb-private.h
+++ b/lldb/include/lldb/lldb-private.h
@@ -12,6 +12,10 @@
#if defined(__cplusplus)
+#ifdef _WIN32
+#include "lldb/Host/windows/win32.h"
+#endif
+
#include "lldb/lldb-public.h"
#include "lldb/lldb-private-enumerations.h"
#include "lldb/lldb-private-interfaces.h"
diff --git a/lldb/include/lldb/lldb-types.h b/lldb/include/lldb/lldb-types.h
index 2693c0c822b..67c56003fef 100644
--- a/lldb/include/lldb/lldb-types.h
+++ b/lldb/include/lldb/lldb-types.h
@@ -14,11 +14,8 @@
#include "lldb/lldb-forward.h"
#include <assert.h>
-#include <pthread.h>
#include <signal.h>
#include <stdint.h>
-#include <stdbool.h>
-#include <unistd.h>
//----------------------------------------------------------------------
// All host systems must define:
@@ -38,13 +35,40 @@
// things should be defined. Currently MacOSX is being assumed by default
// since that is what lldb was first developed for.
+#ifdef _WIN32
+
+#include "lldb/Host/windows/windows.h"
+#include <process.h>
+
+namespace lldb
+{
+ typedef CRITICAL_SECTION mutex_t;
+ typedef CONDITION_VARIABLE condition_t;
+ typedef void* rwlock_t;
+ typedef uintptr_t thread_t; // Host thread type
+ typedef DWORD thread_key_t;
+ typedef void * thread_arg_t; // Host thread argument type
+ typedef unsigned thread_result_t; // Host thread result type
+ typedef thread_result_t (*thread_func_t)(void *); // Host thread function type
+ typedef void (*LogOutputCallback) (const char *, void *baton);
+ typedef bool (*CommandOverrideCallback)(void *baton, const char **argv);
+}
+
+#else
+
+#include <pthread.h>
+#include <stdbool.h>
+#include <unistd.h>
+
namespace lldb {
//----------------------------------------------------------------------
// MacOSX Types
//----------------------------------------------------------------------
typedef ::pthread_mutex_t mutex_t;
typedef pthread_cond_t condition_t;
+ typedef pthread_rwlock_t rwlock_t;
typedef pthread_t thread_t; // Host thread type
+ typedef pthread_key_t thread_key_t;
typedef void * thread_arg_t; // Host thread argument type
typedef void * thread_result_t; // Host thread result type
typedef void * (*thread_func_t)(void *); // Host thread function type
@@ -52,19 +76,11 @@ namespace lldb {
typedef bool (*CommandOverrideCallback)(void *baton, const char **argv);
} // namespace lldb
-#if defined(__MINGW32__)
-
-const lldb::thread_t lldb_invalid_host_thread_const = { NULL, 0 } ;
-#define LLDB_INVALID_HOST_THREAD (lldb_invalid_host_thread_const)
-#define IS_VALID_LLDB_HOST_THREAD(t) (!(NULL == (t).p && 0 == (t).x))
-
-#else
+#endif
#define LLDB_INVALID_HOST_THREAD ((lldb::thread_t)NULL)
#define IS_VALID_LLDB_HOST_THREAD(t) ((t) != LLDB_INVALID_HOST_THREAD)
-#endif
-
#define LLDB_INVALID_HOST_TIME { 0, 0 }
namespace lldb
diff --git a/lldb/lib/Makefile b/lldb/lib/Makefile
index eb527682392..30ed3340b6b 100644
--- a/lldb/lib/Makefile
+++ b/lldb/lib/Makefile
@@ -17,7 +17,9 @@ NO_BUILD_ARCHIVE = 1
LINK_LIBS_IN_SHARED = 1
SHARED_LIBRARY = 1
+ifeq (,$(findstring -DLLDB_DISABLE_PYTHON,$(CXXFLAGS)))
PYTHON_BUILD_FLAGS = $(shell python-config --ldflags)
+endif
# Include all archives in liblldb.so file
USEDLIBS = lldbAPI.a \
@@ -72,7 +74,7 @@ USEDLIBS = lldbAPI.a \
# Because GCC requires RTTI enabled for lldbCore (see source/Core/Makefile) it is
# necessary to also link the clang rewriter libraries so vtable references can
# be resolved correctly, if we are building with GCC.
-ifeq (g++,$(shell basename $(CXX) | colrm 4))
+ifeq (g++,$(shell basename $(CXX) | cut -c 1-4))
USEDLIBS += clangRewriteCore.a \
clangRewriteFrontend.a
endif
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index f5e71d5f1a0..4ff0999730b 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -480,7 +480,7 @@ SBDebugger::GetScriptingLanguage (const char *script_language_name)
const char *
SBDebugger::GetVersionString ()
{
- return GetVersion();
+ return lldb_private::GetVersion();
}
const char *
diff --git a/lldb/source/API/SBHostOS.cpp b/lldb/source/API/SBHostOS.cpp
index a8f7db90a15..166403103ad 100644
--- a/lldb/source/API/SBHostOS.cpp
+++ b/lldb/source/API/SBHostOS.cpp
@@ -42,7 +42,7 @@ lldb::thread_t
SBHostOS::ThreadCreate
(
const char *name,
- void *(*thread_function)(void *),
+ thread_func_t thread_function,
void *thread_arg,
SBError *error_ptr
)
@@ -77,7 +77,7 @@ SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr)
}
bool
-SBHostOS::ThreadJoin (lldb::thread_t thread, void **result, SBError *error_ptr)
+SBHostOS::ThreadJoin (lldb::thread_t thread, thread_result_t *result, SBError *error_ptr)
{
return Host::ThreadJoin (thread, result, error_ptr ? error_ptr->get() : NULL);
}
diff --git a/lldb/source/CMakeLists.txt b/lldb/source/CMakeLists.txt
index 57543e06c0f..eddd8cb095a 100644
--- a/lldb/source/CMakeLists.txt
+++ b/lldb/source/CMakeLists.txt
@@ -78,9 +78,9 @@ set( LLDB_USED_LIBS
# Windows-only libraries
if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
list(APPEND LLDB_USED_LIBS
- #lldbHostWindows
+ lldbHostWindows
#lldbPluginPlatformWindows
- #Ws2_32
+ Ws2_32
)
endif ()
@@ -137,10 +137,12 @@ set( CLANG_USED_LIBS
clangSerialization
)
-set( LLDB_SYSTEM_LIBS
- edit
- python2.7
- )
+if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
+ set( LLDB_SYSTEM_LIBS
+ edit
+ python2.7
+ )
+endif()
set( LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
@@ -164,10 +166,14 @@ set( LLVM_LINK_COMPONENTS
set_source_files_properties(${LLDB_BINARY_DIR}/scripts/LLDBWrapPython.cpp PROPERTIES GENERATED 1)
set(SHARED_LIBRARY 1)
+if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
+ set(LLDB_WRAP_PYTHON ${LLDB_BINARY_DIR}/scripts/LLDBWrapPython.cpp)
+endif()
+
add_lldb_library(liblldb
lldb.cpp
lldb-log.cpp
- ${LLDB_BINARY_DIR}/scripts/LLDBWrapPython.cpp
+ ${LLDB_WRAP_PYTHON}
${LLDB_VERS_GENERATED_FILE}
)
set_target_properties(liblldb
@@ -175,10 +181,12 @@ set_target_properties(liblldb
OUTPUT_NAME lldb
VERSION ${LLDB_VERSION}
)
-add_dependencies(liblldb
- ${LLDB_BINARY_DIR}/scripts/LLDBWrapPython.cpp
- ${LLDB_VERS_GENERATED_FILE}
- )
+if (LLDB_WRAP_PYTHON OR LLDB_VERS_GENERATED_FILE)
+ add_dependencies(liblldb
+ ${LLDB_WRAP_PYTHON}
+ ${LLDB_VERS_GENERATED_FILE}
+ )
+endif()
target_link_libraries(liblldb ${LLDB_SYSTEM_LIBS})
# Determine LLDB revision and repository. GetSourceVersion and GetRepositoryPath are shell-scripts, and as
@@ -209,4 +217,5 @@ endif ()
install(TARGETS liblldb
+ RUNTIME DESTINATION bin
LIBRARY DESTINATION lib)
diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp
index a9d2f21b9ba..138fdfe5744 100644
--- a/lldb/source/Commands/CommandCompletions.cpp
+++ b/lldb/source/Commands/CommandCompletions.cpp
@@ -11,7 +11,6 @@
// C Includes
#include <sys/stat.h>
-#include <dirent.h>
#if defined(__APPLE__) || defined(__linux__)
#include <pwd.h>
#endif
@@ -121,6 +120,72 @@ CommandCompletions::SourceFiles
return matches.GetSize();
}
+typedef struct DiskFilesOrDirectoriesBaton
+{
+ const char *remainder;
+ char *partial_name_copy;
+ bool only_directories;
+ bool *saw_directory;
+ StringList *matches;
+ char *end_ptr;
+ size_t baselen;
+};
+
+FileSpec::EnumerateDirectoryResult DiskFilesOrDirectoriesCallback(void *baton, FileSpec::FileType file_type, const FileSpec &spec)
+{
+ const char *name = spec.GetFilename().AsCString();
+
+ const DiskFilesOrDirectoriesBaton *parameters = (DiskFilesOrDirectoriesBaton*)baton;
+ char *end_ptr = parameters->end_ptr;
+ char *partial_name_copy = parameters->partial_name_copy;
+ size_t baselen = end_ptr - partial_name_copy;
+ const char *remainder = parameters->remainder;
+
+ // Omit ".", ".." and any . files if the match string doesn't start with .
+ if (name[0] == '.')
+ {
+ if (name[1] == '\0')
+ return FileSpec::eEnumerateDirectoryResultNext;
+ else if (name[1] == '.' && name[2] == '\0')
+ return FileSpec::eEnumerateDirectoryResultNext;
+ else if (remainder[0] != '.')
+ return FileSpec::eEnumerateDirectoryResultNext;
+ }
+
+ // If we found a directory, we put a "/" at the end of the name.
+
+ if (remainder[0] == '\0' || strstr(name, remainder) == name)
+ {
+ if (strlen(name) + parameters->baselen >= PATH_MAX)
+ return FileSpec::eEnumerateDirectoryResultNext;
+
+ strcpy(end_ptr, name);
+
+ bool isa_directory = false;
+ if (file_type == FileSpec::eFileTypeDirectory)
+ isa_directory = true;
+ else if (file_type == FileSpec::eFileTypeSymbolicLink)
+ {
+ struct stat stat_buf;
+ if ((stat(partial_name_copy, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
+ isa_directory = true;
+ }
+
+ if (isa_directory)
+ {
+ *parameters->saw_directory = true;
+ size_t len = strlen(parameters->partial_name_copy);
+ partial_name_copy[len] = '/';
+ partial_name_copy[len + 1] = '\0';
+ }
+ if (parameters->only_directories && !isa_directory)
+ return FileSpec::eEnumerateDirectoryResultNext;
+ parameters->matches->AppendString(partial_name_copy);
+ }
+
+ return FileSpec::eEnumerateDirectoryResultNext;
+}
+
static int
DiskFilesOrDirectories
(
@@ -239,60 +304,18 @@ DiskFilesOrDirectories
// Okay, containing_part is now the directory we want to open and look for files:
- lldb_utility::CleanUp <DIR *, int> dir_stream (opendir(containing_part), NULL, closedir);
- if (!dir_stream.is_valid())
- return matches.GetSize();
-
- struct dirent *dirent_buf;
-
size_t baselen = end_ptr - partial_name_copy;
- while ((dirent_buf = readdir(dir_stream.get())) != NULL)
- {
- char *name = dirent_buf->d_name;
-
- // Omit ".", ".." and any . files if the match string doesn't start with .
- if (name[0] == '.')
- {
- if (name[1] == '\0')
- continue;
- else if (name[1] == '.' && name[2] == '\0')
- continue;
- else if (remainder[0] != '.')
- continue;
- }
-
- // If we found a directory, we put a "/" at the end of the name.
-
- if (remainder[0] == '\0' || strstr(dirent_buf->d_name, remainder) == name)
- {
- if (strlen(name) + baselen >= PATH_MAX)
- continue;
-
- strcpy(end_ptr, name);
-
- bool isa_directory = false;
- if (dirent_buf->d_type & DT_DIR)
- isa_directory = true;
- else if (dirent_buf->d_type & DT_LNK)
- {
- struct stat stat_buf;
- if ((stat(partial_name_copy, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
- isa_directory = true;
- }
-
- if (isa_directory)
- {
- saw_directory = true;
- size_t len = strlen(partial_name_copy);
- partial_name_copy[len] = '/';
- partial_name_copy[len + 1] = '\0';
- }
- if (only_directories && !isa_directory)
- continue;
- matches.AppendString(partial_name_copy);
- }
- }
+ DiskFilesOrDirectoriesBaton parameters;
+ parameters.remainder = remainder;
+ parameters.partial_name_copy = partial_name_copy;
+ parameters.only_directories = only_directories;
+ parameters.saw_directory = &saw_directory;
+ parameters.matches = &matches;
+ parameters.end_ptr = end_ptr;
+ parameters.baselen = baselen;
+
+ FileSpec::EnumerateDirectory(containing_part, true, true, true, DiskFilesOrDirectoriesCallback, &parameters);
return matches.GetSize();
}
diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt
index 3b8f8641b00..f2946ce1be1 100644
--- a/lldb/source/Core/CMakeLists.txt
+++ b/lldb/source/Core/CMakeLists.txt
@@ -71,6 +71,5 @@ add_lldb_library(lldbCore
ValueObjectSyntheticFilter.cpp
ValueObjectVariable.cpp
VMRange.cpp
- #Windows.cpp
)
diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp
index 7f40e652020..6ea7a11426b 100644
--- a/lldb/source/Core/Communication.cpp
+++ b/lldb/source/Core/Communication.cpp
@@ -333,8 +333,8 @@ Communication::ReadThreadIsRunning ()
return m_read_thread_enabled;
}
-void *
-Communication::ReadThread (void *p)
+lldb::thread_result_t
+Communication::ReadThread (lldb::thread_arg_t p)
{
Communication *comm = (Communication *)p;
diff --git a/lldb/source/Core/ConnectionFileDescriptor.cpp b/lldb/source/Core/ConnectionFileDescriptor.cpp
index e320bda2fcd..77645d2194c 100644
--- a/lldb/source/Core/ConnectionFileDescriptor.cpp
+++ b/lldb/source/Core/ConnectionFileDescriptor.cpp
@@ -15,10 +15,15 @@
#endif
#include "lldb/Core/ConnectionFileDescriptor.h"
+#include "lldb/Host/Config.h"
// C Includes
#include <errno.h>
#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#ifndef LLDB_DISABLE_POSIX
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
@@ -26,10 +31,8 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <termios.h>
-#include <sys/types.h>
-#include <string.h>
-#include <stdlib.h>
#include <unistd.h>
+#endif
// C++ Includes
// Other libraries and framework includes
@@ -135,7 +138,11 @@ ConnectionFileDescriptor::OpenCommandPipe ()
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION));
// Make the command file descriptor here:
int filedes[2];
+#ifndef LLDB_DISABLE_POSIX
int result = pipe (filedes);
+#else
+ int result = -1;
+#endif
if (result != 0)
{
if (log)
@@ -223,7 +230,11 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr)
// get the flags from the file descriptor and making sure it
// isn't a bad fd.
errno = 0;
+#ifndef LLDB_DISABLE_POSIX
int flags = ::fcntl (m_fd_send, F_GETFL, 0);
+#else
+ int flags = -1;
+#endif
if (flags == -1 || errno == EBADF)
{
if (error_ptr)
@@ -262,6 +273,7 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr)
{
// file:///PATH
const char *path = s + strlen("file://");
+#ifndef LLDB_DISABLE_POSIX
do
{
m_fd_send = m_fd_recv = ::open (path, O_RDWR);
@@ -304,6 +316,9 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr)
}
m_should_close_fd = true;
return eConnectionStatusSuccess;
+#else
+ return eConnectionStatusError;
+#endif
}
if (error_ptr)
error_ptr->SetErrorStringWithFormat ("unsupported connection URL: '%s'", s);
@@ -420,7 +435,21 @@ ConnectionFileDescriptor::Read (void *dst,
{
do
{
+#ifndef LLDB_DISABLE_POSIX
bytes_read = ::read (m_fd_recv, dst, dst_len);
+#else
+ switch (m_fd_send_type) {
+ case eFDTypeSocket:
+ case eFDTypeSocketUDP:
+ bytes_read = ::recv (m_fd_recv, (char*)dst, dst_len, 0);
+ break;
+ default:
+ bytes_read = -1;
+ break;
+
+ }
+
+#endif
} while (bytes_read < 0 && errno == EINTR);
}
@@ -523,17 +552,18 @@ ConnectionFileDescriptor::Write (const void *src, size_t src_len, ConnectionStat
switch (m_fd_send_type)
{
+#ifndef LLDB_DISABLE_POSIX
case eFDTypeFile: // Other FD requireing read/write
do
{
bytes_sent = ::write (m_fd_send, src, src_len);
} while (bytes_sent < 0 && errno == EINTR);
break;
-
+#endif
case eFDTypeSocket: // Socket requiring send/recv
do
{
- bytes_sent = ::send (m_fd_send, src, src_len, 0);
+ bytes_sent = ::send (m_fd_send, (char*)src, src_len, 0);
} while (bytes_sent < 0 && errno == EINTR);
break;
@@ -542,7 +572,7 @@ ConnectionFileDescriptor::Write (const void *src, size_t src_len, ConnectionStat
do
{
bytes_sent = ::sendto (m_fd_send,
- src,
+ (char*)src,
src_len,
0,
m_udp_send_sockaddr,
@@ -1115,6 +1145,7 @@ ConnectionFileDescriptor::Close (int& fd, Error *error_ptr)
ConnectionStatus
ConnectionFileDescriptor::NamedSocketAccept (const char *socket_name, Error *error_ptr)
{
+#ifndef LLDB_DISABLE_POSIX
ConnectionStatus result = eConnectionStatusError;
struct sockaddr_un saddr_un;
@@ -1159,11 +1190,15 @@ ConnectionFileDescriptor::NamedSocketAccept (const char *socket_name, Error *err
// We are done with the listen port
Close (listen_socket, NULL);
return result;
+#else
+ return eConnectionStatusError;
+#endif
}
ConnectionStatus
ConnectionFileDescriptor::NamedSocketConnect (const char *socket_name, Error *error_ptr)
{
+#ifndef LLDB_DISABLE_POSIX
Disconnect (NULL);
m_fd_send_type = m_fd_recv_type = eFDTypeSocket;
@@ -1194,6 +1229,9 @@ ConnectionFileDescriptor::NamedSocketConnect (const char *socket_name, Error *er
if (error_ptr)
error_ptr->Clear();
return eConnectionStatusSuccess;
+#else
+ return eConnectionStatusError;
+#endif
}
ConnectionStatus
@@ -1430,18 +1468,18 @@ ConnectionFileDescriptor::ConnectUDP (const char *host_and_port, Error *error_pt
return eConnectionStatusSuccess;
}
-#if defined(__MINGW32__) || defined(__MINGW64__)
+#if defined(_WIN32)
typedef const char * set_socket_option_arg_type;
typedef char * get_socket_option_arg_type;
-#else // #if defined(__MINGW32__) || defined(__MINGW64__)
+#else // #if defined(_WIN32)
typedef const void * set_socket_option_arg_type;
typedef void * get_socket_option_arg_type;
-#endif // #if defined(__MINGW32__) || defined(__MINGW64__)
+#endif // #if defined(_WIN32)
int
ConnectionFileDescriptor::GetSocketOption(int fd, int level, int option_name, int &option_value)
{
- get_socket_option_arg_type option_value_p = static_cast<get_socket_option_arg_type>(&option_value);
+ get_socket_option_arg_type option_value_p = reinterpret_cast<get_socket_option_arg_type>(&option_value);
socklen_t option_value_size = sizeof(int);
return ::getsockopt(fd, level, option_name, option_value_p, &option_value_size);
}
@@ -1449,7 +1487,7 @@ ConnectionFileDescriptor::GetSocketOption(int fd, int level, int option_name, in
int
ConnectionFileDescriptor::SetSocketOption(int fd, int level, int option_name, int option_value)
{
- set_socket_option_arg_type option_value_p = static_cast<get_socket_option_arg_type>(&option_value);
+ set_socket_option_arg_type option_value_p = reinterpret_cast<get_socket_option_arg_type>(&option_value);
return ::setsockopt(fd, level, option_name, option_value_p, sizeof(option_value));
}
@@ -1487,7 +1525,7 @@ ConnectionFileDescriptor::SetSocketReceiveTimeout (uint32_t timeout_usec)
timeout.tv_sec = timeout_usec / TimeValue::MicroSecPerSec;
timeout.tv_usec = timeout_usec % TimeValue::MicroSecPerSec;
}
- if (::setsockopt (m_fd_recv, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == 0)
+ if (::setsockopt (m_fd_recv, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<get_socket_option_arg_type>(&timeout), sizeof(timeout)) == 0)
{
m_socket_timeout_usec = timeout_usec;
return true;
diff --git a/lldb/source/Core/ConnectionSharedMemory.cpp b/lldb/source/Core/ConnectionSharedMemory.cpp
index 625f17a0985..cd708c4868c 100644
--- a/lldb/source/Core/ConnectionSharedMemory.cpp
+++ b/lldb/source/Core/ConnectionSharedMemory.cpp
@@ -11,12 +11,15 @@
// C Includes
#include <errno.h>
-#include <pthread.h>
#include <stdlib.h>
+#ifdef _WIN32
+#include "lldb/Host/windows/windows.h"
+#else
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
+#endif
// C++ Includes
// Other libraries and framework includes
@@ -73,7 +76,12 @@ ConnectionSharedMemory::Disconnect (Error *error_ptr)
m_mmap.Clear();
if (!m_name.empty())
{
+#ifdef _WIN32
+ close(m_fd);
+ m_fd = -1;
+#else
shm_unlink (m_name.c_str());
+#endif
m_name.clear();
}
return eConnectionStatusSuccess;
@@ -114,6 +122,16 @@ ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error
}
m_name.assign (name);
+
+#ifdef _WIN32
+ HANDLE handle;
+ if (create)
+ handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, (DWORD)(size >> 32), (DWORD)(size), name);
+ else
+ handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name);
+
+ m_fd = _open_osfhandle((intptr_t)handle, 0);
+#else
int oflag = O_RDWR;
if (create)
oflag |= O_CREAT;
@@ -121,6 +139,7 @@ ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error
if (create)
::ftruncate (m_fd, size);
+#endif
if (m_mmap.MemoryMapFromFileDescriptor(m_fd, 0, size, true, false) == size)
return eConnectionStatusSuccess;
diff --git a/lldb/source/Core/DataBufferMemoryMap.cpp b/lldb/source/Core/DataBufferMemoryMap.cpp
index a4382a0c67e..374834a00e0 100644
--- a/lldb/source/Core/DataBufferMemoryMap.cpp
+++ b/lldb/source/Core/DataBufferMemoryMap.cpp
@@ -12,7 +12,11 @@
#include <fcntl.h>
#include <limits.h>
#include <sys/stat.h>
+#ifdef _WIN32
+#include "lldb/Host/windows/windows.h"
+#else
#include <sys/mman.h>
+#endif
#include "lldb/Core/DataBufferMemoryMap.h"
#include "lldb/Core/Error.h"
@@ -86,7 +90,11 @@ DataBufferMemoryMap::Clear()
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_MMAP));
if (log)
log->Printf("DataBufferMemoryMap::Clear() m_mmap_addr = %p, m_mmap_size = %zu", m_mmap_addr, m_mmap_size);
+#ifdef _WIN32
+ UnmapViewOfFile(m_mmap_addr);
+#else
::munmap((void *)m_mmap_addr, m_mmap_size);
+#endif
m_mmap_addr = NULL;
m_mmap_size = 0;
m_data = NULL;
@@ -166,13 +174,49 @@ DataBufferMemoryMap::MemoryMapFromFileDescriptor (int fd,
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_MMAP|LIBLLDB_LOG_VERBOSE));
if (log)
{
+#ifdef _WIN32
+ log->Printf("DataBufferMemoryMap::MemoryMapFromFileSpec(fd=%p, offset=0x%" PRIx64 ", length=0x%" PRIx64 ", writeable=%i, fd_is_file=%i)",
+#else
log->Printf("DataBufferMemoryMap::MemoryMapFromFileSpec(fd=%i, offset=0x%" PRIx64 ", length=0x%" PRIx64 ", writeable=%i, fd_is_file=%i)",
+#endif
fd,
offset,
length,
writeable,
fd_is_file);
}
+#ifdef _WIN32
+ HANDLE handle = (HANDLE)_get_osfhandle(fd);
+ DWORD file_size_low, file_size_high;
+ file_size_low = GetFileSize(handle, &file_size_high);
+ const size_t file_size = (file_size_high << 32) | file_size_low;
+ const size_t max_bytes_available = file_size - offset;
+ if (length == SIZE_MAX)
+ {
+ length = max_bytes_available;
+ }
+ else if (length > max_bytes_available)
+ {
+ // Cap the length if too much data was requested
+ length = max_bytes_available;
+ }
+
+ if (length > 0)
+ {
+ HANDLE fileMapping = CreateFileMapping(handle, NULL, writeable ? PAGE_READWRITE : PAGE_READONLY, file_size_high, file_size_low, NULL);
+ if (fileMapping != NULL)
+ {
+ m_mmap_addr = (uint8_t*)MapViewOfFile(fileMapping, writeable ? FILE_MAP_ALL_ACCESS : FILE_MAP_READ, (DWORD)(offset >> 32), (DWORD)(offset), length);
+ if (m_mmap_addr != NULL)
+ {
+ m_mmap_size = length;
+ m_data = m_mmap_addr;
+ m_size = length;
+ }
+ CloseHandle(fileMapping);
+ }
+ }
+#else
struct stat stat;
if (::fstat(fd, &stat) == 0)
{
@@ -253,6 +297,7 @@ DataBufferMemoryMap::MemoryMapFromFileDescriptor (int fd,
}
}
}
+#endif
}
return GetByteSize ();
}
diff --git a/lldb/source/Core/Log.cpp b/lldb/source/Core/Log.cpp
index d73ab15f697..9200fe13892 100644
--- a/lldb/source/Core/Log.cpp
+++ b/lldb/source/Core/Log.cpp
@@ -10,7 +10,6 @@
#include "lldb/lldb-python.h"
// C Includes
-#include <pthread.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
diff --git a/lldb/source/Core/Timer.cpp b/lldb/source/Core/Timer.cpp
index b1416bdaf62..bbd990056ba 100644
--- a/lldb/source/Core/Timer.cpp
+++ b/lldb/source/Core/Timer.cpp
@@ -14,6 +14,7 @@
#include "lldb/Core/Stream.h"
#include "lldb/Host/Mutex.h"
+#include "lldb/Host/Host.h"
#include <stdio.h>
@@ -26,7 +27,7 @@ uint32_t Timer::g_display_depth = 0;
FILE * Timer::g_file = NULL;
typedef std::vector<Timer *> TimerStack;
typedef std::map<const char *, uint64_t> TimerCategoryMap;
-static pthread_key_t g_key;
+static lldb::thread_key_t g_key;
static Mutex &
GetCategoryMutex()
@@ -46,11 +47,11 @@ GetCategoryMap()
static TimerStack *
GetTimerStackForCurrentThread ()
{
- void *timer_stack = ::pthread_getspecific (g_key);
+ void *timer_stack = Host::ThreadLocalStorageGet(g_key);
if (timer_stack == NULL)
{
- ::pthread_setspecific (g_key, new TimerStack);
- timer_stack = ::pthread_getspecific (g_key);
+ Host::ThreadLocalStorageSet(g_key, new TimerStack);
+ timer_stack = Host::ThreadLocalStorageGet(g_key);
}
return (TimerStack *)timer_stack;
}
@@ -71,8 +72,7 @@ void
Timer::Initialize ()
{
Timer::g_file = stdout;
- ::pthread_key_create (&g_key, ThreadSpecificCleanup);
-
+ g_key = Host::ThreadLocalStorageCreate(ThreadSpecificCleanup);
}
Timer::Timer (const char *category, const char *format, ...) :
diff --git a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp
index fba92170d83..43a935c35cc 100644
--- a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp
+++ b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp
@@ -1237,6 +1237,7 @@ lldb_private::formatters::GetOSXEpoch ()
static time_t epoch = 0;
if (!epoch)
{
+#ifndef _WIN32
tzset();
tm tm_epoch;
tm_epoch.tm_sec = 0;
@@ -1249,6 +1250,7 @@ lldb_private::formatters::GetOSXEpoch ()
tm_epoch.tm_gmtoff = 0;
tm_epoch.tm_zone = NULL;
epoch = timegm(&tm_epoch);
+#endif
}
return epoch;
}
diff --git a/lldb/source/Expression/IRMemoryMap.cpp b/lldb/source/Expression/IRMemoryMap.cpp
index ef362baff16..53f74aebfed 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -74,15 +74,15 @@ IRMemoryMap::FindSpace (size_t size)
{
case 4:
{
- uint32_t random_data = random();
+ uint32_t random_data = rand();
candidate = random_data;
candidate &= ~0xfffull;
break;
}
case 8:
{
- uint32_t random_low = random();
- uint32_t random_high = random();
+ uint32_t random_low = rand();
+ uint32_t random_high = rand();
candidate = random_high;
candidate <<= 32ull;
candidate |= random_low;
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index d990f3f6f62..6c92a6cde26 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -6,6 +6,6 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
add_subdirectory(linux)
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
add_subdirectory(freebsd)
-#elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
-# add_subdirectory(windows)
+elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
+ add_subdirectory(windows)
endif()
diff --git a/lldb/source/Host/Makefile b/lldb/source/Host/Makefile
index 72155ce576b..0a4e8ac85c3 100644
--- a/lldb/source/Host/Makefile
+++ b/lldb/source/Host/Makefile
@@ -25,4 +25,8 @@ ifneq (,$(filter $(HOST_OS), FreeBSD GNU/kFreeBSD))
DIRS += freebsd
endif
+ifeq ($(HOST_OS),MingW)
+DIRS += windows
+endif
+
include $(LLDB_LEVEL)/Makefile
diff --git a/lldb/source/Host/common/CMakeLists.txt b/lldb/source/Host/common/CMakeLists.txt
index cad9c074e5f..d079d4afd1d 100644
--- a/lldb/source/Host/common/CMakeLists.txt
+++ b/lldb/source/Host/common/CMakeLists.txt
@@ -7,6 +7,7 @@ add_lldb_library(lldbHostCommon
FileSpec.cpp
Host.cpp
Mutex.cpp
+ ProcessRunLock.cpp
SocketAddress.cpp
Symbols.cpp
Terminal.cpp
diff --git a/lldb/source/Host/common/Condition.cpp b/lldb/source/Host/common/Condition.cpp
index daa729cadca..7bc6b655464 100644
--- a/lldb/source/Host/common/Condition.cpp
+++ b/lldb/source/Host/common/Condition.cpp
@@ -15,6 +15,8 @@
using namespace lldb_private;
+#ifndef _WIN32
+
//----------------------------------------------------------------------
// Default constructor
//
@@ -47,15 +49,6 @@ Condition::Broadcast ()
}
//----------------------------------------------------------------------
-// Get accessor to the pthread condition object
-//----------------------------------------------------------------------
-pthread_cond_t *
-Condition::GetCondition ()
-{
- return &m_condition;
-}
-
-//----------------------------------------------------------------------
// Unblocks one thread waiting for the condition variable
//----------------------------------------------------------------------
int
@@ -64,6 +57,11 @@ Condition::Signal ()
return ::pthread_cond_signal (&m_condition);
}
+/* convert struct timeval to ms(milliseconds) */
+static unsigned long int tv2ms(struct timeval a) {
+ return ((a.tv_sec * 1000) + (a.tv_usec / 1000));
+}
+
//----------------------------------------------------------------------
// The Wait() function atomically blocks the current thread
// waiting on the owned condition variable, and unblocks the mutex
@@ -100,7 +98,16 @@ Condition::Wait (Mutex &mutex, const TimeValue *abstime, bool *timed_out)
*timed_out = false;
}
-
return err;
}
+#endif
+
+//----------------------------------------------------------------------
+// Get accessor to the pthread condition object
+//----------------------------------------------------------------------
+lldb::condition_t *
+Condition::GetCondition()
+{
+ return &m_condition;
+}
diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp
index c0d3c290f4c..343312fb484 100644
--- a/lldb/source/Host/common/File.cpp
+++ b/lldb/source/Host/common/File.cpp
@@ -16,6 +16,10 @@
#include <stdarg.h>
#include <sys/stat.h>
+#ifdef _WIN32
+#include "lldb/Host/windows/windows.h"
+#endif
+
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/Error.h"
#include "lldb/Host/Config.h"
@@ -167,7 +171,11 @@ File::Duplicate (const File &rhs)
if (rhs.DescriptorIsValid())
{
+#ifdef _WIN32
+ m_descriptor = ::_dup(rhs.GetDescriptor());
+#else
m_descriptor = ::fcntl(rhs.GetDescriptor(), F_DUPFD);
+#endif
if (!DescriptorIsValid())
error.SetErrorToErrno();
else
@@ -217,8 +225,12 @@ File::Open (const char *path, uint32_t options, uint32_t permissions)
oflag |= O_RDONLY;
}
+#ifndef _WIN32
if (options & eOpenOptionNonBlocking)
oflag |= O_NONBLOCK;
+#else
+ oflag |= O_BINARY;
+#endif
mode_t mode = 0;
if (oflag & O_CREAT)
@@ -226,12 +238,14 @@ File::Open (const char *path, uint32_t options, uint32_t permissions)
if (permissions & ePermissionsUserRead) mode |= S_IRUSR;
if (permissions & ePermissionsUserWrite) mode |= S_IWUSR;
if (permissions & ePermissionsUserExecute) mode |= S_IXUSR;
+#ifndef _WIN32
if (permissions & ePermissionsGroupRead) mode |= S_IRGRP;
if (permissions & ePermissionsGroupWrite) mode |= S_IWGRP;
if (permissions & ePermissionsGroupExecute) mode |= S_IXGRP;
if (permissions & ePermissionsWorldRead) mode |= S_IROTH;
if (permissions & ePermissionsWorldWrite) mode |= S_IWOTH;
if (permissions & ePermissionsWorldExecute) mode |= S_IXOTH;
+#endif
}
do
@@ -452,6 +466,11 @@ File::Sync ()
Error error;
if (DescriptorIsValid())
{
+#ifdef _WIN32
+ int err = FlushFileBuffers((HANDLE)_get_osfhandle(m_descriptor));
+ if (err == 0)
+ error.SetErrorToGenericError();
+#else
int err = 0;
do
{
@@ -460,6 +479,7 @@ File::Sync ()
if (err == -1)
error.SetErrorToErrno();
+#endif
}
else
{
@@ -559,6 +579,7 @@ File::Write (const void *buf, size_t &num_bytes)
Error
File::Read (void *buf, size_t &num_bytes, off_t &offset)
{
+#ifndef _WIN32
Error error;
int fd = GetDescriptor();
if (fd != kInvalidDescriptor)
@@ -586,6 +607,14 @@ File::Read (void *buf, size_t &num_bytes, off_t &offset)
error.SetErrorString("invalid file handle");
}
return error;
+#else
+ long cur = ::lseek(m_descriptor, 0, SEEK_CUR);
+ SeekFromStart(offset);
+ Error error = Read(buf, num_bytes);
+ if (!error.Fail())
+ SeekFromStart(cur);
+ return error;
+#endif
}
Error
@@ -648,6 +677,7 @@ File::Write (const void *buf, size_t &num_bytes, off_t &offset)
int fd = GetDescriptor();
if (fd != kInvalidDescriptor)
{
+#ifndef _WIN32
ssize_t bytes_written = -1;
do
{
@@ -664,6 +694,17 @@ File::Write (const void *buf, size_t &num_bytes, off_t &offset)
offset += bytes_written;
num_bytes = bytes_written;
}
+#else
+ long cur = ::lseek(m_descriptor, 0, SEEK_CUR);
+ error = Write(buf, num_bytes);
+ long after = ::lseek(m_descriptor, 0, SEEK_CUR);
+
+ if (!error.Fail())
+ SeekFromStart(cur);
+
+ ssize_t bytes_written = after - cur;
+ offset = after;
+#endif
}
else
{
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp
index 08d626e836a..0bf7681aa48 100644
--- a/lldb/source/Host/common/FileSpec.cpp
+++ b/lldb/source/Host/common/FileSpec.cpp
@@ -8,7 +8,11 @@
//===----------------------------------------------------------------------===//
+#ifndef _WIN32
#include <dirent.h>
+#else
+#include "lldb/Host/windows/windows.h"
+#endif
#include <fcntl.h>
#include <libgen.h>
#include <sys/stat.h>
@@ -616,10 +620,12 @@ FileSpec::GetFileType () const
switch (file_type)
{
case S_IFDIR: return eFileTypeDirectory;
- case S_IFIFO: return eFileTypePipe;
case S_IFREG: return eFileTypeRegular;
+#ifndef _WIN32
+ case S_IFIFO: return eFileTypePipe;
case S_IFSOCK: return eFileTypeSocket;
case S_IFLNK: return eFileTypeSymbolicLink;
+#endif
default:
break;
}
@@ -907,7 +913,94 @@ FileSpec::EnumerateDirectory
{
if (dir_path && dir_path[0])
{
- lldb_utility::CleanUp <DIR *, int> dir_path_dir (opendir(dir_path), NULL, closedir);
+#if _WIN32
+ char szDir[MAX_PATH];
+ strcpy_s(szDir, MAX_PATH, dir_path);
+ strcat_s(szDir, MAX_PATH, "\\*");
+
+ WIN32_FIND_DATA ffd;
+ HANDLE hFind = FindFirstFile(szDir, &ffd);
+
+ if (hFind == INVALID_HANDLE_VALUE)
+ {
+ return eEnumerateDirectoryResultNext;
+ }
+
+ do
+ {
+ bool call_callback = false;
+ FileSpec::FileType file_type = eFileTypeUnknown;
+ if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ size_t len = strlen(ffd.cFileName);
+
+ if (len == 1 && ffd.cFileName[0] == '.')
+ continue;
+
+ if (len == 2 && ffd.cFileName[0] == '.' && ffd.cFileName[1] == '.')
+ continue;
+
+ file_type = eFileTypeDirectory;
+ call_callback = find_directories;
+ }
+ else if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DEVICE)
+ {
+ file_type = eFileTypeOther;
+ call_callback = find_other;
+ }
+ else
+ {
+ file_type = eFileTypeRegular;
+ call_callback = find_files;
+ }
+ if (call_callback)
+ {
+ char child_path[MAX_PATH];
+ const int child_path_len = ::snprintf (child_path, sizeof(child_path), "%s\\%s", dir_path, ffd.cFileName);
+ if (child_path_len < (int)(sizeof(child_path) - 1))
+ {
+ // Don't resolve the file type or path
+ FileSpec child_path_spec (child_path, false);
+
+ EnumerateDirectoryResult result = callback (callback_baton, file_type, child_path_spec);
+
+ switch (result)
+ {
+ case eEnumerateDirectoryResultNext:
+ // Enumerate next entry in the current directory. We just
+ // exit this switch and will continue enumerating the
+ // current directory as we currently are...
+ break;
+
+ case eEnumerateDirectoryResultEnter: // Recurse into the current entry if it is a directory or symlink, or next if not
+ if (FileSpec::EnumerateDirectory(child_path,
+ find_directories,
+ find_files,
+ find_other,
+ callback,
+ callback_baton) == eEnumerateDirectoryResultQuit)
+ {
+ // The subdirectory returned Quit, which means to
+ // stop all directory enumerations at all levels.
+ return eEnumerateDirectoryResultQuit;
+ }
+ break;
+
+ case eEnumerateDirectoryResultExit: // Exit from the current directory at the current level.
+ // Exit from this directory level and tell parent to
+ // keep enumerating.
+ return eEnumerateDirectoryResultNext;
+
+ case eEnumerateDirectoryResultQuit: // Stop directory enumerations at any level
+ return eEnumerateDirectoryResultQuit;
+ }
+ }
+ }
+ } while (FindNextFile(hFind, &ffd) != 0);
+
+ FindClose(hFind);
+#else
+ lldb_utility::CleanUp <DIR *, int> dir_path_dir(opendir(dir_path), NULL, closedir);
if (dir_path_dir.is_valid())
{
long path_max = fpathconf (dirfd (dir_path_dir.get()), _PC_NAME_MAX);
@@ -1006,6 +1099,7 @@ FileSpec::EnumerateDirectory
free (buf);
}
}
+#endif
}
// By default when exiting a directory, we tell the parent enumeration
// to continue enumerating.
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index a7bad0063ef..826069b358c 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -10,15 +10,21 @@
#include "lldb/lldb-python.h"
// C includes
-#include <dlfcn.h>
#include <errno.h>
-#include <grp.h>
#include <limits.h>
+#include <sys/types.h>
+#include <unistd.h>
+#ifdef _WIN32
+#include "lldb/Host/windows/windows.h"
+#include <winsock2.h>
+#include <WS2tcpip.h>
+#else
+#include <dlfcn.h>
+#include <grp.h>
#include <netdb.h>
#include <pwd.h>
-#include <sys/types.h>
#include <sys/sysctl.h>
-#include <unistd.h>
+#endif
#if defined (__APPLE__)
@@ -66,7 +72,7 @@ using namespace lldb;
using namespace lldb_private;
-#if !defined (__APPLE__)
+#if !defined (__APPLE__) && !defined (_WIN32)
struct MonitorInfo
{
lldb::pid_t pid; // The process ID to monitor
@@ -75,7 +81,7 @@ struct MonitorInfo
bool monitor_signals; // If true, call the callback when "pid" gets signaled.
};
-static void *
+static thread_result_t
MonitorChildProcessThreadFunction (void *arg);
lldb::thread_t
@@ -133,7 +139,7 @@ private:
int m_old_state; // Save the old cancelability state.
};
-static void *
+static thread_result_t
MonitorChildProcessThreadFunction (void *arg)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
@@ -259,6 +265,9 @@ MonitorChildProcessThreadFunction (void *arg)
return NULL;
}
+#endif // #if !defined (__APPLE__) && !defined (_WIN32)
+
+#if !defined (__APPLE__)
void
Host::SystemLog (SystemLogType type, const char *format, va_list args)
@@ -266,7 +275,7 @@ Host::SystemLog (SystemLogType type, const char *format, va_list args)
vfprintf (stderr, format, args);
}
-#endif // #if !defined (__APPLE__)
+#endif
void
Host::SystemLog (SystemLogType type, const char *format, ...)
@@ -277,12 +286,6 @@ Host::SystemLog (SystemLogType type, const char *format, ...)
va_end (args);
}
-size_t
-Host::GetPageSize()
-{
- return ::getpagesize();
-}
-
const ArchSpec &
Host::GetArchitecture (SystemDefaultArchitecture arch_kind)
{
@@ -445,6 +448,8 @@ Host::GetCurrentProcessID()
return ::getpid();
}
+#ifndef _WIN32
+
lldb::tid_t
Host::GetCurrentThreadID()
{
@@ -521,6 +526,8 @@ Host::GetSignalAsCString (int signo)
return NULL;
}
+#endif
+
void
Host::WillTerminate ()
{
@@ -563,6 +570,9 @@ struct HostThreadCreateInfo
};
static thread_result_t
+#ifdef _WIN32
+__stdcall
+#endif
ThreadCreateTrampoline (thread_arg_t arg)
{
HostThreadCreateInfo *info = (HostThreadCreateInfo *)arg;
@@ -592,7 +602,12 @@ Host::ThreadCreate
// Host::ThreadCreateTrampoline will delete this pointer for us.
HostThreadCreateInfo *info_ptr = new HostThreadCreateInfo (thread_name, thread_fptr, thread_arg);
+#ifdef _WIN32
+ thread = ::_beginthreadex(0, 0, ThreadCreateTrampoline, info_ptr, 0, NULL);
+ int err = thread <= 0 ? GetLastError() : 0;
+#else
int err = ::pthread_create (&thread, NULL, ThreadCreateTrampoline, info_ptr);
+#endif
if (err == 0)
{
if (error)
@@ -606,6 +621,8 @@ Host::ThreadCreate
return LLDB_INVALID_HOST_THREAD;
}
+#ifndef _WIN32
+
bool
Host::ThreadCancel (lldb::thread_t thread, Error *error)
{
@@ -633,6 +650,26 @@ Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Err
return err == 0;
}
+lldb::thread_key_t
+Host::ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback)
+{
+ pthread_key_t key;
+ ::pthread_key_create (&key, callback);
+ return key;
+}
+
+void*
+Host::ThreadLocalStorageGet(lldb::thread_key_t key)
+{
+ return ::pthread_getspecific (key);
+}
+
+void
+Host::ThreadLocalStorageSet(lldb::thread_key_t key, void *value)
+{
+ ::pthread_setspecific (key, value);
+}
+
bool
Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
{
@@ -726,6 +763,8 @@ Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid,
return false;
}
+#endif
+
FileSpec
Host::GetProgramFileSpec ()
{
@@ -771,19 +810,6 @@ Host::GetProgramFileSpec ()
return g_program_filespec;
}
-FileSpec
-Host::GetModuleFileSpecForHostAddress (const void *host_addr)
-{
- FileSpec module_filespec;
- Dl_info info;
- if (::dladdr (host_addr, &info))
- {
- if (info.dli_fname)
- module_filespec.SetFile(info.dli_fname, true);
- }
- return module_filespec;
-}
-
#if !defined (__APPLE__) // see Host.mm
bool
@@ -800,6 +826,8 @@ Host::ResolveExecutableInBundle (FileSpec &file)
}
#endif
+#ifndef _WIN32
+
// Opaque info that tracks a dynamic library that was loaded
struct DynamicLibraryInfo
{
@@ -924,6 +952,21 @@ Host::DynamicLibraryGetSymbol (void *opaque, const char *symbol_name, Error &err
return NULL;
}
+FileSpec
+Host::GetModuleFileSpecForHostAddress (const void *host_addr)
+{
+ FileSpec module_filespec;
+ Dl_info info;
+ if (::dladdr (host_addr, &info))
+ {
+ if (info.dli_fname)
+ module_filespec.SetFile(info.dli_fname, true);
+ }
+ return module_filespec;
+}
+
+#endif
+
bool
Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)
{
@@ -1175,6 +1218,8 @@ Host::GetHostname (std::string &s)
return false;
}
+#ifndef _WIN32
+
const char *
Host::GetUserName (uint32_t uid, std::string &user_name)
{
@@ -1234,22 +1279,6 @@ Host::GetGroupName (uint32_t gid, std::string &group_name)
return NULL;
}
-#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) // see macosx/Host.mm
-bool
-Host::GetOSBuildString (std::string &s)
-{
- s.clear();
- return false;
-}
-
-bool
-Host::GetOSKernelDescription (std::string &s)
-{
- s.clear();
- return false;
-}
-#endif
-
uint32_t
Host::GetUserID ()
{
@@ -1274,6 +1303,24 @@ Host::GetEffectiveGroupID ()
return getegid();
}
+#endif
+
+#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) // see macosx/Host.mm
+bool
+Host::GetOSBuildString (std::string &s)
+{
+ s.clear();
+ return false;
+}
+
+bool
+Host::GetOSKernelDescription (std::string &s)
+{
+ s.clear();
+ return false;
+}
+#endif
+
#if !defined (__APPLE__) && !defined(__linux__)
uint32_t
Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos)
@@ -1441,7 +1488,7 @@ Host::RunShellCommand (const char *command,
error.SetErrorString("timed out waiting for shell command to complete");
// Kill the process since it didn't complete withint the timeout specified
- ::kill (pid, SIGKILL);
+ Kill (pid, SIGKILL);
// Wait for the monitor callback to get the message
timeout_time = TimeValue::Now();
timeout_time.OffsetWithSeconds(1);
@@ -1490,6 +1537,13 @@ Host::RunShellCommand (const char *command,
return error;
}
+#ifndef _WIN32
+
+size_t
+Host::GetPageSize()
+{
+ return ::getpagesize();
+}
uint32_t
Host::GetNumberCPUS ()
@@ -1500,14 +1554,7 @@ Host::GetNumberCPUS ()
#if defined(__APPLE__) or defined (__linux__) or defined (__FreeBSD__) or defined (__FreeBSD_kernel__)
g_num_cores = ::sysconf(_SC_NPROCESSORS_ONLN);
-
-#elif defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
-
- // Header file for this might need to be included at the top of this file
- SYSTEM_INFO system_info;
- ::GetSystemInfo (&system_info);
- g_num_cores = system_info.dwNumberOfProcessors;
-
+
#else
// Assume POSIX support if a host specific case has not been supplied above
@@ -1540,7 +1587,13 @@ Host::GetNumberCPUS ()
return g_num_cores;
}
+void
+Host::Kill(lldb::pid_t pid, int signo)
+{
+ ::kill(pid, signo);
+}
+#endif
#if !defined (__APPLE__)
bool
diff --git a/lldb/source/Host/common/Mutex.cpp b/lldb/source/Host/common/Mutex.cpp
index 39cd8c6adb4..3733100d6fd 100644
--- a/lldb/source/Host/common/Mutex.cpp
+++ b/lldb/source/Host/common/Mutex.cpp
@@ -10,6 +10,9 @@
#include "lldb/Host/Mutex.h"
#include "lldb/Host/Host.h"
+#ifndef _WIN32
+#include <pthread.h>
+#endif
#include <string.h>
#include <stdio.h>
#include <unistd.h>
@@ -177,6 +180,8 @@ Mutex::Locker::TryLock (Mutex &mutex, const char *failure_message)
return m_mutex_ptr != NULL;
}
+#ifndef _WIN32
+
//----------------------------------------------------------------------
// Default constructor.
//
@@ -253,15 +258,6 @@ Mutex::~Mutex()
}
//----------------------------------------------------------------------
-// Mutex get accessor.
-//----------------------------------------------------------------------
-pthread_mutex_t *
-Mutex::GetMutex()
-{
- return &m_mutex;
-}
-
-//----------------------------------------------------------------------
// Locks the mutex owned by this object, if the mutex is already
// locked, the calling thread will block until the mutex becomes
// available.
@@ -341,6 +337,17 @@ Mutex::Unlock()
return err;
}
+#endif
+
+//----------------------------------------------------------------------
+// Mutex get accessor.
+//----------------------------------------------------------------------
+lldb::mutex_t *
+Mutex::GetMutex()
+{
+ return &m_mutex;
+}
+
#ifdef LLDB_CONFIGURATION_DEBUG
int
TrackingMutex::Unlock ()
diff --git a/lldb/source/Host/common/ProcessRunLock.cpp b/lldb/source/Host/common/ProcessRunLock.cpp
new file mode 100644
index 00000000000..669a96ddd70
--- /dev/null
+++ b/lldb/source/Host/common/ProcessRunLock.cpp
@@ -0,0 +1,71 @@
+#ifndef _WIN32
+
+#include "lldb/Host/ProcessRunLock.h"
+
+namespace lldb_private {
+
+ ProcessRunLock::ProcessRunLock()
+ : m_running(false)
+ {
+ int err = ::pthread_rwlock_init(&m_rwlock, NULL); (void) err;
+ //#if LLDB_CONFIGURATION_DEBUG
+ // assert(err == 0);
+ //#endif
+ }
+
+ ProcessRunLock::~ProcessRunLock()
+ {
+ int err = ::pthread_rwlock_destroy(&m_rwlock); (void) err;
+ //#if LLDB_CONFIGURATION_DEBUG
+ // assert(err == 0);
+ //#endif
+ }
+
+ bool ProcessRunLock::ReadTryLock()
+ {
+ ::pthread_rwlock_rdlock(&m_rwlock);
+ if (m_running == false)
+ {
+ return true;
+ }
+ ::pthread_rwlock_unlock(&m_rwlock);
+ return false;
+ }
+
+ bool ProcessRunLock::ReadUnlock()
+ {
+ return ::pthread_rwlock_unlock(&m_rwlock) == 0;
+ }
+
+ bool ProcessRunLock::SetRunning()
+ {
+ ::pthread_rwlock_wrlock(&m_rwlock);
+ m_running = true;
+ ::pthread_rwlock_unlock(&m_rwlock);
+ return true;
+ }
+
+ bool ProcessRunLock::TrySetRunning()
+ {
+ bool r;
+
+ if (::pthread_rwlock_trywrlock(&m_rwlock) == 0)
+ {
+ r = !m_running;
+ m_running = true;
+ ::pthread_rwlock_unlock(&m_rwlock);
+ return r;
+ }
+ return false;
+ }
+
+ bool ProcessRunLock::SetStopped()
+ {
+ ::pthread_rwlock_wrlock(&m_rwlock);
+ m_running = false;
+ ::pthread_rwlock_unlock(&m_rwlock);
+ return true;
+ }
+}
+
+#endif
diff --git a/lldb/source/Host/common/Terminal.cpp b/lldb/source/Host/common/Terminal.cpp
index 89d21cf0bf6..08a54551702 100644
--- a/lldb/source/Host/common/Terminal.cpp
+++ b/lldb/source/Host/common/Terminal.cpp
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/Terminal.h"
-#include "lldb/Host/Config.h"
#include <fcntl.h>
#include <unistd.h>
@@ -24,6 +23,7 @@ using namespace lldb_private;
bool
Terminal::IsATerminal () const
{
+
return m_fd >= 0 && ::isatty (m_fd);
}
@@ -108,7 +108,9 @@ Terminal::SetCanonical (bool enabled)
TerminalState::TerminalState() :
m_tty(),
m_tflags(-1),
+#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
m_termios_ap(),
+#endif
m_process_group(-1)
{
}
@@ -125,7 +127,9 @@ TerminalState::Clear ()
{
m_tty.Clear();
m_tflags = -1;
+#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
m_termios_ap.reset();
+#endif
m_process_group = -1;
}
@@ -140,7 +144,9 @@ TerminalState::Save (int fd, bool save_process_group)
m_tty.SetFileDescriptor(fd);
if (m_tty.IsATerminal())
{
+#ifndef LLDB_DISABLE_POSIX
m_tflags = ::fcntl (fd, F_GETFL, 0);
+#endif
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
if (m_termios_ap.get() == NULL)
m_termios_ap.reset (new struct termios);
@@ -148,16 +154,20 @@ TerminalState::Save (int fd, bool save_process_group)
if (err != 0)
m_termios_ap.reset();
#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
+#ifndef LLDB_DISABLE_POSIX
if (save_process_group)
m_process_group = ::tcgetpgrp (0);
else
m_process_group = -1;
+#endif
}
else
{
m_tty.Clear();
m_tflags = -1;
+#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
m_termios_ap.reset();
+#endif
m_process_group = -1;
}
return IsValid();
@@ -173,14 +183,17 @@ TerminalState::Restore () const
if (IsValid())
{
const int fd = m_tty.GetFileDescriptor();
+#ifndef LLDB_DISABLE_POSIX
if (TFlagsIsValid())
fcntl (fd, F_SETFL, m_tflags);
+#endif
#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
if (TTYStateIsValid())
tcsetattr (fd, TCSANOW, m_termios_ap.get());
#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
+#ifndef LLDB_DISABLE_POSIX
if (ProcessGroupIsValid())
{
// Save the original signal handler.
@@ -191,6 +204,7 @@ TerminalState::Restore () const
// Restore the original signal handler.
signal (SIGTTOU, saved_sigttou_callback);
}
+#endif
return true;
}
return false;
@@ -224,7 +238,11 @@ TerminalState::TFlagsIsValid() const
bool
TerminalState::TTYStateIsValid() const
{
+#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED
return m_termios_ap.get() != 0;
+#else
+ return false;
+#endif
}
//----------------------------------------------------------------------
diff --git a/lldb/source/Host/common/TimeValue.cpp b/lldb/source/Host/common/TimeValue.cpp
index 303ac94058b..0858255cc45 100644
--- a/lldb/source/Host/common/TimeValue.cpp
+++ b/lldb/source/Host/common/TimeValue.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/TimeValue.h"
+#include "lldb/Host/Config.h"
// C Includes
#include <stddef.h>
@@ -148,6 +149,7 @@ TimeValue::Dump (Stream *s, uint32_t width) const
if (s == NULL)
return;
+#ifndef LLDB_DISABLE_POSIX
char time_buf[32];
time_t time = GetAsSecondsSinceJan1_1970();
char *time_cstr = ::ctime_r(&time, time_buf);
@@ -163,6 +165,7 @@ TimeValue::Dump (Stream *s, uint32_t width) const
}
else if (width > 0)
s->Printf("%-*s", width, "");
+#endif
}
bool
diff --git a/lldb/source/Host/windows/CMakeLists.txt b/lldb/source/Host/windows/CMakeLists.txt
new file mode 100644
index 00000000000..0ffe73439c8
--- /dev/null
+++ b/lldb/source/Host/windows/CMakeLists.txt
@@ -0,0 +1,9 @@
+set(LLVM_NO_RTTI 1)
+
+add_lldb_library(lldbHostWindows
+ Host.cpp
+ ProcessRunLock.cpp
+ Mutex.cpp
+ Condition.cpp
+ Windows.cpp
+ )
diff --git a/lldb/source/Host/windows/Condition.cpp b/lldb/source/Host/windows/Condition.cpp
new file mode 100644
index 00000000000..efece6d7519
--- /dev/null
+++ b/lldb/source/Host/windows/Condition.cpp
@@ -0,0 +1,95 @@
+//===-- Condition.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <errno.h>
+
+#include "lldb/Host/Condition.h"
+#include "lldb/Host/TimeValue.h"
+
+
+using namespace lldb_private;
+
+//----------------------------------------------------------------------
+// Default constructor
+//
+// The default constructor will initialize a new pthread condition
+// and maintain the condition in the object state.
+//----------------------------------------------------------------------
+Condition::Condition () :
+ m_condition()
+{
+ InitializeConditionVariable(&m_condition);
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//
+// Destroys the pthread condition that the object owns.
+//----------------------------------------------------------------------
+Condition::~Condition ()
+{
+}
+
+//----------------------------------------------------------------------
+// Unblock all threads waiting for a condition variable
+//----------------------------------------------------------------------
+int
+Condition::Broadcast ()
+{
+ WakeAllConditionVariable(&m_condition);
+ return 0;
+}
+
+//----------------------------------------------------------------------
+// Unblocks one thread waiting for the condition variable
+//----------------------------------------------------------------------
+int
+Condition::Signal ()
+{
+ WakeConditionVariable(&m_condition);
+ return 0;
+}
+
+//----------------------------------------------------------------------
+// The Wait() function atomically blocks the current thread
+// waiting on the owned condition variable, and unblocks the mutex
+// specified by "mutex". The waiting thread unblocks only after
+// another thread calls Signal(), or Broadcast() with the same
+// condition variable, or if "abstime" is valid (non-NULL) this
+// function will return when the system time reaches the time
+// specified in "abstime". If "abstime" is NULL this function will
+// wait for an infinite amount of time for the condition variable
+// to be signaled or broadcasted.
+//
+// The current thread re-acquires the lock on "mutex".
+//----------------------------------------------------------------------
+int
+Condition::Wait (Mutex &mutex, const TimeValue *abstime, bool *timed_out)
+{
+ DWORD wait = INFINITE;
+ if (abstime != NULL) {
+ int wval = (*abstime - TimeValue::Now()) / 1000000;
+ if (wval < 0) wval = 0;
+
+ wait = wval;
+ }
+
+ int err = SleepConditionVariableCS(&m_condition, &mutex.m_mutex, wait);
+
+ if (timed_out != NULL)
+ {
+ if ((err == 0) && GetLastError() == ERROR_TIMEOUT)
+ *timed_out = true;
+ else
+ *timed_out = false;
+ }
+
+ return err != 0;
+}
+
diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp
new file mode 100644
index 00000000000..24f7e4bd896
--- /dev/null
+++ b/lldb/source/Host/windows/Host.cpp
@@ -0,0 +1,245 @@
+//===-- source/Host/windows/Host.cpp ----------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// C Includes
+#include <stdio.h>
+#include "lldb/Host/windows/windows.h"
+
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Error.h"
+#include "lldb/Core/Log.h"
+#include "lldb/Target/Process.h"
+
+#include "lldb/Host/Host.h"
+#include "lldb/Core/DataBufferHeap.h"
+#include "lldb/Core/DataExtractor.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+bool
+Host::GetOSVersion(uint32_t &major,
+ uint32_t &minor,
+ uint32_t &update)
+{
+ OSVERSIONINFOEX info;
+
+ ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
+ info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+
+ if (GetVersionEx((LPOSVERSIONINFO) &info) == 0) {
+ return false;
+ }
+
+ major = (uint32_t) info.dwMajorVersion;
+ minor = (uint32_t) info.dwMinorVersion;
+ update = (uint32_t) info.wServicePackMajor;
+
+ return true;
+}
+
+Error
+Host::LaunchProcess (ProcessLaunchInfo &launch_info)
+{
+ Error error;
+ assert(!"Not implemented yet!!!");
+ return error;
+}
+
+lldb::DataBufferSP
+Host::GetAuxvData(lldb_private::Process *process)
+{
+ return 0;
+}
+
+std::string
+Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid)
+{
+ return std::string();
+}
+
+lldb::tid_t
+Host::GetCurrentThreadID()
+{
+ return lldb::tid_t(::GetCurrentThreadId());
+}
+
+lldb::thread_t
+Host::GetCurrentThread ()
+{
+ return lldb::thread_t(::GetCurrentThread());
+}
+
+bool
+Host::ThreadCancel (lldb::thread_t thread, Error *error)
+{
+ int err = ::TerminateThread((HANDLE)thread, 0);
+ return err == 0;
+}
+
+bool
+Host::ThreadDetach (lldb::thread_t thread, Error *error)
+{
+ return ThreadCancel(thread, error);
+}
+
+bool
+Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error)
+{
+ WaitForSingleObject((HANDLE) thread, INFINITE);
+ return true;
+}
+
+lldb::thread_key_t
+Host::ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback)
+{
+ return TlsAlloc();
+}
+
+void*
+Host::ThreadLocalStorageGet(lldb::thread_key_t key)
+{
+ return ::TlsGetValue (key);
+}
+
+void
+Host::ThreadLocalStorageSet(lldb::thread_key_t key, void *value)
+{
+ ::TlsSetValue (key, value);
+}
+
+bool
+Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
+{
+ return false;
+}
+
+bool
+Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid,
+ const char *thread_name, size_t len)
+{
+ return false;
+}
+
+void
+Host::Kill(lldb::pid_t pid, int signo)
+{
+ TerminateProcess((HANDLE) pid, 1);
+}
+
+uint32_t
+Host::GetNumberCPUS()
+{
+ static uint32_t g_num_cores = UINT32_MAX;
+ if (g_num_cores == UINT32_MAX)
+ {
+ SYSTEM_INFO system_info;
+ ::GetSystemInfo(&system_info);
+ g_num_cores = system_info.dwNumberOfProcessors;
+ }
+ return g_num_cores;
+}
+
+size_t
+Host::GetPageSize()
+{
+ static long g_pagesize = 0;
+ if (!g_pagesize)
+ {
+ SYSTEM_INFO systemInfo;
+ GetNativeSystemInfo(&systemInfo);
+ g_pagesize = systemInfo.dwPageSize;
+ }
+ return g_pagesize;
+}
+
+const char *
+Host::GetSignalAsCString(int signo)
+{
+ return NULL;
+}
+
+FileSpec
+Host::GetModuleFileSpecForHostAddress (const void *host_addr)
+{
+ FileSpec module_filespec;
+ return module_filespec;
+}
+
+void *
+Host::DynamicLibraryOpen(const FileSpec &file_spec, uint32_t options, Error &error)
+{
+ error.SetErrorString("not implemented");
+ return NULL;
+}
+
+Error
+Host::DynamicLibraryClose (void *opaque)
+{
+ Error error;
+ error.SetErrorString("not implemented");
+ return error;
+}
+
+void *
+Host::DynamicLibraryGetSymbol(void *opaque, const char *symbol_name, Error &error)
+{
+ error.SetErrorString("not implemented");
+ return NULL;
+}
+
+const char *
+Host::GetUserName (uint32_t uid, std::string &user_name)
+{
+ return NULL;
+}
+
+const char *
+Host::GetGroupName (uint32_t gid, std::string &group_name)
+{
+ return NULL;
+}
+
+uint32_t
+Host::GetUserID ()
+{
+ return 0;
+}
+
+uint32_t
+Host::GetGroupID ()
+{
+ return 0;
+}
+
+uint32_t
+Host::GetEffectiveUserID ()
+{
+ return 0;
+}
+
+uint32_t
+Host::GetEffectiveGroupID ()
+{
+ return 0;
+}
+
+lldb::thread_t
+Host::StartMonitoringChildProcess
+(
+ Host::MonitorChildProcessCallback callback,
+ void *callback_baton,
+ lldb::pid_t pid,
+ bool monitor_signals
+)
+{
+ return LLDB_INVALID_HOST_THREAD;
+} \ No newline at end of file
diff --git a/lldb/source/Host/windows/Makefile b/lldb/source/Host/windows/Makefile
new file mode 100644
index 00000000000..f85327a987c
--- /dev/null
+++ b/lldb/source/Host/windows/Makefile
@@ -0,0 +1,14 @@
+##===- source/Host/windows/Makefile ------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LLDB_LEVEL := ../../..
+LIBRARYNAME := lldbHostWindows
+BUILD_ARCHIVE = 1
+
+include $(LLDB_LEVEL)/Makefile
diff --git a/lldb/source/Host/windows/Mutex.cpp b/lldb/source/Host/windows/Mutex.cpp
new file mode 100644
index 00000000000..6a74506898d
--- /dev/null
+++ b/lldb/source/Host/windows/Mutex.cpp
@@ -0,0 +1,106 @@
+//===-- Mutex.cpp -----------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Host/Mutex.h"
+#include "lldb/Host/Host.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#if 0
+// This logging is way too verbose to enable even for a log channel.
+// This logging can be enabled by changing the "#if 0", but should be
+// reverted prior to checking in.
+#include <cstdio>
+#define DEBUG_LOG(fmt, ...) printf(fmt, ## __VA_ARGS__)
+#else
+#define DEBUG_LOG(fmt, ...)
+#endif
+
+using namespace lldb_private;
+
+//----------------------------------------------------------------------
+// Default constructor.
+//
+// Creates a pthread mutex with no attributes.
+//----------------------------------------------------------------------
+Mutex::Mutex () :
+ m_mutex()
+{
+ InitializeCriticalSection(&m_mutex);
+}
+
+//----------------------------------------------------------------------
+// Default constructor.
+//
+// Creates a pthread mutex with "type" as the mutex type.
+//----------------------------------------------------------------------
+Mutex::Mutex (Mutex::Type type) :
+ m_mutex()
+{
+ InitializeCriticalSection(&m_mutex);
+}
+
+//----------------------------------------------------------------------
+// Destructor.
+//
+// Destroys the mutex owned by this object.
+//----------------------------------------------------------------------
+Mutex::~Mutex()
+{
+ DeleteCriticalSection(&m_mutex);
+}
+
+//----------------------------------------------------------------------
+// Locks the mutex owned by this object, if the mutex is already
+// locked, the calling thread will block until the mutex becomes
+// available.
+//
+// RETURNS
+// The error code from the pthread_mutex_lock() function call.
+//----------------------------------------------------------------------
+int
+Mutex::Lock()
+{
+ DEBUG_LOG ("[%4.4" PRIx64 "/%4.4" PRIx64 "] pthread_mutex_lock (%p)...\n", Host::GetCurrentProcessID(), Host::GetCurrentThreadID(), &m_mutex);
+
+ EnterCriticalSection(&m_mutex);
+ return 0;
+}
+
+//----------------------------------------------------------------------
+// Attempts to lock the mutex owned by this object without blocking.
+// If the mutex is already locked, TryLock() will not block waiting
+// for the mutex, but will return an error condition.
+//
+// RETURNS
+// The error code from the pthread_mutex_trylock() function call.
+//----------------------------------------------------------------------
+int
+Mutex::TryLock(const char *failure_message)
+{
+ return TryEnterCriticalSection(&m_mutex) == 0;
+}
+
+//----------------------------------------------------------------------
+// If the current thread holds the lock on the owned mutex, then
+// Unlock() will unlock the mutex. Calling Unlock() on this object
+// that the calling thread does not hold will result in undefined
+// behavior.
+//
+// RETURNS
+// The error code from the pthread_mutex_unlock() function call.
+//----------------------------------------------------------------------
+int
+Mutex::Unlock()
+{
+ LeaveCriticalSection(&m_mutex);
+ return 0;
+}
diff --git a/lldb/source/Host/windows/ProcessRunLock.cpp b/lldb/source/Host/windows/ProcessRunLock.cpp
new file mode 100644
index 00000000000..ae9a9733c16
--- /dev/null
+++ b/lldb/source/Host/windows/ProcessRunLock.cpp
@@ -0,0 +1,240 @@
+#ifdef _WIN32
+
+#include "lldb/Host/ProcessRunLock.h"
+
+namespace lldb_private {
+
+ // Windows has slim read-writer lock support on Vista and higher, so we
+ // will attempt to load the APIs. If they exist, we will use them, and
+ // if not, we will fall back on critical sections. When we drop support
+ // for XP, we can stop lazy-loading these APIs and just use them directly.
+#if defined(__MINGW32__)
+ // Taken from WinNT.h
+ typedef struct _RTL_SRWLOCK {
+ PVOID Ptr;
+ } RTL_SRWLOCK, *PRTL_SRWLOCK;
+
+ // Taken from WinBase.h
+ typedef RTL_SRWLOCK SRWLOCK, *PSRWLOCK;
+#endif
+
+
+ typedef struct Win32RWLOCK
+ {
+ unsigned long int readlockcount;
+ HANDLE writable;
+ CRITICAL_SECTION writelock;
+ unsigned long int writelocked;
+ } Win32RWLOCK;
+
+ typedef Win32RWLOCK* PWin32RWLOCK;
+
+ static VOID (WINAPI *fpInitializeSRWLock)(PSRWLOCK lock) = NULL;
+ static VOID (WINAPI *fpAcquireSRWLockExclusive)(PSRWLOCK lock) = NULL;
+ static VOID (WINAPI *fpAcquireSRWLockShared)(PSRWLOCK lock) = NULL;
+ static VOID (WINAPI *fpReleaseSRWLockExclusive)(PSRWLOCK lock) = NULL;
+ static VOID (WINAPI *fpReleaseSRWLockShared)(PSRWLOCK lock) = NULL;
+ static BOOL (WINAPI *fpTryAcquireSRWLockExclusive)(PSRWLOCK lock) = NULL;
+ static BOOL (WINAPI *fpTryAcquireSRWLockShared)(PSRWLOCK lock) = NULL;
+
+ static bool sHasSRW = false;
+
+ static bool loadSRW()
+ {
+ static bool sChecked = false;
+ if (!sChecked)
+ {
+ sChecked = true;
+ return false;
+
+ HMODULE hLib = ::LoadLibrary(TEXT("Kernel32"));
+ if (hLib)
+ {
+ fpInitializeSRWLock =
+ (VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib,
+ "InitializeSRWLock");
+ fpAcquireSRWLockExclusive =
+ (VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib,
+ "AcquireSRWLockExclusive");
+ fpAcquireSRWLockShared =
+ (VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib,
+ "AcquireSRWLockShared");
+ fpReleaseSRWLockExclusive =
+ (VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib,
+ "ReleaseSRWLockExclusive");
+ fpReleaseSRWLockShared =
+ (VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib,
+ "ReleaseSRWLockShared");
+ fpTryAcquireSRWLockExclusive =
+ (BOOL (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib,
+ "TryAcquireSRWLockExclusive");
+ fpTryAcquireSRWLockShared =
+ (BOOL (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib,
+ "TryAcquireSRWLockShared");
+
+ ::FreeLibrary(hLib);
+
+ if (fpInitializeSRWLock != NULL) {
+ sHasSRW = true;
+ }
+ }
+ }
+ return sHasSRW;
+ }
+
+ ProcessRunLock::ProcessRunLock ()
+ : m_running(false)
+ {
+ if (loadSRW())
+ {
+ m_rwlock = calloc(1, sizeof(SRWLOCK));
+ fpInitializeSRWLock(static_cast<PSRWLOCK>(m_rwlock));
+ }
+ else
+ {
+ m_rwlock = calloc(1, sizeof(Win32RWLOCK));
+ static_cast<PWin32RWLOCK>(m_rwlock)->readlockcount = 0;
+ static_cast<PWin32RWLOCK>(m_rwlock)->writable = CreateEvent(NULL, true, true, NULL);
+ InitializeCriticalSection(&static_cast<PWin32RWLOCK>(m_rwlock)->writelock);
+ }
+ }
+
+ ProcessRunLock::~ProcessRunLock ()
+ {
+ if (!sHasSRW)
+ {
+ CloseHandle(static_cast<PWin32RWLOCK>(m_rwlock)->writable);
+ DeleteCriticalSection(&static_cast<PWin32RWLOCK>(m_rwlock)->writelock);
+ }
+ free(m_rwlock);
+ }
+
+ bool ReadLock (lldb::rwlock_t rwlock)
+ {
+ if (sHasSRW)
+ {
+ fpAcquireSRWLockShared(static_cast<PSRWLOCK>(rwlock));
+ return true;
+ }
+ else
+ {
+ EnterCriticalSection(&static_cast<PWin32RWLOCK>(rwlock)->writelock);
+ InterlockedIncrement(&static_cast<PWin32RWLOCK>(rwlock)->readlockcount);
+ ResetEvent(static_cast<PWin32RWLOCK>(rwlock)->writable);
+ LeaveCriticalSection(&static_cast<PWin32RWLOCK>(rwlock)->writelock);
+ return true;
+ }
+ }
+
+ bool ProcessRunLock::ReadTryLock ()
+ {
+ ReadLock(m_rwlock);
+ if (m_running == false)
+ return true;
+ ReadUnlock();
+ return false;
+ }
+
+ bool ProcessRunLock::ReadUnlock ()
+ {
+ if (sHasSRW)
+ {
+ fpReleaseSRWLockShared(static_cast<PSRWLOCK>(m_rwlock));
+ return true;
+ }
+ else
+ {
+ unsigned long int value = InterlockedDecrement(&static_cast<PWin32RWLOCK>(m_rwlock)->readlockcount);
+ assert(((int)value) >= 0);
+ if (value == 0)
+ SetEvent(static_cast<PWin32RWLOCK>(m_rwlock)->writable);
+ return true;
+ }
+ }
+
+ bool WriteLock(lldb::rwlock_t rwlock)
+ {
+ if (sHasSRW)
+ {
+ fpAcquireSRWLockExclusive(static_cast<PSRWLOCK>(rwlock));
+ return true;
+ }
+ else
+ {
+ EnterCriticalSection(&static_cast<PWin32RWLOCK>(rwlock)->writelock);
+ WaitForSingleObject(static_cast<PWin32RWLOCK>(rwlock)->writable, INFINITE);
+ int res = InterlockedExchange(&static_cast<PWin32RWLOCK>(rwlock)->writelocked, 1);
+ assert(res == 0);
+ return true;
+ }
+ }
+
+ bool WriteTryLock(lldb::rwlock_t rwlock)
+ {
+ if (sHasSRW)
+ {
+ return fpTryAcquireSRWLockExclusive(static_cast<PSRWLOCK>(rwlock)) != 0;
+ }
+ else
+ {
+ if (TryEnterCriticalSection(&static_cast<PWin32RWLOCK>(rwlock)->writelock)) {
+ if (WaitForSingleObject(static_cast<PWin32RWLOCK>(rwlock)->writable, 0)) {
+ LeaveCriticalSection(&static_cast<PWin32RWLOCK>(rwlock)->writelock);
+ return false;
+ }
+ int res = InterlockedExchange(&static_cast<PWin32RWLOCK>(rwlock)->writelocked, 1);
+ assert(res == 0);
+ return true;
+ }
+ return false;
+ }
+ }
+
+ bool WriteUnlock(lldb::rwlock_t rwlock)
+ {
+ if (sHasSRW)
+ {
+ fpReleaseSRWLockExclusive(static_cast<PSRWLOCK>(rwlock));
+ return true;
+ }
+ else
+ {
+ int res = InterlockedExchange(&static_cast<PWin32RWLOCK>(rwlock)->writelocked, 0);
+ if (res == 1) {
+ LeaveCriticalSection(&static_cast<PWin32RWLOCK>(rwlock)->writelock);
+ return true;
+ }
+ return false;
+ }
+ }
+
+ bool ProcessRunLock::SetRunning ()
+ {
+ WriteLock(m_rwlock);
+ m_running = true;
+ WriteUnlock(m_rwlock);
+ return true;
+ }
+
+ bool ProcessRunLock::TrySetRunning ()
+ {
+ if (WriteTryLock(m_rwlock))
+ {
+ bool r = !m_running;
+ m_running = true;
+ WriteUnlock(m_rwlock);
+ return r;
+ }
+ return false;
+ }
+
+ bool ProcessRunLock::SetStopped ()
+ {
+ WriteLock(m_rwlock);
+ m_running = false;
+ WriteUnlock(m_rwlock);
+ return true;
+ }
+}
+
+#endif
diff --git a/lldb/source/Host/windows/Windows.cpp b/lldb/source/Host/windows/Windows.cpp
new file mode 100644
index 00000000000..34dbc238428
--- /dev/null
+++ b/lldb/source/Host/windows/Windows.cpp
@@ -0,0 +1,146 @@
+//===-- Windows.cpp ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// This file provides Windows support functions
+
+#include "lldb/Host/windows/windows.h"
+#include "lldb/Host/windows/win32.h"
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <io.h>
+#include <cerrno>
+
+int vasprintf(char **ret, const char *fmt, va_list ap)
+{
+ char *buf;
+ int len;
+ size_t buflen;
+ va_list ap2;
+
+#if defined(_MSC_VER) || defined(__MINGW64)
+ ap2 = ap;
+ len = _vscprintf(fmt, ap2);
+#else
+ va_copy(ap2, ap);
+ len = vsnprintf(NULL, 0, fmt, ap2);
+#endif
+
+ if (len >= 0 && (buf = (char*) malloc ((buflen = (size_t) (len + 1)))) != NULL) {
+ len = vsnprintf(buf, buflen, fmt, ap);
+ *ret = buf;
+ } else {
+ *ret = NULL;
+ len = -1;
+ }
+
+ va_end(ap2);
+ return len;
+}
+
+char * strcasestr(const char *s, const char* find)
+{
+ char c, sc;
+ size_t len;
+
+ if ((c = *find++) != 0) {
+ c = tolower((unsigned char) c);
+ len = strlen(find);
+ do {
+ do {
+ if ((sc = *s++) == 0)
+ return 0;
+ } while ((char) tolower((unsigned char) sc) != c);
+ } while (strncasecmp(s, find, len) != 0);
+ s--;
+ }
+ return ((char *) s);
+}
+
+char* __cdecl realpath(const char * name, char * resolved)
+{
+ char *retname = NULL; /* we will return this, if we fail */
+
+ /* SUSv3 says we must set `errno = EINVAL', and return NULL,
+ * if `name' is passed as a NULL pointer.
+ */
+
+ if (name == NULL)
+ errno = EINVAL;
+
+ /* Otherwise, `name' must refer to a readable filesystem object,
+ * if we are going to resolve its absolute path name.
+ */
+
+ else if (access(name, 4) == 0)
+ {
+ /* If `name' didn't point to an existing entity,
+ * then we don't get to here; we simply fall past this block,
+ * returning NULL, with `errno' appropriately set by `access'.
+ *
+ * When we _do_ get to here, then we can use `_fullpath' to
+ * resolve the full path for `name' into `resolved', but first,
+ * check that we have a suitable buffer, in which to return it.
+ */
+
+ if ((retname = resolved) == NULL)
+ {
+ /* Caller didn't give us a buffer, so we'll exercise the
+ * option granted by SUSv3, and allocate one.
+ *
+ * `_fullpath' would do this for us, but it uses `malloc', and
+ * Microsoft's implementation doesn't set `errno' on failure.
+ * If we don't do this explicitly ourselves, then we will not
+ * know if `_fullpath' fails on `malloc' failure, or for some
+ * other reason, and we want to set `errno = ENOMEM' for the
+ * `malloc' failure case.
+ */
+
+ retname = (char*) malloc(_MAX_PATH);
+ }
+
+ /* By now, we should have a valid buffer.
+ * If we don't, then we know that `malloc' failed,
+ * so we can set `errno = ENOMEM' appropriately.
+ */
+
+ if (retname == NULL)
+ errno = ENOMEM;
+
+ /* Otherwise, when we do have a valid buffer,
+ * `_fullpath' should only fail if the path name is too long.
+ */
+
+ else if ((retname = _fullpath(retname, name, _MAX_PATH)) == NULL)
+ errno = ENAMETOOLONG;
+ }
+
+ /* By the time we get to here,
+ * `retname' either points to the required resolved path name,
+ * or it is NULL, with `errno' set appropriately, either of which
+ * is our required return condition.
+ */
+
+ if (retname != NULL)
+ {
+ // Do a LongPath<->ShortPath roundtrip so that case is resolved by OS
+ int initialLength = strlen(retname);
+ TCHAR buffer[MAX_PATH];
+ GetShortPathName(retname, buffer, MAX_PATH);
+ GetLongPathName(buffer, retname, initialLength + 1);
+
+ // Force drive to be upper case
+ if (retname[1] == ':')
+ retname[0] = toupper(retname[0]);
+ }
+
+ return retname;
+}
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp
index e6d20435803..833afd606a1 100644
--- a/lldb/source/Interpreter/Args.cpp
+++ b/lldb/source/Interpreter/Args.cpp
@@ -10,6 +10,9 @@
#include "lldb/lldb-python.h"
// C Includes
+#ifdef _WIN32
+#define _BSD_SOURCE // Required so that getopt.h defines optreset
+#endif
#include <getopt.h>
#include <cstdlib>
// C++ Includes
diff --git a/lldb/source/Interpreter/Makefile b/lldb/source/Interpreter/Makefile
index 24ee3941e82..d69d51cd0ac 100644
--- a/lldb/source/Interpreter/Makefile
+++ b/lldb/source/Interpreter/Makefile
@@ -11,7 +11,9 @@ LLDB_LEVEL := ../..
LIBRARYNAME := lldbInterpreter
BUILD_ARCHIVE = 1
+ifeq (,$(findstring -DLLDB_DISABLE_PYTHON,$(CXXFLAGS)))
BUILT_SOURCES := LLDBWrapPython.cpp
+endif
include $(LLDB_LEVEL)/Makefile
-include $(PROJ_OBJ_DIR)/LLDBWrapPython.cpp.d
diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
index e920d70cd59..59f9ad728c9 100644
--- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
+++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
@@ -38,7 +38,7 @@
#include "lldb/Target/Target.h"
#include "lldb/Target/StackFrame.h"
-#include <regex.h>
+#include "lldb/Core/RegularExpression.h"
using namespace lldb;
using namespace lldb_private;
@@ -369,20 +369,17 @@ public:
}
}
- if (!s_regex_compiled)
+ if (!s_regex.IsValid())
{
- ::regcomp(&s_regex, "[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?", REG_EXTENDED);
- s_regex_compiled = true;
+ s_regex.Compile("[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?", REG_EXTENDED);
}
- ::regmatch_t matches[3];
+ RegularExpression::Match matches(3);
- if (!::regexec(&s_regex, out_string, sizeof(matches) / sizeof(::regmatch_t), matches, 0))
+ if (s_regex.Execute(out_string, &matches))
{
- if (matches[1].rm_so != -1)
- m_opcode_name.assign(out_string + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
- if (matches[2].rm_so != -1)
- m_mnemonics.assign(out_string + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so);
+ matches.GetMatchAtIndex(out_string, 1, m_opcode_name);
+ matches.GetMatchAtIndex(out_string, 2, m_mnemonics);
}
}
}
@@ -416,12 +413,10 @@ protected:
bool m_is_valid;
bool m_using_file_addr;
- static bool s_regex_compiled;
- static ::regex_t s_regex;
+ static RegularExpression s_regex;
};
-bool InstructionLLVMC::s_regex_compiled = false;
-::regex_t InstructionLLVMC::s_regex;
+RegularExpression InstructionLLVMC::s_regex;
DisassemblerLLVMC::LLVMCDisassembler::LLVMCDisassembler (const char *triple, unsigned flavor, DisassemblerLLVMC &owner):
m_is_valid(true)
@@ -796,7 +791,7 @@ int DisassemblerLLVMC::OpInfo (uint64_t PC,
default:
break;
case 1:
- bzero (tag_bug, sizeof(::LLVMOpInfo1));
+ memset (tag_bug, 0, sizeof(::LLVMOpInfo1));
break;
}
return 0;
diff --git a/lldb/source/Plugins/Makefile b/lldb/source/Plugins/Makefile
index 3694f319b69..1fc50248303 100644
--- a/lldb/source/Plugins/Makefile
+++ b/lldb/source/Plugins/Makefile
@@ -22,6 +22,10 @@ DIRS := ABI/MacOSX-arm ABI/MacOSX-i386 ABI/SysV-x86_64 Disassembler/llvm \
DynamicLoader/POSIX-DYLD \
OperatingSystem/Python
+ifeq ($(HOST_OS),MingW)
+DIRS += SymbolVendor/ELF
+endif
+
ifeq ($(HOST_OS),Darwin)
DIRS += Process/MacOSX-Kernel
DIRS += DynamicLoader/MacOSX-DYLD DynamicLoader/Darwin-Kernel
diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
index 1ec5f3d733a..8260555fd47 100644
--- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -9,7 +9,24 @@
#include "ObjectContainerBSDArchive.h"
+#ifdef _WIN32
+// Defines from ar, missing on Windows
+#define ARMAG "!<arch>\n"
+#define SARMAG 8
+#define ARFMAG "`\n"
+
+typedef struct ar_hdr
+{
+ char ar_name[16];
+ char ar_date[12];
+ char ar_uid[6], ar_gid[6];
+ char ar_mode[8];
+ char ar_size[10];
+ char ar_fmag[2];
+} ar_hdr;
+#else
#include <ar.h>
+#endif
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/DataBuffer.h"
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 178c0a09266..88213c750e4 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1545,7 +1545,7 @@ ObjectFileMachO::ParseSymtab ()
function_starts_load_command.cmd = lc.cmd;
function_starts_load_command.cmdsize = lc.cmdsize;
if (m_data.GetU32(&offset, &function_starts_load_command.dataoff, 2) == NULL) // fill in symoff, nsyms, stroff, strsize fields
- bzero (&function_starts_load_command, sizeof(function_starts_load_command));
+ memset (&function_starts_load_command, 0, sizeof(function_starts_load_command));
break;
default:
diff --git a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
index dc0917255d9..cdca4463fff 100644
--- a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
+++ b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
@@ -10,10 +10,13 @@
#include "lldb/lldb-python.h"
#include "PlatformFreeBSD.h"
+#include "lldb/Host/Config.h"
// C Includes
#include <stdio.h>
+#ifndef LLDB_DISABLE_POSIX
#include <sys/utsname.h>
+#endif
// C++ Includes
// Other libraries and framework includes
@@ -636,6 +639,7 @@ PlatformFreeBSD::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
void
PlatformFreeBSD::GetStatus (Stream &strm)
{
+#ifndef LLDB_DISABLE_POSIX
struct utsname un;
if (uname(&un)) {
@@ -644,5 +648,7 @@ PlatformFreeBSD::GetStatus (Stream &strm)
}
strm << "Host: " << un.sysname << ' ' << un.release << ' ' << un.version << '\n';
+#endif
+
Platform::GetStatus(strm);
}
diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
index 4bf4cf8bc44..1456a7cf714 100644
--- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -10,10 +10,13 @@
#include "lldb/lldb-python.h"
#include "PlatformLinux.h"
+#include "lldb/Host/Config.h"
// C Includes
#include <stdio.h>
+#ifndef LLDB_DISABLE_POSIX
#include <sys/utsname.h>
+#endif
// C++ Includes
// Other libraries and framework includes
@@ -357,16 +360,18 @@ PlatformLinux::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
void
PlatformLinux::GetStatus (Stream &strm)
{
- struct utsname un;
-
Platform::GetStatus(strm);
+#ifndef LLDB_DISABLE_POSIX
+ struct utsname un;
+
if (uname(&un))
return;
strm.Printf (" Kernel: %s\n", un.sysname);
strm.Printf (" Release: %s\n", un.release);
strm.Printf (" Version: %s\n", un.version);
+#endif
}
size_t
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
index 16bcafd97b8..3b0e159e454 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
@@ -8,9 +8,12 @@
//===----------------------------------------------------------------------===//
#include "PlatformMacOSX.h"
+#include "lldb/Host/Config.h"
// C Includes
+#ifndef LLDB_DISABLE_POSIX
#include <sys/sysctl.h>
+#endif
// C++ Includes
// Other libraries and framework includes
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 684d1921e92..5d15db53de7 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -10,9 +10,12 @@
#include "lldb/lldb-python.h"
#include "PlatformRemoteGDBServer.h"
+#include "lldb/Host/Config.h"
// C Includes
+#ifndef LLDB_DISABLE_POSIX
#include <sys/sysctl.h>
+#endif
// C++ Includes
// Other libraries and framework includes
diff --git a/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp b/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
index 499d6d76615..8b22d6457ad 100644
--- a/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ b/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -17,8 +17,19 @@
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/ThreadPlanCallFunction.h"
+#include "lldb/Host/Config.h"
+#ifndef LLDB_DISABLE_POSIX
#include <sys/mman.h>
+#else
+// define them
+#define PROT_NONE 0
+#define PROT_READ 1
+#define PROT_WRITE 2
+#define PROT_EXEC 4
+#define MAP_PRIVATE 2
+#define MAP_ANON 0x1000
+#endif
using namespace lldb;
using namespace lldb_private;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index ca594a8f3fd..6a6e063e35b 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -29,10 +29,15 @@
#include "Utility/StringExtractorGDBRemote.h"
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
+#include "lldb/Host/Config.h"
using namespace lldb;
using namespace lldb_private;
+#ifdef LLDB_DISABLE_POSIX
+#define SIGSTOP 17
+#endif
+
//----------------------------------------------------------------------
// GDBRemoteCommunicationClient constructor
//----------------------------------------------------------------------
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index 3a14e9fe759..050ed00ff6d 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -668,6 +668,10 @@ GDBRemoteCommunicationServer::Handle_qC (StringExtractorGDBRemote &packet)
bool
GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet)
{
+#ifdef _WIN32
+ // No unix sockets on windows
+ return false;
+#else
// Spawn a local debugserver as a platform so we can then attach or launch
// a process...
@@ -731,6 +735,7 @@ GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote
}
}
return SendErrorResponse (13);
+#endif
}
bool
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index d27207f121d..4a3bd041524 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -8,13 +8,16 @@
//===----------------------------------------------------------------------===//
#include "lldb/lldb-python.h"
+#include "lldb/Host/Config.h"
// C Includes
#include <errno.h>
-#include <spawn.h>
#include <stdlib.h>
+#ifndef LLDB_DISABLE_POSIX
+#include <spawn.h>
#include <netinet/in.h>
#include <sys/mman.h> // for mmap
+#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
@@ -2687,7 +2690,7 @@ ProcessGDBRemote::KillDebugserverProcess ()
{
if (m_debugserver_pid != LLDB_INVALID_PROCESS_ID)
{
- ::kill (m_debugserver_pid, SIGINT);
+ Host::Kill (m_debugserver_pid, SIGINT);
m_debugserver_pid = LLDB_INVALID_PROCESS_ID;
}
}
@@ -2794,7 +2797,7 @@ ProcessGDBRemote::StopAsyncThread ()
}
-void *
+thread_result_t
ProcessGDBRemote::AsyncThread (void *arg)
{
ProcessGDBRemote *process = (ProcessGDBRemote*) arg;
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index e104b7191ea..c8bd42bdfab 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -340,7 +340,7 @@ protected:
void
StopAsyncThread ();
- static void *
+ static lldb::thread_result_t
AsyncThread (void *arg);
static bool
diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp
index 0c6159122cf..5cddb0b11e5 100644
--- a/lldb/source/Symbol/ObjectFile.cpp
+++ b/lldb/source/Symbol/ObjectFile.cpp
@@ -501,7 +501,7 @@ ObjectFile::ReadSectionData (const Section *section, off_t section_offset, void
uint64_t section_dst_len = dst_len;
if (section_dst_len > section_bytes_left)
section_dst_len = section_bytes_left;
- bzero(dst, section_dst_len);
+ memset(dst, 0, section_dst_len);
return section_dst_len;
}
}
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 6edb9390d99..c93d7da965c 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -663,6 +663,7 @@ ProcessLaunchInfo::FileAction::Duplicate (int fd, int dup_fd)
+#ifndef LLDB_DISABLE_POSIX
bool
ProcessLaunchInfo::FileAction::AddPosixSpawnFileAction (posix_spawn_file_actions_t *file_actions,
const FileAction *info,
@@ -733,6 +734,7 @@ ProcessLaunchInfo::FileAction::AddPosixSpawnFileAction (posix_spawn_file_actions
}
return error.Success();
}
+#endif
Error
ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
@@ -3968,15 +3970,15 @@ Process::HandlePrivateEvent (EventSP &event_sp)
m_currently_handling_event.SetValue(false, eBroadcastAlways);
}
-void *
+thread_result_t
Process::PrivateStateThread (void *arg)
{
Process *proc = static_cast<Process*> (arg);
- void *result = proc->RunPrivateStateThread ();
+ thread_result_t result = proc->RunPrivateStateThread();
return result;
}
-void *
+thread_result_t
Process::RunPrivateStateThread ()
{
bool control_only = true;
diff --git a/lldb/source/Utility/PseudoTerminal.cpp b/lldb/source/Utility/PseudoTerminal.cpp
index e4b444c3687..98d581def4c 100644
--- a/lldb/source/Utility/PseudoTerminal.cpp
+++ b/lldb/source/Utility/PseudoTerminal.cpp
@@ -17,6 +17,21 @@
#include <sys/ioctl.h>
#endif
+#ifdef _WIN32
+#include "lldb/Host/windows/win32.h"
+// empty functions
+int posix_openpt(int flag) { return 0; }
+
+int strerror_r(int errnum, char *buf, size_t buflen) { return 0; }
+
+int unlockpt(int fd) { return 0; }
+int grantpt(int fd) { return 0; }
+char *ptsname(int fd) { return 0; }
+
+pid_t fork(void) { return 0; }
+pid_t setsid(void) { return 0; }
+#endif
+
using namespace lldb_utility;
//----------------------------------------------------------------------
diff --git a/lldb/tools/CMakeLists.txt b/lldb/tools/CMakeLists.txt
index e086568229a..960ac22ea9c 100644
--- a/lldb/tools/CMakeLists.txt
+++ b/lldb/tools/CMakeLists.txt
@@ -1,4 +1,7 @@
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_subdirectory(debugserver)
endif()
-add_subdirectory(driver)
+if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
+ add_subdirectory(driver)
+endif()
+
diff --git a/lldb/tools/Makefile b/lldb/tools/Makefile
index 6a4a8ed87cd..4245082f33a 100644
--- a/lldb/tools/Makefile
+++ b/lldb/tools/Makefile
@@ -8,6 +8,10 @@
##===----------------------------------------------------------------------===##
LLDB_LEVEL := ..
+include $(LLDB_LEVEL)/../../Makefile.config
+
+ifneq ($(HOST_OS),MingW)
DIRS := driver lldb-platform
+endif
include $(LLDB_LEVEL)/Makefile
OpenPOWER on IntegriCloud