]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/unwind/sigtramp/TestSigtrampUnwind.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / unwind / sigtramp / TestSigtrampUnwind.py
1 """
2 Test that we can backtrace correctly with 'sigtramp' functions on the stack
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15
16 class SigtrampUnwind(TestBase):
17     mydir = TestBase.compute_mydir(__file__)
18
19     # On different platforms the "_sigtramp" and "__kill" frames are likely to be different.
20     # This test could probably be adapted to run on linux/*bsd easily enough.
21     @skipUnlessDarwin
22     def test(self):
23         """Test that we can backtrace correctly with _sigtramp on the stack"""
24         self.build()
25         self.setTearDownCleanup()
26
27         exe = os.path.join(os.getcwd(), "a.out")
28         target = self.dbg.CreateTarget(exe)
29         self.assertTrue(target, VALID_TARGET)
30
31         lldbutil.run_break_set_by_file_and_line(self, "main.c", line_number(
32             'main.c', '// Set breakpoint here'), num_expected_locations=1)
33
34         process = target.LaunchSimple(
35             None, None, self.get_process_working_directory())
36
37         if not process:
38             self.fail("SBTarget.Launch() failed")
39
40         if process.GetState() != lldb.eStateStopped:
41             self.fail("Process should be in the 'stopped' state, "
42                       "instead the actual state is: '%s'" %
43                       lldbutil.state_type_to_str(process.GetState()))
44
45         self.expect(
46             "pro handle  -n false -p true -s false SIGUSR1",
47             "Have lldb pass SIGUSR1 signals",
48             substrs=[
49                 "SIGUSR1",
50                 "true",
51                 "false",
52                 "false"])
53
54         lldbutil.run_break_set_by_symbol(
55             self,
56             "handler",
57             num_expected_locations=1,
58             module_name="a.out")
59
60         self.runCmd("continue")
61
62         thread = process.GetThreadAtIndex(0)
63
64         found_handler = False
65         found_sigtramp = False
66         found_kill = False
67         found_main = False
68
69         for f in thread.frames:
70             if f.GetFunctionName() == "handler":
71                 found_handler = True
72             if f.GetFunctionName() == "_sigtramp":
73                 found_sigtramp = True
74             if f.GetFunctionName() == "__kill":
75                 found_kill = True
76             if f.GetFunctionName() == "main":
77                 found_main = True
78
79         if self.TraceOn():
80             print("Backtrace once we're stopped:")
81             for f in thread.frames:
82                 print("  %d %s" % (f.GetFrameID(), f.GetFunctionName()))
83
84         if not found_handler:
85             self.fail("Unable to find handler() in backtrace.")
86
87         if not found_sigtramp:
88             self.fail("Unable to find _sigtramp() in backtrace.")
89
90         if not found_kill:
91             self.fail("Unable to find kill() in backtrace.")
92
93         if not found_main:
94             self.fail("Unable to find main() in backtrace.")