1 /* Native-dependent code for FreeBSD/i386.
2 Copyright 2001, 2002 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include <sys/types.h>
26 #include <sys/ptrace.h>
27 #include <sys/sysctl.h>
29 #include "i386-tdep.h"
31 /* Prevent warning from -Wmissing-prototypes. */
32 void _initialize_i386fbsd_nat (void);
34 /* Resume execution of the inferior process.
35 If STEP is nonzero, single-step it.
36 If SIGNAL is nonzero, give it that signal. */
39 child_resume (ptid_t ptid, int step, enum target_signal signal)
41 pid_t pid = ptid_get_pid (ptid);
42 int request = PT_STEP;
45 /* Resume all threads. This only gets used in the non-threaded
46 case, where "resume all threads" and "resume inferior_ptid" are
48 pid = ptid_get_pid (inferior_ptid);
54 /* Workaround for a bug in FreeBSD. Make sure that the trace
55 flag is off when doing a continue. There is a code path
56 through the kernel which leaves the flag set when it should
57 have been cleared. If a process has a signal pending (such
58 as SIGALRM) and we do a PT_STEP, the process never really has
59 a chance to run because the kernel needs to notify the
60 debugger that a signal is being sent. Therefore, the process
61 never goes through the kernel's trap() function which would
64 regcache_cooked_read_unsigned (current_regcache, I386_EFLAGS_REGNUM,
67 regcache_cooked_write_unsigned (current_regcache, I386_EFLAGS_REGNUM,
70 request = PT_CONTINUE;
73 /* An addres of (caddr_t) 1 tells ptrace to continue from where it
74 was. (If GDB wanted it to start some other way, we have already
75 written a new PC value to the child.) */
76 if (ptrace (request, pid, (caddr_t) 1,
77 target_signal_to_host (signal)) == -1)
78 perror_with_name ("ptrace");
82 _initialize_i386fbsd_nat (void)
84 /* FreeBSD provides a kern.ps_strings sysctl that we can use to
85 locate the sigtramp. That way we can still recognize a sigtramp
86 if its location is changed in a new kernel. Of course this is
87 still based on the assumption that the sigtramp is placed
88 directly under the location where the program arguments and
89 environment can be found. */
90 #ifdef KERN_PS_STRINGS
96 extern CORE_ADDR i386fbsd_sigtramp_start;
97 extern CORE_ADDR i386fbsd_sigtramp_end;
100 mib[1] = KERN_PS_STRINGS;
101 len = sizeof (ps_strings);
102 if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) == 0)
104 i386fbsd_sigtramp_start = ps_strings - 128;
105 i386fbsd_sigtramp_end = ps_strings;