2004-05-04 Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
[deliverable/binutils-gdb.git] / gdb / i386fbsd-nat.c
CommitLineData
25630444 1/* Native-dependent code for FreeBSD/i386.
5d93ae8c
MK
2
3 Copyright 2001, 2002, 2003, 2004 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
9 the Free Software Foundation; either version 2 of the License, or
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
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22#include "defs.h"
23#include "inferior.h"
24#include "regcache.h"
25
26#include <sys/types.h>
27#include <sys/ptrace.h>
28#include <sys/sysctl.h>
29
f0925262
MK
30#include "i386-tdep.h"
31
25630444
MK
32/* Prevent warning from -Wmissing-prototypes. */
33void _initialize_i386fbsd_nat (void);
34
35/* Resume execution of the inferior process.
36 If STEP is nonzero, single-step it.
37 If SIGNAL is nonzero, give it that signal. */
38
39void
40child_resume (ptid_t ptid, int step, enum target_signal signal)
41{
42 pid_t pid = ptid_get_pid (ptid);
43 int request = PT_STEP;
44
45 if (pid == -1)
46 /* Resume all threads. This only gets used in the non-threaded
47 case, where "resume all threads" and "resume inferior_ptid" are
48 the same. */
49 pid = ptid_get_pid (inferior_ptid);
50
51 if (!step)
52 {
f0925262 53 ULONGEST eflags;
25630444
MK
54
55 /* Workaround for a bug in FreeBSD. Make sure that the trace
56 flag is off when doing a continue. There is a code path
57 through the kernel which leaves the flag set when it should
58 have been cleared. If a process has a signal pending (such
59 as SIGALRM) and we do a PT_STEP, the process never really has
60 a chance to run because the kernel needs to notify the
61 debugger that a signal is being sent. Therefore, the process
62 never goes through the kernel's trap() function which would
63 normally clear it. */
64
f0925262
MK
65 regcache_cooked_read_unsigned (current_regcache, I386_EFLAGS_REGNUM,
66 &eflags);
25630444 67 if (eflags & 0x0100)
f0925262
MK
68 regcache_cooked_write_unsigned (current_regcache, I386_EFLAGS_REGNUM,
69 eflags & ~0x0100);
25630444
MK
70
71 request = PT_CONTINUE;
72 }
73
74 /* An addres of (caddr_t) 1 tells ptrace to continue from where it
75 was. (If GDB wanted it to start some other way, we have already
76 written a new PC value to the child.) */
77 if (ptrace (request, pid, (caddr_t) 1,
78 target_signal_to_host (signal)) == -1)
79 perror_with_name ("ptrace");
80}
81\f
82void
83_initialize_i386fbsd_nat (void)
84{
85 /* FreeBSD provides a kern.ps_strings sysctl that we can use to
86 locate the sigtramp. That way we can still recognize a sigtramp
8201327c 87 if its location is changed in a new kernel. Of course this is
25630444
MK
88 still based on the assumption that the sigtramp is placed
89 directly under the location where the program arguments and
90 environment can be found. */
91#ifdef KERN_PS_STRINGS
92 {
93 int mib[2];
94 int ps_strings;
95 size_t len;
96
97 mib[0] = CTL_KERN;
98 mib[1] = KERN_PS_STRINGS;
99 len = sizeof (ps_strings);
100 if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) == 0)
101 {
5d93ae8c
MK
102 i386fbsd_sigtramp_start_addr = ps_strings - 128;
103 i386fbsd_sigtramp_end_addr = ps_strings;
25630444
MK
104 }
105 }
106#endif
107}
This page took 0.282878 seconds and 4 git commands to generate.