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