blob: 393dbb483650dadd56866bba216fabfc879018e4 [file] [log] [blame]
Johnny Chenacfbeff2010-07-08 00:17:29 +00001"""
2Test that debug symbols have the correct order as specified by the order file.
3"""
4
5import os, time
6import re
Johnny Chen73258832010-08-05 23:42:46 +00007import unittest2
Johnny Chenacfbeff2010-07-08 00:17:29 +00008import lldb
Johnny Chen17941842010-08-09 23:44:24 +00009from lldbtest import *
Johnny Chenacfbeff2010-07-08 00:17:29 +000010
Johnny Chencbb4be02010-09-01 19:59:58 +000011class OrderFileTestCase(TestBase):
Johnny Chenacfbeff2010-07-08 00:17:29 +000012
Johnny Chenfd709992011-06-27 18:25:00 +000013 mydir = os.path.join("macosx", "order")
Johnny Chenacfbeff2010-07-08 00:17:29 +000014
Johnny Chen1d8ab8a2010-09-14 22:55:48 +000015 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chen24086bc2012-04-06 19:54:10 +000016 @dsym_test
Johnny Chen1d8ab8a2010-09-14 22:55:48 +000017 def test_with_dsym(self):
Johnny Chenacfbeff2010-07-08 00:17:29 +000018 """Test debug symbols follow the correct order by the order file."""
Johnny Chen1d8ab8a2010-09-14 22:55:48 +000019 self.buildDsym()
20 self.order_file()
Johnny Chen6c3f6862010-09-14 22:50:50 +000021
Johnny Chen025c58f2011-12-22 19:21:46 +000022 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chen24086bc2012-04-06 19:54:10 +000023 @dwarf_test
Johnny Chen1d8ab8a2010-09-14 22:55:48 +000024 def test_with_dwarf(self):
25 """Test debug symbols follow the correct order by the order file."""
26 self.buildDwarf()
27 self.order_file()
28
29 def order_file(self):
30 """Test debug symbols follow the correct order by the order file."""
Johnny Chenacfbeff2010-07-08 00:17:29 +000031 exe = os.path.join(os.getcwd(), "a.out")
Johnny Chenff3d01d2010-08-20 21:03:09 +000032 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
Johnny Chenacfbeff2010-07-08 00:17:29 +000033
34 # Test that the debug symbols have Function f3 before Function f1.
Johnny Chen96332142010-12-17 18:02:08 +000035 # Use "-s address" option to sort by address.
36 self.runCmd("image dump symtab -s address a.out")
Johnny Chenff3d01d2010-08-20 21:03:09 +000037 output = self.res.GetOutput()
Johnny Chen9440d1c2010-09-13 16:59:11 +000038 mo_f3 = re.search("Code +.+f3", output)
39 mo_f1 = re.search("Code +.+f1", output)
Johnny Chenacfbeff2010-07-08 00:17:29 +000040
41 # Match objects for f3 and f1 must exist and f3 must come before f1.
Johnny Chen17941842010-08-09 23:44:24 +000042 self.assertTrue(mo_f3 and mo_f1 and mo_f3.start() < mo_f1.start(),
43 "Symbols have correct order by the order file")
Johnny Chenacfbeff2010-07-08 00:17:29 +000044
Johnny Chenff3d01d2010-08-20 21:03:09 +000045 self.runCmd("run", RUN_COMPLETED)
Johnny Chenacfbeff2010-07-08 00:17:29 +000046
47
48if __name__ == '__main__':
Johnny Chena2124952010-08-05 21:23:45 +000049 import atexit
Johnny Chenacfbeff2010-07-08 00:17:29 +000050 lldb.SBDebugger.Initialize()
Johnny Chena2124952010-08-05 21:23:45 +000051 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen73258832010-08-05 23:42:46 +000052 unittest2.main()