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