View | Details | Raw Unified | Return to bug 197501
Collapse All | Expand All

(-)Makefile (-6 / +1 lines)
Lines 66-76 Link Here
66
EXCLUDE+=	readline
66
EXCLUDE+=	readline
67
.endif
67
.endif
68
68
69
.if ${PORT_OPTIONS:MTHREADS}
70
EXTRA_PATCHES+=	${FILESDIR}/extrapatch-gdb-configure.tgt \
71
		${FILESDIR}/extrapatch-gdb-Makefile.in
72
.endif
73
74
.if ${ARCH} == "amd64"
69
.if ${ARCH} == "amd64"
75
CONFIGURE_TARGET=	x86_64-portbld-freebsd${OSREL}
70
CONFIGURE_TARGET=	x86_64-portbld-freebsd${OSREL}
76
.endif
71
.endif
Lines 78-86 Link Here
78
post-patch:
73
post-patch:
79
	@${REINPLACE_CMD} -e 's|$$| [GDB v${PORTVERSION} for FreeBSD]|' \
74
	@${REINPLACE_CMD} -e 's|$$| [GDB v${PORTVERSION} for FreeBSD]|' \
80
		${WRKSRC}/gdb/version.in
75
		${WRKSRC}/gdb/version.in
81
82
.if ${PORT_OPTIONS:MTHREADS}
76
.if ${PORT_OPTIONS:MTHREADS}
83
	@${CP} ${FILESDIR}/fbsd-threads.c ${WRKSRC}/gdb/
77
	@${CP} ${FILESDIR}/fbsd-threads.c ${WRKSRC}/gdb/
78
	@${PATCH} ${PATCH_ARGS} < ${FILESDIR}/extrapatch-threads
84
.endif
79
.endif
85
80
86
do-install:
81
do-install:
(-)files/extrapatch-gdb-Makefile.in (-28 lines)
Lines 1-28 Link Here
1
--- gdb/Makefile.in.orig	2013-04-02 19:38:43.000000000 +0200
2
+++ gdb/Makefile.in	2013-05-18 13:08:47.000000000 +0200
3
@@ -585,6 +585,7 @@
4
 	xtensa-config.o xtensa-tdep.o xtensa-linux-tdep.o \
5
 	glibc-tdep.o \
6
 	bsd-uthread.o \
7
+	fbsd-threads.o \
8
 	nbsd-tdep.o obsd-tdep.o \
9
 	sol2-tdep.o \
10
 	solib-frv.o solib-irix.o solib-svr4.o \
11
@@ -1173,7 +1174,7 @@
12
 # Removing the old gdb first works better if it is running, at least on SunOS.
13
 gdb$(EXEEXT): gdb.o $(LIBGDB_OBS) $(ADD_DEPS) $(CDEPS) $(TDEPLIBS)
14
 	rm -f gdb$(EXEEXT)
15
-	$(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \
16
+	$(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) -Wl,-E \
17
 		-o gdb$(EXEEXT) gdb.o $(LIBGDB_OBS) \
18
 		$(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES)
19
 
20
@@ -1442,7 +1443,7 @@
21
 	armnbsd-nat.c armbsd-tdep.c armnbsd-tdep.c armobsd-tdep.c \
22
 	avr-tdep.c \
23
 	bfin-linux-tdep.c bfin-tdep.c \
24
-	bsd-uthread.c bsd-kvm.c \
25
+	bsd-uthread.c fbsd-threads.c bsd-kvm.c \
26
 	core-regset.c \
27
 	dcache.c dicos-tdep.c darwin-nat.c \
28
 	exec.c \
(-)files/extrapatch-gdb-configure.tgt (-29 lines)
Lines 1-29 Link Here
1
--- gdb/configure.tgt.orig	2013-03-05 14:37:10.000000000 +0100
2
+++ gdb/configure.tgt	2013-05-18 13:11:06.000000000 +0200
3
@@ -188,7 +188,7 @@
4
 i[34567]86-*-freebsd* | i[34567]86-*-kfreebsd*-gnu)
5
 	# Target: FreeBSD/i386
6
 	gdb_target_obs="i386-tdep.o i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \
7
-			bsd-uthread.o solib-svr4.o"
8
+			fbsd-threads.o solib-svr4.o"
9
 	;;
10
 i[34567]86-*-netbsd* | i[34567]86-*-knetbsd*-gnu)
11
 	# Target: NetBSD/i386
12
@@ -398,7 +398,7 @@
13
 powerpc*-*-freebsd*)
14
 	# Target: FreeBSD/powerpc
15
 	gdb_target_obs="rs6000-tdep.o ppc-sysv-tdep.o ppc64-tdep.o \
16
-		        ppcfbsd-tdep.o solib-svr4.o \
17
+		        ppcfbsd-tdep.o solib-svr4.o fbsd-threads.o \
18
 			ravenscar-thread.o ppc-ravenscar-thread.o"
19
 	;;
20
 
21
@@ -650,7 +650,7 @@
22
 	# Target: FreeBSD/amd64
23
 	gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o i386-tdep.o \
24
 			i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \
25
-			bsd-uthread.o solib-svr4.o"
26
+			fbsd-threads.o solib-svr4.o"
27
 	;;
28
 x86_64-*-mingw* | x86_64-*-cygwin*)
29
         # Target: MingW/amd64
(-)files/extrapatch-threads (+712 lines)
Line 0 Link Here
1
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
2
index ea27cf5..d17752f 100644
3
--- gdb/Makefile.in
4
+++ gdb/Makefile.in
5
@@ -668,6 +668,7 @@ ALL_TARGET_OBS = \
6
 	xtensa-config.o xtensa-tdep.o xtensa-linux-tdep.o \
7
 	glibc-tdep.o \
8
 	bsd-uthread.o \
9
+	fbsd-threads.o \
10
 	nbsd-tdep.o obsd-tdep.o \
11
 	sol2-tdep.o \
12
 	solib-frv.o solib-irix.o solib-svr4.o \
13
@@ -1327,7 +1328,7 @@ libgdb.a: $(LIBGDB_OBS)
14
 # Removing the old gdb first works better if it is running, at least on SunOS.
15
 gdb$(EXEEXT): gdb.o $(LIBGDB_OBS) $(ADD_DEPS) $(CDEPS) $(TDEPLIBS)
16
 	rm -f gdb$(EXEEXT)
17
-	$(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \
18
+	$(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) -Wl,-E \
19
 		-o gdb$(EXEEXT) gdb.o $(LIBGDB_OBS) \
20
 		$(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES)
21
 
22
@@ -1600,7 +1601,7 @@ ALLDEPFILES = \
23
 	armnbsd-nat.c armbsd-tdep.c armnbsd-tdep.c armobsd-tdep.c \
24
 	avr-tdep.c \
25
 	bfin-linux-tdep.c bfin-tdep.c \
26
-	bsd-uthread.c bsd-kvm.c \
27
+	bsd-uthread.c fbsd-threads.c bsd-kvm.c \
28
 	core-regset.c \
29
 	dcache.c dicos-tdep.c darwin-nat.c \
30
 	exec.c \
31
diff --git a/gdb/amd64bsd-nat.c b/gdb/amd64bsd-nat.c
32
index 9e6a0df..7aff6f0 100644
33
--- gdb/amd64bsd-nat.c
34
+++ gdb/amd64bsd-nat.c
35
@@ -41,6 +41,19 @@
36
 size_t x86_xsave_len;
37
 #endif
38
 
39
+static pid_t
40
+ptrace_pid (ptid_t ptid)
41
+{
42
+  pid_t pid;
43
+
44
+#ifdef __FreeBSD__
45
+  pid = ptid_get_lwp (ptid);
46
+  if (pid == 0)
47
+#endif
48
+    pid = ptid_get_pid (ptid);
49
+  return pid;
50
+}
51
+  
52
 /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
53
    for all registers (including the floating-point registers).  */
54
 
55
@@ -54,7 +67,7 @@ amd64bsd_fetch_inferior_registers (struct target_ops *ops,
56
     {
57
       struct reg regs;
58
 
59
-      if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
60
+      if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid),
61
 		  (PTRACE_TYPE_ARG3) &regs, 0) == -1)
62
 	perror_with_name (_("Couldn't get registers"));
63
 
64
@@ -72,7 +85,7 @@ amd64bsd_fetch_inferior_registers (struct target_ops *ops,
65
       if (x86_xsave_len != 0)
66
 	{
67
 	  xstateregs = alloca(x86_xsave_len);
68
-	  if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
69
+	  if (ptrace (PT_GETXSTATE, ptrace_pid (inferior_ptid),
70
 		      (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
71
 	    perror_with_name (_("Couldn't get extended state status"));
72
 
73
@@ -81,7 +94,7 @@ amd64bsd_fetch_inferior_registers (struct target_ops *ops,
74
 	}
75
 #endif
76
 
77
-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
78
+      if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid),
79
 		  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
80
 	perror_with_name (_("Couldn't get floating point status"));
81
 
82
@@ -104,11 +117,11 @@ amd64bsd_store_inferior_registers (struct target_ops *ops,
83
 
84
       memset( &regs, 0, sizeof(struct reg));
85
       memset( &oldregs, 0, sizeof(struct reg));
86
-      if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
87
+      if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid),
88
                   (PTRACE_TYPE_ARG3) &regs, 0) == -1)
89
         perror_with_name (_("Couldn't get registers"));
90
 
91
-      ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
92
+      ptrace (PT_GETREGS, ptrace_pid (inferior_ptid),
93
                   (PTRACE_TYPE_ARG3) &oldregs, 0);
94
       amd64_collect_native_gregset (regcache, &regs, regnum);
95
 
96
@@ -118,7 +131,7 @@ amd64bsd_store_inferior_registers (struct target_ops *ops,
97
         regs.r_rflags ^= (regs.r_rflags ^ oldregs.r_rflags ) & ~PSL_USERCHANGE;
98
         //printf("    allowed regs.r_rflags = 0x%8.8X\n", regs.r_rflags );
99
       }
100
-      if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
101
+      if (ptrace (PT_SETREGS, ptrace_pid (inferior_ptid),
102
 	          (PTRACE_TYPE_ARG3) &regs, 0) == -1)
103
         perror_with_name (_("Couldn't write registers"));
104
 
105
@@ -135,26 +148,26 @@ amd64bsd_store_inferior_registers (struct target_ops *ops,
106
       if (x86_xsave_len != 0)
107
 	{
108
 	  xstateregs = alloca(x86_xsave_len);
109
-	  if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
110
+	  if (ptrace (PT_GETXSTATE, ptrace_pid (inferior_ptid),
111
 		      (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
112
 	    perror_with_name (_("Couldn't get extended state status"));
113
 
114
 	  amd64_collect_xsave (regcache, regnum, xstateregs, 0);
115
 
116
-	  if (ptrace (PT_SETXSTATE, ptid_get_pid (inferior_ptid),
117
+	  if (ptrace (PT_SETXSTATE, ptrace_pid (inferior_ptid),
118
 		      (PTRACE_TYPE_ARG3) xstateregs, x86_xsave_len) == -1)
119
 	    perror_with_name (_("Couldn't write extended state status"));
120
 	  return;
121
 	}
122
 #endif
123
 
124
-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
125
+      if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid),
126
 		  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
127
 	perror_with_name (_("Couldn't get floating point status"));
128
 
129
       amd64_collect_fxsave (regcache, regnum, &fpregs);
130
 
131
-      if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
132
+      if (ptrace (PT_SETFPREGS, ptrace_pid (inferior_ptid),
133
 		  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
134
 	perror_with_name (_("Couldn't write floating point status"));
135
     }
136
@@ -184,7 +197,7 @@ amd64bsd_dr_get (ptid_t ptid, int regnum)
137
 {
138
   struct dbreg dbregs;
139
 
140
-  if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid),
141
+  if (ptrace (PT_GETDBREGS, ptrace_pid (inferior_ptid),
142
 	      (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
143
     perror_with_name (_("Couldn't read debug registers"));
144
 
145
@@ -196,7 +209,7 @@ amd64bsd_dr_set (int regnum, unsigned long value)
146
 {
147
   struct dbreg dbregs;
148
 
149
-  if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid),
150
+  if (ptrace (PT_GETDBREGS, ptrace_pid (inferior_ptid),
151
               (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
152
     perror_with_name (_("Couldn't get debug registers"));
153
 
154
@@ -207,7 +220,7 @@ amd64bsd_dr_set (int regnum, unsigned long value)
155
 
156
   DBREG_DRX ((&dbregs), regnum) = value;
157
 
158
-  if (ptrace (PT_SETDBREGS, ptid_get_pid (inferior_ptid),
159
+  if (ptrace (PT_SETDBREGS, ptrace_pid (inferior_ptid),
160
               (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
161
     perror_with_name (_("Couldn't write debug registers"));
162
 }
163
diff --git a/gdb/amd64fbsd-nat.c b/gdb/amd64fbsd-nat.c
164
index eea2472..9ce6a54 100644
165
--- gdb/amd64fbsd-nat.c
166
+++ gdb/amd64fbsd-nat.c
167
@@ -18,6 +18,7 @@
168
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
169
 
170
 #include "defs.h"
171
+#include "gregset.h"
172
 #include "inferior.h"
173
 #include "regcache.h"
174
 #include "target.h"
175
@@ -95,6 +96,46 @@ static int amd64fbsd32_r_reg_offset[I386_NUM_GREGS] =
176
 };
177
 
178
 
179
+/* Transfering the registers between GDB, inferiors and core files.  */
180
+
181
+/* Fill GDB's register array with the general-purpose register values
182
+   in *GREGSETP.  */
183
+
184
+void
185
+supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
186
+{
187
+  amd64_supply_native_gregset (regcache, gregsetp, -1);
188
+}
189
+
190
+/* Fill register REGNUM (if it is a general-purpose register) in
191
+   *GREGSETPS with the value in GDB's register array.  If REGNUM is -1,
192
+   do this for all registers.  */
193
+
194
+void
195
+fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
196
+{
197
+  amd64_collect_native_gregset (regcache, gregsetp, regnum);
198
+}
199
+
200
+/* Fill GDB's register array with the floating-point register values
201
+   in *FPREGSETP.  */
202
+
203
+void
204
+supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
205
+{
206
+  amd64_supply_fxsave (regcache, -1, fpregsetp);
207
+}
208
+
209
+/* Fill register REGNUM (if it is a floating-point register) in
210
+   *FPREGSETP with the value in GDB's register array.  If REGNUM is -1,
211
+   do this for all registers.  */
212
+
213
+void
214
+fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
215
+{
216
+  amd64_collect_fxsave (regcache, regnum, fpregsetp);
217
+}
218
+
219
 /* Support for debugging kernel virtual memory images.  */
220
 
221
 #include <machine/pcb.h>
222
diff --git a/gdb/amd64fbsd-tdep.c b/gdb/amd64fbsd-tdep.c
223
index 582ae50..8e07369 100644
224
--- gdb/amd64fbsd-tdep.c
225
+++ gdb/amd64fbsd-tdep.c
226
@@ -31,7 +31,6 @@
227
 #include <string.h>
228
 
229
 #include "amd64-tdep.h"
230
-#include "bsd-uthread.h"
231
 #include "solib-svr4.h"
232
 
233
 /* Supported register note sections.  */
234
@@ -178,46 +177,6 @@ amd64fbsd_core_read_description (struct gdbarch *gdbarch,
235
 }
236
 
237
 static void
238
-amd64fbsd_supply_uthread (struct regcache *regcache,
239
-			  int regnum, CORE_ADDR addr)
240
-{
241
-  gdb_byte buf[8];
242
-  int i;
243
-
244
-  gdb_assert (regnum >= -1);
245
-
246
-  for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++)
247
-    {
248
-      if (amd64fbsd_jmp_buf_reg_offset[i] != -1
249
-	  && (regnum == -1 || regnum == i))
250
-	{
251
-	  read_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
252
-	  regcache_raw_supply (regcache, i, buf);
253
-	}
254
-    }
255
-}
256
-
257
-static void
258
-amd64fbsd_collect_uthread (const struct regcache *regcache,
259
-			   int regnum, CORE_ADDR addr)
260
-{
261
-  gdb_byte buf[8];
262
-  int i;
263
-
264
-  gdb_assert (regnum >= -1);
265
-
266
-  for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++)
267
-    {
268
-      if (amd64fbsd_jmp_buf_reg_offset[i] != -1
269
-	  && (regnum == -1 || regnum == i))
270
-	{
271
-	  regcache_raw_collect (regcache, i, buf);
272
-	  write_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
273
-	}
274
-    }
275
-}
276
-
277
-static void
278
 amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
279
 {
280
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
281
@@ -245,10 +204,6 @@ amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
282
   set_gdbarch_core_read_description (gdbarch,
283
 				     amd64fbsd_core_read_description);
284
 
285
-  /* FreeBSD provides a user-level threads implementation.  */
286
-  bsd_uthread_set_supply_uthread (gdbarch, amd64fbsd_supply_uthread);
287
-  bsd_uthread_set_collect_uthread (gdbarch, amd64fbsd_collect_uthread);
288
-
289
   /* FreeBSD uses SVR4-style shared libraries.  */
290
   set_solib_svr4_fetch_link_map_offsets
291
     (gdbarch, svr4_lp64_fetch_link_map_offsets);
292
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
293
index 01311b2..0929a25 100644
294
--- gdb/configure.tgt
295
+++ gdb/configure.tgt
296
@@ -189,7 +189,7 @@ i[34567]86-*-dicos*)
297
 i[34567]86-*-freebsd* | i[34567]86-*-kfreebsd*-gnu)
298
 	# Target: FreeBSD/i386
299
 	gdb_target_obs="i386-tdep.o i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \
300
-			bsd-uthread.o solib-svr4.o"
301
+			fbsd-threads.o solib-svr4.o"
302
 	;;
303
 i[34567]86-*-netbsd* | i[34567]86-*-knetbsd*-gnu)
304
 	# Target: NetBSD/i386
305
@@ -415,7 +415,7 @@ nios2*-*-*)
306
 powerpc*-*-freebsd*)
307
 	# Target: FreeBSD/powerpc
308
 	gdb_target_obs="rs6000-tdep.o ppc-sysv-tdep.o ppc64-tdep.o \
309
-		        ppcfbsd-tdep.o solib-svr4.o \
310
+		        ppcfbsd-tdep.o solib-svr4.o fbsd-threads.o \
311
 			ravenscar-thread.o ppc-ravenscar-thread.o"
312
 	;;
313
 
314
@@ -667,7 +667,7 @@ x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
315
 	# Target: FreeBSD/amd64
316
 	gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o i386-tdep.o \
317
 			i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \
318
-			bsd-uthread.o solib-svr4.o"
319
+			fbsd-threads.o solib-svr4.o"
320
 	;;
321
 x86_64-*-mingw* | x86_64-*-cygwin*)
322
         # Target: MingW/amd64
323
diff --git a/gdb/i386bsd-nat.c b/gdb/i386bsd-nat.c
324
index c26e830..246acdd 100644
325
--- gdb/i386bsd-nat.c
326
+++ gdb/i386bsd-nat.c
327
@@ -89,9 +89,22 @@ size_t x86_xsave_len;
328
 #endif
329
 
330
 
331
+static pid_t
332
+ptrace_pid (ptid_t ptid)
333
+{
334
+  pid_t pid;
335
+
336
+#ifdef __FreeBSD__
337
+  pid = ptid_get_lwp (ptid);
338
+  if (pid == 0)
339
+#endif
340
+    pid = ptid_get_pid (ptid);
341
+  return pid;
342
+}
343
+  
344
 /* Supply the general-purpose registers in GREGS, to REGCACHE.  */
345
 
346
-static void
347
+void
348
 i386bsd_supply_gregset (struct regcache *regcache, const void *gregs)
349
 {
350
   const char *regs = gregs;
351
@@ -110,7 +123,7 @@ i386bsd_supply_gregset (struct regcache *regcache, const void *gregs)
352
    GREGS.  If REGNUM is -1, collect and store all appropriate
353
    registers.  */
354
 
355
-static void
356
+void
357
 i386bsd_collect_gregset (const struct regcache *regcache,
358
 			 void *gregs, int regnum)
359
 {
360
@@ -140,7 +153,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
361
     {
362
       struct reg regs;
363
 
364
-      if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
365
+      if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid),
366
 		  (PTRACE_TYPE_ARG3) &regs, 0) == -1)
367
 	perror_with_name (_("Couldn't get registers"));
368
 
369
@@ -162,7 +175,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
370
 	  char *xstateregs;
371
 
372
 	  xstateregs = alloca(x86_xsave_len);
373
-	  if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
374
+	  if (ptrace (PT_GETXSTATE, ptrace_pid (inferior_ptid),
375
 		      (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
376
 	    perror_with_name (_("Couldn't get extended state status"));
377
 
378
@@ -174,7 +187,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
379
       
380
 #ifdef HAVE_PT_GETXMMREGS
381
       if (have_ptrace_xmmregs != 0
382
-	  && ptrace(PT_GETXMMREGS, ptid_get_pid (inferior_ptid),
383
+	  && ptrace(PT_GETXMMREGS, ptrace_pid (inferior_ptid),
384
 		    (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
385
 	{
386
 	  have_ptrace_xmmregs = 1;
387
@@ -184,7 +197,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
388
 	{
389
 	  have_ptrace_xmmregs = 0;
390
 #endif
391
-          if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
392
+          if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid),
393
 		      (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
394
 	    perror_with_name (_("Couldn't get floating point status"));
395
 
396
@@ -206,13 +219,13 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
397
     {
398
       struct reg regs;
399
 
400
-      if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
401
+      if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid),
402
                   (PTRACE_TYPE_ARG3) &regs, 0) == -1)
403
         perror_with_name (_("Couldn't get registers"));
404
 
405
       i386bsd_collect_gregset (regcache, &regs, regnum);
406
 
407
-      if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
408
+      if (ptrace (PT_SETREGS, ptrace_pid (inferior_ptid),
409
 	          (PTRACE_TYPE_ARG3) &regs, 0) == -1)
410
         perror_with_name (_("Couldn't write registers"));
411
 
412
@@ -233,13 +246,13 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
413
 	  char *xstateregs;
414
 
415
 	  xstateregs = alloca(x86_xsave_len);
416
-	  if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
417
+	  if (ptrace (PT_GETXSTATE, ptrace_pid (inferior_ptid),
418
 		      (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
419
 	    perror_with_name (_("Couldn't get extended state status"));
420
 
421
 	  i387_collect_xsave (regcache, -1, xstateregs, 0);
422
 
423
-	  if (ptrace (PT_SETXSTATE, ptid_get_pid (inferior_ptid),
424
+	  if (ptrace (PT_SETXSTATE, ptrace_pid (inferior_ptid),
425
 		      (PTRACE_TYPE_ARG3) xstateregs, x86_xsave_len) == -1)
426
 	    perror_with_name (_("Couldn't write extended state status"));
427
 	}
428
@@ -247,14 +260,14 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
429
 
430
 #ifdef HAVE_PT_GETXMMREGS
431
       if (have_ptrace_xmmregs != 0
432
-	  && ptrace(PT_GETXMMREGS, ptid_get_pid (inferior_ptid),
433
+	  && ptrace(PT_GETXMMREGS, ptrace_pid (inferior_ptid),
434
 		    (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
435
 	{
436
 	  have_ptrace_xmmregs = 1;
437
 
438
 	  i387_collect_fxsave (regcache, regnum, xmmregs);
439
 
440
-	  if (ptrace (PT_SETXMMREGS, ptid_get_pid (inferior_ptid),
441
+	  if (ptrace (PT_SETXMMREGS, ptrace_pid (inferior_ptid),
442
 		      (PTRACE_TYPE_ARG3) xmmregs, 0) == -1)
443
             perror_with_name (_("Couldn't write XMM registers"));
444
 	}
445
@@ -262,13 +275,13 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
446
 	{
447
 	  have_ptrace_xmmregs = 0;
448
 #endif
449
-          if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
450
+          if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid),
451
 		      (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
452
 	    perror_with_name (_("Couldn't get floating point status"));
453
 
454
           i387_collect_fsave (regcache, regnum, &fpregs);
455
 
456
-          if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
457
+          if (ptrace (PT_SETFPREGS, ptrace_pid (inferior_ptid),
458
 		      (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
459
 	    perror_with_name (_("Couldn't write floating point status"));
460
 #ifdef HAVE_PT_GETXMMREGS
461
@@ -307,7 +320,7 @@ i386bsd_dr_get (ptid_t ptid, int regnum)
462
 {
463
   struct dbreg dbregs;
464
 
465
-  if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid),
466
+  if (ptrace (PT_GETDBREGS, ptrace_pid (inferior_ptid),
467
 	      (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
468
     perror_with_name (_("Couldn't read debug registers"));
469
 
470
@@ -319,7 +332,7 @@ i386bsd_dr_set (int regnum, unsigned int value)
471
 {
472
   struct dbreg dbregs;
473
 
474
-  if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid),
475
+  if (ptrace (PT_GETDBREGS, ptrace_pid (inferior_ptid),
476
               (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
477
     perror_with_name (_("Couldn't get debug registers"));
478
 
479
@@ -330,7 +343,7 @@ i386bsd_dr_set (int regnum, unsigned int value)
480
 
481
   DBREG_DRX ((&dbregs), regnum) = value;
482
 
483
-  if (ptrace (PT_SETDBREGS, ptid_get_pid (inferior_ptid),
484
+  if (ptrace (PT_SETDBREGS, ptrace_pid (inferior_ptid),
485
               (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
486
     perror_with_name (_("Couldn't write debug registers"));
487
 }
488
diff --git a/gdb/i386bsd-nat.h b/gdb/i386bsd-nat.h
489
index 044f530..2fca773 100644
490
--- gdb/i386bsd-nat.h
491
+++ gdb/i386bsd-nat.h
492
@@ -38,6 +38,14 @@ extern CORE_ADDR i386bsd_dr_get_addr (int regnum);
493
 
494
 extern unsigned long i386bsd_dr_get_status (void);
495
 
496
+/* low level i386 register functions used in i386fbsd-nat.c. */
497
+
498
+extern void i386bsd_supply_gregset (struct regcache *regcache,
499
+				    const void *gregs);
500
+
501
+extern void i386bsd_collect_gregset (const struct regcache *regcache,
502
+				     void *gregs, int regnum);
503
+
504
 extern unsigned long i386bsd_dr_get_control (void);
505
 
506
 #endif /* i386bsd-nat.h */
507
diff --git a/gdb/i386fbsd-nat.c b/gdb/i386fbsd-nat.c
508
index b9620e1..71abcdf 100644
509
--- gdb/i386fbsd-nat.c
510
+++ gdb/i386fbsd-nat.c
511
@@ -21,6 +21,7 @@
512
 #include "inferior.h"
513
 #include "regcache.h"
514
 #include "target.h"
515
+#include "gregset.h"
516
 
517
 #include <sys/types.h>
518
 #include <sys/ptrace.h>
519
@@ -82,6 +83,49 @@ i386fbsd_resume (struct target_ops *ops,
520
 }
521
 
522
 
523
+/* Transfering the registers between GDB, inferiors and core files.  */
524
+
525
+/* Fill GDB's register array with the general-purpose register values
526
+   in *GREGSETP.  */
527
+
528
+void
529
+supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
530
+{
531
+  i386bsd_supply_gregset (regcache, gregsetp);
532
+}
533
+
534
+/* Fill register REGNUM (if it is a general-purpose register) in
535
+   *GREGSETPS with the value in GDB's register array.  If REGNUM is -1,
536
+   do this for all registers.  */
537
+
538
+void
539
+fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
540
+{
541
+  i386bsd_collect_gregset (regcache, gregsetp, regnum);
542
+}
543
+
544
+#include "i387-tdep.h"
545
+
546
+/* Fill GDB's register array with the floating-point register values
547
+   in *FPREGSETP.  */
548
+
549
+void
550
+supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
551
+{
552
+  i387_supply_fsave (regcache, -1, fpregsetp);
553
+}
554
+
555
+/* Fill register REGNUM (if it is a floating-point register) in
556
+   *FPREGSETP with the value in GDB's register array.  If REGNUM is -1,
557
+   do this for all registers.  */
558
+
559
+void
560
+fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
561
+{
562
+  i387_collect_fsave (regcache, regnum, fpregsetp);
563
+}
564
+
565
+
566
 /* Support for debugging kernel virtual memory images.  */
567
 
568
 #include <machine/pcb.h>
569
diff --git a/gdb/i386fbsd-tdep.c b/gdb/i386fbsd-tdep.c
570
index 8f7109f..fcb85d8 100644
571
--- gdb/i386fbsd-tdep.c
572
+++ gdb/i386fbsd-tdep.c
573
@@ -30,7 +30,6 @@
574
 
575
 #include "i386-tdep.h"
576
 #include "i387-tdep.h"
577
-#include "bsd-uthread.h"
578
 #include "solib-svr4.h"
579
 
580
 /* FreeBSD 3.0-RELEASE or later.  */
581
@@ -153,46 +152,6 @@ i386fbsd_core_read_description (struct gdbarch *gdbarch,
582
 }
583
 
584
 static void
585
-i386fbsd_supply_uthread (struct regcache *regcache,
586
-			 int regnum, CORE_ADDR addr)
587
-{
588
-  gdb_byte buf[4];
589
-  int i;
590
-
591
-  gdb_assert (regnum >= -1);
592
-
593
-  for (i = 0; i < ARRAY_SIZE (i386fbsd_jmp_buf_reg_offset); i++)
594
-    {
595
-      if (i386fbsd_jmp_buf_reg_offset[i] != -1
596
-	  && (regnum == -1 || regnum == i))
597
-	{
598
-	  read_memory (addr + i386fbsd_jmp_buf_reg_offset[i], buf, 4);
599
-	  regcache_raw_supply (regcache, i, buf);
600
-	}
601
-    }
602
-}
603
-
604
-static void
605
-i386fbsd_collect_uthread (const struct regcache *regcache,
606
-			  int regnum, CORE_ADDR addr)
607
-{
608
-  gdb_byte buf[4];
609
-  int i;
610
-
611
-  gdb_assert (regnum >= -1);
612
-
613
-  for (i = 0; i < ARRAY_SIZE (i386fbsd_jmp_buf_reg_offset); i++)
614
-    {
615
-      if (i386fbsd_jmp_buf_reg_offset[i] != -1
616
-	  && (regnum == -1 || regnum == i))
617
-	{
618
-	  regcache_raw_collect (regcache, i, buf);
619
-	  write_memory (addr + i386fbsd_jmp_buf_reg_offset[i], buf, 4);
620
-	}
621
-    }
622
-}
623
-
624
-static void
625
 i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
626
 {
627
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
628
@@ -217,10 +176,6 @@ i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
629
   /* FreeBSD has a more complete `struct sigcontext'.  */
630
   tdep->sc_reg_offset = i386fbsd_sc_reg_offset;
631
   tdep->sc_num_regs = ARRAY_SIZE (i386fbsd_sc_reg_offset);
632
-
633
-  /* FreeBSD provides a user-level threads implementation.  */
634
-  bsd_uthread_set_supply_uthread (gdbarch, i386fbsd_supply_uthread);
635
-  bsd_uthread_set_collect_uthread (gdbarch, i386fbsd_collect_uthread);
636
 }
637
 
638
 static void
639
diff --git a/gdb/ppcfbsd-nat.c b/gdb/ppcfbsd-nat.c
640
index 079bd12..74922f2 100644
641
--- gdb/ppcfbsd-nat.c
642
+++ gdb/ppcfbsd-nat.c
643
@@ -39,6 +39,19 @@
644
 #include "inf-ptrace.h"
645
 #include "bsd-kvm.h"
646
 
647
+static pid_t
648
+ptrace_pid (ptid_t ptid)
649
+{
650
+  pid_t pid;
651
+
652
+#ifdef __FreeBSD__
653
+  pid = ptid_get_lwp (ptid);
654
+  if (pid == 0)
655
+#endif
656
+    pid = ptid_get_pid (ptid);
657
+  return pid;
658
+}
659
+  
660
 /* Fill GDB's register array with the general-purpose register values
661
    in *GREGSETP.  */
662
 
663
@@ -123,7 +136,7 @@ ppcfbsd_fetch_inferior_registers (struct target_ops *ops,
664
 {
665
   gdb_gregset_t regs;
666
 
667
-  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
668
+  if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid),
669
 	      (PTRACE_TYPE_ARG3) &regs, 0) == -1)
670
     perror_with_name (_("Couldn't get registers"));
671
 
672
@@ -134,7 +147,7 @@ ppcfbsd_fetch_inferior_registers (struct target_ops *ops,
673
       const struct regset *fpregset = ppc_fbsd_fpregset ();
674
       gdb_fpregset_t fpregs;
675
 
676
-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
677
+      if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid),
678
 		  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
679
 	perror_with_name (_("Couldn't get FP registers"));
680
 
681
@@ -151,13 +164,13 @@ ppcfbsd_store_inferior_registers (struct target_ops *ops,
682
 {
683
   gdb_gregset_t regs;
684
 
685
-  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
686
+  if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid),
687
 	      (PTRACE_TYPE_ARG3) &regs, 0) == -1)
688
     perror_with_name (_("Couldn't get registers"));
689
 
690
   fill_gregset (regcache, &regs, regno);
691
 
692
-  if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
693
+  if (ptrace (PT_SETREGS, ptrace_pid (inferior_ptid),
694
 	      (PTRACE_TYPE_ARG3) &regs, 0) == -1)
695
     perror_with_name (_("Couldn't write registers"));
696
 
697
@@ -165,13 +178,13 @@ ppcfbsd_store_inferior_registers (struct target_ops *ops,
698
     {
699
       gdb_fpregset_t fpregs;
700
 
701
-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
702
+      if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid),
703
 		  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
704
 	perror_with_name (_("Couldn't get FP registers"));
705
 
706
       fill_fpregset (regcache, &fpregs, regno);
707
 
708
-      if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
709
+      if (ptrace (PT_SETFPREGS, ptrace_pid (inferior_ptid),
710
 		  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
711
 	perror_with_name (_("Couldn't set FP registers"));
712
     }
(-)files/fbsd-threads.c (-97 / +6 lines)
Lines 803-849 Link Here
803
}
803
}
804
804
805
static void
805
static void
806
fbsd_lwp_fetch_registers (struct target_ops *ops,
807
			  struct regcache *regcache, int regnum)
808
{
809
  gregset_t gregs;
810
  fpregset_t fpregs;
811
  lwpid_t lwp;
812
#ifdef PT_GETXMMREGS
813
  char xmmregs[512];
814
#endif
815
816
  if (!target_has_execution)
817
    {
818
      struct target_ops *beneath = find_target_beneath (ops);
819
820
      beneath->to_fetch_registers (ops, regcache, regnum);
821
      return;
822
    }
823
824
  lwp = GET_LWP (inferior_ptid);
825
826
  if (ptrace (PT_GETREGS, lwp, (caddr_t) &gregs, 0) == -1)
827
    error ("Cannot get lwp %d registers: %s\n", lwp, safe_strerror (errno));
828
  supply_gregset (regcache, &gregs);
829
830
#ifdef PT_GETXMMREGS
831
  if (ptrace (PT_GETXMMREGS, lwp, xmmregs, 0) == 0)
832
    {
833
      i387_supply_fxsave (regcache, -1, xmmregs);
834
    }
835
  else
836
    {
837
#endif
838
      if (ptrace (PT_GETFPREGS, lwp, (caddr_t) &fpregs, 0) == -1)
839
	error ("Cannot get lwp %d registers: %s\n ", lwp, safe_strerror (errno));
840
      supply_fpregset (regcache, &fpregs);
841
#ifdef PT_GETXMMREGS
842
    }
843
#endif
844
}
845
846
static void
847
fbsd_thread_fetch_registers (struct target_ops *ops,
806
fbsd_thread_fetch_registers (struct target_ops *ops,
848
			     struct regcache *regcache, int regnum)
807
			     struct regcache *regcache, int regnum)
849
{
808
{
Lines 857-863 Link Here
857
816
858
  if (!IS_THREAD (inferior_ptid))
817
  if (!IS_THREAD (inferior_ptid))
859
    {
818
    {
860
      fbsd_lwp_fetch_registers (ops, regcache, regnum);
819
      struct target_ops *beneath = find_target_beneath (ops);
820
821
      beneath->to_fetch_registers (ops, regcache, regnum);
861
      return;
822
      return;
862
    }
823
    }
863
824
Lines 895-954 Link Here
895
}
856
}
896
857
897
static void
858
static void
898
fbsd_lwp_store_registers (struct target_ops *ops,
899
			  struct regcache *regcache, int regnum)
900
{
901
  gregset_t gregs;
902
  fpregset_t fpregs;
903
  lwpid_t lwp;
904
#ifdef PT_GETXMMREGS
905
  char xmmregs[512];
906
#endif
907
908
  /* FIXME, is it possible ? */
909
  if (!IS_LWP (inferior_ptid))
910
    {
911
      struct target_ops *beneath = find_target_beneath (ops);
912
913
      beneath->to_store_registers (ops, regcache, regnum);
914
      return ;
915
    }
916
917
  lwp = GET_LWP (inferior_ptid);
918
  if (regnum != -1)
919
    if (ptrace (PT_GETREGS, lwp, (caddr_t) &gregs, 0) == -1)
920
      error ("Cannot get lwp %d registers: %s\n", lwp, safe_strerror (errno));
921
922
  fill_gregset (regcache, &gregs, regnum);
923
  if (ptrace (PT_SETREGS, lwp, (caddr_t) &gregs, 0) == -1)
924
      error ("Cannot set lwp %d registers: %s\n", lwp, safe_strerror (errno));
925
926
#ifdef PT_GETXMMREGS
927
  if (regnum != -1)
928
    if (ptrace (PT_GETXMMREGS, lwp, xmmregs, 0) == -1)
929
      goto noxmm;
930
931
  i387_collect_fxsave (regcache, regnum, xmmregs);
932
  if (ptrace (PT_SETXMMREGS, lwp, xmmregs, 0) == -1)
933
    goto noxmm;
934
935
  return;
936
937
noxmm:
938
#endif
939
940
  if (regnum != -1)
941
    if (ptrace (PT_GETFPREGS, lwp, (caddr_t) &fpregs, 0) == -1)
942
      error ("Cannot get lwp %d float registers: %s\n", lwp,
943
             safe_strerror (errno));
944
945
  fill_fpregset (regcache, &fpregs, regnum);
946
  if (ptrace (PT_SETFPREGS, lwp, (caddr_t) &fpregs, 0) == -1)
947
     error ("Cannot set lwp %d float registers: %s\n", lwp,
948
            safe_strerror (errno));
949
}
950
951
static void
952
fbsd_thread_store_registers (struct target_ops *ops,
859
fbsd_thread_store_registers (struct target_ops *ops,
953
			     struct regcache *regcache, int regnum)
860
			     struct regcache *regcache, int regnum)
954
{
861
{
Lines 962-968 Link Here
962
869
963
  if (!IS_THREAD (inferior_ptid))
870
  if (!IS_THREAD (inferior_ptid))
964
    {
871
    {
965
      fbsd_lwp_store_registers (ops, regcache, regnum);
872
      struct target_ops *beneath = find_target_beneath (ops);
873
874
      beneath->to_store_registers (ops, regcache, regnum);
966
      return;
875
      return;
967
    }
876
    }
968
877
(-)files/patch-gdb-amd64fbsd-nat.c (-49 / +1 lines)
Lines 1-10 Link Here
1
--- gdb/amd64fbsd-nat.c.orig	2014-06-11 18:34:41.000000000 +0200
1
--- gdb/amd64fbsd-nat.c.orig	2014-06-11 18:34:41.000000000 +0200
2
+++ gdb/amd64fbsd-nat.c	2014-09-24 18:27:50.618458853 +0200
2
+++ gdb/amd64fbsd-nat.c	2014-09-24 18:27:50.618458853 +0200
3
@@ -21,13 +21,17 @@
3
@@ -21,13 +21,16 @@
4
 #include "inferior.h"
4
 #include "inferior.h"
5
 #include "regcache.h"
5
 #include "regcache.h"
6
 #include "target.h"
6
 #include "target.h"
7
+#include "gregset.h"
8
 
7
 
9
 #include "gdb_assert.h"
8
 #include "gdb_assert.h"
10
 #include <signal.h>
9
 #include <signal.h>
Lines 18-70 Link Here
18
 #include <machine/reg.h>
17
 #include <machine/reg.h>
19
 
18
 
20
 #include "fbsd-nat.h"
19
 #include "fbsd-nat.h"
21
@@ -93,6 +97,46 @@
22
 };
23
 
24
 
25
+/* Transfering the registers between GDB, inferiors and core files.  */
26
+
27
+/* Fill GDB's register array with the general-purpose register values
28
+   in *GREGSETP.  */
29
+
30
+void
31
+supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
32
+{
33
+  amd64_supply_native_gregset (regcache, gregsetp, -1);
34
+}
35
+
36
+/* Fill register REGNUM (if it is a general-purpose register) in
37
+   *GREGSETPS with the value in GDB's register array.  If REGNUM is -1,
38
+   do this for all registers.  */
39
+
40
+void
41
+fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
42
+{
43
+  amd64_collect_native_gregset (regcache, gregsetp, regnum);
44
+}
45
+
46
+/* Fill GDB's register array with the floating-point register values
47
+   in *FPREGSETP.  */
48
+
49
+void
50
+supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
51
+{
52
+  amd64_supply_fxsave (regcache, -1, fpregsetp);
53
+}
54
+
55
+/* Fill register REGNUM (if it is a floating-point register) in
56
+   *FPREGSETP with the value in GDB's register array.  If REGNUM is -1,
57
+   do this for all registers.  */
58
+
59
+void
60
+fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
61
+{
62
+  amd64_collect_fxsave (regcache, regnum, fpregsetp);
63
+}
64
+
65
 /* Support for debugging kernel virtual memory images.  */
66
 
67
 #include <machine/pcb.h>
68
@@ -247,6 +291,10 @@
20
@@ -247,6 +291,10 @@
69
 
21
 
70
   SC_RBP_OFFSET = offset;
22
   SC_RBP_OFFSET = offset;
(-)files/patch-gdb-amd64fbsd-tdep.c (-66 lines)
Lines 1-13 Link Here
1
--- gdb/amd64fbsd-tdep.c.orig	2010-01-01 02:31:29.000000000 -0500
1
--- gdb/amd64fbsd-tdep.c.orig	2010-01-01 02:31:29.000000000 -0500
2
+++ gdb/amd64fbsd-tdep.c	2011-01-05 17:27:29.264869000 -0500
2
+++ gdb/amd64fbsd-tdep.c	2011-01-05 17:27:29.264869000 -0500
3
@@ -29,7 +29,6 @@
4
 #include "gdb_string.h"
5
 
6
 #include "amd64-tdep.h"
7
-#include "bsd-uthread.h"
8
 #include "solib-svr4.h"
9
 
10
 /* Support for signal handlers.  */
11
@@ -40,12 +39,16 @@
3
@@ -40,12 +39,16 @@
12
 static CORE_ADDR
4
 static CORE_ADDR
13
 amd64fbsd_sigcontext_addr (struct frame_info *this_frame)
5
 amd64fbsd_sigcontext_addr (struct frame_info *this_frame)
Lines 26-86 Link Here
26
   return sp + 16;
18
   return sp + 16;
27
 }
19
 }
28
 
20
 
29
@@ -142,46 +145,6 @@
30
 };
31
 
32
 static void
33
-amd64fbsd_supply_uthread (struct regcache *regcache,
34
-			  int regnum, CORE_ADDR addr)
35
-{
36
-  gdb_byte buf[8];
37
-  int i;
38
-
39
-  gdb_assert (regnum >= -1);
40
-
41
-  for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++)
42
-    {
43
-      if (amd64fbsd_jmp_buf_reg_offset[i] != -1
44
-	  && (regnum == -1 || regnum == i))
45
-	{
46
-	  read_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
47
-	  regcache_raw_supply (regcache, i, buf);
48
-	}
49
-    }
50
-}
51
-
52
-static void
53
-amd64fbsd_collect_uthread (const struct regcache *regcache,
54
-			   int regnum, CORE_ADDR addr)
55
-{
56
-  gdb_byte buf[8];
57
-  int i;
58
-
59
-  gdb_assert (regnum >= -1);
60
-
61
-  for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++)
62
-    {
63
-      if (amd64fbsd_jmp_buf_reg_offset[i] != -1
64
-	  && (regnum == -1 || regnum == i))
65
-	{
66
-	  regcache_raw_collect (regcache, i, buf);
67
-	  write_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
68
-	}
69
-    }
70
-}
71
-
72
-static void
73
 amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
74
 {
75
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
76
@@ -201,10 +164,6 @@
77
   tdep->sc_reg_offset = amd64fbsd_sc_reg_offset;
78
   tdep->sc_num_regs = ARRAY_SIZE (amd64fbsd_sc_reg_offset);
79
 
80
-  /* FreeBSD provides a user-level threads implementation.  */
81
-  bsd_uthread_set_supply_uthread (gdbarch, amd64fbsd_supply_uthread);
82
-  bsd_uthread_set_collect_uthread (gdbarch, amd64fbsd_collect_uthread);
83
-
84
   /* FreeBSD uses SVR4-style shared libraries.  */
85
   set_solib_svr4_fetch_link_map_offsets
86
     (gdbarch, svr4_lp64_fetch_link_map_offsets);
(-)files/patch-gdb-i386bsd-nat.c (-20 lines)
Lines 1-20 Link Here
1
--- gdb/i386bsd-nat.c.orig	2010-10-21 11:18:03.171107000 -0400
2
+++ gdb/i386bsd-nat.c	2010-10-21 11:18:18.849642000 -0400
3
@@ -88,7 +88,7 @@
4
 
5
 /* Supply the general-purpose registers in GREGS, to REGCACHE.  */
6
 
7
-static void
8
+void
9
 i386bsd_supply_gregset (struct regcache *regcache, const void *gregs)
10
 {
11
   const char *regs = gregs;
12
@@ -107,7 +107,7 @@
13
    GREGS.  If REGNUM is -1, collect and store all appropriate
14
    registers.  */
15
 
16
-static void
17
+void
18
 i386bsd_collect_gregset (const struct regcache *regcache,
19
 			 void *gregs, int regnum)
20
 {
(-)files/patch-gdb-i386bsd-nat.h (-15 lines)
Lines 1-15 Link Here
1
--- gdb/i386bsd-nat.h.orig	2010-10-21 11:18:08.097659000 -0400
2
+++ gdb/i386bsd-nat.h	2010-10-21 11:20:49.341989000 -0400
3
@@ -35,4 +35,12 @@
4
 
5
 extern unsigned long i386bsd_dr_get_status (void);
6
 
7
+/* low level i386 register functions used in i386fbsd-nat.c. */
8
+
9
+extern void i386bsd_supply_gregset (struct regcache *regcache,
10
+				    const void *gregs);
11
+
12
+extern void i386bsd_collect_gregset (const struct regcache *regcache,
13
+				     void *gregs, int regnum);
14
+
15
 #endif /* i386bsd-nat.h */
(-)files/patch-gdb-i386fbsd-nat.c (-53 / +40 lines)
Lines 1-67 Link Here
1
--- gdb/i386fbsd-nat.c.orig	2012-05-24 18:39:09.000000000 +0200
1
--- gdb/i386fbsd-nat.c.orig	2012-05-24 18:39:09.000000000 +0200
2
+++ gdb/i386fbsd-nat.c	2012-08-29 17:19:57.000000000 +0200
2
+++ gdb/i386fbsd-nat.c	2012-08-29 17:19:57.000000000 +0200
3
@@ -21,8 +21,10 @@
3
@@ -21,10 +21,12 @@
4
 #include "inferior.h"
4
 #include "inferior.h"
5
 #include "regcache.h"
5
 #include "regcache.h"
6
 #include "target.h"
6
 #include "target.h"
7
+#include "gregset.h"
8
 
7
 
9
 #include <sys/types.h>
8
 #include <sys/types.h>
10
+#include <sys/procfs.h>
9
+#include <sys/procfs.h>
11
 #include <sys/ptrace.h>
10
 #include <sys/ptrace.h>
12
 #include <sys/sysctl.h>
11
 #include <sys/sysctl.h>
12
+#include <sys/user.h>
13
 
13
 
14
@@ -80,6 +82,49 @@
14
 #include "fbsd-nat.h"
15
 }
15
 #include "i386-tdep.h"
16
 
16
@@ -140,7 +141,6 @@
17
 
18
+/* Transfering the registers between GDB, inferiors and core files.  */
19
+
20
+/* Fill GDB's register array with the general-purpose register values
21
+   in *GREGSETP.  */
22
+
23
+void
24
+supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
25
+{
26
+  i386bsd_supply_gregset (regcache, gregsetp);
27
+}
28
+
29
+/* Fill register REGNUM (if it is a general-purpose register) in
30
+   *GREGSETPS with the value in GDB's register array.  If REGNUM is -1,
31
+   do this for all registers.  */
32
+
33
+void
34
+fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
35
+{
36
+  i386bsd_collect_gregset (regcache, gregsetp, regnum);
37
+}
38
+
39
+#include "i387-tdep.h"
40
+
41
+/* Fill GDB's register array with the floating-point register values
42
+   in *FPREGSETP.  */
43
+
44
+void
45
+supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
46
+{
47
+  i387_supply_fsave (regcache, -1, fpregsetp);
48
+}
49
+
50
+/* Fill register REGNUM (if it is a floating-point register) in
51
+   *FPREGSETP with the value in GDB's register array.  If REGNUM is -1,
52
+   do this for all registers.  */
53
+
54
+void
55
+fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
56
+{
57
+  i387_collect_fsave (regcache, regnum, fpregsetp);
58
+}
59
+
60
+
61
 /* Support for debugging kernel virtual memory images.  */
62
 
63
 #include <sys/types.h>
64
@@ -141,7 +186,6 @@
65
 #endif /* HAVE_PT_GETDBREGS */
17
 #endif /* HAVE_PT_GETDBREGS */
66
 
18
 
67
 
19
 
Lines 69-71 Link Here
69
   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
21
   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
70
   t->to_find_memory_regions = fbsd_find_memory_regions;
22
   t->to_find_memory_regions = fbsd_find_memory_regions;
71
   t->to_make_corefile_notes = fbsd_make_corefile_notes;
23
   t->to_make_corefile_notes = fbsd_make_corefile_notes;
24
@@ -149,13 +149,33 @@ _initialize_i386fbsd_nat (void)
25
   /* Support debugging kernel virtual memory images.  */
26
   bsd_kvm_add_target (i386fbsd_supply_pcb);
27
 
28
+#ifdef KERN_PROC_SIGTRAMP
29
+  /* FreeBSD provides a kern.proc.sigtramp sysctl that we can use to
30
+     locate the sigtramp.  That way we can still recognize a sigtramp
31
+     if its location is changed in a new kernel. */
32
+  {
33
+    int mib[4];
34
+    struct kinfo_sigtramp kst;
35
+    size_t len;
36
+
37
+    mib[0] = CTL_KERN;
38
+    mib[1] = KERN_PROC;
39
+    mib[2] = KERN_PROC_SIGTRAMP;
40
+    mib[3] = getpid();
41
+    len = sizeof (kst);
42
+    if (sysctl (mib, sizeof(mib)/sizeof(mib[0]), &kst, &len, NULL, 0) == 0)
43
+      {
44
+	i386fbsd_sigtramp_start_addr = (uintptr_t)kst.ksigtramp_start;
45
+	i386fbsd_sigtramp_end_addr = (uintptr_t)kst.ksigtramp_end;
46
+      }
47
+  }
48
+#elif defined(KERN_PS_STRINGS)
49
   /* FreeBSD provides a kern.ps_strings sysctl that we can use to
50
      locate the sigtramp.  That way we can still recognize a sigtramp
51
      if its location is changed in a new kernel.  Of course this is
52
      still based on the assumption that the sigtramp is placed
53
      directly under the location where the program arguments and
54
      environment can be found.  */
55
-#ifdef KERN_PS_STRINGS
56
   {
57
     int mib[2];
58
     u_long ps_strings;
(-)files/patch-gdb-i386fbsd-tdep.c (-68 lines)
Lines 1-68 Link Here
1
--- gdb/i386fbsd-tdep.c.orig	2010-09-30 13:39:50.654492000 -0400
2
+++ gdb/i386fbsd-tdep.c	2010-09-30 13:40:43.858675000 -0400
3
@@ -28,7 +28,6 @@
4
 
5
 #include "i386-tdep.h"
6
 #include "i387-tdep.h"
7
-#include "bsd-uthread.h"
8
 #include "solib-svr4.h"
9
 
10
 /* FreeBSD 3.0-RELEASE or later.  */
11
@@ -84,46 +83,6 @@
12
 };
13
 
14
 static void
15
-i386fbsd_supply_uthread (struct regcache *regcache,
16
-			 int regnum, CORE_ADDR addr)
17
-{
18
-  gdb_byte buf[4];
19
-  int i;
20
-
21
-  gdb_assert (regnum >= -1);
22
-
23
-  for (i = 0; i < ARRAY_SIZE (i386fbsd_jmp_buf_reg_offset); i++)
24
-    {
25
-      if (i386fbsd_jmp_buf_reg_offset[i] != -1
26
-	  && (regnum == -1 || regnum == i))
27
-	{
28
-	  read_memory (addr + i386fbsd_jmp_buf_reg_offset[i], buf, 4);
29
-	  regcache_raw_supply (regcache, i, buf);
30
-	}
31
-    }
32
-}
33
-
34
-static void
35
-i386fbsd_collect_uthread (const struct regcache *regcache,
36
-			  int regnum, CORE_ADDR addr)
37
-{
38
-  gdb_byte buf[4];
39
-  int i;
40
-
41
-  gdb_assert (regnum >= -1);
42
-
43
-  for (i = 0; i < ARRAY_SIZE (i386fbsd_jmp_buf_reg_offset); i++)
44
-    {
45
-      if (i386fbsd_jmp_buf_reg_offset[i] != -1
46
-	  && (regnum == -1 || regnum == i))
47
-	{
48
-	  regcache_raw_collect (regcache, i, buf);
49
-	  write_memory (addr + i386fbsd_jmp_buf_reg_offset[i], buf, 4);
50
-	}
51
-    }
52
-}
53
-
54
-static void
55
 i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
56
 {
57
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
58
@@ -148,10 +107,6 @@
59
   /* FreeBSD has a more complete `struct sigcontext'.  */
60
   tdep->sc_reg_offset = i386fbsd_sc_reg_offset;
61
   tdep->sc_num_regs = ARRAY_SIZE (i386fbsd_sc_reg_offset);
62
-
63
-  /* FreeBSD provides a user-level threads implementation.  */
64
-  bsd_uthread_set_supply_uthread (gdbarch, i386fbsd_supply_uthread);
65
-  bsd_uthread_set_collect_uthread (gdbarch, i386fbsd_collect_uthread);
66
 }
67
 
68
 static void
(-)files/patch-xsave (+606 lines)
Line 0 Link Here
1
diff --git a/bfd/elf.c b/bfd/elf.c
2
index 3f377d1..9481435 100644
3
--- bfd/elf.c
4
+++ bfd/elf.c
5
@@ -8609,6 +8609,9 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note)
6
       if (note->namesz == 6
7
 	  && strcmp (note->namedata, "LINUX") == 0)
8
 	return elfcore_grok_xstatereg (abfd, note);
9
+      else if (note->namesz == 8
10
+	  && strcmp (note->namedata, "FreeBSD") == 0)
11
+	return elfcore_grok_xstatereg (abfd, note);
12
       else
13
 	return TRUE;
14
 
15
diff --git a/gdb/amd64-tdep.h b/gdb/amd64-tdep.h
16
index f1b039e..7a4c1dc 100644
17
--- gdb/amd64-tdep.h
18
+++ gdb/amd64-tdep.h
19
@@ -84,6 +84,11 @@ enum amd64_regnum
20
 
21
 #define AMD64_NUM_REGS		(AMD64_ZMM31H_REGNUM + 1)
22
 
23
+extern struct target_desc *tdesc_amd64;
24
+extern struct target_desc *tdesc_amd64_avx;
25
+extern struct target_desc *tdesc_amd64_mpx;
26
+extern struct target_desc *tdesc_amd64_avx512;
27
+
28
 extern struct displaced_step_closure *amd64_displaced_step_copy_insn
29
   (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to,
30
    struct regcache *regs);
31
diff --git a/gdb/amd64bsd-nat.c b/gdb/amd64bsd-nat.c
32
index 4b0a231..9e6a0df 100644
33
--- gdb/amd64bsd-nat.c
34
+++ gdb/amd64bsd-nat.c
35
@@ -37,6 +37,10 @@
36
 #include "inf-ptrace.h"
37
 
38
 
39
+#ifdef PT_GETXSTATE_INFO
40
+size_t x86_xsave_len;
41
+#endif
42
+
43
 /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
44
    for all registers (including the floating-point registers).  */
45
 
46
@@ -62,6 +66,20 @@ amd64bsd_fetch_inferior_registers (struct target_ops *ops,
47
   if (regnum == -1 || !amd64_native_gregset_supplies_p (gdbarch, regnum))
48
     {
49
       struct fpreg fpregs;
50
+#ifdef PT_GETXSTATE_INFO
51
+      char *xstateregs;
52
+
53
+      if (x86_xsave_len != 0)
54
+	{
55
+	  xstateregs = alloca(x86_xsave_len);
56
+	  if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
57
+		      (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
58
+	    perror_with_name (_("Couldn't get extended state status"));
59
+
60
+	  amd64_supply_xsave (regcache, -1, xstateregs);
61
+	  return;
62
+	}
63
+#endif
64
 
65
       if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
66
 		  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
67
@@ -111,6 +129,24 @@ amd64bsd_store_inferior_registers (struct target_ops *ops,
68
   if (regnum == -1 || !amd64_native_gregset_supplies_p (gdbarch, regnum))
69
     {
70
       struct fpreg fpregs;
71
+#ifdef PT_GETXSTATE_INFO
72
+      char *xstateregs;
73
+
74
+      if (x86_xsave_len != 0)
75
+	{
76
+	  xstateregs = alloca(x86_xsave_len);
77
+	  if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
78
+		      (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
79
+	    perror_with_name (_("Couldn't get extended state status"));
80
+
81
+	  amd64_collect_xsave (regcache, regnum, xstateregs, 0);
82
+
83
+	  if (ptrace (PT_SETXSTATE, ptid_get_pid (inferior_ptid),
84
+		      (PTRACE_TYPE_ARG3) xstateregs, x86_xsave_len) == -1)
85
+	    perror_with_name (_("Couldn't write extended state status"));
86
+	  return;
87
+	}
88
+#endif
89
 
90
       if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
91
 		  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
92
diff --git a/gdb/amd64bsd-nat.h b/gdb/amd64bsd-nat.h
93
index 7ff95f3..9d85a1f 100644
94
--- gdb/amd64bsd-nat.h
95
+++ gdb/amd64bsd-nat.h
96
@@ -20,6 +20,9 @@
97
 #ifndef AMD64BSD_NAT_H
98
 #define AMD64BSD_NAT_H
99
 
100
+/* Low level amd64 XSAVE info. */
101
+extern size_t x86_xsave_len;
102
+
103
 /* Low level amd64 debug register functions.  */
104
 
105
 extern void amd64bsd_dr_set_control (unsigned long control);
106
diff --git a/gdb/amd64fbsd-nat.c b/gdb/amd64fbsd-nat.c
107
index 08de9a1..eea2472 100644
108
--- gdb/amd64fbsd-nat.c
109
+++ gdb/amd64fbsd-nat.c
110
@@ -36,6 +36,7 @@
111
 #include "amd64-nat.h"
112
 #include "amd64bsd-nat.h"
113
 #include "i386-nat.h"
114
+#include "i386-xstate.h"
115
 
116
 
117
 /* Offset in `struct reg' where MEMBER is stored.  */
118
@@ -153,6 +154,68 @@ amd64fbsd_mourn_inferior (struct target_ops *ops)
119
   super_mourn_inferior (ops);
120
 }
121
 
122
+static const struct target_desc *
123
+amd64fbsd_read_description (struct target_ops *ops)
124
+{
125
+#ifdef PT_GETXSTATE_INFO
126
+  static int xsave_probed;
127
+  static uint64_t xcr0;
128
+#endif
129
+  struct reg regs;
130
+  int is64;
131
+
132
+  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
133
+	      (PTRACE_TYPE_ARG3) &regs, 0) == -1)
134
+    perror_with_name (_("Couldn't get registers"));
135
+  is64 = (regs.r_cs == GSEL(GUCODE_SEL, SEL_UPL));
136
+#ifdef PT_GETXSTATE_INFO
137
+  if (!xsave_probed)
138
+    {
139
+      struct ptrace_xstate_info info;
140
+
141
+      if (ptrace (PT_GETXSTATE_INFO, ptid_get_pid (inferior_ptid),
142
+		  (PTRACE_TYPE_ARG3) &info, sizeof(info)) == 0)
143
+	{
144
+	  x86_xsave_len = info.xsave_len;
145
+	  xcr0 = info.xsave_mask;
146
+	}
147
+      xsave_probed = 1;
148
+    }
149
+
150
+  if (x86_xsave_len != 0)
151
+    {
152
+      switch (xcr0 & I386_XSTATE_ALL_MASK)
153
+	{
154
+	case I386_XSTATE_MPX_AVX512_MASK:
155
+	case I386_XSTATE_AVX512_MASK:
156
+	  if (is64)
157
+	    return tdesc_amd64_avx512;
158
+	  else
159
+	    return tdesc_i386_avx512;
160
+	case I386_XSTATE_MPX_MASK:
161
+	  if (is64)
162
+	    return tdesc_amd64_mpx;
163
+	  else
164
+	    return tdesc_i386_mpx;
165
+	case I386_XSTATE_AVX_MASK:
166
+	  if (is64)
167
+	    return tdesc_amd64_avx;
168
+	  else
169
+	    return tdesc_i386_avx;
170
+	default:
171
+	  if (is64)
172
+	    return tdesc_amd64;
173
+	  else
174
+	    return tdesc_i386;
175
+	}
176
+    }
177
+#endif
178
+  if (is64)
179
+    return tdesc_amd64;
180
+  else
181
+    return tdesc_i386;
182
+}
183
+
184
 /* Provide a prototype to silence -Wmissing-prototypes.  */
185
 void _initialize_amd64fbsd_nat (void);
186
 
187
@@ -183,6 +246,7 @@ _initialize_amd64fbsd_nat (void)
188
 
189
   super_mourn_inferior = t->to_mourn_inferior;
190
   t->to_mourn_inferior = amd64fbsd_mourn_inferior;
191
+  t->to_read_description = amd64fbsd_read_description;
192
 
193
   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
194
   t->to_find_memory_regions = fbsd_find_memory_regions;
195
diff --git a/gdb/amd64fbsd-tdep.c b/gdb/amd64fbsd-tdep.c
196
index 884fbc4..582ae50 100644
197
--- gdb/amd64fbsd-tdep.c
198
+++ gdb/amd64fbsd-tdep.c
199
@@ -23,6 +23,9 @@
200
 #include "gdbcore.h"
201
 #include "regcache.h"
202
 #include "osabi.h"
203
+#include "regset.h"
204
+#include "i386fbsd-tdep.h"
205
+#include "i386-xstate.h"
206
 
207
 #include "gdb_assert.h"
208
 #include <string.h>
209
@@ -31,6 +34,15 @@
210
 #include "bsd-uthread.h"
211
 #include "solib-svr4.h"
212
 
213
+/* Supported register note sections.  */
214
+static struct core_regset_section amd64fbsd_regset_sections[] =
215
+{
216
+  { ".reg", 22 * 8, "general-purpose" },
217
+  { ".reg2", 512, "floating-point" },
218
+  { ".reg-xstate", I386_XSTATE_MAX_SIZE, "XSAVE extended state" },
219
+  { NULL, 0 }
220
+};
221
+
222
 /* Support for signal handlers.  */
223
 
224
 /* Assuming THIS_FRAME is for a BSD sigtramp routine, return the
225
@@ -144,6 +156,27 @@ static int amd64fbsd_jmp_buf_reg_offset[] =
226
   0 * 8				/* %rip */
227
 };
228
 
229
+static const struct target_desc *
230
+amd64fbsd_core_read_description (struct gdbarch *gdbarch,
231
+				 struct target_ops *target,
232
+				 bfd *abfd)
233
+{
234
+  uint64_t xcr0 = i386fbsd_core_read_xcr0 (abfd);
235
+
236
+  switch (xcr0 & I386_XSTATE_ALL_MASK)
237
+    {
238
+    case I386_XSTATE_MPX_AVX512_MASK:
239
+    case I386_XSTATE_AVX512_MASK:
240
+      return tdesc_amd64_avx512;
241
+    case I386_XSTATE_MPX_MASK:
242
+      return tdesc_amd64_mpx;
243
+    case I386_XSTATE_AVX_MASK:
244
+      return tdesc_amd64_avx;
245
+    default:
246
+      return tdesc_amd64;
247
+    }
248
+}
249
+
250
 static void
251
 amd64fbsd_supply_uthread (struct regcache *regcache,
252
 			  int regnum, CORE_ADDR addr)
253
@@ -204,6 +237,14 @@ amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
254
   tdep->sc_reg_offset = amd64fbsd_sc_reg_offset;
255
   tdep->sc_num_regs = ARRAY_SIZE (amd64fbsd_sc_reg_offset);
256
 
257
+  tdep->xsave_xcr0_offset = I386_FBSD_XSAVE_XCR0_OFFSET;
258
+
259
+  /* Install supported register note sections.  */
260
+  set_gdbarch_core_regset_sections (gdbarch, amd64fbsd_regset_sections);
261
+
262
+  set_gdbarch_core_read_description (gdbarch,
263
+				     amd64fbsd_core_read_description);
264
+
265
   /* FreeBSD provides a user-level threads implementation.  */
266
   bsd_uthread_set_supply_uthread (gdbarch, amd64fbsd_supply_uthread);
267
   bsd_uthread_set_collect_uthread (gdbarch, amd64fbsd_collect_uthread);
268
diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h
269
index e0950a3..0498445 100644
270
--- gdb/i386-tdep.h
271
+++ gdb/i386-tdep.h
272
@@ -325,6 +325,11 @@ enum record_i386_regnum
273
 /* Size of the largest register.  */
274
 #define I386_MAX_REGISTER_SIZE	64
275
 
276
+extern struct target_desc *tdesc_i386;
277
+extern struct target_desc *tdesc_i386_avx;
278
+extern struct target_desc *tdesc_i386_mpx;
279
+extern struct target_desc *tdesc_i386_avx512;
280
+
281
 /* Types for i386-specific registers.  */
282
 extern struct type *i387_ext_type (struct gdbarch *gdbarch);
283
 
284
diff --git a/gdb/i386bsd-nat.c b/gdb/i386bsd-nat.c
285
index acae6cb..c26e830 100644
286
--- gdb/i386bsd-nat.c
287
+++ gdb/i386bsd-nat.c
288
@@ -83,6 +83,10 @@ static int i386bsd_r_reg_offset[] =
289
    so that we try PT_GETXMMREGS the first time around.  */
290
 static int have_ptrace_xmmregs = -1;
291
 #endif
292
+
293
+#ifdef PT_GETXSTATE_INFO
294
+size_t x86_xsave_len;
295
+#endif
296
 
297
 
298
 /* Supply the general-purpose registers in GREGS, to REGCACHE.  */
299
@@ -150,7 +154,25 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
300
       struct fpreg fpregs;
301
 #ifdef HAVE_PT_GETXMMREGS
302
       char xmmregs[512];
303
+#endif
304
+
305
+#ifdef PT_GETXSTATE_INFO
306
+      if (x86_xsave_len != 0)
307
+	{
308
+	  char *xstateregs;
309
+
310
+	  xstateregs = alloca(x86_xsave_len);
311
+	  if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
312
+		      (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
313
+	    perror_with_name (_("Couldn't get extended state status"));
314
 
315
+	  i387_supply_xsave (regcache, -1, xstateregs);
316
+	  return;
317
+	}
318
+      else
319
+#endif
320
+      
321
+#ifdef HAVE_PT_GETXMMREGS
322
       if (have_ptrace_xmmregs != 0
323
 	  && ptrace(PT_GETXMMREGS, ptid_get_pid (inferior_ptid),
324
 		    (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
325
@@ -160,18 +182,15 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops,
326
 	}
327
       else
328
 	{
329
+	  have_ptrace_xmmregs = 0;
330
+#endif
331
           if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
332
 		      (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
333
 	    perror_with_name (_("Couldn't get floating point status"));
334
 
335
 	  i387_supply_fsave (regcache, -1, &fpregs);
336
+#ifdef HAVE_PT_GETXMMREGS
337
 	}
338
-#else
339
-      if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
340
-		  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
341
-	perror_with_name (_("Couldn't get floating point status"));
342
-
343
-      i387_supply_fsave (regcache, -1, &fpregs);
344
 #endif
345
     }
346
 }
347
@@ -206,7 +225,27 @@ i386bsd_store_inferior_registers (struct target_ops *ops,
348
       struct fpreg fpregs;
349
 #ifdef HAVE_PT_GETXMMREGS
350
       char xmmregs[512];
351
+#endif
352
+
353
+#ifdef PT_GETXSTATE_INFO
354
+      if (x86_xsave_len != 0)
355
+	{
356
+	  char *xstateregs;
357
 
358
+	  xstateregs = alloca(x86_xsave_len);
359
+	  if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid),
360
+		      (PTRACE_TYPE_ARG3) xstateregs, 0) == -1)
361
+	    perror_with_name (_("Couldn't get extended state status"));
362
+
363
+	  i387_collect_xsave (regcache, -1, xstateregs, 0);
364
+
365
+	  if (ptrace (PT_SETXSTATE, ptid_get_pid (inferior_ptid),
366
+		      (PTRACE_TYPE_ARG3) xstateregs, x86_xsave_len) == -1)
367
+	    perror_with_name (_("Couldn't write extended state status"));
368
+	}
369
+#endif
370
+
371
+#ifdef HAVE_PT_GETXMMREGS
372
       if (have_ptrace_xmmregs != 0
373
 	  && ptrace(PT_GETXMMREGS, ptid_get_pid (inferior_ptid),
374
 		    (PTRACE_TYPE_ARG3) xmmregs, 0) == 0)
375
diff --git a/gdb/i386bsd-nat.h b/gdb/i386bsd-nat.h
376
index a92fa56..044f530 100644
377
--- gdb/i386bsd-nat.h
378
+++ gdb/i386bsd-nat.h
379
@@ -25,6 +25,9 @@
380
 
381
 extern struct target_ops *i386bsd_target (void);
382
 
383
+/* Low level i386 XSAVE info. */
384
+extern size_t x86_xsave_len;
385
+
386
 /* low level i386 debug register functions used in i386fbsd-nat.c.  */
387
 
388
 extern void i386bsd_dr_set_control (unsigned long control);
389
diff --git a/gdb/i386fbsd-nat.c b/gdb/i386fbsd-nat.c
390
index fb80991..b9620e1 100644
391
--- gdb/i386fbsd-nat.c
392
+++ gdb/i386fbsd-nat.c
393
@@ -31,6 +31,7 @@
394
 #include "i386-tdep.h"
395
 #include "i386-nat.h"
396
 #include "i386bsd-nat.h"
397
+#include "i386-xstate.h"
398
 
399
 /* Resume execution of the inferior process.  If STEP is nonzero,
400
    single-step it.  If SIGNAL is nonzero, give it that signal.  */
401
@@ -116,6 +117,46 @@ i386fbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
402
 }
403
 
404
 
405
+#ifdef PT_GETXSTATE_INFO
406
+static const struct target_desc *
407
+i386fbsd_read_description (struct target_ops *ops)
408
+{
409
+  static int xsave_probed;
410
+  static uint64_t xcr0;
411
+
412
+  if (!xsave_probed)
413
+    {
414
+      struct ptrace_xstate_info info;
415
+
416
+      if (ptrace (PT_GETXSTATE_INFO, ptid_get_pid (inferior_ptid),
417
+		  (PTRACE_TYPE_ARG3) &info, sizeof(info)) == 0)
418
+	{
419
+	  x86_xsave_len = info.xsave_len;
420
+	  xcr0 = info.xsave_mask;
421
+	}
422
+      xsave_probed = 1;
423
+    }
424
+
425
+  if (x86_xsave_len != 0)
426
+    {
427
+      switch (xcr0 & I386_XSTATE_ALL_MASK)
428
+	{
429
+	case I386_XSTATE_MPX_AVX512_MASK:
430
+	case I386_XSTATE_AVX512_MASK:
431
+	  return tdesc_i386_avx512;
432
+	case I386_XSTATE_MPX_MASK:
433
+	  return tdesc_i386_mpx;
434
+	case I386_XSTATE_AVX_MASK:
435
+	  return tdesc_i386_avx;
436
+	default:
437
+	  return tdesc_i386;
438
+	}
439
+    }
440
+  else
441
+    return tdesc_i386;
442
+}
443
+#endif
444
+
445
 /* Prevent warning from -Wmissing-prototypes.  */
446
 void _initialize_i386fbsd_nat (void);
447
 
448
@@ -140,6 +181,9 @@ _initialize_i386fbsd_nat (void)
449
 
450
 #endif /* HAVE_PT_GETDBREGS */
451
 
452
+#ifdef PT_GETXSTATE_INFO
453
+  t->to_read_description = i386fbsd_read_description;
454
+#endif
455
 
456
   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
457
   t->to_find_memory_regions = fbsd_find_memory_regions;
458
diff --git a/gdb/i386fbsd-tdep.c b/gdb/i386fbsd-tdep.c
459
index ed6df6b..8f7109f 100644
460
--- gdb/i386fbsd-tdep.c
461
+++ gdb/i386fbsd-tdep.c
462
@@ -22,6 +22,9 @@
463
 #include "gdbcore.h"
464
 #include "osabi.h"
465
 #include "regcache.h"
466
+#include "regset.h"
467
+#include "i386fbsd-tdep.h"
468
+#include "i386-xstate.h"
469
 
470
 #include "gdb_assert.h"
471
 
472
@@ -32,6 +35,15 @@
473
 
474
 /* FreeBSD 3.0-RELEASE or later.  */
475
 
476
+/* Supported register note sections.  */
477
+static struct core_regset_section i386fbsd_regset_sections[] =
478
+{
479
+  { ".reg", 19 * 4, "general-purpose" },
480
+  { ".reg2", 512, "floating-point" },
481
+  { ".reg-xstate", I386_XSTATE_MAX_SIZE, "XSAVE extended state" },
482
+  { NULL, 0 }
483
+};
484
+
485
 /* From <machine/reg.h>.  */
486
 static int i386fbsd_r_reg_offset[] =
487
 {
488
@@ -82,6 +94,64 @@ static int i386fbsd_jmp_buf_reg_offset[] =
489
   0 * 4				/* %eip */
490
 };
491
 
492
+/* Get XSAVE extended state xcr0 from core dump.  */
493
+
494
+uint64_t
495
+i386fbsd_core_read_xcr0 (bfd *abfd)
496
+{
497
+  asection *xstate = bfd_get_section_by_name (abfd, ".reg-xstate");
498
+  uint64_t xcr0;
499
+
500
+  if (xstate)
501
+    {
502
+      size_t size = bfd_section_size (abfd, xstate);
503
+
504
+      /* Check extended state size.  */
505
+      if (size < I386_XSTATE_AVX_SIZE)
506
+	xcr0 = I386_XSTATE_SSE_MASK;
507
+      else
508
+	{
509
+	  char contents[8];
510
+
511
+	  if (! bfd_get_section_contents (abfd, xstate, contents,
512
+					  I386_FBSD_XSAVE_XCR0_OFFSET,
513
+					  8))
514
+	    {
515
+	      warning (_("Couldn't read `xcr0' bytes from "
516
+			 "`.reg-xstate' section in core file."));
517
+	      return 0;
518
+	    }
519
+
520
+	  xcr0 = bfd_get_64 (abfd, contents);
521
+	}
522
+    }
523
+  else
524
+    xcr0 = 0;
525
+
526
+  return xcr0;
527
+}
528
+
529
+static const struct target_desc *
530
+i386fbsd_core_read_description (struct gdbarch *gdbarch,
531
+				struct target_ops *target,
532
+				bfd *abfd)
533
+{
534
+  uint64_t xcr0 = i386fbsd_core_read_xcr0 (abfd);
535
+
536
+  switch (xcr0 & I386_XSTATE_ALL_MASK)
537
+    {
538
+    case I386_XSTATE_MPX_AVX512_MASK:
539
+    case I386_XSTATE_AVX512_MASK:
540
+      return tdesc_i386_avx512;
541
+    case I386_XSTATE_MPX_MASK:
542
+      return tdesc_i386_mpx;
543
+    case I386_XSTATE_AVX_MASK:
544
+      return tdesc_i386_avx;
545
+    default:
546
+      return tdesc_i386;
547
+    }
548
+}
549
+
550
 static void
551
 i386fbsd_supply_uthread (struct regcache *regcache,
552
 			 int regnum, CORE_ADDR addr)
553
@@ -218,6 +288,14 @@ i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
554
   /* FreeBSD 4.0 introduced a new `struct sigcontext'.  */
555
   tdep->sc_reg_offset = i386fbsd4_sc_reg_offset;
556
   tdep->sc_num_regs = ARRAY_SIZE (i386fbsd4_sc_reg_offset);
557
+
558
+  tdep->xsave_xcr0_offset = I386_FBSD_XSAVE_XCR0_OFFSET;
559
+
560
+  /* Install supported register note sections.  */
561
+  set_gdbarch_core_regset_sections (gdbarch, i386fbsd_regset_sections);
562
+
563
+  set_gdbarch_core_read_description (gdbarch,
564
+				     i386fbsd_core_read_description);
565
 }
566
 
567
 
568
diff --git a/gdb/i386fbsd-tdep.h b/gdb/i386fbsd-tdep.h
569
new file mode 100644
570
index 0000000..8935255
571
--- /dev/null
572
+++ gdb/i386fbsd-tdep.h
573
@@ -0,0 +1,33 @@
574
+/* Target-dependent code for FreeBSD x86.
575
+
576
+   Copyright (C) 2014 Free Software Foundation, Inc.
577
+
578
+   This file is part of GDB.
579
+
580
+   This program is free software; you can redistribute it and/or modify
581
+   it under the terms of the GNU General Public License as published by
582
+   the Free Software Foundation; either version 3 of the License, or
583
+   (at your option) any later version.
584
+
585
+   This program is distributed in the hope that it will be useful,
586
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
587
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
588
+   GNU General Public License for more details.
589
+
590
+   You should have received a copy of the GNU General Public License
591
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
592
+
593
+#ifndef I386FBSD_TDEP_H
594
+#define I386FBSD_TDEP_H
595
+
596
+/* Get XSAVE extended state xcr0 from core dump.  */
597
+extern uint64_t i386fbsd_core_read_xcr0 (bfd *abfd);
598
+
599
+/*
600
+ * The format of the XSAVE extended area is determined by hardware.
601
+ * Cores store the XSAVE extended area in a NT_X86_XSTATE note that
602
+ * matches the layout on Linux.
603
+ */
604
+#define I386_FBSD_XSAVE_XCR0_OFFSET 464
605
+
606
+#endif /* i386fbsd-tdep.h */

Return to bug 197501