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