blob: 0997f878af51c8436e7a82a642e12a5fb0e2c4e6 [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")
16 def test_with_dsym(self):
Johnny Chenacfbeff2010-07-08 00:17:29 +000017 """Test debug symbols follow the correct order by the order file."""
Johnny Chen1d8ab8a2010-09-14 22:55:48 +000018 self.buildDsym()
19 self.order_file()
Johnny Chen6c3f6862010-09-14 22:50:50 +000020
Johnny Chen025c58f2011-12-22 19:21:46 +000021 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chen1d8ab8a2010-09-14 22:55:48 +000022 def test_with_dwarf(self):
23 """Test debug symbols follow the correct order by the order file."""
24 self.buildDwarf()
25 self.order_file()
26
27 def order_file(self):
28 """Test debug symbols follow the correct order by the order file."""
Johnny Chenacfbeff2010-07-08 00:17:29 +000029 exe = os.path.join(os.getcwd(), "a.out")
Johnny Chenff3d01d2010-08-20 21:03:09 +000030 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
Johnny Chenacfbeff2010-07-08 00:17:29 +000031
32 # Test that the debug symbols have Function f3 before Function f1.
Johnny Chen96332142010-12-17 18:02:08 +000033 # Use "-s address" option to sort by address.
34 self.runCmd("image dump symtab -s address a.out")
Johnny Chenff3d01d2010-08-20 21:03:09 +000035 output = self.res.GetOutput()
Johnny Chen9440d1c2010-09-13 16:59:11 +000036 mo_f3 = re.search("Code +.+f3", output)
37 mo_f1 = re.search("Code +.+f1", output)
Johnny Chenacfbeff2010-07-08 00:17:29 +000038
39 # Match objects for f3 and f1 must exist and f3 must come before f1.
Johnny Chen17941842010-08-09 23:44:24 +000040 self.assertTrue(mo_f3 and mo_f1 and mo_f3.start() < mo_f1.start(),
41 "Symbols have correct order by the order file")
Johnny Chenacfbeff2010-07-08 00:17:29 +000042
Johnny Chenff3d01d2010-08-20 21:03:09 +000043 self.runCmd("run", RUN_COMPLETED)
Johnny Chenacfbeff2010-07-08 00:17:29 +000044
45
46if __name__ == '__main__':
Johnny Chena2124952010-08-05 21:23:45 +000047 import atexit
Johnny Chenacfbeff2010-07-08 00:17:29 +000048 lldb.SBDebugger.Initialize()
Johnny Chena2124952010-08-05 21:23:45 +000049 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen73258832010-08-05 23:42:46 +000050 unittest2.main()