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