blob: 98bd8e60109714aa2311342dd02549961d68c277 [file] [log] [blame]
Johnny Chen4cfd07e2011-06-20 00:26:39 +00001"""
2Testlldb Python SBFrame APIs IsInlined() and GetFunctionName().
3"""
4
5import os, time
6import re
7import unittest2
8import lldb, lldbutil
9from lldbtest import *
10
11class InlinedFrameAPITestCase(TestBase):
12
Greg Clayton4570d3e2013-12-10 23:19:29 +000013 mydir = TestBase.compute_mydir(__file__)
Johnny Chen4cfd07e2011-06-20 00:26:39 +000014
Johnny Chen13ea11a2011-07-13 22:34:29 +000015 def setUp(self):
Johnny Chen13ea11a2011-07-13 22:34:29 +000016 # 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 Berghammerc8fd1302015-09-30 10:12:40 +000023 @python_api_test
24 def test_stop_at_outer_inline(self):
Johnny Chen4cfd07e2011-06-20 00:26:39 +000025 """Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName()."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000026 self.build()
Johnny Chen4cfd07e2011-06-20 00:26:39 +000027 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 Chen13ea11a2011-07-13 22:34:29 +000033 # Now create a breakpoint on main.c by the name of 'inner_inline'.
34 breakpoint = target.BreakpointCreateByName('inner_inline', 'a.out')
Johnny Chen4cfd07e2011-06-20 00:26:39 +000035 #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 Claytonc6947512013-12-13 19:18:59 +000041 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Johnny Chen4cfd07e2011-06-20 00:26:39 +000042
43 process = target.GetProcess()
44 self.assertTrue(process.GetState() == lldb.eStateStopped,
45 PROCESS_STOPPED)
46
Johnny Chen13ea11a2011-07-13 22:34:29 +000047 import lldbutil
48 stack_traces1 = lldbutil.print_stacktraces(process, string_buffer=True)
Johnny Chen4cfd07e2011-06-20 00:26:39 +000049 if self.TraceOn():
Johnny Chen13ea11a2011-07-13 22:34:29 +000050 print "Full stack traces when first stopped on the breakpoint 'inner_inline':"
51 print stack_traces1
Johnny Chenf4e9a4c2011-07-08 01:01:45 +000052
53 # The first breakpoint should correspond to an inlined call frame.
Johnny Chen13ea11a2011-07-13 22:34:29 +000054 # 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 Chenf4e9a4c2011-07-08 01:01:45 +000059 frame0 = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
Johnny Chen13ea11a2011-07-13 22:34:29 +000060 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 Chen4cfd07e2011-06-20 00:26:39 +000065
Johnny Chen13ea11a2011-07-13 22:34:29 +000066 # 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 Chen4cfd07e2011-06-20 00:26:39 +000076
77if __name__ == '__main__':
78 import atexit
79 lldb.SBDebugger.Initialize()
80 atexit.register(lambda: lldb.SBDebugger.Terminate())
81 unittest2.main()