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