2 Test that objective-c constant strings are generated correctly by the expression
6 from __future__ import print_function
14 from lldbsuite.test.decorators import *
15 from lldbsuite.test.lldbtest import *
16 from lldbsuite.test import lldbutil
20 class TestObjCBreakpoints(TestBase):
22 mydir = TestBase.compute_mydir(__file__)
25 """Test setting Objective C specific breakpoints (DWARF in .o files)."""
27 self.setTearDownCleanup()
28 self.check_objc_breakpoints(False)
31 # Call super's setUp().
33 # Find the line number to break inside main().
34 self.main_source = "main.m"
35 self.line = line_number(self.main_source, '// Set breakpoint here')
37 def check_category_breakpoints(self):
38 name_bp = self.target.BreakpointCreateByName("myCategoryFunction")
39 selector_bp = self.target.BreakpointCreateByName(
41 lldb.eFunctionNameTypeSelector,
42 lldb.SBFileSpecList(),
43 lldb.SBFileSpecList())
45 name_bp.GetNumLocations() == selector_bp.GetNumLocations(),
46 'Make sure setting a breakpoint by name "myCategoryFunction" sets a breakpoint even though it is in a category')
47 for bp_loc in selector_bp:
48 function_name = bp_loc.GetAddress().GetSymbol().GetName()
50 " myCategoryFunction]" in function_name,
51 'Make sure all function names have " myCategoryFunction]" in their names')
53 category_bp = self.target.BreakpointCreateByName(
54 "-[MyClass(MyCategory) myCategoryFunction]")
55 stripped_bp = self.target.BreakpointCreateByName(
56 "-[MyClass myCategoryFunction]")
57 stripped2_bp = self.target.BreakpointCreateByName(
58 "[MyClass myCategoryFunction]")
60 category_bp.GetNumLocations() == 1,
61 "Make sure we can set a breakpoint using a full objective C function name with the category included (-[MyClass(MyCategory) myCategoryFunction])")
63 stripped_bp.GetNumLocations() == 1,
64 "Make sure we can set a breakpoint using a full objective C function name without the category included (-[MyClass myCategoryFunction])")
66 stripped2_bp.GetNumLocations() == 1,
67 "Make sure we can set a breakpoint using a full objective C function name without the category included ([MyClass myCategoryFunction])")
69 def check_objc_breakpoints(self, have_dsym):
70 """Test constant string generation amd comparison by the expression parser."""
72 # Set debugger into synchronous mode
73 self.dbg.SetAsync(False)
75 # Create a target by the debugger.
76 exe = os.path.join(os.getcwd(), "a.out")
77 self.target = self.dbg.CreateTarget(exe)
78 self.assertTrue(self.target, VALID_TARGET)
80 #----------------------------------------------------------------------
81 # Set breakpoints on all selectors whose name is "count". This should
82 # catch breakpoints that are both C functions _and_ anything whose
83 # selector is "count" because just looking at "count" we can't tell
84 # definitively if the name is a selector or a C function
85 #----------------------------------------------------------------------
86 name_bp = self.target.BreakpointCreateByName("count")
87 selector_bp = self.target.BreakpointCreateByName(
89 lldb.eFunctionNameTypeSelector,
90 lldb.SBFileSpecList(),
91 lldb.SBFileSpecList())
93 name_bp.GetNumLocations() >= selector_bp.GetNumLocations(),
94 'Make sure we get at least the same amount of breakpoints if not more when setting by name "count"')
96 selector_bp.GetNumLocations() > 50,
97 'Make sure we find a lot of "count" selectors') # There are 93 on the latest MacOSX
98 for bp_loc in selector_bp:
99 function_name = bp_loc.GetAddress().GetSymbol().GetName()
101 " count]" in function_name,
102 'Make sure all function names have " count]" in their names')
104 #----------------------------------------------------------------------
105 # Set breakpoints on all selectors whose name is "isEqual:". This should
106 # catch breakpoints that are only ObjC selectors because no C function
108 #----------------------------------------------------------------------
109 name_bp = self.target.BreakpointCreateByName("isEqual:")
110 selector_bp = self.target.BreakpointCreateByName(
112 lldb.eFunctionNameTypeSelector,
113 lldb.SBFileSpecList(),
114 lldb.SBFileSpecList())
116 name_bp.GetNumLocations() == selector_bp.GetNumLocations(),
117 'Make sure setting a breakpoint by name "isEqual:" only sets selector breakpoints')
118 for bp_loc in selector_bp:
119 function_name = bp_loc.GetAddress().GetSymbol().GetName()
121 " isEqual:]" in function_name,
122 'Make sure all function names have " isEqual:]" in their names')
124 self.check_category_breakpoints()
127 shutil.rmtree(exe + ".dSYM")
128 self.assertTrue(subprocess.call(
129 ['/usr/bin/strip', '-Sx', exe]) == 0, 'stripping dylib succeeded')
131 # Check breakpoints again, this time using the symbol table only
132 self.check_category_breakpoints()