1from lldbsuite.test import decorators
2
3import lldb
4from lldbsuite.test.decorators import *
5from lldbsuite.test.lldbtest import *
6from lldbsuite.test import lldbutil
7from lldbsuite.test import lldbtest
8
9
10class PlatformProcessCrashInfoTestCase(TestBase):
11
12    mydir = TestBase.compute_mydir(__file__)
13
14    @expectedFailureAll(oslist=["windows", "linux", "netbsd"])
15    def test_thread_local(self):
16        # Set a breakpoint on the first instruction of the main function,
17        # before the TLS initialization has run.
18        self.build()
19        exe = self.getBuildArtifact("a.out")
20
21        (target, process, _, _) = \
22            lldbutil.run_to_source_breakpoint(self, "Set breakpoint here",
23                                              lldb.SBFileSpec("main.cpp"))
24        self.expect_expr("tl_local_int + 1",
25                         result_type="int", result_value="323")
26        self.expect_expr("*tl_local_ptr + 2",
27                         result_type="int", result_value="324")
28        self.expect_expr("tl_global_int",
29                         result_type="int", result_value="123")
30        self.expect_expr("*tl_global_ptr",
31                         result_type="int", result_value="45")
32
33        # Create the filespec by which to locate our a.out module.
34        #
35        #  - Use the absolute path to get the module for the current variant.
36        #  - Use the relative path for reproducers. The modules are never
37        #    orphaned because the SB objects are leaked intentionally. This
38        #    causes LLDB to reuse the same module for every variant, because the
39        #    UUID is the same for all the inferiors. FindModule below only
40        #    compares paths and is oblivious to the fact that the UUIDs are the
41        #    same.
42        if configuration.is_reproducer():
43            filespec = lldb.SBFileSpec('a.out', False)
44        else:
45            filespec = lldb.SBFileSpec(exe, False)
46
47        # Now see if we emit the correct error when the TLS is not yet
48        # initialized. Let's set a breakpoint on the first instruction
49        # of main.
50        main_module = target.FindModule(filespec)
51        self.assertTrue(main_module, VALID_MODULE)
52        main_address = main_module.FindSymbol("main").GetStartAddress()
53        main_bkpt = target.BreakpointCreateBySBAddress(main_address)
54
55        process.Kill()
56        lldbutil.run_to_breakpoint_do_run(self, target, main_bkpt)
57
58        self.expect("expr tl_local_int", error=True,
59                    substrs=["couldn't get the value of variable tl_local_int",
60                             "No TLS data currently exists for this thread"])
61        self.expect("expr *tl_local_ptr", error=True,
62                    substrs=["couldn't get the value of variable tl_local_ptr",
63                             "No TLS data currently exists for this thread"])
64
65