[Lldb-commits] [lldb] r215562 - Get test executables compiling on Windows.

Zachary Turner zturner at google.com
Wed Aug 13 10:44:53 PDT 2014


Author: zturner
Date: Wed Aug 13 12:44:53 2014
New Revision: 215562

URL: http://llvm.org/viewvc/llvm-project?rev=215562&view=rev
Log:
Get test executables compiling on Windows.

Many of the test executables use pthreads directly.  This isn't
portable on Windows, so this patch converts these test to use
C++11 threads and mutexes.  Since Windows' implementation of
std::thread classes throw and catch from header files, this patch
also disables exceptions when compiling with clang on Windows.

Reviewed by: Todd Fiala, Ed Maste

Differential Revision: http://reviews.llvm.org/D4816

Added:
    lldb/trunk/test/expression_command/timeout/wait-a-while.cpp
    lldb/trunk/test/functionalities/attach_resume/main.cpp
      - copied, changed from r215488, lldb/trunk/test/functionalities/attach_resume/main.c
    lldb/trunk/test/make/uncaught_exception.h
Removed:
    lldb/trunk/test/expression_command/timeout/wait-a-while.c
    lldb/trunk/test/functionalities/attach_resume/main.c
Modified:
    lldb/trunk/test/api/multiple-debuggers/multi-process-driver.cpp
    lldb/trunk/test/expression_command/call-restarts/TestCallThatRestarts.py
    lldb/trunk/test/expression_command/timeout/Makefile
    lldb/trunk/test/expression_command/timeout/TestCallWithTimeout.py
    lldb/trunk/test/functionalities/attach_resume/Makefile
    lldb/trunk/test/functionalities/attach_resume/TestAttachResume.py
    lldb/trunk/test/functionalities/expr-doesnt-deadlock/Makefile
    lldb/trunk/test/functionalities/stop-hook/multiple_threads/Makefile
    lldb/trunk/test/functionalities/thread/Makefile
    lldb/trunk/test/functionalities/thread/concurrent_events/Makefile
    lldb/trunk/test/functionalities/thread/step_out/Makefile
    lldb/trunk/test/functionalities/thread/thread_specific_break/Makefile
    lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/Makefile
    lldb/trunk/test/functionalities/watchpoint/multiple_threads/Makefile
    lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/Makefile
    lldb/trunk/test/lang/c/tls_globals/Makefile
    lldb/trunk/test/lldbtest.py
    lldb/trunk/test/make/Makefile.rules
    lldb/trunk/test/python_api/lldbutil/iter/Makefile
    lldb/trunk/test/python_api/lldbutil/iter/main.cpp
    lldb/trunk/test/python_api/lldbutil/process/Makefile
    lldb/trunk/test/python_api/lldbutil/process/main.cpp
    lldb/trunk/test/python_api/module_section/Makefile
    lldb/trunk/test/python_api/module_section/main.cpp
    lldb/trunk/test/python_api/signals/main.cpp
    lldb/trunk/test/python_api/watchpoint/watchlocation/Makefile
    lldb/trunk/test/tools/lldb-gdbserver/Makefile

Modified: lldb/trunk/test/api/multiple-debuggers/multi-process-driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/api/multiple-debuggers/multi-process-driver.cpp?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/api/multiple-debuggers/multi-process-driver.cpp (original)
+++ lldb/trunk/test/api/multiple-debuggers/multi-process-driver.cpp Wed Aug 13 12:44:53 2014
@@ -29,6 +29,9 @@
 #include <lldb/API/SBDebugger.h>
 #endif
 
+#include <chrono>
+#include <thread>
+
 #define NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS 50
 
 #define DEBUG 0
@@ -233,10 +236,10 @@ int main (int argc, char **argv)
         inferior_process_name = argv[1];
     }
 
+    std::thread threads[NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS];
     for (uint64_t i = 0; i< NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS; i++)
     {
-        pthread_t thread;
-        pthread_create (&thread, NULL, do_one_debugger, (void*) i);
+        threads[i] = std::move(std::thread(do_one_debugger, (void*)i));
     }
 
 
@@ -244,7 +247,7 @@ int main (int argc, char **argv)
     int iter = 0;
     while (1)
     {
-        sleep (3);
+        std::this_thread::sleep_for(std::chrono::seconds(3));
         bool all_done = true;
         int successful_threads = 0;
         int total_completed_threads = 0;

Modified: lldb/trunk/test/expression_command/call-restarts/TestCallThatRestarts.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/call-restarts/TestCallThatRestarts.py?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/expression_command/call-restarts/TestCallThatRestarts.py (original)
+++ lldb/trunk/test/expression_command/call-restarts/TestCallThatRestarts.py Wed Aug 13 12:44:53 2014
@@ -30,6 +30,7 @@ class ExprCommandThatRestartsTestCase(Te
     @dwarf_test
     @skipIfLinux # llvm.org/pr19246: intermittent failure
     @skipIfDarwin # llvm.org/pr19246: intermittent failure
+    @skipIfWindows # Test relies on signals, unsupported on Windows
     def test_with_dwarf(self):
         """Test calling std::String member function."""
         self.buildDwarf()

Modified: lldb/trunk/test/expression_command/timeout/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/timeout/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/expression_command/timeout/Makefile (original)
+++ lldb/trunk/test/expression_command/timeout/Makefile Wed Aug 13 12:44:53 2014
@@ -1,5 +1,5 @@
 LEVEL = ../../make
 
-C_SOURCES := wait-a-while.c
+CXX_SOURCES := wait-a-while.cpp
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/expression_command/timeout/TestCallWithTimeout.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/timeout/TestCallWithTimeout.py?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/expression_command/timeout/TestCallWithTimeout.py (original)
+++ lldb/trunk/test/expression_command/timeout/TestCallWithTimeout.py Wed Aug 13 12:44:53 2014
@@ -15,7 +15,7 @@ class ExprCommandWithTimeoutsTestCase(Te
         # Call super's setUp().
         TestBase.setUp(self)
 
-        self.main_source = "wait-a-while.c"
+        self.main_source = "wait-a-while.cpp"
         self.main_source_spec = lldb.SBFileSpec (self.main_source)
 
 

Removed: lldb/trunk/test/expression_command/timeout/wait-a-while.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/timeout/wait-a-while.c?rev=215561&view=auto
==============================================================================
--- lldb/trunk/test/expression_command/timeout/wait-a-while.c (original)
+++ lldb/trunk/test/expression_command/timeout/wait-a-while.c (removed)
@@ -1,41 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <stdint.h>
-
-int 
-wait_a_while (useconds_t interval)
-{
-  int num_times = 0;
-  int return_value = 1;
-
-  struct timeval start_time;
-  gettimeofday(&start_time, NULL);
-  uint64_t target = start_time.tv_sec * 1000000 + start_time.tv_usec + interval;
-
-  while (1)
-    {
-      num_times++;
-      return_value = usleep (interval);
-      if (return_value != 0)
-        {
-          struct timeval now;
-          gettimeofday(&now, NULL);
-          interval = target - (now.tv_sec * 1000000 + now.tv_usec);
-        }
-      else
-        break;
-    }
-  return num_times;
-}
-
-int
-main (int argc, char **argv)
-{
-  printf ("stop here in main.\n");
-  int num_times = wait_a_while (argc * 1000);
-  printf ("Done, took %d times.\n", num_times);
-
-  return 0;
-
-}

Added: lldb/trunk/test/expression_command/timeout/wait-a-while.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/timeout/wait-a-while.cpp?rev=215562&view=auto
==============================================================================
--- lldb/trunk/test/expression_command/timeout/wait-a-while.cpp (added)
+++ lldb/trunk/test/expression_command/timeout/wait-a-while.cpp Wed Aug 13 12:44:53 2014
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdint.h>
+
+#include <chrono>
+#include <thread>
+
+
+int
+wait_a_while (int microseconds)
+{
+    int num_times = 0;
+
+    while (1)
+    {
+        num_times++;
+        std::this_thread::sleep_for(std::chrono::microseconds(microseconds));
+        break;
+    }
+    return num_times;
+}
+
+int
+main (int argc, char **argv)
+{
+    printf ("stop here in main.\n");
+    int num_times = wait_a_while (argc * 1000);
+    printf ("Done, took %d times.\n", num_times);
+
+    return 0;
+
+}

Modified: lldb/trunk/test/functionalities/attach_resume/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/attach_resume/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/attach_resume/Makefile (original)
+++ lldb/trunk/test/functionalities/attach_resume/Makefile Wed Aug 13 12:44:53 2014
@@ -1,8 +1,7 @@
 LEVEL = ../../make
 
-C_SOURCES := main.c
-LD_EXTRAS := -lpthread
-
+CXX_SOURCES := main.cpp
+ENABLE_THREADS := Yes
 EXE := AttachResume
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/functionalities/attach_resume/TestAttachResume.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/attach_resume/TestAttachResume.py?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/attach_resume/TestAttachResume.py (original)
+++ lldb/trunk/test/functionalities/attach_resume/TestAttachResume.py Wed Aug 13 12:44:53 2014
@@ -70,7 +70,7 @@ class AttachResumeTestCase(TestBase):
             'Process not stopped after interrupt')
 
         # check that this breakpoint is auto-cleared on detach (r204752)
-        self.runCmd("br set -f main.c -l 12")
+        self.runCmd("br set -f main.cpp -l 12")
 
         self.runCmd("c")
         self.assertTrue(wait_for_state(lldb.eStateRunning),

Removed: lldb/trunk/test/functionalities/attach_resume/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/attach_resume/main.c?rev=215561&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/attach_resume/main.c (original)
+++ lldb/trunk/test/functionalities/attach_resume/main.c (removed)
@@ -1,32 +0,0 @@
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <pthread.h>
-
-void *start(void *data)
-{
-    int i;
-    size_t idx = (size_t)data;
-    for (i=0; i<30; i++)
-    {
-        if ( idx == 0 )
-            usleep(1);
-        sleep(1);
-    }
-    return 0;
-}
-
-int main(int argc, char const *argv[])
-{
-    static const size_t nthreads = 16;
-    pthread_attr_t attr;
-    pthread_t threads[nthreads];
-    size_t i;
-
-    pthread_attr_init(&attr);
-    for (i=0; i<nthreads; i++)
-        pthread_create(&threads[i], &attr, &start, (void *)i);
-
-    for (i=0; i<nthreads; i++)
-        pthread_join(threads[i], 0);
-}

Copied: lldb/trunk/test/functionalities/attach_resume/main.cpp (from r215488, lldb/trunk/test/functionalities/attach_resume/main.c)
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/attach_resume/main.cpp?p2=lldb/trunk/test/functionalities/attach_resume/main.cpp&p1=lldb/trunk/test/functionalities/attach_resume/main.c&r1=215488&r2=215562&rev=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/attach_resume/main.c (original)
+++ lldb/trunk/test/functionalities/attach_resume/main.cpp Wed Aug 13 12:44:53 2014
@@ -1,7 +1,8 @@
-#include <unistd.h>
 #include <stdio.h>
 #include <fcntl.h>
-#include <pthread.h>
+
+#include <chrono>
+#include <thread>
 
 void *start(void *data)
 {
@@ -10,8 +11,8 @@ void *start(void *data)
     for (i=0; i<30; i++)
     {
         if ( idx == 0 )
-            usleep(1);
-        sleep(1);
+            std::this_thread::sleep_for(std::chrono::microseconds(1));
+        std::this_thread::sleep_for(std::chrono::seconds(1));
     }
     return 0;
 }
@@ -19,14 +20,12 @@ void *start(void *data)
 int main(int argc, char const *argv[])
 {
     static const size_t nthreads = 16;
-    pthread_attr_t attr;
-    pthread_t threads[nthreads];
+    std::thread threads[nthreads];
     size_t i;
 
-    pthread_attr_init(&attr);
     for (i=0; i<nthreads; i++)
-        pthread_create(&threads[i], &attr, &start, (void *)i);
+        threads[i] = std::move(std::thread(start, (void*)i));
 
     for (i=0; i<nthreads; i++)
-        pthread_join(threads[i], 0);
+        threads[i].join();
 }

Modified: lldb/trunk/test/functionalities/expr-doesnt-deadlock/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/expr-doesnt-deadlock/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/expr-doesnt-deadlock/Makefile (original)
+++ lldb/trunk/test/functionalities/expr-doesnt-deadlock/Makefile Wed Aug 13 12:44:53 2014
@@ -1,6 +1,6 @@
 LEVEL = ../../make
 
-CFLAGS_EXTRAS := -lpthread
 C_SOURCES := locking.c
+ENABLE_THREADS := YES
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/functionalities/stop-hook/multiple_threads/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/stop-hook/multiple_threads/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/stop-hook/multiple_threads/Makefile (original)
+++ lldb/trunk/test/functionalities/stop-hook/multiple_threads/Makefile Wed Aug 13 12:44:53 2014
@@ -1,6 +1,6 @@
 LEVEL = ../../../make
 
-LD_EXTRAS := -lpthread
 CXX_SOURCES := main.cpp
+ENABLE_THREADS := YES
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/functionalities/thread/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/thread/Makefile (original)
+++ lldb/trunk/test/functionalities/thread/Makefile Wed Aug 13 12:44:53 2014
@@ -1,5 +1,5 @@
 LEVEL = ../../make
 
 C_SOURCES := main.c
-LD_EXTRAS := -lpthread
+ENABLE_THREADS := YES
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/functionalities/thread/concurrent_events/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/concurrent_events/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/thread/concurrent_events/Makefile (original)
+++ lldb/trunk/test/functionalities/thread/concurrent_events/Makefile Wed Aug 13 12:44:53 2014
@@ -2,7 +2,6 @@ LEVEL = ../../../make
 
 CXX_SOURCES := main.cpp
 
-CFLAGS_EXTRAS += -std=c++11 -lpthread
-LD_EXTRAS += -lpthread
+ENABLE_THREADS := YES
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/functionalities/thread/step_out/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/step_out/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/thread/step_out/Makefile (original)
+++ lldb/trunk/test/functionalities/thread/step_out/Makefile Wed Aug 13 12:44:53 2014
@@ -1,7 +1,6 @@
 LEVEL = ../../../make
-CXX_SOURCES := main.cpp
-LD_EXTRAS := -lpthread
 
-CFLAGS_EXTRAS += -std=c++11
+CXX_SOURCES := main.cpp
+ENABLE_THREADS := YES
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/functionalities/thread/thread_specific_break/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/thread_specific_break/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/thread/thread_specific_break/Makefile (original)
+++ lldb/trunk/test/functionalities/thread/thread_specific_break/Makefile Wed Aug 13 12:44:53 2014
@@ -1,6 +1,6 @@
 LEVEL = ../../../make
 
 C_SOURCES := main.c
-LD_EXTRAS := -lpthread
+ENABLE_THREADS := YES
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/Makefile (original)
+++ lldb/trunk/test/functionalities/watchpoint/hello_watchlocation/Makefile Wed Aug 13 12:44:53 2014
@@ -1,6 +1,6 @@
 LEVEL = ../../../make
 
-LD_EXTRAS := -lpthread
+ENABLE_THREADS := YES
 CXX_SOURCES := main.cpp
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/functionalities/watchpoint/multiple_threads/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/multiple_threads/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/watchpoint/multiple_threads/Makefile (original)
+++ lldb/trunk/test/functionalities/watchpoint/multiple_threads/Makefile Wed Aug 13 12:44:53 2014
@@ -1,6 +1,6 @@
 LEVEL = ../../../make
 
-LD_EXTRAS := -lpthread
+ENABLE_THREADS := YES
 CXX_SOURCES := main.cpp
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/Makefile (original)
+++ lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/Makefile Wed Aug 13 12:44:53 2014
@@ -1,6 +1,6 @@
 LEVEL = ../../../make
 
-LD_EXTRAS := -lpthread
+ENABLE_THREADS := YES
 CXX_SOURCES := main.cpp
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/lang/c/tls_globals/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/tls_globals/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/lang/c/tls_globals/Makefile (original)
+++ lldb/trunk/test/lang/c/tls_globals/Makefile Wed Aug 13 12:44:53 2014
@@ -6,6 +6,6 @@ CFLAGS_EXTRAS += -fPIC
 DYLIB_NAME := a
 DYLIB_C_SOURCES := a.c
 
-LD_EXTRAS += -lpthread
+ENABLE_THREADS := YES
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Wed Aug 13 12:44:53 2014
@@ -554,6 +554,21 @@ def skipIfLinux(func):
             func(*args, **kwargs)
     return wrapper
 
+def skipIfWindows(func):
+    """Decorate the item to skip tests that should be skipped on Windows."""
+    if isinstance(func, type) and issubclass(func, unittest2.TestCase):
+        raise Exception("@skipIfWindows can only be used to decorate a test method")
+    @wraps(func)
+    def wrapper(*args, **kwargs):
+        from unittest2 import case
+        self = args[0]
+        platform = sys.platform
+        if "win32" in platform:
+            self.skipTest("skip on Windows")
+        else:
+            func(*args, **kwargs)
+    return wrapper
+
 def skipIfDarwin(func):
     """Decorate the item to skip tests that should be skipped on Darwin."""
     if isinstance(func, type) and issubclass(func, unittest2.TestCase):

Modified: lldb/trunk/test/make/Makefile.rules
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/make/Makefile.rules?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/make/Makefile.rules (original)
+++ lldb/trunk/test/make/Makefile.rules Wed Aug 13 12:44:53 2014
@@ -26,6 +26,9 @@
 # Uncomment line below for debugging shell commands
 # SHELL = /bin/sh -x
 
+THIS_FILE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
+LLDB_BASE_DIR := $(THIS_FILE_DIR)../../
+
 #----------------------------------------------------------------------
 # If ARCH is not defined, default to x86_64.
 # If OS is not defined, use 'uname -s' to determine the OS name.
@@ -73,7 +76,7 @@ else
 	# 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))
@@ -84,6 +87,9 @@ else
 	ifeq "$(ARCH)" "x64"
 		override ARCH := $(subst x64,64,$(ARCH))
 	endif
+	ifeq "$(ARCH)" "x86"
+		override ARCH := $(subst x86,32,$(ARCH))
+	endif
 	ifeq "$(ARCH)" "i386"
 		override ARCH := $(subst i386,32,$(ARCH))
 	endif
@@ -97,15 +103,21 @@ else
 endif
 
 CFLAGS ?= -g -O0
-CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS)
+CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
 
 # Use this one if you want to build one part of the result without debug information:
 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS)
 
-CXXFLAGS +=$(CFLAGS)
+CXXFLAGS += -std=c++11
+CXXFLAGS += $(CFLAGS)
 LD = $(CC)
 LDFLAGS ?= $(CFLAGS)
 LDFLAGS += $(LD_EXTRAS)
+ifneq "$(OS)" "Windows_NT"
+	ifeq "$(ENABLE_THREADS)" "Yes"
+		LDFLAGS += -lpthread
+	endif
+endif
 OBJECTS =
 EXE ?= a.out
 
@@ -126,6 +138,17 @@ cxx_linker_notdir = $(if $(findstring cl
 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 $(THIS_FILE_DIR)uncaught_exception.h
+		CXXFLAGS += -D_HAS_EXCEPTIONS=0
+	endif
+endif
+
+#----------------------------------------------------------------------
 # C++ standard library options
 #----------------------------------------------------------------------
 ifeq (1,$(USE_LIBSTDCPP))

Added: lldb/trunk/test/make/uncaught_exception.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/make/uncaught_exception.h?rev=215562&view=auto
==============================================================================
--- lldb/trunk/test/make/uncaught_exception.h (added)
+++ lldb/trunk/test/make/uncaught_exception.h Wed Aug 13 12:44:53 2014
@@ -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; }

Modified: lldb/trunk/test/python_api/lldbutil/iter/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/lldbutil/iter/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/python_api/lldbutil/iter/Makefile (original)
+++ lldb/trunk/test/python_api/lldbutil/iter/Makefile Wed Aug 13 12:44:53 2014
@@ -1,8 +1,8 @@
 LEVEL = ../../../make
 
 CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS
-LD_EXTRAS := -lpthread
+ENABLE_THREADS := YES
 CXX_SOURCES := main.cpp
-MAKE_DSYM :=NO
+MAKE_DSYM := NO
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/python_api/lldbutil/iter/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/lldbutil/iter/main.cpp?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/python_api/lldbutil/iter/main.cpp (original)
+++ lldb/trunk/test/python_api/lldbutil/iter/main.cpp Wed Aug 13 12:44:53 2014
@@ -8,15 +8,20 @@
 //===----------------------------------------------------------------------===//
 
 // C includes
-#include <pthread.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <unistd.h>
 
-pthread_t g_thread_1 = NULL;
-pthread_t g_thread_2 = NULL;
-pthread_t g_thread_3 = NULL;
+// C++ includes
+#include <chrono>
+#include <mutex>
+#include <random>
+#include <thread>
+
+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_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<std::mutex> lock(g_mask_mutex);
     switch (action)
     {
     case eGet:
@@ -45,9 +50,7 @@ mask_access (MaskAction action, uint32_t
         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 @@ thread_func (void *arg)
     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<int> 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 @@ thread_func (void *arg)
 
 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 @@ int main (int argc, char const *argv[])
     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 @@ int main (int argc, char const *argv[])
     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;
 }

Modified: lldb/trunk/test/python_api/lldbutil/process/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/lldbutil/process/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/python_api/lldbutil/process/Makefile (original)
+++ lldb/trunk/test/python_api/lldbutil/process/Makefile Wed Aug 13 12:44:53 2014
@@ -1,7 +1,7 @@
 LEVEL = ../../../make
 
 CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS
-LD_EXTRAS := -lpthread
+ENABLE_THREADS := YES
 CXX_SOURCES := main.cpp
 MAKE_DSYM :=NO
 

Modified: lldb/trunk/test/python_api/lldbutil/process/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/lldbutil/process/main.cpp?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/python_api/lldbutil/process/main.cpp (original)
+++ lldb/trunk/test/python_api/lldbutil/process/main.cpp Wed Aug 13 12:44:53 2014
@@ -8,15 +8,20 @@
 //===----------------------------------------------------------------------===//
 
 // C includes
-#include <pthread.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <unistd.h>
 
-pthread_t g_thread_1 = NULL;
-pthread_t g_thread_2 = NULL;
-pthread_t g_thread_3 = NULL;
+// C++ includes
+#include <chrono>
+#include <mutex>
+#include <random>
+#include <thread>
+
+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_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<std::mutex> lock(g_mask_mutex);
     switch (action)
     {
     case eGet:
@@ -45,9 +50,7 @@ mask_access (MaskAction action, uint32_t
         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 @@ thread_func (void *arg)
     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<int> 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 @@ int main (int argc, char const *argv[])
     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 @@ int main (int argc, char const *argv[])
     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;
 }

Modified: lldb/trunk/test/python_api/module_section/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/module_section/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/python_api/module_section/Makefile (original)
+++ lldb/trunk/test/python_api/module_section/Makefile Wed Aug 13 12:44:53 2014
@@ -1,7 +1,7 @@
 LEVEL = ../../make
 
 CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS
-LD_EXTRAS := -lpthread
+ENABLE_THREADS := YES
 CXX_SOURCES := main.cpp b.cpp c.cpp
 MAKE_DSYM :=NO
 

Modified: lldb/trunk/test/python_api/module_section/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/module_section/main.cpp?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/python_api/module_section/main.cpp (original)
+++ lldb/trunk/test/python_api/module_section/main.cpp Wed Aug 13 12:44:53 2014
@@ -8,15 +8,20 @@
 //===----------------------------------------------------------------------===//
 
 // C includes
-#include <pthread.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <unistd.h>
 
-pthread_t g_thread_1 = NULL;
-pthread_t g_thread_2 = NULL;
-pthread_t g_thread_3 = NULL;
+// C++ includes
+#include <chrono>
+#include <mutex>
+#include <random>
+#include <thread>
+
+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_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<std::mutex> lock(g_mask_mutex);
     switch (action)
     {
     case eGet:
@@ -45,9 +50,7 @@ mask_access (MaskAction action, uint32_t
         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 @@ thread_func (void *arg)
     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<int> 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 @@ int main (int argc, char const *argv[])
     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 @@ int main (int argc, char const *argv[])
     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;
 }

Modified: lldb/trunk/test/python_api/signals/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/signals/main.cpp?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/python_api/signals/main.cpp (original)
+++ lldb/trunk/test/python_api/signals/main.cpp Wed Aug 13 12:44:53 2014
@@ -8,13 +8,21 @@
 //===----------------------------------------------------------------------===//
 #include <stdio.h>
 #include <sys/types.h>
+#if defined(_WIN32)
+#include <windows.h>
+#else
 #include <unistd.h>
 #include <signal.h>
+#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;
 }

Modified: lldb/trunk/test/python_api/watchpoint/watchlocation/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/watchpoint/watchlocation/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/python_api/watchpoint/watchlocation/Makefile (original)
+++ lldb/trunk/test/python_api/watchpoint/watchlocation/Makefile Wed Aug 13 12:44:53 2014
@@ -1,6 +1,6 @@
 LEVEL = ../../../make
 
-LD_EXTRAS := -lpthread
+ENABLE_THREADS := YES
 CXX_SOURCES := main.cpp
 
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/tools/lldb-gdbserver/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-gdbserver/Makefile?rev=215562&r1=215561&r2=215562&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-gdbserver/Makefile (original)
+++ lldb/trunk/test/tools/lldb-gdbserver/Makefile Wed Aug 13 12:44:53 2014
@@ -1,7 +1,7 @@
 LEVEL = ../../make
 
-CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -std=c++11
-LD_EXTRAS := -lpthread
+CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS
+ENABLE_THREADS := YES
 CXX_SOURCES := main.cpp
 MAKE_DSYM :=NO
 





More information about the lldb-commits mailing list