aboutsummaryrefslogtreecommitdiffstats
path: root/packages/Python/lldbsuite/test/functionalities/unwind/noreturn/TestNoreturnUnwind.py
blob: 5946f3ffa21161d1f9e6b7057274192f3d4856f4 (plain) (blame)
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
"""
Test that we can backtrace correctly with 'noreturn' functions on the stack
"""

from __future__ import print_function


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


class NoreturnUnwind(TestBase):
    mydir = TestBase.compute_mydir(__file__)

    @skipIfWindows  # clang-cl does not support gcc style attributes.
    @expectedFailureAndroid(bugnumber="llvm.org/pr31192", archs=["x86_64"])
    def test(self):
        """Test that we can backtrace correctly with 'noreturn' functions on the stack"""
        self.build()
        self.setTearDownCleanup()

        exe = os.path.join(os.getcwd(), "a.out")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        process = target.LaunchSimple(
            None, None, self.get_process_working_directory())

        if not process:
            self.fail("SBTarget.Launch() failed")

        if process.GetState() != lldb.eStateStopped:
            self.fail("Process should be in the 'stopped' state, "
                      "instead the actual state is: '%s'" %
                      lldbutil.state_type_to_str(process.GetState()))

        thread = process.GetThreadAtIndex(0)
        abort_frame_number = 0
        for f in thread.frames:
            # Some C libraries mangle the abort symbol into __GI_abort.
            if f.GetFunctionName() in ["abort", "__GI_abort"]:
                break
            abort_frame_number = abort_frame_number + 1

        if self.TraceOn():
            print("Backtrace once we're stopped:")
            for f in thread.frames:
                print("  %d %s" % (f.GetFrameID(), f.GetFunctionName()))

        # I'm going to assume that abort() ends up calling/invoking another
        # function before halting the process.  In which case if abort_frame_number
        # equals 0, we didn't find abort() in the backtrace.
        if abort_frame_number == len(thread.frames):
            self.fail("Unable to find abort() in backtrace.")

        func_c_frame_number = abort_frame_number + 1
        if thread.GetFrameAtIndex(
                func_c_frame_number).GetFunctionName() != "func_c":
            self.fail("Did not find func_c() above abort().")

        # This depends on whether we see the func_b inlined function in the backtrace
        # or not.  I'm not interested in testing that aspect of the backtrace here
        # right now.

        if thread.GetFrameAtIndex(
                func_c_frame_number +
                1).GetFunctionName() == "func_b":
            func_a_frame_number = func_c_frame_number + 2
        else:
            func_a_frame_number = func_c_frame_number + 1

        if thread.GetFrameAtIndex(
                func_a_frame_number).GetFunctionName() != "func_a":
            self.fail("Did not find func_a() above func_c().")

        main_frame_number = func_a_frame_number + 1

        if thread.GetFrameAtIndex(
                main_frame_number).GetFunctionName() != "main":
            self.fail("Did not find main() above func_a().")