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