hanchenye-llvm-project/lldb/test
Richard Mitton 0a55835755 Added support for reading thread-local storage variables, as defined using the __thread modifier.
To make this work this patch extends LLDB to:

- Explicitly track the link_map address for each module. This is effectively the module handle, not sure why it wasn't already being stored off anywhere. As an extension later, it would be nice if someone were to add support for printing this as part of the modules list.

- Allow reading the per-thread data pointer via ptrace. I have added support for Linux here. I'll be happy to add support for FreeBSD once this is reviewed. OS X does not appear to have __thread variables, so maybe we don't need it there. Windows support should eventually be workable along the same lines.

- Make DWARF expressions track which module they originated from.

- Add support for the DW_OP_GNU_push_tls_address DWARF opcode, as generated by gcc and recent versions of clang. Earlier versions of clang (such as 3.2, which is default on Ubuntu right now) do not generate TLS debug info correctly so can not be supported here.

- Understand the format of the pthread DTV block. This is where it gets tricky. We have three basic options here:

  1) Call "dlinfo" or "__tls_get_addr" on the inferior and ask it directly. However this won't work on core dumps, and generally speaking it's not a good idea for the debugger to call functions itself, as it has the potential to not work depending on the state of the target.

  2) Use libthread_db. This is what GDB does. However this option requires having a version of libthread_db on the host cross-compiled for each potential target. This places a large burden on the user, and would make it very hard to cross-debug from Windows to Linux, for example. Trying to build a library intended exclusively for one OS on a different one is not pleasant. GDB sidesteps the problem and asks the user to figure it out.

  3) Parse the DTV structure ourselves. On initial inspection this seems to be a bad option, as the DTV structure (the format used by the runtime to manage TLS data) is not in fact a kernel data structure, it is implemented entirely in useerland in libc. Therefore the layout of it's fields are version and OS dependent, and are not standardized.

  However, it turns out not to be such a problem. All OSes use basically the same algorithm (a per-module lookup table) as detailed in Ulrich Drepper's TLS ELF ABI document, so we can easily write code to decode it ourselves. The only question therefore is the exact field layouts required. Happily, the implementors of libpthread expose the structure of the DTV via metadata exported as symbols from the .so itself, designed exactly for this kind of thing. So this patch simply reads that metadata in, and re-implements libthread_db's algorithm itself. We thereby get cross-platform TLS lookup without either requiring third-party libraries, while still being independent of the version of libpthread being used.

Test case included.

llvm-svn: 192922
2013-10-17 21:14:00 +00:00
..
api test: Update FreeBSD failure decorators 2013-09-13 15:34:59 +00:00
arm_emulation <rdar://problem/11358639> 2012-05-08 01:45:38 +00:00
attic Initial commit of a new testsuite feature: test categories. 2012-09-21 19:10:53 +00:00
benchmarks Test file renaming. 2012-04-23 17:54:40 +00:00
example Initial commit of a new testsuite feature: test categories. 2012-09-21 19:10:53 +00:00
expression_command <rdar://problem/12042982> 2013-10-04 23:14:13 +00:00
functionalities <rdar://problem/15235492> 2013-10-15 22:42:14 +00:00
help Re-apply TestHelp.py fix 2013-07-03 19:29:46 +00:00
lang Added support for reading thread-local storage variables, as defined using the __thread modifier. 2013-10-17 21:14:00 +00:00
linux/builtin_trap Clean up linux test decorators and add links to known bugs 2013-05-15 18:48:32 +00:00
logging Fix Linux Host::GetCurrentThreadID() to return real tid (not pthread_t). 2013-08-01 18:51:08 +00:00
macosx merge lldb-platform-work branch (and assorted fixes) into trunk 2013-08-26 23:57:52 +00:00
make Rearranged linker flags for test suite. 2013-10-17 20:09:33 +00:00
pexpect-2.4 Switch '/bin/bash' to '/bin/sh' 2013-09-03 23:04:53 +00:00
plugins Fix test execution on FreeBSD versions other than 9.x 2013-07-25 13:24:34 +00:00
python_api Mark 32/64-bit tests as expected fail after root causing and referencing bugzilla. 2013-09-26 23:30:59 +00:00
settings Fixed TestSettings.py to correctly restore the frame format string. 2013-10-03 01:50:35 +00:00
source-manager Fixed the TestSourceManager.py test case to not fail. It was using the "list" alias which has now been turned into a regex command that mimics the GDB equivalent. Changed "list" to "source list" to get around this problem. 2013-02-06 00:35:33 +00:00
terminal Continue the cleanup started on r158737 2012-06-20 10:13:40 +00:00
types <rdar://problem/12798131> 2012-12-04 00:32:51 +00:00
unittest2 Added a simple legend to the unit test 'dots' output, to aid understandability. 2013-09-25 20:47:51 +00:00
warnings/uuid <rdar://problem/13092722> 2013-02-01 21:38:35 +00:00
.categories Initial commit of a new testsuite feature: test categories. 2012-09-21 19:10:53 +00:00
CMakeLists.txt Unset CFLAGS/CXXFLAGS when running tests via cmake/make check targets 2013-05-13 21:41:35 +00:00
Makefile Unset CFLAGS/CXXFLAGS when running tests via cmake/make check targets 2013-05-13 21:41:35 +00:00
README-TestSuite Fix a typo. 2013-08-13 14:06:16 +00:00
argparse_compat.py Include a small argparse compatibility layer for Python < 2.7 2013-02-16 09:05:23 +00:00
bench-history Add bench entries. 2011-11-29 19:13:38 +00:00
bench.py
blacklist.py
dosep.ty Cleanup test output when run via cmake/make check targets 2013-05-13 21:37:02 +00:00
dotest.py Enabling 32-bit tests for clang on Linux by default (ie. for the buildbot.). 2013-09-30 23:33:43 +00:00
lldbbench.py Tests decorated with @benchmarks_test do not participate in the remote-macosx test suite run. 2012-04-19 23:50:00 +00:00
lldbtest.py Mark 32/64-bit tests as expected fail after root causing and referencing bugzilla. 2013-09-26 23:30:59 +00:00
lldbutil.py Add TestConcurrentEvents test for LLDB's handling of inferior threads 2013-07-09 00:08:01 +00:00
progress.py The new progress bar mode was losing us information compared to the old dots mode in that we would have no way of knowing about test failures (short of peeking into the test result directory.. and you're not supposed to peek!) 2013-02-09 00:37:07 +00:00
redo.py The new ReadStringFromMemory() API does not work correctly with NSStrings that have an explicit length and no NULL terminator 2013-04-23 20:05:05 +00:00