summaryrefslogtreecommitdiffstats
path: root/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2016-01-06 20:12:03 +0000
committerdim <dim@FreeBSD.org>2016-01-06 20:12:03 +0000
commit78b9749c0a4ea980a8b934645da6ae98fcc665e8 (patch)
treedd2a1ddf0476664c2b823409c36cbccd52662ca7 /packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break
parent60cb593f9d55fa5ca7a5372b731f2330345b4b9a (diff)
downloadFreeBSD-src-78b9749c0a4ea980a8b934645da6ae98fcc665e8.zip
FreeBSD-src-78b9749c0a4ea980a8b934645da6ae98fcc665e8.tar.gz
Vendor import of lldb trunk r256945:
https://llvm.org/svn/llvm-project/lldb/trunk@256945
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break')
-rw-r--r--packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/Makefile6
-rw-r--r--packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py63
-rw-r--r--packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/main.cpp20
3 files changed, 89 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/Makefile b/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/Makefile
new file mode 100644
index 0000000..035413f
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+ENABLE_THREADS := YES
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py b/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py
new file mode 100644
index 0000000..3c69b66
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py
@@ -0,0 +1,63 @@
+"""
+Test that we obey thread conditioned breakpoints.
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+import re
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+class ThreadSpecificBreakTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @add_test_categories(['pyapi'])
+ @expectedFailureWindows # Thread specific breakpoints cause the inferior to crash
+ def test_python(self):
+ """Test that we obey thread conditioned breakpoints."""
+ self.build()
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # This test works by setting a breakpoint in a function conditioned to stop only on
+ # the main thread, and then calling this function on a secondary thread, joining,
+ # and then calling again on the main thread. If the thread specific breakpoint works
+ # then it should not be hit on the secondary thread, only on the main thread.
+
+ main_source_spec = lldb.SBFileSpec ("main.cpp")
+
+ main_breakpoint = target.BreakpointCreateBySourceRegex("Set main breakpoint here", main_source_spec);
+ thread_breakpoint = target.BreakpointCreateBySourceRegex("Set thread-specific breakpoint here", main_source_spec)
+
+ self.assertTrue(main_breakpoint.IsValid(), "Failed to set main breakpoint.")
+ self.assertGreater(main_breakpoint.GetNumLocations(), 0, "main breakpoint has no locations associated with it.")
+ self.assertTrue(thread_breakpoint.IsValid(), "Failed to set thread breakpoint.")
+ self.assertGreater(thread_breakpoint.GetNumLocations(), 0, "thread breakpoint has no locations associated with it.")
+
+ process = target.LaunchSimple (None, None, self.get_process_working_directory())
+
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(process, main_breakpoint)
+ self.assertEqual(len(stopped_threads), 1, "main breakpoint stopped at unexpected number of threads")
+ main_thread = stopped_threads[0]
+ main_thread_id = main_thread.GetThreadID()
+
+ # Set the thread-specific breakpoint to only stop on the main thread. The run the function
+ # on another thread and join on it. If the thread-specific breakpoint works, the next
+ # stop should be on the main thread.
+ thread_breakpoint.SetThreadID(main_thread_id)
+
+ process.Continue()
+ next_stop_state = process.GetState()
+ self.assertEqual(next_stop_state, lldb.eStateStopped, "We should have stopped at the thread breakpoint.")
+ stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(process, thread_breakpoint)
+ self.assertEqual(len(stopped_threads), 1, "thread breakpoint stopped at unexpected number of threads")
+ self.assertEqual(stopped_threads[0].GetThreadID(), main_thread_id, "thread breakpoint stopped at the wrong thread")
diff --git a/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/main.cpp b/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/main.cpp
new file mode 100644
index 0000000..7721b5d
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/thread/thread_specific_break/main.cpp
@@ -0,0 +1,20 @@
+#include <chrono>
+#include <thread>
+
+void
+thread_function ()
+{
+ // Set thread-specific breakpoint here.
+ std::this_thread::sleep_for(std::chrono::microseconds(100));
+}
+
+int
+main ()
+{
+ // Set main breakpoint here.
+ std::thread t(thread_function);
+ t.join();
+
+ thread_function();
+ return 0;
+}
OpenPOWER on IntegriCloud