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