xref: /llvm-project/lldb/test/API/lang/cpp/thread_local/TestThreadLocal.py (revision 5b386158aacac4b41126983a5379d36ed413d0ea)
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    @expectedFailureAll(oslist=["windows", "linux", "freebsd", "netbsd"])
12    @skipIfDarwin  # rdar://120795095
13    def test_thread_local(self):
14        # Set a breakpoint on the first instruction of the main function,
15        # before the TLS initialization has run.
16        self.build()
17        exe = self.getBuildArtifact("a.out")
18
19        (target, process, _, _) = lldbutil.run_to_source_breakpoint(
20            self, "Set breakpoint here", lldb.SBFileSpec("main.cpp")
21        )
22        self.expect_expr("tl_local_int + 1", result_type="int", result_value="323")
23        self.expect_expr("*tl_local_ptr + 2", result_type="int", result_value="324")
24        self.expect_expr("tl_global_int", result_type="int", result_value="123")
25        self.expect_expr("*tl_global_ptr", result_type="int", result_value="45")
26
27        # Create the filespec by which to locate our a.out module. Use the
28        # absolute path to get the module for the current variant.
29        filespec = lldb.SBFileSpec(exe, False)
30
31        # Now see if we emit the correct error when the TLS is not yet
32        # initialized. Let's set a breakpoint on the first instruction
33        # of main.
34        main_module = target.FindModule(filespec)
35        self.assertTrue(main_module, VALID_MODULE)
36        main_address = main_module.FindSymbol("main").GetStartAddress()
37        main_bkpt = target.BreakpointCreateBySBAddress(main_address)
38
39        process.Kill()
40        lldbutil.run_to_breakpoint_do_run(self, target, main_bkpt)
41
42        # The test fails during tear down because the module isn't cleared.
43        # Even though this test case is marked as xfail, a failure during
44        # tear down still counts as an error.
45        main_module.Clear()
46
47        self.expect(
48            "expr tl_local_int",
49            error=True,
50            substrs=[
51                "couldn't get the value of variable tl_local_int",
52                "No TLS data currently exists for this thread",
53            ],
54        )
55        self.expect(
56            "expr *tl_local_ptr",
57            error=True,
58            substrs=[
59                "couldn't get the value of variable tl_local_ptr",
60                "No TLS data currently exists for this thread",
61            ],
62        )
63