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