[Lldb-commits] [lldb] r113325 - in /lldb/trunk/test/conditional_break: ./ Makefile TestConditionalBreak.py main.c
Johnny Chen
johnny.chen at apple.com
Tue Sep 7 17:46:08 PDT 2010
Author: johnny
Date: Tue Sep 7 19:46:08 2010
New Revision: 113325
URL: http://llvm.org/viewvc/llvm-project?rev=113325&view=rev
Log:
Added a test case which exercises some thread and frame APIs to break only when
the call site of c() is a().
Added:
lldb/trunk/test/conditional_break/
lldb/trunk/test/conditional_break/Makefile
lldb/trunk/test/conditional_break/TestConditionalBreak.py
lldb/trunk/test/conditional_break/main.c
Added: lldb/trunk/test/conditional_break/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/conditional_break/Makefile?rev=113325&view=auto
==============================================================================
--- lldb/trunk/test/conditional_break/Makefile (added)
+++ lldb/trunk/test/conditional_break/Makefile Tue Sep 7 19:46:08 2010
@@ -0,0 +1,5 @@
+LEVEL = ../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/conditional_break/TestConditionalBreak.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/conditional_break/TestConditionalBreak.py?rev=113325&view=auto
==============================================================================
--- lldb/trunk/test/conditional_break/TestConditionalBreak.py (added)
+++ lldb/trunk/test/conditional_break/TestConditionalBreak.py Tue Sep 7 19:46:08 2010
@@ -0,0 +1,74 @@
+"""
+Test conditionally break on a function and inspect its variables.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb
+from lldbtest import *
+
+class ConditionalBreakTestCase(TestBase):
+
+ mydir = "conditional_break"
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_with_dsym(self):
+ """Exercise some thread and frame APIs to break if c() is called by a()."""
+ self.buildDsym()
+ self.do_conditional_break()
+
+ def test_with_dwarf(self):
+ """Exercise some thread and frame APIs to break if c() is called by a()."""
+ self.buildDwarf()
+ self.do_conditional_break()
+
+ def do_conditional_break(self):
+ """Exercise some thread and frame APIs to break if c() is called by a()."""
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Break on c().
+ self.expect("breakpoint set -n c", BREAKPOINT_CREATED,
+ startstr = "Breakpoint created: 1: name = 'c', locations = 1")
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['state is Stopped', 'stop reason = breakpoint'])
+
+ # Suppose we are only interested in the call scenario where c()'s
+ # immediate caller is a() and we want to find out the value passed
+ # from a().
+ for j in range(3):
+ target = self.dbg.GetSelectedTarget()
+ process = target.GetProcess()
+ thread = process.GetThreadAtIndex(0)
+
+ if thread.GetNumFrames() >= 2:
+ frame0 = thread.GetFrameAtIndex(0)
+ name0 = frame0.GetFunction().GetName()
+ frame1 = thread.GetFrameAtIndex(1)
+ name1 = frame1.GetFunction().GetName()
+ self.assertTrue(name0 == "c", "Break on function c()")
+ if (name1 == "a"):
+ line = frame1.GetLineEntry().GetLine()
+ # By design, we know that a() calls c() only from main.c:27.
+ # In reality, similar logic can be used to find out the call
+ # site.
+ self.assertTrue(line == 27, "Immediate caller a() at main.c:27")
+ self.runCmd("thread backtrace")
+ self.runCmd("frame variable")
+ break
+
+ # This doesn't work?
+ #process.Continue()
+ self.runCmd("process continue")
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
Added: lldb/trunk/test/conditional_break/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/conditional_break/main.c?rev=113325&view=auto
==============================================================================
--- lldb/trunk/test/conditional_break/main.c (added)
+++ lldb/trunk/test/conditional_break/main.c Tue Sep 7 19:46:08 2010
@@ -0,0 +1,54 @@
+//===-- 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 command add" to add a set of commands to a breakpoint to be
+// executed when the breakpoint is hit.
+//
+// In particular, we want to break within c(), but only if the immediate caller
+// is a().
+
+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;
+}
+
+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;
+}
More information about the lldb-commits
mailing list