blob: d7651cb46fdcd8acf56339d1c88f1348e82258ff [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 Chen1d8ab8a2010-09-14 22:55:48 +000021 def test_with_dwarf(self):
22 """Test debug symbols follow the correct order by the order file."""
23 self.buildDwarf()
24 self.order_file()
25
26 def order_file(self):
27 """Test debug symbols follow the correct order by the order file."""
Johnny Chenacfbeff2010-07-08 00:17:29 +000028 exe = os.path.join(os.getcwd(), "a.out")
Johnny Chenff3d01d2010-08-20 21:03:09 +000029 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
Johnny Chenacfbeff2010-07-08 00:17:29 +000030
31 # Test that the debug symbols have Function f3 before Function f1.
Johnny Chen96332142010-12-17 18:02:08 +000032 # Use "-s address" option to sort by address.
33 self.runCmd("image dump symtab -s address a.out")
Johnny Chenff3d01d2010-08-20 21:03:09 +000034 output = self.res.GetOutput()
Johnny Chen9440d1c2010-09-13 16:59:11 +000035 mo_f3 = re.search("Code +.+f3", output)
36 mo_f1 = re.search("Code +.+f1", output)
Johnny Chenacfbeff2010-07-08 00:17:29 +000037
38 # Match objects for f3 and f1 must exist and f3 must come before f1.
Johnny Chen17941842010-08-09 23:44:24 +000039 self.assertTrue(mo_f3 and mo_f1 and mo_f3.start() < mo_f1.start(),
40 "Symbols have correct order by the order file")
Johnny Chenacfbeff2010-07-08 00:17:29 +000041
Johnny Chenff3d01d2010-08-20 21:03:09 +000042 self.runCmd("run", RUN_COMPLETED)
Johnny Chenacfbeff2010-07-08 00:17:29 +000043
44
45if __name__ == '__main__':
Johnny Chena2124952010-08-05 21:23:45 +000046 import atexit
Johnny Chenacfbeff2010-07-08 00:17:29 +000047 lldb.SBDebugger.Initialize()
Johnny Chena2124952010-08-05 21:23:45 +000048 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen73258832010-08-05 23:42:46 +000049 unittest2.main()