aboutsummaryrefslogtreecommitdiff
path: root/gdb/parse.c
diff options
context:
space:
mode:
authorJan Kratochvil <jan.kratochvil@redhat.com>2017-09-06 12:32:46 +0100
committerPedro Alves <palves@redhat.com>2017-09-06 12:32:46 +0100
commitfbd1b77155bd8139033b72871dbe7bf5be6031b1 (patch)
tree9a4e72928009e61d4214b3a026139161555ca4b7 /gdb/parse.c
parent39250b0a1c788215a39aea51dee9ba4f9937d404 (diff)
downloadgdb-fbd1b77155bd8139033b72871dbe7bf5be6031b1.zip
gdb-fbd1b77155bd8139033b72871dbe7bf5be6031b1.tar.gz
gdb-fbd1b77155bd8139033b72871dbe7bf5be6031b1.tar.bz2
Fix accessing TLS variables with no debug info
Since 2273f0ac95a7 ("change minsyms not to be relocated at read-time"), printing TLS symbols of objfiles with a non-zero base address, without debug info, fails. E.g., with: $ mv /usr/lib/debug /usr/lib/debug-x to get debug info out of the way, we get: $ echo 'int main(){}' | gcc -pthread -x c - $ ./gdb -q -ex start -ex 'p (int) errno' ./a.out Cannot access memory at address 0xffffef7c0698 instead of the expected: $1 = 0 The regression is not visible with glibc debuginfo installed. The problem is that we compute the address of TLS minsyms incorrectly. To trigger the problem, it is important that the variable is in an objfile with a non-zero base address. While glibc is a shared library for 'errno', it's easier for the testcase to use PIE instead of a shlib. For TLS variables in PT_EXEC the regression obviously does not happen. gdb/ChangeLog 2017-09-06 Jan Kratochvil <jan.kratochvil@redhat.com> * parse.c (find_minsym_type_and_address): Don't relocate addresses of TLS symbols. gdb/testsuite/ChangeLog 2017-09-06 Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.threads/tls-nodebug-pie.c: New file. * gdb.threads/tls-nodebug-pie.exp: New file.
Diffstat (limited to 'gdb/parse.c')
-rw-r--r--gdb/parse.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/gdb/parse.c b/gdb/parse.c
index 7971f6c..a11689b 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -491,11 +491,19 @@ find_minsym_type_and_address (minimal_symbol *msymbol,
{
bound_minimal_symbol bound_msym = {msymbol, objfile};
struct gdbarch *gdbarch = get_objfile_arch (objfile);
- CORE_ADDR addr = BMSYMBOL_VALUE_ADDRESS (bound_msym);
struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
enum minimal_symbol_type type = MSYMBOL_TYPE (msymbol);
CORE_ADDR pc;
+ bool is_tls = (section != NULL
+ && section->the_bfd_section->flags & SEC_THREAD_LOCAL);
+
+ /* Addresses of TLS symbols are really offsets into a
+ per-objfile/per-thread storage block. */
+ CORE_ADDR addr = (is_tls
+ ? MSYMBOL_VALUE_RAW_ADDRESS (bound_msym.minsym)
+ : BMSYMBOL_VALUE_ADDRESS (bound_msym));
+
/* The minimal symbol might point to a function descriptor;
resolve it to the actual code address instead. */
pc = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, &current_target);
@@ -525,7 +533,7 @@ find_minsym_type_and_address (minimal_symbol *msymbol,
if (overlay_debugging)
addr = symbol_overlayed_address (addr, section);
- if (section && section->the_bfd_section->flags & SEC_THREAD_LOCAL)
+ if (is_tls)
{
/* Skip translation if caller does not need the address. */
if (address_p != NULL)