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