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