diff options
Diffstat (limited to 'lldb/test/python_api')
-rw-r--r-- | lldb/test/python_api/lldbutil/iter/Makefile | 4 | ||||
-rw-r--r-- | lldb/test/python_api/lldbutil/iter/main.cpp | 46 | ||||
-rw-r--r-- | lldb/test/python_api/lldbutil/process/Makefile | 2 | ||||
-rw-r--r-- | lldb/test/python_api/lldbutil/process/main.cpp | 44 | ||||
-rw-r--r-- | lldb/test/python_api/module_section/Makefile | 2 | ||||
-rw-r--r-- | lldb/test/python_api/module_section/main.cpp | 44 | ||||
-rw-r--r-- | lldb/test/python_api/signals/main.cpp | 8 | ||||
-rw-r--r-- | lldb/test/python_api/watchpoint/watchlocation/Makefile | 2 |
8 files changed, 91 insertions, 61 deletions
diff --git a/lldb/test/python_api/lldbutil/iter/Makefile b/lldb/test/python_api/lldbutil/iter/Makefile index 190194e2ebc..3952b1acff1 100644 --- a/lldb/test/python_api/lldbutil/iter/Makefile +++ b/lldb/test/python_api/lldbutil/iter/Makefile @@ -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 diff --git a/lldb/test/python_api/lldbutil/iter/main.cpp b/lldb/test/python_api/lldbutil/iter/main.cpp index c7dcba4884c..8fb45f94b1e 100644 --- a/lldb/test/python_api/lldbutil/iter/main.cpp +++ b/lldb/test/python_api/lldbutil/iter/main.cpp @@ -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 = 0); 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 mask) 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; } diff --git a/lldb/test/python_api/lldbutil/process/Makefile b/lldb/test/python_api/lldbutil/process/Makefile index 190194e2ebc..6c249e519d3 100644 --- a/lldb/test/python_api/lldbutil/process/Makefile +++ b/lldb/test/python_api/lldbutil/process/Makefile @@ -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 diff --git a/lldb/test/python_api/lldbutil/process/main.cpp b/lldb/test/python_api/lldbutil/process/main.cpp index c7dcba4884c..6b87c3d649e 100644 --- a/lldb/test/python_api/lldbutil/process/main.cpp +++ b/lldb/test/python_api/lldbutil/process/main.cpp @@ -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 = 0); 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 mask) 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; } diff --git a/lldb/test/python_api/module_section/Makefile b/lldb/test/python_api/module_section/Makefile index 7b5f11134bf..956077500f1 100644 --- a/lldb/test/python_api/module_section/Makefile +++ b/lldb/test/python_api/module_section/Makefile @@ -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 diff --git a/lldb/test/python_api/module_section/main.cpp b/lldb/test/python_api/module_section/main.cpp index c7dcba4884c..6b87c3d649e 100644 --- a/lldb/test/python_api/module_section/main.cpp +++ b/lldb/test/python_api/module_section/main.cpp @@ -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 = 0); 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 mask) 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; } diff --git a/lldb/test/python_api/signals/main.cpp b/lldb/test/python_api/signals/main.cpp index ddd2ffe5fb2..81924f435a1 100644 --- a/lldb/test/python_api/signals/main.cpp +++ b/lldb/test/python_api/signals/main.cpp @@ -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; } diff --git a/lldb/test/python_api/watchpoint/watchlocation/Makefile b/lldb/test/python_api/watchpoint/watchlocation/Makefile index 2af752bd465..8817fff55e8 100644 --- a/lldb/test/python_api/watchpoint/watchlocation/Makefile +++ b/lldb/test/python_api/watchpoint/watchlocation/Makefile @@ -1,6 +1,6 @@ LEVEL = ../../../make -LD_EXTRAS := -lpthread +ENABLE_THREADS := YES CXX_SOURCES := main.cpp include $(LEVEL)/Makefile.rules |