blob: 6a59ee361fb66a8ffd1348b376227e4c1ed3dcbb [file] [log] [blame]
Johnny Chendf2963e2011-04-01 00:35:55 +00001"""
2Test newly added SBSymbol and SBAddress APIs.
3"""
4
5import os, time
6import re
7import unittest2
8import lldb, lldbutil
9from lldbtest import *
10
11class SymbolAPITestCase(TestBase):
12
Greg Clayton4570d3e2013-12-10 23:19:29 +000013 mydir = TestBase.compute_mydir(__file__)
Johnny Chendf2963e2011-04-01 00:35:55 +000014
Robert Flack13c7ad92015-03-30 14:12:17 +000015 @skipUnlessDarwin
Johnny Chendf2963e2011-04-01 00:35:55 +000016 @python_api_test
Johnny Chen24086bc2012-04-06 19:54:10 +000017 @dsym_test
Johnny Chendf2963e2011-04-01 00:35:55 +000018 def test_with_dsym(self):
19 """Exercise some SBSymbol and SBAddress APIs."""
20 self.buildDsym()
21 self.symbol_and_address_api()
22
23 @python_api_test
Johnny Chen24086bc2012-04-06 19:54:10 +000024 @dwarf_test
Zachary Turner9c7b08e2015-09-11 20:01:24 +000025 @expectedFailureWindows("llvm.org/pr24778")
Johnny Chendf2963e2011-04-01 00:35:55 +000026 def test_with_dwarf(self):
27 """Exercise some SBSymbol and SBAddress APIs."""
28 self.buildDwarf()
29 self.symbol_and_address_api()
30
31 def setUp(self):
32 # Call super's setUp().
33 TestBase.setUp(self)
34 # Find the line number to of function 'c'.
35 self.line1 = line_number('main.c', '// Find the line number for breakpoint 1 here.')
36 self.line2 = line_number('main.c', '// Find the line number for breakpoint 2 here.')
37
38 def symbol_and_address_api(self):
39 """Exercise some SBSymbol and SBAddress APIs."""
40 exe = os.path.join(os.getcwd(), "a.out")
41
42 # Create a target by the debugger.
43 target = self.dbg.CreateTarget(exe)
Johnny Chen4ebd0192011-05-24 18:22:45 +000044 self.assertTrue(target, VALID_TARGET)
Johnny Chendf2963e2011-04-01 00:35:55 +000045
46 # Now create the two breakpoints inside function 'a'.
47 breakpoint1 = target.BreakpointCreateByLocation('main.c', self.line1)
48 breakpoint2 = target.BreakpointCreateByLocation('main.c', self.line2)
49 #print "breakpoint1:", breakpoint1
50 #print "breakpoint2:", breakpoint2
Johnny Chen4ebd0192011-05-24 18:22:45 +000051 self.assertTrue(breakpoint1 and
Johnny Chendf2963e2011-04-01 00:35:55 +000052 breakpoint1.GetNumLocations() == 1,
53 VALID_BREAKPOINT)
Johnny Chen4ebd0192011-05-24 18:22:45 +000054 self.assertTrue(breakpoint2 and
Johnny Chendf2963e2011-04-01 00:35:55 +000055 breakpoint2.GetNumLocations() == 1,
56 VALID_BREAKPOINT)
57
58 # Now launch the process, and do not stop at entry point.
Greg Claytonc6947512013-12-13 19:18:59 +000059 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Johnny Chen5a0bee72011-06-15 22:14:12 +000060 self.assertTrue(process, PROCESS_IS_VALID)
Johnny Chendf2963e2011-04-01 00:35:55 +000061
62 # Frame #0 should be on self.line1.
Johnny Chen5a0bee72011-06-15 22:14:12 +000063 self.assertTrue(process.GetState() == lldb.eStateStopped)
64 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
Greg Clayton53c5ddf2013-03-19 17:59:30 +000065 self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition")
Johnny Chendf2963e2011-04-01 00:35:55 +000066 frame0 = thread.GetFrameAtIndex(0)
67 symbol_line1 = frame0.GetSymbol()
68 # We should have a symbol type of code.
69 self.assertTrue(symbol_line1.GetType() == lldb.eSymbolTypeCode)
70 addr_line1 = symbol_line1.GetStartAddress()
71 # And a section type of code, too.
Greg Claytoncac9c5f2011-09-24 00:52:29 +000072 self.assertTrue(addr_line1.GetSection().GetSectionType() == lldb.eSectionTypeCode)
Johnny Chendf2963e2011-04-01 00:35:55 +000073
74 # Continue the inferior, the breakpoint 2 should be hit.
Johnny Chen5a0bee72011-06-15 22:14:12 +000075 process.Continue()
76 self.assertTrue(process.GetState() == lldb.eStateStopped)
77 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
Greg Clayton53c5ddf2013-03-19 17:59:30 +000078 self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition")
Johnny Chendf2963e2011-04-01 00:35:55 +000079 frame0 = thread.GetFrameAtIndex(0)
80 symbol_line2 = frame0.GetSymbol()
81 # We should have a symbol type of code.
82 self.assertTrue(symbol_line2.GetType() == lldb.eSymbolTypeCode)
83 addr_line2 = symbol_line2.GetStartAddress()
84 # And a section type of code, too.
Greg Claytoncac9c5f2011-09-24 00:52:29 +000085 self.assertTrue(addr_line2.GetSection().GetSectionType() == lldb.eSectionTypeCode)
Johnny Chendf2963e2011-04-01 00:35:55 +000086
87 # Now verify that both addresses point to the same module.
Johnny Chen9efcb0e2011-04-19 19:44:26 +000088 if self.TraceOn():
89 print "UUID:", addr_line1.GetModule().GetUUIDString()
Johnny Chendf2963e2011-04-01 00:35:55 +000090 self.assertTrue(addr_line1.GetModule().GetUUIDString() == addr_line2.GetModule().GetUUIDString())
91
92
93if __name__ == '__main__':
94 import atexit
95 lldb.SBDebugger.Initialize()
96 atexit.register(lambda: lldb.SBDebugger.Terminate())
97 unittest2.main()