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