Add a test case for exercising breakpoint conditions using the lldb command:
breakpoint modify -c 'val == 3' 1
after:
breakpoint set -n c
which sets a breakpoint on function 'c'. The breakpoint should only stop if
expression 'val == 3' evaluates to true.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@116607 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/breakpoint_conditions/Makefile b/test/breakpoint_conditions/Makefile
new file mode 100644
index 0000000..d6cd0db
--- /dev/null
+++ b/test/breakpoint_conditions/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/test/breakpoint_conditions/TestBreakpointConditions.py b/test/breakpoint_conditions/TestBreakpointConditions.py
new file mode 100644
index 0000000..a5308ac
--- /dev/null
+++ b/test/breakpoint_conditions/TestBreakpointConditions.py
@@ -0,0 +1,68 @@
+"""
+Test breakpoint conditions with 'breakpoint modify -c <expr> id'.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb, lldbutil
+from lldbtest import *
+
+class BreakpointConditionsTestCase(TestBase):
+
+ mydir = "breakpoint_conditions"
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_with_dsym_python(self):
+ """Exercise breakpoint condition with 'breakpoint modify -c <expr> id'."""
+ self.buildDsym()
+ self.breakpoint_conditions()
+
+ def test_with_dwarf_python(self):
+ """Exercise breakpoint condition with 'breakpoint modify -c <expr> id'."""
+ self.buildDwarf()
+ self.breakpoint_conditions()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to of function 'c'.
+ self.line = line_number('main.c', '// Find the line number of function "c" here.')
+
+ def breakpoint_conditions(self):
+ """Exercise breakpoint condition with 'breakpoint modify -c <expr> id'."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Create a breakpoint by function name 'c'.
+ self.expect("breakpoint set -n c", BREAKPOINT_CREATED,
+ startstr = "Breakpoint created: 1: name = 'c', locations = 1")
+
+ # And set a condition on the breakpoint to stop on when 'val == 3'.
+ self.runCmd("breakpoint modify -c 'val == 3' 1")
+
+ # Now run the program.
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # 'frame variable -t val' should return 3 due to breakpoint condition.
+ self.expect("frame variable -t val", VARIABLES_DISPLAYED_CORRECTLY,
+ startstr = '(int) val = 3')
+
+ # Also check the hit count, which should be 3, by design.
+ self.expect("breakpoint list", BREAKPOINT_HIT_THRICE,
+ substrs = ["resolved = 1",
+ "Condition: val == 3",
+ "hit count = 3"])
+
+ # The frame #0 should correspond to main.c:36, the executable statement
+ # in function name 'c'.
+ self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ["stop reason = breakpoint"],
+ patterns = ["frame #0.*main.c:%d" % self.line])
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/test/breakpoint_conditions/main.c b/test/breakpoint_conditions/main.c
new file mode 100644
index 0000000..0a08790
--- /dev/null
+++ b/test/breakpoint_conditions/main.c
@@ -0,0 +1,51 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+
+// This simple program is to demonstrate the capability of the lldb command
+// "breakpoint modify -c 'val == 3' breakpt-id" to break within c(int val) only
+// when the value of the arg is 3.
+
+int a(int);
+int b(int);
+int c(int);
+
+int a(int val)
+{
+ if (val <= 1)
+ return b(val);
+ else if (val >= 3)
+ return c(val);
+
+ return val;
+}
+
+int b(int val)
+{
+ return c(val);
+}
+
+int c(int val)
+{
+ return val + 3; // Find the line number of function "c" here.
+}
+
+int main (int argc, char const *argv[])
+{
+ int A1 = a(1); // a(1) -> b(1) -> c(1)
+ printf("a(1) returns %d\n", A1);
+
+ int B2 = b(2); // b(2) -> c(2)
+ printf("b(2) returns %d\n", B2);
+
+ int A3 = a(3); // a(3) -> c(3)
+ printf("a(3) returns %d\n", A3);
+
+ return 0;
+}
diff --git a/test/lldbtest.py b/test/lldbtest.py
index 5445d9c..5659403 100644
--- a/test/lldbtest.py
+++ b/test/lldbtest.py
@@ -491,7 +491,7 @@
with recording(self, trace) as sbuf:
print >> sbuf, "runCmd:", cmd
if not check:
- print >> sbuf, "checking of return status not required"
+ print >> sbuf, "check of return status not required"
if self.res.Succeeded():
print >> sbuf, "output:", self.res.GetOutput()
else: