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