1843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen"""
2b201736d1daeee3238a9e85947d93a1044d09439Johnny ChenTest that breakpoint by symbol name works correctly with dynamic libs.
3843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen"""
4843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
5843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chenimport os, time
655e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chenimport re
775e28f942c1b9f9c6d5a0d5f2efd037cbbc9fc74Johnny Chenimport unittest2
8843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chenimport lldb
9d85dae5a089177582aff128c897c78332167fe08Johnny Chenfrom lldbtest import *
10431d839a33e9a274e705f7a268a1c9de2ffc2da2Jim Inghamimport lldbutil
11843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
121c42e8684d26e1473f92c799eeae65a3eec991d6Johnny Chenclass LoadUnloadTestCase(TestBase):
13843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
14edc4ddbef15572e68a500bfb11ecfeaf60b90894Jim Ingham    def getCategories (self):
15edc4ddbef15572e68a500bfb11ecfeaf60b90894Jim Ingham        return ['basic_process']
16edc4ddbef15572e68a500bfb11ecfeaf60b90894Jim Ingham
17607914d2274f35335911d14ad4dcbce98f7e0511Johnny Chen    mydir = os.path.join("functionalities", "load_unload")
18843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
1955e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen    def setUp(self):
2055e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        # Call super's setUp().
2155e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        TestBase.setUp(self)
2255e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        # Find the line number to break for main.cpp.
2355e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        self.line = line_number('main.c',
2455e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen                                '// Set break point at this line for test_lldb_process_load_and_unload_commands().')
25b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        self.line_d_function = line_number('d.c',
26b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen                                           '// Find this line number within d_dunction().')
27b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen
289c19b015ac6161a35fc56bb2d0fa84d1837063f8Ed Maste    @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
296bc4dcdfbcdfa455299d2123011b82a77351ee72Daniel Malea    @skipIfLinux # llvm.org/pr14424 - missing linux Makefiles/testcase support
309157f5dcfcf796e53e51b36d6beee68b060d1b07Johnny Chen    def test_modules_search_paths(self):
31af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        """Test target modules list after loading a different copy of the library libd.dylib, and verifies that it works with 'target modules search-paths add'."""
324d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen
334d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen        # Invoke the default build rule.
344d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen        self.buildDefault()
354d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen
364d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen        if sys.platform.startswith("darwin"):
374d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen            dylibName = 'libd.dylib'
384d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen
39dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        # The directory with the dynamic library we did not link to.
40af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        new_dir = os.path.join(os.getcwd(), "hidden")
414d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen
424d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen        old_dylib = os.path.join(os.getcwd(), dylibName)
434d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen        new_dylib = os.path.join(new_dir, dylibName)
444d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen
454d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen        exe = os.path.join(os.getcwd(), "a.out")
464d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
4713f96c3f674d5c46df1d4016ec4616b129b637ccJohnny Chen
489157f5dcfcf796e53e51b36d6beee68b060d1b07Johnny Chen        self.expect("target modules list",
494d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen            substrs = [old_dylib])
5067130e42592e68c3055e7ab5b7a368d89a06f05eJohnny Chen        #self.expect("target modules list -t 3",
5167130e42592e68c3055e7ab5b7a368d89a06f05eJohnny Chen        #    patterns = ["%s-[^-]*-[^-]*" % self.getArchitecture()])
52dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        # Add an image search path substitution pair.
539157f5dcfcf796e53e51b36d6beee68b060d1b07Johnny Chen        self.runCmd("target modules search-paths add %s %s" % (os.getcwd(), new_dir))
54dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        # Add teardown hook to clear image-search-paths after the test.
55dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        # rdar://problem/10501020
56dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        # Uncomment the following to reproduce 10501020.
57fa21ffd0c50efce27bfa084c6fb33dff255288b0Johnny Chen        self.addTearDownHook(lambda: self.runCmd("target modules search-paths clear"))
589157f5dcfcf796e53e51b36d6beee68b060d1b07Johnny Chen
599157f5dcfcf796e53e51b36d6beee68b060d1b07Johnny Chen        self.expect("target modules search-paths list",
609157f5dcfcf796e53e51b36d6beee68b060d1b07Johnny Chen            substrs = [os.getcwd(), new_dir])
619157f5dcfcf796e53e51b36d6beee68b060d1b07Johnny Chen
62dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        self.expect("target modules search-paths query %s" % os.getcwd(), "Image search path successfully transformed",
63dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen            substrs = [new_dir])
64dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen
65dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        # Obliterate traces of libd from the old location.
66dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        os.remove(old_dylib)
67dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        # Inform dyld of the new path, too.
68e5aa0d42b55ff6510888c737ef731f3fc1b54bb2Daniel Malea        env_cmd_string = "settings set target.env-vars " + self.dylibPath + "=" + new_dir
69dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        if self.TraceOn():
70dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen            print "Set environment to: ", env_cmd_string
71dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        self.runCmd(env_cmd_string)
72dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        self.runCmd("settings show target.env-vars")
73dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen
74e5aa0d42b55ff6510888c737ef731f3fc1b54bb2Daniel Malea        remove_dyld_path_cmd = "settings remove target.env-vars " + self.dylibPath
75dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        self.addTearDownHook(lambda: self.runCmd(remove_dyld_path_cmd))
76dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen
77dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen        self.runCmd("run")
78dd549796720f67a739815bbf507ac933dd5ca12fJohnny Chen
799157f5dcfcf796e53e51b36d6beee68b060d1b07Johnny Chen        self.expect("target modules list", "LLDB successfully locates the relocated dynamic library",
804d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen            substrs = [new_dylib])
814d661357f2d535c8243ae8433ba030058fb698c7Johnny Chen
829c19b015ac6161a35fc56bb2d0fa84d1837063f8Ed Maste    @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
836bc4dcdfbcdfa455299d2123011b82a77351ee72Daniel Malea    @skipIfLinux # llvm.org/pr14424 - missing linux Makefiles/testcase support
84b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen    def test_dyld_library_path(self):
85b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        """Test DYLD_LIBRARY_PATH after moving libd.dylib, which defines d_function, somewhere else."""
86b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen
87b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        # Invoke the default build rule.
88b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        self.buildDefault()
89b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen
90af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        exe = os.path.join(os.getcwd(), "a.out")
91af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
92af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham
93b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        if sys.platform.startswith("darwin"):
94b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen            dylibName = 'libd.dylib'
95b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen            dsymName = 'libd.dylib.dSYM'
96b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen
97b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        # The directory to relocate the dynamic library and its debugging info.
982a45d0e1d8ff6ac9c9e30b682c8dd8ed6d11a3c7Johnny Chen        special_dir = "hidden"
992a45d0e1d8ff6ac9c9e30b682c8dd8ed6d11a3c7Johnny Chen        new_dir = os.path.join(os.getcwd(), special_dir)
100b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen
101b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        old_dylib = os.path.join(os.getcwd(), dylibName)
102b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        new_dylib = os.path.join(new_dir, dylibName)
103b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        old_dSYM = os.path.join(os.getcwd(), dsymName)
104b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        new_dSYM = os.path.join(new_dir, dsymName)
105af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham
106b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        #system(["ls", "-lR", "."])
107b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen
108af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        # Try running with the DYLD_LIBRARY_PATH environment variable set, make sure
109af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        # we pick up the hidden dylib.
110af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham
111e5aa0d42b55ff6510888c737ef731f3fc1b54bb2Daniel Malea        env_cmd_string = "settings set target.env-vars " + self.dylibPath + "=" + new_dir
112a013b20d2cf2c2c5ab589efcfd6f0eecce4db3cfJohnny Chen        if self.TraceOn():
113a013b20d2cf2c2c5ab589efcfd6f0eecce4db3cfJohnny Chen            print "Set environment to: ", env_cmd_string
1141684446acb5d2a66c8546c8b833522ca2b12c5fdJohnny Chen        self.runCmd(env_cmd_string)
115abb3302051246273eb92cca203c9a1b9d9736e05Greg Clayton        self.runCmd("settings show target.env-vars")
116af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham
117e5aa0d42b55ff6510888c737ef731f3fc1b54bb2Daniel Malea        remove_dyld_path_cmd = "settings remove target.env-vars " + self.dylibPath
118af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        self.addTearDownHook(lambda: self.runCmd(remove_dyld_path_cmd))
119af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham
120431d839a33e9a274e705f7a268a1c9de2ffc2da2Jim Ingham        lldbutil.run_break_set_by_file_and_line (self, "d.c", self.line_d_function, num_expected_locations=1, loc_exact=True)
121431d839a33e9a274e705f7a268a1c9de2ffc2da2Jim Ingham
122af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        # For now we don't track DYLD_LIBRARY_PATH, so the old library will be in
123af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        # the modules list.
124af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        self.expect("target modules list",
1252a45d0e1d8ff6ac9c9e30b682c8dd8ed6d11a3c7Johnny Chen            substrs = [os.path.basename(old_dylib)],
126af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham            matching=True)
127af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham
128b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        self.runCmd("run")
129b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
130b201736d1daeee3238a9e85947d93a1044d09439Johnny Chen            patterns = ["frame #0.*d_function.*at d.c:%d" % self.line_d_function])
13155e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
132af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        # After run, make sure the hidden library is present, and the one we didn't
133af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        # load is not.
134af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham        self.expect("target modules list",
1352a45d0e1d8ff6ac9c9e30b682c8dd8ed6d11a3c7Johnny Chen            substrs = [special_dir, os.path.basename(new_dylib)])
136af60381708b9a35f3fe21d7fc4d145df3f50a215Jim Ingham
1379c19b015ac6161a35fc56bb2d0fa84d1837063f8Ed Maste    @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
1386bc4dcdfbcdfa455299d2123011b82a77351ee72Daniel Malea    @skipIfLinux # llvm.org/pr14424 - missing linux Makefiles/testcase support
13955e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen    def test_lldb_process_load_and_unload_commands(self):
14055e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        """Test that lldb process load/unload command work correctly."""
14155e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
14255e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        # Invoke the default build rule.
14355e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        self.buildDefault()
14455e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
14555e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        exe = os.path.join(os.getcwd(), "a.out")
14655e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
14755e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
14855e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        # Break at main.c before the call to dlopen().
14955e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        # Use lldb's process load command to load the dylib, instead.
15055e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
151431d839a33e9a274e705f7a268a1c9de2ffc2da2Jim Ingham        lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
15255e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
15355e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        self.runCmd("run", RUN_SUCCEEDED)
15455e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
15555e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        # Make sure that a_function does not exist at this point.
15655e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        self.expect("image lookup -n a_function", "a_function should not exist yet",
15755e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen                    error=True, matching=False,
15855e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen            patterns = ["1 match found .* %s" % self.mydir])
15955e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
16055e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        # Use lldb 'process load' to load the dylib.
16155e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        self.expect("process load liba.dylib", "liba.dylib loaded correctly",
16255e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen            patterns = ['Loading "liba.dylib".*ok',
16355e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen                        'Image [0-9]+ loaded'])
16455e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
16555e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        # Search for and match the "Image ([0-9]+) loaded" pattern.
16655e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        output = self.res.GetOutput()
16755e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        pattern = re.compile("Image ([0-9]+) loaded")
16855e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        for l in output.split(os.linesep):
16955e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen            #print "l:", l
17055e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen            match = pattern.search(l)
17155e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen            if match:
17255e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen                break
17355e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        index = match.group(1)
17455e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
17555e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        # Now we should have an entry for a_function.
17655e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        self.expect("image lookup -n a_function", "a_function should now exist",
17755e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen            patterns = ["1 match found .*%s" % self.mydir])
17855e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
17955e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        # Use lldb 'process unload' to unload the dylib.
18055e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        self.expect("process unload %s" % index, "liba.dylib unloaded correctly",
18155e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen            patterns = ["Unloading .* with index %s.*ok" % index])
18255e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
18355e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen        self.runCmd("process continue")
18455e1bdf472f3965243ebfd634c1d729bbed58353Johnny Chen
1859c19b015ac6161a35fc56bb2d0fa84d1837063f8Ed Maste    @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
1866bc4dcdfbcdfa455299d2123011b82a77351ee72Daniel Malea    @skipIfLinux # llvm.org/pr14424 - missing linux Makefiles/testcase support
1873097439ac52d25909e706503afe5c0772f2aead2Johnny Chen    def test_load_unload(self):
188843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen        """Test breakpoint by name works correctly with dlopen'ing."""
189821a8c478a14484c3fd560db3354825b2dc49b99Johnny Chen
190821a8c478a14484c3fd560db3354825b2dc49b99Johnny Chen        # Invoke the default build rule.
191821a8c478a14484c3fd560db3354825b2dc49b99Johnny Chen        self.buildDefault()
192821a8c478a14484c3fd560db3354825b2dc49b99Johnny Chen
193843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen        exe = os.path.join(os.getcwd(), "a.out")
194029acae0cafa565e876eb8cbce1231310eef5356Johnny Chen        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
195843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
196843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen        # Break by function name a_function (not yet loaded).
197431d839a33e9a274e705f7a268a1c9de2ffc2da2Jim Ingham        lldbutil.run_break_set_by_symbol (self, "a_function", num_expected_locations=0)
198843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
1991bb9f9a3917c7ac7228d0a81a0ff8a225165800aJohnny Chen        self.runCmd("run", RUN_SUCCEEDED)
200843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
201843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen        # The stop reason of the thread should be breakpoint and at a_function.
202029acae0cafa565e876eb8cbce1231310eef5356Johnny Chen        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
203abe0fed36d83e1c37af9dae90c2d25db742b4515Greg Clayton            substrs = ['stopped',
204029acae0cafa565e876eb8cbce1231310eef5356Johnny Chen                       'a_function',
205029acae0cafa565e876eb8cbce1231310eef5356Johnny Chen                       'stop reason = breakpoint'])
206843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
207843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen        # The breakpoint should have a hit count of 1.
20841950cc77813637e6c67b069e4ad2faf8c5f6fa7Caroline Tice        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
209029acae0cafa565e876eb8cbce1231310eef5356Johnny Chen            substrs = [' resolved, hit count = 1'])
210843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
21114df3d469f2deb5eeaf19b37fe3ffb379907ce83Johnny Chen        # Issue the 'contnue' command.  We should stop agaian at a_function.
21214df3d469f2deb5eeaf19b37fe3ffb379907ce83Johnny Chen        # The stop reason of the thread should be breakpoint and at a_function.
21314df3d469f2deb5eeaf19b37fe3ffb379907ce83Johnny Chen        self.runCmd("continue")
214c958be48bdf79ce5b731e42b56793686f7fa559fJohnny Chen
215c958be48bdf79ce5b731e42b56793686f7fa559fJohnny Chen        # rdar://problem/8508987
216c958be48bdf79ce5b731e42b56793686f7fa559fJohnny Chen        # The a_function breakpoint should be encountered twice.
21714df3d469f2deb5eeaf19b37fe3ffb379907ce83Johnny Chen        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
218abe0fed36d83e1c37af9dae90c2d25db742b4515Greg Clayton            substrs = ['stopped',
21914df3d469f2deb5eeaf19b37fe3ffb379907ce83Johnny Chen                       'a_function',
22014df3d469f2deb5eeaf19b37fe3ffb379907ce83Johnny Chen                       'stop reason = breakpoint'])
22114df3d469f2deb5eeaf19b37fe3ffb379907ce83Johnny Chen
22214df3d469f2deb5eeaf19b37fe3ffb379907ce83Johnny Chen        # The breakpoint should have a hit count of 2.
22341950cc77813637e6c67b069e4ad2faf8c5f6fa7Caroline Tice        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
22414df3d469f2deb5eeaf19b37fe3ffb379907ce83Johnny Chen            substrs = [' resolved, hit count = 2'])
225843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
2269c19b015ac6161a35fc56bb2d0fa84d1837063f8Ed Maste    @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
2276bc4dcdfbcdfa455299d2123011b82a77351ee72Daniel Malea    @skipIfLinux # llvm.org/pr14424 - missing linux Makefiles/testcase support
228e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham    def test_step_over_load (self):
229e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        """Test stepping over code that loads a shared library works correctly."""
230e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham
231e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        # Invoke the default build rule.
232e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        self.buildDefault()
233e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham
234e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        exe = os.path.join(os.getcwd(), "a.out")
235e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
236e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham
237e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        # Break by function name a_function (not yet loaded).
238431d839a33e9a274e705f7a268a1c9de2ffc2da2Jim Ingham        lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
239e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham
240e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        self.runCmd("run", RUN_SUCCEEDED)
241e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham
242e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        # The stop reason of the thread should be breakpoint and at a_function.
243e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
244e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham            substrs = ['stopped',
245e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham                       'stop reason = breakpoint'])
246e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham
247e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        self.runCmd("thread step-over", "Stepping over function that loads library")
248e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham
249e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        # The stop reason should be step end.
250e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham        self.expect("thread list", "step over succeeded.",
251e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham            substrs = ['stopped',
252e787c7ea61b1d857b56a0c42a1cf7535115ecbfcJim Ingham                      'stop reason = step over'])
253843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen
254843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chenif __name__ == '__main__':
25588f8304a5b7864ce3c6966bc0250fa3b7069aef0Johnny Chen    import atexit
256843f689fd76344aa6921b94576a92d4ff7bba609Johnny Chen    lldb.SBDebugger.Initialize()
25788f8304a5b7864ce3c6966bc0250fa3b7069aef0Johnny Chen    atexit.register(lambda: lldb.SBDebugger.Terminate())
25875e28f942c1b9f9c6d5a0d5f2efd037cbbc9fc74Johnny Chen    unittest2.main()
259