Home | History | Annotate | Download | only in struct_types
      1 """
      2 Test that break on a struct declaration has no effect.
      3 
      4 Instead, the first executable statement is set as the breakpoint.
      5 """
      6 
      7 import os, time
      8 import unittest2
      9 import lldb
     10 from lldbtest import *
     11 import lldbutil
     12 
     13 class StructTypesTestCase(TestBase):
     14 
     15     mydir = os.path.join("lang", "c", "struct_types")
     16 
     17     # rdar://problem/12566646
     18     @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
     19     @dsym_test
     20     def test_with_dsym(self):
     21         """Test that break on a struct declaration has no effect."""
     22         self.buildDsym()
     23         self.struct_types()
     24 
     25     # rdar://problem/12566646
     26     @expectedFailureIcc # llvm.org/pr16793
     27                         # ICC generates DW_AT_byte_size zero with a zero-length 
     28                         # array and LLDB doesn't process it correctly.
     29     @dwarf_test
     30     def test_with_dwarf(self):
     31         """Test that break on a struct declaration has no effect."""
     32         self.buildDwarf()
     33         self.struct_types()
     34 
     35     def setUp(self):
     36         # Call super's setUp().
     37         TestBase.setUp(self)
     38         # Find the line number to break for main.c.
     39         self.source = 'main.c'
     40         self.line = line_number(self.source, '// Set break point at this line.')
     41         self.first_executable_line = line_number(self.source,
     42                                                  '// This is the first executable statement.')
     43         self.return_line = line_number(self.source, '// This is the return statement.')
     44 
     45     def struct_types(self):
     46         """Test that break on a struct declaration has no effect and test structure access for zero sized arrays."""
     47         exe = os.path.join(os.getcwd(), "a.out")
     48 
     49         # Create a target by the debugger.
     50         target = self.dbg.CreateTarget(exe)
     51         self.assertTrue(target, VALID_TARGET)
     52 
     53         # Break on the struct declration statement in main.c.
     54         lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=False)
     55         lldbutil.run_break_set_by_file_and_line (self, "main.c", self.return_line, num_expected_locations=1, loc_exact=True)
     56 
     57         # Now launch the process, and do not stop at entry point.
     58         process = target.LaunchSimple(None, None, os.getcwd())
     59 
     60         if not process:
     61             self.fail("SBTarget.Launch() failed")
     62 
     63         thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
     64 
     65         # We should be stopped on the first executable statement within the
     66         # function where the original breakpoint was attempted.
     67         self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
     68             substrs = ['main.c:%d' % self.first_executable_line,
     69                        'stop reason = breakpoint'])
     70 
     71         # The breakpoint should have a hit count of 1.
     72         self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
     73             substrs = [' resolved, hit count = 1'])
     74 
     75         process.Continue()
     76         thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
     77 
     78         # Test zero length array access and make sure it succeeds with "frame variable"
     79         self.expect("frame variable pt.padding[0]",
     80             DATA_TYPES_DISPLAYED_CORRECTLY,
     81             substrs = ["pt.padding[0] = "])
     82         self.expect("frame variable pt.padding[1]",
     83             DATA_TYPES_DISPLAYED_CORRECTLY,
     84             substrs = ["pt.padding[1] = "])
     85         # Test zero length array access and make sure it succeeds with "expression"
     86         self.expect("expression -- (pt.padding[0])",
     87             DATA_TYPES_DISPLAYED_CORRECTLY,
     88             substrs = ["(char)", " = "])
     89 
     90         # The padding should be an array of size 0
     91         self.expect("image lookup -t point_tag",
     92             DATA_TYPES_DISPLAYED_CORRECTLY,
     93             substrs = ['padding[]']) # Once rdar://problem/12566646 is fixed, this should display correctly
     94 
     95         self.expect("expression -- &pt == (struct point_tag*)0",
     96                     substrs = ['false'])
     97 
     98 if __name__ == '__main__':
     99     import atexit
    100     lldb.SBDebugger.Initialize()
    101     atexit.register(lambda: lldb.SBDebugger.Terminate())
    102     unittest2.main()
    103