Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 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 = "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 Chen | 0c0f977 | 2011-05-26 21:43:19 +0000 | [diff] [blame] | 23 | self.buildDefault() |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 24 | 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 Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 30 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 31 | |
| 32 | breakpoint = target.BreakpointCreateByLocation("main.c", self.line) |
Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 33 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 34 | |
| 35 | # Now launch the process, and do not stop at entry point. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame^] | 36 | process = target.LaunchSimple(None, None, os.getcwd()) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 37 | |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame^] | 38 | if not process: |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 39 | self.fail("SBTarget.LaunchProcess() failed") |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame^] | 40 | self.assertTrue(process.GetState() == lldb.eStateStopped, |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 41 | PROCESS_STOPPED) |
| 42 | |
| 43 | import lldbutil |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame^] | 44 | thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 45 | frame0 = thread.GetFrameAtIndex(0) |
| 46 | frame1 = thread.GetFrameAtIndex(1) |
| 47 | parent = lldbutil.get_parent_frame(frame0) |
Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 48 | self.assertTrue(parent and parent.GetFrameID() == frame1.GetFrameID()) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 49 | 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 | |
| 58 | if __name__ == '__main__': |
| 59 | import atexit |
| 60 | lldb.SBDebugger.Initialize() |
| 61 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 62 | unittest2.main() |