summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression
diff options
context:
space:
mode:
authorRaphael Isemann <teemperor@gmail.com>2019-09-01 09:12:37 +0000
committerRaphael Isemann <teemperor@gmail.com>2019-09-01 09:12:37 +0000
commit29872606d220420d53fde7cc5e3bea15f8da62e7 (patch)
tree47d7a82ccea48a6dd10a2d8ecb6b3c3127724131 /lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression
parentadfdcb9c2652aeee585b9005fd6c67be06af8ea9 (diff)
downloadbcm5719-llvm-29872606d220420d53fde7cc5e3bea15f8da62e7.tar.gz
bcm5719-llvm-29872606d220420d53fde7cc5e3bea15f8da62e7.zip
[lldb] Restructure test folders to match LLDB command hierarchy
Summary: As discussed on lldb-dev, this patch moves some LLDB tests into a hierarchy that more closely resembles the commands we use in the LLDB interpreter. This patch should only move tests that use the command interpreter and shouldn't touch any tests that primarily test the SB API. Reviewers: #lldb, jfb, JDevlieghere Reviewed By: #lldb, JDevlieghere Subscribers: dexonsmith, arphaman, JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67033 llvm-svn: 370605
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression')
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/TestUnwindExpression.py101
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/main.cpp22
3 files changed, 128 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/Makefile b/lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/Makefile
new file mode 100644
index 00000000000..8a7102e347a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/TestUnwindExpression.py b/lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/TestUnwindExpression.py
new file mode 100644
index 00000000000..d42ee3de404
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/TestUnwindExpression.py
@@ -0,0 +1,101 @@
+"""
+Test stopping at a breakpoint in an expression, and unwinding from there.
+"""
+
+from __future__ import print_function
+
+
+import unittest2
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class UnwindFromExpressionTest(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ main_spec = lldb.SBFileSpec("main.cpp", False)
+
+ def build_and_run_to_bkpt(self):
+ self.build()
+
+ (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
+ "// Set a breakpoint here to get started", self.main_spec)
+
+ # Next set a breakpoint in this function, set up Expression options to stop on
+ # breakpoint hits, and call the function.
+ self.fun_bkpt = self.target().BreakpointCreateBySourceRegex(
+ "// Stop inside the function here.", self.main_spec)
+ self.assertTrue(self.fun_bkpt, VALID_BREAKPOINT)
+
+
+ @no_debug_info_test
+ @expectedFailureAll(bugnumber="llvm.org/pr33164")
+ def test_conditional_bktp(self):
+ """
+ Test conditional breakpoint handling in the IgnoreBreakpoints = False case
+ """
+ self.build_and_run_to_bkpt()
+
+ self.fun_bkpt.SetCondition("0") # Should not get hit
+ options = lldb.SBExpressionOptions()
+ options.SetIgnoreBreakpoints(False)
+ options.SetUnwindOnError(False)
+
+ main_frame = self.thread.GetFrameAtIndex(0)
+ val = main_frame.EvaluateExpression("second_function(47)", options)
+ self.assertTrue(
+ val.GetError().Success(),
+ "We did complete the execution.")
+ self.assertEquals(47, val.GetValueAsSigned())
+
+
+ @add_test_categories(['pyapi'])
+ @expectedFlakeyNetBSD
+ def test_unwind_expression(self):
+ """Test unwinding from an expression."""
+ self.build_and_run_to_bkpt()
+
+ # Run test with varying one thread timeouts to also test the halting
+ # logic in the IgnoreBreakpoints = False case
+ self.do_unwind_test(self.thread, self.fun_bkpt, 1000)
+ self.do_unwind_test(self.thread, self.fun_bkpt, 100000)
+
+ def do_unwind_test(self, thread, bkpt, timeout):
+ #
+ # Use Python API to evaluate expressions while stopped in a stack frame.
+ #
+ main_frame = thread.GetFrameAtIndex(0)
+
+ options = lldb.SBExpressionOptions()
+ options.SetIgnoreBreakpoints(False)
+ options.SetUnwindOnError(False)
+ options.SetOneThreadTimeoutInMicroSeconds(timeout)
+
+ val = main_frame.EvaluateExpression("a_function_to_call()", options)
+
+ self.assertTrue(
+ val.GetError().Fail(),
+ "We did not complete the execution.")
+ error_str = val.GetError().GetCString()
+ self.assertTrue(
+ "Execution was interrupted, reason: breakpoint" in error_str,
+ "And the reason was right.")
+
+ thread = lldbutil.get_one_thread_stopped_at_breakpoint(
+ self.process(), bkpt)
+ self.assertTrue(
+ thread.IsValid(),
+ "We are indeed stopped at our breakpoint")
+
+ # Now unwind the expression, and make sure we got back to where we
+ # started.
+ error = thread.UnwindInnermostExpression()
+ self.assertTrue(error.Success(), "We succeeded in unwinding")
+
+ cur_frame = thread.GetFrameAtIndex(0)
+ self.assertTrue(
+ cur_frame.IsEqual(main_frame),
+ "We got back to the main frame.")
diff --git a/lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/main.cpp
new file mode 100644
index 00000000000..56b06f31ecc
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/expression/unwind_expression/main.cpp
@@ -0,0 +1,22 @@
+static int static_value = 0;
+
+int
+a_function_to_call()
+{
+ static_value++; // Stop inside the function here.
+ return static_value;
+}
+
+int second_function(int x){
+ for(int i=0; i<10; ++i) {
+ a_function_to_call();
+ }
+ return x;
+}
+
+int main (int argc, char const *argv[])
+{
+ a_function_to_call(); // Set a breakpoint here to get started
+ second_function(1);
+ return 0;
+}
OpenPOWER on IntegriCloud