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