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
15 class TlsGlobalTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
22 if self.getPlatform() == "freebsd" or self.getPlatform() == "linux":
23 # LD_LIBRARY_PATH must be set so the shared libraries are found on
25 if "LD_LIBRARY_PATH" in os.environ:
27 "settings set target.env-vars " +
30 os.environ["LD_LIBRARY_PATH"] +
34 self.runCmd("settings set target.env-vars " +
35 self.dylibPath + "=" + os.getcwd())
38 "settings remove target.env-vars " +
41 # TLS works differently on Windows, this would need to be implemented
45 bugnumber="llvm.org/pr28392",
47 lldbplatformutil.getDarwinOSTriples()))
49 """Test thread-local storage."""
51 exe = os.path.join(os.getcwd(), "a.out")
52 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
54 line1 = line_number('main.c', '// thread breakpoint')
55 lldbutil.run_break_set_by_file_and_line(
56 self, "main.c", line1, num_expected_locations=1, loc_exact=True)
57 self.runCmd("run", RUN_SUCCEEDED)
59 # The stop reason of the thread should be breakpoint.
60 self.runCmd("process status", "Get process status")
61 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
63 'stop reason = breakpoint'])
65 # BUG: sometimes lldb doesn't change threads to the stopped thread.
66 # (unrelated to this test).
67 self.runCmd("thread select 2", "Change thread")
69 # Check that TLS evaluates correctly within the thread.
70 self.expect("expr var_static", VARIABLES_DISPLAYED_CORRECTLY,
71 patterns=["\(int\) \$.* = 88"])
72 self.expect("expr var_shared", VARIABLES_DISPLAYED_CORRECTLY,
73 patterns=["\(int\) \$.* = 66"])
75 # Continue on the main thread
76 line2 = line_number('main.c', '// main breakpoint')
77 lldbutil.run_break_set_by_file_and_line(
78 self, "main.c", line2, num_expected_locations=1, loc_exact=True)
79 self.runCmd("continue", RUN_SUCCEEDED)
81 # The stop reason of the thread should be breakpoint.
82 self.runCmd("process status", "Get process status")
83 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
85 'stop reason = breakpoint'])
87 # BUG: sometimes lldb doesn't change threads to the stopped thread.
88 # (unrelated to this test).
89 self.runCmd("thread select 1", "Change thread")
91 # Check that TLS evaluates correctly within the main thread.
92 self.expect("expr var_static", VARIABLES_DISPLAYED_CORRECTLY,
93 patterns=["\(int\) \$.* = 44"])
94 self.expect("expr var_shared", VARIABLES_DISPLAYED_CORRECTLY,
95 patterns=["\(int\) \$.* = 33"])