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