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.""" |
| 23 | self.buildDefault(dictionary={'C_SOURCES': 'main.c'}) |
| 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) |
| 30 | self.assertTrue(target.IsValid(), VALID_TARGET) |
| 31 | |
| 32 | breakpoint = target.BreakpointCreateByLocation("main.c", self.line) |
| 33 | self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT) |
| 34 | |
| 35 | # Now launch the process, and do not stop at entry point. |
| 36 | self.process = target.LaunchSimple(None, None, os.getcwd()) |
| 37 | |
| 38 | if not self.process.IsValid(): |
| 39 | self.fail("SBTarget.LaunchProcess() failed") |
| 40 | self.assertTrue(self.process.GetState() == lldb.eStateStopped, |
| 41 | PROCESS_STOPPED) |
| 42 | |
| 43 | import lldbutil |
| 44 | thread = lldbutil.get_stopped_thread(self.process, lldb.eStopReasonBreakpoint) |
| 45 | frame0 = thread.GetFrameAtIndex(0) |
| 46 | frame1 = thread.GetFrameAtIndex(1) |
| 47 | parent = lldbutil.get_parent_frame(frame0) |
| 48 | self.assertTrue(parent.IsValid() and parent.GetFrameID() == frame1.GetFrameID()) |
| 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() |