File: TestUnwindExpression.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 (88 lines) | stat: -rw-r--r-- 3,296 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
"""
Test stopping at a breakpoint in an expression, and unwinding from there.
"""


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


class UnwindFromExpressionTest(TestBase):
    main_spec = lldb.SBFileSpec("main.cpp", False)

    def build_and_run_to_bkpt(self):
        self.build()

        (target, process, self.thread, bkpt) = lldbutil.run_to_source_breakpoint(
            self, "// Set a breakpoint here to get started", self.main_spec
        )

        # Next set a breakpoint in this function, set up Expression options to stop on
        # breakpoint hits, and call the function.
        self.fun_bkpt = self.target().BreakpointCreateBySourceRegex(
            "// Stop inside the function here.", self.main_spec
        )
        self.assertTrue(self.fun_bkpt, VALID_BREAKPOINT)

    @no_debug_info_test
    @expectedFailureAll(bugnumber="llvm.org/pr33164")
    def test_conditional_bktp(self):
        """
        Test conditional breakpoint handling in the IgnoreBreakpoints = False case
        """
        self.build_and_run_to_bkpt()

        self.fun_bkpt.SetCondition("0")  # Should not get hit
        options = lldb.SBExpressionOptions()
        options.SetIgnoreBreakpoints(False)
        options.SetUnwindOnError(False)

        main_frame = self.thread.GetFrameAtIndex(0)
        val = main_frame.EvaluateExpression("second_function(47)", options)
        self.assertSuccess(val.GetError(), "We did complete the execution.")
        self.assertEqual(47, val.GetValueAsSigned())

    @add_test_categories(["pyapi"])
    @expectedFlakeyNetBSD
    def test_unwind_expression(self):
        """Test unwinding from an expression."""
        self.build_and_run_to_bkpt()

        # Run test with varying one thread timeouts to also test the halting
        # logic in the IgnoreBreakpoints = False case
        self.do_unwind_test(self.thread, self.fun_bkpt, 1000)
        self.do_unwind_test(self.thread, self.fun_bkpt, 100000)

    def do_unwind_test(self, thread, bkpt, timeout):
        #
        # Use Python API to evaluate expressions while stopped in a stack frame.
        #
        main_frame = thread.GetFrameAtIndex(0)

        options = lldb.SBExpressionOptions()
        options.SetIgnoreBreakpoints(False)
        options.SetUnwindOnError(False)
        options.SetOneThreadTimeoutInMicroSeconds(timeout)

        val = main_frame.EvaluateExpression("a_function_to_call()", options)

        self.assertTrue(val.GetError().Fail(), "We did not complete the execution.")
        error_str = val.GetError().GetCString()
        self.assertTrue(
            "Execution was interrupted, reason: breakpoint" in error_str,
            "And the reason was right.",
        )

        thread = lldbutil.get_one_thread_stopped_at_breakpoint(self.process(), bkpt)
        self.assertTrue(thread.IsValid(), "We are indeed stopped at our breakpoint")

        # Now unwind the expression, and make sure we got back to where we
        # started.
        self.assertSuccess(
            thread.UnwindInnermostExpression(), "We succeeded in unwinding"
        )

        cur_frame = thread.GetFrameAtIndex(0)
        self.assertTrue(cur_frame.IsEqual(main_frame), "We got back to the main frame.")