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