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