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