File: TestIndirectSymbols.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 (117 lines) | stat: -rw-r--r-- 4,445 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""Test stepping and setting breakpoints in indirect and re-exported symbols."""


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


class TestIndirectFunctions(TestBase):
    def setUp(self):
        # Call super's setUp().
        TestBase.setUp(self)
        # Find the line numbers that we will step to in main:
        self.main_source = "main.c"

    @skipUnlessDarwin
    @add_test_categories(["pyapi"])
    @expectedFailureDarwin("rdar://120796553")
    def test_with_python_api(self):
        """Test stepping and setting breakpoints in indirect and re-exported symbols."""
        self.build()
        exe = self.getBuildArtifact("a.out")

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

        lib1 = self.getBuildArtifact("libindirect.dylib")
        lib2 = self.getBuildArtifact("libreexport.dylib")
        self.registerSharedLibrariesWithTarget(target, [lib1, lib2])

        self.main_source_spec = lldb.SBFileSpec(self.main_source)

        break1 = target.BreakpointCreateBySourceRegex(
            "Set breakpoint here to step in indirect.", self.main_source_spec
        )
        self.assertTrue(break1, VALID_BREAKPOINT)

        break2 = target.BreakpointCreateBySourceRegex(
            "Set breakpoint here to step in reexported.", self.main_source_spec
        )
        self.assertTrue(break2, VALID_BREAKPOINT)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None, self.get_process_working_directory())

        self.assertTrue(process, PROCESS_IS_VALID)

        # The stop reason of the thread should be breakpoint.
        threads = lldbutil.get_threads_stopped_at_breakpoint(process, break1)
        if len(threads) != 1:
            self.fail("Failed to stop at breakpoint 1.")

        thread = threads[0]

        # Now do a step-into, and we should end up in the hidden target of this
        # indirect function.
        thread.StepInto()
        curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
        self.assertEqual(
            curr_function,
            "call_through_indirect_hidden",
            "Stepped into indirect symbols.",
        )

        # Now set a breakpoint using the indirect symbol name, and make sure we
        # get to that:
        break_indirect = target.BreakpointCreateByName("call_through_indirect")
        self.assertTrue(break_indirect, VALID_BREAKPOINT)

        # Now continue should take us to the second call through the indirect
        # symbol:

        threads = lldbutil.continue_to_breakpoint(process, break_indirect)
        self.assertEqual(len(threads), 1, "Stopped at breakpoint in indirect function.")
        curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
        self.assertEqual(
            curr_function,
            "call_through_indirect_hidden",
            "Stepped into indirect symbols.",
        )

        # Delete this breakpoint so it won't get in the way:
        target.BreakpointDelete(break_indirect.GetID())

        # Now continue to the site of the first re-exported function call in
        # main:
        threads = lldbutil.continue_to_breakpoint(process, break2)

        # This is stepping Into through a re-exported symbol to an indirect
        # symbol:
        thread.StepInto()
        curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
        self.assertEqual(
            curr_function,
            "call_through_indirect_hidden",
            "Stepped into indirect symbols.",
        )

        # And the last bit is to set a breakpoint on the re-exported symbol and
        # make sure we are again in out target function.
        break_reexported = target.BreakpointCreateByName("reexport_to_indirect")
        self.assertEqual(break_reexported.GetNumLocations(), 1, VALID_BREAKPOINT)

        # Now continue should take us to the second call through the indirect
        # symbol:

        threads = lldbutil.continue_to_breakpoint(process, break_reexported)
        self.assertEqual(
            len(threads), 1, "Stopped at breakpoint in reexported function target."
        )
        curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
        self.assertEqual(
            curr_function,
            "call_through_indirect_hidden",
            "Stepped into indirect symbols.",
        )