2003-11-22 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / i386fbsd-nat.c
CommitLineData
25630444 1/* Native-dependent code for FreeBSD/i386.
e2dbbd2d 2 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
25630444
MK
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
20
21#include "defs.h"
22#include "inferior.h"
23#include "regcache.h"
24
25#include <sys/types.h>
26#include <sys/ptrace.h>
27#include <sys/sysctl.h>
28
f0925262
MK
29#include "i386-tdep.h"
30
25630444
MK
31/* Prevent warning from -Wmissing-prototypes. */
32void _initialize_i386fbsd_nat (void);
33
34/* Resume execution of the inferior process.
35 If STEP is nonzero, single-step it.
36 If SIGNAL is nonzero, give it that signal. */
37
38void
39child_resume (ptid_t ptid, int step, enum target_signal signal)
40{
41 pid_t pid = ptid_get_pid (ptid);
42 int request = PT_STEP;
43
44 if (pid == -1)
45 /* Resume all threads. This only gets used in the non-threaded
46 case, where "resume all threads" and "resume inferior_ptid" are
47 the same. */
48 pid = ptid_get_pid (inferior_ptid);
49
50 if (!step)
51 {
f0925262 52 ULONGEST eflags;
25630444
MK
53
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
62 normally clear it. */
63
f0925262
MK
64 regcache_cooked_read_unsigned (current_regcache, I386_EFLAGS_REGNUM,
65 &eflags);
25630444 66 if (eflags & 0x0100)
f0925262
MK
67 regcache_cooked_write_unsigned (current_regcache, I386_EFLAGS_REGNUM,
68 eflags & ~0x0100);
25630444
MK
69
70 request = PT_CONTINUE;
71 }
72
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");
79}
80\f
81void
82_initialize_i386fbsd_nat (void)
83{
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
8201327c 86 if its location is changed in a new kernel. Of course this is
25630444
MK
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
91 {
92 int mib[2];
93 int ps_strings;
94 size_t len;
95
96 mib[0] = CTL_KERN;
97 mib[1] = KERN_PS_STRINGS;
98 len = sizeof (ps_strings);
99 if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) == 0)
100 {
8201327c
MK
101 i386fbsd_sigtramp_start = ps_strings - 128;
102 i386fbsd_sigtramp_end = ps_strings;
25630444
MK
103 }
104 }
105#endif
106}
This page took 0.227227 seconds and 4 git commands to generate.