blob: 1b49ebc2f1559b333e5b9cccc0ac9ddce53769ef [file] [log] [blame]
Johnny Chendf2963e2011-04-01 00:35:55 +00001"""
2Test newly added SBSymbol and SBAddress APIs.
3"""
4
Zachary Turner35d017f2015-10-23 17:04:29 +00005from __future__ import print_function
6
Zachary Turner0a0490b2015-10-27 20:12:05 +00007import use_lldb_suite
Zachary Turner77db4a82015-10-22 20:06:20 +00008
Johnny Chendf2963e2011-04-01 00:35:55 +00009import os, time
10import re
Johnny Chendf2963e2011-04-01 00:35:55 +000011import lldb, lldbutil
12from lldbtest import *
13
14class SymbolAPITestCase(TestBase):
15
Greg Clayton4570d3e2013-12-10 23:19:29 +000016 mydir = TestBase.compute_mydir(__file__)
Johnny Chendf2963e2011-04-01 00:35:55 +000017
Johnny Chendf2963e2011-04-01 00:35:55 +000018 def setUp(self):
19 # Call super's setUp().
20 TestBase.setUp(self)
21 # Find the line number to of function 'c'.
22 self.line1 = line_number('main.c', '// Find the line number for breakpoint 1 here.')
23 self.line2 = line_number('main.c', '// Find the line number for breakpoint 2 here.')
24
Pavel Labathdc8b2d32015-10-26 09:28:32 +000025 @add_test_categories(['pyapi'])
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000026 @expectedFailureWindows("llvm.org/pr24778")
27 def test(self):
Johnny Chendf2963e2011-04-01 00:35:55 +000028 """Exercise some SBSymbol and SBAddress APIs."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000029 self.build()
Johnny Chendf2963e2011-04-01 00:35:55 +000030 exe = os.path.join(os.getcwd(), "a.out")
31
32 # Create a target by the debugger.
33 target = self.dbg.CreateTarget(exe)
Johnny Chen4ebd0192011-05-24 18:22:45 +000034 self.assertTrue(target, VALID_TARGET)
Johnny Chendf2963e2011-04-01 00:35:55 +000035
36 # Now create the two breakpoints inside function 'a'.
37 breakpoint1 = target.BreakpointCreateByLocation('main.c', self.line1)
38 breakpoint2 = target.BreakpointCreateByLocation('main.c', self.line2)
Zachary Turner35d017f2015-10-23 17:04:29 +000039 #print("breakpoint1:", breakpoint1)
40 #print("breakpoint2:", breakpoint2)
Johnny Chen4ebd0192011-05-24 18:22:45 +000041 self.assertTrue(breakpoint1 and
Johnny Chendf2963e2011-04-01 00:35:55 +000042 breakpoint1.GetNumLocations() == 1,
43 VALID_BREAKPOINT)
Johnny Chen4ebd0192011-05-24 18:22:45 +000044 self.assertTrue(breakpoint2 and
Johnny Chendf2963e2011-04-01 00:35:55 +000045 breakpoint2.GetNumLocations() == 1,
46 VALID_BREAKPOINT)
47
48 # Now launch the process, and do not stop at entry point.
Greg Claytonc6947512013-12-13 19:18:59 +000049 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Johnny Chen5a0bee72011-06-15 22:14:12 +000050 self.assertTrue(process, PROCESS_IS_VALID)
Johnny Chendf2963e2011-04-01 00:35:55 +000051
52 # Frame #0 should be on self.line1.
Johnny Chen5a0bee72011-06-15 22:14:12 +000053 self.assertTrue(process.GetState() == lldb.eStateStopped)
54 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
Greg Clayton53c5ddf2013-03-19 17:59:30 +000055 self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition")
Johnny Chendf2963e2011-04-01 00:35:55 +000056 frame0 = thread.GetFrameAtIndex(0)
57 symbol_line1 = frame0.GetSymbol()
58 # We should have a symbol type of code.
59 self.assertTrue(symbol_line1.GetType() == lldb.eSymbolTypeCode)
60 addr_line1 = symbol_line1.GetStartAddress()
61 # And a section type of code, too.
Greg Claytoncac9c5f2011-09-24 00:52:29 +000062 self.assertTrue(addr_line1.GetSection().GetSectionType() == lldb.eSectionTypeCode)
Johnny Chendf2963e2011-04-01 00:35:55 +000063
64 # Continue the inferior, the breakpoint 2 should be hit.
Johnny Chen5a0bee72011-06-15 22:14:12 +000065 process.Continue()
66 self.assertTrue(process.GetState() == lldb.eStateStopped)
67 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
Greg Clayton53c5ddf2013-03-19 17:59:30 +000068 self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition")
Johnny Chendf2963e2011-04-01 00:35:55 +000069 frame0 = thread.GetFrameAtIndex(0)
70 symbol_line2 = frame0.GetSymbol()
71 # We should have a symbol type of code.
72 self.assertTrue(symbol_line2.GetType() == lldb.eSymbolTypeCode)
73 addr_line2 = symbol_line2.GetStartAddress()
74 # And a section type of code, too.
Greg Claytoncac9c5f2011-09-24 00:52:29 +000075 self.assertTrue(addr_line2.GetSection().GetSectionType() == lldb.eSectionTypeCode)
Johnny Chendf2963e2011-04-01 00:35:55 +000076
77 # Now verify that both addresses point to the same module.
Johnny Chen9efcb0e2011-04-19 19:44:26 +000078 if self.TraceOn():
Zachary Turner35d017f2015-10-23 17:04:29 +000079 print("UUID:", addr_line1.GetModule().GetUUIDString())
Johnny Chendf2963e2011-04-01 00:35:55 +000080 self.assertTrue(addr_line1.GetModule().GetUUIDString() == addr_line2.GetModule().GetUUIDString())