Commit | Line | Data |
---|---|---|
25630444 | 1 | /* Native-dependent code for FreeBSD/i386. |
5d93ae8c | 2 | |
ecd75fc8 | 3 | Copyright (C) 2001-2014 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> | |
28 | ||
9692934b | 29 | #include "fbsd-nat.h" |
f0925262 | 30 | #include "i386-tdep.h" |
9bb9e8ad | 31 | #include "i386-nat.h" |
9692934b | 32 | #include "i386bsd-nat.h" |
f0925262 | 33 | |
9692934b MK |
34 | /* Resume execution of the inferior process. If STEP is nonzero, |
35 | single-step it. If SIGNAL is nonzero, give it that signal. */ | |
25630444 | 36 | |
9692934b | 37 | static void |
28439f5e | 38 | i386fbsd_resume (struct target_ops *ops, |
2ea28649 | 39 | ptid_t ptid, int step, enum gdb_signal signal) |
25630444 MK |
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 | { | |
594f7785 | 52 | struct regcache *regcache = get_current_regcache (); |
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 | ||
594f7785 | 65 | regcache_cooked_read_unsigned (regcache, I386_EFLAGS_REGNUM, |
f0925262 | 66 | &eflags); |
25630444 | 67 | if (eflags & 0x0100) |
594f7785 | 68 | regcache_cooked_write_unsigned (regcache, I386_EFLAGS_REGNUM, |
f0925262 | 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, | |
2ea28649 | 78 | gdb_signal_to_host (signal)) == -1) |
e2e0b3e5 | 79 | perror_with_name (("ptrace")); |
25630444 MK |
80 | } |
81 | \f | |
2e0c3539 MK |
82 | |
83 | /* Support for debugging kernel virtual memory images. */ | |
84 | ||
2e0c3539 MK |
85 | #include <machine/pcb.h> |
86 | ||
87 | #include "bsd-kvm.h" | |
88 | ||
89 | static int | |
90 | i386fbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb) | |
91 | { | |
92 | /* The following is true for FreeBSD 4.7: | |
93 | ||
94 | The pcb contains %eip, %ebx, %esp, %ebp, %esi, %edi and %gs. | |
95 | This accounts for all callee-saved registers specified by the | |
96 | psABI and then some. Here %esp contains the stack pointer at the | |
97 | point just after the call to cpu_switch(). From this information | |
98 | we reconstruct the register state as it would look when we just | |
99 | returned from cpu_switch(). */ | |
100 | ||
101 | /* The stack pointer shouldn't be zero. */ | |
102 | if (pcb->pcb_esp == 0) | |
103 | return 0; | |
104 | ||
105 | pcb->pcb_esp += 4; | |
106 | regcache_raw_supply (regcache, I386_EDI_REGNUM, &pcb->pcb_edi); | |
107 | regcache_raw_supply (regcache, I386_ESI_REGNUM, &pcb->pcb_esi); | |
108 | regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp); | |
109 | regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp); | |
110 | regcache_raw_supply (regcache, I386_EBX_REGNUM, &pcb->pcb_ebx); | |
111 | regcache_raw_supply (regcache, I386_EIP_REGNUM, &pcb->pcb_eip); | |
112 | regcache_raw_supply (regcache, I386_GS_REGNUM, &pcb->pcb_gs); | |
113 | ||
114 | return 1; | |
115 | } | |
116 | \f | |
117 | ||
118 | /* Prevent warning from -Wmissing-prototypes. */ | |
119 | void _initialize_i386fbsd_nat (void); | |
120 | ||
25630444 MK |
121 | void |
122 | _initialize_i386fbsd_nat (void) | |
123 | { | |
9692934b MK |
124 | struct target_ops *t; |
125 | ||
126 | /* Add some extra features to the common *BSD/i386 target. */ | |
127 | t = i386bsd_target (); | |
9bb9e8ad PM |
128 | |
129 | #ifdef HAVE_PT_GETDBREGS | |
130 | ||
5aca5a82 | 131 | i386_use_watchpoints (t); |
9bb9e8ad PM |
132 | |
133 | i386_dr_low.set_control = i386bsd_dr_set_control; | |
134 | i386_dr_low.set_addr = i386bsd_dr_set_addr; | |
7b50312a | 135 | i386_dr_low.get_addr = i386bsd_dr_get_addr; |
9bb9e8ad | 136 | i386_dr_low.get_status = i386bsd_dr_get_status; |
7b50312a | 137 | i386_dr_low.get_control = i386bsd_dr_get_control; |
9bb9e8ad PM |
138 | i386_set_debug_register_length (4); |
139 | ||
140 | #endif /* HAVE_PT_GETDBREGS */ | |
141 | ||
142 | ||
9692934b MK |
143 | t->to_resume = i386fbsd_resume; |
144 | t->to_pid_to_exec_file = fbsd_pid_to_exec_file; | |
145 | t->to_find_memory_regions = fbsd_find_memory_regions; | |
146 | t->to_make_corefile_notes = fbsd_make_corefile_notes; | |
147 | add_target (t); | |
148 | ||
771e236c MK |
149 | /* Support debugging kernel virtual memory images. */ |
150 | bsd_kvm_add_target (i386fbsd_supply_pcb); | |
151 | ||
25630444 MK |
152 | /* FreeBSD provides a kern.ps_strings sysctl that we can use to |
153 | locate the sigtramp. That way we can still recognize a sigtramp | |
8201327c | 154 | if its location is changed in a new kernel. Of course this is |
25630444 MK |
155 | still based on the assumption that the sigtramp is placed |
156 | directly under the location where the program arguments and | |
157 | environment can be found. */ | |
158 | #ifdef KERN_PS_STRINGS | |
159 | { | |
160 | int mib[2]; | |
57ac95b8 | 161 | u_long ps_strings; |
25630444 MK |
162 | size_t len; |
163 | ||
164 | mib[0] = CTL_KERN; | |
165 | mib[1] = KERN_PS_STRINGS; | |
166 | len = sizeof (ps_strings); | |
167 | if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) == 0) | |
168 | { | |
5d93ae8c MK |
169 | i386fbsd_sigtramp_start_addr = ps_strings - 128; |
170 | i386fbsd_sigtramp_end_addr = ps_strings; | |
25630444 MK |
171 | } |
172 | } | |
173 | #endif | |
174 | } |