blob: 22db4a4be36489949ccc615bee8897e36bfb0568 [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
Greg Clayton4570d3e2013-12-10 23:19:29 +000012 mydir = TestBase.compute_mydir(__file__)
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.
Greg Claytonc6947512013-12-13 19:18:59 +000037 process = target.LaunchSimple (None, None, self.get_process_working_directory())
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)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000046 self.assertTrue (thread)
Johnny Chenad7372c2011-05-12 00:32:41 +000047 frame0 = thread.GetFrameAtIndex(0)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000048 self.assertTrue (frame0)
Johnny Chenad7372c2011-05-12 00:32:41 +000049 frame1 = thread.GetFrameAtIndex(1)
Greg Clayton7fdf9ef2012-04-05 16:12:35 +000050 self.assertTrue (frame1)
Johnny Chenad7372c2011-05-12 00:32:41 +000051 parent = lldbutil.get_parent_frame(frame0)
Johnny Chen112f5692011-05-17 22:14:39 +000052 self.assertTrue(parent and parent.GetFrameID() == frame1.GetFrameID())
Johnny Chenad7372c2011-05-12 00:32:41 +000053 frame0_args = lldbutil.get_args_as_string(frame0)
54 parent_args = lldbutil.get_args_as_string(parent)
Johnny Chen0d4f6dd2011-06-16 22:07:48 +000055 self.assertTrue(frame0_args and parent_args and "(int)val=1" in frame0_args)
Johnny Chenad7372c2011-05-12 00:32:41 +000056 if self.TraceOn():
57 lldbutil.print_stacktrace(thread)
58 print "Current frame: %s" % frame0_args
59 print "Parent frame: %s" % parent_args
60
61
62if __name__ == '__main__':
63 import atexit
64 lldb.SBDebugger.Initialize()
65 atexit.register(lambda: lldb.SBDebugger.Terminate())
66 unittest2.main()