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