[Lldb-commits] [lldb] r116607 - in /lldb/trunk/test: breakpoint_conditions/ breakpoint_conditions/Makefile breakpoint_conditions/TestBreakpointConditions.py breakpoint_conditions/main.c lldbtest.py
Johnny Chen
johnny.chen at apple.com
Fri Oct 15 11:52:22 PDT 2010
Author: johnny
Date: Fri Oct 15 13:52:22 2010
New Revision: 116607
URL: http://llvm.org/viewvc/llvm-project?rev=116607&view=rev
Log:
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.
Added:
lldb/trunk/test/breakpoint_conditions/
lldb/trunk/test/breakpoint_conditions/Makefile
lldb/trunk/test/breakpoint_conditions/TestBreakpointConditions.py
lldb/trunk/test/breakpoint_conditions/main.c
Modified:
lldb/trunk/test/lldbtest.py
Added: lldb/trunk/test/breakpoint_conditions/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/breakpoint_conditions/Makefile?rev=116607&view=auto
==============================================================================
--- lldb/trunk/test/breakpoint_conditions/Makefile (added)
+++ lldb/trunk/test/breakpoint_conditions/Makefile Fri Oct 15 13:52:22 2010
@@ -0,0 +1,5 @@
+LEVEL = ../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/breakpoint_conditions/TestBreakpointConditions.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/breakpoint_conditions/TestBreakpointConditions.py?rev=116607&view=auto
==============================================================================
--- lldb/trunk/test/breakpoint_conditions/TestBreakpointConditions.py (added)
+++ lldb/trunk/test/breakpoint_conditions/TestBreakpointConditions.py Fri Oct 15 13:52:22 2010
@@ -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()
Added: lldb/trunk/test/breakpoint_conditions/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/breakpoint_conditions/main.c?rev=116607&view=auto
==============================================================================
--- lldb/trunk/test/breakpoint_conditions/main.c (added)
+++ lldb/trunk/test/breakpoint_conditions/main.c Fri Oct 15 13:52:22 2010
@@ -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;
+}
Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=116607&r1=116606&r2=116607&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Fri Oct 15 13:52:22 2010
@@ -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:
More information about the lldb-commits
mailing list