1"""
2Test that LLDB can launch a linux executable through the dynamic loader and still hit a breakpoint.
3"""
4
5import lldb
6import os
7
8from lldbsuite.test.lldbtest import *
9
10class TestLinux64LaunchingViaDynamicLoader(TestBase):
11    mydir = TestBase.compute_mydir(__file__)
12
13    def test(self):
14        self.build()
15        exe = "/lib64/ld-linux-x86-64.so.2"
16        if(os.path.exists(exe)):
17            target = self.dbg.CreateTarget(exe)
18            self.assertTrue(target, VALID_TARGET)
19
20            # Set breakpoints both on shared library function as well as on
21            # main. Both of them will be pending breakpoints.
22            breakpoint_main = target.BreakpointCreateBySourceRegex("// Break here", lldb.SBFileSpec("main.cpp"))
23            breakpoint_shared_library = target.BreakpointCreateBySourceRegex("get_signal_crash", lldb.SBFileSpec("signal_file.cpp"))
24            launch_info = lldb.SBLaunchInfo([ "--library-path",self.get_process_working_directory(),self.getBuildArtifact("a.out")])
25            launch_info.SetWorkingDirectory(self.get_process_working_directory())
26            error = lldb.SBError()
27            process = target.Launch(launch_info,error)
28            self.assertTrue(error.Success())
29
30            # Stopped on main here.
31            self.assertEqual(process.GetState(), lldb.eStateStopped)
32            thread = process.GetSelectedThread()
33            self.assertIn("main",thread.GetFrameAtIndex(0).GetDisplayFunctionName())
34            process.Continue()
35
36            # Stopped on get_signal_crash function here.
37            self.assertEqual(process.GetState(), lldb.eStateStopped)
38            self.assertIn("get_signal_crash",thread.GetFrameAtIndex(0).GetDisplayFunctionName())
39            process.Continue()
40
41            # Stopped because of generated signal.
42            self.assertEqual(process.GetState(), lldb.eStateStopped)
43            self.assertIn("raise",thread.GetFrameAtIndex(0).GetDisplayFunctionName())
44            self.assertIn("get_signal_crash",thread.GetFrameAtIndex(1).GetDisplayFunctionName())
45
46
47