]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/breakpoint/objc/TestObjCBreakpoints.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / breakpoint / objc / TestObjCBreakpoints.py
1 """
2 Test that objective-c constant strings are generated correctly by the expression
3 parser.
4 """
5
6 from __future__ import print_function
7
8
9 import os
10 import time
11 import shutil
12 import subprocess
13 import lldb
14 from lldbsuite.test.decorators import *
15 from lldbsuite.test.lldbtest import *
16 from lldbsuite.test import lldbutil
17
18
19 @skipUnlessDarwin
20 class TestObjCBreakpoints(TestBase):
21
22     mydir = TestBase.compute_mydir(__file__)
23
24     def test_break(self):
25         """Test setting Objective C specific breakpoints (DWARF in .o files)."""
26         self.build()
27         self.setTearDownCleanup()
28         self.check_objc_breakpoints(False)
29
30     def setUp(self):
31         # Call super's setUp().
32         TestBase.setUp(self)
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')
36
37     def check_category_breakpoints(self):
38         name_bp = self.target.BreakpointCreateByName("myCategoryFunction")
39         selector_bp = self.target.BreakpointCreateByName(
40             "myCategoryFunction",
41             lldb.eFunctionNameTypeSelector,
42             lldb.SBFileSpecList(),
43             lldb.SBFileSpecList())
44         self.assertTrue(
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()
49             self.assertTrue(
50                 " myCategoryFunction]" in function_name,
51                 'Make sure all function names have " myCategoryFunction]" in their names')
52
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]")
59         self.assertTrue(
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])")
62         self.assertTrue(
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])")
65         self.assertTrue(
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])")
68
69     def check_objc_breakpoints(self, have_dsym):
70         """Test constant string generation amd comparison by the expression parser."""
71
72         # Set debugger into synchronous mode
73         self.dbg.SetAsync(False)
74
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)
79
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(
88             "count",
89             lldb.eFunctionNameTypeSelector,
90             lldb.SBFileSpecList(),
91             lldb.SBFileSpecList())
92         self.assertTrue(
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"')
95         self.assertTrue(
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()
100             self.assertTrue(
101                 " count]" in function_name,
102                 'Make sure all function names have " count]" in their names')
103
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
107         # can end with a :
108         #----------------------------------------------------------------------
109         name_bp = self.target.BreakpointCreateByName("isEqual:")
110         selector_bp = self.target.BreakpointCreateByName(
111             "isEqual:",
112             lldb.eFunctionNameTypeSelector,
113             lldb.SBFileSpecList(),
114             lldb.SBFileSpecList())
115         self.assertTrue(
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()
120             self.assertTrue(
121                 " isEqual:]" in function_name,
122                 'Make sure all function names have " isEqual:]" in their names')
123
124         self.check_category_breakpoints()
125
126         if have_dsym:
127             shutil.rmtree(exe + ".dSYM")
128         self.assertTrue(subprocess.call(
129             ['/usr/bin/strip', '-Sx', exe]) == 0, 'stripping dylib succeeded')
130
131         # Check breakpoints again, this time using the symbol table only
132         self.check_category_breakpoints()