Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-struct-independent code to start (run) and stop an inferior process. |
8926118c AC |
2 | |
3 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, | |
4 | 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software | |
5 | Foundation, Inc. | |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b JM |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program; if not, write to the Free Software | |
21 | Foundation, Inc., 59 Temple Place - Suite 330, | |
22 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
23 | |
24 | #include "defs.h" | |
25 | #include "gdb_string.h" | |
26 | #include <ctype.h> | |
27 | #include "symtab.h" | |
28 | #include "frame.h" | |
29 | #include "inferior.h" | |
30 | #include "breakpoint.h" | |
03f2053f | 31 | #include "gdb_wait.h" |
c906108c SS |
32 | #include "gdbcore.h" |
33 | #include "gdbcmd.h" | |
210661e7 | 34 | #include "cli/cli-script.h" |
c906108c SS |
35 | #include "target.h" |
36 | #include "gdbthread.h" | |
37 | #include "annotate.h" | |
1adeb98a | 38 | #include "symfile.h" |
7a292a7a | 39 | #include "top.h" |
c906108c | 40 | #include <signal.h> |
2acceee2 | 41 | #include "inf-loop.h" |
4e052eda | 42 | #include "regcache.h" |
fd0407d6 | 43 | #include "value.h" |
c906108c SS |
44 | |
45 | /* Prototypes for local functions */ | |
46 | ||
96baa820 | 47 | static void signals_info (char *, int); |
c906108c | 48 | |
96baa820 | 49 | static void handle_command (char *, int); |
c906108c | 50 | |
96baa820 | 51 | static void sig_print_info (enum target_signal); |
c906108c | 52 | |
96baa820 | 53 | static void sig_print_header (void); |
c906108c | 54 | |
74b7792f | 55 | static void resume_cleanups (void *); |
c906108c | 56 | |
96baa820 | 57 | static int hook_stop_stub (void *); |
c906108c | 58 | |
96baa820 | 59 | static void delete_breakpoint_current_contents (void *); |
c906108c | 60 | |
96baa820 JM |
61 | static void set_follow_fork_mode_command (char *arg, int from_tty, |
62 | struct cmd_list_element * c); | |
7a292a7a | 63 | |
96baa820 JM |
64 | static struct inferior_status *xmalloc_inferior_status (void); |
65 | ||
66 | static void free_inferior_status (struct inferior_status *); | |
67 | ||
68 | static int restore_selected_frame (void *); | |
69 | ||
70 | static void build_infrun (void); | |
71 | ||
72 | static void follow_inferior_fork (int parent_pid, int child_pid, | |
73 | int has_forked, int has_vforked); | |
74 | ||
75 | static void follow_fork (int parent_pid, int child_pid); | |
76 | ||
77 | static void follow_vfork (int parent_pid, int child_pid); | |
78 | ||
79 | static void set_schedlock_func (char *args, int from_tty, | |
80 | struct cmd_list_element * c); | |
81 | ||
96baa820 JM |
82 | struct execution_control_state; |
83 | ||
84 | static int currently_stepping (struct execution_control_state *ecs); | |
85 | ||
86 | static void xdb_handle_command (char *args, int from_tty); | |
87 | ||
88 | void _initialize_infrun (void); | |
43ff13b4 | 89 | |
c906108c SS |
90 | int inferior_ignoring_startup_exec_events = 0; |
91 | int inferior_ignoring_leading_exec_events = 0; | |
92 | ||
5fbbeb29 CF |
93 | /* When set, stop the 'step' command if we enter a function which has |
94 | no line number information. The normal behavior is that we step | |
95 | over such function. */ | |
96 | int step_stop_if_no_debug = 0; | |
97 | ||
43ff13b4 | 98 | /* In asynchronous mode, but simulating synchronous execution. */ |
96baa820 | 99 | |
43ff13b4 JM |
100 | int sync_execution = 0; |
101 | ||
c906108c SS |
102 | /* wait_for_inferior and normal_stop use this to notify the user |
103 | when the inferior stopped in a different thread than it had been | |
96baa820 JM |
104 | running in. */ |
105 | ||
39f77062 | 106 | static ptid_t previous_inferior_ptid; |
7a292a7a SS |
107 | |
108 | /* This is true for configurations that may follow through execl() and | |
109 | similar functions. At present this is only true for HP-UX native. */ | |
110 | ||
111 | #ifndef MAY_FOLLOW_EXEC | |
112 | #define MAY_FOLLOW_EXEC (0) | |
c906108c SS |
113 | #endif |
114 | ||
7a292a7a SS |
115 | static int may_follow_exec = MAY_FOLLOW_EXEC; |
116 | ||
c906108c SS |
117 | /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the |
118 | program. It needs to examine the jmp_buf argument and extract the PC | |
119 | from it. The return value is non-zero on success, zero otherwise. */ | |
120 | ||
121 | #ifndef GET_LONGJMP_TARGET | |
122 | #define GET_LONGJMP_TARGET(PC_ADDR) 0 | |
123 | #endif | |
124 | ||
125 | ||
c906108c SS |
126 | /* Dynamic function trampolines are similar to solib trampolines in that they |
127 | are between the caller and the callee. The difference is that when you | |
128 | enter a dynamic trampoline, you can't determine the callee's address. Some | |
129 | (usually complex) code needs to run in the dynamic trampoline to figure out | |
130 | the callee's address. This macro is usually called twice. First, when we | |
131 | enter the trampoline (looks like a normal function call at that point). It | |
132 | should return the PC of a point within the trampoline where the callee's | |
133 | address is known. Second, when we hit the breakpoint, this routine returns | |
134 | the callee's address. At that point, things proceed as per a step resume | |
135 | breakpoint. */ | |
136 | ||
137 | #ifndef DYNAMIC_TRAMPOLINE_NEXTPC | |
138 | #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0 | |
139 | #endif | |
140 | ||
d4f3574e SS |
141 | /* If the program uses ELF-style shared libraries, then calls to |
142 | functions in shared libraries go through stubs, which live in a | |
143 | table called the PLT (Procedure Linkage Table). The first time the | |
144 | function is called, the stub sends control to the dynamic linker, | |
145 | which looks up the function's real address, patches the stub so | |
146 | that future calls will go directly to the function, and then passes | |
147 | control to the function. | |
148 | ||
149 | If we are stepping at the source level, we don't want to see any of | |
150 | this --- we just want to skip over the stub and the dynamic linker. | |
151 | The simple approach is to single-step until control leaves the | |
152 | dynamic linker. | |
153 | ||
154 | However, on some systems (e.g., Red Hat Linux 5.2) the dynamic | |
155 | linker calls functions in the shared C library, so you can't tell | |
156 | from the PC alone whether the dynamic linker is still running. In | |
157 | this case, we use a step-resume breakpoint to get us past the | |
158 | dynamic linker, as if we were using "next" to step over a function | |
159 | call. | |
160 | ||
161 | IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic | |
162 | linker code or not. Normally, this means we single-step. However, | |
163 | if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an | |
164 | address where we can place a step-resume breakpoint to get past the | |
165 | linker's symbol resolution function. | |
166 | ||
167 | IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a | |
168 | pretty portable way, by comparing the PC against the address ranges | |
169 | of the dynamic linker's sections. | |
170 | ||
171 | SKIP_SOLIB_RESOLVER is generally going to be system-specific, since | |
172 | it depends on internal details of the dynamic linker. It's usually | |
173 | not too hard to figure out where to put a breakpoint, but it | |
174 | certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of | |
175 | sanity checking. If it can't figure things out, returning zero and | |
176 | getting the (possibly confusing) stepping behavior is better than | |
177 | signalling an error, which will obscure the change in the | |
178 | inferior's state. */ | |
c906108c SS |
179 | |
180 | #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE | |
181 | #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0 | |
182 | #endif | |
183 | ||
d4f3574e SS |
184 | #ifndef SKIP_SOLIB_RESOLVER |
185 | #define SKIP_SOLIB_RESOLVER(pc) 0 | |
186 | #endif | |
187 | ||
c906108c SS |
188 | /* In some shared library schemes, the return path from a shared library |
189 | call may need to go through a trampoline too. */ | |
190 | ||
191 | #ifndef IN_SOLIB_RETURN_TRAMPOLINE | |
192 | #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0 | |
193 | #endif | |
194 | ||
195 | /* This function returns TRUE if pc is the address of an instruction | |
196 | that lies within the dynamic linker (such as the event hook, or the | |
197 | dld itself). | |
198 | ||
199 | This function must be used only when a dynamic linker event has | |
200 | been caught, and the inferior is being stepped out of the hook, or | |
201 | undefined results are guaranteed. */ | |
202 | ||
203 | #ifndef SOLIB_IN_DYNAMIC_LINKER | |
204 | #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 | |
205 | #endif | |
206 | ||
207 | /* On MIPS16, a function that returns a floating point value may call | |
208 | a library helper function to copy the return value to a floating point | |
209 | register. The IGNORE_HELPER_CALL macro returns non-zero if we | |
210 | should ignore (i.e. step over) this function call. */ | |
211 | #ifndef IGNORE_HELPER_CALL | |
212 | #define IGNORE_HELPER_CALL(pc) 0 | |
213 | #endif | |
214 | ||
215 | /* On some systems, the PC may be left pointing at an instruction that won't | |
216 | actually be executed. This is usually indicated by a bit in the PSW. If | |
217 | we find ourselves in such a state, then we step the target beyond the | |
218 | nullified instruction before returning control to the user so as to avoid | |
219 | confusion. */ | |
220 | ||
221 | #ifndef INSTRUCTION_NULLIFIED | |
222 | #define INSTRUCTION_NULLIFIED 0 | |
223 | #endif | |
224 | ||
c2c6d25f JM |
225 | /* We can't step off a permanent breakpoint in the ordinary way, because we |
226 | can't remove it. Instead, we have to advance the PC to the next | |
227 | instruction. This macro should expand to a pointer to a function that | |
228 | does that, or zero if we have no such function. If we don't have a | |
229 | definition for it, we have to report an error. */ | |
230 | #ifndef SKIP_PERMANENT_BREAKPOINT | |
231 | #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint) | |
232 | static void | |
c2d11a7d | 233 | default_skip_permanent_breakpoint (void) |
c2c6d25f | 234 | { |
255e7dbf | 235 | error ("\ |
c2c6d25f JM |
236 | The program is stopped at a permanent breakpoint, but GDB does not know\n\ |
237 | how to step past a permanent breakpoint on this architecture. Try using\n\ | |
255e7dbf | 238 | a command like `return' or `jump' to continue execution."); |
c2c6d25f JM |
239 | } |
240 | #endif | |
241 | ||
242 | ||
7a292a7a SS |
243 | /* Convert the #defines into values. This is temporary until wfi control |
244 | flow is completely sorted out. */ | |
245 | ||
246 | #ifndef HAVE_STEPPABLE_WATCHPOINT | |
247 | #define HAVE_STEPPABLE_WATCHPOINT 0 | |
248 | #else | |
249 | #undef HAVE_STEPPABLE_WATCHPOINT | |
250 | #define HAVE_STEPPABLE_WATCHPOINT 1 | |
251 | #endif | |
252 | ||
253 | #ifndef HAVE_NONSTEPPABLE_WATCHPOINT | |
254 | #define HAVE_NONSTEPPABLE_WATCHPOINT 0 | |
255 | #else | |
256 | #undef HAVE_NONSTEPPABLE_WATCHPOINT | |
257 | #define HAVE_NONSTEPPABLE_WATCHPOINT 1 | |
258 | #endif | |
259 | ||
260 | #ifndef HAVE_CONTINUABLE_WATCHPOINT | |
261 | #define HAVE_CONTINUABLE_WATCHPOINT 0 | |
262 | #else | |
263 | #undef HAVE_CONTINUABLE_WATCHPOINT | |
264 | #define HAVE_CONTINUABLE_WATCHPOINT 1 | |
265 | #endif | |
266 | ||
692590c1 MS |
267 | #ifndef CANNOT_STEP_HW_WATCHPOINTS |
268 | #define CANNOT_STEP_HW_WATCHPOINTS 0 | |
269 | #else | |
270 | #undef CANNOT_STEP_HW_WATCHPOINTS | |
271 | #define CANNOT_STEP_HW_WATCHPOINTS 1 | |
272 | #endif | |
273 | ||
c906108c SS |
274 | /* Tables of how to react to signals; the user sets them. */ |
275 | ||
276 | static unsigned char *signal_stop; | |
277 | static unsigned char *signal_print; | |
278 | static unsigned char *signal_program; | |
279 | ||
280 | #define SET_SIGS(nsigs,sigs,flags) \ | |
281 | do { \ | |
282 | int signum = (nsigs); \ | |
283 | while (signum-- > 0) \ | |
284 | if ((sigs)[signum]) \ | |
285 | (flags)[signum] = 1; \ | |
286 | } while (0) | |
287 | ||
288 | #define UNSET_SIGS(nsigs,sigs,flags) \ | |
289 | do { \ | |
290 | int signum = (nsigs); \ | |
291 | while (signum-- > 0) \ | |
292 | if ((sigs)[signum]) \ | |
293 | (flags)[signum] = 0; \ | |
294 | } while (0) | |
295 | ||
39f77062 KB |
296 | /* Value to pass to target_resume() to cause all threads to resume */ |
297 | ||
298 | #define RESUME_ALL (pid_to_ptid (-1)) | |
c906108c SS |
299 | |
300 | /* Command list pointer for the "stop" placeholder. */ | |
301 | ||
302 | static struct cmd_list_element *stop_command; | |
303 | ||
304 | /* Nonzero if breakpoints are now inserted in the inferior. */ | |
305 | ||
306 | static int breakpoints_inserted; | |
307 | ||
308 | /* Function inferior was in as of last step command. */ | |
309 | ||
310 | static struct symbol *step_start_function; | |
311 | ||
312 | /* Nonzero if we are expecting a trace trap and should proceed from it. */ | |
313 | ||
314 | static int trap_expected; | |
315 | ||
316 | #ifdef SOLIB_ADD | |
317 | /* Nonzero if we want to give control to the user when we're notified | |
318 | of shared library events by the dynamic linker. */ | |
319 | static int stop_on_solib_events; | |
320 | #endif | |
321 | ||
322 | #ifdef HP_OS_BUG | |
323 | /* Nonzero if the next time we try to continue the inferior, it will | |
324 | step one instruction and generate a spurious trace trap. | |
325 | This is used to compensate for a bug in HP-UX. */ | |
326 | ||
327 | static int trap_expected_after_continue; | |
328 | #endif | |
329 | ||
330 | /* Nonzero means expecting a trace trap | |
331 | and should stop the inferior and return silently when it happens. */ | |
332 | ||
333 | int stop_after_trap; | |
334 | ||
335 | /* Nonzero means expecting a trap and caller will handle it themselves. | |
336 | It is used after attach, due to attaching to a process; | |
337 | when running in the shell before the child program has been exec'd; | |
338 | and when running some kinds of remote stuff (FIXME?). */ | |
339 | ||
340 | int stop_soon_quietly; | |
341 | ||
342 | /* Nonzero if proceed is being used for a "finish" command or a similar | |
343 | situation when stop_registers should be saved. */ | |
344 | ||
345 | int proceed_to_finish; | |
346 | ||
347 | /* Save register contents here when about to pop a stack dummy frame, | |
348 | if-and-only-if proceed_to_finish is set. | |
349 | Thus this contains the return value from the called function (assuming | |
350 | values are returned in a register). */ | |
351 | ||
7a292a7a | 352 | char *stop_registers; |
c906108c SS |
353 | |
354 | /* Nonzero if program stopped due to error trying to insert breakpoints. */ | |
355 | ||
356 | static int breakpoints_failed; | |
357 | ||
358 | /* Nonzero after stop if current stack frame should be printed. */ | |
359 | ||
360 | static int stop_print_frame; | |
361 | ||
362 | static struct breakpoint *step_resume_breakpoint = NULL; | |
363 | static struct breakpoint *through_sigtramp_breakpoint = NULL; | |
364 | ||
365 | /* On some platforms (e.g., HP-UX), hardware watchpoints have bad | |
366 | interactions with an inferior that is running a kernel function | |
367 | (aka, a system call or "syscall"). wait_for_inferior therefore | |
368 | may have a need to know when the inferior is in a syscall. This | |
369 | is a count of the number of inferior threads which are known to | |
370 | currently be running in a syscall. */ | |
371 | static int number_of_threads_in_syscalls; | |
372 | ||
e02bc4cc DS |
373 | /* This is a cached copy of the pid/waitstatus of the last event |
374 | returned by target_wait()/target_wait_hook(). This information is | |
375 | returned by get_last_target_status(). */ | |
39f77062 | 376 | static ptid_t target_last_wait_ptid; |
e02bc4cc DS |
377 | static struct target_waitstatus target_last_waitstatus; |
378 | ||
c906108c SS |
379 | /* This is used to remember when a fork, vfork or exec event |
380 | was caught by a catchpoint, and thus the event is to be | |
381 | followed at the next resume of the inferior, and not | |
382 | immediately. */ | |
383 | static struct | |
384 | { | |
385 | enum target_waitkind kind; | |
386 | struct | |
387 | { | |
388 | int parent_pid; | |
389 | int saw_parent_fork; | |
390 | int child_pid; | |
391 | int saw_child_fork; | |
392 | int saw_child_exec; | |
393 | } | |
394 | fork_event; | |
395 | char *execd_pathname; | |
396 | } | |
397 | pending_follow; | |
398 | ||
399 | /* Some platforms don't allow us to do anything meaningful with a | |
400 | vforked child until it has exec'd. Vforked processes on such | |
401 | platforms can only be followed after they've exec'd. | |
402 | ||
403 | When this is set to 0, a vfork can be immediately followed, | |
404 | and an exec can be followed merely as an exec. When this is | |
405 | set to 1, a vfork event has been seen, but cannot be followed | |
406 | until the exec is seen. | |
407 | ||
39f77062 | 408 | (In the latter case, inferior_ptid is still the parent of the |
c906108c SS |
409 | vfork, and pending_follow.fork_event.child_pid is the child. The |
410 | appropriate process is followed, according to the setting of | |
411 | follow-fork-mode.) */ | |
412 | static int follow_vfork_when_exec; | |
413 | ||
53904c9e AC |
414 | static const char follow_fork_mode_ask[] = "ask"; |
415 | static const char follow_fork_mode_both[] = "both"; | |
416 | static const char follow_fork_mode_child[] = "child"; | |
417 | static const char follow_fork_mode_parent[] = "parent"; | |
418 | ||
419 | static const char *follow_fork_mode_kind_names[] = | |
c906108c | 420 | { |
53904c9e | 421 | follow_fork_mode_ask, |
ef346e04 AC |
422 | /* ??rehrauer: The "both" option is broken, by what may be a 10.20 |
423 | kernel problem. It's also not terribly useful without a GUI to | |
424 | help the user drive two debuggers. So for now, I'm disabling the | |
425 | "both" option. */ | |
53904c9e AC |
426 | /* follow_fork_mode_both, */ |
427 | follow_fork_mode_child, | |
428 | follow_fork_mode_parent, | |
429 | NULL | |
ef346e04 | 430 | }; |
c906108c | 431 | |
53904c9e | 432 | static const char *follow_fork_mode_string = follow_fork_mode_parent; |
c906108c SS |
433 | \f |
434 | ||
c906108c | 435 | static void |
96baa820 JM |
436 | follow_inferior_fork (int parent_pid, int child_pid, int has_forked, |
437 | int has_vforked) | |
c906108c SS |
438 | { |
439 | int followed_parent = 0; | |
440 | int followed_child = 0; | |
c906108c SS |
441 | |
442 | /* Which process did the user want us to follow? */ | |
53904c9e | 443 | const char *follow_mode = follow_fork_mode_string; |
c906108c SS |
444 | |
445 | /* Or, did the user not know, and want us to ask? */ | |
e28d556f | 446 | if (follow_fork_mode_string == follow_fork_mode_ask) |
c906108c | 447 | { |
8e65ff28 AC |
448 | internal_error (__FILE__, __LINE__, |
449 | "follow_inferior_fork: \"ask\" mode not implemented"); | |
53904c9e | 450 | /* follow_mode = follow_fork_mode_...; */ |
c906108c SS |
451 | } |
452 | ||
453 | /* If we're to be following the parent, then detach from child_pid. | |
454 | We're already following the parent, so need do nothing explicit | |
455 | for it. */ | |
53904c9e | 456 | if (follow_mode == follow_fork_mode_parent) |
c906108c SS |
457 | { |
458 | followed_parent = 1; | |
459 | ||
460 | /* We're already attached to the parent, by default. */ | |
461 | ||
462 | /* Before detaching from the child, remove all breakpoints from | |
463 | it. (This won't actually modify the breakpoint list, but will | |
464 | physically remove the breakpoints from the child.) */ | |
465 | if (!has_vforked || !follow_vfork_when_exec) | |
466 | { | |
467 | detach_breakpoints (child_pid); | |
7a292a7a | 468 | #ifdef SOLIB_REMOVE_INFERIOR_HOOK |
c906108c | 469 | SOLIB_REMOVE_INFERIOR_HOOK (child_pid); |
7a292a7a | 470 | #endif |
c906108c SS |
471 | } |
472 | ||
473 | /* Detach from the child. */ | |
474 | dont_repeat (); | |
475 | ||
476 | target_require_detach (child_pid, "", 1); | |
477 | } | |
478 | ||
479 | /* If we're to be following the child, then attach to it, detach | |
39f77062 | 480 | from inferior_ptid, and set inferior_ptid to child_pid. */ |
53904c9e | 481 | else if (follow_mode == follow_fork_mode_child) |
c906108c SS |
482 | { |
483 | char child_pid_spelling[100]; /* Arbitrary length. */ | |
484 | ||
485 | followed_child = 1; | |
486 | ||
487 | /* Before detaching from the parent, detach all breakpoints from | |
488 | the child. But only if we're forking, or if we follow vforks | |
489 | as soon as they happen. (If we're following vforks only when | |
490 | the child has exec'd, then it's very wrong to try to write | |
491 | back the "shadow contents" of inserted breakpoints now -- they | |
492 | belong to the child's pre-exec'd a.out.) */ | |
493 | if (!has_vforked || !follow_vfork_when_exec) | |
494 | { | |
495 | detach_breakpoints (child_pid); | |
496 | } | |
497 | ||
498 | /* Before detaching from the parent, remove all breakpoints from it. */ | |
499 | remove_breakpoints (); | |
500 | ||
501 | /* Also reset the solib inferior hook from the parent. */ | |
7a292a7a | 502 | #ifdef SOLIB_REMOVE_INFERIOR_HOOK |
39f77062 | 503 | SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
7a292a7a | 504 | #endif |
c906108c SS |
505 | |
506 | /* Detach from the parent. */ | |
507 | dont_repeat (); | |
508 | target_detach (NULL, 1); | |
509 | ||
510 | /* Attach to the child. */ | |
39f77062 | 511 | inferior_ptid = pid_to_ptid (child_pid); |
c906108c SS |
512 | sprintf (child_pid_spelling, "%d", child_pid); |
513 | dont_repeat (); | |
514 | ||
515 | target_require_attach (child_pid_spelling, 1); | |
516 | ||
517 | /* Was there a step_resume breakpoint? (There was if the user | |
518 | did a "next" at the fork() call.) If so, explicitly reset its | |
519 | thread number. | |
520 | ||
521 | step_resumes are a form of bp that are made to be per-thread. | |
522 | Since we created the step_resume bp when the parent process | |
523 | was being debugged, and now are switching to the child process, | |
524 | from the breakpoint package's viewpoint, that's a switch of | |
525 | "threads". We must update the bp's notion of which thread | |
526 | it is for, or it'll be ignored when it triggers... */ | |
527 | if (step_resume_breakpoint && | |
528 | (!has_vforked || !follow_vfork_when_exec)) | |
529 | breakpoint_re_set_thread (step_resume_breakpoint); | |
530 | ||
531 | /* Reinsert all breakpoints in the child. (The user may've set | |
532 | breakpoints after catching the fork, in which case those | |
533 | actually didn't get set in the child, but only in the parent.) */ | |
534 | if (!has_vforked || !follow_vfork_when_exec) | |
535 | { | |
536 | breakpoint_re_set (); | |
537 | insert_breakpoints (); | |
538 | } | |
539 | } | |
540 | ||
541 | /* If we're to be following both parent and child, then fork ourselves, | |
542 | and attach the debugger clone to the child. */ | |
53904c9e | 543 | else if (follow_mode == follow_fork_mode_both) |
c906108c SS |
544 | { |
545 | char pid_suffix[100]; /* Arbitrary length. */ | |
546 | ||
547 | /* Clone ourselves to follow the child. This is the end of our | |
c5aa993b | 548 | involvement with child_pid; our clone will take it from here... */ |
c906108c SS |
549 | dont_repeat (); |
550 | target_clone_and_follow_inferior (child_pid, &followed_child); | |
551 | followed_parent = !followed_child; | |
552 | ||
553 | /* We continue to follow the parent. To help distinguish the two | |
554 | debuggers, though, both we and our clone will reset our prompts. */ | |
39f77062 | 555 | sprintf (pid_suffix, "[%d] ", PIDGET (inferior_ptid)); |
c906108c SS |
556 | set_prompt (strcat (get_prompt (), pid_suffix)); |
557 | } | |
558 | ||
559 | /* The parent and child of a vfork share the same address space. | |
560 | Also, on some targets the order in which vfork and exec events | |
561 | are received for parent in child requires some delicate handling | |
562 | of the events. | |
563 | ||
564 | For instance, on ptrace-based HPUX we receive the child's vfork | |
565 | event first, at which time the parent has been suspended by the | |
566 | OS and is essentially untouchable until the child's exit or second | |
567 | exec event arrives. At that time, the parent's vfork event is | |
568 | delivered to us, and that's when we see and decide how to follow | |
569 | the vfork. But to get to that point, we must continue the child | |
570 | until it execs or exits. To do that smoothly, all breakpoints | |
571 | must be removed from the child, in case there are any set between | |
572 | the vfork() and exec() calls. But removing them from the child | |
573 | also removes them from the parent, due to the shared-address-space | |
574 | nature of a vfork'd parent and child. On HPUX, therefore, we must | |
575 | take care to restore the bp's to the parent before we continue it. | |
576 | Else, it's likely that we may not stop in the expected place. (The | |
577 | worst scenario is when the user tries to step over a vfork() call; | |
578 | the step-resume bp must be restored for the step to properly stop | |
579 | in the parent after the call completes!) | |
580 | ||
581 | Sequence of events, as reported to gdb from HPUX: | |
582 | ||
c5aa993b JM |
583 | Parent Child Action for gdb to take |
584 | ------------------------------------------------------- | |
585 | 1 VFORK Continue child | |
586 | 2 EXEC | |
587 | 3 EXEC or EXIT | |
588 | 4 VFORK */ | |
c906108c SS |
589 | if (has_vforked) |
590 | { | |
591 | target_post_follow_vfork (parent_pid, | |
592 | followed_parent, | |
593 | child_pid, | |
594 | followed_child); | |
595 | } | |
596 | ||
597 | pending_follow.fork_event.saw_parent_fork = 0; | |
598 | pending_follow.fork_event.saw_child_fork = 0; | |
c906108c SS |
599 | } |
600 | ||
601 | static void | |
96baa820 | 602 | follow_fork (int parent_pid, int child_pid) |
c906108c SS |
603 | { |
604 | follow_inferior_fork (parent_pid, child_pid, 1, 0); | |
605 | } | |
606 | ||
607 | ||
608 | /* Forward declaration. */ | |
96baa820 | 609 | static void follow_exec (int, char *); |
c906108c SS |
610 | |
611 | static void | |
96baa820 | 612 | follow_vfork (int parent_pid, int child_pid) |
c906108c SS |
613 | { |
614 | follow_inferior_fork (parent_pid, child_pid, 0, 1); | |
615 | ||
616 | /* Did we follow the child? Had it exec'd before we saw the parent vfork? */ | |
39f77062 KB |
617 | if (pending_follow.fork_event.saw_child_exec |
618 | && (PIDGET (inferior_ptid) == child_pid)) | |
c906108c SS |
619 | { |
620 | pending_follow.fork_event.saw_child_exec = 0; | |
621 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
39f77062 | 622 | follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname); |
b8c9b27d | 623 | xfree (pending_follow.execd_pathname); |
c906108c SS |
624 | } |
625 | } | |
c906108c | 626 | |
1adeb98a FN |
627 | /* EXECD_PATHNAME is assumed to be non-NULL. */ |
628 | ||
c906108c | 629 | static void |
96baa820 | 630 | follow_exec (int pid, char *execd_pathname) |
c906108c | 631 | { |
c906108c | 632 | int saved_pid = pid; |
7a292a7a SS |
633 | struct target_ops *tgt; |
634 | ||
635 | if (!may_follow_exec) | |
636 | return; | |
c906108c SS |
637 | |
638 | /* Did this exec() follow a vfork()? If so, we must follow the | |
639 | vfork now too. Do it before following the exec. */ | |
640 | if (follow_vfork_when_exec && | |
641 | (pending_follow.kind == TARGET_WAITKIND_VFORKED)) | |
642 | { | |
643 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
39f77062 KB |
644 | follow_vfork (PIDGET (inferior_ptid), |
645 | pending_follow.fork_event.child_pid); | |
c906108c | 646 | follow_vfork_when_exec = 0; |
39f77062 | 647 | saved_pid = PIDGET (inferior_ptid); |
c906108c SS |
648 | |
649 | /* Did we follow the parent? If so, we're done. If we followed | |
650 | the child then we must also follow its exec(). */ | |
39f77062 | 651 | if (PIDGET (inferior_ptid) == pending_follow.fork_event.parent_pid) |
c906108c SS |
652 | return; |
653 | } | |
654 | ||
655 | /* This is an exec event that we actually wish to pay attention to. | |
656 | Refresh our symbol table to the newly exec'd program, remove any | |
657 | momentary bp's, etc. | |
658 | ||
659 | If there are breakpoints, they aren't really inserted now, | |
660 | since the exec() transformed our inferior into a fresh set | |
661 | of instructions. | |
662 | ||
663 | We want to preserve symbolic breakpoints on the list, since | |
664 | we have hopes that they can be reset after the new a.out's | |
665 | symbol table is read. | |
666 | ||
667 | However, any "raw" breakpoints must be removed from the list | |
668 | (e.g., the solib bp's), since their address is probably invalid | |
669 | now. | |
670 | ||
671 | And, we DON'T want to call delete_breakpoints() here, since | |
672 | that may write the bp's "shadow contents" (the instruction | |
673 | value that was overwritten witha TRAP instruction). Since | |
674 | we now have a new a.out, those shadow contents aren't valid. */ | |
675 | update_breakpoints_after_exec (); | |
676 | ||
677 | /* If there was one, it's gone now. We cannot truly step-to-next | |
678 | statement through an exec(). */ | |
679 | step_resume_breakpoint = NULL; | |
680 | step_range_start = 0; | |
681 | step_range_end = 0; | |
682 | ||
683 | /* If there was one, it's gone now. */ | |
684 | through_sigtramp_breakpoint = NULL; | |
685 | ||
686 | /* What is this a.out's name? */ | |
687 | printf_unfiltered ("Executing new program: %s\n", execd_pathname); | |
688 | ||
689 | /* We've followed the inferior through an exec. Therefore, the | |
690 | inferior has essentially been killed & reborn. */ | |
7a292a7a SS |
691 | |
692 | /* First collect the run target in effect. */ | |
693 | tgt = find_run_target (); | |
694 | /* If we can't find one, things are in a very strange state... */ | |
695 | if (tgt == NULL) | |
696 | error ("Could find run target to save before following exec"); | |
697 | ||
c906108c SS |
698 | gdb_flush (gdb_stdout); |
699 | target_mourn_inferior (); | |
39f77062 KB |
700 | inferior_ptid = pid_to_ptid (saved_pid); |
701 | /* Because mourn_inferior resets inferior_ptid. */ | |
7a292a7a | 702 | push_target (tgt); |
c906108c SS |
703 | |
704 | /* That a.out is now the one to use. */ | |
705 | exec_file_attach (execd_pathname, 0); | |
706 | ||
707 | /* And also is where symbols can be found. */ | |
1adeb98a | 708 | symbol_file_add_main (execd_pathname, 0); |
c906108c SS |
709 | |
710 | /* Reset the shared library package. This ensures that we get | |
711 | a shlib event when the child reaches "_start", at which point | |
712 | the dld will have had a chance to initialize the child. */ | |
7a292a7a | 713 | #if defined(SOLIB_RESTART) |
c906108c | 714 | SOLIB_RESTART (); |
7a292a7a SS |
715 | #endif |
716 | #ifdef SOLIB_CREATE_INFERIOR_HOOK | |
39f77062 | 717 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
7a292a7a | 718 | #endif |
c906108c SS |
719 | |
720 | /* Reinsert all breakpoints. (Those which were symbolic have | |
721 | been reset to the proper address in the new a.out, thanks | |
722 | to symbol_file_command...) */ | |
723 | insert_breakpoints (); | |
724 | ||
725 | /* The next resume of this inferior should bring it to the shlib | |
726 | startup breakpoints. (If the user had also set bp's on | |
727 | "main" from the old (parent) process, then they'll auto- | |
728 | matically get reset there in the new process.) */ | |
c906108c SS |
729 | } |
730 | ||
731 | /* Non-zero if we just simulating a single-step. This is needed | |
732 | because we cannot remove the breakpoints in the inferior process | |
733 | until after the `wait' in `wait_for_inferior'. */ | |
734 | static int singlestep_breakpoints_inserted_p = 0; | |
735 | \f | |
736 | ||
737 | /* Things to clean up if we QUIT out of resume (). */ | |
738 | /* ARGSUSED */ | |
739 | static void | |
74b7792f | 740 | resume_cleanups (void *ignore) |
c906108c SS |
741 | { |
742 | normal_stop (); | |
743 | } | |
744 | ||
53904c9e AC |
745 | static const char schedlock_off[] = "off"; |
746 | static const char schedlock_on[] = "on"; | |
747 | static const char schedlock_step[] = "step"; | |
748 | static const char *scheduler_mode = schedlock_off; | |
749 | static const char *scheduler_enums[] = | |
ef346e04 AC |
750 | { |
751 | schedlock_off, | |
752 | schedlock_on, | |
753 | schedlock_step, | |
754 | NULL | |
755 | }; | |
c906108c SS |
756 | |
757 | static void | |
96baa820 | 758 | set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) |
c906108c SS |
759 | { |
760 | if (c->type == set_cmd) | |
761 | if (!target_can_lock_scheduler) | |
762 | { | |
763 | scheduler_mode = schedlock_off; | |
764 | error ("Target '%s' cannot support this command.", | |
765 | target_shortname); | |
766 | } | |
767 | } | |
768 | ||
769 | ||
770 | /* Resume the inferior, but allow a QUIT. This is useful if the user | |
771 | wants to interrupt some lengthy single-stepping operation | |
772 | (for child processes, the SIGINT goes to the inferior, and so | |
773 | we get a SIGINT random_signal, but for remote debugging and perhaps | |
774 | other targets, that's not true). | |
775 | ||
776 | STEP nonzero if we should step (zero to continue instead). | |
777 | SIG is the signal to give the inferior (zero for none). */ | |
778 | void | |
96baa820 | 779 | resume (int step, enum target_signal sig) |
c906108c SS |
780 | { |
781 | int should_resume = 1; | |
74b7792f | 782 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); |
c906108c SS |
783 | QUIT; |
784 | ||
ef5cf84e MS |
785 | /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */ |
786 | ||
c906108c | 787 | |
692590c1 MS |
788 | /* Some targets (e.g. Solaris x86) have a kernel bug when stepping |
789 | over an instruction that causes a page fault without triggering | |
790 | a hardware watchpoint. The kernel properly notices that it shouldn't | |
791 | stop, because the hardware watchpoint is not triggered, but it forgets | |
792 | the step request and continues the program normally. | |
793 | Work around the problem by removing hardware watchpoints if a step is | |
794 | requested, GDB will check for a hardware watchpoint trigger after the | |
795 | step anyway. */ | |
796 | if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted) | |
797 | remove_hw_watchpoints (); | |
798 | ||
799 | ||
c2c6d25f JM |
800 | /* Normally, by the time we reach `resume', the breakpoints are either |
801 | removed or inserted, as appropriate. The exception is if we're sitting | |
802 | at a permanent breakpoint; we need to step over it, but permanent | |
803 | breakpoints can't be removed. So we have to test for it here. */ | |
804 | if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here) | |
805 | SKIP_PERMANENT_BREAKPOINT (); | |
806 | ||
b0ed3589 | 807 | if (SOFTWARE_SINGLE_STEP_P () && step) |
c906108c SS |
808 | { |
809 | /* Do it the hard way, w/temp breakpoints */ | |
c5aa993b | 810 | SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ ); |
c906108c SS |
811 | /* ...and don't ask hardware to do it. */ |
812 | step = 0; | |
813 | /* and do not pull these breakpoints until after a `wait' in | |
814 | `wait_for_inferior' */ | |
815 | singlestep_breakpoints_inserted_p = 1; | |
816 | } | |
817 | ||
818 | /* Handle any optimized stores to the inferior NOW... */ | |
819 | #ifdef DO_DEFERRED_STORES | |
820 | DO_DEFERRED_STORES; | |
821 | #endif | |
822 | ||
c906108c SS |
823 | /* If there were any forks/vforks/execs that were caught and are |
824 | now to be followed, then do so. */ | |
825 | switch (pending_follow.kind) | |
826 | { | |
827 | case (TARGET_WAITKIND_FORKED): | |
828 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
39f77062 KB |
829 | follow_fork (PIDGET (inferior_ptid), |
830 | pending_follow.fork_event.child_pid); | |
c906108c SS |
831 | break; |
832 | ||
833 | case (TARGET_WAITKIND_VFORKED): | |
834 | { | |
835 | int saw_child_exec = pending_follow.fork_event.saw_child_exec; | |
836 | ||
837 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
39f77062 KB |
838 | follow_vfork (PIDGET (inferior_ptid), |
839 | pending_follow.fork_event.child_pid); | |
c906108c SS |
840 | |
841 | /* Did we follow the child, but not yet see the child's exec event? | |
c5aa993b JM |
842 | If so, then it actually ought to be waiting for us; we respond to |
843 | parent vfork events. We don't actually want to resume the child | |
844 | in this situation; we want to just get its exec event. */ | |
c906108c | 845 | if (!saw_child_exec && |
39f77062 | 846 | (PIDGET (inferior_ptid) == pending_follow.fork_event.child_pid)) |
c906108c SS |
847 | should_resume = 0; |
848 | } | |
849 | break; | |
850 | ||
851 | case (TARGET_WAITKIND_EXECD): | |
852 | /* If we saw a vfork event but couldn't follow it until we saw | |
c5aa993b | 853 | an exec, then now might be the time! */ |
c906108c SS |
854 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
855 | /* follow_exec is called as soon as the exec event is seen. */ | |
856 | break; | |
857 | ||
858 | default: | |
859 | break; | |
860 | } | |
c906108c SS |
861 | |
862 | /* Install inferior's terminal modes. */ | |
863 | target_terminal_inferior (); | |
864 | ||
865 | if (should_resume) | |
866 | { | |
39f77062 | 867 | ptid_t resume_ptid; |
dfcd3bfb | 868 | |
ef5cf84e MS |
869 | resume_ptid = RESUME_ALL; /* Default */ |
870 | ||
871 | if ((step || singlestep_breakpoints_inserted_p) && | |
872 | !breakpoints_inserted && breakpoint_here_p (read_pc ())) | |
c906108c | 873 | { |
ef5cf84e MS |
874 | /* Stepping past a breakpoint without inserting breakpoints. |
875 | Make sure only the current thread gets to step, so that | |
876 | other threads don't sneak past breakpoints while they are | |
877 | not inserted. */ | |
c906108c | 878 | |
ef5cf84e | 879 | resume_ptid = inferior_ptid; |
c906108c | 880 | } |
ef5cf84e MS |
881 | |
882 | if ((scheduler_mode == schedlock_on) || | |
883 | (scheduler_mode == schedlock_step && | |
884 | (step || singlestep_breakpoints_inserted_p))) | |
c906108c | 885 | { |
ef5cf84e | 886 | /* User-settable 'scheduler' mode requires solo thread resume. */ |
39f77062 | 887 | resume_ptid = inferior_ptid; |
c906108c | 888 | } |
ef5cf84e MS |
889 | |
890 | #ifdef CANNOT_STEP_BREAKPOINT | |
891 | /* Most targets can step a breakpoint instruction, thus executing it | |
892 | normally. But if this one cannot, just continue and we will hit | |
893 | it anyway. */ | |
894 | if (step && breakpoints_inserted && breakpoint_here_p (read_pc ())) | |
895 | step = 0; | |
896 | #endif | |
39f77062 | 897 | target_resume (resume_ptid, step, sig); |
c906108c SS |
898 | } |
899 | ||
900 | discard_cleanups (old_cleanups); | |
901 | } | |
902 | \f | |
903 | ||
904 | /* Clear out all variables saying what to do when inferior is continued. | |
905 | First do this, then set the ones you want, then call `proceed'. */ | |
906 | ||
907 | void | |
96baa820 | 908 | clear_proceed_status (void) |
c906108c SS |
909 | { |
910 | trap_expected = 0; | |
911 | step_range_start = 0; | |
912 | step_range_end = 0; | |
913 | step_frame_address = 0; | |
5fbbeb29 | 914 | step_over_calls = STEP_OVER_UNDEBUGGABLE; |
c906108c SS |
915 | stop_after_trap = 0; |
916 | stop_soon_quietly = 0; | |
917 | proceed_to_finish = 0; | |
918 | breakpoint_proceeded = 1; /* We're about to proceed... */ | |
919 | ||
920 | /* Discard any remaining commands or status from previous stop. */ | |
921 | bpstat_clear (&stop_bpstat); | |
922 | } | |
923 | ||
924 | /* Basic routine for continuing the program in various fashions. | |
925 | ||
926 | ADDR is the address to resume at, or -1 for resume where stopped. | |
927 | SIGGNAL is the signal to give it, or 0 for none, | |
c5aa993b | 928 | or -1 for act according to how it stopped. |
c906108c | 929 | STEP is nonzero if should trap after one instruction. |
c5aa993b JM |
930 | -1 means return after that and print nothing. |
931 | You should probably set various step_... variables | |
932 | before calling here, if you are stepping. | |
c906108c SS |
933 | |
934 | You should call clear_proceed_status before calling proceed. */ | |
935 | ||
936 | void | |
96baa820 | 937 | proceed (CORE_ADDR addr, enum target_signal siggnal, int step) |
c906108c SS |
938 | { |
939 | int oneproc = 0; | |
940 | ||
941 | if (step > 0) | |
942 | step_start_function = find_pc_function (read_pc ()); | |
943 | if (step < 0) | |
944 | stop_after_trap = 1; | |
945 | ||
2acceee2 | 946 | if (addr == (CORE_ADDR) -1) |
c906108c SS |
947 | { |
948 | /* If there is a breakpoint at the address we will resume at, | |
c5aa993b JM |
949 | step one instruction before inserting breakpoints |
950 | so that we do not stop right away (and report a second | |
c906108c SS |
951 | hit at this breakpoint). */ |
952 | ||
953 | if (read_pc () == stop_pc && breakpoint_here_p (read_pc ())) | |
954 | oneproc = 1; | |
955 | ||
956 | #ifndef STEP_SKIPS_DELAY | |
957 | #define STEP_SKIPS_DELAY(pc) (0) | |
958 | #define STEP_SKIPS_DELAY_P (0) | |
959 | #endif | |
960 | /* Check breakpoint_here_p first, because breakpoint_here_p is fast | |
c5aa993b JM |
961 | (it just checks internal GDB data structures) and STEP_SKIPS_DELAY |
962 | is slow (it needs to read memory from the target). */ | |
c906108c SS |
963 | if (STEP_SKIPS_DELAY_P |
964 | && breakpoint_here_p (read_pc () + 4) | |
965 | && STEP_SKIPS_DELAY (read_pc ())) | |
966 | oneproc = 1; | |
967 | } | |
968 | else | |
969 | { | |
970 | write_pc (addr); | |
c906108c SS |
971 | } |
972 | ||
973 | #ifdef PREPARE_TO_PROCEED | |
974 | /* In a multi-threaded task we may select another thread | |
975 | and then continue or step. | |
976 | ||
977 | But if the old thread was stopped at a breakpoint, it | |
978 | will immediately cause another breakpoint stop without | |
979 | any execution (i.e. it will report a breakpoint hit | |
980 | incorrectly). So we must step over it first. | |
981 | ||
982 | PREPARE_TO_PROCEED checks the current thread against the thread | |
983 | that reported the most recent event. If a step-over is required | |
984 | it returns TRUE and sets the current thread to the old thread. */ | |
9e086581 | 985 | if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ())) |
c906108c SS |
986 | { |
987 | oneproc = 1; | |
c906108c SS |
988 | } |
989 | ||
990 | #endif /* PREPARE_TO_PROCEED */ | |
991 | ||
992 | #ifdef HP_OS_BUG | |
993 | if (trap_expected_after_continue) | |
994 | { | |
995 | /* If (step == 0), a trap will be automatically generated after | |
c5aa993b JM |
996 | the first instruction is executed. Force step one |
997 | instruction to clear this condition. This should not occur | |
998 | if step is nonzero, but it is harmless in that case. */ | |
c906108c SS |
999 | oneproc = 1; |
1000 | trap_expected_after_continue = 0; | |
1001 | } | |
1002 | #endif /* HP_OS_BUG */ | |
1003 | ||
1004 | if (oneproc) | |
1005 | /* We will get a trace trap after one instruction. | |
1006 | Continue it automatically and insert breakpoints then. */ | |
1007 | trap_expected = 1; | |
1008 | else | |
1009 | { | |
1010 | int temp = insert_breakpoints (); | |
1011 | if (temp) | |
1012 | { | |
010a3cd9 | 1013 | print_sys_errmsg ("insert_breakpoints", temp); |
c906108c | 1014 | error ("Cannot insert breakpoints.\n\ |
010a3cd9 EZ |
1015 | The same program may be running in another process,\n\ |
1016 | or you may have requested too many hardware\n\ | |
1017 | breakpoints and/or watchpoints.\n"); | |
c906108c SS |
1018 | } |
1019 | ||
1020 | breakpoints_inserted = 1; | |
1021 | } | |
1022 | ||
1023 | if (siggnal != TARGET_SIGNAL_DEFAULT) | |
1024 | stop_signal = siggnal; | |
1025 | /* If this signal should not be seen by program, | |
1026 | give it zero. Used for debugging signals. */ | |
1027 | else if (!signal_program[stop_signal]) | |
1028 | stop_signal = TARGET_SIGNAL_0; | |
1029 | ||
1030 | annotate_starting (); | |
1031 | ||
1032 | /* Make sure that output from GDB appears before output from the | |
1033 | inferior. */ | |
1034 | gdb_flush (gdb_stdout); | |
1035 | ||
1036 | /* Resume inferior. */ | |
1037 | resume (oneproc || step || bpstat_should_step (), stop_signal); | |
1038 | ||
1039 | /* Wait for it to stop (if not standalone) | |
1040 | and in any case decode why it stopped, and act accordingly. */ | |
43ff13b4 JM |
1041 | /* Do this only if we are not using the event loop, or if the target |
1042 | does not support asynchronous execution. */ | |
6426a772 | 1043 | if (!event_loop_p || !target_can_async_p ()) |
43ff13b4 JM |
1044 | { |
1045 | wait_for_inferior (); | |
1046 | normal_stop (); | |
1047 | } | |
c906108c SS |
1048 | } |
1049 | ||
1050 | /* Record the pc and sp of the program the last time it stopped. | |
1051 | These are just used internally by wait_for_inferior, but need | |
1052 | to be preserved over calls to it and cleared when the inferior | |
1053 | is started. */ | |
1054 | static CORE_ADDR prev_pc; | |
1055 | static CORE_ADDR prev_func_start; | |
1056 | static char *prev_func_name; | |
1057 | \f | |
1058 | ||
1059 | /* Start remote-debugging of a machine over a serial link. */ | |
96baa820 | 1060 | |
c906108c | 1061 | void |
96baa820 | 1062 | start_remote (void) |
c906108c SS |
1063 | { |
1064 | init_thread_list (); | |
1065 | init_wait_for_inferior (); | |
1066 | stop_soon_quietly = 1; | |
1067 | trap_expected = 0; | |
43ff13b4 | 1068 | |
6426a772 JM |
1069 | /* Always go on waiting for the target, regardless of the mode. */ |
1070 | /* FIXME: cagney/1999-09-23: At present it isn't possible to | |
7e73cedf | 1071 | indicate to wait_for_inferior that a target should timeout if |
6426a772 JM |
1072 | nothing is returned (instead of just blocking). Because of this, |
1073 | targets expecting an immediate response need to, internally, set | |
1074 | things up so that the target_wait() is forced to eventually | |
1075 | timeout. */ | |
1076 | /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to | |
1077 | differentiate to its caller what the state of the target is after | |
1078 | the initial open has been performed. Here we're assuming that | |
1079 | the target has stopped. It should be possible to eventually have | |
1080 | target_open() return to the caller an indication that the target | |
1081 | is currently running and GDB state should be set to the same as | |
1082 | for an async run. */ | |
1083 | wait_for_inferior (); | |
1084 | normal_stop (); | |
c906108c SS |
1085 | } |
1086 | ||
1087 | /* Initialize static vars when a new inferior begins. */ | |
1088 | ||
1089 | void | |
96baa820 | 1090 | init_wait_for_inferior (void) |
c906108c SS |
1091 | { |
1092 | /* These are meaningless until the first time through wait_for_inferior. */ | |
1093 | prev_pc = 0; | |
1094 | prev_func_start = 0; | |
1095 | prev_func_name = NULL; | |
1096 | ||
1097 | #ifdef HP_OS_BUG | |
1098 | trap_expected_after_continue = 0; | |
1099 | #endif | |
1100 | breakpoints_inserted = 0; | |
1101 | breakpoint_init_inferior (inf_starting); | |
1102 | ||
1103 | /* Don't confuse first call to proceed(). */ | |
1104 | stop_signal = TARGET_SIGNAL_0; | |
1105 | ||
1106 | /* The first resume is not following a fork/vfork/exec. */ | |
1107 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */ | |
1108 | pending_follow.fork_event.saw_parent_fork = 0; | |
1109 | pending_follow.fork_event.saw_child_fork = 0; | |
1110 | pending_follow.fork_event.saw_child_exec = 0; | |
1111 | ||
1112 | /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */ | |
1113 | number_of_threads_in_syscalls = 0; | |
1114 | ||
1115 | clear_proceed_status (); | |
1116 | } | |
1117 | ||
1118 | static void | |
96baa820 | 1119 | delete_breakpoint_current_contents (void *arg) |
c906108c SS |
1120 | { |
1121 | struct breakpoint **breakpointp = (struct breakpoint **) arg; | |
1122 | if (*breakpointp != NULL) | |
1123 | { | |
1124 | delete_breakpoint (*breakpointp); | |
1125 | *breakpointp = NULL; | |
1126 | } | |
1127 | } | |
1128 | \f | |
b83266a0 SS |
1129 | /* This enum encodes possible reasons for doing a target_wait, so that |
1130 | wfi can call target_wait in one place. (Ultimately the call will be | |
1131 | moved out of the infinite loop entirely.) */ | |
1132 | ||
c5aa993b JM |
1133 | enum infwait_states |
1134 | { | |
cd0fc7c3 SS |
1135 | infwait_normal_state, |
1136 | infwait_thread_hop_state, | |
1137 | infwait_nullified_state, | |
1138 | infwait_nonstep_watch_state | |
b83266a0 SS |
1139 | }; |
1140 | ||
11cf8741 JM |
1141 | /* Why did the inferior stop? Used to print the appropriate messages |
1142 | to the interface from within handle_inferior_event(). */ | |
1143 | enum inferior_stop_reason | |
1144 | { | |
1145 | /* We don't know why. */ | |
1146 | STOP_UNKNOWN, | |
1147 | /* Step, next, nexti, stepi finished. */ | |
1148 | END_STEPPING_RANGE, | |
1149 | /* Found breakpoint. */ | |
1150 | BREAKPOINT_HIT, | |
1151 | /* Inferior terminated by signal. */ | |
1152 | SIGNAL_EXITED, | |
1153 | /* Inferior exited. */ | |
1154 | EXITED, | |
1155 | /* Inferior received signal, and user asked to be notified. */ | |
1156 | SIGNAL_RECEIVED | |
1157 | }; | |
1158 | ||
cd0fc7c3 SS |
1159 | /* This structure contains what used to be local variables in |
1160 | wait_for_inferior. Probably many of them can return to being | |
1161 | locals in handle_inferior_event. */ | |
1162 | ||
c5aa993b JM |
1163 | struct execution_control_state |
1164 | { | |
1165 | struct target_waitstatus ws; | |
1166 | struct target_waitstatus *wp; | |
1167 | int another_trap; | |
1168 | int random_signal; | |
1169 | CORE_ADDR stop_func_start; | |
1170 | CORE_ADDR stop_func_end; | |
1171 | char *stop_func_name; | |
1172 | struct symtab_and_line sal; | |
1173 | int remove_breakpoints_on_following_step; | |
1174 | int current_line; | |
1175 | struct symtab *current_symtab; | |
1176 | int handling_longjmp; /* FIXME */ | |
39f77062 KB |
1177 | ptid_t ptid; |
1178 | ptid_t saved_inferior_ptid; | |
c5aa993b JM |
1179 | int update_step_sp; |
1180 | int stepping_through_solib_after_catch; | |
1181 | bpstat stepping_through_solib_catchpoints; | |
1182 | int enable_hw_watchpoints_after_wait; | |
1183 | int stepping_through_sigtramp; | |
1184 | int new_thread_event; | |
1185 | struct target_waitstatus tmpstatus; | |
1186 | enum infwait_states infwait_state; | |
39f77062 | 1187 | ptid_t waiton_ptid; |
c5aa993b JM |
1188 | int wait_some_more; |
1189 | }; | |
1190 | ||
96baa820 | 1191 | void init_execution_control_state (struct execution_control_state * ecs); |
c5aa993b | 1192 | |
96baa820 | 1193 | void handle_inferior_event (struct execution_control_state * ecs); |
cd0fc7c3 | 1194 | |
104c1213 | 1195 | static void check_sigtramp2 (struct execution_control_state *ecs); |
c2c6d25f | 1196 | static void step_into_function (struct execution_control_state *ecs); |
d4f3574e | 1197 | static void step_over_function (struct execution_control_state *ecs); |
104c1213 JM |
1198 | static void stop_stepping (struct execution_control_state *ecs); |
1199 | static void prepare_to_wait (struct execution_control_state *ecs); | |
d4f3574e | 1200 | static void keep_going (struct execution_control_state *ecs); |
11cf8741 | 1201 | static void print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info); |
104c1213 | 1202 | |
cd0fc7c3 SS |
1203 | /* Wait for control to return from inferior to debugger. |
1204 | If inferior gets a signal, we may decide to start it up again | |
1205 | instead of returning. That is why there is a loop in this function. | |
1206 | When this function actually returns it means the inferior | |
1207 | should be left stopped and GDB should read more commands. */ | |
1208 | ||
1209 | void | |
96baa820 | 1210 | wait_for_inferior (void) |
cd0fc7c3 SS |
1211 | { |
1212 | struct cleanup *old_cleanups; | |
1213 | struct execution_control_state ecss; | |
1214 | struct execution_control_state *ecs; | |
c906108c | 1215 | |
8601f500 | 1216 | old_cleanups = make_cleanup (delete_step_resume_breakpoint, |
c906108c SS |
1217 | &step_resume_breakpoint); |
1218 | make_cleanup (delete_breakpoint_current_contents, | |
1219 | &through_sigtramp_breakpoint); | |
cd0fc7c3 SS |
1220 | |
1221 | /* wfi still stays in a loop, so it's OK just to take the address of | |
1222 | a local to get the ecs pointer. */ | |
1223 | ecs = &ecss; | |
1224 | ||
1225 | /* Fill in with reasonable starting values. */ | |
1226 | init_execution_control_state (ecs); | |
1227 | ||
c906108c | 1228 | /* We'll update this if & when we switch to a new thread. */ |
39f77062 | 1229 | previous_inferior_ptid = inferior_ptid; |
c906108c | 1230 | |
cd0fc7c3 SS |
1231 | overlay_cache_invalid = 1; |
1232 | ||
1233 | /* We have to invalidate the registers BEFORE calling target_wait | |
1234 | because they can be loaded from the target while in target_wait. | |
1235 | This makes remote debugging a bit more efficient for those | |
1236 | targets that provide critical registers as part of their normal | |
1237 | status mechanism. */ | |
1238 | ||
1239 | registers_changed (); | |
b83266a0 | 1240 | |
c906108c SS |
1241 | while (1) |
1242 | { | |
cd0fc7c3 | 1243 | if (target_wait_hook) |
39f77062 | 1244 | ecs->ptid = target_wait_hook (ecs->waiton_ptid, ecs->wp); |
cd0fc7c3 | 1245 | else |
39f77062 | 1246 | ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp); |
c906108c | 1247 | |
cd0fc7c3 SS |
1248 | /* Now figure out what to do with the result of the result. */ |
1249 | handle_inferior_event (ecs); | |
c906108c | 1250 | |
cd0fc7c3 SS |
1251 | if (!ecs->wait_some_more) |
1252 | break; | |
1253 | } | |
1254 | do_cleanups (old_cleanups); | |
1255 | } | |
c906108c | 1256 | |
43ff13b4 JM |
1257 | /* Asynchronous version of wait_for_inferior. It is called by the |
1258 | event loop whenever a change of state is detected on the file | |
1259 | descriptor corresponding to the target. It can be called more than | |
1260 | once to complete a single execution command. In such cases we need | |
1261 | to keep the state in a global variable ASYNC_ECSS. If it is the | |
1262 | last time that this function is called for a single execution | |
1263 | command, then report to the user that the inferior has stopped, and | |
1264 | do the necessary cleanups. */ | |
1265 | ||
1266 | struct execution_control_state async_ecss; | |
1267 | struct execution_control_state *async_ecs; | |
1268 | ||
1269 | void | |
fba45db2 | 1270 | fetch_inferior_event (void *client_data) |
43ff13b4 JM |
1271 | { |
1272 | static struct cleanup *old_cleanups; | |
1273 | ||
c5aa993b | 1274 | async_ecs = &async_ecss; |
43ff13b4 JM |
1275 | |
1276 | if (!async_ecs->wait_some_more) | |
1277 | { | |
8601f500 | 1278 | old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint, |
c5aa993b | 1279 | &step_resume_breakpoint); |
43ff13b4 | 1280 | make_exec_cleanup (delete_breakpoint_current_contents, |
c5aa993b | 1281 | &through_sigtramp_breakpoint); |
43ff13b4 JM |
1282 | |
1283 | /* Fill in with reasonable starting values. */ | |
1284 | init_execution_control_state (async_ecs); | |
1285 | ||
43ff13b4 | 1286 | /* We'll update this if & when we switch to a new thread. */ |
39f77062 | 1287 | previous_inferior_ptid = inferior_ptid; |
43ff13b4 JM |
1288 | |
1289 | overlay_cache_invalid = 1; | |
1290 | ||
1291 | /* We have to invalidate the registers BEFORE calling target_wait | |
c5aa993b JM |
1292 | because they can be loaded from the target while in target_wait. |
1293 | This makes remote debugging a bit more efficient for those | |
1294 | targets that provide critical registers as part of their normal | |
1295 | status mechanism. */ | |
43ff13b4 JM |
1296 | |
1297 | registers_changed (); | |
1298 | } | |
1299 | ||
1300 | if (target_wait_hook) | |
39f77062 | 1301 | async_ecs->ptid = target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp); |
43ff13b4 | 1302 | else |
39f77062 | 1303 | async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp); |
43ff13b4 JM |
1304 | |
1305 | /* Now figure out what to do with the result of the result. */ | |
1306 | handle_inferior_event (async_ecs); | |
1307 | ||
1308 | if (!async_ecs->wait_some_more) | |
1309 | { | |
adf40b2e JM |
1310 | /* Do only the cleanups that have been added by this |
1311 | function. Let the continuations for the commands do the rest, | |
1312 | if there are any. */ | |
43ff13b4 JM |
1313 | do_exec_cleanups (old_cleanups); |
1314 | normal_stop (); | |
c2d11a7d JM |
1315 | if (step_multi && stop_step) |
1316 | inferior_event_handler (INF_EXEC_CONTINUE, NULL); | |
1317 | else | |
1318 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); | |
43ff13b4 JM |
1319 | } |
1320 | } | |
1321 | ||
cd0fc7c3 SS |
1322 | /* Prepare an execution control state for looping through a |
1323 | wait_for_inferior-type loop. */ | |
1324 | ||
1325 | void | |
96baa820 | 1326 | init_execution_control_state (struct execution_control_state *ecs) |
cd0fc7c3 | 1327 | { |
c2d11a7d | 1328 | /* ecs->another_trap? */ |
cd0fc7c3 SS |
1329 | ecs->random_signal = 0; |
1330 | ecs->remove_breakpoints_on_following_step = 0; | |
1331 | ecs->handling_longjmp = 0; /* FIXME */ | |
1332 | ecs->update_step_sp = 0; | |
1333 | ecs->stepping_through_solib_after_catch = 0; | |
1334 | ecs->stepping_through_solib_catchpoints = NULL; | |
1335 | ecs->enable_hw_watchpoints_after_wait = 0; | |
1336 | ecs->stepping_through_sigtramp = 0; | |
1337 | ecs->sal = find_pc_line (prev_pc, 0); | |
1338 | ecs->current_line = ecs->sal.line; | |
1339 | ecs->current_symtab = ecs->sal.symtab; | |
1340 | ecs->infwait_state = infwait_normal_state; | |
39f77062 | 1341 | ecs->waiton_ptid = pid_to_ptid (-1); |
cd0fc7c3 SS |
1342 | ecs->wp = &(ecs->ws); |
1343 | } | |
1344 | ||
a0b3c4fd | 1345 | /* Call this function before setting step_resume_breakpoint, as a |
53a5351d JM |
1346 | sanity check. There should never be more than one step-resume |
1347 | breakpoint per thread, so we should never be setting a new | |
1348 | step_resume_breakpoint when one is already active. */ | |
a0b3c4fd | 1349 | static void |
96baa820 | 1350 | check_for_old_step_resume_breakpoint (void) |
a0b3c4fd JM |
1351 | { |
1352 | if (step_resume_breakpoint) | |
1353 | warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint"); | |
1354 | } | |
1355 | ||
e02bc4cc DS |
1356 | /* Return the cached copy of the last pid/waitstatus returned by |
1357 | target_wait()/target_wait_hook(). The data is actually cached by | |
1358 | handle_inferior_event(), which gets called immediately after | |
1359 | target_wait()/target_wait_hook(). */ | |
1360 | ||
1361 | void | |
39f77062 | 1362 | get_last_target_status(ptid_t *ptidp, struct target_waitstatus *status) |
e02bc4cc | 1363 | { |
39f77062 | 1364 | *ptidp = target_last_wait_ptid; |
e02bc4cc DS |
1365 | *status = target_last_waitstatus; |
1366 | } | |
1367 | ||
dd80620e MS |
1368 | /* Switch thread contexts, maintaining "infrun state". */ |
1369 | ||
1370 | static void | |
1371 | context_switch (struct execution_control_state *ecs) | |
1372 | { | |
1373 | /* Caution: it may happen that the new thread (or the old one!) | |
1374 | is not in the thread list. In this case we must not attempt | |
1375 | to "switch context", or we run the risk that our context may | |
1376 | be lost. This may happen as a result of the target module | |
1377 | mishandling thread creation. */ | |
1378 | ||
1379 | if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid)) | |
1380 | { /* Perform infrun state context switch: */ | |
1381 | /* Save infrun state for the old thread. */ | |
1382 | save_infrun_state (inferior_ptid, prev_pc, | |
1383 | prev_func_start, prev_func_name, | |
1384 | trap_expected, step_resume_breakpoint, | |
1385 | through_sigtramp_breakpoint, step_range_start, | |
1386 | step_range_end, step_frame_address, | |
1387 | ecs->handling_longjmp, ecs->another_trap, | |
1388 | ecs->stepping_through_solib_after_catch, | |
1389 | ecs->stepping_through_solib_catchpoints, | |
1390 | ecs->stepping_through_sigtramp, | |
1391 | ecs->current_line, ecs->current_symtab, | |
1392 | step_sp); | |
1393 | ||
1394 | /* Load infrun state for the new thread. */ | |
1395 | load_infrun_state (ecs->ptid, &prev_pc, | |
1396 | &prev_func_start, &prev_func_name, | |
1397 | &trap_expected, &step_resume_breakpoint, | |
1398 | &through_sigtramp_breakpoint, &step_range_start, | |
1399 | &step_range_end, &step_frame_address, | |
1400 | &ecs->handling_longjmp, &ecs->another_trap, | |
1401 | &ecs->stepping_through_solib_after_catch, | |
1402 | &ecs->stepping_through_solib_catchpoints, | |
1403 | &ecs->stepping_through_sigtramp, | |
1404 | &ecs->current_line, &ecs->current_symtab, | |
1405 | &step_sp); | |
1406 | } | |
1407 | inferior_ptid = ecs->ptid; | |
1408 | } | |
1409 | ||
1410 | ||
cd0fc7c3 SS |
1411 | /* Given an execution control state that has been freshly filled in |
1412 | by an event from the inferior, figure out what it means and take | |
1413 | appropriate action. */ | |
c906108c | 1414 | |
cd0fc7c3 | 1415 | void |
96baa820 | 1416 | handle_inferior_event (struct execution_control_state *ecs) |
cd0fc7c3 SS |
1417 | { |
1418 | CORE_ADDR tmp; | |
1419 | int stepped_after_stopped_by_watchpoint; | |
1420 | ||
e02bc4cc | 1421 | /* Cache the last pid/waitstatus. */ |
39f77062 | 1422 | target_last_wait_ptid = ecs->ptid; |
e02bc4cc DS |
1423 | target_last_waitstatus = *ecs->wp; |
1424 | ||
cd0fc7c3 SS |
1425 | /* Keep this extra brace for now, minimizes diffs. */ |
1426 | { | |
c5aa993b JM |
1427 | switch (ecs->infwait_state) |
1428 | { | |
dd80620e MS |
1429 | case infwait_thread_hop_state: |
1430 | /* Cancel the waiton_ptid. */ | |
1431 | ecs->waiton_ptid = pid_to_ptid (-1); | |
1432 | /* Fall thru to the normal_state case. */ | |
1433 | ||
c5aa993b | 1434 | case infwait_normal_state: |
c5aa993b JM |
1435 | /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event |
1436 | is serviced in this loop, below. */ | |
1437 | if (ecs->enable_hw_watchpoints_after_wait) | |
1438 | { | |
39f77062 | 1439 | TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid)); |
c5aa993b JM |
1440 | ecs->enable_hw_watchpoints_after_wait = 0; |
1441 | } | |
1442 | stepped_after_stopped_by_watchpoint = 0; | |
1443 | break; | |
b83266a0 | 1444 | |
c5aa993b JM |
1445 | case infwait_nullified_state: |
1446 | break; | |
b83266a0 | 1447 | |
c5aa993b JM |
1448 | case infwait_nonstep_watch_state: |
1449 | insert_breakpoints (); | |
b83266a0 | 1450 | |
c5aa993b JM |
1451 | /* FIXME-maybe: is this cleaner than setting a flag? Does it |
1452 | handle things like signals arriving and other things happening | |
1453 | in combination correctly? */ | |
1454 | stepped_after_stopped_by_watchpoint = 1; | |
1455 | break; | |
1456 | } | |
1457 | ecs->infwait_state = infwait_normal_state; | |
c906108c | 1458 | |
c5aa993b | 1459 | flush_cached_frames (); |
c906108c | 1460 | |
c5aa993b | 1461 | /* If it's a new process, add it to the thread database */ |
c906108c | 1462 | |
39f77062 KB |
1463 | ecs->new_thread_event = (! ptid_equal (ecs->ptid, inferior_ptid) |
1464 | && ! in_thread_list (ecs->ptid)); | |
c906108c | 1465 | |
c5aa993b JM |
1466 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED |
1467 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED | |
1468 | && ecs->new_thread_event) | |
1469 | { | |
39f77062 | 1470 | add_thread (ecs->ptid); |
c906108c | 1471 | |
8b93c638 | 1472 | ui_out_text (uiout, "[New "); |
39f77062 | 1473 | ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid)); |
8b93c638 | 1474 | ui_out_text (uiout, "]\n"); |
c906108c SS |
1475 | |
1476 | #if 0 | |
c5aa993b JM |
1477 | /* NOTE: This block is ONLY meant to be invoked in case of a |
1478 | "thread creation event"! If it is invoked for any other | |
1479 | sort of event (such as a new thread landing on a breakpoint), | |
1480 | the event will be discarded, which is almost certainly | |
1481 | a bad thing! | |
1482 | ||
1483 | To avoid this, the low-level module (eg. target_wait) | |
1484 | should call in_thread_list and add_thread, so that the | |
1485 | new thread is known by the time we get here. */ | |
1486 | ||
1487 | /* We may want to consider not doing a resume here in order | |
1488 | to give the user a chance to play with the new thread. | |
1489 | It might be good to make that a user-settable option. */ | |
1490 | ||
1491 | /* At this point, all threads are stopped (happens | |
1492 | automatically in either the OS or the native code). | |
1493 | Therefore we need to continue all threads in order to | |
1494 | make progress. */ | |
1495 | ||
39f77062 | 1496 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); |
104c1213 JM |
1497 | prepare_to_wait (ecs); |
1498 | return; | |
c906108c | 1499 | #endif |
c5aa993b | 1500 | } |
c906108c | 1501 | |
c5aa993b JM |
1502 | switch (ecs->ws.kind) |
1503 | { | |
1504 | case TARGET_WAITKIND_LOADED: | |
1505 | /* Ignore gracefully during startup of the inferior, as it | |
1506 | might be the shell which has just loaded some objects, | |
1507 | otherwise add the symbols for the newly loaded objects. */ | |
c906108c | 1508 | #ifdef SOLIB_ADD |
c5aa993b JM |
1509 | if (!stop_soon_quietly) |
1510 | { | |
1511 | /* Remove breakpoints, SOLIB_ADD might adjust | |
1512 | breakpoint addresses via breakpoint_re_set. */ | |
1513 | if (breakpoints_inserted) | |
1514 | remove_breakpoints (); | |
c906108c | 1515 | |
c5aa993b | 1516 | /* Check for any newly added shared libraries if we're |
990f9fe3 FF |
1517 | supposed to be adding them automatically. Switch |
1518 | terminal for any messages produced by | |
1519 | breakpoint_re_set. */ | |
1520 | target_terminal_ours_for_output (); | |
1521 | SOLIB_ADD (NULL, 0, NULL, auto_solib_add); | |
1522 | target_terminal_inferior (); | |
c906108c | 1523 | |
c5aa993b JM |
1524 | /* Reinsert breakpoints and continue. */ |
1525 | if (breakpoints_inserted) | |
1526 | insert_breakpoints (); | |
1527 | } | |
c906108c | 1528 | #endif |
c5aa993b | 1529 | resume (0, TARGET_SIGNAL_0); |
104c1213 JM |
1530 | prepare_to_wait (ecs); |
1531 | return; | |
c5aa993b JM |
1532 | |
1533 | case TARGET_WAITKIND_SPURIOUS: | |
1534 | resume (0, TARGET_SIGNAL_0); | |
104c1213 JM |
1535 | prepare_to_wait (ecs); |
1536 | return; | |
c5aa993b JM |
1537 | |
1538 | case TARGET_WAITKIND_EXITED: | |
1539 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
11cf8741 | 1540 | print_stop_reason (EXITED, ecs->ws.value.integer); |
c5aa993b JM |
1541 | |
1542 | /* Record the exit code in the convenience variable $_exitcode, so | |
1543 | that the user can inspect this again later. */ | |
1544 | set_internalvar (lookup_internalvar ("_exitcode"), | |
1545 | value_from_longest (builtin_type_int, | |
1546 | (LONGEST) ecs->ws.value.integer)); | |
1547 | gdb_flush (gdb_stdout); | |
1548 | target_mourn_inferior (); | |
b0ed3589 | 1549 | singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */ |
c5aa993b | 1550 | stop_print_frame = 0; |
104c1213 JM |
1551 | stop_stepping (ecs); |
1552 | return; | |
c5aa993b JM |
1553 | |
1554 | case TARGET_WAITKIND_SIGNALLED: | |
1555 | stop_print_frame = 0; | |
1556 | stop_signal = ecs->ws.value.sig; | |
1557 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
c5aa993b | 1558 | |
c7e79b4b ND |
1559 | /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't |
1560 | reach here unless the inferior is dead. However, for years | |
1561 | target_kill() was called here, which hints that fatal signals aren't | |
1562 | really fatal on some systems. If that's true, then some changes | |
1563 | may be needed. */ | |
1564 | target_mourn_inferior (); | |
c5aa993b | 1565 | |
11cf8741 | 1566 | print_stop_reason (SIGNAL_EXITED, stop_signal); |
b0ed3589 | 1567 | singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */ |
104c1213 JM |
1568 | stop_stepping (ecs); |
1569 | return; | |
c5aa993b JM |
1570 | |
1571 | /* The following are the only cases in which we keep going; | |
1572 | the above cases end in a continue or goto. */ | |
1573 | case TARGET_WAITKIND_FORKED: | |
1574 | stop_signal = TARGET_SIGNAL_TRAP; | |
1575 | pending_follow.kind = ecs->ws.kind; | |
1576 | ||
1577 | /* Ignore fork events reported for the parent; we're only | |
1578 | interested in reacting to forks of the child. Note that | |
1579 | we expect the child's fork event to be available if we | |
1580 | waited for it now. */ | |
39f77062 | 1581 | if (ptid_equal (inferior_ptid, ecs->ptid)) |
c5aa993b JM |
1582 | { |
1583 | pending_follow.fork_event.saw_parent_fork = 1; | |
39f77062 | 1584 | pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid); |
c5aa993b | 1585 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; |
104c1213 JM |
1586 | prepare_to_wait (ecs); |
1587 | return; | |
c5aa993b JM |
1588 | } |
1589 | else | |
1590 | { | |
1591 | pending_follow.fork_event.saw_child_fork = 1; | |
39f77062 | 1592 | pending_follow.fork_event.child_pid = PIDGET (ecs->ptid); |
c5aa993b JM |
1593 | pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid; |
1594 | } | |
c906108c | 1595 | |
39f77062 KB |
1596 | stop_pc = read_pc_pid (ecs->ptid); |
1597 | ecs->saved_inferior_ptid = inferior_ptid; | |
1598 | inferior_ptid = ecs->ptid; | |
80b34fab MS |
1599 | /* The second argument of bpstat_stop_status is meant to help |
1600 | distinguish between a breakpoint trap and a singlestep trap. | |
1601 | This is only important on targets where DECR_PC_AFTER_BREAK | |
1602 | is non-zero. The prev_pc test is meant to distinguish between | |
1603 | singlestepping a trap instruction, and singlestepping thru a | |
1604 | jump to the instruction following a trap instruction. */ | |
1605 | ||
1606 | stop_bpstat = bpstat_stop_status (&stop_pc, | |
1607 | currently_stepping (ecs) && | |
1608 | prev_pc != | |
1609 | stop_pc - DECR_PC_AFTER_BREAK); | |
c5aa993b | 1610 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
39f77062 | 1611 | inferior_ptid = ecs->saved_inferior_ptid; |
c5aa993b JM |
1612 | goto process_event_stop_test; |
1613 | ||
1614 | /* If this a platform which doesn't allow a debugger to touch a | |
1615 | vfork'd inferior until after it exec's, then we'd best keep | |
1616 | our fingers entirely off the inferior, other than continuing | |
1617 | it. This has the unfortunate side-effect that catchpoints | |
1618 | of vforks will be ignored. But since the platform doesn't | |
1619 | allow the inferior be touched at vfork time, there's really | |
1620 | little choice. */ | |
1621 | case TARGET_WAITKIND_VFORKED: | |
1622 | stop_signal = TARGET_SIGNAL_TRAP; | |
1623 | pending_follow.kind = ecs->ws.kind; | |
1624 | ||
1625 | /* Is this a vfork of the parent? If so, then give any | |
1626 | vfork catchpoints a chance to trigger now. (It's | |
1627 | dangerous to do so if the child canot be touched until | |
1628 | it execs, and the child has not yet exec'd. We probably | |
1629 | should warn the user to that effect when the catchpoint | |
1630 | triggers...) */ | |
39f77062 | 1631 | if (ptid_equal (ecs->ptid, inferior_ptid)) |
c5aa993b JM |
1632 | { |
1633 | pending_follow.fork_event.saw_parent_fork = 1; | |
39f77062 | 1634 | pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid); |
c5aa993b JM |
1635 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; |
1636 | } | |
c906108c | 1637 | |
c5aa993b JM |
1638 | /* If we've seen the child's vfork event but cannot really touch |
1639 | the child until it execs, then we must continue the child now. | |
1640 | Else, give any vfork catchpoints a chance to trigger now. */ | |
1641 | else | |
1642 | { | |
1643 | pending_follow.fork_event.saw_child_fork = 1; | |
39f77062 | 1644 | pending_follow.fork_event.child_pid = PIDGET (ecs->ptid); |
c5aa993b | 1645 | pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid; |
39f77062 KB |
1646 | target_post_startup_inferior ( |
1647 | pid_to_ptid (pending_follow.fork_event.child_pid)); | |
c5aa993b JM |
1648 | follow_vfork_when_exec = !target_can_follow_vfork_prior_to_exec (); |
1649 | if (follow_vfork_when_exec) | |
1650 | { | |
39f77062 | 1651 | target_resume (ecs->ptid, 0, TARGET_SIGNAL_0); |
104c1213 JM |
1652 | prepare_to_wait (ecs); |
1653 | return; | |
c5aa993b JM |
1654 | } |
1655 | } | |
c906108c | 1656 | |
c5aa993b | 1657 | stop_pc = read_pc (); |
80b34fab MS |
1658 | /* The second argument of bpstat_stop_status is meant to help |
1659 | distinguish between a breakpoint trap and a singlestep trap. | |
1660 | This is only important on targets where DECR_PC_AFTER_BREAK | |
1661 | is non-zero. The prev_pc test is meant to distinguish between | |
1662 | singlestepping a trap instruction, and singlestepping thru a | |
1663 | jump to the instruction following a trap instruction. */ | |
1664 | ||
1665 | stop_bpstat = bpstat_stop_status (&stop_pc, | |
1666 | currently_stepping (ecs) && | |
1667 | prev_pc != | |
1668 | stop_pc - DECR_PC_AFTER_BREAK); | |
c5aa993b JM |
1669 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
1670 | goto process_event_stop_test; | |
1671 | ||
1672 | case TARGET_WAITKIND_EXECD: | |
1673 | stop_signal = TARGET_SIGNAL_TRAP; | |
1674 | ||
1675 | /* Is this a target which reports multiple exec events per actual | |
1676 | call to exec()? (HP-UX using ptrace does, for example.) If so, | |
1677 | ignore all but the last one. Just resume the exec'r, and wait | |
1678 | for the next exec event. */ | |
1679 | if (inferior_ignoring_leading_exec_events) | |
1680 | { | |
1681 | inferior_ignoring_leading_exec_events--; | |
1682 | if (pending_follow.kind == TARGET_WAITKIND_VFORKED) | |
1683 | ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.parent_pid); | |
39f77062 | 1684 | target_resume (ecs->ptid, 0, TARGET_SIGNAL_0); |
104c1213 JM |
1685 | prepare_to_wait (ecs); |
1686 | return; | |
c5aa993b JM |
1687 | } |
1688 | inferior_ignoring_leading_exec_events = | |
1689 | target_reported_exec_events_per_exec_call () - 1; | |
c906108c | 1690 | |
96baa820 JM |
1691 | pending_follow.execd_pathname = |
1692 | savestring (ecs->ws.value.execd_pathname, | |
1693 | strlen (ecs->ws.value.execd_pathname)); | |
c906108c | 1694 | |
39f77062 | 1695 | /* Did inferior_ptid exec, or did a (possibly not-yet-followed) |
c5aa993b | 1696 | child of a vfork exec? |
c906108c | 1697 | |
c5aa993b JM |
1698 | ??rehrauer: This is unabashedly an HP-UX specific thing. On |
1699 | HP-UX, events associated with a vforking inferior come in | |
1700 | threes: a vfork event for the child (always first), followed | |
1701 | a vfork event for the parent and an exec event for the child. | |
1702 | The latter two can come in either order. | |
c906108c | 1703 | |
c5aa993b JM |
1704 | If we get the parent vfork event first, life's good: We follow |
1705 | either the parent or child, and then the child's exec event is | |
1706 | a "don't care". | |
c906108c | 1707 | |
c5aa993b JM |
1708 | But if we get the child's exec event first, then we delay |
1709 | responding to it until we handle the parent's vfork. Because, | |
1710 | otherwise we can't satisfy a "catch vfork". */ | |
1711 | if (pending_follow.kind == TARGET_WAITKIND_VFORKED) | |
1712 | { | |
1713 | pending_follow.fork_event.saw_child_exec = 1; | |
1714 | ||
1715 | /* On some targets, the child must be resumed before | |
1716 | the parent vfork event is delivered. A single-step | |
1717 | suffices. */ | |
1718 | if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ()) | |
39f77062 | 1719 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); |
c5aa993b | 1720 | /* We expect the parent vfork event to be available now. */ |
104c1213 JM |
1721 | prepare_to_wait (ecs); |
1722 | return; | |
c5aa993b | 1723 | } |
c906108c | 1724 | |
c5aa993b JM |
1725 | /* This causes the eventpoints and symbol table to be reset. Must |
1726 | do this now, before trying to determine whether to stop. */ | |
39f77062 | 1727 | follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname); |
b8c9b27d | 1728 | xfree (pending_follow.execd_pathname); |
c5aa993b | 1729 | |
39f77062 KB |
1730 | stop_pc = read_pc_pid (ecs->ptid); |
1731 | ecs->saved_inferior_ptid = inferior_ptid; | |
1732 | inferior_ptid = ecs->ptid; | |
80b34fab MS |
1733 | /* The second argument of bpstat_stop_status is meant to help |
1734 | distinguish between a breakpoint trap and a singlestep trap. | |
1735 | This is only important on targets where DECR_PC_AFTER_BREAK | |
1736 | is non-zero. The prev_pc test is meant to distinguish between | |
1737 | singlestepping a trap instruction, and singlestepping thru a | |
1738 | jump to the instruction following a trap instruction. */ | |
1739 | ||
1740 | stop_bpstat = bpstat_stop_status (&stop_pc, | |
1741 | currently_stepping (ecs) && | |
1742 | prev_pc != | |
1743 | stop_pc - DECR_PC_AFTER_BREAK); | |
c5aa993b | 1744 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
39f77062 | 1745 | inferior_ptid = ecs->saved_inferior_ptid; |
c5aa993b JM |
1746 | goto process_event_stop_test; |
1747 | ||
1748 | /* These syscall events are returned on HP-UX, as part of its | |
1749 | implementation of page-protection-based "hardware" watchpoints. | |
1750 | HP-UX has unfortunate interactions between page-protections and | |
1751 | some system calls. Our solution is to disable hardware watches | |
1752 | when a system call is entered, and reenable them when the syscall | |
1753 | completes. The downside of this is that we may miss the precise | |
1754 | point at which a watched piece of memory is modified. "Oh well." | |
1755 | ||
1756 | Note that we may have multiple threads running, which may each | |
1757 | enter syscalls at roughly the same time. Since we don't have a | |
1758 | good notion currently of whether a watched piece of memory is | |
1759 | thread-private, we'd best not have any page-protections active | |
1760 | when any thread is in a syscall. Thus, we only want to reenable | |
1761 | hardware watches when no threads are in a syscall. | |
1762 | ||
1763 | Also, be careful not to try to gather much state about a thread | |
1764 | that's in a syscall. It's frequently a losing proposition. */ | |
1765 | case TARGET_WAITKIND_SYSCALL_ENTRY: | |
1766 | number_of_threads_in_syscalls++; | |
1767 | if (number_of_threads_in_syscalls == 1) | |
1768 | { | |
39f77062 | 1769 | TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid)); |
c5aa993b JM |
1770 | } |
1771 | resume (0, TARGET_SIGNAL_0); | |
104c1213 JM |
1772 | prepare_to_wait (ecs); |
1773 | return; | |
c906108c | 1774 | |
c5aa993b | 1775 | /* Before examining the threads further, step this thread to |
c906108c SS |
1776 | get it entirely out of the syscall. (We get notice of the |
1777 | event when the thread is just on the verge of exiting a | |
1778 | syscall. Stepping one instruction seems to get it back | |
1779 | into user code.) | |
1780 | ||
1781 | Note that although the logical place to reenable h/w watches | |
1782 | is here, we cannot. We cannot reenable them before stepping | |
1783 | the thread (this causes the next wait on the thread to hang). | |
1784 | ||
1785 | Nor can we enable them after stepping until we've done a wait. | |
cd0fc7c3 | 1786 | Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait |
c906108c SS |
1787 | here, which will be serviced immediately after the target |
1788 | is waited on. */ | |
c5aa993b | 1789 | case TARGET_WAITKIND_SYSCALL_RETURN: |
39f77062 | 1790 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); |
c906108c | 1791 | |
c5aa993b JM |
1792 | if (number_of_threads_in_syscalls > 0) |
1793 | { | |
1794 | number_of_threads_in_syscalls--; | |
1795 | ecs->enable_hw_watchpoints_after_wait = | |
1796 | (number_of_threads_in_syscalls == 0); | |
1797 | } | |
104c1213 JM |
1798 | prepare_to_wait (ecs); |
1799 | return; | |
c906108c | 1800 | |
c5aa993b JM |
1801 | case TARGET_WAITKIND_STOPPED: |
1802 | stop_signal = ecs->ws.value.sig; | |
1803 | break; | |
c4093a6a JM |
1804 | |
1805 | /* We had an event in the inferior, but we are not interested | |
1806 | in handling it at this level. The lower layers have already | |
1807 | done what needs to be done, if anything. This case can | |
1808 | occur only when the target is async or extended-async. One | |
1809 | of the circumstamces for this to happen is when the | |
1810 | inferior produces output for the console. The inferior has | |
1811 | not stopped, and we are ignoring the event. */ | |
1812 | case TARGET_WAITKIND_IGNORE: | |
1813 | ecs->wait_some_more = 1; | |
1814 | return; | |
c5aa993b | 1815 | } |
c906108c | 1816 | |
c5aa993b JM |
1817 | /* We may want to consider not doing a resume here in order to give |
1818 | the user a chance to play with the new thread. It might be good | |
1819 | to make that a user-settable option. */ | |
c906108c | 1820 | |
c5aa993b JM |
1821 | /* At this point, all threads are stopped (happens automatically in |
1822 | either the OS or the native code). Therefore we need to continue | |
1823 | all threads in order to make progress. */ | |
1824 | if (ecs->new_thread_event) | |
1825 | { | |
39f77062 | 1826 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); |
104c1213 JM |
1827 | prepare_to_wait (ecs); |
1828 | return; | |
c5aa993b | 1829 | } |
c906108c | 1830 | |
39f77062 | 1831 | stop_pc = read_pc_pid (ecs->ptid); |
c906108c | 1832 | |
c5aa993b JM |
1833 | /* See if a thread hit a thread-specific breakpoint that was meant for |
1834 | another thread. If so, then step that thread past the breakpoint, | |
1835 | and continue it. */ | |
c906108c | 1836 | |
c5aa993b JM |
1837 | if (stop_signal == TARGET_SIGNAL_TRAP) |
1838 | { | |
b0ed3589 | 1839 | if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) |
c5aa993b JM |
1840 | ecs->random_signal = 0; |
1841 | else if (breakpoints_inserted | |
1842 | && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK)) | |
1843 | { | |
cd0fc7c3 | 1844 | ecs->random_signal = 0; |
c5aa993b | 1845 | if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, |
39f77062 | 1846 | ecs->ptid)) |
c5aa993b JM |
1847 | { |
1848 | int remove_status; | |
1849 | ||
1850 | /* Saw a breakpoint, but it was hit by the wrong thread. | |
1851 | Just continue. */ | |
80b34fab MS |
1852 | if (DECR_PC_AFTER_BREAK) |
1853 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->ptid); | |
c5aa993b JM |
1854 | |
1855 | remove_status = remove_breakpoints (); | |
1856 | /* Did we fail to remove breakpoints? If so, try | |
1857 | to set the PC past the bp. (There's at least | |
1858 | one situation in which we can fail to remove | |
1859 | the bp's: On HP-UX's that use ttrace, we can't | |
1860 | change the address space of a vforking child | |
1861 | process until the child exits (well, okay, not | |
1862 | then either :-) or execs. */ | |
1863 | if (remove_status != 0) | |
1864 | { | |
80b34fab MS |
1865 | /* FIXME! This is obviously non-portable! */ |
1866 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, | |
1867 | ecs->ptid); | |
c6ad9598 MS |
1868 | /* We need to restart all the threads now, |
1869 | * unles we're running in scheduler-locked mode. | |
1870 | * Use currently_stepping to determine whether to | |
1871 | * step or continue. | |
1872 | */ | |
dd80620e | 1873 | /* FIXME MVS: is there any reason not to call resume()? */ |
c6ad9598 MS |
1874 | if (scheduler_mode == schedlock_on) |
1875 | target_resume (ecs->ptid, | |
1876 | currently_stepping (ecs), | |
1877 | TARGET_SIGNAL_0); | |
1878 | else | |
1879 | target_resume (RESUME_ALL, | |
1880 | currently_stepping (ecs), | |
1881 | TARGET_SIGNAL_0); | |
1882 | prepare_to_wait (ecs); | |
1883 | return; | |
c5aa993b JM |
1884 | } |
1885 | else | |
1886 | { /* Single step */ | |
dd80620e MS |
1887 | breakpoints_inserted = 0; |
1888 | if (!ptid_equal (inferior_ptid, ecs->ptid)) | |
1889 | context_switch (ecs); | |
39f77062 | 1890 | ecs->waiton_ptid = ecs->ptid; |
c5aa993b | 1891 | ecs->wp = &(ecs->ws); |
dd80620e MS |
1892 | ecs->another_trap = 1; |
1893 | ||
c5aa993b | 1894 | ecs->infwait_state = infwait_thread_hop_state; |
dd80620e MS |
1895 | keep_going (ecs); |
1896 | registers_changed (); | |
104c1213 | 1897 | return; |
c5aa993b | 1898 | } |
c5aa993b | 1899 | } |
c5aa993b JM |
1900 | } |
1901 | } | |
1902 | else | |
1903 | ecs->random_signal = 1; | |
1904 | ||
1905 | /* See if something interesting happened to the non-current thread. If | |
1906 | so, then switch to that thread, and eventually give control back to | |
1907 | the user. | |
1908 | ||
1909 | Note that if there's any kind of pending follow (i.e., of a fork, | |
1910 | vfork or exec), we don't want to do this now. Rather, we'll let | |
1911 | the next resume handle it. */ | |
39f77062 | 1912 | if (! ptid_equal (ecs->ptid, inferior_ptid) && |
c5aa993b JM |
1913 | (pending_follow.kind == TARGET_WAITKIND_SPURIOUS)) |
1914 | { | |
1915 | int printed = 0; | |
c906108c | 1916 | |
c5aa993b JM |
1917 | /* If it's a random signal for a non-current thread, notify user |
1918 | if he's expressed an interest. */ | |
1919 | if (ecs->random_signal | |
1920 | && signal_print[stop_signal]) | |
1921 | { | |
c906108c SS |
1922 | /* ??rehrauer: I don't understand the rationale for this code. If the |
1923 | inferior will stop as a result of this signal, then the act of handling | |
1924 | the stop ought to print a message that's couches the stoppage in user | |
1925 | terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior | |
1926 | won't stop as a result of the signal -- i.e., if the signal is merely | |
1927 | a side-effect of something GDB's doing "under the covers" for the | |
1928 | user, such as stepping threads over a breakpoint they shouldn't stop | |
1929 | for -- then the message seems to be a serious annoyance at best. | |
1930 | ||
1931 | For now, remove the message altogether. */ | |
1932 | #if 0 | |
c5aa993b JM |
1933 | printed = 1; |
1934 | target_terminal_ours_for_output (); | |
1935 | printf_filtered ("\nProgram received signal %s, %s.\n", | |
1936 | target_signal_to_name (stop_signal), | |
1937 | target_signal_to_string (stop_signal)); | |
1938 | gdb_flush (gdb_stdout); | |
c906108c | 1939 | #endif |
c5aa993b | 1940 | } |
c906108c | 1941 | |
c5aa993b JM |
1942 | /* If it's not SIGTRAP and not a signal we want to stop for, then |
1943 | continue the thread. */ | |
c906108c | 1944 | |
c5aa993b JM |
1945 | if (stop_signal != TARGET_SIGNAL_TRAP |
1946 | && !signal_stop[stop_signal]) | |
1947 | { | |
1948 | if (printed) | |
1949 | target_terminal_inferior (); | |
c906108c | 1950 | |
c5aa993b JM |
1951 | /* Clear the signal if it should not be passed. */ |
1952 | if (signal_program[stop_signal] == 0) | |
1953 | stop_signal = TARGET_SIGNAL_0; | |
c906108c | 1954 | |
39f77062 | 1955 | target_resume (ecs->ptid, 0, stop_signal); |
104c1213 JM |
1956 | prepare_to_wait (ecs); |
1957 | return; | |
c5aa993b | 1958 | } |
c906108c | 1959 | |
c5aa993b JM |
1960 | /* It's a SIGTRAP or a signal we're interested in. Switch threads, |
1961 | and fall into the rest of wait_for_inferior(). */ | |
1962 | ||
dd80620e | 1963 | context_switch (ecs); |
c5aa993b | 1964 | |
c5aa993b | 1965 | if (context_hook) |
39f77062 | 1966 | context_hook (pid_to_thread_id (ecs->ptid)); |
c5aa993b | 1967 | |
c5aa993b JM |
1968 | flush_cached_frames (); |
1969 | } | |
c906108c | 1970 | |
b0ed3589 | 1971 | if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) |
c5aa993b JM |
1972 | { |
1973 | /* Pull the single step breakpoints out of the target. */ | |
1974 | SOFTWARE_SINGLE_STEP (0, 0); | |
1975 | singlestep_breakpoints_inserted_p = 0; | |
1976 | } | |
c906108c | 1977 | |
c5aa993b JM |
1978 | /* If PC is pointing at a nullified instruction, then step beyond |
1979 | it so that the user won't be confused when GDB appears to be ready | |
1980 | to execute it. */ | |
c906108c | 1981 | |
c5aa993b JM |
1982 | /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */ |
1983 | if (INSTRUCTION_NULLIFIED) | |
1984 | { | |
1985 | registers_changed (); | |
39f77062 | 1986 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); |
c906108c | 1987 | |
c5aa993b JM |
1988 | /* We may have received a signal that we want to pass to |
1989 | the inferior; therefore, we must not clobber the waitstatus | |
1990 | in WS. */ | |
c906108c | 1991 | |
c5aa993b | 1992 | ecs->infwait_state = infwait_nullified_state; |
39f77062 | 1993 | ecs->waiton_ptid = ecs->ptid; |
c5aa993b | 1994 | ecs->wp = &(ecs->tmpstatus); |
104c1213 JM |
1995 | prepare_to_wait (ecs); |
1996 | return; | |
c5aa993b | 1997 | } |
c906108c | 1998 | |
c5aa993b JM |
1999 | /* It may not be necessary to disable the watchpoint to stop over |
2000 | it. For example, the PA can (with some kernel cooperation) | |
2001 | single step over a watchpoint without disabling the watchpoint. */ | |
2002 | if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) | |
2003 | { | |
2004 | resume (1, 0); | |
104c1213 JM |
2005 | prepare_to_wait (ecs); |
2006 | return; | |
c5aa993b | 2007 | } |
c906108c | 2008 | |
c5aa993b JM |
2009 | /* It is far more common to need to disable a watchpoint to step |
2010 | the inferior over it. FIXME. What else might a debug | |
2011 | register or page protection watchpoint scheme need here? */ | |
2012 | if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) | |
2013 | { | |
2014 | /* At this point, we are stopped at an instruction which has | |
2015 | attempted to write to a piece of memory under control of | |
2016 | a watchpoint. The instruction hasn't actually executed | |
2017 | yet. If we were to evaluate the watchpoint expression | |
2018 | now, we would get the old value, and therefore no change | |
2019 | would seem to have occurred. | |
2020 | ||
2021 | In order to make watchpoints work `right', we really need | |
2022 | to complete the memory write, and then evaluate the | |
2023 | watchpoint expression. The following code does that by | |
2024 | removing the watchpoint (actually, all watchpoints and | |
2025 | breakpoints), single-stepping the target, re-inserting | |
2026 | watchpoints, and then falling through to let normal | |
2027 | single-step processing handle proceed. Since this | |
2028 | includes evaluating watchpoints, things will come to a | |
2029 | stop in the correct manner. */ | |
2030 | ||
80b34fab MS |
2031 | if (DECR_PC_AFTER_BREAK) |
2032 | write_pc (stop_pc - DECR_PC_AFTER_BREAK); | |
c5aa993b JM |
2033 | |
2034 | remove_breakpoints (); | |
2035 | registers_changed (); | |
39f77062 | 2036 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */ |
c5aa993b | 2037 | |
39f77062 | 2038 | ecs->waiton_ptid = ecs->ptid; |
c5aa993b JM |
2039 | ecs->wp = &(ecs->ws); |
2040 | ecs->infwait_state = infwait_nonstep_watch_state; | |
104c1213 JM |
2041 | prepare_to_wait (ecs); |
2042 | return; | |
c5aa993b | 2043 | } |
c906108c | 2044 | |
c5aa993b JM |
2045 | /* It may be possible to simply continue after a watchpoint. */ |
2046 | if (HAVE_CONTINUABLE_WATCHPOINT) | |
2047 | STOPPED_BY_WATCHPOINT (ecs->ws); | |
2048 | ||
2049 | ecs->stop_func_start = 0; | |
2050 | ecs->stop_func_end = 0; | |
2051 | ecs->stop_func_name = 0; | |
2052 | /* Don't care about return value; stop_func_start and stop_func_name | |
2053 | will both be 0 if it doesn't work. */ | |
2054 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
2055 | &ecs->stop_func_start, &ecs->stop_func_end); | |
2056 | ecs->stop_func_start += FUNCTION_START_OFFSET; | |
2057 | ecs->another_trap = 0; | |
2058 | bpstat_clear (&stop_bpstat); | |
2059 | stop_step = 0; | |
2060 | stop_stack_dummy = 0; | |
2061 | stop_print_frame = 1; | |
2062 | ecs->random_signal = 0; | |
2063 | stopped_by_random_signal = 0; | |
2064 | breakpoints_failed = 0; | |
2065 | ||
2066 | /* Look at the cause of the stop, and decide what to do. | |
2067 | The alternatives are: | |
2068 | 1) break; to really stop and return to the debugger, | |
2069 | 2) drop through to start up again | |
2070 | (set ecs->another_trap to 1 to single step once) | |
2071 | 3) set ecs->random_signal to 1, and the decision between 1 and 2 | |
2072 | will be made according to the signal handling tables. */ | |
2073 | ||
2074 | /* First, distinguish signals caused by the debugger from signals | |
2075 | that have to do with the program's own actions. | |
2076 | Note that breakpoint insns may cause SIGTRAP or SIGILL | |
2077 | or SIGEMT, depending on the operating system version. | |
2078 | Here we detect when a SIGILL or SIGEMT is really a breakpoint | |
2079 | and change it to SIGTRAP. */ | |
2080 | ||
2081 | if (stop_signal == TARGET_SIGNAL_TRAP | |
2082 | || (breakpoints_inserted && | |
2083 | (stop_signal == TARGET_SIGNAL_ILL | |
2084 | || stop_signal == TARGET_SIGNAL_EMT | |
2085 | )) | |
2086 | || stop_soon_quietly) | |
2087 | { | |
2088 | if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) | |
2089 | { | |
2090 | stop_print_frame = 0; | |
104c1213 JM |
2091 | stop_stepping (ecs); |
2092 | return; | |
c5aa993b JM |
2093 | } |
2094 | if (stop_soon_quietly) | |
104c1213 JM |
2095 | { |
2096 | stop_stepping (ecs); | |
2097 | return; | |
2098 | } | |
c906108c | 2099 | |
c5aa993b JM |
2100 | /* Don't even think about breakpoints |
2101 | if just proceeded over a breakpoint. | |
c906108c | 2102 | |
c5aa993b JM |
2103 | However, if we are trying to proceed over a breakpoint |
2104 | and end up in sigtramp, then through_sigtramp_breakpoint | |
2105 | will be set and we should check whether we've hit the | |
2106 | step breakpoint. */ | |
2107 | if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected | |
2108 | && through_sigtramp_breakpoint == NULL) | |
2109 | bpstat_clear (&stop_bpstat); | |
2110 | else | |
2111 | { | |
2112 | /* See if there is a breakpoint at the current PC. */ | |
80b34fab MS |
2113 | |
2114 | /* The second argument of bpstat_stop_status is meant to help | |
2115 | distinguish between a breakpoint trap and a singlestep trap. | |
2116 | This is only important on targets where DECR_PC_AFTER_BREAK | |
2117 | is non-zero. The prev_pc test is meant to distinguish between | |
2118 | singlestepping a trap instruction, and singlestepping thru a | |
2119 | jump to the instruction following a trap instruction. */ | |
2120 | ||
c5aa993b JM |
2121 | stop_bpstat = bpstat_stop_status |
2122 | (&stop_pc, | |
6426a772 JM |
2123 | /* Pass TRUE if our reason for stopping is something other |
2124 | than hitting a breakpoint. We do this by checking that | |
2125 | 1) stepping is going on and 2) we didn't hit a breakpoint | |
2126 | in a signal handler without an intervening stop in | |
2127 | sigtramp, which is detected by a new stack pointer value | |
2128 | below any usual function calling stack adjustments. */ | |
c5aa993b | 2129 | (currently_stepping (ecs) |
80b34fab | 2130 | && prev_pc != stop_pc - DECR_PC_AFTER_BREAK |
c5aa993b | 2131 | && !(step_range_end |
6426a772 | 2132 | && INNER_THAN (read_sp (), (step_sp - 16)))) |
c5aa993b JM |
2133 | ); |
2134 | /* Following in case break condition called a | |
2135 | function. */ | |
2136 | stop_print_frame = 1; | |
2137 | } | |
c906108c | 2138 | |
c5aa993b JM |
2139 | if (stop_signal == TARGET_SIGNAL_TRAP) |
2140 | ecs->random_signal | |
2141 | = !(bpstat_explains_signal (stop_bpstat) | |
2142 | || trap_expected | |
2143 | || (!CALL_DUMMY_BREAKPOINT_OFFSET_P | |
2144 | && PC_IN_CALL_DUMMY (stop_pc, read_sp (), | |
2145 | FRAME_FP (get_current_frame ()))) | |
2146 | || (step_range_end && step_resume_breakpoint == NULL)); | |
2147 | ||
2148 | else | |
2149 | { | |
cd0fc7c3 | 2150 | ecs->random_signal |
c906108c | 2151 | = !(bpstat_explains_signal (stop_bpstat) |
c5aa993b JM |
2152 | /* End of a stack dummy. Some systems (e.g. Sony |
2153 | news) give another signal besides SIGTRAP, so | |
2154 | check here as well as above. */ | |
7a292a7a SS |
2155 | || (!CALL_DUMMY_BREAKPOINT_OFFSET_P |
2156 | && PC_IN_CALL_DUMMY (stop_pc, read_sp (), | |
2157 | FRAME_FP (get_current_frame ()))) | |
c5aa993b JM |
2158 | ); |
2159 | if (!ecs->random_signal) | |
2160 | stop_signal = TARGET_SIGNAL_TRAP; | |
2161 | } | |
2162 | } | |
c906108c | 2163 | |
c5aa993b JM |
2164 | /* When we reach this point, we've pretty much decided |
2165 | that the reason for stopping must've been a random | |
2166 | (unexpected) signal. */ | |
2167 | ||
2168 | else | |
2169 | ecs->random_signal = 1; | |
2170 | /* If a fork, vfork or exec event was seen, then there are two | |
2171 | possible responses we can make: | |
2172 | ||
2173 | 1. If a catchpoint triggers for the event (ecs->random_signal == 0), | |
2174 | then we must stop now and issue a prompt. We will resume | |
2175 | the inferior when the user tells us to. | |
2176 | 2. If no catchpoint triggers for the event (ecs->random_signal == 1), | |
2177 | then we must resume the inferior now and keep checking. | |
2178 | ||
2179 | In either case, we must take appropriate steps to "follow" the | |
2180 | the fork/vfork/exec when the inferior is resumed. For example, | |
2181 | if follow-fork-mode is "child", then we must detach from the | |
2182 | parent inferior and follow the new child inferior. | |
2183 | ||
2184 | In either case, setting pending_follow causes the next resume() | |
2185 | to take the appropriate following action. */ | |
2186 | process_event_stop_test: | |
2187 | if (ecs->ws.kind == TARGET_WAITKIND_FORKED) | |
2188 | { | |
2189 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ | |
2190 | { | |
2191 | trap_expected = 1; | |
2192 | stop_signal = TARGET_SIGNAL_0; | |
d4f3574e SS |
2193 | keep_going (ecs); |
2194 | return; | |
c5aa993b JM |
2195 | } |
2196 | } | |
2197 | else if (ecs->ws.kind == TARGET_WAITKIND_VFORKED) | |
2198 | { | |
2199 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ | |
2200 | { | |
d4f3574e SS |
2201 | stop_signal = TARGET_SIGNAL_0; |
2202 | keep_going (ecs); | |
2203 | return; | |
c5aa993b JM |
2204 | } |
2205 | } | |
2206 | else if (ecs->ws.kind == TARGET_WAITKIND_EXECD) | |
2207 | { | |
2208 | pending_follow.kind = ecs->ws.kind; | |
2209 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ | |
2210 | { | |
2211 | trap_expected = 1; | |
2212 | stop_signal = TARGET_SIGNAL_0; | |
d4f3574e SS |
2213 | keep_going (ecs); |
2214 | return; | |
c5aa993b JM |
2215 | } |
2216 | } | |
c906108c | 2217 | |
c5aa993b JM |
2218 | /* For the program's own signals, act according to |
2219 | the signal handling tables. */ | |
c906108c | 2220 | |
c5aa993b JM |
2221 | if (ecs->random_signal) |
2222 | { | |
2223 | /* Signal not for debugging purposes. */ | |
2224 | int printed = 0; | |
2225 | ||
2226 | stopped_by_random_signal = 1; | |
2227 | ||
2228 | if (signal_print[stop_signal]) | |
2229 | { | |
2230 | printed = 1; | |
2231 | target_terminal_ours_for_output (); | |
11cf8741 | 2232 | print_stop_reason (SIGNAL_RECEIVED, stop_signal); |
c5aa993b JM |
2233 | } |
2234 | if (signal_stop[stop_signal]) | |
104c1213 JM |
2235 | { |
2236 | stop_stepping (ecs); | |
2237 | return; | |
2238 | } | |
c5aa993b JM |
2239 | /* If not going to stop, give terminal back |
2240 | if we took it away. */ | |
2241 | else if (printed) | |
2242 | target_terminal_inferior (); | |
2243 | ||
2244 | /* Clear the signal if it should not be passed. */ | |
2245 | if (signal_program[stop_signal] == 0) | |
2246 | stop_signal = TARGET_SIGNAL_0; | |
2247 | ||
a0b3c4fd JM |
2248 | /* I'm not sure whether this needs to be check_sigtramp2 or |
2249 | whether it could/should be keep_going. | |
2250 | ||
2251 | This used to jump to step_over_function if we are stepping, | |
2252 | which is wrong. | |
2253 | ||
2254 | Suppose the user does a `next' over a function call, and while | |
2255 | that call is in progress, the inferior receives a signal for | |
2256 | which GDB does not stop (i.e., signal_stop[SIG] is false). In | |
2257 | that case, when we reach this point, there is already a | |
2258 | step-resume breakpoint established, right where it should be: | |
2259 | immediately after the function call the user is "next"-ing | |
d4f3574e | 2260 | over. If we call step_over_function now, two bad things |
a0b3c4fd JM |
2261 | happen: |
2262 | ||
2263 | - we'll create a new breakpoint, at wherever the current | |
2264 | frame's return address happens to be. That could be | |
2265 | anywhere, depending on what function call happens to be on | |
2266 | the top of the stack at that point. Point is, it's probably | |
2267 | not where we need it. | |
2268 | ||
2269 | - the existing step-resume breakpoint (which is at the correct | |
2270 | address) will get orphaned: step_resume_breakpoint will point | |
2271 | to the new breakpoint, and the old step-resume breakpoint | |
2272 | will never be cleaned up. | |
2273 | ||
2274 | The old behavior was meant to help HP-UX single-step out of | |
2275 | sigtramps. It would place the new breakpoint at prev_pc, which | |
2276 | was certainly wrong. I don't know the details there, so fixing | |
2277 | this probably breaks that. As with anything else, it's up to | |
2278 | the HP-UX maintainer to furnish a fix that doesn't break other | |
2279 | platforms. --JimB, 20 May 1999 */ | |
104c1213 | 2280 | check_sigtramp2 (ecs); |
e441088d MK |
2281 | keep_going (ecs); |
2282 | return; | |
c5aa993b JM |
2283 | } |
2284 | ||
2285 | /* Handle cases caused by hitting a breakpoint. */ | |
2286 | { | |
2287 | CORE_ADDR jmp_buf_pc; | |
2288 | struct bpstat_what what; | |
2289 | ||
2290 | what = bpstat_what (stop_bpstat); | |
2291 | ||
2292 | if (what.call_dummy) | |
c906108c | 2293 | { |
c5aa993b JM |
2294 | stop_stack_dummy = 1; |
2295 | #ifdef HP_OS_BUG | |
2296 | trap_expected_after_continue = 1; | |
2297 | #endif | |
c906108c | 2298 | } |
c5aa993b JM |
2299 | |
2300 | switch (what.main_action) | |
c906108c | 2301 | { |
c5aa993b JM |
2302 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: |
2303 | /* If we hit the breakpoint at longjmp, disable it for the | |
2304 | duration of this command. Then, install a temporary | |
2305 | breakpoint at the target of the jmp_buf. */ | |
2306 | disable_longjmp_breakpoint (); | |
2307 | remove_breakpoints (); | |
2308 | breakpoints_inserted = 0; | |
2309 | if (!GET_LONGJMP_TARGET (&jmp_buf_pc)) | |
d4f3574e SS |
2310 | { |
2311 | keep_going (ecs); | |
2312 | return; | |
2313 | } | |
c5aa993b JM |
2314 | |
2315 | /* Need to blow away step-resume breakpoint, as it | |
2316 | interferes with us */ | |
2317 | if (step_resume_breakpoint != NULL) | |
c906108c | 2318 | { |
8601f500 | 2319 | delete_step_resume_breakpoint (&step_resume_breakpoint); |
c906108c | 2320 | } |
c5aa993b JM |
2321 | /* Not sure whether we need to blow this away too, but probably |
2322 | it is like the step-resume breakpoint. */ | |
2323 | if (through_sigtramp_breakpoint != NULL) | |
c906108c | 2324 | { |
c5aa993b JM |
2325 | delete_breakpoint (through_sigtramp_breakpoint); |
2326 | through_sigtramp_breakpoint = NULL; | |
c906108c | 2327 | } |
c906108c | 2328 | |
c5aa993b JM |
2329 | #if 0 |
2330 | /* FIXME - Need to implement nested temporary breakpoints */ | |
2331 | if (step_over_calls > 0) | |
2332 | set_longjmp_resume_breakpoint (jmp_buf_pc, | |
2333 | get_current_frame ()); | |
2334 | else | |
2335 | #endif /* 0 */ | |
2336 | set_longjmp_resume_breakpoint (jmp_buf_pc, NULL); | |
2337 | ecs->handling_longjmp = 1; /* FIXME */ | |
d4f3574e SS |
2338 | keep_going (ecs); |
2339 | return; | |
c906108c | 2340 | |
c5aa993b JM |
2341 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
2342 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE: | |
2343 | remove_breakpoints (); | |
2344 | breakpoints_inserted = 0; | |
2345 | #if 0 | |
2346 | /* FIXME - Need to implement nested temporary breakpoints */ | |
2347 | if (step_over_calls | |
2348 | && (INNER_THAN (FRAME_FP (get_current_frame ()), | |
2349 | step_frame_address))) | |
2350 | { | |
2351 | ecs->another_trap = 1; | |
d4f3574e SS |
2352 | keep_going (ecs); |
2353 | return; | |
c5aa993b JM |
2354 | } |
2355 | #endif /* 0 */ | |
2356 | disable_longjmp_breakpoint (); | |
2357 | ecs->handling_longjmp = 0; /* FIXME */ | |
2358 | if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME) | |
2359 | break; | |
2360 | /* else fallthrough */ | |
c906108c | 2361 | |
c5aa993b JM |
2362 | case BPSTAT_WHAT_SINGLE: |
2363 | if (breakpoints_inserted) | |
c906108c | 2364 | { |
c5aa993b | 2365 | remove_breakpoints (); |
c906108c | 2366 | } |
c5aa993b JM |
2367 | breakpoints_inserted = 0; |
2368 | ecs->another_trap = 1; | |
2369 | /* Still need to check other stuff, at least the case | |
2370 | where we are stepping and step out of the right range. */ | |
2371 | break; | |
c906108c | 2372 | |
c5aa993b JM |
2373 | case BPSTAT_WHAT_STOP_NOISY: |
2374 | stop_print_frame = 1; | |
c906108c | 2375 | |
c5aa993b JM |
2376 | /* We are about to nuke the step_resume_breakpoint and |
2377 | through_sigtramp_breakpoint via the cleanup chain, so | |
2378 | no need to worry about it here. */ | |
c906108c | 2379 | |
104c1213 JM |
2380 | stop_stepping (ecs); |
2381 | return; | |
c906108c | 2382 | |
c5aa993b JM |
2383 | case BPSTAT_WHAT_STOP_SILENT: |
2384 | stop_print_frame = 0; | |
c906108c | 2385 | |
c5aa993b JM |
2386 | /* We are about to nuke the step_resume_breakpoint and |
2387 | through_sigtramp_breakpoint via the cleanup chain, so | |
2388 | no need to worry about it here. */ | |
c906108c | 2389 | |
104c1213 JM |
2390 | stop_stepping (ecs); |
2391 | return; | |
c906108c | 2392 | |
c5aa993b JM |
2393 | case BPSTAT_WHAT_STEP_RESUME: |
2394 | /* This proably demands a more elegant solution, but, yeah | |
2395 | right... | |
2396 | ||
2397 | This function's use of the simple variable | |
2398 | step_resume_breakpoint doesn't seem to accomodate | |
2399 | simultaneously active step-resume bp's, although the | |
2400 | breakpoint list certainly can. | |
2401 | ||
2402 | If we reach here and step_resume_breakpoint is already | |
2403 | NULL, then apparently we have multiple active | |
2404 | step-resume bp's. We'll just delete the breakpoint we | |
53a5351d JM |
2405 | stopped at, and carry on. |
2406 | ||
2407 | Correction: what the code currently does is delete a | |
2408 | step-resume bp, but it makes no effort to ensure that | |
2409 | the one deleted is the one currently stopped at. MVS */ | |
2410 | ||
c5aa993b JM |
2411 | if (step_resume_breakpoint == NULL) |
2412 | { | |
2413 | step_resume_breakpoint = | |
2414 | bpstat_find_step_resume_breakpoint (stop_bpstat); | |
2415 | } | |
8601f500 | 2416 | delete_step_resume_breakpoint (&step_resume_breakpoint); |
c5aa993b JM |
2417 | break; |
2418 | ||
2419 | case BPSTAT_WHAT_THROUGH_SIGTRAMP: | |
2420 | if (through_sigtramp_breakpoint) | |
2421 | delete_breakpoint (through_sigtramp_breakpoint); | |
2422 | through_sigtramp_breakpoint = NULL; | |
2423 | ||
2424 | /* If were waiting for a trap, hitting the step_resume_break | |
2425 | doesn't count as getting it. */ | |
2426 | if (trap_expected) | |
2427 | ecs->another_trap = 1; | |
2428 | break; | |
c906108c | 2429 | |
c5aa993b JM |
2430 | case BPSTAT_WHAT_CHECK_SHLIBS: |
2431 | case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK: | |
2432 | #ifdef SOLIB_ADD | |
c906108c | 2433 | { |
c5aa993b JM |
2434 | /* Remove breakpoints, we eventually want to step over the |
2435 | shlib event breakpoint, and SOLIB_ADD might adjust | |
2436 | breakpoint addresses via breakpoint_re_set. */ | |
2437 | if (breakpoints_inserted) | |
2438 | remove_breakpoints (); | |
c906108c | 2439 | breakpoints_inserted = 0; |
c906108c | 2440 | |
c5aa993b | 2441 | /* Check for any newly added shared libraries if we're |
990f9fe3 FF |
2442 | supposed to be adding them automatically. Switch |
2443 | terminal for any messages produced by | |
2444 | breakpoint_re_set. */ | |
2445 | target_terminal_ours_for_output (); | |
2446 | SOLIB_ADD (NULL, 0, NULL, auto_solib_add); | |
2447 | target_terminal_inferior (); | |
c5aa993b JM |
2448 | |
2449 | /* Try to reenable shared library breakpoints, additional | |
2450 | code segments in shared libraries might be mapped in now. */ | |
2451 | re_enable_breakpoints_in_shlibs (); | |
2452 | ||
2453 | /* If requested, stop when the dynamic linker notifies | |
2454 | gdb of events. This allows the user to get control | |
2455 | and place breakpoints in initializer routines for | |
2456 | dynamically loaded objects (among other things). */ | |
2457 | if (stop_on_solib_events) | |
c906108c | 2458 | { |
104c1213 JM |
2459 | stop_stepping (ecs); |
2460 | return; | |
c906108c SS |
2461 | } |
2462 | ||
c5aa993b JM |
2463 | /* If we stopped due to an explicit catchpoint, then the |
2464 | (see above) call to SOLIB_ADD pulled in any symbols | |
2465 | from a newly-loaded library, if appropriate. | |
2466 | ||
2467 | We do want the inferior to stop, but not where it is | |
2468 | now, which is in the dynamic linker callback. Rather, | |
2469 | we would like it stop in the user's program, just after | |
2470 | the call that caused this catchpoint to trigger. That | |
2471 | gives the user a more useful vantage from which to | |
2472 | examine their program's state. */ | |
2473 | else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK) | |
2474 | { | |
2475 | /* ??rehrauer: If I could figure out how to get the | |
2476 | right return PC from here, we could just set a temp | |
2477 | breakpoint and resume. I'm not sure we can without | |
2478 | cracking open the dld's shared libraries and sniffing | |
2479 | their unwind tables and text/data ranges, and that's | |
2480 | not a terribly portable notion. | |
2481 | ||
2482 | Until that time, we must step the inferior out of the | |
2483 | dld callback, and also out of the dld itself (and any | |
2484 | code or stubs in libdld.sl, such as "shl_load" and | |
2485 | friends) until we reach non-dld code. At that point, | |
2486 | we can stop stepping. */ | |
2487 | bpstat_get_triggered_catchpoints (stop_bpstat, | |
2488 | &ecs->stepping_through_solib_catchpoints); | |
2489 | ecs->stepping_through_solib_after_catch = 1; | |
2490 | ||
2491 | /* Be sure to lift all breakpoints, so the inferior does | |
2492 | actually step past this point... */ | |
2493 | ecs->another_trap = 1; | |
2494 | break; | |
2495 | } | |
2496 | else | |
c906108c | 2497 | { |
c5aa993b | 2498 | /* We want to step over this breakpoint, then keep going. */ |
cd0fc7c3 | 2499 | ecs->another_trap = 1; |
c5aa993b | 2500 | break; |
c906108c | 2501 | } |
c5aa993b JM |
2502 | } |
2503 | #endif | |
2504 | break; | |
c906108c | 2505 | |
c5aa993b JM |
2506 | case BPSTAT_WHAT_LAST: |
2507 | /* Not a real code, but listed here to shut up gcc -Wall. */ | |
c906108c | 2508 | |
c5aa993b JM |
2509 | case BPSTAT_WHAT_KEEP_CHECKING: |
2510 | break; | |
2511 | } | |
2512 | } | |
c906108c | 2513 | |
c5aa993b JM |
2514 | /* We come here if we hit a breakpoint but should not |
2515 | stop for it. Possibly we also were stepping | |
2516 | and should stop for that. So fall through and | |
2517 | test for stepping. But, if not stepping, | |
2518 | do not stop. */ | |
c906108c | 2519 | |
c5aa993b JM |
2520 | /* Are we stepping to get the inferior out of the dynamic |
2521 | linker's hook (and possibly the dld itself) after catching | |
2522 | a shlib event? */ | |
2523 | if (ecs->stepping_through_solib_after_catch) | |
2524 | { | |
2525 | #if defined(SOLIB_ADD) | |
2526 | /* Have we reached our destination? If not, keep going. */ | |
39f77062 | 2527 | if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc)) |
c5aa993b JM |
2528 | { |
2529 | ecs->another_trap = 1; | |
d4f3574e SS |
2530 | keep_going (ecs); |
2531 | return; | |
c5aa993b JM |
2532 | } |
2533 | #endif | |
2534 | /* Else, stop and report the catchpoint(s) whose triggering | |
2535 | caused us to begin stepping. */ | |
2536 | ecs->stepping_through_solib_after_catch = 0; | |
2537 | bpstat_clear (&stop_bpstat); | |
2538 | stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints); | |
2539 | bpstat_clear (&ecs->stepping_through_solib_catchpoints); | |
2540 | stop_print_frame = 1; | |
104c1213 JM |
2541 | stop_stepping (ecs); |
2542 | return; | |
c5aa993b | 2543 | } |
c906108c | 2544 | |
c5aa993b JM |
2545 | if (!CALL_DUMMY_BREAKPOINT_OFFSET_P) |
2546 | { | |
2547 | /* This is the old way of detecting the end of the stack dummy. | |
2548 | An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets | |
2549 | handled above. As soon as we can test it on all of them, all | |
2550 | architectures should define it. */ | |
2551 | ||
2552 | /* If this is the breakpoint at the end of a stack dummy, | |
2553 | just stop silently, unless the user was doing an si/ni, in which | |
2554 | case she'd better know what she's doing. */ | |
2555 | ||
2556 | if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (), | |
2557 | FRAME_FP (get_current_frame ())) | |
2558 | && !step_range_end) | |
2559 | { | |
c906108c | 2560 | stop_print_frame = 0; |
c5aa993b JM |
2561 | stop_stack_dummy = 1; |
2562 | #ifdef HP_OS_BUG | |
2563 | trap_expected_after_continue = 1; | |
2564 | #endif | |
104c1213 JM |
2565 | stop_stepping (ecs); |
2566 | return; | |
c5aa993b JM |
2567 | } |
2568 | } | |
c906108c | 2569 | |
c5aa993b | 2570 | if (step_resume_breakpoint) |
104c1213 JM |
2571 | { |
2572 | /* Having a step-resume breakpoint overrides anything | |
2573 | else having to do with stepping commands until | |
2574 | that breakpoint is reached. */ | |
2575 | /* I'm not sure whether this needs to be check_sigtramp2 or | |
2576 | whether it could/should be keep_going. */ | |
2577 | check_sigtramp2 (ecs); | |
d4f3574e SS |
2578 | keep_going (ecs); |
2579 | return; | |
104c1213 JM |
2580 | } |
2581 | ||
c5aa993b | 2582 | if (step_range_end == 0) |
104c1213 JM |
2583 | { |
2584 | /* Likewise if we aren't even stepping. */ | |
2585 | /* I'm not sure whether this needs to be check_sigtramp2 or | |
2586 | whether it could/should be keep_going. */ | |
2587 | check_sigtramp2 (ecs); | |
d4f3574e SS |
2588 | keep_going (ecs); |
2589 | return; | |
104c1213 | 2590 | } |
c5aa993b JM |
2591 | |
2592 | /* If stepping through a line, keep going if still within it. | |
2593 | ||
2594 | Note that step_range_end is the address of the first instruction | |
2595 | beyond the step range, and NOT the address of the last instruction | |
2596 | within it! */ | |
2597 | if (stop_pc >= step_range_start | |
2598 | && stop_pc < step_range_end) | |
2599 | { | |
2600 | /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal. | |
2601 | So definately need to check for sigtramp here. */ | |
104c1213 | 2602 | check_sigtramp2 (ecs); |
d4f3574e SS |
2603 | keep_going (ecs); |
2604 | return; | |
c5aa993b | 2605 | } |
c906108c | 2606 | |
c5aa993b | 2607 | /* We stepped out of the stepping range. */ |
c906108c | 2608 | |
c5aa993b JM |
2609 | /* If we are stepping at the source level and entered the runtime |
2610 | loader dynamic symbol resolution code, we keep on single stepping | |
2611 | until we exit the run time loader code and reach the callee's | |
2612 | address. */ | |
5fbbeb29 | 2613 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc)) |
d4f3574e SS |
2614 | { |
2615 | CORE_ADDR pc_after_resolver = SKIP_SOLIB_RESOLVER (stop_pc); | |
2616 | ||
2617 | if (pc_after_resolver) | |
2618 | { | |
2619 | /* Set up a step-resume breakpoint at the address | |
2620 | indicated by SKIP_SOLIB_RESOLVER. */ | |
2621 | struct symtab_and_line sr_sal; | |
2622 | INIT_SAL (&sr_sal); | |
2623 | sr_sal.pc = pc_after_resolver; | |
2624 | ||
2625 | check_for_old_step_resume_breakpoint (); | |
2626 | step_resume_breakpoint = | |
2627 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); | |
2628 | if (breakpoints_inserted) | |
2629 | insert_breakpoints (); | |
2630 | } | |
2631 | ||
2632 | keep_going (ecs); | |
2633 | return; | |
2634 | } | |
c906108c | 2635 | |
c5aa993b JM |
2636 | /* We can't update step_sp every time through the loop, because |
2637 | reading the stack pointer would slow down stepping too much. | |
2638 | But we can update it every time we leave the step range. */ | |
2639 | ecs->update_step_sp = 1; | |
c906108c | 2640 | |
c5aa993b JM |
2641 | /* Did we just take a signal? */ |
2642 | if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name) | |
2643 | && !IN_SIGTRAMP (prev_pc, prev_func_name) | |
2644 | && INNER_THAN (read_sp (), step_sp)) | |
2645 | { | |
2646 | /* We've just taken a signal; go until we are back to | |
2647 | the point where we took it and one more. */ | |
c906108c | 2648 | |
c5aa993b JM |
2649 | /* Note: The test above succeeds not only when we stepped |
2650 | into a signal handler, but also when we step past the last | |
2651 | statement of a signal handler and end up in the return stub | |
2652 | of the signal handler trampoline. To distinguish between | |
2653 | these two cases, check that the frame is INNER_THAN the | |
2654 | previous one below. pai/1997-09-11 */ | |
c906108c | 2655 | |
c906108c | 2656 | |
c5aa993b JM |
2657 | { |
2658 | CORE_ADDR current_frame = FRAME_FP (get_current_frame ()); | |
c906108c | 2659 | |
c5aa993b JM |
2660 | if (INNER_THAN (current_frame, step_frame_address)) |
2661 | { | |
2662 | /* We have just taken a signal; go until we are back to | |
2663 | the point where we took it and one more. */ | |
c906108c | 2664 | |
c5aa993b JM |
2665 | /* This code is needed at least in the following case: |
2666 | The user types "next" and then a signal arrives (before | |
2667 | the "next" is done). */ | |
c906108c | 2668 | |
c5aa993b JM |
2669 | /* Note that if we are stopped at a breakpoint, then we need |
2670 | the step_resume breakpoint to override any breakpoints at | |
2671 | the same location, so that we will still step over the | |
2672 | breakpoint even though the signal happened. */ | |
2673 | struct symtab_and_line sr_sal; | |
c906108c | 2674 | |
c5aa993b JM |
2675 | INIT_SAL (&sr_sal); |
2676 | sr_sal.symtab = NULL; | |
2677 | sr_sal.line = 0; | |
2678 | sr_sal.pc = prev_pc; | |
2679 | /* We could probably be setting the frame to | |
2680 | step_frame_address; I don't think anyone thought to | |
2681 | try it. */ | |
a0b3c4fd | 2682 | check_for_old_step_resume_breakpoint (); |
c5aa993b JM |
2683 | step_resume_breakpoint = |
2684 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); | |
2685 | if (breakpoints_inserted) | |
2686 | insert_breakpoints (); | |
c906108c | 2687 | } |
c5aa993b | 2688 | else |
c906108c | 2689 | { |
c5aa993b JM |
2690 | /* We just stepped out of a signal handler and into |
2691 | its calling trampoline. | |
2692 | ||
d4f3574e | 2693 | Normally, we'd call step_over_function from |
c5aa993b JM |
2694 | here, but for some reason GDB can't unwind the |
2695 | stack correctly to find the real PC for the point | |
2696 | user code where the signal trampoline will return | |
2697 | -- FRAME_SAVED_PC fails, at least on HP-UX 10.20. | |
2698 | But signal trampolines are pretty small stubs of | |
2699 | code, anyway, so it's OK instead to just | |
2700 | single-step out. Note: assuming such trampolines | |
2701 | don't exhibit recursion on any platform... */ | |
2702 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
2703 | &ecs->stop_func_start, | |
2704 | &ecs->stop_func_end); | |
2705 | /* Readjust stepping range */ | |
2706 | step_range_start = ecs->stop_func_start; | |
2707 | step_range_end = ecs->stop_func_end; | |
2708 | ecs->stepping_through_sigtramp = 1; | |
c906108c | 2709 | } |
c906108c SS |
2710 | } |
2711 | ||
c906108c | 2712 | |
c5aa993b JM |
2713 | /* If this is stepi or nexti, make sure that the stepping range |
2714 | gets us past that instruction. */ | |
2715 | if (step_range_end == 1) | |
2716 | /* FIXME: Does this run afoul of the code below which, if | |
2717 | we step into the middle of a line, resets the stepping | |
2718 | range? */ | |
2719 | step_range_end = (step_range_start = prev_pc) + 1; | |
c906108c | 2720 | |
c5aa993b | 2721 | ecs->remove_breakpoints_on_following_step = 1; |
d4f3574e SS |
2722 | keep_going (ecs); |
2723 | return; | |
c5aa993b | 2724 | } |
c906108c | 2725 | |
c5aa993b JM |
2726 | if (stop_pc == ecs->stop_func_start /* Quick test */ |
2727 | || (in_prologue (stop_pc, ecs->stop_func_start) && | |
2728 | !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) | |
2729 | || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name) | |
2730 | || ecs->stop_func_name == 0) | |
2731 | { | |
2732 | /* It's a subroutine call. */ | |
c906108c | 2733 | |
100a02e1 AC |
2734 | if ((step_over_calls == STEP_OVER_NONE) |
2735 | || ((step_range_end == 1) | |
2736 | && in_prologue (prev_pc, ecs->stop_func_start))) | |
c906108c | 2737 | { |
c5aa993b JM |
2738 | /* I presume that step_over_calls is only 0 when we're |
2739 | supposed to be stepping at the assembly language level | |
2740 | ("stepi"). Just stop. */ | |
100a02e1 AC |
2741 | /* Also, maybe we just did a "nexti" inside a prolog, |
2742 | so we thought it was a subroutine call but it was not. | |
2743 | Stop as well. FENN */ | |
c5aa993b | 2744 | stop_step = 1; |
11cf8741 | 2745 | print_stop_reason (END_STEPPING_RANGE, 0); |
104c1213 JM |
2746 | stop_stepping (ecs); |
2747 | return; | |
c5aa993b | 2748 | } |
c906108c | 2749 | |
5fbbeb29 | 2750 | if (step_over_calls == STEP_OVER_ALL || IGNORE_HELPER_CALL (stop_pc)) |
d4f3574e SS |
2751 | { |
2752 | /* We're doing a "next". */ | |
d41707c8 MK |
2753 | |
2754 | if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name) | |
2755 | && INNER_THAN (step_frame_address, read_sp())) | |
2756 | /* We stepped out of a signal handler, and into its | |
2757 | calling trampoline. This is misdetected as a | |
2758 | subroutine call, but stepping over the signal | |
2759 | trampoline isn't such a bad idea. In order to do | |
2760 | that, we have to ignore the value in | |
2761 | step_frame_address, since that doesn't represent the | |
2762 | frame that'll reach when we return from the signal | |
2763 | trampoline. Otherwise we'll probably continue to the | |
2764 | end of the program. */ | |
2765 | step_frame_address = 0; | |
2766 | ||
d4f3574e SS |
2767 | step_over_function (ecs); |
2768 | keep_going (ecs); | |
2769 | return; | |
2770 | } | |
c5aa993b JM |
2771 | |
2772 | /* If we are in a function call trampoline (a stub between | |
2773 | the calling routine and the real function), locate the real | |
2774 | function. That's what tells us (a) whether we want to step | |
2775 | into it at all, and (b) what prologue we want to run to | |
2776 | the end of, if we do step into it. */ | |
2777 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); | |
2778 | if (tmp != 0) | |
2779 | ecs->stop_func_start = tmp; | |
2780 | else | |
2781 | { | |
2782 | tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc); | |
2783 | if (tmp) | |
c906108c | 2784 | { |
c5aa993b JM |
2785 | struct symtab_and_line xxx; |
2786 | /* Why isn't this s_a_l called "sr_sal", like all of the | |
2787 | other s_a_l's where this code is duplicated? */ | |
2788 | INIT_SAL (&xxx); /* initialize to zeroes */ | |
2789 | xxx.pc = tmp; | |
2790 | xxx.section = find_pc_overlay (xxx.pc); | |
a0b3c4fd | 2791 | check_for_old_step_resume_breakpoint (); |
c906108c | 2792 | step_resume_breakpoint = |
c5aa993b JM |
2793 | set_momentary_breakpoint (xxx, NULL, bp_step_resume); |
2794 | insert_breakpoints (); | |
d4f3574e SS |
2795 | keep_going (ecs); |
2796 | return; | |
c906108c SS |
2797 | } |
2798 | } | |
2799 | ||
c5aa993b JM |
2800 | /* If we have line number information for the function we |
2801 | are thinking of stepping into, step into it. | |
c906108c | 2802 | |
c5aa993b JM |
2803 | If there are several symtabs at that PC (e.g. with include |
2804 | files), just want to know whether *any* of them have line | |
2805 | numbers. find_pc_line handles this. */ | |
2806 | { | |
2807 | struct symtab_and_line tmp_sal; | |
c906108c | 2808 | |
c5aa993b JM |
2809 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
2810 | if (tmp_sal.line != 0) | |
c2c6d25f JM |
2811 | { |
2812 | step_into_function (ecs); | |
2813 | return; | |
2814 | } | |
c906108c | 2815 | } |
5fbbeb29 CF |
2816 | |
2817 | /* If we have no line number and the step-stop-if-no-debug | |
2818 | is set, we stop the step so that the user has a chance to | |
2819 | switch in assembly mode. */ | |
2820 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug) | |
2821 | { | |
2822 | stop_step = 1; | |
2823 | print_stop_reason (END_STEPPING_RANGE, 0); | |
2824 | stop_stepping (ecs); | |
2825 | return; | |
2826 | } | |
2827 | ||
d4f3574e SS |
2828 | step_over_function (ecs); |
2829 | keep_going (ecs); | |
2830 | return; | |
c906108c | 2831 | |
c5aa993b | 2832 | } |
c906108c | 2833 | |
c5aa993b | 2834 | /* We've wandered out of the step range. */ |
c906108c | 2835 | |
c5aa993b | 2836 | ecs->sal = find_pc_line (stop_pc, 0); |
c906108c | 2837 | |
c5aa993b JM |
2838 | if (step_range_end == 1) |
2839 | { | |
2840 | /* It is stepi or nexti. We always want to stop stepping after | |
2841 | one instruction. */ | |
2842 | stop_step = 1; | |
11cf8741 | 2843 | print_stop_reason (END_STEPPING_RANGE, 0); |
104c1213 JM |
2844 | stop_stepping (ecs); |
2845 | return; | |
c5aa993b | 2846 | } |
c906108c | 2847 | |
c5aa993b JM |
2848 | /* If we're in the return path from a shared library trampoline, |
2849 | we want to proceed through the trampoline when stepping. */ | |
2850 | if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) | |
2851 | { | |
2852 | CORE_ADDR tmp; | |
c906108c | 2853 | |
c5aa993b JM |
2854 | /* Determine where this trampoline returns. */ |
2855 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); | |
c906108c | 2856 | |
c5aa993b JM |
2857 | /* Only proceed through if we know where it's going. */ |
2858 | if (tmp) | |
2859 | { | |
2860 | /* And put the step-breakpoint there and go until there. */ | |
2861 | struct symtab_and_line sr_sal; | |
c906108c | 2862 | |
c5aa993b JM |
2863 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
2864 | sr_sal.pc = tmp; | |
2865 | sr_sal.section = find_pc_overlay (sr_sal.pc); | |
2866 | /* Do not specify what the fp should be when we stop | |
2867 | since on some machines the prologue | |
2868 | is where the new fp value is established. */ | |
a0b3c4fd | 2869 | check_for_old_step_resume_breakpoint (); |
c5aa993b JM |
2870 | step_resume_breakpoint = |
2871 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); | |
2872 | if (breakpoints_inserted) | |
2873 | insert_breakpoints (); | |
c906108c | 2874 | |
c5aa993b JM |
2875 | /* Restart without fiddling with the step ranges or |
2876 | other state. */ | |
d4f3574e SS |
2877 | keep_going (ecs); |
2878 | return; | |
c5aa993b JM |
2879 | } |
2880 | } | |
c906108c | 2881 | |
c5aa993b | 2882 | if (ecs->sal.line == 0) |
c906108c | 2883 | { |
c5aa993b JM |
2884 | /* We have no line number information. That means to stop |
2885 | stepping (does this always happen right after one instruction, | |
2886 | when we do "s" in a function with no line numbers, | |
2887 | or can this happen as a result of a return or longjmp?). */ | |
2888 | stop_step = 1; | |
11cf8741 | 2889 | print_stop_reason (END_STEPPING_RANGE, 0); |
104c1213 JM |
2890 | stop_stepping (ecs); |
2891 | return; | |
c906108c SS |
2892 | } |
2893 | ||
c5aa993b JM |
2894 | if ((stop_pc == ecs->sal.pc) |
2895 | && (ecs->current_line != ecs->sal.line || ecs->current_symtab != ecs->sal.symtab)) | |
2896 | { | |
2897 | /* We are at the start of a different line. So stop. Note that | |
2898 | we don't stop if we step into the middle of a different line. | |
2899 | That is said to make things like for (;;) statements work | |
2900 | better. */ | |
2901 | stop_step = 1; | |
11cf8741 | 2902 | print_stop_reason (END_STEPPING_RANGE, 0); |
104c1213 JM |
2903 | stop_stepping (ecs); |
2904 | return; | |
c5aa993b | 2905 | } |
c906108c | 2906 | |
c5aa993b | 2907 | /* We aren't done stepping. |
c906108c | 2908 | |
c5aa993b JM |
2909 | Optimize by setting the stepping range to the line. |
2910 | (We might not be in the original line, but if we entered a | |
2911 | new line in mid-statement, we continue stepping. This makes | |
2912 | things like for(;;) statements work better.) */ | |
c906108c | 2913 | |
c5aa993b JM |
2914 | if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end) |
2915 | { | |
2916 | /* If this is the last line of the function, don't keep stepping | |
2917 | (it would probably step us out of the function). | |
2918 | This is particularly necessary for a one-line function, | |
2919 | in which after skipping the prologue we better stop even though | |
2920 | we will be in mid-line. */ | |
2921 | stop_step = 1; | |
11cf8741 | 2922 | print_stop_reason (END_STEPPING_RANGE, 0); |
104c1213 JM |
2923 | stop_stepping (ecs); |
2924 | return; | |
c5aa993b JM |
2925 | } |
2926 | step_range_start = ecs->sal.pc; | |
2927 | step_range_end = ecs->sal.end; | |
2928 | step_frame_address = FRAME_FP (get_current_frame ()); | |
2929 | ecs->current_line = ecs->sal.line; | |
2930 | ecs->current_symtab = ecs->sal.symtab; | |
2931 | ||
2932 | /* In the case where we just stepped out of a function into the middle | |
2933 | of a line of the caller, continue stepping, but step_frame_address | |
2934 | must be modified to current frame */ | |
2935 | { | |
2936 | CORE_ADDR current_frame = FRAME_FP (get_current_frame ()); | |
2937 | if (!(INNER_THAN (current_frame, step_frame_address))) | |
2938 | step_frame_address = current_frame; | |
2939 | } | |
c906108c | 2940 | |
d4f3574e | 2941 | keep_going (ecs); |
cd0fc7c3 | 2942 | |
104c1213 | 2943 | } /* extra brace, to preserve old indentation */ |
104c1213 JM |
2944 | } |
2945 | ||
2946 | /* Are we in the middle of stepping? */ | |
2947 | ||
2948 | static int | |
2949 | currently_stepping (struct execution_control_state *ecs) | |
2950 | { | |
2951 | return ((through_sigtramp_breakpoint == NULL | |
2952 | && !ecs->handling_longjmp | |
2953 | && ((step_range_end && step_resume_breakpoint == NULL) | |
2954 | || trap_expected)) | |
2955 | || ecs->stepping_through_solib_after_catch | |
2956 | || bpstat_should_step ()); | |
2957 | } | |
c906108c | 2958 | |
104c1213 JM |
2959 | static void |
2960 | check_sigtramp2 (struct execution_control_state *ecs) | |
2961 | { | |
2962 | if (trap_expected | |
2963 | && IN_SIGTRAMP (stop_pc, ecs->stop_func_name) | |
2964 | && !IN_SIGTRAMP (prev_pc, prev_func_name) | |
2965 | && INNER_THAN (read_sp (), step_sp)) | |
2966 | { | |
2967 | /* What has happened here is that we have just stepped the | |
2968 | inferior with a signal (because it is a signal which | |
2969 | shouldn't make us stop), thus stepping into sigtramp. | |
2970 | ||
2971 | So we need to set a step_resume_break_address breakpoint and | |
2972 | continue until we hit it, and then step. FIXME: This should | |
2973 | be more enduring than a step_resume breakpoint; we should | |
2974 | know that we will later need to keep going rather than | |
2975 | re-hitting the breakpoint here (see the testsuite, | |
2976 | gdb.base/signals.exp where it says "exceedingly difficult"). */ | |
2977 | ||
2978 | struct symtab_and_line sr_sal; | |
2979 | ||
2980 | INIT_SAL (&sr_sal); /* initialize to zeroes */ | |
2981 | sr_sal.pc = prev_pc; | |
2982 | sr_sal.section = find_pc_overlay (sr_sal.pc); | |
2983 | /* We perhaps could set the frame if we kept track of what the | |
2984 | frame corresponding to prev_pc was. But we don't, so don't. */ | |
2985 | through_sigtramp_breakpoint = | |
2986 | set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp); | |
2987 | if (breakpoints_inserted) | |
2988 | insert_breakpoints (); | |
cd0fc7c3 | 2989 | |
104c1213 JM |
2990 | ecs->remove_breakpoints_on_following_step = 1; |
2991 | ecs->another_trap = 1; | |
2992 | } | |
2993 | } | |
2994 | ||
c2c6d25f JM |
2995 | /* Subroutine call with source code we should not step over. Do step |
2996 | to the first line of code in it. */ | |
2997 | ||
2998 | static void | |
2999 | step_into_function (struct execution_control_state *ecs) | |
3000 | { | |
3001 | struct symtab *s; | |
3002 | struct symtab_and_line sr_sal; | |
3003 | ||
3004 | s = find_pc_symtab (stop_pc); | |
3005 | if (s && s->language != language_asm) | |
3006 | ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start); | |
3007 | ||
3008 | ecs->sal = find_pc_line (ecs->stop_func_start, 0); | |
3009 | /* Use the step_resume_break to step until the end of the prologue, | |
3010 | even if that involves jumps (as it seems to on the vax under | |
3011 | 4.2). */ | |
3012 | /* If the prologue ends in the middle of a source line, continue to | |
3013 | the end of that source line (if it is still within the function). | |
3014 | Otherwise, just go to end of prologue. */ | |
3015 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP | |
3016 | /* no, don't either. It skips any code that's legitimately on the | |
3017 | first line. */ | |
3018 | #else | |
3019 | if (ecs->sal.end | |
3020 | && ecs->sal.pc != ecs->stop_func_start | |
3021 | && ecs->sal.end < ecs->stop_func_end) | |
3022 | ecs->stop_func_start = ecs->sal.end; | |
3023 | #endif | |
3024 | ||
3025 | if (ecs->stop_func_start == stop_pc) | |
3026 | { | |
3027 | /* We are already there: stop now. */ | |
3028 | stop_step = 1; | |
11cf8741 | 3029 | print_stop_reason (END_STEPPING_RANGE, 0); |
c2c6d25f JM |
3030 | stop_stepping (ecs); |
3031 | return; | |
3032 | } | |
3033 | else | |
3034 | { | |
3035 | /* Put the step-breakpoint there and go until there. */ | |
3036 | INIT_SAL (&sr_sal); /* initialize to zeroes */ | |
3037 | sr_sal.pc = ecs->stop_func_start; | |
3038 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); | |
3039 | /* Do not specify what the fp should be when we stop since on | |
3040 | some machines the prologue is where the new fp value is | |
3041 | established. */ | |
3042 | check_for_old_step_resume_breakpoint (); | |
3043 | step_resume_breakpoint = | |
3044 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); | |
3045 | if (breakpoints_inserted) | |
3046 | insert_breakpoints (); | |
3047 | ||
3048 | /* And make sure stepping stops right away then. */ | |
3049 | step_range_end = step_range_start; | |
3050 | } | |
3051 | keep_going (ecs); | |
3052 | } | |
d4f3574e SS |
3053 | |
3054 | /* We've just entered a callee, and we wish to resume until it returns | |
3055 | to the caller. Setting a step_resume breakpoint on the return | |
3056 | address will catch a return from the callee. | |
3057 | ||
3058 | However, if the callee is recursing, we want to be careful not to | |
3059 | catch returns of those recursive calls, but only of THIS instance | |
3060 | of the call. | |
3061 | ||
3062 | To do this, we set the step_resume bp's frame to our current | |
3063 | caller's frame (step_frame_address, which is set by the "next" or | |
3064 | "until" command, before execution begins). */ | |
3065 | ||
3066 | static void | |
3067 | step_over_function (struct execution_control_state *ecs) | |
3068 | { | |
3069 | struct symtab_and_line sr_sal; | |
3070 | ||
3071 | INIT_SAL (&sr_sal); /* initialize to zeros */ | |
3072 | sr_sal.pc = ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ())); | |
3073 | sr_sal.section = find_pc_overlay (sr_sal.pc); | |
3074 | ||
3075 | check_for_old_step_resume_breakpoint (); | |
3076 | step_resume_breakpoint = | |
3077 | set_momentary_breakpoint (sr_sal, get_current_frame (), bp_step_resume); | |
3078 | ||
d41707c8 | 3079 | if (step_frame_address && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc)) |
d4f3574e SS |
3080 | step_resume_breakpoint->frame = step_frame_address; |
3081 | ||
3082 | if (breakpoints_inserted) | |
3083 | insert_breakpoints (); | |
3084 | } | |
3085 | ||
104c1213 JM |
3086 | static void |
3087 | stop_stepping (struct execution_control_state *ecs) | |
3088 | { | |
c906108c SS |
3089 | if (target_has_execution) |
3090 | { | |
3091 | /* Are we stopping for a vfork event? We only stop when we see | |
3092 | the child's event. However, we may not yet have seen the | |
39f77062 | 3093 | parent's event. And, inferior_ptid is still set to the |
104c1213 JM |
3094 | parent's pid, until we resume again and follow either the |
3095 | parent or child. | |
c906108c | 3096 | |
39f77062 | 3097 | To ensure that we can really touch inferior_ptid (aka, the |
c906108c SS |
3098 | parent process) -- which calls to functions like read_pc |
3099 | implicitly do -- wait on the parent if necessary. */ | |
3100 | if ((pending_follow.kind == TARGET_WAITKIND_VFORKED) | |
3101 | && !pending_follow.fork_event.saw_parent_fork) | |
3102 | { | |
39f77062 | 3103 | ptid_t parent_ptid; |
c906108c SS |
3104 | |
3105 | do | |
3106 | { | |
3107 | if (target_wait_hook) | |
39f77062 | 3108 | parent_ptid = target_wait_hook (pid_to_ptid (-1), &(ecs->ws)); |
c906108c | 3109 | else |
39f77062 | 3110 | parent_ptid = target_wait (pid_to_ptid (-1), &(ecs->ws)); |
c906108c | 3111 | } |
39f77062 | 3112 | while (! ptid_equal (parent_ptid, inferior_ptid)); |
c906108c SS |
3113 | } |
3114 | ||
c906108c | 3115 | /* Assuming the inferior still exists, set these up for next |
c5aa993b JM |
3116 | time, just like we did above if we didn't break out of the |
3117 | loop. */ | |
c906108c | 3118 | prev_pc = read_pc (); |
cd0fc7c3 SS |
3119 | prev_func_start = ecs->stop_func_start; |
3120 | prev_func_name = ecs->stop_func_name; | |
c906108c | 3121 | } |
104c1213 | 3122 | |
cd0fc7c3 SS |
3123 | /* Let callers know we don't want to wait for the inferior anymore. */ |
3124 | ecs->wait_some_more = 0; | |
3125 | } | |
3126 | ||
d4f3574e SS |
3127 | /* This function handles various cases where we need to continue |
3128 | waiting for the inferior. */ | |
3129 | /* (Used to be the keep_going: label in the old wait_for_inferior) */ | |
3130 | ||
3131 | static void | |
3132 | keep_going (struct execution_control_state *ecs) | |
3133 | { | |
3134 | /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a | |
3135 | vforked child between its creation and subsequent exit or call to | |
3136 | exec(). However, I had big problems in this rather creaky exec | |
3137 | engine, getting that to work. The fundamental problem is that | |
3138 | I'm trying to debug two processes via an engine that only | |
3139 | understands a single process with possibly multiple threads. | |
3140 | ||
3141 | Hence, this spot is known to have problems when | |
3142 | target_can_follow_vfork_prior_to_exec returns 1. */ | |
3143 | ||
3144 | /* Save the pc before execution, to compare with pc after stop. */ | |
3145 | prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ | |
3146 | prev_func_start = ecs->stop_func_start; /* Ok, since if DECR_PC_AFTER | |
3147 | BREAK is defined, the | |
3148 | original pc would not have | |
3149 | been at the start of a | |
3150 | function. */ | |
3151 | prev_func_name = ecs->stop_func_name; | |
3152 | ||
3153 | if (ecs->update_step_sp) | |
3154 | step_sp = read_sp (); | |
3155 | ecs->update_step_sp = 0; | |
3156 | ||
3157 | /* If we did not do break;, it means we should keep running the | |
3158 | inferior and not return to debugger. */ | |
3159 | ||
3160 | if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP) | |
3161 | { | |
3162 | /* We took a signal (which we are supposed to pass through to | |
3163 | the inferior, else we'd have done a break above) and we | |
3164 | haven't yet gotten our trap. Simply continue. */ | |
3165 | resume (currently_stepping (ecs), stop_signal); | |
3166 | } | |
3167 | else | |
3168 | { | |
3169 | /* Either the trap was not expected, but we are continuing | |
3170 | anyway (the user asked that this signal be passed to the | |
3171 | child) | |
3172 | -- or -- | |
3173 | The signal was SIGTRAP, e.g. it was our signal, but we | |
3174 | decided we should resume from it. | |
3175 | ||
3176 | We're going to run this baby now! | |
3177 | ||
3178 | Insert breakpoints now, unless we are trying to one-proceed | |
3179 | past a breakpoint. */ | |
3180 | /* If we've just finished a special step resume and we don't | |
3181 | want to hit a breakpoint, pull em out. */ | |
3182 | if (step_resume_breakpoint == NULL | |
3183 | && through_sigtramp_breakpoint == NULL | |
3184 | && ecs->remove_breakpoints_on_following_step) | |
3185 | { | |
3186 | ecs->remove_breakpoints_on_following_step = 0; | |
3187 | remove_breakpoints (); | |
3188 | breakpoints_inserted = 0; | |
3189 | } | |
3190 | else if (!breakpoints_inserted && | |
3191 | (through_sigtramp_breakpoint != NULL || !ecs->another_trap)) | |
3192 | { | |
3193 | breakpoints_failed = insert_breakpoints (); | |
3194 | if (breakpoints_failed) | |
3195 | { | |
3196 | stop_stepping (ecs); | |
3197 | return; | |
3198 | } | |
3199 | breakpoints_inserted = 1; | |
3200 | } | |
3201 | ||
3202 | trap_expected = ecs->another_trap; | |
3203 | ||
3204 | /* Do not deliver SIGNAL_TRAP (except when the user explicitly | |
3205 | specifies that such a signal should be delivered to the | |
3206 | target program). | |
3207 | ||
3208 | Typically, this would occure when a user is debugging a | |
3209 | target monitor on a simulator: the target monitor sets a | |
3210 | breakpoint; the simulator encounters this break-point and | |
3211 | halts the simulation handing control to GDB; GDB, noteing | |
3212 | that the break-point isn't valid, returns control back to the | |
3213 | simulator; the simulator then delivers the hardware | |
3214 | equivalent of a SIGNAL_TRAP to the program being debugged. */ | |
3215 | ||
3216 | if (stop_signal == TARGET_SIGNAL_TRAP | |
3217 | && !signal_program[stop_signal]) | |
3218 | stop_signal = TARGET_SIGNAL_0; | |
3219 | ||
3220 | #ifdef SHIFT_INST_REGS | |
3221 | /* I'm not sure when this following segment applies. I do know, | |
3222 | now, that we shouldn't rewrite the regs when we were stopped | |
3223 | by a random signal from the inferior process. */ | |
3224 | /* FIXME: Shouldn't this be based on the valid bit of the SXIP? | |
3225 | (this is only used on the 88k). */ | |
3226 | ||
3227 | if (!bpstat_explains_signal (stop_bpstat) | |
3228 | && (stop_signal != TARGET_SIGNAL_CHLD) | |
3229 | && !stopped_by_random_signal) | |
3230 | SHIFT_INST_REGS (); | |
3231 | #endif /* SHIFT_INST_REGS */ | |
3232 | ||
3233 | resume (currently_stepping (ecs), stop_signal); | |
3234 | } | |
3235 | ||
3236 | prepare_to_wait (ecs); | |
3237 | } | |
3238 | ||
104c1213 JM |
3239 | /* This function normally comes after a resume, before |
3240 | handle_inferior_event exits. It takes care of any last bits of | |
3241 | housekeeping, and sets the all-important wait_some_more flag. */ | |
cd0fc7c3 | 3242 | |
104c1213 JM |
3243 | static void |
3244 | prepare_to_wait (struct execution_control_state *ecs) | |
cd0fc7c3 | 3245 | { |
104c1213 JM |
3246 | if (ecs->infwait_state == infwait_normal_state) |
3247 | { | |
3248 | overlay_cache_invalid = 1; | |
3249 | ||
3250 | /* We have to invalidate the registers BEFORE calling | |
3251 | target_wait because they can be loaded from the target while | |
3252 | in target_wait. This makes remote debugging a bit more | |
3253 | efficient for those targets that provide critical registers | |
3254 | as part of their normal status mechanism. */ | |
3255 | ||
3256 | registers_changed (); | |
39f77062 | 3257 | ecs->waiton_ptid = pid_to_ptid (-1); |
104c1213 JM |
3258 | ecs->wp = &(ecs->ws); |
3259 | } | |
3260 | /* This is the old end of the while loop. Let everybody know we | |
3261 | want to wait for the inferior some more and get called again | |
3262 | soon. */ | |
3263 | ecs->wait_some_more = 1; | |
c906108c | 3264 | } |
11cf8741 JM |
3265 | |
3266 | /* Print why the inferior has stopped. We always print something when | |
3267 | the inferior exits, or receives a signal. The rest of the cases are | |
3268 | dealt with later on in normal_stop() and print_it_typical(). Ideally | |
3269 | there should be a call to this function from handle_inferior_event() | |
3270 | each time stop_stepping() is called.*/ | |
3271 | static void | |
3272 | print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info) | |
3273 | { | |
3274 | switch (stop_reason) | |
3275 | { | |
3276 | case STOP_UNKNOWN: | |
3277 | /* We don't deal with these cases from handle_inferior_event() | |
3278 | yet. */ | |
3279 | break; | |
3280 | case END_STEPPING_RANGE: | |
3281 | /* We are done with a step/next/si/ni command. */ | |
3282 | /* For now print nothing. */ | |
fb40c209 AC |
3283 | /* Print a message only if not in the middle of doing a "step n" |
3284 | operation for n > 1 */ | |
3285 | if (!step_multi || !stop_step) | |
9dc5e2a9 | 3286 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 3287 | ui_out_field_string (uiout, "reason", "end-stepping-range"); |
11cf8741 JM |
3288 | break; |
3289 | case BREAKPOINT_HIT: | |
3290 | /* We found a breakpoint. */ | |
3291 | /* For now print nothing. */ | |
3292 | break; | |
3293 | case SIGNAL_EXITED: | |
3294 | /* The inferior was terminated by a signal. */ | |
8b93c638 | 3295 | annotate_signalled (); |
9dc5e2a9 | 3296 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 3297 | ui_out_field_string (uiout, "reason", "exited-signalled"); |
8b93c638 JM |
3298 | ui_out_text (uiout, "\nProgram terminated with signal "); |
3299 | annotate_signal_name (); | |
3300 | ui_out_field_string (uiout, "signal-name", target_signal_to_name (stop_info)); | |
3301 | annotate_signal_name_end (); | |
3302 | ui_out_text (uiout, ", "); | |
3303 | annotate_signal_string (); | |
3304 | ui_out_field_string (uiout, "signal-meaning", target_signal_to_string (stop_info)); | |
3305 | annotate_signal_string_end (); | |
3306 | ui_out_text (uiout, ".\n"); | |
3307 | ui_out_text (uiout, "The program no longer exists.\n"); | |
11cf8741 JM |
3308 | break; |
3309 | case EXITED: | |
3310 | /* The inferior program is finished. */ | |
8b93c638 JM |
3311 | annotate_exited (stop_info); |
3312 | if (stop_info) | |
3313 | { | |
9dc5e2a9 | 3314 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 3315 | ui_out_field_string (uiout, "reason", "exited"); |
8b93c638 JM |
3316 | ui_out_text (uiout, "\nProgram exited with code "); |
3317 | ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) stop_info); | |
3318 | ui_out_text (uiout, ".\n"); | |
3319 | } | |
3320 | else | |
3321 | { | |
9dc5e2a9 | 3322 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 3323 | ui_out_field_string (uiout, "reason", "exited-normally"); |
8b93c638 JM |
3324 | ui_out_text (uiout, "\nProgram exited normally.\n"); |
3325 | } | |
11cf8741 JM |
3326 | break; |
3327 | case SIGNAL_RECEIVED: | |
3328 | /* Signal received. The signal table tells us to print about | |
3329 | it. */ | |
8b93c638 JM |
3330 | annotate_signal (); |
3331 | ui_out_text (uiout, "\nProgram received signal "); | |
3332 | annotate_signal_name (); | |
84c6c83c KS |
3333 | if (ui_out_is_mi_like_p (uiout)) |
3334 | ui_out_field_string (uiout, "reason", "signal-received"); | |
8b93c638 JM |
3335 | ui_out_field_string (uiout, "signal-name", target_signal_to_name (stop_info)); |
3336 | annotate_signal_name_end (); | |
3337 | ui_out_text (uiout, ", "); | |
3338 | annotate_signal_string (); | |
3339 | ui_out_field_string (uiout, "signal-meaning", target_signal_to_string (stop_info)); | |
3340 | annotate_signal_string_end (); | |
3341 | ui_out_text (uiout, ".\n"); | |
11cf8741 JM |
3342 | break; |
3343 | default: | |
8e65ff28 AC |
3344 | internal_error (__FILE__, __LINE__, |
3345 | "print_stop_reason: unrecognized enum value"); | |
11cf8741 JM |
3346 | break; |
3347 | } | |
3348 | } | |
c906108c | 3349 | \f |
43ff13b4 | 3350 | |
c906108c SS |
3351 | /* Here to return control to GDB when the inferior stops for real. |
3352 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
3353 | ||
3354 | STOP_PRINT_FRAME nonzero means print the executing frame | |
3355 | (pc, function, args, file, line number and line text). | |
3356 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
3357 | attempting to insert breakpoints. */ | |
3358 | ||
3359 | void | |
96baa820 | 3360 | normal_stop (void) |
c906108c | 3361 | { |
c906108c SS |
3362 | /* As with the notification of thread events, we want to delay |
3363 | notifying the user that we've switched thread context until | |
3364 | the inferior actually stops. | |
3365 | ||
3366 | (Note that there's no point in saying anything if the inferior | |
3367 | has exited!) */ | |
39f77062 | 3368 | if (! ptid_equal (previous_inferior_ptid, inferior_ptid) |
7a292a7a | 3369 | && target_has_execution) |
c906108c SS |
3370 | { |
3371 | target_terminal_ours_for_output (); | |
c3f6f71d | 3372 | printf_filtered ("[Switching to %s]\n", |
39f77062 KB |
3373 | target_pid_or_tid_to_str (inferior_ptid)); |
3374 | previous_inferior_ptid = inferior_ptid; | |
c906108c | 3375 | } |
c906108c SS |
3376 | |
3377 | /* Make sure that the current_frame's pc is correct. This | |
3378 | is a correction for setting up the frame info before doing | |
3379 | DECR_PC_AFTER_BREAK */ | |
3380 | if (target_has_execution && get_current_frame ()) | |
3381 | (get_current_frame ())->pc = read_pc (); | |
3382 | ||
3383 | if (breakpoints_failed) | |
3384 | { | |
3385 | target_terminal_ours_for_output (); | |
010a3cd9 | 3386 | print_sys_errmsg ("While inserting breakpoints", breakpoints_failed); |
c906108c | 3387 | printf_filtered ("Stopped; cannot insert breakpoints.\n\ |
010a3cd9 EZ |
3388 | The same program may be running in another process,\n\ |
3389 | or you may have requested too many hardware breakpoints\n\ | |
3390 | and/or watchpoints.\n"); | |
c906108c SS |
3391 | } |
3392 | ||
3393 | if (target_has_execution && breakpoints_inserted) | |
3394 | { | |
3395 | if (remove_breakpoints ()) | |
3396 | { | |
3397 | target_terminal_ours_for_output (); | |
3398 | printf_filtered ("Cannot remove breakpoints because "); | |
3399 | printf_filtered ("program is no longer writable.\n"); | |
3400 | printf_filtered ("It might be running in another process.\n"); | |
3401 | printf_filtered ("Further execution is probably impossible.\n"); | |
3402 | } | |
3403 | } | |
3404 | breakpoints_inserted = 0; | |
3405 | ||
3406 | /* Delete the breakpoint we stopped at, if it wants to be deleted. | |
3407 | Delete any breakpoint that is to be deleted at the next stop. */ | |
3408 | ||
3409 | breakpoint_auto_delete (stop_bpstat); | |
3410 | ||
3411 | /* If an auto-display called a function and that got a signal, | |
3412 | delete that auto-display to avoid an infinite recursion. */ | |
3413 | ||
3414 | if (stopped_by_random_signal) | |
3415 | disable_current_display (); | |
3416 | ||
3417 | /* Don't print a message if in the middle of doing a "step n" | |
3418 | operation for n > 1 */ | |
3419 | if (step_multi && stop_step) | |
3420 | goto done; | |
3421 | ||
3422 | target_terminal_ours (); | |
3423 | ||
c906108c SS |
3424 | /* Look up the hook_stop and run it if it exists. */ |
3425 | ||
73bc900d | 3426 | if (stop_command && stop_command->hook_pre) |
c906108c | 3427 | { |
73bc900d | 3428 | catch_errors (hook_stop_stub, stop_command->hook_pre, |
c906108c SS |
3429 | "Error while running hook_stop:\n", RETURN_MASK_ALL); |
3430 | } | |
3431 | ||
3432 | if (!target_has_stack) | |
3433 | { | |
3434 | ||
3435 | goto done; | |
3436 | } | |
3437 | ||
3438 | /* Select innermost stack frame - i.e., current frame is frame 0, | |
3439 | and current location is based on that. | |
3440 | Don't do this on return from a stack dummy routine, | |
3441 | or if the program has exited. */ | |
3442 | ||
3443 | if (!stop_stack_dummy) | |
3444 | { | |
3445 | select_frame (get_current_frame (), 0); | |
3446 | ||
3447 | /* Print current location without a level number, if | |
c5aa993b JM |
3448 | we have changed functions or hit a breakpoint. |
3449 | Print source line if we have one. | |
3450 | bpstat_print() contains the logic deciding in detail | |
3451 | what to print, based on the event(s) that just occurred. */ | |
c906108c | 3452 | |
d082b2bb AC |
3453 | if (stop_print_frame |
3454 | && selected_frame) | |
c906108c SS |
3455 | { |
3456 | int bpstat_ret; | |
3457 | int source_flag; | |
917317f4 | 3458 | int do_frame_printing = 1; |
c906108c SS |
3459 | |
3460 | bpstat_ret = bpstat_print (stop_bpstat); | |
917317f4 JM |
3461 | switch (bpstat_ret) |
3462 | { | |
3463 | case PRINT_UNKNOWN: | |
3464 | if (stop_step | |
3465 | && step_frame_address == FRAME_FP (get_current_frame ()) | |
3466 | && step_start_function == find_pc_function (stop_pc)) | |
c5394b80 | 3467 | source_flag = SRC_LINE; /* finished step, just print source line */ |
917317f4 | 3468 | else |
c5394b80 | 3469 | source_flag = SRC_AND_LOC; /* print location and source line */ |
917317f4 JM |
3470 | break; |
3471 | case PRINT_SRC_AND_LOC: | |
c5394b80 | 3472 | source_flag = SRC_AND_LOC; /* print location and source line */ |
917317f4 JM |
3473 | break; |
3474 | case PRINT_SRC_ONLY: | |
c5394b80 | 3475 | source_flag = SRC_LINE; |
917317f4 JM |
3476 | break; |
3477 | case PRINT_NOTHING: | |
88665544 | 3478 | source_flag = SRC_LINE; /* something bogus */ |
917317f4 JM |
3479 | do_frame_printing = 0; |
3480 | break; | |
3481 | default: | |
8e65ff28 AC |
3482 | internal_error (__FILE__, __LINE__, |
3483 | "Unknown value."); | |
917317f4 | 3484 | } |
fb40c209 AC |
3485 | /* For mi, have the same behavior every time we stop: |
3486 | print everything but the source line. */ | |
9dc5e2a9 | 3487 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 3488 | source_flag = LOC_AND_ADDRESS; |
c906108c | 3489 | |
9dc5e2a9 | 3490 | if (ui_out_is_mi_like_p (uiout)) |
39f77062 KB |
3491 | ui_out_field_int (uiout, "thread-id", |
3492 | pid_to_thread_id (inferior_ptid)); | |
c906108c SS |
3493 | /* The behavior of this routine with respect to the source |
3494 | flag is: | |
c5394b80 JM |
3495 | SRC_LINE: Print only source line |
3496 | LOCATION: Print only location | |
3497 | SRC_AND_LOC: Print location and source line */ | |
917317f4 JM |
3498 | if (do_frame_printing) |
3499 | show_and_print_stack_frame (selected_frame, -1, source_flag); | |
c906108c SS |
3500 | |
3501 | /* Display the auto-display expressions. */ | |
3502 | do_displays (); | |
3503 | } | |
3504 | } | |
3505 | ||
3506 | /* Save the function value return registers, if we care. | |
3507 | We might be about to restore their previous contents. */ | |
3508 | if (proceed_to_finish) | |
3509 | read_register_bytes (0, stop_registers, REGISTER_BYTES); | |
3510 | ||
3511 | if (stop_stack_dummy) | |
3512 | { | |
3513 | /* Pop the empty frame that contains the stack dummy. | |
3514 | POP_FRAME ends with a setting of the current frame, so we | |
c5aa993b | 3515 | can use that next. */ |
c906108c SS |
3516 | POP_FRAME; |
3517 | /* Set stop_pc to what it was before we called the function. | |
c5aa993b JM |
3518 | Can't rely on restore_inferior_status because that only gets |
3519 | called if we don't stop in the called function. */ | |
c906108c SS |
3520 | stop_pc = read_pc (); |
3521 | select_frame (get_current_frame (), 0); | |
3522 | } | |
3523 | ||
c906108c SS |
3524 | done: |
3525 | annotate_stopped (); | |
3526 | } | |
3527 | ||
3528 | static int | |
96baa820 | 3529 | hook_stop_stub (void *cmd) |
c906108c SS |
3530 | { |
3531 | execute_user_command ((struct cmd_list_element *) cmd, 0); | |
3532 | return (0); | |
3533 | } | |
3534 | \f | |
c5aa993b | 3535 | int |
96baa820 | 3536 | signal_stop_state (int signo) |
c906108c SS |
3537 | { |
3538 | return signal_stop[signo]; | |
3539 | } | |
3540 | ||
c5aa993b | 3541 | int |
96baa820 | 3542 | signal_print_state (int signo) |
c906108c SS |
3543 | { |
3544 | return signal_print[signo]; | |
3545 | } | |
3546 | ||
c5aa993b | 3547 | int |
96baa820 | 3548 | signal_pass_state (int signo) |
c906108c SS |
3549 | { |
3550 | return signal_program[signo]; | |
3551 | } | |
3552 | ||
d4f3574e SS |
3553 | int signal_stop_update (signo, state) |
3554 | int signo; | |
3555 | int state; | |
3556 | { | |
3557 | int ret = signal_stop[signo]; | |
3558 | signal_stop[signo] = state; | |
3559 | return ret; | |
3560 | } | |
3561 | ||
3562 | int signal_print_update (signo, state) | |
3563 | int signo; | |
3564 | int state; | |
3565 | { | |
3566 | int ret = signal_print[signo]; | |
3567 | signal_print[signo] = state; | |
3568 | return ret; | |
3569 | } | |
3570 | ||
3571 | int signal_pass_update (signo, state) | |
3572 | int signo; | |
3573 | int state; | |
3574 | { | |
3575 | int ret = signal_program[signo]; | |
3576 | signal_program[signo] = state; | |
3577 | return ret; | |
3578 | } | |
3579 | ||
c906108c | 3580 | static void |
96baa820 | 3581 | sig_print_header (void) |
c906108c SS |
3582 | { |
3583 | printf_filtered ("\ | |
3584 | Signal Stop\tPrint\tPass to program\tDescription\n"); | |
3585 | } | |
3586 | ||
3587 | static void | |
96baa820 | 3588 | sig_print_info (enum target_signal oursig) |
c906108c SS |
3589 | { |
3590 | char *name = target_signal_to_name (oursig); | |
3591 | int name_padding = 13 - strlen (name); | |
96baa820 | 3592 | |
c906108c SS |
3593 | if (name_padding <= 0) |
3594 | name_padding = 0; | |
3595 | ||
3596 | printf_filtered ("%s", name); | |
3597 | printf_filtered ("%*.*s ", name_padding, name_padding, | |
3598 | " "); | |
3599 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); | |
3600 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); | |
3601 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); | |
3602 | printf_filtered ("%s\n", target_signal_to_string (oursig)); | |
3603 | } | |
3604 | ||
3605 | /* Specify how various signals in the inferior should be handled. */ | |
3606 | ||
3607 | static void | |
96baa820 | 3608 | handle_command (char *args, int from_tty) |
c906108c SS |
3609 | { |
3610 | char **argv; | |
3611 | int digits, wordlen; | |
3612 | int sigfirst, signum, siglast; | |
3613 | enum target_signal oursig; | |
3614 | int allsigs; | |
3615 | int nsigs; | |
3616 | unsigned char *sigs; | |
3617 | struct cleanup *old_chain; | |
3618 | ||
3619 | if (args == NULL) | |
3620 | { | |
3621 | error_no_arg ("signal to handle"); | |
3622 | } | |
3623 | ||
3624 | /* Allocate and zero an array of flags for which signals to handle. */ | |
3625 | ||
3626 | nsigs = (int) TARGET_SIGNAL_LAST; | |
3627 | sigs = (unsigned char *) alloca (nsigs); | |
3628 | memset (sigs, 0, nsigs); | |
3629 | ||
3630 | /* Break the command line up into args. */ | |
3631 | ||
3632 | argv = buildargv (args); | |
3633 | if (argv == NULL) | |
3634 | { | |
3635 | nomem (0); | |
3636 | } | |
7a292a7a | 3637 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
3638 | |
3639 | /* Walk through the args, looking for signal oursigs, signal names, and | |
3640 | actions. Signal numbers and signal names may be interspersed with | |
3641 | actions, with the actions being performed for all signals cumulatively | |
3642 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ | |
3643 | ||
3644 | while (*argv != NULL) | |
3645 | { | |
3646 | wordlen = strlen (*argv); | |
3647 | for (digits = 0; isdigit ((*argv)[digits]); digits++) | |
3648 | {; | |
3649 | } | |
3650 | allsigs = 0; | |
3651 | sigfirst = siglast = -1; | |
3652 | ||
3653 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) | |
3654 | { | |
3655 | /* Apply action to all signals except those used by the | |
3656 | debugger. Silently skip those. */ | |
3657 | allsigs = 1; | |
3658 | sigfirst = 0; | |
3659 | siglast = nsigs - 1; | |
3660 | } | |
3661 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) | |
3662 | { | |
3663 | SET_SIGS (nsigs, sigs, signal_stop); | |
3664 | SET_SIGS (nsigs, sigs, signal_print); | |
3665 | } | |
3666 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) | |
3667 | { | |
3668 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3669 | } | |
3670 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) | |
3671 | { | |
3672 | SET_SIGS (nsigs, sigs, signal_print); | |
3673 | } | |
3674 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) | |
3675 | { | |
3676 | SET_SIGS (nsigs, sigs, signal_program); | |
3677 | } | |
3678 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) | |
3679 | { | |
3680 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3681 | } | |
3682 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) | |
3683 | { | |
3684 | SET_SIGS (nsigs, sigs, signal_program); | |
3685 | } | |
3686 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) | |
3687 | { | |
3688 | UNSET_SIGS (nsigs, sigs, signal_print); | |
3689 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3690 | } | |
3691 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) | |
3692 | { | |
3693 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3694 | } | |
3695 | else if (digits > 0) | |
3696 | { | |
3697 | /* It is numeric. The numeric signal refers to our own | |
3698 | internal signal numbering from target.h, not to host/target | |
3699 | signal number. This is a feature; users really should be | |
3700 | using symbolic names anyway, and the common ones like | |
3701 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ | |
3702 | ||
3703 | sigfirst = siglast = (int) | |
3704 | target_signal_from_command (atoi (*argv)); | |
3705 | if ((*argv)[digits] == '-') | |
3706 | { | |
3707 | siglast = (int) | |
3708 | target_signal_from_command (atoi ((*argv) + digits + 1)); | |
3709 | } | |
3710 | if (sigfirst > siglast) | |
3711 | { | |
3712 | /* Bet he didn't figure we'd think of this case... */ | |
3713 | signum = sigfirst; | |
3714 | sigfirst = siglast; | |
3715 | siglast = signum; | |
3716 | } | |
3717 | } | |
3718 | else | |
3719 | { | |
3720 | oursig = target_signal_from_name (*argv); | |
3721 | if (oursig != TARGET_SIGNAL_UNKNOWN) | |
3722 | { | |
3723 | sigfirst = siglast = (int) oursig; | |
3724 | } | |
3725 | else | |
3726 | { | |
3727 | /* Not a number and not a recognized flag word => complain. */ | |
3728 | error ("Unrecognized or ambiguous flag word: \"%s\".", *argv); | |
3729 | } | |
3730 | } | |
3731 | ||
3732 | /* If any signal numbers or symbol names were found, set flags for | |
c5aa993b | 3733 | which signals to apply actions to. */ |
c906108c SS |
3734 | |
3735 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) | |
3736 | { | |
3737 | switch ((enum target_signal) signum) | |
3738 | { | |
3739 | case TARGET_SIGNAL_TRAP: | |
3740 | case TARGET_SIGNAL_INT: | |
3741 | if (!allsigs && !sigs[signum]) | |
3742 | { | |
3743 | if (query ("%s is used by the debugger.\n\ | |
3744 | Are you sure you want to change it? ", | |
3745 | target_signal_to_name | |
3746 | ((enum target_signal) signum))) | |
3747 | { | |
3748 | sigs[signum] = 1; | |
3749 | } | |
3750 | else | |
3751 | { | |
3752 | printf_unfiltered ("Not confirmed, unchanged.\n"); | |
3753 | gdb_flush (gdb_stdout); | |
3754 | } | |
3755 | } | |
3756 | break; | |
3757 | case TARGET_SIGNAL_0: | |
3758 | case TARGET_SIGNAL_DEFAULT: | |
3759 | case TARGET_SIGNAL_UNKNOWN: | |
3760 | /* Make sure that "all" doesn't print these. */ | |
3761 | break; | |
3762 | default: | |
3763 | sigs[signum] = 1; | |
3764 | break; | |
3765 | } | |
3766 | } | |
3767 | ||
3768 | argv++; | |
3769 | } | |
3770 | ||
39f77062 | 3771 | target_notice_signals (inferior_ptid); |
c906108c SS |
3772 | |
3773 | if (from_tty) | |
3774 | { | |
3775 | /* Show the results. */ | |
3776 | sig_print_header (); | |
3777 | for (signum = 0; signum < nsigs; signum++) | |
3778 | { | |
3779 | if (sigs[signum]) | |
3780 | { | |
3781 | sig_print_info (signum); | |
3782 | } | |
3783 | } | |
3784 | } | |
3785 | ||
3786 | do_cleanups (old_chain); | |
3787 | } | |
3788 | ||
3789 | static void | |
96baa820 | 3790 | xdb_handle_command (char *args, int from_tty) |
c906108c SS |
3791 | { |
3792 | char **argv; | |
3793 | struct cleanup *old_chain; | |
3794 | ||
3795 | /* Break the command line up into args. */ | |
3796 | ||
3797 | argv = buildargv (args); | |
3798 | if (argv == NULL) | |
3799 | { | |
3800 | nomem (0); | |
3801 | } | |
7a292a7a | 3802 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
3803 | if (argv[1] != (char *) NULL) |
3804 | { | |
3805 | char *argBuf; | |
3806 | int bufLen; | |
3807 | ||
3808 | bufLen = strlen (argv[0]) + 20; | |
3809 | argBuf = (char *) xmalloc (bufLen); | |
3810 | if (argBuf) | |
3811 | { | |
3812 | int validFlag = 1; | |
3813 | enum target_signal oursig; | |
3814 | ||
3815 | oursig = target_signal_from_name (argv[0]); | |
3816 | memset (argBuf, 0, bufLen); | |
3817 | if (strcmp (argv[1], "Q") == 0) | |
3818 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
3819 | else | |
3820 | { | |
3821 | if (strcmp (argv[1], "s") == 0) | |
3822 | { | |
3823 | if (!signal_stop[oursig]) | |
3824 | sprintf (argBuf, "%s %s", argv[0], "stop"); | |
3825 | else | |
3826 | sprintf (argBuf, "%s %s", argv[0], "nostop"); | |
3827 | } | |
3828 | else if (strcmp (argv[1], "i") == 0) | |
3829 | { | |
3830 | if (!signal_program[oursig]) | |
3831 | sprintf (argBuf, "%s %s", argv[0], "pass"); | |
3832 | else | |
3833 | sprintf (argBuf, "%s %s", argv[0], "nopass"); | |
3834 | } | |
3835 | else if (strcmp (argv[1], "r") == 0) | |
3836 | { | |
3837 | if (!signal_print[oursig]) | |
3838 | sprintf (argBuf, "%s %s", argv[0], "print"); | |
3839 | else | |
3840 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
3841 | } | |
3842 | else | |
3843 | validFlag = 0; | |
3844 | } | |
3845 | if (validFlag) | |
3846 | handle_command (argBuf, from_tty); | |
3847 | else | |
3848 | printf_filtered ("Invalid signal handling flag.\n"); | |
3849 | if (argBuf) | |
b8c9b27d | 3850 | xfree (argBuf); |
c906108c SS |
3851 | } |
3852 | } | |
3853 | do_cleanups (old_chain); | |
3854 | } | |
3855 | ||
3856 | /* Print current contents of the tables set by the handle command. | |
3857 | It is possible we should just be printing signals actually used | |
3858 | by the current target (but for things to work right when switching | |
3859 | targets, all signals should be in the signal tables). */ | |
3860 | ||
3861 | static void | |
96baa820 | 3862 | signals_info (char *signum_exp, int from_tty) |
c906108c SS |
3863 | { |
3864 | enum target_signal oursig; | |
3865 | sig_print_header (); | |
3866 | ||
3867 | if (signum_exp) | |
3868 | { | |
3869 | /* First see if this is a symbol name. */ | |
3870 | oursig = target_signal_from_name (signum_exp); | |
3871 | if (oursig == TARGET_SIGNAL_UNKNOWN) | |
3872 | { | |
3873 | /* No, try numeric. */ | |
3874 | oursig = | |
bb518678 | 3875 | target_signal_from_command (parse_and_eval_long (signum_exp)); |
c906108c SS |
3876 | } |
3877 | sig_print_info (oursig); | |
3878 | return; | |
3879 | } | |
3880 | ||
3881 | printf_filtered ("\n"); | |
3882 | /* These ugly casts brought to you by the native VAX compiler. */ | |
3883 | for (oursig = TARGET_SIGNAL_FIRST; | |
3884 | (int) oursig < (int) TARGET_SIGNAL_LAST; | |
3885 | oursig = (enum target_signal) ((int) oursig + 1)) | |
3886 | { | |
3887 | QUIT; | |
3888 | ||
3889 | if (oursig != TARGET_SIGNAL_UNKNOWN | |
3890 | && oursig != TARGET_SIGNAL_DEFAULT | |
3891 | && oursig != TARGET_SIGNAL_0) | |
3892 | sig_print_info (oursig); | |
3893 | } | |
3894 | ||
3895 | printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); | |
3896 | } | |
3897 | \f | |
7a292a7a SS |
3898 | struct inferior_status |
3899 | { | |
3900 | enum target_signal stop_signal; | |
3901 | CORE_ADDR stop_pc; | |
3902 | bpstat stop_bpstat; | |
3903 | int stop_step; | |
3904 | int stop_stack_dummy; | |
3905 | int stopped_by_random_signal; | |
3906 | int trap_expected; | |
3907 | CORE_ADDR step_range_start; | |
3908 | CORE_ADDR step_range_end; | |
3909 | CORE_ADDR step_frame_address; | |
5fbbeb29 | 3910 | enum step_over_calls_kind step_over_calls; |
7a292a7a SS |
3911 | CORE_ADDR step_resume_break_address; |
3912 | int stop_after_trap; | |
3913 | int stop_soon_quietly; | |
3914 | CORE_ADDR selected_frame_address; | |
3915 | char *stop_registers; | |
3916 | ||
3917 | /* These are here because if call_function_by_hand has written some | |
3918 | registers and then decides to call error(), we better not have changed | |
3919 | any registers. */ | |
3920 | char *registers; | |
3921 | ||
3922 | int selected_level; | |
3923 | int breakpoint_proceeded; | |
3924 | int restore_stack_info; | |
3925 | int proceed_to_finish; | |
3926 | }; | |
3927 | ||
7a292a7a | 3928 | static struct inferior_status * |
96baa820 | 3929 | xmalloc_inferior_status (void) |
7a292a7a SS |
3930 | { |
3931 | struct inferior_status *inf_status; | |
3932 | inf_status = xmalloc (sizeof (struct inferior_status)); | |
3933 | inf_status->stop_registers = xmalloc (REGISTER_BYTES); | |
3934 | inf_status->registers = xmalloc (REGISTER_BYTES); | |
3935 | return inf_status; | |
3936 | } | |
3937 | ||
7a292a7a | 3938 | static void |
96baa820 | 3939 | free_inferior_status (struct inferior_status *inf_status) |
7a292a7a | 3940 | { |
b8c9b27d KB |
3941 | xfree (inf_status->registers); |
3942 | xfree (inf_status->stop_registers); | |
3943 | xfree (inf_status); | |
7a292a7a SS |
3944 | } |
3945 | ||
3946 | void | |
96baa820 JM |
3947 | write_inferior_status_register (struct inferior_status *inf_status, int regno, |
3948 | LONGEST val) | |
7a292a7a | 3949 | { |
c5aa993b | 3950 | int size = REGISTER_RAW_SIZE (regno); |
7a292a7a SS |
3951 | void *buf = alloca (size); |
3952 | store_signed_integer (buf, size, val); | |
3953 | memcpy (&inf_status->registers[REGISTER_BYTE (regno)], buf, size); | |
3954 | } | |
3955 | ||
c906108c SS |
3956 | /* Save all of the information associated with the inferior<==>gdb |
3957 | connection. INF_STATUS is a pointer to a "struct inferior_status" | |
3958 | (defined in inferior.h). */ | |
3959 | ||
7a292a7a | 3960 | struct inferior_status * |
96baa820 | 3961 | save_inferior_status (int restore_stack_info) |
c906108c | 3962 | { |
7a292a7a SS |
3963 | struct inferior_status *inf_status = xmalloc_inferior_status (); |
3964 | ||
c906108c SS |
3965 | inf_status->stop_signal = stop_signal; |
3966 | inf_status->stop_pc = stop_pc; | |
3967 | inf_status->stop_step = stop_step; | |
3968 | inf_status->stop_stack_dummy = stop_stack_dummy; | |
3969 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
3970 | inf_status->trap_expected = trap_expected; | |
3971 | inf_status->step_range_start = step_range_start; | |
3972 | inf_status->step_range_end = step_range_end; | |
3973 | inf_status->step_frame_address = step_frame_address; | |
3974 | inf_status->step_over_calls = step_over_calls; | |
3975 | inf_status->stop_after_trap = stop_after_trap; | |
3976 | inf_status->stop_soon_quietly = stop_soon_quietly; | |
3977 | /* Save original bpstat chain here; replace it with copy of chain. | |
3978 | If caller's caller is walking the chain, they'll be happier if we | |
7a292a7a SS |
3979 | hand them back the original chain when restore_inferior_status is |
3980 | called. */ | |
c906108c SS |
3981 | inf_status->stop_bpstat = stop_bpstat; |
3982 | stop_bpstat = bpstat_copy (stop_bpstat); | |
3983 | inf_status->breakpoint_proceeded = breakpoint_proceeded; | |
3984 | inf_status->restore_stack_info = restore_stack_info; | |
3985 | inf_status->proceed_to_finish = proceed_to_finish; | |
c5aa993b | 3986 | |
c906108c SS |
3987 | memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES); |
3988 | ||
3989 | read_register_bytes (0, inf_status->registers, REGISTER_BYTES); | |
3990 | ||
3991 | record_selected_frame (&(inf_status->selected_frame_address), | |
3992 | &(inf_status->selected_level)); | |
7a292a7a | 3993 | return inf_status; |
c906108c SS |
3994 | } |
3995 | ||
3996 | struct restore_selected_frame_args | |
3997 | { | |
3998 | CORE_ADDR frame_address; | |
3999 | int level; | |
4000 | }; | |
4001 | ||
c906108c | 4002 | static int |
96baa820 | 4003 | restore_selected_frame (void *args) |
c906108c SS |
4004 | { |
4005 | struct restore_selected_frame_args *fr = | |
4006 | (struct restore_selected_frame_args *) args; | |
4007 | struct frame_info *frame; | |
4008 | int level = fr->level; | |
4009 | ||
4010 | frame = find_relative_frame (get_current_frame (), &level); | |
4011 | ||
4012 | /* If inf_status->selected_frame_address is NULL, there was no | |
4013 | previously selected frame. */ | |
4014 | if (frame == NULL || | |
4015 | /* FRAME_FP (frame) != fr->frame_address || */ | |
4016 | /* elz: deleted this check as a quick fix to the problem that | |
c5aa993b JM |
4017 | for function called by hand gdb creates no internal frame |
4018 | structure and the real stack and gdb's idea of stack are | |
4019 | different if nested calls by hands are made. | |
c906108c | 4020 | |
c5aa993b | 4021 | mvs: this worries me. */ |
c906108c SS |
4022 | level != 0) |
4023 | { | |
4024 | warning ("Unable to restore previously selected frame.\n"); | |
4025 | return 0; | |
4026 | } | |
4027 | ||
4028 | select_frame (frame, fr->level); | |
4029 | ||
4030 | return (1); | |
4031 | } | |
4032 | ||
4033 | void | |
96baa820 | 4034 | restore_inferior_status (struct inferior_status *inf_status) |
c906108c SS |
4035 | { |
4036 | stop_signal = inf_status->stop_signal; | |
4037 | stop_pc = inf_status->stop_pc; | |
4038 | stop_step = inf_status->stop_step; | |
4039 | stop_stack_dummy = inf_status->stop_stack_dummy; | |
4040 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
4041 | trap_expected = inf_status->trap_expected; | |
4042 | step_range_start = inf_status->step_range_start; | |
4043 | step_range_end = inf_status->step_range_end; | |
4044 | step_frame_address = inf_status->step_frame_address; | |
4045 | step_over_calls = inf_status->step_over_calls; | |
4046 | stop_after_trap = inf_status->stop_after_trap; | |
4047 | stop_soon_quietly = inf_status->stop_soon_quietly; | |
4048 | bpstat_clear (&stop_bpstat); | |
4049 | stop_bpstat = inf_status->stop_bpstat; | |
4050 | breakpoint_proceeded = inf_status->breakpoint_proceeded; | |
4051 | proceed_to_finish = inf_status->proceed_to_finish; | |
4052 | ||
7a292a7a | 4053 | /* FIXME: Is the restore of stop_registers always needed */ |
c906108c SS |
4054 | memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES); |
4055 | ||
4056 | /* The inferior can be gone if the user types "print exit(0)" | |
4057 | (and perhaps other times). */ | |
4058 | if (target_has_execution) | |
4059 | write_register_bytes (0, inf_status->registers, REGISTER_BYTES); | |
4060 | ||
c906108c SS |
4061 | /* FIXME: If we are being called after stopping in a function which |
4062 | is called from gdb, we should not be trying to restore the | |
4063 | selected frame; it just prints a spurious error message (The | |
4064 | message is useful, however, in detecting bugs in gdb (like if gdb | |
4065 | clobbers the stack)). In fact, should we be restoring the | |
4066 | inferior status at all in that case? . */ | |
4067 | ||
4068 | if (target_has_stack && inf_status->restore_stack_info) | |
4069 | { | |
4070 | struct restore_selected_frame_args fr; | |
4071 | fr.level = inf_status->selected_level; | |
4072 | fr.frame_address = inf_status->selected_frame_address; | |
4073 | /* The point of catch_errors is that if the stack is clobbered, | |
c5aa993b JM |
4074 | walking the stack might encounter a garbage pointer and error() |
4075 | trying to dereference it. */ | |
c906108c SS |
4076 | if (catch_errors (restore_selected_frame, &fr, |
4077 | "Unable to restore previously selected frame:\n", | |
4078 | RETURN_MASK_ERROR) == 0) | |
4079 | /* Error in restoring the selected frame. Select the innermost | |
4080 | frame. */ | |
4081 | ||
4082 | ||
4083 | select_frame (get_current_frame (), 0); | |
4084 | ||
4085 | } | |
c906108c | 4086 | |
7a292a7a SS |
4087 | free_inferior_status (inf_status); |
4088 | } | |
c906108c | 4089 | |
74b7792f AC |
4090 | static void |
4091 | do_restore_inferior_status_cleanup (void *sts) | |
4092 | { | |
4093 | restore_inferior_status (sts); | |
4094 | } | |
4095 | ||
4096 | struct cleanup * | |
4097 | make_cleanup_restore_inferior_status (struct inferior_status *inf_status) | |
4098 | { | |
4099 | return make_cleanup (do_restore_inferior_status_cleanup, inf_status); | |
4100 | } | |
4101 | ||
c906108c | 4102 | void |
96baa820 | 4103 | discard_inferior_status (struct inferior_status *inf_status) |
7a292a7a SS |
4104 | { |
4105 | /* See save_inferior_status for info on stop_bpstat. */ | |
4106 | bpstat_clear (&inf_status->stop_bpstat); | |
4107 | free_inferior_status (inf_status); | |
4108 | } | |
4109 | ||
ca6724c1 KB |
4110 | /* Oft used ptids */ |
4111 | ptid_t null_ptid; | |
4112 | ptid_t minus_one_ptid; | |
4113 | ||
4114 | /* Create a ptid given the necessary PID, LWP, and TID components. */ | |
4115 | ||
4116 | ptid_t | |
4117 | ptid_build (int pid, long lwp, long tid) | |
4118 | { | |
4119 | ptid_t ptid; | |
4120 | ||
4121 | ptid.pid = pid; | |
4122 | ptid.lwp = lwp; | |
4123 | ptid.tid = tid; | |
4124 | return ptid; | |
4125 | } | |
4126 | ||
4127 | /* Create a ptid from just a pid. */ | |
4128 | ||
4129 | ptid_t | |
4130 | pid_to_ptid (int pid) | |
4131 | { | |
4132 | return ptid_build (pid, 0, 0); | |
4133 | } | |
4134 | ||
4135 | /* Fetch the pid (process id) component from a ptid. */ | |
4136 | ||
4137 | int | |
4138 | ptid_get_pid (ptid_t ptid) | |
4139 | { | |
4140 | return ptid.pid; | |
4141 | } | |
4142 | ||
4143 | /* Fetch the lwp (lightweight process) component from a ptid. */ | |
4144 | ||
4145 | long | |
4146 | ptid_get_lwp (ptid_t ptid) | |
4147 | { | |
4148 | return ptid.lwp; | |
4149 | } | |
4150 | ||
4151 | /* Fetch the tid (thread id) component from a ptid. */ | |
4152 | ||
4153 | long | |
4154 | ptid_get_tid (ptid_t ptid) | |
4155 | { | |
4156 | return ptid.tid; | |
4157 | } | |
4158 | ||
4159 | /* ptid_equal() is used to test equality of two ptids. */ | |
4160 | ||
4161 | int | |
4162 | ptid_equal (ptid_t ptid1, ptid_t ptid2) | |
4163 | { | |
4164 | return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp | |
4165 | && ptid1.tid == ptid2.tid); | |
4166 | } | |
4167 | ||
4168 | /* restore_inferior_ptid() will be used by the cleanup machinery | |
4169 | to restore the inferior_ptid value saved in a call to | |
4170 | save_inferior_ptid(). */ | |
ce696e05 KB |
4171 | |
4172 | static void | |
4173 | restore_inferior_ptid (void *arg) | |
4174 | { | |
4175 | ptid_t *saved_ptid_ptr = arg; | |
4176 | inferior_ptid = *saved_ptid_ptr; | |
4177 | xfree (arg); | |
4178 | } | |
4179 | ||
4180 | /* Save the value of inferior_ptid so that it may be restored by a | |
4181 | later call to do_cleanups(). Returns the struct cleanup pointer | |
4182 | needed for later doing the cleanup. */ | |
4183 | ||
4184 | struct cleanup * | |
4185 | save_inferior_ptid (void) | |
4186 | { | |
4187 | ptid_t *saved_ptid_ptr; | |
4188 | ||
4189 | saved_ptid_ptr = xmalloc (sizeof (ptid_t)); | |
4190 | *saved_ptid_ptr = inferior_ptid; | |
4191 | return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); | |
4192 | } | |
4193 | ||
c5aa993b | 4194 | \f |
7a292a7a | 4195 | static void |
96baa820 | 4196 | build_infrun (void) |
7a292a7a SS |
4197 | { |
4198 | stop_registers = xmalloc (REGISTER_BYTES); | |
4199 | } | |
c906108c | 4200 | |
c906108c | 4201 | void |
96baa820 | 4202 | _initialize_infrun (void) |
c906108c SS |
4203 | { |
4204 | register int i; | |
4205 | register int numsigs; | |
4206 | struct cmd_list_element *c; | |
4207 | ||
7a292a7a SS |
4208 | build_infrun (); |
4209 | ||
0f71a2f6 JM |
4210 | register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL); |
4211 | register_gdbarch_swap (NULL, 0, build_infrun); | |
4212 | ||
c906108c SS |
4213 | add_info ("signals", signals_info, |
4214 | "What debugger does when program gets various signals.\n\ | |
4215 | Specify a signal as argument to print info on that signal only."); | |
4216 | add_info_alias ("handle", "signals", 0); | |
4217 | ||
4218 | add_com ("handle", class_run, handle_command, | |
4219 | concat ("Specify how to handle a signal.\n\ | |
4220 | Args are signals and actions to apply to those signals.\n\ | |
4221 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
4222 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
4223 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
4224 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
4225 | used by the debugger, typically SIGTRAP and SIGINT.\n", | |
4226 | "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ | |
4227 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ | |
4228 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
4229 | Print means print a message if this signal happens.\n\ | |
4230 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
4231 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
4232 | Pass and Stop may be combined.", NULL)); | |
4233 | if (xdb_commands) | |
4234 | { | |
4235 | add_com ("lz", class_info, signals_info, | |
4236 | "What debugger does when program gets various signals.\n\ | |
4237 | Specify a signal as argument to print info on that signal only."); | |
4238 | add_com ("z", class_run, xdb_handle_command, | |
4239 | concat ("Specify how to handle a signal.\n\ | |
4240 | Args are signals and actions to apply to those signals.\n\ | |
4241 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
4242 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
4243 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
4244 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
4245 | used by the debugger, typically SIGTRAP and SIGINT.\n", | |
4246 | "Recognized actions include \"s\" (toggles between stop and nostop), \n\ | |
4247 | \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ | |
4248 | nopass), \"Q\" (noprint)\n\ | |
4249 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
4250 | Print means print a message if this signal happens.\n\ | |
4251 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
4252 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
4253 | Pass and Stop may be combined.", NULL)); | |
4254 | } | |
4255 | ||
4256 | if (!dbx_commands) | |
4257 | stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command, | |
4258 | "There is no `stop' command, but you can set a hook on `stop'.\n\ | |
4259 | This allows you to set a list of commands to be run each time execution\n\ | |
4260 | of the program stops.", &cmdlist); | |
4261 | ||
4262 | numsigs = (int) TARGET_SIGNAL_LAST; | |
4263 | signal_stop = (unsigned char *) | |
4264 | xmalloc (sizeof (signal_stop[0]) * numsigs); | |
4265 | signal_print = (unsigned char *) | |
4266 | xmalloc (sizeof (signal_print[0]) * numsigs); | |
4267 | signal_program = (unsigned char *) | |
4268 | xmalloc (sizeof (signal_program[0]) * numsigs); | |
4269 | for (i = 0; i < numsigs; i++) | |
4270 | { | |
4271 | signal_stop[i] = 1; | |
4272 | signal_print[i] = 1; | |
4273 | signal_program[i] = 1; | |
4274 | } | |
4275 | ||
4276 | /* Signals caused by debugger's own actions | |
4277 | should not be given to the program afterwards. */ | |
4278 | signal_program[TARGET_SIGNAL_TRAP] = 0; | |
4279 | signal_program[TARGET_SIGNAL_INT] = 0; | |
4280 | ||
4281 | /* Signals that are not errors should not normally enter the debugger. */ | |
4282 | signal_stop[TARGET_SIGNAL_ALRM] = 0; | |
4283 | signal_print[TARGET_SIGNAL_ALRM] = 0; | |
4284 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; | |
4285 | signal_print[TARGET_SIGNAL_VTALRM] = 0; | |
4286 | signal_stop[TARGET_SIGNAL_PROF] = 0; | |
4287 | signal_print[TARGET_SIGNAL_PROF] = 0; | |
4288 | signal_stop[TARGET_SIGNAL_CHLD] = 0; | |
4289 | signal_print[TARGET_SIGNAL_CHLD] = 0; | |
4290 | signal_stop[TARGET_SIGNAL_IO] = 0; | |
4291 | signal_print[TARGET_SIGNAL_IO] = 0; | |
4292 | signal_stop[TARGET_SIGNAL_POLL] = 0; | |
4293 | signal_print[TARGET_SIGNAL_POLL] = 0; | |
4294 | signal_stop[TARGET_SIGNAL_URG] = 0; | |
4295 | signal_print[TARGET_SIGNAL_URG] = 0; | |
4296 | signal_stop[TARGET_SIGNAL_WINCH] = 0; | |
4297 | signal_print[TARGET_SIGNAL_WINCH] = 0; | |
4298 | ||
cd0fc7c3 SS |
4299 | /* These signals are used internally by user-level thread |
4300 | implementations. (See signal(5) on Solaris.) Like the above | |
4301 | signals, a healthy program receives and handles them as part of | |
4302 | its normal operation. */ | |
4303 | signal_stop[TARGET_SIGNAL_LWP] = 0; | |
4304 | signal_print[TARGET_SIGNAL_LWP] = 0; | |
4305 | signal_stop[TARGET_SIGNAL_WAITING] = 0; | |
4306 | signal_print[TARGET_SIGNAL_WAITING] = 0; | |
4307 | signal_stop[TARGET_SIGNAL_CANCEL] = 0; | |
4308 | signal_print[TARGET_SIGNAL_CANCEL] = 0; | |
4309 | ||
c906108c SS |
4310 | #ifdef SOLIB_ADD |
4311 | add_show_from_set | |
4312 | (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger, | |
4313 | (char *) &stop_on_solib_events, | |
4314 | "Set stopping for shared library events.\n\ | |
4315 | If nonzero, gdb will give control to the user when the dynamic linker\n\ | |
4316 | notifies gdb of shared library events. The most common event of interest\n\ | |
4317 | to the user would be loading/unloading of a new library.\n", | |
4318 | &setlist), | |
4319 | &showlist); | |
4320 | #endif | |
4321 | ||
4322 | c = add_set_enum_cmd ("follow-fork-mode", | |
4323 | class_run, | |
4324 | follow_fork_mode_kind_names, | |
1ed2a135 | 4325 | &follow_fork_mode_string, |
c906108c SS |
4326 | /* ??rehrauer: The "both" option is broken, by what may be a 10.20 |
4327 | kernel problem. It's also not terribly useful without a GUI to | |
4328 | help the user drive two debuggers. So for now, I'm disabling | |
4329 | the "both" option. */ | |
c5aa993b JM |
4330 | /* "Set debugger response to a program call of fork \ |
4331 | or vfork.\n\ | |
4332 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ | |
4333 | parent - the original process is debugged after a fork\n\ | |
4334 | child - the new process is debugged after a fork\n\ | |
4335 | both - both the parent and child are debugged after a fork\n\ | |
4336 | ask - the debugger will ask for one of the above choices\n\ | |
4337 | For \"both\", another copy of the debugger will be started to follow\n\ | |
4338 | the new child process. The original debugger will continue to follow\n\ | |
4339 | the original parent process. To distinguish their prompts, the\n\ | |
4340 | debugger copy's prompt will be changed.\n\ | |
4341 | For \"parent\" or \"child\", the unfollowed process will run free.\n\ | |
4342 | By default, the debugger will follow the parent process.", | |
4343 | */ | |
c906108c SS |
4344 | "Set debugger response to a program call of fork \ |
4345 | or vfork.\n\ | |
4346 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ | |
4347 | parent - the original process is debugged after a fork\n\ | |
4348 | child - the new process is debugged after a fork\n\ | |
4349 | ask - the debugger will ask for one of the above choices\n\ | |
4350 | For \"parent\" or \"child\", the unfollowed process will run free.\n\ | |
4351 | By default, the debugger will follow the parent process.", | |
4352 | &setlist); | |
c906108c SS |
4353 | add_show_from_set (c, &showlist); |
4354 | ||
c906108c SS |
4355 | c = add_set_enum_cmd ("scheduler-locking", class_run, |
4356 | scheduler_enums, /* array of string names */ | |
1ed2a135 | 4357 | &scheduler_mode, /* current mode */ |
c906108c SS |
4358 | "Set mode for locking scheduler during execution.\n\ |
4359 | off == no locking (threads may preempt at any time)\n\ | |
4360 | on == full locking (no thread except the current thread may run)\n\ | |
4361 | step == scheduler locked during every single-step operation.\n\ | |
4362 | In this mode, no other thread may run during a step command.\n\ | |
4363 | Other threads may run while stepping over a function call ('next').", | |
4364 | &setlist); | |
4365 | ||
9f60d481 | 4366 | set_cmd_sfunc (c, set_schedlock_func); /* traps on target vector */ |
c906108c | 4367 | add_show_from_set (c, &showlist); |
5fbbeb29 CF |
4368 | |
4369 | c = add_set_cmd ("step-mode", class_run, | |
4370 | var_boolean, (char*) &step_stop_if_no_debug, | |
4371 | "Set mode of the step operation. When set, doing a step over a\n\ | |
4372 | function without debug line information will stop at the first\n\ | |
4373 | instruction of that function. Otherwise, the function is skipped and\n\ | |
4374 | the step command stops at a different source line.", | |
4375 | &setlist); | |
4376 | add_show_from_set (c, &showlist); | |
ca6724c1 KB |
4377 | |
4378 | /* ptid initializations */ | |
4379 | null_ptid = ptid_build (0, 0, 0); | |
4380 | minus_one_ptid = ptid_build (-1, 0, 0); | |
4381 | inferior_ptid = null_ptid; | |
4382 | target_last_wait_ptid = minus_one_ptid; | |
c906108c | 4383 | } |