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