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