1 /* Native-dependent code for DragonFly/i386.
3 Copyright (C) 2001-2013 Free Software Foundation, Inc.
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include <sys/types.h>
27 #include <sys/procfs.h>
28 #include <sys/ptrace.h>
29 #include <sys/sysctl.h>
32 #include "i386-tdep.h"
34 #include "i386bsd-nat.h"
36 #ifdef DFLY_PCB_SUPPLY
37 /* Resume execution of the inferior process. If STEP is nonzero,
38 single-step it. If SIGNAL is nonzero, give it that signal. */
41 i386dfly_resume (struct target_ops *ops,
42 ptid_t ptid, int step, enum gdb_signal signal)
44 pid_t pid = ptid_get_pid (ptid);
45 int request = PT_STEP;
48 /* Resume all threads. This only gets used in the non-threaded
49 case, where "resume all threads" and "resume inferior_ptid" are
51 pid = ptid_get_pid (inferior_ptid);
55 struct regcache *regcache = get_current_regcache ();
58 /* Workaround for a bug in FreeBSD. Make sure that the trace
59 flag is off when doing a continue. There is a code path
60 through the kernel which leaves the flag set when it should
61 have been cleared. If a process has a signal pending (such
62 as SIGALRM) and we do a PT_STEP, the process never really has
63 a chance to run because the kernel needs to notify the
64 debugger that a signal is being sent. Therefore, the process
65 never goes through the kernel's trap() function which would
68 regcache_cooked_read_unsigned (regcache, I386_EFLAGS_REGNUM,
71 regcache_cooked_write_unsigned (regcache, I386_EFLAGS_REGNUM,
74 request = PT_CONTINUE;
77 /* An addres of (caddr_t) 1 tells ptrace to continue from where it
78 was. (If GDB wanted it to start some other way, we have already
79 written a new PC value to the child.) */
80 if (ptrace (request, pid, (caddr_t) 1,
81 gdb_signal_to_host (signal)) == -1)
82 perror_with_name (("ptrace"));
86 /* Transfering the registers between GDB, inferiors and core files. */
88 /* Fill GDB's register array with the general-purpose register values
92 supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
94 i386bsd_supply_gregset (regcache, gregsetp);
97 /* Fill register REGNUM (if it is a general-purpose register) in
98 *GREGSETPS with the value in GDB's register array. If REGNUM is -1,
99 do this for all registers. */
102 fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
104 i386bsd_collect_gregset (regcache, gregsetp, regnum);
107 #include "i387-tdep.h"
109 /* Fill GDB's register array with the floating-point register values
113 supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
115 i387_supply_fsave (regcache, -1, fpregsetp);
118 /* Fill register REGNUM (if it is a floating-point register) in
119 *FPREGSETP with the value in GDB's register array. If REGNUM is -1,
120 do this for all registers. */
123 fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
125 i387_collect_fsave (regcache, regnum, fpregsetp);
129 /* Support for debugging kernel virtual memory images. */
131 #include <sys/types.h>
132 #include <machine/pcb.h>
137 i386dfly_supply_pcb (struct regcache *regcache, struct pcb *pcb)
139 /* The following is true for FreeBSD 4.7:
141 The pcb contains %eip, %ebx, %esp, %ebp, %esi, %edi and %gs.
142 This accounts for all callee-saved registers specified by the
143 psABI and then some. Here %esp contains the stack pointer at the
144 point just after the call to cpu_switch(). From this information
145 we reconstruct the register state as it would look when we just
146 returned from cpu_switch(). */
148 /* The stack pointer shouldn't be zero. */
149 if (pcb->pcb_esp == 0)
153 regcache_raw_supply (regcache, I386_EDI_REGNUM, &pcb->pcb_edi);
154 regcache_raw_supply (regcache, I386_ESI_REGNUM, &pcb->pcb_esi);
155 regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
156 regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
157 regcache_raw_supply (regcache, I386_EBX_REGNUM, &pcb->pcb_ebx);
158 regcache_raw_supply (regcache, I386_EIP_REGNUM, &pcb->pcb_eip);
159 regcache_raw_supply (regcache, I386_GS_REGNUM, &pcb->pcb_gs);
163 #endif /* DFLY_PCB_SUPPLY */
166 /* Prevent warning from -Wmissing-prototypes. */
167 void _initialize_i386dfly_nat (void);
170 _initialize_i386dfly_nat (void)
172 struct target_ops *t;
174 /* Add some extra features to the common *BSD/i386 target. */
175 t = i386bsd_target ();
177 #ifdef HAVE_PT_GETDBREGS
179 i386_use_watchpoints (t);
181 i386_dr_low.set_control = i386bsd_dr_set_control;
182 i386_dr_low.set_addr = i386bsd_dr_set_addr;
183 i386_dr_low.get_addr = i386bsd_dr_get_addr;
184 i386_dr_low.get_status = i386bsd_dr_get_status;
185 i386_dr_low.get_control = i386bsd_dr_get_control;
186 i386_set_debug_register_length (4);
188 #endif /* HAVE_PT_GETDBREGS */
191 t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
192 t->to_find_memory_regions = fbsd_find_memory_regions;
193 t->to_make_corefile_notes = fbsd_make_corefile_notes;
196 #ifdef DFLY_PCB_SUPPLY
197 /* Support debugging kernel virtual memory images. */
198 bsd_kvm_add_target (i386dfly_supply_pcb);
201 /* DragonFly provides a kern.ps_strings sysctl that we can use to
202 locate the sigtramp. That way we can still recognize a sigtramp
203 if its location is changed in a new kernel. Of course this is
204 still based on the assumption that the sigtramp is placed
205 directly under the location where the program arguments and
206 environment can be found. */
207 #ifdef KERN_PS_STRINGS
214 mib[1] = KERN_PS_STRINGS;
215 len = sizeof (ps_strings);
216 if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) == 0)
218 i386dfly_sigtramp_start_addr = ps_strings - 128;
219 i386dfly_sigtramp_end_addr = ps_strings;