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