import gdb-1999-08-16 snapshot
[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
JM
1287/* Call this function before setting step_resume_breakpoint, as a
1288 sanity check. We should never be setting a new
1289 step_resume_breakpoint when we have an old one active. */
1290static void
96baa820 1291check_for_old_step_resume_breakpoint (void)
a0b3c4fd
JM
1292{
1293 if (step_resume_breakpoint)
1294 warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint");
1295}
1296
cd0fc7c3
SS
1297/* Given an execution control state that has been freshly filled in
1298 by an event from the inferior, figure out what it means and take
1299 appropriate action. */
c906108c 1300
cd0fc7c3 1301void
96baa820 1302handle_inferior_event (struct execution_control_state *ecs)
cd0fc7c3
SS
1303{
1304 CORE_ADDR tmp;
1305 int stepped_after_stopped_by_watchpoint;
1306
1307 /* Keep this extra brace for now, minimizes diffs. */
1308 {
c5aa993b
JM
1309 switch (ecs->infwait_state)
1310 {
1311 case infwait_normal_state:
1312 /* Since we've done a wait, we have a new event. Don't
1313 carry over any expectations about needing to step over a
1314 breakpoint. */
1315 thread_step_needed = 0;
1316
1317 /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event
1318 is serviced in this loop, below. */
1319 if (ecs->enable_hw_watchpoints_after_wait)
1320 {
1321 TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid);
1322 ecs->enable_hw_watchpoints_after_wait = 0;
1323 }
1324 stepped_after_stopped_by_watchpoint = 0;
1325 break;
b83266a0 1326
c5aa993b
JM
1327 case infwait_thread_hop_state:
1328 insert_breakpoints ();
c906108c 1329
c5aa993b
JM
1330 /* We need to restart all the threads now,
1331 * unles we're running in scheduler-locked mode.
1332 * FIXME: shouldn't we look at currently_stepping ()?
1333 */
1334 if (scheduler_mode == schedlock_on)
1335 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1336 else
1337 target_resume (-1, 0, TARGET_SIGNAL_0);
1338 ecs->infwait_state = infwait_normal_state;
1339 goto wfi_continue;
c906108c 1340
c5aa993b
JM
1341 case infwait_nullified_state:
1342 break;
b83266a0 1343
c5aa993b
JM
1344 case infwait_nonstep_watch_state:
1345 insert_breakpoints ();
b83266a0 1346
c5aa993b
JM
1347 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1348 handle things like signals arriving and other things happening
1349 in combination correctly? */
1350 stepped_after_stopped_by_watchpoint = 1;
1351 break;
1352 }
1353 ecs->infwait_state = infwait_normal_state;
c906108c 1354
c5aa993b 1355 flush_cached_frames ();
c906108c 1356
c5aa993b 1357 /* If it's a new process, add it to the thread database */
c906108c 1358
c5aa993b 1359 ecs->new_thread_event = ((ecs->pid != inferior_pid) && !in_thread_list (ecs->pid));
c906108c 1360
c5aa993b
JM
1361 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1362 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
1363 && ecs->new_thread_event)
1364 {
1365 add_thread (ecs->pid);
c906108c 1366
c5aa993b 1367 printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs->pid));
c906108c
SS
1368
1369#if 0
c5aa993b
JM
1370 /* NOTE: This block is ONLY meant to be invoked in case of a
1371 "thread creation event"! If it is invoked for any other
1372 sort of event (such as a new thread landing on a breakpoint),
1373 the event will be discarded, which is almost certainly
1374 a bad thing!
1375
1376 To avoid this, the low-level module (eg. target_wait)
1377 should call in_thread_list and add_thread, so that the
1378 new thread is known by the time we get here. */
1379
1380 /* We may want to consider not doing a resume here in order
1381 to give the user a chance to play with the new thread.
1382 It might be good to make that a user-settable option. */
1383
1384 /* At this point, all threads are stopped (happens
1385 automatically in either the OS or the native code).
1386 Therefore we need to continue all threads in order to
1387 make progress. */
1388
1389 target_resume (-1, 0, TARGET_SIGNAL_0);
1390 goto wfi_continue;
c906108c 1391#endif
c5aa993b 1392 }
c906108c 1393
c5aa993b
JM
1394 switch (ecs->ws.kind)
1395 {
1396 case TARGET_WAITKIND_LOADED:
1397 /* Ignore gracefully during startup of the inferior, as it
1398 might be the shell which has just loaded some objects,
1399 otherwise add the symbols for the newly loaded objects. */
c906108c 1400#ifdef SOLIB_ADD
c5aa993b
JM
1401 if (!stop_soon_quietly)
1402 {
1403 /* Remove breakpoints, SOLIB_ADD might adjust
1404 breakpoint addresses via breakpoint_re_set. */
1405 if (breakpoints_inserted)
1406 remove_breakpoints ();
c906108c 1407
c5aa993b
JM
1408 /* Check for any newly added shared libraries if we're
1409 supposed to be adding them automatically. */
1410 if (auto_solib_add)
1411 {
1412 /* Switch terminal for any messages produced by
1413 breakpoint_re_set. */
1414 target_terminal_ours_for_output ();
1415 SOLIB_ADD (NULL, 0, NULL);
1416 target_terminal_inferior ();
1417 }
c906108c 1418
c5aa993b
JM
1419 /* Reinsert breakpoints and continue. */
1420 if (breakpoints_inserted)
1421 insert_breakpoints ();
1422 }
c906108c 1423#endif
c5aa993b
JM
1424 resume (0, TARGET_SIGNAL_0);
1425 goto wfi_continue;
1426
1427 case TARGET_WAITKIND_SPURIOUS:
1428 resume (0, TARGET_SIGNAL_0);
1429 goto wfi_continue;
1430
1431 case TARGET_WAITKIND_EXITED:
1432 target_terminal_ours (); /* Must do this before mourn anyway */
1433 annotate_exited (ecs->ws.value.integer);
1434 if (ecs->ws.value.integer)
1435 printf_filtered ("\nProgram exited with code 0%o.\n",
1436 (unsigned int) ecs->ws.value.integer);
1437 else
1438 printf_filtered ("\nProgram exited normally.\n");
1439
1440 /* Record the exit code in the convenience variable $_exitcode, so
1441 that the user can inspect this again later. */
1442 set_internalvar (lookup_internalvar ("_exitcode"),
1443 value_from_longest (builtin_type_int,
1444 (LONGEST) ecs->ws.value.integer));
1445 gdb_flush (gdb_stdout);
1446 target_mourn_inferior ();
1447 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P */
1448 stop_print_frame = 0;
1449 goto stop_stepping;
1450
1451 case TARGET_WAITKIND_SIGNALLED:
1452 stop_print_frame = 0;
1453 stop_signal = ecs->ws.value.sig;
1454 target_terminal_ours (); /* Must do this before mourn anyway */
1455 annotate_signalled ();
1456
1457 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
1458 mean it is already dead? This has been here since GDB 2.8, so
1459 perhaps it means rms didn't understand unix waitstatuses?
1460 For the moment I'm just kludging around this in remote.c
1461 rather than trying to change it here --kingdon, 5 Dec 1994. */
1462 target_kill (); /* kill mourns as well */
1463
1464 printf_filtered ("\nProgram terminated with signal ");
1465 annotate_signal_name ();
1466 printf_filtered ("%s", target_signal_to_name (stop_signal));
1467 annotate_signal_name_end ();
1468 printf_filtered (", ");
1469 annotate_signal_string ();
1470 printf_filtered ("%s", target_signal_to_string (stop_signal));
1471 annotate_signal_string_end ();
1472 printf_filtered (".\n");
1473
1474 printf_filtered ("The program no longer exists.\n");
1475 gdb_flush (gdb_stdout);
1476 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P */
1477 goto stop_stepping;
1478
1479 /* The following are the only cases in which we keep going;
1480 the above cases end in a continue or goto. */
1481 case TARGET_WAITKIND_FORKED:
1482 stop_signal = TARGET_SIGNAL_TRAP;
1483 pending_follow.kind = ecs->ws.kind;
1484
1485 /* Ignore fork events reported for the parent; we're only
1486 interested in reacting to forks of the child. Note that
1487 we expect the child's fork event to be available if we
1488 waited for it now. */
1489 if (inferior_pid == ecs->pid)
1490 {
1491 pending_follow.fork_event.saw_parent_fork = 1;
1492 pending_follow.fork_event.parent_pid = ecs->pid;
1493 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1494 goto wfi_continue;
1495 }
1496 else
1497 {
1498 pending_follow.fork_event.saw_child_fork = 1;
1499 pending_follow.fork_event.child_pid = ecs->pid;
1500 pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid;
1501 }
c906108c 1502
c5aa993b
JM
1503 stop_pc = read_pc_pid (ecs->pid);
1504 ecs->saved_inferior_pid = inferior_pid;
1505 inferior_pid = ecs->pid;
1506 stop_bpstat = bpstat_stop_status
1507 (&stop_pc,
1508 (DECR_PC_AFTER_BREAK ?
1509 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1510 && currently_stepping (ecs))
1511 : 0)
1512 );
1513 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1514 inferior_pid = ecs->saved_inferior_pid;
1515 goto process_event_stop_test;
1516
1517 /* If this a platform which doesn't allow a debugger to touch a
1518 vfork'd inferior until after it exec's, then we'd best keep
1519 our fingers entirely off the inferior, other than continuing
1520 it. This has the unfortunate side-effect that catchpoints
1521 of vforks will be ignored. But since the platform doesn't
1522 allow the inferior be touched at vfork time, there's really
1523 little choice. */
1524 case TARGET_WAITKIND_VFORKED:
1525 stop_signal = TARGET_SIGNAL_TRAP;
1526 pending_follow.kind = ecs->ws.kind;
1527
1528 /* Is this a vfork of the parent? If so, then give any
1529 vfork catchpoints a chance to trigger now. (It's
1530 dangerous to do so if the child canot be touched until
1531 it execs, and the child has not yet exec'd. We probably
1532 should warn the user to that effect when the catchpoint
1533 triggers...) */
1534 if (ecs->pid == inferior_pid)
1535 {
1536 pending_follow.fork_event.saw_parent_fork = 1;
1537 pending_follow.fork_event.parent_pid = ecs->pid;
1538 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1539 }
c906108c 1540
c5aa993b
JM
1541 /* If we've seen the child's vfork event but cannot really touch
1542 the child until it execs, then we must continue the child now.
1543 Else, give any vfork catchpoints a chance to trigger now. */
1544 else
1545 {
1546 pending_follow.fork_event.saw_child_fork = 1;
1547 pending_follow.fork_event.child_pid = ecs->pid;
1548 pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid;
1549 target_post_startup_inferior (pending_follow.fork_event.child_pid);
1550 follow_vfork_when_exec = !target_can_follow_vfork_prior_to_exec ();
1551 if (follow_vfork_when_exec)
1552 {
1553 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1554 goto wfi_continue;
1555 }
1556 }
c906108c 1557
c5aa993b
JM
1558 stop_pc = read_pc ();
1559 stop_bpstat = bpstat_stop_status
1560 (&stop_pc,
1561 (DECR_PC_AFTER_BREAK ?
1562 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1563 && currently_stepping (ecs))
1564 : 0)
1565 );
1566 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1567 goto process_event_stop_test;
1568
1569 case TARGET_WAITKIND_EXECD:
1570 stop_signal = TARGET_SIGNAL_TRAP;
1571
1572 /* Is this a target which reports multiple exec events per actual
1573 call to exec()? (HP-UX using ptrace does, for example.) If so,
1574 ignore all but the last one. Just resume the exec'r, and wait
1575 for the next exec event. */
1576 if (inferior_ignoring_leading_exec_events)
1577 {
1578 inferior_ignoring_leading_exec_events--;
1579 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1580 ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.parent_pid);
1581 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1582 goto wfi_continue;
1583 }
1584 inferior_ignoring_leading_exec_events =
1585 target_reported_exec_events_per_exec_call () - 1;
c906108c 1586
96baa820
JM
1587 pending_follow.execd_pathname =
1588 savestring (ecs->ws.value.execd_pathname,
1589 strlen (ecs->ws.value.execd_pathname));
c906108c 1590
c5aa993b
JM
1591 /* Did inferior_pid exec, or did a (possibly not-yet-followed)
1592 child of a vfork exec?
c906108c 1593
c5aa993b
JM
1594 ??rehrauer: This is unabashedly an HP-UX specific thing. On
1595 HP-UX, events associated with a vforking inferior come in
1596 threes: a vfork event for the child (always first), followed
1597 a vfork event for the parent and an exec event for the child.
1598 The latter two can come in either order.
c906108c 1599
c5aa993b
JM
1600 If we get the parent vfork event first, life's good: We follow
1601 either the parent or child, and then the child's exec event is
1602 a "don't care".
c906108c 1603
c5aa993b
JM
1604 But if we get the child's exec event first, then we delay
1605 responding to it until we handle the parent's vfork. Because,
1606 otherwise we can't satisfy a "catch vfork". */
1607 if (pending_follow.kind == TARGET_WAITKIND_VFORKED)
1608 {
1609 pending_follow.fork_event.saw_child_exec = 1;
1610
1611 /* On some targets, the child must be resumed before
1612 the parent vfork event is delivered. A single-step
1613 suffices. */
1614 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
1615 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1616 /* We expect the parent vfork event to be available now. */
1617 goto wfi_continue;
1618 }
c906108c 1619
c5aa993b
JM
1620 /* This causes the eventpoints and symbol table to be reset. Must
1621 do this now, before trying to determine whether to stop. */
1622 follow_exec (inferior_pid, pending_follow.execd_pathname);
1623 free (pending_follow.execd_pathname);
1624
1625 stop_pc = read_pc_pid (ecs->pid);
1626 ecs->saved_inferior_pid = inferior_pid;
1627 inferior_pid = ecs->pid;
1628 stop_bpstat = bpstat_stop_status
1629 (&stop_pc,
1630 (DECR_PC_AFTER_BREAK ?
1631 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
1632 && currently_stepping (ecs))
1633 : 0)
1634 );
1635 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1636 inferior_pid = ecs->saved_inferior_pid;
1637 goto process_event_stop_test;
1638
1639 /* These syscall events are returned on HP-UX, as part of its
1640 implementation of page-protection-based "hardware" watchpoints.
1641 HP-UX has unfortunate interactions between page-protections and
1642 some system calls. Our solution is to disable hardware watches
1643 when a system call is entered, and reenable them when the syscall
1644 completes. The downside of this is that we may miss the precise
1645 point at which a watched piece of memory is modified. "Oh well."
1646
1647 Note that we may have multiple threads running, which may each
1648 enter syscalls at roughly the same time. Since we don't have a
1649 good notion currently of whether a watched piece of memory is
1650 thread-private, we'd best not have any page-protections active
1651 when any thread is in a syscall. Thus, we only want to reenable
1652 hardware watches when no threads are in a syscall.
1653
1654 Also, be careful not to try to gather much state about a thread
1655 that's in a syscall. It's frequently a losing proposition. */
1656 case TARGET_WAITKIND_SYSCALL_ENTRY:
1657 number_of_threads_in_syscalls++;
1658 if (number_of_threads_in_syscalls == 1)
1659 {
1660 TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid);
1661 }
1662 resume (0, TARGET_SIGNAL_0);
1663 goto wfi_continue;
c906108c 1664
c5aa993b 1665 /* Before examining the threads further, step this thread to
c906108c
SS
1666 get it entirely out of the syscall. (We get notice of the
1667 event when the thread is just on the verge of exiting a
1668 syscall. Stepping one instruction seems to get it back
1669 into user code.)
1670
1671 Note that although the logical place to reenable h/w watches
1672 is here, we cannot. We cannot reenable them before stepping
1673 the thread (this causes the next wait on the thread to hang).
1674
1675 Nor can we enable them after stepping until we've done a wait.
cd0fc7c3 1676 Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait
c906108c
SS
1677 here, which will be serviced immediately after the target
1678 is waited on. */
c5aa993b
JM
1679 case TARGET_WAITKIND_SYSCALL_RETURN:
1680 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
c906108c 1681
c5aa993b
JM
1682 if (number_of_threads_in_syscalls > 0)
1683 {
1684 number_of_threads_in_syscalls--;
1685 ecs->enable_hw_watchpoints_after_wait =
1686 (number_of_threads_in_syscalls == 0);
1687 }
1688 goto wfi_continue;
c906108c 1689
c5aa993b
JM
1690 case TARGET_WAITKIND_STOPPED:
1691 stop_signal = ecs->ws.value.sig;
1692 break;
1693 }
c906108c 1694
c5aa993b
JM
1695 /* We may want to consider not doing a resume here in order to give
1696 the user a chance to play with the new thread. It might be good
1697 to make that a user-settable option. */
c906108c 1698
c5aa993b
JM
1699 /* At this point, all threads are stopped (happens automatically in
1700 either the OS or the native code). Therefore we need to continue
1701 all threads in order to make progress. */
1702 if (ecs->new_thread_event)
1703 {
1704 target_resume (-1, 0, TARGET_SIGNAL_0);
1705 goto wfi_continue;
1706 }
c906108c 1707
c5aa993b 1708 stop_pc = read_pc_pid (ecs->pid);
c906108c 1709
c5aa993b
JM
1710 /* See if a thread hit a thread-specific breakpoint that was meant for
1711 another thread. If so, then step that thread past the breakpoint,
1712 and continue it. */
c906108c 1713
c5aa993b
JM
1714 if (stop_signal == TARGET_SIGNAL_TRAP)
1715 {
1716 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1717 ecs->random_signal = 0;
1718 else if (breakpoints_inserted
1719 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
1720 {
cd0fc7c3 1721 ecs->random_signal = 0;
c5aa993b
JM
1722 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK,
1723 ecs->pid))
1724 {
1725 int remove_status;
1726
1727 /* Saw a breakpoint, but it was hit by the wrong thread.
1728 Just continue. */
1729 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->pid);
1730
1731 remove_status = remove_breakpoints ();
1732 /* Did we fail to remove breakpoints? If so, try
1733 to set the PC past the bp. (There's at least
1734 one situation in which we can fail to remove
1735 the bp's: On HP-UX's that use ttrace, we can't
1736 change the address space of a vforking child
1737 process until the child exits (well, okay, not
1738 then either :-) or execs. */
1739 if (remove_status != 0)
1740 {
1741 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, ecs->pid);
1742 }
1743 else
1744 { /* Single step */
1745 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
1746 /* FIXME: What if a signal arrives instead of the
1747 single-step happening? */
1748
1749 ecs->waiton_pid = ecs->pid;
1750 ecs->wp = &(ecs->ws);
1751 ecs->infwait_state = infwait_thread_hop_state;
cd0fc7c3 1752 goto wfi_continue;
c5aa993b 1753 }
c906108c 1754
c5aa993b
JM
1755 /* We need to restart all the threads now,
1756 * unles we're running in scheduler-locked mode.
1757 * FIXME: shouldn't we look at currently_stepping ()?
1758 */
1759 if (scheduler_mode == schedlock_on)
1760 target_resume (ecs->pid, 0, TARGET_SIGNAL_0);
1761 else
1762 target_resume (-1, 0, TARGET_SIGNAL_0);
1763 goto wfi_continue;
1764 }
1765 else
1766 {
1767 /* This breakpoint matches--either it is the right
1768 thread or it's a generic breakpoint for all threads.
1769 Remember that we'll need to step just _this_ thread
1770 on any following user continuation! */
1771 thread_step_needed = 1;
1772 }
1773 }
1774 }
1775 else
1776 ecs->random_signal = 1;
1777
1778 /* See if something interesting happened to the non-current thread. If
1779 so, then switch to that thread, and eventually give control back to
1780 the user.
1781
1782 Note that if there's any kind of pending follow (i.e., of a fork,
1783 vfork or exec), we don't want to do this now. Rather, we'll let
1784 the next resume handle it. */
1785 if ((ecs->pid != inferior_pid) &&
1786 (pending_follow.kind == TARGET_WAITKIND_SPURIOUS))
1787 {
1788 int printed = 0;
c906108c 1789
c5aa993b
JM
1790 /* If it's a random signal for a non-current thread, notify user
1791 if he's expressed an interest. */
1792 if (ecs->random_signal
1793 && signal_print[stop_signal])
1794 {
c906108c
SS
1795/* ??rehrauer: I don't understand the rationale for this code. If the
1796 inferior will stop as a result of this signal, then the act of handling
1797 the stop ought to print a message that's couches the stoppage in user
1798 terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior
1799 won't stop as a result of the signal -- i.e., if the signal is merely
1800 a side-effect of something GDB's doing "under the covers" for the
1801 user, such as stepping threads over a breakpoint they shouldn't stop
1802 for -- then the message seems to be a serious annoyance at best.
1803
1804 For now, remove the message altogether. */
1805#if 0
c5aa993b
JM
1806 printed = 1;
1807 target_terminal_ours_for_output ();
1808 printf_filtered ("\nProgram received signal %s, %s.\n",
1809 target_signal_to_name (stop_signal),
1810 target_signal_to_string (stop_signal));
1811 gdb_flush (gdb_stdout);
c906108c 1812#endif
c5aa993b 1813 }
c906108c 1814
c5aa993b
JM
1815 /* If it's not SIGTRAP and not a signal we want to stop for, then
1816 continue the thread. */
c906108c 1817
c5aa993b
JM
1818 if (stop_signal != TARGET_SIGNAL_TRAP
1819 && !signal_stop[stop_signal])
1820 {
1821 if (printed)
1822 target_terminal_inferior ();
c906108c 1823
c5aa993b
JM
1824 /* Clear the signal if it should not be passed. */
1825 if (signal_program[stop_signal] == 0)
1826 stop_signal = TARGET_SIGNAL_0;
c906108c 1827
c5aa993b
JM
1828 target_resume (ecs->pid, 0, stop_signal);
1829 goto wfi_continue;
1830 }
c906108c 1831
c5aa993b
JM
1832 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
1833 and fall into the rest of wait_for_inferior(). */
1834
1835 /* Save infrun state for the old thread. */
1836 save_infrun_state (inferior_pid, prev_pc,
1837 prev_func_start, prev_func_name,
1838 trap_expected, step_resume_breakpoint,
1839 through_sigtramp_breakpoint,
1840 step_range_start, step_range_end,
1841 step_frame_address, ecs->handling_longjmp,
1842 ecs->another_trap,
1843 ecs->stepping_through_solib_after_catch,
1844 ecs->stepping_through_solib_catchpoints,
1845 ecs->stepping_through_sigtramp);
1846
1847 if (may_switch_from_inferior_pid)
1848 switched_from_inferior_pid = inferior_pid;
1849
1850 inferior_pid = ecs->pid;
1851
1852 /* Load infrun state for the new thread. */
1853 load_infrun_state (inferior_pid, &prev_pc,
1854 &prev_func_start, &prev_func_name,
1855 &trap_expected, &step_resume_breakpoint,
1856 &through_sigtramp_breakpoint,
1857 &step_range_start, &step_range_end,
1858 &step_frame_address, &ecs->handling_longjmp,
1859 &ecs->another_trap,
1860 &ecs->stepping_through_solib_after_catch,
1861 &ecs->stepping_through_solib_catchpoints,
1862 &ecs->stepping_through_sigtramp);
1863
1864 if (context_hook)
1865 context_hook (pid_to_thread_id (ecs->pid));
1866
1867 printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs->pid));
1868 flush_cached_frames ();
1869 }
c906108c 1870
c5aa993b
JM
1871 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
1872 {
1873 /* Pull the single step breakpoints out of the target. */
1874 SOFTWARE_SINGLE_STEP (0, 0);
1875 singlestep_breakpoints_inserted_p = 0;
1876 }
c906108c 1877
c5aa993b
JM
1878 /* If PC is pointing at a nullified instruction, then step beyond
1879 it so that the user won't be confused when GDB appears to be ready
1880 to execute it. */
c906108c 1881
c5aa993b
JM
1882 /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */
1883 if (INSTRUCTION_NULLIFIED)
1884 {
1885 registers_changed ();
1886 target_resume (ecs->pid, 1, TARGET_SIGNAL_0);
c906108c 1887
c5aa993b
JM
1888 /* We may have received a signal that we want to pass to
1889 the inferior; therefore, we must not clobber the waitstatus
1890 in WS. */
c906108c 1891
c5aa993b
JM
1892 ecs->infwait_state = infwait_nullified_state;
1893 ecs->waiton_pid = ecs->pid;
1894 ecs->wp = &(ecs->tmpstatus);
1895 goto wfi_continue;
1896 }
c906108c 1897
c5aa993b
JM
1898 /* It may not be necessary to disable the watchpoint to stop over
1899 it. For example, the PA can (with some kernel cooperation)
1900 single step over a watchpoint without disabling the watchpoint. */
1901 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1902 {
1903 resume (1, 0);
1904 goto wfi_continue;
1905 }
c906108c 1906
c5aa993b
JM
1907 /* It is far more common to need to disable a watchpoint to step
1908 the inferior over it. FIXME. What else might a debug
1909 register or page protection watchpoint scheme need here? */
1910 if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws))
1911 {
1912 /* At this point, we are stopped at an instruction which has
1913 attempted to write to a piece of memory under control of
1914 a watchpoint. The instruction hasn't actually executed
1915 yet. If we were to evaluate the watchpoint expression
1916 now, we would get the old value, and therefore no change
1917 would seem to have occurred.
1918
1919 In order to make watchpoints work `right', we really need
1920 to complete the memory write, and then evaluate the
1921 watchpoint expression. The following code does that by
1922 removing the watchpoint (actually, all watchpoints and
1923 breakpoints), single-stepping the target, re-inserting
1924 watchpoints, and then falling through to let normal
1925 single-step processing handle proceed. Since this
1926 includes evaluating watchpoints, things will come to a
1927 stop in the correct manner. */
1928
1929 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
1930
1931 remove_breakpoints ();
1932 registers_changed ();
1933 target_resume (ecs->pid, 1, TARGET_SIGNAL_0); /* Single step */
1934
1935 ecs->waiton_pid = ecs->pid;
1936 ecs->wp = &(ecs->ws);
1937 ecs->infwait_state = infwait_nonstep_watch_state;
1938 goto wfi_continue;
1939 }
c906108c 1940
c5aa993b
JM
1941 /* It may be possible to simply continue after a watchpoint. */
1942 if (HAVE_CONTINUABLE_WATCHPOINT)
1943 STOPPED_BY_WATCHPOINT (ecs->ws);
1944
1945 ecs->stop_func_start = 0;
1946 ecs->stop_func_end = 0;
1947 ecs->stop_func_name = 0;
1948 /* Don't care about return value; stop_func_start and stop_func_name
1949 will both be 0 if it doesn't work. */
1950 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
1951 &ecs->stop_func_start, &ecs->stop_func_end);
1952 ecs->stop_func_start += FUNCTION_START_OFFSET;
1953 ecs->another_trap = 0;
1954 bpstat_clear (&stop_bpstat);
1955 stop_step = 0;
1956 stop_stack_dummy = 0;
1957 stop_print_frame = 1;
1958 ecs->random_signal = 0;
1959 stopped_by_random_signal = 0;
1960 breakpoints_failed = 0;
1961
1962 /* Look at the cause of the stop, and decide what to do.
1963 The alternatives are:
1964 1) break; to really stop and return to the debugger,
1965 2) drop through to start up again
1966 (set ecs->another_trap to 1 to single step once)
1967 3) set ecs->random_signal to 1, and the decision between 1 and 2
1968 will be made according to the signal handling tables. */
1969
1970 /* First, distinguish signals caused by the debugger from signals
1971 that have to do with the program's own actions.
1972 Note that breakpoint insns may cause SIGTRAP or SIGILL
1973 or SIGEMT, depending on the operating system version.
1974 Here we detect when a SIGILL or SIGEMT is really a breakpoint
1975 and change it to SIGTRAP. */
1976
1977 if (stop_signal == TARGET_SIGNAL_TRAP
1978 || (breakpoints_inserted &&
1979 (stop_signal == TARGET_SIGNAL_ILL
1980 || stop_signal == TARGET_SIGNAL_EMT
1981 ))
1982 || stop_soon_quietly)
1983 {
1984 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1985 {
1986 stop_print_frame = 0;
cd0fc7c3 1987 goto wfi_break;
c5aa993b
JM
1988 }
1989 if (stop_soon_quietly)
1990 goto wfi_break;
c906108c 1991
c5aa993b
JM
1992 /* Don't even think about breakpoints
1993 if just proceeded over a breakpoint.
c906108c 1994
c5aa993b
JM
1995 However, if we are trying to proceed over a breakpoint
1996 and end up in sigtramp, then through_sigtramp_breakpoint
1997 will be set and we should check whether we've hit the
1998 step breakpoint. */
1999 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
2000 && through_sigtramp_breakpoint == NULL)
2001 bpstat_clear (&stop_bpstat);
2002 else
2003 {
2004 /* See if there is a breakpoint at the current PC. */
2005 stop_bpstat = bpstat_stop_status
2006 (&stop_pc,
2007 (DECR_PC_AFTER_BREAK ?
2008 /* Notice the case of stepping through a jump
2009 that lands just after a breakpoint.
2010 Don't confuse that with hitting the breakpoint.
2011 What we check for is that 1) stepping is going on
2012 and 2) the pc before the last insn does not match
2013 the address of the breakpoint before the current pc
2014 and 3) we didn't hit a breakpoint in a signal handler
2015 without an intervening stop in sigtramp, which is
2016 detected by a new stack pointer value below
2017 any usual function calling stack adjustments. */
2018 (currently_stepping (ecs)
2019 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
2020 && !(step_range_end
2021 && INNER_THAN (read_sp (), (step_sp - 16)))) :
2022 0)
2023 );
2024 /* Following in case break condition called a
2025 function. */
2026 stop_print_frame = 1;
2027 }
c906108c 2028
c5aa993b
JM
2029 if (stop_signal == TARGET_SIGNAL_TRAP)
2030 ecs->random_signal
2031 = !(bpstat_explains_signal (stop_bpstat)
2032 || trap_expected
2033 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2034 && PC_IN_CALL_DUMMY (stop_pc, read_sp (),
2035 FRAME_FP (get_current_frame ())))
2036 || (step_range_end && step_resume_breakpoint == NULL));
2037
2038 else
2039 {
cd0fc7c3 2040 ecs->random_signal
c906108c 2041 = !(bpstat_explains_signal (stop_bpstat)
c5aa993b
JM
2042 /* End of a stack dummy. Some systems (e.g. Sony
2043 news) give another signal besides SIGTRAP, so
2044 check here as well as above. */
7a292a7a
SS
2045 || (!CALL_DUMMY_BREAKPOINT_OFFSET_P
2046 && PC_IN_CALL_DUMMY (stop_pc, read_sp (),
2047 FRAME_FP (get_current_frame ())))
c5aa993b
JM
2048 );
2049 if (!ecs->random_signal)
2050 stop_signal = TARGET_SIGNAL_TRAP;
2051 }
2052 }
c906108c 2053
c5aa993b
JM
2054 /* When we reach this point, we've pretty much decided
2055 that the reason for stopping must've been a random
2056 (unexpected) signal. */
2057
2058 else
2059 ecs->random_signal = 1;
2060 /* If a fork, vfork or exec event was seen, then there are two
2061 possible responses we can make:
2062
2063 1. If a catchpoint triggers for the event (ecs->random_signal == 0),
2064 then we must stop now and issue a prompt. We will resume
2065 the inferior when the user tells us to.
2066 2. If no catchpoint triggers for the event (ecs->random_signal == 1),
2067 then we must resume the inferior now and keep checking.
2068
2069 In either case, we must take appropriate steps to "follow" the
2070 the fork/vfork/exec when the inferior is resumed. For example,
2071 if follow-fork-mode is "child", then we must detach from the
2072 parent inferior and follow the new child inferior.
2073
2074 In either case, setting pending_follow causes the next resume()
2075 to take the appropriate following action. */
2076 process_event_stop_test:
2077 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
2078 {
2079 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2080 {
2081 trap_expected = 1;
2082 stop_signal = TARGET_SIGNAL_0;
2083 goto keep_going;
2084 }
2085 }
2086 else if (ecs->ws.kind == TARGET_WAITKIND_VFORKED)
2087 {
2088 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2089 {
2090 stop_signal = TARGET_SIGNAL_0;
2091 goto keep_going;
2092 }
2093 }
2094 else if (ecs->ws.kind == TARGET_WAITKIND_EXECD)
2095 {
2096 pending_follow.kind = ecs->ws.kind;
2097 if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */
2098 {
2099 trap_expected = 1;
2100 stop_signal = TARGET_SIGNAL_0;
2101 goto keep_going;
2102 }
2103 }
c906108c 2104
c5aa993b
JM
2105 /* For the program's own signals, act according to
2106 the signal handling tables. */
c906108c 2107
c5aa993b
JM
2108 if (ecs->random_signal)
2109 {
2110 /* Signal not for debugging purposes. */
2111 int printed = 0;
2112
2113 stopped_by_random_signal = 1;
2114
2115 if (signal_print[stop_signal])
2116 {
2117 printed = 1;
2118 target_terminal_ours_for_output ();
2119 annotate_signal ();
2120 printf_filtered ("\nProgram received signal ");
2121 annotate_signal_name ();
2122 printf_filtered ("%s", target_signal_to_name (stop_signal));
2123 annotate_signal_name_end ();
2124 printf_filtered (", ");
2125 annotate_signal_string ();
2126 printf_filtered ("%s", target_signal_to_string (stop_signal));
2127 annotate_signal_string_end ();
2128 printf_filtered (".\n");
2129 gdb_flush (gdb_stdout);
2130 }
2131 if (signal_stop[stop_signal])
2132 goto wfi_break;
2133 /* If not going to stop, give terminal back
2134 if we took it away. */
2135 else if (printed)
2136 target_terminal_inferior ();
2137
2138 /* Clear the signal if it should not be passed. */
2139 if (signal_program[stop_signal] == 0)
2140 stop_signal = TARGET_SIGNAL_0;
2141
a0b3c4fd
JM
2142 /* I'm not sure whether this needs to be check_sigtramp2 or
2143 whether it could/should be keep_going.
2144
2145 This used to jump to step_over_function if we are stepping,
2146 which is wrong.
2147
2148 Suppose the user does a `next' over a function call, and while
2149 that call is in progress, the inferior receives a signal for
2150 which GDB does not stop (i.e., signal_stop[SIG] is false). In
2151 that case, when we reach this point, there is already a
2152 step-resume breakpoint established, right where it should be:
2153 immediately after the function call the user is "next"-ing
2154 over. If we jump to step_over_function now, two bad things
2155 happen:
2156
2157 - we'll create a new breakpoint, at wherever the current
2158 frame's return address happens to be. That could be
2159 anywhere, depending on what function call happens to be on
2160 the top of the stack at that point. Point is, it's probably
2161 not where we need it.
2162
2163 - the existing step-resume breakpoint (which is at the correct
2164 address) will get orphaned: step_resume_breakpoint will point
2165 to the new breakpoint, and the old step-resume breakpoint
2166 will never be cleaned up.
2167
2168 The old behavior was meant to help HP-UX single-step out of
2169 sigtramps. It would place the new breakpoint at prev_pc, which
2170 was certainly wrong. I don't know the details there, so fixing
2171 this probably breaks that. As with anything else, it's up to
2172 the HP-UX maintainer to furnish a fix that doesn't break other
2173 platforms. --JimB, 20 May 1999 */
2174 goto check_sigtramp2;
c5aa993b
JM
2175 }
2176
2177 /* Handle cases caused by hitting a breakpoint. */
2178 {
2179 CORE_ADDR jmp_buf_pc;
2180 struct bpstat_what what;
2181
2182 what = bpstat_what (stop_bpstat);
2183
2184 if (what.call_dummy)
c906108c 2185 {
c5aa993b
JM
2186 stop_stack_dummy = 1;
2187#ifdef HP_OS_BUG
2188 trap_expected_after_continue = 1;
2189#endif
c906108c 2190 }
c5aa993b
JM
2191
2192 switch (what.main_action)
c906108c 2193 {
c5aa993b
JM
2194 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2195 /* If we hit the breakpoint at longjmp, disable it for the
2196 duration of this command. Then, install a temporary
2197 breakpoint at the target of the jmp_buf. */
2198 disable_longjmp_breakpoint ();
2199 remove_breakpoints ();
2200 breakpoints_inserted = 0;
2201 if (!GET_LONGJMP_TARGET (&jmp_buf_pc))
2202 goto keep_going;
2203
2204 /* Need to blow away step-resume breakpoint, as it
2205 interferes with us */
2206 if (step_resume_breakpoint != NULL)
c906108c 2207 {
c5aa993b
JM
2208 delete_breakpoint (step_resume_breakpoint);
2209 step_resume_breakpoint = NULL;
c906108c 2210 }
c5aa993b
JM
2211 /* Not sure whether we need to blow this away too, but probably
2212 it is like the step-resume breakpoint. */
2213 if (through_sigtramp_breakpoint != NULL)
c906108c 2214 {
c5aa993b
JM
2215 delete_breakpoint (through_sigtramp_breakpoint);
2216 through_sigtramp_breakpoint = NULL;
c906108c 2217 }
c906108c 2218
c5aa993b
JM
2219#if 0
2220 /* FIXME - Need to implement nested temporary breakpoints */
2221 if (step_over_calls > 0)
2222 set_longjmp_resume_breakpoint (jmp_buf_pc,
2223 get_current_frame ());
2224 else
2225#endif /* 0 */
2226 set_longjmp_resume_breakpoint (jmp_buf_pc, NULL);
2227 ecs->handling_longjmp = 1; /* FIXME */
2228 goto keep_going;
c906108c 2229
c5aa993b
JM
2230 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2231 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
2232 remove_breakpoints ();
2233 breakpoints_inserted = 0;
2234#if 0
2235 /* FIXME - Need to implement nested temporary breakpoints */
2236 if (step_over_calls
2237 && (INNER_THAN (FRAME_FP (get_current_frame ()),
2238 step_frame_address)))
2239 {
2240 ecs->another_trap = 1;
2241 goto keep_going;
2242 }
2243#endif /* 0 */
2244 disable_longjmp_breakpoint ();
2245 ecs->handling_longjmp = 0; /* FIXME */
2246 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
2247 break;
2248 /* else fallthrough */
c906108c 2249
c5aa993b
JM
2250 case BPSTAT_WHAT_SINGLE:
2251 if (breakpoints_inserted)
c906108c 2252 {
c5aa993b
JM
2253 thread_step_needed = 1;
2254 remove_breakpoints ();
c906108c 2255 }
c5aa993b
JM
2256 breakpoints_inserted = 0;
2257 ecs->another_trap = 1;
2258 /* Still need to check other stuff, at least the case
2259 where we are stepping and step out of the right range. */
2260 break;
c906108c 2261
c5aa993b
JM
2262 case BPSTAT_WHAT_STOP_NOISY:
2263 stop_print_frame = 1;
c906108c 2264
c5aa993b
JM
2265 /* We are about to nuke the step_resume_breakpoint and
2266 through_sigtramp_breakpoint via the cleanup chain, so
2267 no need to worry about it here. */
c906108c 2268
c5aa993b 2269 goto stop_stepping;
c906108c 2270
c5aa993b
JM
2271 case BPSTAT_WHAT_STOP_SILENT:
2272 stop_print_frame = 0;
c906108c 2273
c5aa993b
JM
2274 /* We are about to nuke the step_resume_breakpoint and
2275 through_sigtramp_breakpoint via the cleanup chain, so
2276 no need to worry about it here. */
c906108c 2277
c5aa993b 2278 goto stop_stepping;
c906108c 2279
c5aa993b
JM
2280 case BPSTAT_WHAT_STEP_RESUME:
2281 /* This proably demands a more elegant solution, but, yeah
2282 right...
2283
2284 This function's use of the simple variable
2285 step_resume_breakpoint doesn't seem to accomodate
2286 simultaneously active step-resume bp's, although the
2287 breakpoint list certainly can.
2288
2289 If we reach here and step_resume_breakpoint is already
2290 NULL, then apparently we have multiple active
2291 step-resume bp's. We'll just delete the breakpoint we
2292 stopped at, and carry on. */
2293 if (step_resume_breakpoint == NULL)
2294 {
2295 step_resume_breakpoint =
2296 bpstat_find_step_resume_breakpoint (stop_bpstat);
2297 }
2298 delete_breakpoint (step_resume_breakpoint);
2299 step_resume_breakpoint = NULL;
2300 break;
2301
2302 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
2303 if (through_sigtramp_breakpoint)
2304 delete_breakpoint (through_sigtramp_breakpoint);
2305 through_sigtramp_breakpoint = NULL;
2306
2307 /* If were waiting for a trap, hitting the step_resume_break
2308 doesn't count as getting it. */
2309 if (trap_expected)
2310 ecs->another_trap = 1;
2311 break;
c906108c 2312
c5aa993b
JM
2313 case BPSTAT_WHAT_CHECK_SHLIBS:
2314 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2315#ifdef SOLIB_ADD
c906108c 2316 {
c5aa993b
JM
2317 /* Remove breakpoints, we eventually want to step over the
2318 shlib event breakpoint, and SOLIB_ADD might adjust
2319 breakpoint addresses via breakpoint_re_set. */
2320 if (breakpoints_inserted)
2321 remove_breakpoints ();
c906108c 2322 breakpoints_inserted = 0;
c906108c 2323
c5aa993b
JM
2324 /* Check for any newly added shared libraries if we're
2325 supposed to be adding them automatically. */
2326 if (auto_solib_add)
c906108c 2327 {
c5aa993b
JM
2328 /* Switch terminal for any messages produced by
2329 breakpoint_re_set. */
2330 target_terminal_ours_for_output ();
2331 SOLIB_ADD (NULL, 0, NULL);
2332 target_terminal_inferior ();
c906108c 2333 }
c5aa993b
JM
2334
2335 /* Try to reenable shared library breakpoints, additional
2336 code segments in shared libraries might be mapped in now. */
2337 re_enable_breakpoints_in_shlibs ();
2338
2339 /* If requested, stop when the dynamic linker notifies
2340 gdb of events. This allows the user to get control
2341 and place breakpoints in initializer routines for
2342 dynamically loaded objects (among other things). */
2343 if (stop_on_solib_events)
c906108c 2344 {
c5aa993b
JM
2345 stop_print_frame = 0;
2346 goto stop_stepping;
c906108c
SS
2347 }
2348
c5aa993b
JM
2349 /* If we stopped due to an explicit catchpoint, then the
2350 (see above) call to SOLIB_ADD pulled in any symbols
2351 from a newly-loaded library, if appropriate.
2352
2353 We do want the inferior to stop, but not where it is
2354 now, which is in the dynamic linker callback. Rather,
2355 we would like it stop in the user's program, just after
2356 the call that caused this catchpoint to trigger. That
2357 gives the user a more useful vantage from which to
2358 examine their program's state. */
2359 else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2360 {
2361 /* ??rehrauer: If I could figure out how to get the
2362 right return PC from here, we could just set a temp
2363 breakpoint and resume. I'm not sure we can without
2364 cracking open the dld's shared libraries and sniffing
2365 their unwind tables and text/data ranges, and that's
2366 not a terribly portable notion.
2367
2368 Until that time, we must step the inferior out of the
2369 dld callback, and also out of the dld itself (and any
2370 code or stubs in libdld.sl, such as "shl_load" and
2371 friends) until we reach non-dld code. At that point,
2372 we can stop stepping. */
2373 bpstat_get_triggered_catchpoints (stop_bpstat,
2374 &ecs->stepping_through_solib_catchpoints);
2375 ecs->stepping_through_solib_after_catch = 1;
2376
2377 /* Be sure to lift all breakpoints, so the inferior does
2378 actually step past this point... */
2379 ecs->another_trap = 1;
2380 break;
2381 }
2382 else
c906108c 2383 {
c5aa993b 2384 /* We want to step over this breakpoint, then keep going. */
cd0fc7c3 2385 ecs->another_trap = 1;
c5aa993b 2386 break;
c906108c 2387 }
c5aa993b
JM
2388 }
2389#endif
2390 break;
c906108c 2391
c5aa993b
JM
2392 case BPSTAT_WHAT_LAST:
2393 /* Not a real code, but listed here to shut up gcc -Wall. */
c906108c 2394
c5aa993b
JM
2395 case BPSTAT_WHAT_KEEP_CHECKING:
2396 break;
2397 }
2398 }
c906108c 2399
c5aa993b
JM
2400 /* We come here if we hit a breakpoint but should not
2401 stop for it. Possibly we also were stepping
2402 and should stop for that. So fall through and
2403 test for stepping. But, if not stepping,
2404 do not stop. */
c906108c 2405
c5aa993b
JM
2406 /* Are we stepping to get the inferior out of the dynamic
2407 linker's hook (and possibly the dld itself) after catching
2408 a shlib event? */
2409 if (ecs->stepping_through_solib_after_catch)
2410 {
2411#if defined(SOLIB_ADD)
2412 /* Have we reached our destination? If not, keep going. */
2413 if (SOLIB_IN_DYNAMIC_LINKER (ecs->pid, stop_pc))
2414 {
2415 ecs->another_trap = 1;
2416 goto keep_going;
2417 }
2418#endif
2419 /* Else, stop and report the catchpoint(s) whose triggering
2420 caused us to begin stepping. */
2421 ecs->stepping_through_solib_after_catch = 0;
2422 bpstat_clear (&stop_bpstat);
2423 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2424 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2425 stop_print_frame = 1;
2426 goto stop_stepping;
2427 }
c906108c 2428
c5aa993b
JM
2429 if (!CALL_DUMMY_BREAKPOINT_OFFSET_P)
2430 {
2431 /* This is the old way of detecting the end of the stack dummy.
2432 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
2433 handled above. As soon as we can test it on all of them, all
2434 architectures should define it. */
2435
2436 /* If this is the breakpoint at the end of a stack dummy,
2437 just stop silently, unless the user was doing an si/ni, in which
2438 case she'd better know what she's doing. */
2439
2440 if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (),
2441 FRAME_FP (get_current_frame ()))
2442 && !step_range_end)
2443 {
c906108c 2444 stop_print_frame = 0;
c5aa993b
JM
2445 stop_stack_dummy = 1;
2446#ifdef HP_OS_BUG
2447 trap_expected_after_continue = 1;
2448#endif
2449 goto wfi_break;
2450 }
2451 }
c906108c 2452
c5aa993b
JM
2453 if (step_resume_breakpoint)
2454 /* Having a step-resume breakpoint overrides anything
2455 else having to do with stepping commands until
2456 that breakpoint is reached. */
2457 /* I'm not sure whether this needs to be check_sigtramp2 or
2458 whether it could/should be keep_going. */
2459 goto check_sigtramp2;
2460
2461 if (step_range_end == 0)
2462 /* Likewise if we aren't even stepping. */
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 stepping through a line, keep going if still within it.
2468
2469 Note that step_range_end is the address of the first instruction
2470 beyond the step range, and NOT the address of the last instruction
2471 within it! */
2472 if (stop_pc >= step_range_start
2473 && stop_pc < step_range_end)
2474 {
2475 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
2476 So definately need to check for sigtramp here. */
2477 goto check_sigtramp2;
2478 }
c906108c 2479
c5aa993b 2480 /* We stepped out of the stepping range. */
c906108c 2481
c5aa993b
JM
2482 /* If we are stepping at the source level and entered the runtime
2483 loader dynamic symbol resolution code, we keep on single stepping
2484 until we exit the run time loader code and reach the callee's
2485 address. */
2486 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
2487 goto keep_going;
c906108c 2488
c5aa993b
JM
2489 /* We can't update step_sp every time through the loop, because
2490 reading the stack pointer would slow down stepping too much.
2491 But we can update it every time we leave the step range. */
2492 ecs->update_step_sp = 1;
c906108c 2493
c5aa993b
JM
2494 /* Did we just take a signal? */
2495 if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2496 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2497 && INNER_THAN (read_sp (), step_sp))
2498 {
2499 /* We've just taken a signal; go until we are back to
2500 the point where we took it and one more. */
c906108c 2501
c5aa993b
JM
2502 /* Note: The test above succeeds not only when we stepped
2503 into a signal handler, but also when we step past the last
2504 statement of a signal handler and end up in the return stub
2505 of the signal handler trampoline. To distinguish between
2506 these two cases, check that the frame is INNER_THAN the
2507 previous one below. pai/1997-09-11 */
c906108c 2508
c906108c 2509
c5aa993b
JM
2510 {
2511 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
c906108c 2512
c5aa993b
JM
2513 if (INNER_THAN (current_frame, step_frame_address))
2514 {
2515 /* We have just taken a signal; go until we are back to
2516 the point where we took it and one more. */
c906108c 2517
c5aa993b
JM
2518 /* This code is needed at least in the following case:
2519 The user types "next" and then a signal arrives (before
2520 the "next" is done). */
c906108c 2521
c5aa993b
JM
2522 /* Note that if we are stopped at a breakpoint, then we need
2523 the step_resume breakpoint to override any breakpoints at
2524 the same location, so that we will still step over the
2525 breakpoint even though the signal happened. */
2526 struct symtab_and_line sr_sal;
c906108c 2527
c5aa993b
JM
2528 INIT_SAL (&sr_sal);
2529 sr_sal.symtab = NULL;
2530 sr_sal.line = 0;
2531 sr_sal.pc = prev_pc;
2532 /* We could probably be setting the frame to
2533 step_frame_address; I don't think anyone thought to
2534 try it. */
a0b3c4fd 2535 check_for_old_step_resume_breakpoint ();
c5aa993b
JM
2536 step_resume_breakpoint =
2537 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2538 if (breakpoints_inserted)
2539 insert_breakpoints ();
c906108c 2540 }
c5aa993b 2541 else
c906108c 2542 {
c5aa993b
JM
2543 /* We just stepped out of a signal handler and into
2544 its calling trampoline.
2545
2546 Normally, we'd jump to step_over_function from
2547 here, but for some reason GDB can't unwind the
2548 stack correctly to find the real PC for the point
2549 user code where the signal trampoline will return
2550 -- FRAME_SAVED_PC fails, at least on HP-UX 10.20.
2551 But signal trampolines are pretty small stubs of
2552 code, anyway, so it's OK instead to just
2553 single-step out. Note: assuming such trampolines
2554 don't exhibit recursion on any platform... */
2555 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2556 &ecs->stop_func_start,
2557 &ecs->stop_func_end);
2558 /* Readjust stepping range */
2559 step_range_start = ecs->stop_func_start;
2560 step_range_end = ecs->stop_func_end;
2561 ecs->stepping_through_sigtramp = 1;
c906108c 2562 }
c906108c
SS
2563 }
2564
c906108c 2565
c5aa993b
JM
2566 /* If this is stepi or nexti, make sure that the stepping range
2567 gets us past that instruction. */
2568 if (step_range_end == 1)
2569 /* FIXME: Does this run afoul of the code below which, if
2570 we step into the middle of a line, resets the stepping
2571 range? */
2572 step_range_end = (step_range_start = prev_pc) + 1;
c906108c 2573
c5aa993b 2574 ecs->remove_breakpoints_on_following_step = 1;
c906108c 2575 goto keep_going;
c5aa993b 2576 }
c906108c 2577
c5aa993b
JM
2578 if (stop_pc == ecs->stop_func_start /* Quick test */
2579 || (in_prologue (stop_pc, ecs->stop_func_start) &&
2580 !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2581 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name)
2582 || ecs->stop_func_name == 0)
2583 {
2584 /* It's a subroutine call. */
c906108c 2585
c5aa993b 2586 if (step_over_calls == 0)
c906108c 2587 {
c5aa993b
JM
2588 /* I presume that step_over_calls is only 0 when we're
2589 supposed to be stepping at the assembly language level
2590 ("stepi"). Just stop. */
2591 stop_step = 1;
2592 goto wfi_break;
2593 }
c906108c 2594
c5aa993b
JM
2595 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
2596 /* We're doing a "next". */
2597 goto step_over_function;
2598
2599 /* If we are in a function call trampoline (a stub between
2600 the calling routine and the real function), locate the real
2601 function. That's what tells us (a) whether we want to step
2602 into it at all, and (b) what prologue we want to run to
2603 the end of, if we do step into it. */
2604 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
2605 if (tmp != 0)
2606 ecs->stop_func_start = tmp;
2607 else
2608 {
2609 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
2610 if (tmp)
c906108c 2611 {
c5aa993b
JM
2612 struct symtab_and_line xxx;
2613 /* Why isn't this s_a_l called "sr_sal", like all of the
2614 other s_a_l's where this code is duplicated? */
2615 INIT_SAL (&xxx); /* initialize to zeroes */
2616 xxx.pc = tmp;
2617 xxx.section = find_pc_overlay (xxx.pc);
a0b3c4fd 2618 check_for_old_step_resume_breakpoint ();
c906108c 2619 step_resume_breakpoint =
c5aa993b
JM
2620 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
2621 insert_breakpoints ();
2622 goto keep_going;
c906108c
SS
2623 }
2624 }
2625
c5aa993b
JM
2626 /* If we have line number information for the function we
2627 are thinking of stepping into, step into it.
c906108c 2628
c5aa993b
JM
2629 If there are several symtabs at that PC (e.g. with include
2630 files), just want to know whether *any* of them have line
2631 numbers. find_pc_line handles this. */
2632 {
2633 struct symtab_and_line tmp_sal;
c906108c 2634
c5aa993b
JM
2635 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2636 if (tmp_sal.line != 0)
2637 goto step_into_function;
c906108c
SS
2638 }
2639
c5aa993b
JM
2640 step_over_function:
2641 /* A subroutine call has happened. */
c906108c 2642 {
a0b3c4fd
JM
2643 /* We've just entered a callee, and we wish to resume until it
2644 returns to the caller. Setting a step_resume breakpoint on
2645 the return address will catch a return from the callee.
2646
2647 However, if the callee is recursing, we want to be careful
2648 not to catch returns of those recursive calls, but only of
2649 THIS instance of the call.
c906108c 2650
a0b3c4fd
JM
2651 To do this, we set the step_resume bp's frame to our current
2652 caller's frame (step_frame_address, which is set by the "next"
2653 or "until" command, before execution begins). */
2654 struct symtab_and_line sr_sal;
c5aa993b 2655
a0b3c4fd
JM
2656 INIT_SAL (&sr_sal); /* initialize to zeros */
2657 sr_sal.pc =
2658 ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
2659 sr_sal.section = find_pc_overlay (sr_sal.pc);
c5aa993b 2660
a0b3c4fd 2661 check_for_old_step_resume_breakpoint ();
c5aa993b 2662 step_resume_breakpoint =
a0b3c4fd 2663 set_momentary_breakpoint (sr_sal, get_current_frame (),
c5aa993b
JM
2664 bp_step_resume);
2665
a0b3c4fd 2666 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
c5aa993b 2667 step_resume_breakpoint->frame = step_frame_address;
c906108c 2668
c5aa993b
JM
2669 if (breakpoints_inserted)
2670 insert_breakpoints ();
2671 }
2672 goto keep_going;
c906108c 2673
c5aa993b
JM
2674 step_into_function:
2675 /* Subroutine call with source code we should not step over.
2676 Do step to the first line of code in it. */
2677 {
2678 struct symtab *s;
c906108c 2679
c5aa993b
JM
2680 s = find_pc_symtab (stop_pc);
2681 if (s && s->language != language_asm)
2682 ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start);
2683 }
2684 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2685 /* Use the step_resume_break to step until
2686 the end of the prologue, even if that involves jumps
2687 (as it seems to on the vax under 4.2). */
2688 /* If the prologue ends in the middle of a source line,
2689 continue to the end of that source line (if it is still
2690 within the function). Otherwise, just go to end of prologue. */
2691#ifdef PROLOGUE_FIRSTLINE_OVERLAP
2692 /* no, don't either. It skips any code that's
2693 legitimately on the first line. */
2694#else
2695 if (ecs->sal.end && ecs->sal.pc != ecs->stop_func_start && ecs->sal.end < ecs->stop_func_end)
2696 ecs->stop_func_start = ecs->sal.end;
2697#endif
c906108c 2698
c5aa993b
JM
2699 if (ecs->stop_func_start == stop_pc)
2700 {
2701 /* We are already there: stop now. */
2702 stop_step = 1;
2703 goto wfi_break;
c906108c 2704 }
c5aa993b
JM
2705 else
2706 /* Put the step-breakpoint there and go until there. */
c906108c 2707 {
c906108c
SS
2708 struct symtab_and_line sr_sal;
2709
c5aa993b
JM
2710 INIT_SAL (&sr_sal); /* initialize to zeroes */
2711 sr_sal.pc = ecs->stop_func_start;
2712 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
2713 /* Do not specify what the fp should be when we stop
2714 since on some machines the prologue
2715 is where the new fp value is established. */
a0b3c4fd 2716 check_for_old_step_resume_breakpoint ();
c906108c 2717 step_resume_breakpoint =
c5aa993b 2718 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
c906108c
SS
2719 if (breakpoints_inserted)
2720 insert_breakpoints ();
c906108c 2721
c5aa993b
JM
2722 /* And make sure stepping stops right away then. */
2723 step_range_end = step_range_start;
c906108c 2724 }
c5aa993b
JM
2725 goto keep_going;
2726 }
c906108c 2727
c5aa993b 2728 /* We've wandered out of the step range. */
c906108c 2729
c5aa993b 2730 ecs->sal = find_pc_line (stop_pc, 0);
c906108c 2731
c5aa993b
JM
2732 if (step_range_end == 1)
2733 {
2734 /* It is stepi or nexti. We always want to stop stepping after
2735 one instruction. */
2736 stop_step = 1;
2737 goto wfi_break;
2738 }
c906108c 2739
c5aa993b
JM
2740 /* If we're in the return path from a shared library trampoline,
2741 we want to proceed through the trampoline when stepping. */
2742 if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name))
2743 {
2744 CORE_ADDR tmp;
c906108c 2745
c5aa993b
JM
2746 /* Determine where this trampoline returns. */
2747 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
c906108c 2748
c5aa993b
JM
2749 /* Only proceed through if we know where it's going. */
2750 if (tmp)
2751 {
2752 /* And put the step-breakpoint there and go until there. */
2753 struct symtab_and_line sr_sal;
c906108c 2754
c5aa993b
JM
2755 INIT_SAL (&sr_sal); /* initialize to zeroes */
2756 sr_sal.pc = tmp;
2757 sr_sal.section = find_pc_overlay (sr_sal.pc);
2758 /* Do not specify what the fp should be when we stop
2759 since on some machines the prologue
2760 is where the new fp value is established. */
a0b3c4fd 2761 check_for_old_step_resume_breakpoint ();
c5aa993b
JM
2762 step_resume_breakpoint =
2763 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
2764 if (breakpoints_inserted)
2765 insert_breakpoints ();
c906108c 2766
c5aa993b
JM
2767 /* Restart without fiddling with the step ranges or
2768 other state. */
2769 goto keep_going;
2770 }
2771 }
c906108c 2772
c5aa993b 2773 if (ecs->sal.line == 0)
c906108c 2774 {
c5aa993b
JM
2775 /* We have no line number information. That means to stop
2776 stepping (does this always happen right after one instruction,
2777 when we do "s" in a function with no line numbers,
2778 or can this happen as a result of a return or longjmp?). */
2779 stop_step = 1;
2780 goto wfi_break;
c906108c
SS
2781 }
2782
c5aa993b
JM
2783 if ((stop_pc == ecs->sal.pc)
2784 && (ecs->current_line != ecs->sal.line || ecs->current_symtab != ecs->sal.symtab))
2785 {
2786 /* We are at the start of a different line. So stop. Note that
2787 we don't stop if we step into the middle of a different line.
2788 That is said to make things like for (;;) statements work
2789 better. */
2790 stop_step = 1;
2791 goto wfi_break;
2792 }
c906108c 2793
c5aa993b 2794 /* We aren't done stepping.
c906108c 2795
c5aa993b
JM
2796 Optimize by setting the stepping range to the line.
2797 (We might not be in the original line, but if we entered a
2798 new line in mid-statement, we continue stepping. This makes
2799 things like for(;;) statements work better.) */
c906108c 2800
c5aa993b
JM
2801 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2802 {
2803 /* If this is the last line of the function, don't keep stepping
2804 (it would probably step us out of the function).
2805 This is particularly necessary for a one-line function,
2806 in which after skipping the prologue we better stop even though
2807 we will be in mid-line. */
2808 stop_step = 1;
2809 goto wfi_break;
2810 }
2811 step_range_start = ecs->sal.pc;
2812 step_range_end = ecs->sal.end;
2813 step_frame_address = FRAME_FP (get_current_frame ());
2814 ecs->current_line = ecs->sal.line;
2815 ecs->current_symtab = ecs->sal.symtab;
2816
2817 /* In the case where we just stepped out of a function into the middle
2818 of a line of the caller, continue stepping, but step_frame_address
2819 must be modified to current frame */
2820 {
2821 CORE_ADDR current_frame = FRAME_FP (get_current_frame ());
2822 if (!(INNER_THAN (current_frame, step_frame_address)))
2823 step_frame_address = current_frame;
2824 }
c906108c 2825
c906108c 2826
c5aa993b 2827 goto keep_going;
c906108c 2828
c5aa993b
JM
2829 check_sigtramp2:
2830 if (trap_expected
2831 && IN_SIGTRAMP (stop_pc, ecs->stop_func_name)
2832 && !IN_SIGTRAMP (prev_pc, prev_func_name)
2833 && INNER_THAN (read_sp (), step_sp))
2834 {
2835 /* What has happened here is that we have just stepped the inferior
2836 with a signal (because it is a signal which shouldn't make
2837 us stop), thus stepping into sigtramp.
2838
2839 So we need to set a step_resume_break_address breakpoint
2840 and continue until we hit it, and then step. FIXME: This should
2841 be more enduring than a step_resume breakpoint; we should know
2842 that we will later need to keep going rather than re-hitting
2843 the breakpoint here (see testsuite/gdb.t06/signals.exp where
2844 it says "exceedingly difficult"). */
2845 struct symtab_and_line sr_sal;
2846
2847 INIT_SAL (&sr_sal); /* initialize to zeroes */
2848 sr_sal.pc = prev_pc;
2849 sr_sal.section = find_pc_overlay (sr_sal.pc);
2850 /* We perhaps could set the frame if we kept track of what
2851 the frame corresponding to prev_pc was. But we don't,
2852 so don't. */
2853 through_sigtramp_breakpoint =
2854 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
2855 if (breakpoints_inserted)
2856 insert_breakpoints ();
c906108c 2857
c5aa993b
JM
2858 ecs->remove_breakpoints_on_following_step = 1;
2859 ecs->another_trap = 1;
2860 }
c906108c 2861
c5aa993b
JM
2862 keep_going:
2863 /* Come to this label when you need to resume the inferior.
2864 It's really much cleaner to do a goto than a maze of if-else
2865 conditions. */
2866
2867 /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug
2868 a vforked child beetween its creation and subsequent exit or
2869 call to exec(). However, I had big problems in this rather
2870 creaky exec engine, getting that to work. The fundamental
2871 problem is that I'm trying to debug two processes via an
2872 engine that only understands a single process with possibly
2873 multiple threads.
2874
2875 Hence, this spot is known to have problems when
2876 target_can_follow_vfork_prior_to_exec returns 1. */
2877
2878 /* Save the pc before execution, to compare with pc after stop. */
2879 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2880 prev_func_start = ecs->stop_func_start; /* Ok, since if DECR_PC_AFTER
2881 BREAK is defined, the
2882 original pc would not have
2883 been at the start of a
2884 function. */
2885 prev_func_name = ecs->stop_func_name;
2886
2887 if (ecs->update_step_sp)
2888 step_sp = read_sp ();
2889 ecs->update_step_sp = 0;
2890
2891 /* If we did not do break;, it means we should keep
2892 running the inferior and not return to debugger. */
2893
2894 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2895 {
2896 /* We took a signal (which we are supposed to pass through to
2897 the inferior, else we'd have done a break above) and we
2898 haven't yet gotten our trap. Simply continue. */
2899 resume (currently_stepping (ecs), stop_signal);
2900 }
2901 else
2902 {
2903 /* Either the trap was not expected, but we are continuing
2904 anyway (the user asked that this signal be passed to the
2905 child)
2906 -- or --
2907 The signal was SIGTRAP, e.g. it was our signal, but we
2908 decided we should resume from it.
2909
2910 We're going to run this baby now!
2911
2912 Insert breakpoints now, unless we are trying
2913 to one-proceed past a breakpoint. */
2914 /* If we've just finished a special step resume and we don't
2915 want to hit a breakpoint, pull em out. */
2916 if (step_resume_breakpoint == NULL
2917 && through_sigtramp_breakpoint == NULL
2918 && ecs->remove_breakpoints_on_following_step)
2919 {
2920 ecs->remove_breakpoints_on_following_step = 0;
2921 remove_breakpoints ();
2922 breakpoints_inserted = 0;
2923 }
2924 else if (!breakpoints_inserted &&
2925 (through_sigtramp_breakpoint != NULL || !ecs->another_trap))
2926 {
2927 breakpoints_failed = insert_breakpoints ();
2928 if (breakpoints_failed)
2929 goto wfi_break;
2930 breakpoints_inserted = 1;
2931 }
c906108c 2932
c5aa993b 2933 trap_expected = ecs->another_trap;
c906108c 2934
c5aa993b
JM
2935 /* Do not deliver SIGNAL_TRAP (except when the user
2936 explicitly specifies that such a signal should be
2937 delivered to the target program).
c906108c 2938
c5aa993b
JM
2939 Typically, this would occure when a user is debugging a
2940 target monitor on a simulator: the target monitor sets a
2941 breakpoint; the simulator encounters this break-point and
2942 halts the simulation handing control to GDB; GDB, noteing
2943 that the break-point isn't valid, returns control back to
2944 the simulator; the simulator then delivers the hardware
2945 equivalent of a SIGNAL_TRAP to the program being
2946 debugged. */
c906108c 2947
c5aa993b
JM
2948 if (stop_signal == TARGET_SIGNAL_TRAP
2949 && !signal_program[stop_signal])
2950 stop_signal = TARGET_SIGNAL_0;
c906108c
SS
2951
2952#ifdef SHIFT_INST_REGS
c5aa993b
JM
2953 /* I'm not sure when this following segment applies. I do know,
2954 now, that we shouldn't rewrite the regs when we were stopped
2955 by a random signal from the inferior process. */
2956 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
2957 (this is only used on the 88k). */
2958
2959 if (!bpstat_explains_signal (stop_bpstat)
2960 && (stop_signal != TARGET_SIGNAL_CHLD)
2961 && !stopped_by_random_signal)
2962 SHIFT_INST_REGS ();
c906108c
SS
2963#endif /* SHIFT_INST_REGS */
2964
c5aa993b
JM
2965 resume (currently_stepping (ecs), stop_signal);
2966 }
cd0fc7c3 2967
c5aa993b
JM
2968 /* Former continues in the main loop goto here. */
2969 wfi_continue:
2970 /* This used to be at the top of the loop. */
2971 if (ecs->infwait_state == infwait_normal_state)
2972 {
2973 overlay_cache_invalid = 1;
cd0fc7c3 2974
c5aa993b
JM
2975 /* We have to invalidate the registers BEFORE calling
2976 target_wait because they can be loaded from the target
2977 while in target_wait. This makes remote debugging a bit
2978 more efficient for those targets that provide critical
2979 registers as part of their normal status mechanism. */
cd0fc7c3 2980
c5aa993b
JM
2981 registers_changed ();
2982 ecs->waiton_pid = -1;
2983 ecs->wp = &(ecs->ws);
2984 }
2985 /* This is the old end of the while loop. Let everybody know
2986 we want to wait for the inferior some more and get called
2987 again soon. */
2988 ecs->wait_some_more = 1;
2989 return;
2990 }
c906108c 2991
cd0fc7c3
SS
2992 /* Former breaks in the main loop goto here. */
2993wfi_break:
2994
c906108c
SS
2995stop_stepping:
2996 if (target_has_execution)
2997 {
2998 /* Are we stopping for a vfork event? We only stop when we see
2999 the child's event. However, we may not yet have seen the
3000 parent's event. And, inferior_pid is still set to the parent's
3001 pid, until we resume again and follow either the parent or child.
3002
3003 To ensure that we can really touch inferior_pid (aka, the
3004 parent process) -- which calls to functions like read_pc
3005 implicitly do -- wait on the parent if necessary. */
3006 if ((pending_follow.kind == TARGET_WAITKIND_VFORKED)
3007 && !pending_follow.fork_event.saw_parent_fork)
3008 {
3009 int parent_pid;
3010
3011 do
3012 {
3013 if (target_wait_hook)
cd0fc7c3 3014 parent_pid = target_wait_hook (-1, &(ecs->ws));
c906108c 3015 else
cd0fc7c3 3016 parent_pid = target_wait (-1, &(ecs->ws));
c906108c
SS
3017 }
3018 while (parent_pid != inferior_pid);
3019 }
3020
c906108c 3021 /* Assuming the inferior still exists, set these up for next
c5aa993b
JM
3022 time, just like we did above if we didn't break out of the
3023 loop. */
c906108c 3024 prev_pc = read_pc ();
cd0fc7c3
SS
3025 prev_func_start = ecs->stop_func_start;
3026 prev_func_name = ecs->stop_func_name;
c906108c 3027 }
cd0fc7c3
SS
3028 /* Let callers know we don't want to wait for the inferior anymore. */
3029 ecs->wait_some_more = 0;
3030}
3031
3032/* Are we in the middle of stepping? */
3033
392a587b 3034static int
96baa820 3035currently_stepping (struct execution_control_state *ecs)
cd0fc7c3
SS
3036{
3037 return ((through_sigtramp_breakpoint == NULL
3038 && !ecs->handling_longjmp
3039 && ((step_range_end && step_resume_breakpoint == NULL)
3040 || trap_expected))
3041 || ecs->stepping_through_solib_after_catch
3042 || bpstat_should_step ());
c906108c
SS
3043}
3044
3045/* This function returns TRUE if ep is an internal breakpoint
3046 set to catch generic shared library (aka dynamically-linked
3047 library) events. (This is *NOT* the same as a catchpoint for a
3048 shlib event. The latter is something a user can set; this is
3049 something gdb sets for its own use, and isn't ever shown to a
3050 user.) */
3051static int
96baa820 3052is_internal_shlib_eventpoint (struct breakpoint *ep)
c906108c
SS
3053{
3054 return
3055 (ep->type == bp_shlib_event)
3056 ;
3057}
3058
3059/* This function returns TRUE if bs indicates that the inferior
3060 stopped due to a shared library (aka dynamically-linked library)
3061 event. */
96baa820 3062
c906108c 3063static int
96baa820 3064stopped_for_internal_shlib_event (bpstat bs)
c906108c
SS
3065{
3066 /* Note that multiple eventpoints may've caused the stop. Any
3067 that are associated with shlib events will be accepted. */
3068 for (; bs != NULL; bs = bs->next)
3069 {
3070 if ((bs->breakpoint_at != NULL)
3071 && is_internal_shlib_eventpoint (bs->breakpoint_at))
3072 return 1;
3073 }
3074
3075 /* If we get here, then no candidate was found. */
3076 return 0;
3077}
c906108c 3078\f
43ff13b4
JM
3079/* Reset proper settings after an asynchronous command has finished.
3080 If the execution command was in synchronous mode, register stdin
3081 with the event loop, and reset the prompt. */
96baa820 3082
43ff13b4 3083static void
96baa820 3084complete_execution (void)
43ff13b4 3085{
96baa820 3086 extern int cleanup_sigint_signal_handler (void);
43ff13b4 3087
adf40b2e 3088 target_executing = 0;
43ff13b4
JM
3089 if (sync_execution)
3090 {
7be570e7 3091 add_file_handler (input_fd, call_readline, 0);
43ff13b4
JM
3092 pop_prompt ();
3093 sync_execution = 0;
3094 cleanup_sigint_signal_handler ();
3095 display_gdb_prompt (0);
3096 }
43ff13b4
JM
3097}
3098
c906108c
SS
3099/* Here to return control to GDB when the inferior stops for real.
3100 Print appropriate messages, remove breakpoints, give terminal our modes.
3101
3102 STOP_PRINT_FRAME nonzero means print the executing frame
3103 (pc, function, args, file, line number and line text).
3104 BREAKPOINTS_FAILED nonzero means stop was due to error
3105 attempting to insert breakpoints. */
3106
3107void
96baa820 3108normal_stop (void)
c906108c 3109{
c906108c
SS
3110 /* As with the notification of thread events, we want to delay
3111 notifying the user that we've switched thread context until
3112 the inferior actually stops.
3113
3114 (Note that there's no point in saying anything if the inferior
3115 has exited!) */
7a292a7a
SS
3116 if (may_switch_from_inferior_pid
3117 && (switched_from_inferior_pid != inferior_pid)
3118 && target_has_execution)
c906108c
SS
3119 {
3120 target_terminal_ours_for_output ();
3121 printf_filtered ("[Switched to %s]\n",
3122 target_pid_or_tid_to_str (inferior_pid));
3123 switched_from_inferior_pid = inferior_pid;
3124 }
c906108c
SS
3125
3126 /* Make sure that the current_frame's pc is correct. This
3127 is a correction for setting up the frame info before doing
3128 DECR_PC_AFTER_BREAK */
3129 if (target_has_execution && get_current_frame ())
3130 (get_current_frame ())->pc = read_pc ();
3131
3132 if (breakpoints_failed)
3133 {
3134 target_terminal_ours_for_output ();
3135 print_sys_errmsg ("ptrace", breakpoints_failed);
3136 printf_filtered ("Stopped; cannot insert breakpoints.\n\
3137The same program may be running in another process.\n");
3138 }
3139
3140 if (target_has_execution && breakpoints_inserted)
3141 {
3142 if (remove_breakpoints ())
3143 {
3144 target_terminal_ours_for_output ();
3145 printf_filtered ("Cannot remove breakpoints because ");
3146 printf_filtered ("program is no longer writable.\n");
3147 printf_filtered ("It might be running in another process.\n");
3148 printf_filtered ("Further execution is probably impossible.\n");
3149 }
3150 }
3151 breakpoints_inserted = 0;
3152
3153 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3154 Delete any breakpoint that is to be deleted at the next stop. */
3155
3156 breakpoint_auto_delete (stop_bpstat);
3157
3158 /* If an auto-display called a function and that got a signal,
3159 delete that auto-display to avoid an infinite recursion. */
3160
3161 if (stopped_by_random_signal)
3162 disable_current_display ();
3163
3164 /* Don't print a message if in the middle of doing a "step n"
3165 operation for n > 1 */
3166 if (step_multi && stop_step)
3167 goto done;
3168
3169 target_terminal_ours ();
3170
3171 /* Did we stop because the user set the stop_on_solib_events
3172 variable? (If so, we report this as a generic, "Stopped due
3173 to shlib event" message.) */
3174 if (stopped_for_internal_shlib_event (stop_bpstat))
3175 {
3176 printf_filtered ("Stopped due to shared library event\n");
3177 }
3178
3179 /* Look up the hook_stop and run it if it exists. */
3180
3181 if (stop_command && stop_command->hook)
3182 {
3183 catch_errors (hook_stop_stub, stop_command->hook,
3184 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3185 }
3186
3187 if (!target_has_stack)
3188 {
3189
3190 goto done;
3191 }
3192
3193 /* Select innermost stack frame - i.e., current frame is frame 0,
3194 and current location is based on that.
3195 Don't do this on return from a stack dummy routine,
3196 or if the program has exited. */
3197
3198 if (!stop_stack_dummy)
3199 {
3200 select_frame (get_current_frame (), 0);
3201
3202 /* Print current location without a level number, if
c5aa993b
JM
3203 we have changed functions or hit a breakpoint.
3204 Print source line if we have one.
3205 bpstat_print() contains the logic deciding in detail
3206 what to print, based on the event(s) that just occurred. */
c906108c
SS
3207
3208 if (stop_print_frame)
3209 {
3210 int bpstat_ret;
3211 int source_flag;
3212
3213 bpstat_ret = bpstat_print (stop_bpstat);
3214 /* bpstat_print() returned one of:
c5aa993b
JM
3215 -1: Didn't print anything
3216 0: Printed preliminary "Breakpoint n, " message, desires
3217 location tacked on
3218 1: Printed something, don't tack on location */
c906108c
SS
3219
3220 if (bpstat_ret == -1)
3221 if (stop_step
3222 && step_frame_address == FRAME_FP (get_current_frame ())
3223 && step_start_function == find_pc_function (stop_pc))
3224 source_flag = -1; /* finished step, just print source line */
3225 else
3226 source_flag = 1; /* print location and source line */
3227 else if (bpstat_ret == 0) /* hit bpt, desire location */
3228 source_flag = 1; /* print location and source line */
3229 else /* bpstat_ret == 1, hit bpt, do not desire location */
3230 source_flag = -1; /* just print source line */
3231
3232 /* The behavior of this routine with respect to the source
3233 flag is:
3234 -1: Print only source line
3235 0: Print only location
3236 1: Print location and source line */
3237 show_and_print_stack_frame (selected_frame, -1, source_flag);
3238
3239 /* Display the auto-display expressions. */
3240 do_displays ();
3241 }
3242 }
3243
3244 /* Save the function value return registers, if we care.
3245 We might be about to restore their previous contents. */
3246 if (proceed_to_finish)
3247 read_register_bytes (0, stop_registers, REGISTER_BYTES);
3248
3249 if (stop_stack_dummy)
3250 {
3251 /* Pop the empty frame that contains the stack dummy.
3252 POP_FRAME ends with a setting of the current frame, so we
c5aa993b 3253 can use that next. */
c906108c
SS
3254 POP_FRAME;
3255 /* Set stop_pc to what it was before we called the function.
c5aa993b
JM
3256 Can't rely on restore_inferior_status because that only gets
3257 called if we don't stop in the called function. */
c906108c
SS
3258 stop_pc = read_pc ();
3259 select_frame (get_current_frame (), 0);
3260 }
3261
3262
3263 TUIDO (((TuiOpaqueFuncPtr) tui_vCheckDataValues, selected_frame));
3264
3265done:
3266 annotate_stopped ();
3267}
3268
3269static int
96baa820 3270hook_stop_stub (void *cmd)
c906108c
SS
3271{
3272 execute_user_command ((struct cmd_list_element *) cmd, 0);
3273 return (0);
3274}
3275\f
c5aa993b 3276int
96baa820 3277signal_stop_state (int signo)
c906108c
SS
3278{
3279 return signal_stop[signo];
3280}
3281
c5aa993b 3282int
96baa820 3283signal_print_state (int signo)
c906108c
SS
3284{
3285 return signal_print[signo];
3286}
3287
c5aa993b 3288int
96baa820 3289signal_pass_state (int signo)
c906108c
SS
3290{
3291 return signal_program[signo];
3292}
3293
3294static void
96baa820 3295sig_print_header (void)
c906108c
SS
3296{
3297 printf_filtered ("\
3298Signal Stop\tPrint\tPass to program\tDescription\n");
3299}
3300
3301static void
96baa820 3302sig_print_info (enum target_signal oursig)
c906108c
SS
3303{
3304 char *name = target_signal_to_name (oursig);
3305 int name_padding = 13 - strlen (name);
96baa820 3306
c906108c
SS
3307 if (name_padding <= 0)
3308 name_padding = 0;
3309
3310 printf_filtered ("%s", name);
3311 printf_filtered ("%*.*s ", name_padding, name_padding,
3312 " ");
3313 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3314 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3315 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3316 printf_filtered ("%s\n", target_signal_to_string (oursig));
3317}
3318
3319/* Specify how various signals in the inferior should be handled. */
3320
3321static void
96baa820 3322handle_command (char *args, int from_tty)
c906108c
SS
3323{
3324 char **argv;
3325 int digits, wordlen;
3326 int sigfirst, signum, siglast;
3327 enum target_signal oursig;
3328 int allsigs;
3329 int nsigs;
3330 unsigned char *sigs;
3331 struct cleanup *old_chain;
3332
3333 if (args == NULL)
3334 {
3335 error_no_arg ("signal to handle");
3336 }
3337
3338 /* Allocate and zero an array of flags for which signals to handle. */
3339
3340 nsigs = (int) TARGET_SIGNAL_LAST;
3341 sigs = (unsigned char *) alloca (nsigs);
3342 memset (sigs, 0, nsigs);
3343
3344 /* Break the command line up into args. */
3345
3346 argv = buildargv (args);
3347 if (argv == NULL)
3348 {
3349 nomem (0);
3350 }
7a292a7a 3351 old_chain = make_cleanup_freeargv (argv);
c906108c
SS
3352
3353 /* Walk through the args, looking for signal oursigs, signal names, and
3354 actions. Signal numbers and signal names may be interspersed with
3355 actions, with the actions being performed for all signals cumulatively
3356 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3357
3358 while (*argv != NULL)
3359 {
3360 wordlen = strlen (*argv);
3361 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3362 {;
3363 }
3364 allsigs = 0;
3365 sigfirst = siglast = -1;
3366
3367 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3368 {
3369 /* Apply action to all signals except those used by the
3370 debugger. Silently skip those. */
3371 allsigs = 1;
3372 sigfirst = 0;
3373 siglast = nsigs - 1;
3374 }
3375 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3376 {
3377 SET_SIGS (nsigs, sigs, signal_stop);
3378 SET_SIGS (nsigs, sigs, signal_print);
3379 }
3380 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3381 {
3382 UNSET_SIGS (nsigs, sigs, signal_program);
3383 }
3384 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3385 {
3386 SET_SIGS (nsigs, sigs, signal_print);
3387 }
3388 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3389 {
3390 SET_SIGS (nsigs, sigs, signal_program);
3391 }
3392 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3393 {
3394 UNSET_SIGS (nsigs, sigs, signal_stop);
3395 }
3396 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3397 {
3398 SET_SIGS (nsigs, sigs, signal_program);
3399 }
3400 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3401 {
3402 UNSET_SIGS (nsigs, sigs, signal_print);
3403 UNSET_SIGS (nsigs, sigs, signal_stop);
3404 }
3405 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3406 {
3407 UNSET_SIGS (nsigs, sigs, signal_program);
3408 }
3409 else if (digits > 0)
3410 {
3411 /* It is numeric. The numeric signal refers to our own
3412 internal signal numbering from target.h, not to host/target
3413 signal number. This is a feature; users really should be
3414 using symbolic names anyway, and the common ones like
3415 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3416
3417 sigfirst = siglast = (int)
3418 target_signal_from_command (atoi (*argv));
3419 if ((*argv)[digits] == '-')
3420 {
3421 siglast = (int)
3422 target_signal_from_command (atoi ((*argv) + digits + 1));
3423 }
3424 if (sigfirst > siglast)
3425 {
3426 /* Bet he didn't figure we'd think of this case... */
3427 signum = sigfirst;
3428 sigfirst = siglast;
3429 siglast = signum;
3430 }
3431 }
3432 else
3433 {
3434 oursig = target_signal_from_name (*argv);
3435 if (oursig != TARGET_SIGNAL_UNKNOWN)
3436 {
3437 sigfirst = siglast = (int) oursig;
3438 }
3439 else
3440 {
3441 /* Not a number and not a recognized flag word => complain. */
3442 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
3443 }
3444 }
3445
3446 /* If any signal numbers or symbol names were found, set flags for
c5aa993b 3447 which signals to apply actions to. */
c906108c
SS
3448
3449 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3450 {
3451 switch ((enum target_signal) signum)
3452 {
3453 case TARGET_SIGNAL_TRAP:
3454 case TARGET_SIGNAL_INT:
3455 if (!allsigs && !sigs[signum])
3456 {
3457 if (query ("%s is used by the debugger.\n\
3458Are you sure you want to change it? ",
3459 target_signal_to_name
3460 ((enum target_signal) signum)))
3461 {
3462 sigs[signum] = 1;
3463 }
3464 else
3465 {
3466 printf_unfiltered ("Not confirmed, unchanged.\n");
3467 gdb_flush (gdb_stdout);
3468 }
3469 }
3470 break;
3471 case TARGET_SIGNAL_0:
3472 case TARGET_SIGNAL_DEFAULT:
3473 case TARGET_SIGNAL_UNKNOWN:
3474 /* Make sure that "all" doesn't print these. */
3475 break;
3476 default:
3477 sigs[signum] = 1;
3478 break;
3479 }
3480 }
3481
3482 argv++;
3483 }
3484
3485 target_notice_signals (inferior_pid);
3486
3487 if (from_tty)
3488 {
3489 /* Show the results. */
3490 sig_print_header ();
3491 for (signum = 0; signum < nsigs; signum++)
3492 {
3493 if (sigs[signum])
3494 {
3495 sig_print_info (signum);
3496 }
3497 }
3498 }
3499
3500 do_cleanups (old_chain);
3501}
3502
3503static void
96baa820 3504xdb_handle_command (char *args, int from_tty)
c906108c
SS
3505{
3506 char **argv;
3507 struct cleanup *old_chain;
3508
3509 /* Break the command line up into args. */
3510
3511 argv = buildargv (args);
3512 if (argv == NULL)
3513 {
3514 nomem (0);
3515 }
7a292a7a 3516 old_chain = make_cleanup_freeargv (argv);
c906108c
SS
3517 if (argv[1] != (char *) NULL)
3518 {
3519 char *argBuf;
3520 int bufLen;
3521
3522 bufLen = strlen (argv[0]) + 20;
3523 argBuf = (char *) xmalloc (bufLen);
3524 if (argBuf)
3525 {
3526 int validFlag = 1;
3527 enum target_signal oursig;
3528
3529 oursig = target_signal_from_name (argv[0]);
3530 memset (argBuf, 0, bufLen);
3531 if (strcmp (argv[1], "Q") == 0)
3532 sprintf (argBuf, "%s %s", argv[0], "noprint");
3533 else
3534 {
3535 if (strcmp (argv[1], "s") == 0)
3536 {
3537 if (!signal_stop[oursig])
3538 sprintf (argBuf, "%s %s", argv[0], "stop");
3539 else
3540 sprintf (argBuf, "%s %s", argv[0], "nostop");
3541 }
3542 else if (strcmp (argv[1], "i") == 0)
3543 {
3544 if (!signal_program[oursig])
3545 sprintf (argBuf, "%s %s", argv[0], "pass");
3546 else
3547 sprintf (argBuf, "%s %s", argv[0], "nopass");
3548 }
3549 else if (strcmp (argv[1], "r") == 0)
3550 {
3551 if (!signal_print[oursig])
3552 sprintf (argBuf, "%s %s", argv[0], "print");
3553 else
3554 sprintf (argBuf, "%s %s", argv[0], "noprint");
3555 }
3556 else
3557 validFlag = 0;
3558 }
3559 if (validFlag)
3560 handle_command (argBuf, from_tty);
3561 else
3562 printf_filtered ("Invalid signal handling flag.\n");
3563 if (argBuf)
3564 free (argBuf);
3565 }
3566 }
3567 do_cleanups (old_chain);
3568}
3569
3570/* Print current contents of the tables set by the handle command.
3571 It is possible we should just be printing signals actually used
3572 by the current target (but for things to work right when switching
3573 targets, all signals should be in the signal tables). */
3574
3575static void
96baa820 3576signals_info (char *signum_exp, int from_tty)
c906108c
SS
3577{
3578 enum target_signal oursig;
3579 sig_print_header ();
3580
3581 if (signum_exp)
3582 {
3583 /* First see if this is a symbol name. */
3584 oursig = target_signal_from_name (signum_exp);
3585 if (oursig == TARGET_SIGNAL_UNKNOWN)
3586 {
3587 /* No, try numeric. */
3588 oursig =
3589 target_signal_from_command (parse_and_eval_address (signum_exp));
3590 }
3591 sig_print_info (oursig);
3592 return;
3593 }
3594
3595 printf_filtered ("\n");
3596 /* These ugly casts brought to you by the native VAX compiler. */
3597 for (oursig = TARGET_SIGNAL_FIRST;
3598 (int) oursig < (int) TARGET_SIGNAL_LAST;
3599 oursig = (enum target_signal) ((int) oursig + 1))
3600 {
3601 QUIT;
3602
3603 if (oursig != TARGET_SIGNAL_UNKNOWN
3604 && oursig != TARGET_SIGNAL_DEFAULT
3605 && oursig != TARGET_SIGNAL_0)
3606 sig_print_info (oursig);
3607 }
3608
3609 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
3610}
3611\f
7a292a7a
SS
3612struct inferior_status
3613{
3614 enum target_signal stop_signal;
3615 CORE_ADDR stop_pc;
3616 bpstat stop_bpstat;
3617 int stop_step;
3618 int stop_stack_dummy;
3619 int stopped_by_random_signal;
3620 int trap_expected;
3621 CORE_ADDR step_range_start;
3622 CORE_ADDR step_range_end;
3623 CORE_ADDR step_frame_address;
3624 int step_over_calls;
3625 CORE_ADDR step_resume_break_address;
3626 int stop_after_trap;
3627 int stop_soon_quietly;
3628 CORE_ADDR selected_frame_address;
3629 char *stop_registers;
3630
3631 /* These are here because if call_function_by_hand has written some
3632 registers and then decides to call error(), we better not have changed
3633 any registers. */
3634 char *registers;
3635
3636 int selected_level;
3637 int breakpoint_proceeded;
3638 int restore_stack_info;
3639 int proceed_to_finish;
3640};
3641
7a292a7a 3642static struct inferior_status *
96baa820 3643xmalloc_inferior_status (void)
7a292a7a
SS
3644{
3645 struct inferior_status *inf_status;
3646 inf_status = xmalloc (sizeof (struct inferior_status));
3647 inf_status->stop_registers = xmalloc (REGISTER_BYTES);
3648 inf_status->registers = xmalloc (REGISTER_BYTES);
3649 return inf_status;
3650}
3651
7a292a7a 3652static void
96baa820 3653free_inferior_status (struct inferior_status *inf_status)
7a292a7a
SS
3654{
3655 free (inf_status->registers);
3656 free (inf_status->stop_registers);
3657 free (inf_status);
3658}
3659
3660void
96baa820
JM
3661write_inferior_status_register (struct inferior_status *inf_status, int regno,
3662 LONGEST val)
7a292a7a 3663{
c5aa993b 3664 int size = REGISTER_RAW_SIZE (regno);
7a292a7a
SS
3665 void *buf = alloca (size);
3666 store_signed_integer (buf, size, val);
3667 memcpy (&inf_status->registers[REGISTER_BYTE (regno)], buf, size);
3668}
3669
c906108c
SS
3670/* Save all of the information associated with the inferior<==>gdb
3671 connection. INF_STATUS is a pointer to a "struct inferior_status"
3672 (defined in inferior.h). */
3673
7a292a7a 3674struct inferior_status *
96baa820 3675save_inferior_status (int restore_stack_info)
c906108c 3676{
7a292a7a
SS
3677 struct inferior_status *inf_status = xmalloc_inferior_status ();
3678
c906108c
SS
3679 inf_status->stop_signal = stop_signal;
3680 inf_status->stop_pc = stop_pc;
3681 inf_status->stop_step = stop_step;
3682 inf_status->stop_stack_dummy = stop_stack_dummy;
3683 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3684 inf_status->trap_expected = trap_expected;
3685 inf_status->step_range_start = step_range_start;
3686 inf_status->step_range_end = step_range_end;
3687 inf_status->step_frame_address = step_frame_address;
3688 inf_status->step_over_calls = step_over_calls;
3689 inf_status->stop_after_trap = stop_after_trap;
3690 inf_status->stop_soon_quietly = stop_soon_quietly;
3691 /* Save original bpstat chain here; replace it with copy of chain.
3692 If caller's caller is walking the chain, they'll be happier if we
7a292a7a
SS
3693 hand them back the original chain when restore_inferior_status is
3694 called. */
c906108c
SS
3695 inf_status->stop_bpstat = stop_bpstat;
3696 stop_bpstat = bpstat_copy (stop_bpstat);
3697 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3698 inf_status->restore_stack_info = restore_stack_info;
3699 inf_status->proceed_to_finish = proceed_to_finish;
c5aa993b 3700
c906108c
SS
3701 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
3702
3703 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3704
3705 record_selected_frame (&(inf_status->selected_frame_address),
3706 &(inf_status->selected_level));
7a292a7a 3707 return inf_status;
c906108c
SS
3708}
3709
3710struct restore_selected_frame_args
3711{
3712 CORE_ADDR frame_address;
3713 int level;
3714};
3715
c906108c 3716static int
96baa820 3717restore_selected_frame (void *args)
c906108c
SS
3718{
3719 struct restore_selected_frame_args *fr =
3720 (struct restore_selected_frame_args *) args;
3721 struct frame_info *frame;
3722 int level = fr->level;
3723
3724 frame = find_relative_frame (get_current_frame (), &level);
3725
3726 /* If inf_status->selected_frame_address is NULL, there was no
3727 previously selected frame. */
3728 if (frame == NULL ||
3729 /* FRAME_FP (frame) != fr->frame_address || */
3730 /* elz: deleted this check as a quick fix to the problem that
c5aa993b
JM
3731 for function called by hand gdb creates no internal frame
3732 structure and the real stack and gdb's idea of stack are
3733 different if nested calls by hands are made.
c906108c 3734
c5aa993b 3735 mvs: this worries me. */
c906108c
SS
3736 level != 0)
3737 {
3738 warning ("Unable to restore previously selected frame.\n");
3739 return 0;
3740 }
3741
3742 select_frame (frame, fr->level);
3743
3744 return (1);
3745}
3746
3747void
96baa820 3748restore_inferior_status (struct inferior_status *inf_status)
c906108c
SS
3749{
3750 stop_signal = inf_status->stop_signal;
3751 stop_pc = inf_status->stop_pc;
3752 stop_step = inf_status->stop_step;
3753 stop_stack_dummy = inf_status->stop_stack_dummy;
3754 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3755 trap_expected = inf_status->trap_expected;
3756 step_range_start = inf_status->step_range_start;
3757 step_range_end = inf_status->step_range_end;
3758 step_frame_address = inf_status->step_frame_address;
3759 step_over_calls = inf_status->step_over_calls;
3760 stop_after_trap = inf_status->stop_after_trap;
3761 stop_soon_quietly = inf_status->stop_soon_quietly;
3762 bpstat_clear (&stop_bpstat);
3763 stop_bpstat = inf_status->stop_bpstat;
3764 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3765 proceed_to_finish = inf_status->proceed_to_finish;
3766
7a292a7a 3767 /* FIXME: Is the restore of stop_registers always needed */
c906108c
SS
3768 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
3769
3770 /* The inferior can be gone if the user types "print exit(0)"
3771 (and perhaps other times). */
3772 if (target_has_execution)
3773 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
3774
c906108c
SS
3775 /* FIXME: If we are being called after stopping in a function which
3776 is called from gdb, we should not be trying to restore the
3777 selected frame; it just prints a spurious error message (The
3778 message is useful, however, in detecting bugs in gdb (like if gdb
3779 clobbers the stack)). In fact, should we be restoring the
3780 inferior status at all in that case? . */
3781
3782 if (target_has_stack && inf_status->restore_stack_info)
3783 {
3784 struct restore_selected_frame_args fr;
3785 fr.level = inf_status->selected_level;
3786 fr.frame_address = inf_status->selected_frame_address;
3787 /* The point of catch_errors is that if the stack is clobbered,
c5aa993b
JM
3788 walking the stack might encounter a garbage pointer and error()
3789 trying to dereference it. */
c906108c
SS
3790 if (catch_errors (restore_selected_frame, &fr,
3791 "Unable to restore previously selected frame:\n",
3792 RETURN_MASK_ERROR) == 0)
3793 /* Error in restoring the selected frame. Select the innermost
3794 frame. */
3795
3796
3797 select_frame (get_current_frame (), 0);
3798
3799 }
c906108c 3800
7a292a7a
SS
3801 free_inferior_status (inf_status);
3802}
c906108c
SS
3803
3804void
96baa820 3805discard_inferior_status (struct inferior_status *inf_status)
7a292a7a
SS
3806{
3807 /* See save_inferior_status for info on stop_bpstat. */
3808 bpstat_clear (&inf_status->stop_bpstat);
3809 free_inferior_status (inf_status);
3810}
3811
3812static void
96baa820
JM
3813set_follow_fork_mode_command (char *arg, int from_tty,
3814 struct cmd_list_element *c)
c906108c
SS
3815{
3816 if (!STREQ (arg, "parent") &&
3817 !STREQ (arg, "child") &&
3818 !STREQ (arg, "both") &&
3819 !STREQ (arg, "ask"))
3820 error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\".");
3821
3822 if (follow_fork_mode_string != NULL)
3823 free (follow_fork_mode_string);
3824 follow_fork_mode_string = savestring (arg, strlen (arg));
3825}
c5aa993b 3826\f
7a292a7a 3827static void
96baa820 3828build_infrun (void)
7a292a7a
SS
3829{
3830 stop_registers = xmalloc (REGISTER_BYTES);
3831}
c906108c 3832
c906108c 3833void
96baa820 3834_initialize_infrun (void)
c906108c
SS
3835{
3836 register int i;
3837 register int numsigs;
3838 struct cmd_list_element *c;
3839
7a292a7a
SS
3840 build_infrun ();
3841
0f71a2f6
JM
3842 register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL);
3843 register_gdbarch_swap (NULL, 0, build_infrun);
3844
c906108c
SS
3845 add_info ("signals", signals_info,
3846 "What debugger does when program gets various signals.\n\
3847Specify a signal as argument to print info on that signal only.");
3848 add_info_alias ("handle", "signals", 0);
3849
3850 add_com ("handle", class_run, handle_command,
3851 concat ("Specify how to handle a signal.\n\
3852Args are signals and actions to apply to those signals.\n\
3853Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3854from 1-15 are allowed for compatibility with old versions of GDB.\n\
3855Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3856The special arg \"all\" is recognized to mean all signals except those\n\
3857used by the debugger, typically SIGTRAP and SIGINT.\n",
3858 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
3859\"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
3860Stop means reenter debugger if this signal happens (implies print).\n\
3861Print means print a message if this signal happens.\n\
3862Pass means let program see this signal; otherwise program doesn't know.\n\
3863Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3864Pass and Stop may be combined.", NULL));
3865 if (xdb_commands)
3866 {
3867 add_com ("lz", class_info, signals_info,
3868 "What debugger does when program gets various signals.\n\
3869Specify a signal as argument to print info on that signal only.");
3870 add_com ("z", class_run, xdb_handle_command,
3871 concat ("Specify how to handle a signal.\n\
3872Args are signals and actions to apply to those signals.\n\
3873Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
3874from 1-15 are allowed for compatibility with old versions of GDB.\n\
3875Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
3876The special arg \"all\" is recognized to mean all signals except those\n\
3877used by the debugger, typically SIGTRAP and SIGINT.\n",
3878 "Recognized actions include \"s\" (toggles between stop and nostop), \n\
3879\"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
3880nopass), \"Q\" (noprint)\n\
3881Stop means reenter debugger if this signal happens (implies print).\n\
3882Print means print a message if this signal happens.\n\
3883Pass means let program see this signal; otherwise program doesn't know.\n\
3884Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
3885Pass and Stop may be combined.", NULL));
3886 }
3887
3888 if (!dbx_commands)
3889 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
3890 "There is no `stop' command, but you can set a hook on `stop'.\n\
3891This allows you to set a list of commands to be run each time execution\n\
3892of the program stops.", &cmdlist);
3893
3894 numsigs = (int) TARGET_SIGNAL_LAST;
3895 signal_stop = (unsigned char *)
3896 xmalloc (sizeof (signal_stop[0]) * numsigs);
3897 signal_print = (unsigned char *)
3898 xmalloc (sizeof (signal_print[0]) * numsigs);
3899 signal_program = (unsigned char *)
3900 xmalloc (sizeof (signal_program[0]) * numsigs);
3901 for (i = 0; i < numsigs; i++)
3902 {
3903 signal_stop[i] = 1;
3904 signal_print[i] = 1;
3905 signal_program[i] = 1;
3906 }
3907
3908 /* Signals caused by debugger's own actions
3909 should not be given to the program afterwards. */
3910 signal_program[TARGET_SIGNAL_TRAP] = 0;
3911 signal_program[TARGET_SIGNAL_INT] = 0;
3912
3913 /* Signals that are not errors should not normally enter the debugger. */
3914 signal_stop[TARGET_SIGNAL_ALRM] = 0;
3915 signal_print[TARGET_SIGNAL_ALRM] = 0;
3916 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
3917 signal_print[TARGET_SIGNAL_VTALRM] = 0;
3918 signal_stop[TARGET_SIGNAL_PROF] = 0;
3919 signal_print[TARGET_SIGNAL_PROF] = 0;
3920 signal_stop[TARGET_SIGNAL_CHLD] = 0;
3921 signal_print[TARGET_SIGNAL_CHLD] = 0;
3922 signal_stop[TARGET_SIGNAL_IO] = 0;
3923 signal_print[TARGET_SIGNAL_IO] = 0;
3924 signal_stop[TARGET_SIGNAL_POLL] = 0;
3925 signal_print[TARGET_SIGNAL_POLL] = 0;
3926 signal_stop[TARGET_SIGNAL_URG] = 0;
3927 signal_print[TARGET_SIGNAL_URG] = 0;
3928 signal_stop[TARGET_SIGNAL_WINCH] = 0;
3929 signal_print[TARGET_SIGNAL_WINCH] = 0;
3930
cd0fc7c3
SS
3931 /* These signals are used internally by user-level thread
3932 implementations. (See signal(5) on Solaris.) Like the above
3933 signals, a healthy program receives and handles them as part of
3934 its normal operation. */
3935 signal_stop[TARGET_SIGNAL_LWP] = 0;
3936 signal_print[TARGET_SIGNAL_LWP] = 0;
3937 signal_stop[TARGET_SIGNAL_WAITING] = 0;
3938 signal_print[TARGET_SIGNAL_WAITING] = 0;
3939 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
3940 signal_print[TARGET_SIGNAL_CANCEL] = 0;
3941
c906108c
SS
3942#ifdef SOLIB_ADD
3943 add_show_from_set
3944 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
3945 (char *) &stop_on_solib_events,
3946 "Set stopping for shared library events.\n\
3947If nonzero, gdb will give control to the user when the dynamic linker\n\
3948notifies gdb of shared library events. The most common event of interest\n\
3949to the user would be loading/unloading of a new library.\n",
3950 &setlist),
3951 &showlist);
3952#endif
3953
3954 c = add_set_enum_cmd ("follow-fork-mode",
3955 class_run,
3956 follow_fork_mode_kind_names,
3957 (char *) &follow_fork_mode_string,
3958/* ??rehrauer: The "both" option is broken, by what may be a 10.20
3959 kernel problem. It's also not terribly useful without a GUI to
3960 help the user drive two debuggers. So for now, I'm disabling
3961 the "both" option. */
c5aa993b
JM
3962/* "Set debugger response to a program call of fork \
3963 or vfork.\n\
3964 A fork or vfork creates a new process. follow-fork-mode can be:\n\
3965 parent - the original process is debugged after a fork\n\
3966 child - the new process is debugged after a fork\n\
3967 both - both the parent and child are debugged after a fork\n\
3968 ask - the debugger will ask for one of the above choices\n\
3969 For \"both\", another copy of the debugger will be started to follow\n\
3970 the new child process. The original debugger will continue to follow\n\
3971 the original parent process. To distinguish their prompts, the\n\
3972 debugger copy's prompt will be changed.\n\
3973 For \"parent\" or \"child\", the unfollowed process will run free.\n\
3974 By default, the debugger will follow the parent process.",
3975 */
c906108c
SS
3976 "Set debugger response to a program call of fork \
3977or vfork.\n\
3978A fork or vfork creates a new process. follow-fork-mode can be:\n\
3979 parent - the original process is debugged after a fork\n\
3980 child - the new process is debugged after a fork\n\
3981 ask - the debugger will ask for one of the above choices\n\
3982For \"parent\" or \"child\", the unfollowed process will run free.\n\
3983By default, the debugger will follow the parent process.",
3984 &setlist);
c5aa993b 3985/* c->function.sfunc = ; */
c906108c
SS
3986 add_show_from_set (c, &showlist);
3987
3988 set_follow_fork_mode_command ("parent", 0, NULL);
3989
3990 c = add_set_enum_cmd ("scheduler-locking", class_run,
3991 scheduler_enums, /* array of string names */
3992 (char *) &scheduler_mode, /* current mode */
3993 "Set mode for locking scheduler during execution.\n\
3994off == no locking (threads may preempt at any time)\n\
3995on == full locking (no thread except the current thread may run)\n\
3996step == scheduler locked during every single-step operation.\n\
3997 In this mode, no other thread may run during a step command.\n\
3998 Other threads may run while stepping over a function call ('next').",
3999 &setlist);
4000
4001 c->function.sfunc = set_schedlock_func; /* traps on target vector */
4002 add_show_from_set (c, &showlist);
4003}
This page took 0.201805 seconds and 4 git commands to generate.