summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2016-07-15 01:41:54 +0000
committerJim Ingham <jingham@apple.com>2016-07-15 01:41:54 +0000
commitfa0f2a0dcff94b1c746937e805b9e78a6efeb6ef (patch)
tree4680a8e4fdb90c932bc3b879bf38a4855176e744 /lldb/packages/Python/lldbsuite/test
parent7cd3ac724c3ec35fb239c55c2845c1f166fce5e6 (diff)
downloadbcm5719-llvm-fa0f2a0dcff94b1c746937e805b9e78a6efeb6ef.tar.gz
bcm5719-llvm-fa0f2a0dcff94b1c746937e805b9e78a6efeb6ef.zip
Remember to add the testcase I wrote for r274822.
llvm-svn: 275519
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py83
-rw-r--r--lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/main.cpp14
3 files changed, 102 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/Makefile b/lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/Makefile
new file mode 100644
index 00000000000..8a7102e347a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/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/expression_command/unwind_expression/TestUnwindExpression.py b/lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py
new file mode 100644
index 00000000000..6e9af641d03
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/TestUnwindExpression.py
@@ -0,0 +1,83 @@
+"""
+Test stopping at a breakpoint in an expression, and unwinding from there.
+"""
+
+from __future__ import print_function
+
+
+
+import unittest2
+
+import os, time
+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__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+
+ @add_test_categories(['pyapi'])
+
+ def test_unwind_expression(self):
+ """Test unwinding from an expression."""
+ self.build()
+
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Create the breakpoint.
+ main_spec = lldb.SBFileSpec("main.cpp", False)
+ breakpoint = target.BreakpointCreateBySourceRegex("// Set a breakpoint here to get started", main_spec)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+ # Launch the process, and do not stop at the entry point.
+ process = target.LaunchSimple (None, None, self.get_process_working_directory())
+
+ if not process:
+ self.fail("SBTarget.LaunchProcess() failed")
+
+ if process.GetState() != lldb.eStateStopped:
+ self.fail("Process should be in the 'stopped' state, "
+ "instead the actual state is: '%s'" %
+ lldbutil.state_type_to_str(process.GetState()))
+
+ thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, breakpoint)
+ self.assertIsNotNone(thread, "Expected one thread to be stopped at the breakpoint")
+
+ #
+ # Use Python API to evaluate expressions while stopped in a stack frame.
+ #
+ main_frame = thread.GetFrameAtIndex(0)
+
+ # Next set a breakpoint in this function, set up Expression options to stop on
+ # breakpoint hits, and call the function.
+ fun_bkpt = target.BreakpointCreateBySourceRegex("// Stop inside the function here.", main_spec)
+ self.assertTrue(fun_bkpt, VALID_BREAKPOINT)
+ options = lldb.SBExpressionOptions()
+ options.SetIgnoreBreakpoints(False)
+ options.SetUnwindOnError(False)
+
+ 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(process, fun_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/expression_command/unwind_expression/main.cpp b/lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/main.cpp
new file mode 100644
index 00000000000..e93c34a30b0
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/expression_command/unwind_expression/main.cpp
@@ -0,0 +1,14 @@
+static int static_value = 0;
+
+int
+a_function_to_call()
+{
+ static_value++; // Stop inside the function here.
+ return static_value;
+}
+
+int main (int argc, char const *argv[])
+{
+ a_function_to_call(); // Set a breakpoint here to get started
+ return 0;
+}
OpenPOWER on IntegriCloud