blob: 04d398bc5fa1b95d457aa1aaae5bd15ded01ab94 [file] [log] [blame]
Johnny Chenad7372c2011-05-12 00:32:41 +00001"""
2Test utility functions for the frame object.
3"""
4
5import os
6import unittest2
7import lldb
8from lldbtest import *
9
10class FrameUtilsTestCase(TestBase):
11
Johnny Chen0f2ed0e2011-09-27 21:49:34 +000012 mydir = os.path.join("python_api", "lldbutil", "frame")
Johnny Chenad7372c2011-05-12 00:32:41 +000013
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
Johnny Chen5ccbccf2011-07-30 01:39:58 +000021 @python_api_test
Johnny Chenad7372c2011-05-12 00:32:41 +000022 def test_frame_utils(self):
23 """Test utility functions for the frame object."""
Johnny Chen0c0f9772011-05-26 21:43:19 +000024 self.buildDefault()
Johnny Chenad7372c2011-05-12 00:32:41 +000025 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)
Johnny Chen112f5692011-05-17 22:14:39 +000031 self.assertTrue(target, VALID_TARGET)
Johnny Chenad7372c2011-05-12 00:32:41 +000032
33 breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
Johnny Chen112f5692011-05-17 22:14:39 +000034 self.assertTrue(breakpoint, VALID_BREAKPOINT)
Johnny Chenad7372c2011-05-12 00:32:41 +000035
36 # Now launch the process, and do not stop at entry point.
Johnny Chen5a0bee72011-06-15 22:14:12 +000037 process = target.LaunchSimple(None, None, os.getcwd())
Johnny Chenad7372c2011-05-12 00:32:41 +000038
Johnny Chen5a0bee72011-06-15 22:14:12 +000039 if not process:
Johnny Chenad7372c2011-05-12 00:32:41 +000040 self.fail("SBTarget.LaunchProcess() failed")
Johnny Chen5a0bee72011-06-15 22:14:12 +000041 self.assertTrue(process.GetState() == lldb.eStateStopped,
Johnny Chenad7372c2011-05-12 00:32:41 +000042 PROCESS_STOPPED)
43
44 import lldbutil
Johnny Chen5a0bee72011-06-15 22:14:12 +000045 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
Johnny Chenad7372c2011-05-12 00:32:41 +000046 frame0 = thread.GetFrameAtIndex(0)
47 frame1 = thread.GetFrameAtIndex(1)
48 parent = lldbutil.get_parent_frame(frame0)
Johnny Chen112f5692011-05-17 22:14:39 +000049 self.assertTrue(parent and parent.GetFrameID() == frame1.GetFrameID())
Johnny Chenad7372c2011-05-12 00:32:41 +000050 frame0_args = lldbutil.get_args_as_string(frame0)
51 parent_args = lldbutil.get_args_as_string(parent)
Johnny Chen0d4f6dd2011-06-16 22:07:48 +000052 self.assertTrue(frame0_args and parent_args and "(int)val=1" in frame0_args)
Johnny Chenad7372c2011-05-12 00:32:41 +000053 if self.TraceOn():
54 lldbutil.print_stacktrace(thread)
55 print "Current frame: %s" % frame0_args
56 print "Parent frame: %s" % parent_args
57
58
59if __name__ == '__main__':
60 import atexit
61 lldb.SBDebugger.Initialize()
62 atexit.register(lambda: lldb.SBDebugger.Terminate())
63 unittest2.main()