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