Johnny Chen | 4cfd07e | 2011-06-20 00:26:39 +0000 | [diff] [blame] | 1 | """ |
| 2 | Testlldb Python SBFrame APIs IsInlined() and GetFunctionName(). |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import re |
| 7 | import unittest2 |
| 8 | import lldb, lldbutil |
| 9 | from lldbtest import * |
| 10 | |
| 11 | class InlinedFrameAPITestCase(TestBase): |
| 12 | |
| 13 | mydir = os.path.join("python_api", "frame", "inlines") |
| 14 | |
| 15 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 16 | @python_api_test |
Johnny Chen | 94b431a | 2011-07-26 23:35:38 +0000 | [diff] [blame] | 17 | def test_stop_at_outer_inline_with_dsym(self): |
Johnny Chen | 4cfd07e | 2011-06-20 00:26:39 +0000 | [diff] [blame] | 18 | """Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName().""" |
| 19 | self.buildDsym() |
| 20 | self.do_stop_at_outer_inline() |
| 21 | |
| 22 | @python_api_test |
| 23 | def test_stop_at_outer_inline_with_dwarf(self): |
| 24 | """Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName().""" |
| 25 | self.buildDwarf() |
| 26 | self.do_stop_at_outer_inline() |
| 27 | |
Johnny Chen | 13ea11a | 2011-07-13 22:34:29 +0000 | [diff] [blame] | 28 | def setUp(self): |
| 29 | |
| 30 | # Call super's setUp(). |
| 31 | TestBase.setUp(self) |
| 32 | # Find the line number to of function 'c'. |
| 33 | self.source = 'inlines.c' |
| 34 | self.first_stop = line_number(self.source, '// This should correspond to the first break stop.') |
| 35 | self.second_stop = line_number(self.source, '// This should correspond to the second break stop.') |
| 36 | |
Johnny Chen | 4cfd07e | 2011-06-20 00:26:39 +0000 | [diff] [blame] | 37 | def do_stop_at_outer_inline(self): |
| 38 | """Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName().""" |
| 39 | exe = os.path.join(os.getcwd(), "a.out") |
| 40 | |
| 41 | # Create a target by the debugger. |
| 42 | target = self.dbg.CreateTarget(exe) |
| 43 | self.assertTrue(target, VALID_TARGET) |
| 44 | |
Johnny Chen | 13ea11a | 2011-07-13 22:34:29 +0000 | [diff] [blame] | 45 | # Now create a breakpoint on main.c by the name of 'inner_inline'. |
| 46 | breakpoint = target.BreakpointCreateByName('inner_inline', 'a.out') |
Johnny Chen | 4cfd07e | 2011-06-20 00:26:39 +0000 | [diff] [blame] | 47 | #print "breakpoint:", breakpoint |
| 48 | self.assertTrue(breakpoint and |
| 49 | breakpoint.GetNumLocations() > 1, |
| 50 | VALID_BREAKPOINT) |
| 51 | |
| 52 | # Now launch the process, and do not stop at the entry point. |
| 53 | process = target.LaunchSimple(None, None, os.getcwd()) |
| 54 | |
| 55 | process = target.GetProcess() |
| 56 | self.assertTrue(process.GetState() == lldb.eStateStopped, |
| 57 | PROCESS_STOPPED) |
| 58 | |
Johnny Chen | 13ea11a | 2011-07-13 22:34:29 +0000 | [diff] [blame] | 59 | import lldbutil |
| 60 | stack_traces1 = lldbutil.print_stacktraces(process, string_buffer=True) |
Johnny Chen | 4cfd07e | 2011-06-20 00:26:39 +0000 | [diff] [blame] | 61 | if self.TraceOn(): |
Johnny Chen | 13ea11a | 2011-07-13 22:34:29 +0000 | [diff] [blame] | 62 | print "Full stack traces when first stopped on the breakpoint 'inner_inline':" |
| 63 | print stack_traces1 |
Johnny Chen | f4e9a4c | 2011-07-08 01:01:45 +0000 | [diff] [blame] | 64 | |
| 65 | # The first breakpoint should correspond to an inlined call frame. |
Johnny Chen | 13ea11a | 2011-07-13 22:34:29 +0000 | [diff] [blame] | 66 | # If it's an inlined call frame, expect to find, in the stack trace, |
| 67 | # that there is a frame which corresponds to the following call site: |
| 68 | # |
| 69 | # outer_inline (argc); |
| 70 | # |
Johnny Chen | f4e9a4c | 2011-07-08 01:01:45 +0000 | [diff] [blame] | 71 | frame0 = process.GetThreadAtIndex(0).GetFrameAtIndex(0) |
Johnny Chen | 13ea11a | 2011-07-13 22:34:29 +0000 | [diff] [blame] | 72 | if frame0.IsInlined(): |
| 73 | filename = frame0.GetLineEntry().GetFileSpec().GetFilename() |
| 74 | self.assertTrue(filename == self.source) |
| 75 | self.expect(stack_traces1, "First stop at %s:%d" % (self.source, self.first_stop), exe=False, |
| 76 | substrs = ['%s:%d' % (self.source, self.first_stop)]) |
Johnny Chen | 4cfd07e | 2011-06-20 00:26:39 +0000 | [diff] [blame] | 77 | |
Johnny Chen | 13ea11a | 2011-07-13 22:34:29 +0000 | [diff] [blame] | 78 | # Expect to break again for the second time. |
| 79 | process.Continue() |
| 80 | self.assertTrue(process.GetState() == lldb.eStateStopped, |
| 81 | PROCESS_STOPPED) |
| 82 | stack_traces2 = lldbutil.print_stacktraces(process, string_buffer=True) |
| 83 | if self.TraceOn(): |
| 84 | print "Full stack traces when stopped on the breakpoint 'inner_inline' for the second time:" |
| 85 | print stack_traces2 |
| 86 | self.expect(stack_traces2, "Second stop at %s:%d" % (self.source, self.second_stop), exe=False, |
| 87 | substrs = ['%s:%d' % (self.source, self.second_stop)]) |
Johnny Chen | 4cfd07e | 2011-06-20 00:26:39 +0000 | [diff] [blame] | 88 | |
| 89 | if __name__ == '__main__': |
| 90 | import atexit |
| 91 | lldb.SBDebugger.Initialize() |
| 92 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 93 | unittest2.main() |