+/* Cache all future symbols that thread_db might request. We can not
+ request symbols at arbitrary states in the remote protocol, only
+ when the client tells us that new symbols are available. So when
+ we load the thread library, make sure to check the entire list. */
+
+static void
+thread_db_look_up_symbols (void)
+{
+ struct thread_db *thread_db = current_process ()->priv->thread_db;
+ const char **sym_list;
+ CORE_ADDR unused;
+
+ for (sym_list = thread_db->td_symbol_list_p (); *sym_list; sym_list++)
+ look_up_one_symbol (*sym_list, &unused, 1);
+
+ /* We're not interested in any other libraries loaded after this
+ point, only in symbols in libpthread.so. */
+ thread_db->all_symbols_looked_up = 1;
+}
+
+int
+thread_db_look_up_one_symbol (const char *name, CORE_ADDR *addrp)
+{
+ struct thread_db *thread_db = current_process ()->priv->thread_db;
+ int may_ask_gdb = !thread_db->all_symbols_looked_up;
+
+ /* If we've passed the call to thread_db_look_up_symbols, then
+ anything not in the cache must not exist; we're not interested
+ in any libraries loaded after that point, only in symbols in
+ libpthread.so. It might not be an appropriate time to look
+ up a symbol, e.g. while we're trying to fetch registers. */
+ return look_up_one_symbol (name, addrp, may_ask_gdb);
+}
+
+int
+thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
+ CORE_ADDR load_module, CORE_ADDR *address)
+{
+ psaddr_t addr;
+ td_err_e err;
+ struct lwp_info *lwp;
+ struct thread_info *saved_thread;
+ struct process_info *proc;
+ struct thread_db *thread_db;
+
+ proc = get_thread_process (thread);
+ thread_db = proc->priv->thread_db;
+
+ /* If the thread layer is not (yet) initialized, fail. */
+ if (thread_db == NULL || !thread_db->all_symbols_looked_up)
+ return TD_ERR;
+
+ /* If td_thr_tls_get_addr is missing rather do not expect td_thr_tlsbase
+ could work. */
+ if (thread_db->td_thr_tls_get_addr_p == NULL
+ || (load_module == 0 && thread_db->td_thr_tlsbase_p == NULL))
+ return -1;
+
+ lwp = get_thread_lwp (thread);
+ if (!lwp->thread_known)
+ find_one_thread (thread->entry.id);
+ if (!lwp->thread_known)
+ return TD_NOTHR;
+
+ saved_thread = current_thread;
+ current_thread = thread;
+
+ if (load_module != 0)
+ {
+ /* Note the cast through uintptr_t: this interface only works if
+ a target address fits in a psaddr_t, which is a host pointer.
+ So a 32-bit debugger can not access 64-bit TLS through this. */
+ err = thread_db->td_thr_tls_get_addr_p (&lwp->th,
+ (psaddr_t) (uintptr_t) load_module,
+ offset, &addr);
+ }
+ else
+ {
+ /* This code path handles the case of -static -pthread executables:
+ https://sourceware.org/ml/libc-help/2014-03/msg00024.html
+ For older GNU libc r_debug.r_map is NULL. For GNU libc after
+ PR libc/16831 due to GDB PR threads/16954 LOAD_MODULE is also NULL.
+ The constant number 1 depends on GNU __libc_setup_tls
+ initialization of l_tls_modid to 1. */
+ err = thread_db->td_thr_tlsbase_p (&lwp->th, 1, &addr);
+ addr = (char *) addr + offset;
+ }
+
+ current_thread = saved_thread;
+ if (err == TD_OK)