blob: 217b87e892696f5a9f974f714461cd306ed5a293 [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
Robert Flack13c7ad92015-03-30 14:12:17 +000015 @skipUnlessDarwin
Johnny Chen4cfd07e2011-06-20 00:26:39 +000016 @python_api_test
Johnny Chen24086bc2012-04-06 19:54:10 +000017 @dsym_test
Johnny Chen94b431a2011-07-26 23:35:38 +000018 def test_stop_at_outer_inline_with_dsym(self):
Johnny Chen4cfd07e2011-06-20 00:26:39 +000019 """Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName()."""
20 self.buildDsym()
21 self.do_stop_at_outer_inline()
22
23 @python_api_test
Johnny Chen24086bc2012-04-06 19:54:10 +000024 @dwarf_test
Johnny Chen4cfd07e2011-06-20 00:26:39 +000025 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 Chen13ea11a2011-07-13 22:34:29 +000030 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 Chen4cfd07e2011-06-20 00:26:39 +000039 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 Chen13ea11a2011-07-13 22:34:29 +000047 # Now create a breakpoint on main.c by the name of 'inner_inline'.
48 breakpoint = target.BreakpointCreateByName('inner_inline', 'a.out')
Johnny Chen4cfd07e2011-06-20 00:26:39 +000049 #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 Claytonc6947512013-12-13 19:18:59 +000055 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Johnny Chen4cfd07e2011-06-20 00:26:39 +000056
57 process = target.GetProcess()
58 self.assertTrue(process.GetState() == lldb.eStateStopped,
59 PROCESS_STOPPED)
60
Johnny Chen13ea11a2011-07-13 22:34:29 +000061 import lldbutil
62 stack_traces1 = lldbutil.print_stacktraces(process, string_buffer=True)
Johnny Chen4cfd07e2011-06-20 00:26:39 +000063 if self.TraceOn():
Johnny Chen13ea11a2011-07-13 22:34:29 +000064 print "Full stack traces when first stopped on the breakpoint 'inner_inline':"
65 print stack_traces1
Johnny Chenf4e9a4c2011-07-08 01:01:45 +000066
67 # The first breakpoint should correspond to an inlined call frame.
Johnny Chen13ea11a2011-07-13 22:34:29 +000068 # 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 Chenf4e9a4c2011-07-08 01:01:45 +000073 frame0 = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
Johnny Chen13ea11a2011-07-13 22:34:29 +000074 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 Chen4cfd07e2011-06-20 00:26:39 +000079
Johnny Chen13ea11a2011-07-13 22:34:29 +000080 # 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 Chen4cfd07e2011-06-20 00:26:39 +000090
91if __name__ == '__main__':
92 import atexit
93 lldb.SBDebugger.Initialize()
94 atexit.register(lambda: lldb.SBDebugger.Terminate())
95 unittest2.main()