[Lldb-commits] [lldb] r152050 - in /lldb/trunk: include/lldb/API/SBFrame.h scripts/Python/interface/SBFrame.i source/API/SBFrame.cpp test/python_api/frame/TestFrames.py

Johnny Chen johnny.chen at apple.com
Mon Mar 5 11:53:25 PST 2012


Author: johnny
Date: Mon Mar  5 13:53:24 2012
New Revision: 152050

URL: http://llvm.org/viewvc/llvm-project?rev=152050&view=rev
Log:
rdar://problem/10976649

Add SBFrame::IsEqual(const SBFrame &that) method and export it to the Python binding.
Alos add a test case test_frame_api_IsEqual() to TestFrames.py file.

Modified:
    lldb/trunk/include/lldb/API/SBFrame.h
    lldb/trunk/scripts/Python/interface/SBFrame.i
    lldb/trunk/source/API/SBFrame.cpp
    lldb/trunk/test/python_api/frame/TestFrames.py

Modified: lldb/trunk/include/lldb/API/SBFrame.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFrame.h?rev=152050&r1=152049&r2=152050&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBFrame.h (original)
+++ lldb/trunk/include/lldb/API/SBFrame.h Mon Mar  5 13:53:24 2012
@@ -30,6 +30,9 @@
    ~SBFrame();
 
     bool
+    IsEqual (const lldb::SBFrame &that) const;
+
+    bool
     IsValid() const;
 
     uint32_t

Modified: lldb/trunk/scripts/Python/interface/SBFrame.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBFrame.i?rev=152050&r1=152049&r2=152050&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBFrame.i (original)
+++ lldb/trunk/scripts/Python/interface/SBFrame.i Mon Mar  5 13:53:24 2012
@@ -55,6 +55,9 @@
    ~SBFrame();
 
     bool
+    IsEqual (const lldb::SBFrame &rhs) const;
+
+    bool
     IsValid() const;
 
     uint32_t

Modified: lldb/trunk/source/API/SBFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=152050&r1=152049&r2=152050&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFrame.cpp (original)
+++ lldb/trunk/source/API/SBFrame.cpp Mon Mar  5 13:53:24 2012
@@ -718,15 +718,23 @@
 }
 
 bool
+SBFrame::IsEqual (const SBFrame &that) const
+{
+    lldb::StackFrameSP this_sp = GetFrameSP();
+    lldb::StackFrameSP that_sp = that.GetFrameSP();
+    return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
+}
+
+bool
 SBFrame::operator == (const SBFrame &rhs) const
 {
-    return GetFrameSP().get() == rhs.GetFrameSP().get();
+    return IsEqual(rhs);
 }
 
 bool
 SBFrame::operator != (const SBFrame &rhs) const
 {
-    return GetFrameSP().get() != rhs.GetFrameSP().get();
+    return !IsEqual(rhs);
 }
 
 SBThread

Modified: lldb/trunk/test/python_api/frame/TestFrames.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/frame/TestFrames.py?rev=152050&r1=152049&r2=152050&view=diff
==============================================================================
--- lldb/trunk/test/python_api/frame/TestFrames.py (original)
+++ lldb/trunk/test/python_api/frame/TestFrames.py Mon Mar  5 13:53:24 2012
@@ -1,5 +1,6 @@
 """
 Use lldb Python SBFrame API to get the argument values of the call stacks.
+And other SBFrame API tests.
 """
 
 import os, time
@@ -31,6 +32,12 @@
         self.buildDefault()
         self.frame_api_boundary_condition()
 
+    @python_api_test
+    def test_frame_api_IsEqual(self):
+        """Exercise SBFrame API IsEqual."""
+        self.buildDefault()
+        self.frame_api_IsEqual()
+
     def do_get_arg_vals(self):
         """Get argument vals for the call stack when stopped on a breakpoint."""
         exe = os.path.join(os.getcwd(), "a.out")
@@ -152,6 +159,61 @@
 
         frame.EvaluateExpression(None)
 
+    def frame_api_IsEqual(self):
+        """Exercise SBFrame API IsEqual."""
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        # Create a target by the debugger.
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target, VALID_TARGET)
+
+        # Now create a breakpoint on main.c by name 'c'.
+        breakpoint = target.BreakpointCreateByName('c', 'a.out')
+        #print "breakpoint:", breakpoint
+        self.assertTrue(breakpoint and
+                        breakpoint.GetNumLocations() == 1,
+                        VALID_BREAKPOINT)
+
+        # Now launch the process, and do not stop at the entry point.
+        process = target.LaunchSimple(None, None, os.getcwd())
+
+        process = target.GetProcess()
+        self.assertTrue(process.GetState() == lldb.eStateStopped,
+                        PROCESS_STOPPED)
+
+        thread = process.GetThreadAtIndex(0)
+        self.assertTrue(thread)
+
+        frameEntered = thread.GetFrameAtIndex(0)
+        if self.TraceOn():
+            print frameEntered
+            lldbutil.print_stacktrace(thread)
+        self.assertTrue(frameEntered)
+
+        # Doing two step overs while still inside c().
+        thread.StepOver()
+        thread.StepOver()
+        self.assertTrue(thread)
+        frameNow = thread.GetFrameAtIndex(0)
+        if self.TraceOn():
+            print frameNow
+            lldbutil.print_stacktrace(thread)
+        self.assertTrue(frameNow)
+
+        # The latest two frames are considered equal.
+        self.assertTrue(frameEntered.IsEqual(frameNow))
+
+        # Now let's step out of frame c().
+        thread.StepOutOfFrame(frameNow)
+        frameOutOfC = thread.GetFrameAtIndex(0)
+        if self.TraceOn():
+            print frameOutOfC
+            lldbutil.print_stacktrace(thread)
+        self.assertTrue(frameOutOfC)
+
+        # The latest two frames should not be equal.
+        self.assertFalse(frameEntered.IsEqual(frameNow))
+
 
 if __name__ == '__main__':
     import atexit





More information about the lldb-commits mailing list