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