summaryrefslogtreecommitdiff
path: root/devel/gdb/files/commit-ce25aa57a3
blob: 17e7c705bd0c89cefcfc3f62a2eb44eb1b5682a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
commit ce25aa57a3cdd028be5868423e6e55506ccd1053
Author: John Baldwin <jhb@FreeBSD.org>
Date:   Tue Mar 12 13:39:02 2019 -0700

    Support TLS variables on FreeBSD/i386.
    
    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.

diff --git gdb/i386-fbsd-tdep.c gdb/i386-fbsd-tdep.c
index ac57e7383d..f274847174 100644
--- gdb/i386-fbsd-tdep.c
+++ gdb/i386-fbsd-tdep.c
@@ -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