diff options
author | Greg Clayton <gclayton@apple.com> | 2016-07-01 17:17:23 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2016-07-01 17:17:23 +0000 |
commit | 63a27afae305cfcb30d74e05e406180e66690227 (patch) | |
tree | 8dabb90a545cd4652d476ac57ff7ba8eff3ee892 /lldb/packages/Python/lldbsuite/test | |
parent | 4e3656d2cb91ce5ad2e52d20e4c664de5a602a29 (diff) | |
download | bcm5719-llvm-63a27afae305cfcb30d74e05e406180e66690227.tar.gz bcm5719-llvm-63a27afae305cfcb30d74e05e406180e66690227.zip |
Added support for thread local variables on all Apple OS variants.
We had support that assumed that thread local data for a variable could be determined solely from the module in which the variable exists. While this work for linux, it doesn't work for Apple OSs. The DWARF for thread local variables consists of location opcodes that do something like:
DW_OP_const8u (x)
DW_OP_form_tls_address
or
DW_OP_const8u (x)
DW_OP_GNU_push_tls_address
The "x" is allowed to be anything that is needed to determine the location of the variable. For Linux "x" is the offset within the TLS data for a given executable (ModuleSP in LLDB). For Apple OS variants, it is the file address of the data structure that contains a pthread key that can be used with pthread_getspecific() and the offset needed.
This fix passes the "x" along to the thread:
virtual lldb::addr_t
lldb_private::Thread::GetThreadLocalData(const lldb::ModuleSP module, lldb::addr_t tls_file_addr);
Then this is passed along to the DynamicLoader::GetThreadLocalData():
virtual lldb::addr_t
lldb_private::DynamicLoader::GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr);
This allows each DynamicLoader plug-in do the right thing for the current OS.
The DynamicLoaderMacOSXDYLD was modified to be able to grab the pthread key from the data structure that is in memory and call "void *pthread_getspecific(pthread_key_t key)" to get the value of the thread local storage and it caches it per thread since it never changes.
I had to update the test case to access the thread local data before trying to print it as on Apple OS variants, thread locals are not available unless they have been accessed at least one by the current thread.
I also added a new lldb::ValueType named "eValueTypeVariableThreadLocal" so that we can ask SBValue objects for their ValueType and be able to tell when we have a thread local variable.
<rdar://problem/23308080>
llvm-svn: 274366
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
3 files changed, 16 insertions, 5 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/TestTlsGlobals.py b/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/TestTlsGlobals.py index 984117c143b..8e4f17ab39d 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/TestTlsGlobals.py +++ b/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/TestTlsGlobals.py @@ -26,7 +26,6 @@ class TlsGlobalTestCase(TestBase): self.runCmd("settings set target.env-vars " + self.dylibPath + "=" + os.getcwd()) self.addTearDownHook(lambda: self.runCmd("settings remove target.env-vars " + self.dylibPath)) - @unittest2.expectedFailure("rdar://7796742") @skipIfWindows # TLS works differently on Windows, this would need to be implemented separately. def test(self): """Test thread-local storage.""" diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/a.c b/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/a.c index b9a85902d11..ab1022514d1 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/a.c +++ b/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/a.c @@ -11,6 +11,12 @@ __thread int var_shared = 33; +int +touch_shared() +{ + return var_shared; +} + void shared_check() { var_shared *= 2; diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/main.c b/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/main.c index cbe01b89b7e..73e32ca39a5 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/main.c +++ b/lldb/packages/Python/lldbsuite/test/lang/c/tls_globals/main.c @@ -11,6 +11,10 @@ #include <unistd.h> void shared_check(); +// On some OS's (darwin) you must actually access a thread local variable +// before you can read it +int +touch_shared(); // Create some TLS storage within the static executable. __thread int var_static = 44; @@ -28,9 +32,11 @@ int main (int argc, char const *argv[]) { pthread_t handle; pthread_create(&handle, NULL, &fn_static, NULL); + touch_shared(); + for (; var_static;) + { + usleep(1); // main breakpoint + } - for(;;) - usleep(1); // main breakpoint - - return 0; + return 0; } |