Home | History | Annotate | Download | only in set_values
      1 """Test settings and readings of program variables."""
      2 
      3 import os, time
      4 import unittest2
      5 import lldb
      6 from lldbtest import *
      7 import lldbutil
      8 
      9 class SetValuesTestCase(TestBase):
     10 
     11     mydir = os.path.join("lang", "c", "set_values")
     12 
     13     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     14     @dsym_test
     15     def test_with_dsym(self):
     16         """Test settings and readings of program variables."""
     17         self.buildDsym()
     18         self.set_values()
     19 
     20     @dwarf_test
     21     def test_with_dwarf(self):
     22         """Test settings and readings of program variables."""
     23         self.buildDwarf()
     24         self.set_values()
     25 
     26     def setUp(self):
     27         # Call super's setUp().
     28         TestBase.setUp(self)
     29         # Find the line numbers to break inside main().
     30         self.line1 = line_number('main.c', '// Set break point #1.')
     31         self.line2 = line_number('main.c', '// Set break point #2.')
     32         self.line3 = line_number('main.c', '// Set break point #3.')
     33         self.line4 = line_number('main.c', '// Set break point #4.')
     34         self.line5 = line_number('main.c', '// Set break point #5.')
     35 
     36     def set_values(self):
     37         """Test settings and readings of program variables."""
     38         exe = os.path.join(os.getcwd(), "a.out")
     39         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
     40 
     41         # Set breakpoints on several places to set program variables.
     42         lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line1, num_expected_locations=1, loc_exact=True)
     43 
     44         lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line2, num_expected_locations=1, loc_exact=True)
     45 
     46         lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line3, num_expected_locations=1, loc_exact=True)
     47 
     48         lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line4, num_expected_locations=1, loc_exact=True)
     49 
     50         lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line5, num_expected_locations=1, loc_exact=True)
     51 
     52         self.runCmd("run", RUN_SUCCEEDED)
     53 
     54         # The stop reason of the thread should be breakpoint.
     55         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
     56             substrs = ['stopped',
     57                        'stop reason = breakpoint'])
     58 
     59         # The breakpoint should have a hit count of 1.
     60         self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
     61             substrs = [' resolved, hit count = 1'])
     62 
     63         # main.c:15
     64         # Check that 'frame variable --show-types' displays the correct data type and value.
     65         self.expect("frame variable --show-types", VARIABLES_DISPLAYED_CORRECTLY,
     66             startstr = "(char) i = 'a'")
     67 
     68         # Now set variable 'i' and check that it is correctly displayed.
     69         self.runCmd("expression i = 'b'")
     70         self.expect("frame variable --show-types", VARIABLES_DISPLAYED_CORRECTLY,
     71             startstr = "(char) i = 'b'")
     72 
     73         self.runCmd("continue")
     74 
     75         # main.c:36
     76         # Check that 'frame variable --show-types' displays the correct data type and value.
     77         self.expect("frame variable --show-types", VARIABLES_DISPLAYED_CORRECTLY,
     78             patterns = ["\((short unsigned int|unsigned short)\) i = 33"])
     79 
     80         # Now set variable 'i' and check that it is correctly displayed.
     81         self.runCmd("expression i = 333")
     82         self.expect("frame variable --show-types", VARIABLES_DISPLAYED_CORRECTLY,
     83             patterns = ["\((short unsigned int|unsigned short)\) i = 333"])
     84 
     85         self.runCmd("continue")
     86 
     87         # main.c:57
     88         # Check that 'frame variable --show-types' displays the correct data type and value.
     89         self.expect("frame variable --show-types", VARIABLES_DISPLAYED_CORRECTLY,
     90             startstr = "(long) i = 33")
     91 
     92         # Now set variable 'i' and check that it is correctly displayed.
     93         self.runCmd("expression i = 33333")
     94         self.expect("frame variable --show-types", VARIABLES_DISPLAYED_CORRECTLY,
     95             startstr = "(long) i = 33333")
     96 
     97         self.runCmd("continue")
     98 
     99         # main.c:78
    100         # Check that 'frame variable --show-types' displays the correct data type and value.
    101         self.expect("frame variable --show-types", VARIABLES_DISPLAYED_CORRECTLY,
    102             startstr = "(double) i = 3.14159")
    103 
    104         # Now set variable 'i' and check that it is correctly displayed.
    105         self.runCmd("expression i = 3.14")
    106         self.expect("frame variable --show-types", VARIABLES_DISPLAYED_CORRECTLY,
    107             startstr = "(double) i = 3.14")
    108 
    109         self.runCmd("continue")
    110 
    111         # main.c:85
    112         # Check that 'frame variable --show-types' displays the correct data type and value.
    113         # rdar://problem/8422727
    114         # set_values test directory: 'frame variable' shows only (long double) i =
    115         self.expect("frame variable --show-types", VARIABLES_DISPLAYED_CORRECTLY,
    116             startstr = "(long double) i = 3.14159")
    117 
    118         # Now set variable 'i' and check that it is correctly displayed.
    119         self.runCmd("expression i = 3.1")
    120         self.expect("frame variable --show-types", VARIABLES_DISPLAYED_CORRECTLY,
    121             startstr = "(long double) i = 3.1")
    122 
    123 
    124 if __name__ == '__main__':
    125     import atexit
    126     lldb.SBDebugger.Initialize()
    127     atexit.register(lambda: lldb.SBDebugger.Terminate())
    128     unittest2.main()
    129