File: TestDyldLaunchLinux.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (69 lines) | stat: -rw-r--r-- 2,474 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Test that LLDB can launch a linux executable through the dynamic loader and still hit a breakpoint.
"""

import lldb
import os

from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *


class TestLinux64LaunchingViaDynamicLoader(TestBase):
    @skipIf(oslist=no_match(["linux"]))
    @no_debug_info_test
    @skipIf(oslist=["linux"], archs=["arm"])
    def test(self):
        self.build()

        # Extracts path of the interpreter.
        spec = lldb.SBModuleSpec()
        spec.SetFileSpec(lldb.SBFileSpec(self.getBuildArtifact("a.out")))
        interp_section = lldb.SBModule(spec).FindSection(".interp")
        if not interp_section:
            return
        section_data = interp_section.GetSectionData()
        error = lldb.SBError()
        exe = section_data.GetString(error, 0)
        if error.Fail():
            return

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set breakpoints both on shared library function as well as on
        # main. Both of them will be pending breakpoints.
        breakpoint_main = target.BreakpointCreateBySourceRegex(
            "// Break here", lldb.SBFileSpec("main.cpp")
        )
        breakpoint_shared_library = target.BreakpointCreateBySourceRegex(
            "get_signal_crash", lldb.SBFileSpec("signal_file.cpp")
        )
        launch_info = lldb.SBLaunchInfo(
            [
                "--library-path",
                self.get_process_working_directory(),
                self.getBuildArtifact("a.out"),
            ]
        )
        launch_info.SetWorkingDirectory(self.get_process_working_directory())
        error = lldb.SBError()
        process = target.Launch(launch_info, error)
        self.assertSuccess(error)

        # Stopped on main here.
        self.assertState(process.GetState(), lldb.eStateStopped)
        thread = process.GetSelectedThread()
        self.assertIn("main", thread.GetFrameAtIndex(0).GetDisplayFunctionName())
        process.Continue()

        # Stopped on get_signal_crash function here.
        self.assertState(process.GetState(), lldb.eStateStopped)
        self.assertIn(
            "get_signal_crash", thread.GetFrameAtIndex(0).GetDisplayFunctionName()
        )
        process.Continue()

        # Stopped because of generated signal.
        self.assertState(process.GetState(), lldb.eStateStopped)
        self.assertIn("raise", lldbutil.get_function_names(thread))