Index: test/make/Makefile.rules =================================================================== --- test/make/Makefile.rules +++ test/make/Makefile.rules @@ -26,6 +26,8 @@ # Uncomment line below for debugging shell commands # SHELL = /bin/sh -x +ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/ + #---------------------------------------------------------------------- # If ARCH is not defined, default to x86_64. # If OS is not defined, use 'uname -s' to determine the OS name. @@ -73,11 +75,14 @@ # On non-Apple platforms, -arch becomes -m ARCHFLAG := -m - # i386,i686 -> 32 + # i386, i686, x86 -> 32 # amd64, x86_64, x64 -> 64 ifeq "$(ARCH)" "amd64" override ARCH := $(subst amd64,64,$(ARCH)) endif + ifeq "$(ARCH)" "x86" + override ARCH := $(subst x86,32,$(ARCH)) + endif ifeq "$(ARCH)" "x86_64" override ARCH := $(subst x86_64,64,$(ARCH)) endif @@ -126,6 +131,17 @@ cxx_linker = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_linker_notdir,$(notdir $(1)))),$(call cxx_linker_notdir,$(1))) #---------------------------------------------------------------------- +# Clang for Windows doesn't yet support exceptions +#---------------------------------------------------------------------- +ifeq "$(OS)" "Windows_NT" + ifneq (,$(findstring clang,$(CC))) + CXXFLAGS += -fno-exceptions + CXXFLAGS += -include $(ROOT_DIR)uncaught_exception.h + CXXFLAGS += -D_HAS_EXCEPTIONS=0 + endif +endif + +#---------------------------------------------------------------------- # C++ standard library options #---------------------------------------------------------------------- ifeq (1,$(USE_LIBSTDCPP)) Index: test/make/uncaught_exception.h =================================================================== --- /dev/null +++ test/make/uncaught_exception.h @@ -0,0 +1,5 @@ +// MSVC header files have compilation issues when compiling with exceptions disabled. Notably, +// this function is compiled out when _HAS_EXCEPTIONS=0, but this function is called from another +// place even when _HAS_EXCEPTIONS=0. So we define a dummy implementation as a workaround and +// force include this header file. +static void *__uncaught_exception() { return nullptr; } \ No newline at end of file Index: test/python_api/lldbutil/iter/Makefile =================================================================== --- test/python_api/lldbutil/iter/Makefile +++ test/python_api/lldbutil/iter/Makefile @@ -1,7 +1,9 @@ LEVEL = ../../../make CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS -LD_EXTRAS := -lpthread +ifneq "$(OS)" "Windows_NT" + LD_EXTRAS := -lpthread +endif CXX_SOURCES := main.cpp MAKE_DSYM :=NO Index: test/python_api/lldbutil/iter/main.cpp =================================================================== --- test/python_api/lldbutil/iter/main.cpp +++ test/python_api/lldbutil/iter/main.cpp @@ -8,15 +8,20 @@ //===----------------------------------------------------------------------===// // C includes -#include #include #include #include -#include -pthread_t g_thread_1 = NULL; -pthread_t g_thread_2 = NULL; -pthread_t g_thread_3 = NULL; +// C++ includes +#include +#include +#include +#include + +std::thread g_thread_1; +std::thread g_thread_2; +std::thread g_thread_3; +std::mutex g_mask_mutex; typedef enum { eGet, @@ -29,9 +34,9 @@ uint32_t mask_access (MaskAction action, uint32_t mask) { - static pthread_mutex_t g_mask_mutex = PTHREAD_MUTEX_INITIALIZER; static uint32_t g_mask = 0; - ::pthread_mutex_lock (&g_mask_mutex); + + std::lock_guard lock(g_mask_mutex); switch (action) { case eGet: @@ -45,9 +50,7 @@ g_mask &= ~mask; break; } - uint32_t new_mask = g_mask; - ::pthread_mutex_unlock (&g_mask_mutex); - return new_mask; + return g_mask; } void * @@ -57,12 +60,17 @@ uint32_t thread_mask = (1u << (thread_index)); printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index); + std::default_random_engine generator; + std::uniform_int_distribution distribution(0, 3000000); + while (mask_access(eGet) & thread_mask) { // random micro second sleep from zero to 3 seconds - int usec = ::rand() % 3000000; + int usec = distribution(generator); printf ("%s (thread = %u) doing a usleep (%d)...\n", __FUNCTION__, thread_index, usec); - ::usleep (usec); + + std::chrono::microseconds duration(usec); + std::this_thread::sleep_for(duration); printf ("%s (thread = %u) after usleep ...\n", __FUNCTION__, thread_index); // Set break point at this line. } printf ("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index); @@ -72,8 +80,6 @@ int main (int argc, char const *argv[]) { - int err; - void *thread_result = NULL; uint32_t thread_index_1 = 1; uint32_t thread_index_2 = 2; uint32_t thread_index_3 = 3; @@ -85,9 +91,9 @@ mask_access (eAssign, thread_mask_1 | thread_mask_2 | thread_mask_3); // And that line. // Create 3 threads - err = ::pthread_create (&g_thread_1, NULL, thread_func, &thread_index_1); - err = ::pthread_create (&g_thread_2, NULL, thread_func, &thread_index_2); - err = ::pthread_create (&g_thread_3, NULL, thread_func, &thread_index_3); + g_thread_1 = std::thread(thread_func, (void*)&thread_index_1); + g_thread_2 = std::thread(thread_func, (void*)&thread_index_2); + g_thread_3 = std::thread(thread_func, (void*)&thread_index_3); char line[64]; while (mask_access(eGet) != 0) @@ -120,9 +126,9 @@ mask_access (eClearBits, UINT32_MAX); // Join all of our threads - err = ::pthread_join (g_thread_1, &thread_result); - err = ::pthread_join (g_thread_2, &thread_result); - err = ::pthread_join (g_thread_3, &thread_result); + g_thread_1.join(); + g_thread_2.join(); + g_thread_3.join(); return 0; } Index: test/python_api/lldbutil/process/Makefile =================================================================== --- test/python_api/lldbutil/process/Makefile +++ test/python_api/lldbutil/process/Makefile @@ -1,7 +1,9 @@ LEVEL = ../../../make CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS -LD_EXTRAS := -lpthread +ifneq "$(OS)" "Windows_NT" + LD_EXTRAS := -lpthread +endif CXX_SOURCES := main.cpp MAKE_DSYM :=NO Index: test/python_api/lldbutil/process/main.cpp =================================================================== --- test/python_api/lldbutil/process/main.cpp +++ test/python_api/lldbutil/process/main.cpp @@ -8,15 +8,20 @@ //===----------------------------------------------------------------------===// // C includes -#include #include #include #include -#include -pthread_t g_thread_1 = NULL; -pthread_t g_thread_2 = NULL; -pthread_t g_thread_3 = NULL; +// C++ includes +#include +#include +#include +#include + +std::thread g_thread_1; +std::thread g_thread_2; +std::thread g_thread_3; +std::mutex g_mask_mutex; typedef enum { eGet, @@ -29,9 +34,9 @@ uint32_t mask_access (MaskAction action, uint32_t mask) { - static pthread_mutex_t g_mask_mutex = PTHREAD_MUTEX_INITIALIZER; static uint32_t g_mask = 0; - ::pthread_mutex_lock (&g_mask_mutex); + + std::lock_guard lock(g_mask_mutex); switch (action) { case eGet: @@ -45,9 +50,7 @@ g_mask &= ~mask; break; } - uint32_t new_mask = g_mask; - ::pthread_mutex_unlock (&g_mask_mutex); - return new_mask; + return g_mask; } void * @@ -57,12 +60,17 @@ uint32_t thread_mask = (1u << (thread_index)); printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index); + std::default_random_engine generator; + std::uniform_int_distribution distribution(0, 3000000); + while (mask_access(eGet) & thread_mask) { // random micro second sleep from zero to 3 seconds - int usec = ::rand() % 3000000; + int usec = distribution(generator); + printf ("%s (thread = %u) doing a usleep (%d)...\n", __FUNCTION__, thread_index, usec); - ::usleep (usec); + std::chrono::microseconds duration(usec); + std::this_thread::sleep_for(duration); printf ("%s (thread = %u) after usleep ...\n", __FUNCTION__, thread_index); // Set break point at this line. } printf ("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index); @@ -85,9 +93,9 @@ mask_access (eAssign, thread_mask_1 | thread_mask_2 | thread_mask_3); // And that line. // Create 3 threads - err = ::pthread_create (&g_thread_1, NULL, thread_func, &thread_index_1); - err = ::pthread_create (&g_thread_2, NULL, thread_func, &thread_index_2); - err = ::pthread_create (&g_thread_3, NULL, thread_func, &thread_index_3); + g_thread_1 = std::thread(thread_func, (void*)&thread_index_1); + g_thread_2 = std::thread(thread_func, (void*)&thread_index_2); + g_thread_3 = std::thread(thread_func, (void*)&thread_index_3); char line[64]; while (mask_access(eGet) != 0) @@ -120,9 +128,9 @@ mask_access (eClearBits, UINT32_MAX); // Join all of our threads - err = ::pthread_join (g_thread_1, &thread_result); - err = ::pthread_join (g_thread_2, &thread_result); - err = ::pthread_join (g_thread_3, &thread_result); + g_thread_1.join(); + g_thread_2.join(); + g_thread_3.join(); return 0; } Index: test/python_api/module_section/Makefile =================================================================== --- test/python_api/module_section/Makefile +++ test/python_api/module_section/Makefile @@ -1,7 +1,9 @@ LEVEL = ../../make CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS -LD_EXTRAS := -lpthread +ifneq "$(OS)" "Windows_NT" + LD_EXTRAS := -lpthread +endif CXX_SOURCES := main.cpp b.cpp c.cpp MAKE_DSYM :=NO Index: test/python_api/module_section/main.cpp =================================================================== --- test/python_api/module_section/main.cpp +++ test/python_api/module_section/main.cpp @@ -8,15 +8,20 @@ //===----------------------------------------------------------------------===// // C includes -#include #include #include #include -#include -pthread_t g_thread_1 = NULL; -pthread_t g_thread_2 = NULL; -pthread_t g_thread_3 = NULL; +// C++ includes +#include +#include +#include +#include + +std::thread g_thread_1; +std::thread g_thread_2; +std::thread g_thread_3; +std::mutex g_mask_mutex; typedef enum { eGet, @@ -29,9 +34,9 @@ uint32_t mask_access (MaskAction action, uint32_t mask) { - static pthread_mutex_t g_mask_mutex = PTHREAD_MUTEX_INITIALIZER; static uint32_t g_mask = 0; - ::pthread_mutex_lock (&g_mask_mutex); + + std::lock_guard lock(g_mask_mutex); switch (action) { case eGet: @@ -45,9 +50,7 @@ g_mask &= ~mask; break; } - uint32_t new_mask = g_mask; - ::pthread_mutex_unlock (&g_mask_mutex); - return new_mask; + return g_mask; } void * @@ -57,12 +60,17 @@ uint32_t thread_mask = (1u << (thread_index)); printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index); + std::default_random_engine generator; + std::uniform_int_distribution distribution(0, 3000000); + while (mask_access(eGet) & thread_mask) { // random micro second sleep from zero to 3 seconds - int usec = ::rand() % 3000000; + int usec = distribution(generator); + printf ("%s (thread = %u) doing a usleep (%d)...\n", __FUNCTION__, thread_index, usec); - ::usleep (usec); + std::chrono::microseconds duration(usec); + std::this_thread::sleep_for(duration); printf ("%s (thread = %u) after usleep ...\n", __FUNCTION__, thread_index); // Set break point at this line. } printf ("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index); @@ -85,9 +93,9 @@ mask_access (eAssign, thread_mask_1 | thread_mask_2 | thread_mask_3); // And that line. // Create 3 threads - err = ::pthread_create (&g_thread_1, NULL, thread_func, &thread_index_1); - err = ::pthread_create (&g_thread_2, NULL, thread_func, &thread_index_2); - err = ::pthread_create (&g_thread_3, NULL, thread_func, &thread_index_3); + g_thread_1 = std::thread(thread_func, (void*)&thread_index_1); + g_thread_2 = std::thread(thread_func, (void*)&thread_index_2); + g_thread_3 = std::thread(thread_func, (void*)&thread_index_3); char line[64]; while (mask_access(eGet) != 0) @@ -120,9 +128,9 @@ mask_access (eClearBits, UINT32_MAX); // Join all of our threads - err = ::pthread_join (g_thread_1, &thread_result); - err = ::pthread_join (g_thread_2, &thread_result); - err = ::pthread_join (g_thread_3, &thread_result); + g_thread_1.join(); + g_thread_2.join(); + g_thread_3.join(); return 0; } Index: test/python_api/signals/main.cpp =================================================================== --- test/python_api/signals/main.cpp +++ test/python_api/signals/main.cpp @@ -8,13 +8,21 @@ //===----------------------------------------------------------------------===// #include #include +#if defined(_WIN32) +#include +#else #include #include +#endif // This simple program is to test the lldb Python API related to process. int main (int argc, char const *argv[]) { +#if defined(_WIN32) + ::ExitProcess(1); +#else kill(getpid(), SIGINT); // Set break point at this line and setup signal ignores. +#endif return 0; }