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