]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/i386-fbsd-nat.c
Normalize names of some source files
[thirdparty/binutils-gdb.git] / gdb / i386-fbsd-nat.c
CommitLineData
25630444 1/* Native-dependent code for FreeBSD/i386.
5d93ae8c 2
618f726f 3 Copyright (C) 2001-2016 Free Software Foundation, Inc.
25630444
MK
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
25630444
MK
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25630444
MK
19
20#include "defs.h"
21#include "inferior.h"
22#include "regcache.h"
9692934b 23#include "target.h"
25630444
MK
24
25#include <sys/types.h>
26#include <sys/ptrace.h>
27#include <sys/sysctl.h>
cf424aef 28#include <sys/user.h>
25630444 29
9692934b 30#include "fbsd-nat.h"
f0925262 31#include "i386-tdep.h"
df7e5265 32#include "x86-nat.h"
03b62bbb
SM
33#include "x86-bsd-nat.h"
34#include "i386-bsd-nat.h"
f0925262 35
9692934b
MK
36/* Resume execution of the inferior process. If STEP is nonzero,
37 single-step it. If SIGNAL is nonzero, give it that signal. */
25630444 38
9692934b 39static void
28439f5e 40i386fbsd_resume (struct target_ops *ops,
2ea28649 41 ptid_t ptid, int step, enum gdb_signal signal)
25630444
MK
42{
43 pid_t pid = ptid_get_pid (ptid);
44 int request = PT_STEP;
45
46 if (pid == -1)
47 /* Resume all threads. This only gets used in the non-threaded
48 case, where "resume all threads" and "resume inferior_ptid" are
49 the same. */
50 pid = ptid_get_pid (inferior_ptid);
51
52 if (!step)
53 {
594f7785 54 struct regcache *regcache = get_current_regcache ();
f0925262 55 ULONGEST eflags;
25630444
MK
56
57 /* Workaround for a bug in FreeBSD. Make sure that the trace
58 flag is off when doing a continue. There is a code path
59 through the kernel which leaves the flag set when it should
60 have been cleared. If a process has a signal pending (such
61 as SIGALRM) and we do a PT_STEP, the process never really has
62 a chance to run because the kernel needs to notify the
63 debugger that a signal is being sent. Therefore, the process
64 never goes through the kernel's trap() function which would
65 normally clear it. */
66
594f7785 67 regcache_cooked_read_unsigned (regcache, I386_EFLAGS_REGNUM,
f0925262 68 &eflags);
25630444 69 if (eflags & 0x0100)
594f7785 70 regcache_cooked_write_unsigned (regcache, I386_EFLAGS_REGNUM,
f0925262 71 eflags & ~0x0100);
25630444
MK
72
73 request = PT_CONTINUE;
74 }
75
76 /* An addres of (caddr_t) 1 tells ptrace to continue from where it
77 was. (If GDB wanted it to start some other way, we have already
78 written a new PC value to the child.) */
79 if (ptrace (request, pid, (caddr_t) 1,
2ea28649 80 gdb_signal_to_host (signal)) == -1)
e2e0b3e5 81 perror_with_name (("ptrace"));
25630444
MK
82}
83\f
2e0c3539
MK
84
85/* Support for debugging kernel virtual memory images. */
86
2e0c3539
MK
87#include <machine/pcb.h>
88
89#include "bsd-kvm.h"
90
91static int
92i386fbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
93{
94 /* The following is true for FreeBSD 4.7:
95
96 The pcb contains %eip, %ebx, %esp, %ebp, %esi, %edi and %gs.
97 This accounts for all callee-saved registers specified by the
98 psABI and then some. Here %esp contains the stack pointer at the
99 point just after the call to cpu_switch(). From this information
100 we reconstruct the register state as it would look when we just
101 returned from cpu_switch(). */
102
103 /* The stack pointer shouldn't be zero. */
104 if (pcb->pcb_esp == 0)
105 return 0;
106
107 pcb->pcb_esp += 4;
108 regcache_raw_supply (regcache, I386_EDI_REGNUM, &pcb->pcb_edi);
109 regcache_raw_supply (regcache, I386_ESI_REGNUM, &pcb->pcb_esi);
110 regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
111 regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
112 regcache_raw_supply (regcache, I386_EBX_REGNUM, &pcb->pcb_ebx);
113 regcache_raw_supply (regcache, I386_EIP_REGNUM, &pcb->pcb_eip);
114 regcache_raw_supply (regcache, I386_GS_REGNUM, &pcb->pcb_gs);
115
116 return 1;
117}
118\f
119
97de3545
JB
120#ifdef PT_GETXSTATE_INFO
121/* Implement the to_read_description method. */
122
123static const struct target_desc *
124i386fbsd_read_description (struct target_ops *ops)
125{
126 static int xsave_probed;
127 static uint64_t xcr0;
128
129 if (!xsave_probed)
130 {
131 struct ptrace_xstate_info info;
132
133 if (ptrace (PT_GETXSTATE_INFO, ptid_get_pid (inferior_ptid),
134 (PTRACE_TYPE_ARG3) &info, sizeof (info)) == 0)
135 {
a3405d12 136 x86bsd_xsave_len = info.xsave_len;
97de3545
JB
137 xcr0 = info.xsave_mask;
138 }
139 xsave_probed = 1;
140 }
141
a3405d12 142 if (x86bsd_xsave_len != 0)
97de3545
JB
143 {
144 return i386_target_description (xcr0);
145 }
146 else
147 return tdesc_i386;
148}
149#endif
150
2e0c3539
MK
151/* Prevent warning from -Wmissing-prototypes. */
152void _initialize_i386fbsd_nat (void);
153
25630444
MK
154void
155_initialize_i386fbsd_nat (void)
156{
9692934b
MK
157 struct target_ops *t;
158
159 /* Add some extra features to the common *BSD/i386 target. */
160 t = i386bsd_target ();
9bb9e8ad 161
97de3545
JB
162#ifdef PT_GETXSTATE_INFO
163 t->to_read_description = i386fbsd_read_description;
164#endif
9bb9e8ad 165
9692934b 166 t->to_resume = i386fbsd_resume;
8f60fe01 167 fbsd_nat_add_target (t);
9692934b 168
771e236c
MK
169 /* Support debugging kernel virtual memory images. */
170 bsd_kvm_add_target (i386fbsd_supply_pcb);
171
cf424aef
JB
172#ifdef KERN_PROC_SIGTRAMP
173 /* Normally signal frames are detected via i386fbsd_sigtramp_p.
174 However, FreeBSD 9.2 through 10.1 do not include the page holding
175 the signal code in core dumps. These releases do provide a
176 kern.proc.sigtramp.<pid> sysctl that returns the location of the
177 signal trampoline for a running process. We fetch the location
178 of the current (gdb) process and use this to identify signal
179 frames in core dumps from these releases. */
25630444 180 {
cf424aef
JB
181 int mib[4];
182 struct kinfo_sigtramp kst;
25630444
MK
183 size_t len;
184
185 mib[0] = CTL_KERN;
cf424aef
JB
186 mib[1] = KERN_PROC;
187 mib[2] = KERN_PROC_SIGTRAMP;
188 mib[3] = getpid ();
189 len = sizeof (kst);
190 if (sysctl (mib, 4, &kst, &len, NULL, 0) == 0)
25630444 191 {
cf424aef
JB
192 i386fbsd_sigtramp_start_addr = (uintptr_t) kst.ksigtramp_start;
193 i386fbsd_sigtramp_end_addr = (uintptr_t) kst.ksigtramp_end;
25630444
MK
194 }
195 }
196#endif
197}