1 """Look up enum type information and check for correct display.""" 2 3 import os, time 4 import unittest2 5 import lldb 6 from lldbtest import * 7 import lldbutil 8 9 class EnumTypesTestCase(TestBase): 10 11 mydir = os.path.join("lang", "c", "enum_types") 12 13 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 14 @dsym_test 15 def test_with_dsym(self): 16 """Test 'image lookup -t days' and check for correct display and enum value printing.""" 17 self.buildDsym() 18 self.image_lookup_for_enum_type() 19 20 # rdar://problem/8394746 21 # 'image lookup -t days' returns nothing with dwarf debug format. 22 @dwarf_test 23 def test_with_dwarf(self): 24 """Test 'image lookup -t days' and check for correct display and enum value printing.""" 25 self.buildDwarf() 26 self.image_lookup_for_enum_type() 27 28 def setUp(self): 29 # Call super's setUp(). 30 TestBase.setUp(self) 31 # Find the line number to break inside main(). 32 self.line = line_number('main.c', '// Set break point at this line.') 33 34 def image_lookup_for_enum_type(self): 35 """Test 'image lookup -t days' and check for correct display.""" 36 exe = os.path.join(os.getcwd(), "a.out") 37 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 38 39 # Break inside the main. 40 bkpt_id = lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) 41 42 self.runCmd("run", RUN_SUCCEEDED) 43 44 # The stop reason of the thread should be breakpoint. 45 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 46 substrs = ['stopped', 47 'stop reason = breakpoint']) 48 49 # The breakpoint should have a hit count of 1. 50 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, 51 substrs = [' resolved, hit count = 1']) 52 53 # Look up information about the 'days' enum type. 54 # Check for correct display. 55 self.expect("image lookup -t days", DATA_TYPES_DISPLAYED_CORRECTLY, 56 substrs = ['enum days {', 57 'Monday', 58 'Tuesday', 59 'Wednesday', 60 'Thursday', 61 'Friday', 62 'Saturday', 63 'Sunday', 64 'kNumDays', 65 '}']) 66 67 enum_values = [ '-4', 68 'Monday', 69 'Tuesday', 70 'Wednesday', 71 'Thursday', 72 'Friday', 73 'Saturday', 74 'Sunday', 75 'kNumDays', 76 '5']; 77 78 bkpt = self.target().FindBreakpointByID(bkpt_id) 79 for enum_value in enum_values: 80 self.expect("frame variable day", 'check for valid enumeration value', 81 substrs = [enum_value]) 82 lldbutil.continue_to_breakpoint (self.process(), bkpt) 83 if __name__ == '__main__': 84 import atexit 85 lldb.SBDebugger.Initialize() 86 atexit.register(lambda: lldb.SBDebugger.Terminate()) 87 unittest2.main() 88