blob: 1fd337a78b1d4c4daff6b8af6d6a201f3d5ef7b6 [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
12 mydir = "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 def test_frame_utils(self):
22 """Test utility functions for the frame object."""
Johnny Chen0c0f9772011-05-26 21:43:19 +000023 self.buildDefault()
Johnny Chenad7372c2011-05-12 00:32:41 +000024 self.frame_utils()
25
26 def frame_utils(self):
27 exe = os.path.join(os.getcwd(), "a.out")
28
29 target = self.dbg.CreateTarget(exe)
Johnny Chen112f5692011-05-17 22:14:39 +000030 self.assertTrue(target, VALID_TARGET)
Johnny Chenad7372c2011-05-12 00:32:41 +000031
32 breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
Johnny Chen112f5692011-05-17 22:14:39 +000033 self.assertTrue(breakpoint, VALID_BREAKPOINT)
Johnny Chenad7372c2011-05-12 00:32:41 +000034
35 # Now launch the process, and do not stop at entry point.
Johnny Chen5a0bee72011-06-15 22:14:12 +000036 process = target.LaunchSimple(None, None, os.getcwd())
Johnny Chenad7372c2011-05-12 00:32:41 +000037
Johnny Chen5a0bee72011-06-15 22:14:12 +000038 if not process:
Johnny Chenad7372c2011-05-12 00:32:41 +000039 self.fail("SBTarget.LaunchProcess() failed")
Johnny Chen5a0bee72011-06-15 22:14:12 +000040 self.assertTrue(process.GetState() == lldb.eStateStopped,
Johnny Chenad7372c2011-05-12 00:32:41 +000041 PROCESS_STOPPED)
42
43 import lldbutil
Johnny Chen5a0bee72011-06-15 22:14:12 +000044 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
Johnny Chenad7372c2011-05-12 00:32:41 +000045 frame0 = thread.GetFrameAtIndex(0)
46 frame1 = thread.GetFrameAtIndex(1)
47 parent = lldbutil.get_parent_frame(frame0)
Johnny Chen112f5692011-05-17 22:14:39 +000048 self.assertTrue(parent and parent.GetFrameID() == frame1.GetFrameID())
Johnny Chenad7372c2011-05-12 00:32:41 +000049 frame0_args = lldbutil.get_args_as_string(frame0)
50 parent_args = lldbutil.get_args_as_string(parent)
51 self.assertTrue(frame0_args and parent_args)
52 if self.TraceOn():
53 lldbutil.print_stacktrace(thread)
54 print "Current frame: %s" % frame0_args
55 print "Parent frame: %s" % parent_args
56
57
58if __name__ == '__main__':
59 import atexit
60 lldb.SBDebugger.Initialize()
61 atexit.register(lambda: lldb.SBDebugger.Terminate())
62 unittest2.main()