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