1 """Test that thread-local storage can be read correctly."""
3 from __future__ import print_function
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
14 class TlsGlobalTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
21 if self.getPlatform() == "freebsd" or self.getPlatform() == "linux":
22 # LD_LIBRARY_PATH must be set so the shared libraries are found on startup
23 if "LD_LIBRARY_PATH" in os.environ:
24 self.runCmd("settings set target.env-vars " + self.dylibPath + "=" + os.environ["LD_LIBRARY_PATH"] + ":" + os.getcwd())
26 self.runCmd("settings set target.env-vars " + self.dylibPath + "=" + os.getcwd())
27 self.addTearDownHook(lambda: self.runCmd("settings remove target.env-vars " + self.dylibPath))
29 @skipIfWindows # TLS works differently on Windows, this would need to be implemented separately.
30 @expectedFailureAll(bugnumber="llvm.org/pr28392", oslist=no_match(lldbplatformutil.getDarwinOSTriples()))
32 """Test thread-local storage."""
34 exe = os.path.join(os.getcwd(), "a.out")
35 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
37 line1 = line_number('main.c', '// thread breakpoint')
38 lldbutil.run_break_set_by_file_and_line (self, "main.c", line1, num_expected_locations=1, loc_exact=True)
39 self.runCmd("run", RUN_SUCCEEDED)
41 # The stop reason of the thread should be breakpoint.
42 self.runCmd("process status", "Get process status")
43 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
45 'stop reason = breakpoint'])
47 # BUG: sometimes lldb doesn't change threads to the stopped thread.
48 # (unrelated to this test).
49 self.runCmd("thread select 2", "Change thread")
51 # Check that TLS evaluates correctly within the thread.
52 self.expect("expr var_static", VARIABLES_DISPLAYED_CORRECTLY,
53 patterns = ["\(int\) \$.* = 88"])
54 self.expect("expr var_shared", VARIABLES_DISPLAYED_CORRECTLY,
55 patterns = ["\(int\) \$.* = 66"])
57 # Continue on the main thread
58 line2 = line_number('main.c', '// main breakpoint')
59 lldbutil.run_break_set_by_file_and_line (self, "main.c", line2, num_expected_locations=1, loc_exact=True)
60 self.runCmd("continue", RUN_SUCCEEDED)
62 # The stop reason of the thread should be breakpoint.
63 self.runCmd("process status", "Get process status")
64 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
66 'stop reason = breakpoint'])
68 # BUG: sometimes lldb doesn't change threads to the stopped thread.
69 # (unrelated to this test).
70 self.runCmd("thread select 1", "Change thread")
72 # Check that TLS evaluates correctly within the main thread.
73 self.expect("expr var_static", VARIABLES_DISPLAYED_CORRECTLY,
74 patterns = ["\(int\) \$.* = 44"])
75 self.expect("expr var_shared", VARIABLES_DISPLAYED_CORRECTLY,
76 patterns = ["\(int\) \$.* = 33"])