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 | |
Johnny Chen | 0f2ed0e | 2011-09-27 21:49:34 +0000 | [diff] [blame] | 12 | mydir = os.path.join("python_api", "lldbutil", "frame") |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 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 | |
Johnny Chen | 5ccbccf | 2011-07-30 01:39:58 +0000 | [diff] [blame] | 21 | @python_api_test |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 22 | def test_frame_utils(self): |
| 23 | """Test utility functions for the frame object.""" |
Johnny Chen | 0c0f977 | 2011-05-26 21:43:19 +0000 | [diff] [blame] | 24 | self.buildDefault() |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 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) |
Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 31 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 32 | |
| 33 | breakpoint = target.BreakpointCreateByLocation("main.c", self.line) |
Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 34 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 35 | |
| 36 | # Now launch the process, and do not stop at entry point. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 37 | process = target.LaunchSimple(None, None, os.getcwd()) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 38 | |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 39 | if not process: |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 40 | self.fail("SBTarget.LaunchProcess() failed") |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 41 | self.assertTrue(process.GetState() == lldb.eStateStopped, |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 42 | PROCESS_STOPPED) |
| 43 | |
| 44 | import lldbutil |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 45 | thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 46 | frame0 = thread.GetFrameAtIndex(0) |
| 47 | frame1 = thread.GetFrameAtIndex(1) |
| 48 | parent = lldbutil.get_parent_frame(frame0) |
Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 49 | self.assertTrue(parent and parent.GetFrameID() == frame1.GetFrameID()) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 50 | frame0_args = lldbutil.get_args_as_string(frame0) |
| 51 | parent_args = lldbutil.get_args_as_string(parent) |
Johnny Chen | 0d4f6dd | 2011-06-16 22:07:48 +0000 | [diff] [blame] | 52 | self.assertTrue(frame0_args and parent_args and "(int)val=1" in frame0_args) |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 53 | if self.TraceOn(): |
| 54 | lldbutil.print_stacktrace(thread) |
| 55 | print "Current frame: %s" % frame0_args |
| 56 | print "Parent frame: %s" % parent_args |
| 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |
| 60 | import atexit |
| 61 | lldb.SBDebugger.Initialize() |
| 62 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 63 | unittest2.main() |