Home | History | Annotate | Download | only in frame
      1 """
      2 Test utility functions for the frame object.
      3 """
      4 
      5 import os
      6 import unittest2
      7 import lldb
      8 from lldbtest import *
      9 
     10 class FrameUtilsTestCase(TestBase):
     11 
     12     mydir = os.path.join("python_api", "lldbutil", "frame")
     13 
     14     def setUp(self):
     15         # Call super's setUp().
     16         TestBase.setUp(self)
     17         # Find the line number to break inside main().
     18         self.line = line_number('main.c',
     19                                 "// Find the line number here.")
     20 
     21     @python_api_test
     22     def test_frame_utils(self):
     23         """Test utility functions for the frame object."""
     24         self.buildDefault()
     25         self.frame_utils()
     26 
     27     def frame_utils(self):
     28         exe = os.path.join(os.getcwd(), "a.out")
     29 
     30         target = self.dbg.CreateTarget(exe)
     31         self.assertTrue(target, VALID_TARGET)
     32 
     33         breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
     34         self.assertTrue(breakpoint, VALID_BREAKPOINT)
     35 
     36         # Now launch the process, and do not stop at entry point.
     37         process = target.LaunchSimple(None, None, os.getcwd())
     38 
     39         if not process:
     40             self.fail("SBTarget.LaunchProcess() failed")
     41         self.assertTrue(process.GetState() == lldb.eStateStopped,
     42                         PROCESS_STOPPED)
     43 
     44         import lldbutil
     45         thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
     46         self.assertTrue (thread)
     47         frame0 = thread.GetFrameAtIndex(0)
     48         self.assertTrue (frame0)
     49         frame1 = thread.GetFrameAtIndex(1)
     50         self.assertTrue (frame1)
     51         parent = lldbutil.get_parent_frame(frame0)
     52         self.assertTrue(parent and parent.GetFrameID() == frame1.GetFrameID())
     53         frame0_args = lldbutil.get_args_as_string(frame0)
     54         parent_args = lldbutil.get_args_as_string(parent)
     55         self.assertTrue(frame0_args and parent_args and "(int)val=1" in frame0_args)
     56         if self.TraceOn():
     57             lldbutil.print_stacktrace(thread)
     58             print "Current frame: %s" % frame0_args
     59             print "Parent frame: %s" % parent_args
     60 
     61 
     62 if __name__ == '__main__':
     63     import atexit
     64     lldb.SBDebugger.Initialize()
     65     atexit.register(lambda: lldb.SBDebugger.Terminate())
     66     unittest2.main()
     67