Support TLS variables on FreeBSD/i386.
authorJohn Baldwin <jhb@FreeBSD.org>
Tue, 12 Mar 2019 20:39:02 +0000 (13:39 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Tue, 12 Mar 2019 20:45:48 +0000 (13:45 -0700)
Derive the pointer to the DTV array from the gs_base register.  As
with FreeBSD/amd64, gs_base is currently only available via the native
target.

gdb/ChangeLog:

* i386-fbsd-tdep.c (i386fbsd_get_thread_local_address): New.
(i386fbsd_init_abi): Install gdbarch
"fetch_tls_load_module_address" and "get_thread_local_address"
methods.

gdb/ChangeLog
gdb/i386-fbsd-tdep.c

index 2268dd2ca64e0490ef801914c14def95c729f540..b26f554e47d0ea3e5c0333c22656e77946c6108e 100644 (file)
@@ -1,3 +1,10 @@
+2019-03-12  John Baldwin  <jhb@FreeBSD.org>
+
+       * i386-fbsd-tdep.c (i386fbsd_get_thread_local_address): New.
+       (i386fbsd_init_abi): Install gdbarch
+       "fetch_tls_load_module_address" and "get_thread_local_address"
+       methods.
+
 2019-03-12  John Baldwin  <jhb@FreeBSD.org>
 
        * amd64-fbsd-tdep.c (amd64fbsd_get_thread_local_address): New.
index ac57e7383d7260027b3c1bac3cf7d6e8b4e3c5f7..f274847174cf37ed07589550e28e3af50d09ddc3 100644 (file)
@@ -320,6 +320,30 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
        "XSAVE extended state", cb_data);
 }
 
+/* Implement the get_thread_local_address gdbarch method.  */
+
+static CORE_ADDR
+i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
+                                  CORE_ADDR lm_addr, CORE_ADDR offset)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  struct regcache *regcache;
+
+  if (tdep->fsbase_regnum == -1)
+    error (_("Unable to fetch %%gsbase"));
+
+  regcache = get_thread_arch_regcache (ptid, gdbarch);
+
+  target_fetch_registers (regcache, tdep->fsbase_regnum + 1);
+
+  ULONGEST gsbase;
+  if (regcache->cooked_read (tdep->fsbase_regnum + 1, &gsbase) != REG_VALID)
+    error (_("Unable to fetch %%gsbase"));
+
+  CORE_ADDR dtv_addr = gsbase + gdbarch_ptr_bit (gdbarch) / 8;
+  return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset);
+}
+
 static void
 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
@@ -418,6 +442,11 @@ i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   set_gdbarch_core_read_description (gdbarch,
                                     i386fbsd_core_read_description);
+
+  set_gdbarch_fetch_tls_load_module_address (gdbarch,
+                                            svr4_fetch_objfile_link_map);
+  set_gdbarch_get_thread_local_address (gdbarch,
+                                       i386fbsd_get_thread_local_address);
 }
 
 void