1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
5 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
6 Free Software Foundation, Inc.
8 This file is part of GDB.
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 3 of the License, or
13 (at your option) any later version.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
29 #include "exceptions.h"
30 #include "breakpoint.h"
34 #include "cli/cli-script.h"
36 #include "gdbthread.h"
49 #include "gdb_assert.h"
50 #include "mi/mi-common.h"
52 /* Prototypes for local functions */
54 static void signals_info (char *, int);
56 static void handle_command (char *, int);
58 static void sig_print_info (enum target_signal);
60 static void sig_print_header (void);
62 static void resume_cleanups (void *);
64 static int hook_stop_stub (void *);
66 static int restore_selected_frame (void *);
68 static void build_infrun (void);
70 static int follow_fork (void);
72 static void set_schedlock_func (char *args, int from_tty,
73 struct cmd_list_element *c);
75 struct execution_control_state;
77 static int currently_stepping (struct execution_control_state *ecs);
79 static void xdb_handle_command (char *args, int from_tty);
81 static int prepare_to_proceed (int);
83 void _initialize_infrun (void);
85 int inferior_ignoring_leading_exec_events = 0;
87 /* When set, stop the 'step' command if we enter a function which has
88 no line number information. The normal behavior is that we step
89 over such function. */
90 int step_stop_if_no_debug = 0;
92 show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
93 struct cmd_list_element *c, const char *value)
95 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
98 /* In asynchronous mode, but simulating synchronous execution. */
100 int sync_execution = 0;
102 /* wait_for_inferior and normal_stop use this to notify the user
103 when the inferior stopped in a different thread than it had been
106 static ptid_t previous_inferior_ptid;
108 /* This is true for configurations that may follow through execl() and
109 similar functions. At present this is only true for HP-UX native. */
111 #ifndef MAY_FOLLOW_EXEC
112 #define MAY_FOLLOW_EXEC (0)
115 static int may_follow_exec = MAY_FOLLOW_EXEC;
117 static int debug_infrun = 0;
119 show_debug_infrun (struct ui_file *file, int from_tty,
120 struct cmd_list_element *c, const char *value)
122 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
125 /* If the program uses ELF-style shared libraries, then calls to
126 functions in shared libraries go through stubs, which live in a
127 table called the PLT (Procedure Linkage Table). The first time the
128 function is called, the stub sends control to the dynamic linker,
129 which looks up the function's real address, patches the stub so
130 that future calls will go directly to the function, and then passes
131 control to the function.
133 If we are stepping at the source level, we don't want to see any of
134 this --- we just want to skip over the stub and the dynamic linker.
135 The simple approach is to single-step until control leaves the
138 However, on some systems (e.g., Red Hat's 5.2 distribution) the
139 dynamic linker calls functions in the shared C library, so you
140 can't tell from the PC alone whether the dynamic linker is still
141 running. In this case, we use a step-resume breakpoint to get us
142 past the dynamic linker, as if we were using "next" to step over a
145 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
146 linker code or not. Normally, this means we single-step. However,
147 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
148 address where we can place a step-resume breakpoint to get past the
149 linker's symbol resolution function.
151 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
152 pretty portable way, by comparing the PC against the address ranges
153 of the dynamic linker's sections.
155 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
156 it depends on internal details of the dynamic linker. It's usually
157 not too hard to figure out where to put a breakpoint, but it
158 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
159 sanity checking. If it can't figure things out, returning zero and
160 getting the (possibly confusing) stepping behavior is better than
161 signalling an error, which will obscure the change in the
164 /* This function returns TRUE if pc is the address of an instruction
165 that lies within the dynamic linker (such as the event hook, or the
168 This function must be used only when a dynamic linker event has
169 been caught, and the inferior is being stepped out of the hook, or
170 undefined results are guaranteed. */
172 #ifndef SOLIB_IN_DYNAMIC_LINKER
173 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
177 /* Convert the #defines into values. This is temporary until wfi control
178 flow is completely sorted out. */
180 #ifndef CANNOT_STEP_HW_WATCHPOINTS
181 #define CANNOT_STEP_HW_WATCHPOINTS 0
183 #undef CANNOT_STEP_HW_WATCHPOINTS
184 #define CANNOT_STEP_HW_WATCHPOINTS 1
187 /* Tables of how to react to signals; the user sets them. */
189 static unsigned char *signal_stop;
190 static unsigned char *signal_print;
191 static unsigned char *signal_program;
193 #define SET_SIGS(nsigs,sigs,flags) \
195 int signum = (nsigs); \
196 while (signum-- > 0) \
197 if ((sigs)[signum]) \
198 (flags)[signum] = 1; \
201 #define UNSET_SIGS(nsigs,sigs,flags) \
203 int signum = (nsigs); \
204 while (signum-- > 0) \
205 if ((sigs)[signum]) \
206 (flags)[signum] = 0; \
209 /* Value to pass to target_resume() to cause all threads to resume */
211 #define RESUME_ALL (pid_to_ptid (-1))
213 /* Command list pointer for the "stop" placeholder. */
215 static struct cmd_list_element *stop_command;
217 /* Nonzero if breakpoints are now inserted in the inferior. */
219 static int breakpoints_inserted;
221 /* Function inferior was in as of last step command. */
223 static struct symbol *step_start_function;
225 /* Nonzero if we are expecting a trace trap and should proceed from it. */
227 static int trap_expected;
229 /* Nonzero if we want to give control to the user when we're notified
230 of shared library events by the dynamic linker. */
231 static int stop_on_solib_events;
233 show_stop_on_solib_events (struct ui_file *file, int from_tty,
234 struct cmd_list_element *c, const char *value)
236 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
240 /* Nonzero means expecting a trace trap
241 and should stop the inferior and return silently when it happens. */
245 /* Nonzero means expecting a trap and caller will handle it themselves.
246 It is used after attach, due to attaching to a process;
247 when running in the shell before the child program has been exec'd;
248 and when running some kinds of remote stuff (FIXME?). */
250 enum stop_kind stop_soon;
252 /* Nonzero if proceed is being used for a "finish" command or a similar
253 situation when stop_registers should be saved. */
255 int proceed_to_finish;
257 /* Save register contents here when about to pop a stack dummy frame,
258 if-and-only-if proceed_to_finish is set.
259 Thus this contains the return value from the called function (assuming
260 values are returned in a register). */
262 struct regcache *stop_registers;
264 /* Nonzero after stop if current stack frame should be printed. */
266 static int stop_print_frame;
268 static struct breakpoint *step_resume_breakpoint = NULL;
270 /* This is a cached copy of the pid/waitstatus of the last event
271 returned by target_wait()/deprecated_target_wait_hook(). This
272 information is returned by get_last_target_status(). */
273 static ptid_t target_last_wait_ptid;
274 static struct target_waitstatus target_last_waitstatus;
276 /* This is used to remember when a fork, vfork or exec event
277 was caught by a catchpoint, and thus the event is to be
278 followed at the next resume of the inferior, and not
282 enum target_waitkind kind;
289 char *execd_pathname;
293 static const char follow_fork_mode_child[] = "child";
294 static const char follow_fork_mode_parent[] = "parent";
296 static const char *follow_fork_mode_kind_names[] = {
297 follow_fork_mode_child,
298 follow_fork_mode_parent,
302 static const char *follow_fork_mode_string = follow_fork_mode_parent;
304 show_follow_fork_mode_string (struct ui_file *file, int from_tty,
305 struct cmd_list_element *c, const char *value)
307 fprintf_filtered (file, _("\
308 Debugger response to a program call of fork or vfork is \"%s\".\n"),
316 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
318 return target_follow_fork (follow_child);
322 follow_inferior_reset_breakpoints (void)
324 /* Was there a step_resume breakpoint? (There was if the user
325 did a "next" at the fork() call.) If so, explicitly reset its
328 step_resumes are a form of bp that are made to be per-thread.
329 Since we created the step_resume bp when the parent process
330 was being debugged, and now are switching to the child process,
331 from the breakpoint package's viewpoint, that's a switch of
332 "threads". We must update the bp's notion of which thread
333 it is for, or it'll be ignored when it triggers. */
335 if (step_resume_breakpoint)
336 breakpoint_re_set_thread (step_resume_breakpoint);
338 /* Reinsert all breakpoints in the child. The user may have set
339 breakpoints after catching the fork, in which case those
340 were never set in the child, but only in the parent. This makes
341 sure the inserted breakpoints match the breakpoint list. */
343 breakpoint_re_set ();
344 insert_breakpoints ();
347 /* EXECD_PATHNAME is assumed to be non-NULL. */
350 follow_exec (int pid, char *execd_pathname)
353 struct target_ops *tgt;
355 if (!may_follow_exec)
358 /* This is an exec event that we actually wish to pay attention to.
359 Refresh our symbol table to the newly exec'd program, remove any
362 If there are breakpoints, they aren't really inserted now,
363 since the exec() transformed our inferior into a fresh set
366 We want to preserve symbolic breakpoints on the list, since
367 we have hopes that they can be reset after the new a.out's
368 symbol table is read.
370 However, any "raw" breakpoints must be removed from the list
371 (e.g., the solib bp's), since their address is probably invalid
374 And, we DON'T want to call delete_breakpoints() here, since
375 that may write the bp's "shadow contents" (the instruction
376 value that was overwritten witha TRAP instruction). Since
377 we now have a new a.out, those shadow contents aren't valid. */
378 update_breakpoints_after_exec ();
380 /* If there was one, it's gone now. We cannot truly step-to-next
381 statement through an exec(). */
382 step_resume_breakpoint = NULL;
383 step_range_start = 0;
386 /* What is this a.out's name? */
387 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname);
389 /* We've followed the inferior through an exec. Therefore, the
390 inferior has essentially been killed & reborn. */
392 /* First collect the run target in effect. */
393 tgt = find_run_target ();
394 /* If we can't find one, things are in a very strange state... */
396 error (_("Could find run target to save before following exec"));
398 gdb_flush (gdb_stdout);
399 target_mourn_inferior ();
400 inferior_ptid = pid_to_ptid (saved_pid);
401 /* Because mourn_inferior resets inferior_ptid. */
404 /* That a.out is now the one to use. */
405 exec_file_attach (execd_pathname, 0);
407 /* And also is where symbols can be found. */
408 symbol_file_add_main (execd_pathname, 0);
410 /* Reset the shared library package. This ensures that we get
411 a shlib event when the child reaches "_start", at which point
412 the dld will have had a chance to initialize the child. */
413 #if defined(SOLIB_RESTART)
416 #ifdef SOLIB_CREATE_INFERIOR_HOOK
417 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
419 solib_create_inferior_hook ();
422 /* Reinsert all breakpoints. (Those which were symbolic have
423 been reset to the proper address in the new a.out, thanks
424 to symbol_file_command...) */
425 insert_breakpoints ();
427 /* The next resume of this inferior should bring it to the shlib
428 startup breakpoints. (If the user had also set bp's on
429 "main" from the old (parent) process, then they'll auto-
430 matically get reset there in the new process.) */
433 /* Non-zero if we just simulating a single-step. This is needed
434 because we cannot remove the breakpoints in the inferior process
435 until after the `wait' in `wait_for_inferior'. */
436 static int singlestep_breakpoints_inserted_p = 0;
438 /* The thread we inserted single-step breakpoints for. */
439 static ptid_t singlestep_ptid;
441 /* PC when we started this single-step. */
442 static CORE_ADDR singlestep_pc;
444 /* If another thread hit the singlestep breakpoint, we save the original
445 thread here so that we can resume single-stepping it later. */
446 static ptid_t saved_singlestep_ptid;
447 static int stepping_past_singlestep_breakpoint;
449 /* Similarly, if we are stepping another thread past a breakpoint,
450 save the original thread here so that we can resume stepping it later. */
451 static ptid_t stepping_past_breakpoint_ptid;
452 static int stepping_past_breakpoint;
455 /* Things to clean up if we QUIT out of resume (). */
457 resume_cleanups (void *ignore)
462 static const char schedlock_off[] = "off";
463 static const char schedlock_on[] = "on";
464 static const char schedlock_step[] = "step";
465 static const char *scheduler_enums[] = {
471 static const char *scheduler_mode = schedlock_off;
473 show_scheduler_mode (struct ui_file *file, int from_tty,
474 struct cmd_list_element *c, const char *value)
476 fprintf_filtered (file, _("\
477 Mode for locking scheduler during execution is \"%s\".\n"),
482 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
484 if (!target_can_lock_scheduler)
486 scheduler_mode = schedlock_off;
487 error (_("Target '%s' cannot support this command."), target_shortname);
492 /* Resume the inferior, but allow a QUIT. This is useful if the user
493 wants to interrupt some lengthy single-stepping operation
494 (for child processes, the SIGINT goes to the inferior, and so
495 we get a SIGINT random_signal, but for remote debugging and perhaps
496 other targets, that's not true).
498 STEP nonzero if we should step (zero to continue instead).
499 SIG is the signal to give the inferior (zero for none). */
501 resume (int step, enum target_signal sig)
503 int should_resume = 1;
504 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
508 fprintf_unfiltered (gdb_stdlog, "infrun: resume (step=%d, signal=%d)\n",
511 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */
514 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
515 over an instruction that causes a page fault without triggering
516 a hardware watchpoint. The kernel properly notices that it shouldn't
517 stop, because the hardware watchpoint is not triggered, but it forgets
518 the step request and continues the program normally.
519 Work around the problem by removing hardware watchpoints if a step is
520 requested, GDB will check for a hardware watchpoint trigger after the
522 if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted)
523 remove_hw_watchpoints ();
526 /* Normally, by the time we reach `resume', the breakpoints are either
527 removed or inserted, as appropriate. The exception is if we're sitting
528 at a permanent breakpoint; we need to step over it, but permanent
529 breakpoints can't be removed. So we have to test for it here. */
530 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here)
532 if (gdbarch_skip_permanent_breakpoint_p (current_gdbarch))
533 gdbarch_skip_permanent_breakpoint (current_gdbarch,
534 get_current_regcache ());
537 The program is stopped at a permanent breakpoint, but GDB does not know\n\
538 how to step past a permanent breakpoint on this architecture. Try using\n\
539 a command like `return' or `jump' to continue execution."));
542 if (step && gdbarch_software_single_step_p (current_gdbarch))
544 /* Do it the hard way, w/temp breakpoints */
545 if (gdbarch_software_single_step (current_gdbarch, get_current_frame ()))
547 /* ...and don't ask hardware to do it. */
549 /* and do not pull these breakpoints until after a `wait' in
550 `wait_for_inferior' */
551 singlestep_breakpoints_inserted_p = 1;
552 singlestep_ptid = inferior_ptid;
553 singlestep_pc = read_pc ();
557 /* If there were any forks/vforks/execs that were caught and are
558 now to be followed, then do so. */
559 switch (pending_follow.kind)
561 case TARGET_WAITKIND_FORKED:
562 case TARGET_WAITKIND_VFORKED:
563 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
568 case TARGET_WAITKIND_EXECD:
569 /* follow_exec is called as soon as the exec event is seen. */
570 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
577 /* Install inferior's terminal modes. */
578 target_terminal_inferior ();
584 resume_ptid = RESUME_ALL; /* Default */
586 /* If STEP is set, it's a request to use hardware stepping
587 facilities. But in that case, we should never
588 use singlestep breakpoint. */
589 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
591 if (singlestep_breakpoints_inserted_p
592 && stepping_past_singlestep_breakpoint)
594 /* The situation here is as follows. In thread T1 we wanted to
595 single-step. Lacking hardware single-stepping we've
596 set breakpoint at the PC of the next instruction -- call it
597 P. After resuming, we've hit that breakpoint in thread T2.
598 Now we've removed original breakpoint, inserted breakpoint
599 at P+1, and try to step to advance T2 past breakpoint.
600 We need to step only T2, as if T1 is allowed to freely run,
601 it can run past P, and if other threads are allowed to run,
602 they can hit breakpoint at P+1, and nested hits of single-step
603 breakpoints is not something we'd want -- that's complicated
604 to support, and has no value. */
605 resume_ptid = inferior_ptid;
608 if (step && breakpoint_here_p (read_pc ())
609 && !breakpoint_inserted_here_p (read_pc ()))
611 /* We're stepping, have breakpoint at PC, and it's
612 not inserted. Most likely, proceed has noticed that
613 we have breakpoint and tries to single-step over it,
614 so that it's not hit. In which case, we need to
615 single-step only this thread, and keep others stopped,
616 as they can miss this breakpoint if allowed to run.
618 The current code either has all breakpoints inserted,
619 or all removed, so if we let other threads run,
620 we can actually miss any breakpoint, not the one at PC. */
621 resume_ptid = inferior_ptid;
624 if ((scheduler_mode == schedlock_on)
625 || (scheduler_mode == schedlock_step
626 && (step || singlestep_breakpoints_inserted_p)))
628 /* User-settable 'scheduler' mode requires solo thread resume. */
629 resume_ptid = inferior_ptid;
632 if (gdbarch_cannot_step_breakpoint (current_gdbarch))
634 /* Most targets can step a breakpoint instruction, thus
635 executing it normally. But if this one cannot, just
636 continue and we will hit it anyway. */
637 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
640 target_resume (resume_ptid, step, sig);
643 discard_cleanups (old_cleanups);
647 /* Clear out all variables saying what to do when inferior is continued.
648 First do this, then set the ones you want, then call `proceed'. */
651 clear_proceed_status (void)
654 step_range_start = 0;
656 step_frame_id = null_frame_id;
657 step_over_calls = STEP_OVER_UNDEBUGGABLE;
659 stop_soon = NO_STOP_QUIETLY;
660 proceed_to_finish = 0;
661 breakpoint_proceeded = 1; /* We're about to proceed... */
665 regcache_xfree (stop_registers);
666 stop_registers = NULL;
669 /* Discard any remaining commands or status from previous stop. */
670 bpstat_clear (&stop_bpstat);
673 /* This should be suitable for any targets that support threads. */
676 prepare_to_proceed (int step)
679 struct target_waitstatus wait_status;
681 /* Get the last target status returned by target_wait(). */
682 get_last_target_status (&wait_ptid, &wait_status);
684 /* Make sure we were stopped at a breakpoint. */
685 if (wait_status.kind != TARGET_WAITKIND_STOPPED
686 || wait_status.value.sig != TARGET_SIGNAL_TRAP)
691 /* Switched over from WAIT_PID. */
692 if (!ptid_equal (wait_ptid, minus_one_ptid)
693 && !ptid_equal (inferior_ptid, wait_ptid)
694 && breakpoint_here_p (read_pc_pid (wait_ptid)))
696 /* If stepping, remember current thread to switch back to. */
699 stepping_past_breakpoint = 1;
700 stepping_past_breakpoint_ptid = inferior_ptid;
703 /* Switch back to WAIT_PID thread. */
704 switch_to_thread (wait_ptid);
706 /* We return 1 to indicate that there is a breakpoint here,
707 so we need to step over it before continuing to avoid
708 hitting it straight away. */
715 /* Record the pc of the program the last time it stopped. This is
716 just used internally by wait_for_inferior, but need to be preserved
717 over calls to it and cleared when the inferior is started. */
718 static CORE_ADDR prev_pc;
720 /* Basic routine for continuing the program in various fashions.
722 ADDR is the address to resume at, or -1 for resume where stopped.
723 SIGGNAL is the signal to give it, or 0 for none,
724 or -1 for act according to how it stopped.
725 STEP is nonzero if should trap after one instruction.
726 -1 means return after that and print nothing.
727 You should probably set various step_... variables
728 before calling here, if you are stepping.
730 You should call clear_proceed_status before calling proceed. */
733 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
738 step_start_function = find_pc_function (read_pc ());
742 if (addr == (CORE_ADDR) -1)
744 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
745 /* There is a breakpoint at the address we will resume at,
746 step one instruction before inserting breakpoints so that
747 we do not stop right away (and report a second hit at this
750 else if (gdbarch_single_step_through_delay_p (current_gdbarch)
751 && gdbarch_single_step_through_delay (current_gdbarch,
752 get_current_frame ()))
753 /* We stepped onto an instruction that needs to be stepped
754 again before re-inserting the breakpoint, do so. */
763 fprintf_unfiltered (gdb_stdlog,
764 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
765 paddr_nz (addr), siggnal, step);
767 /* In a multi-threaded task we may select another thread
768 and then continue or step.
770 But if the old thread was stopped at a breakpoint, it
771 will immediately cause another breakpoint stop without
772 any execution (i.e. it will report a breakpoint hit
773 incorrectly). So we must step over it first.
775 prepare_to_proceed checks the current thread against the thread
776 that reported the most recent event. If a step-over is required
777 it returns TRUE and sets the current thread to the old thread. */
778 if (prepare_to_proceed (step))
782 /* We will get a trace trap after one instruction.
783 Continue it automatically and insert breakpoints then. */
787 insert_breakpoints ();
788 /* If we get here there was no call to error() in
789 insert breakpoints -- so they were inserted. */
790 breakpoints_inserted = 1;
793 if (siggnal != TARGET_SIGNAL_DEFAULT)
794 stop_signal = siggnal;
795 /* If this signal should not be seen by program,
796 give it zero. Used for debugging signals. */
797 else if (!signal_program[stop_signal])
798 stop_signal = TARGET_SIGNAL_0;
800 annotate_starting ();
802 /* Make sure that output from GDB appears before output from the
804 gdb_flush (gdb_stdout);
806 /* Refresh prev_pc value just prior to resuming. This used to be
807 done in stop_stepping, however, setting prev_pc there did not handle
808 scenarios such as inferior function calls or returning from
809 a function via the return command. In those cases, the prev_pc
810 value was not set properly for subsequent commands. The prev_pc value
811 is used to initialize the starting line number in the ecs. With an
812 invalid value, the gdb next command ends up stopping at the position
813 represented by the next line table entry past our start position.
814 On platforms that generate one line table entry per line, this
815 is not a problem. However, on the ia64, the compiler generates
816 extraneous line table entries that do not increase the line number.
817 When we issue the gdb next command on the ia64 after an inferior call
818 or a return command, we often end up a few instructions forward, still
819 within the original line we started.
821 An attempt was made to have init_execution_control_state () refresh
822 the prev_pc value before calculating the line number. This approach
823 did not work because on platforms that use ptrace, the pc register
824 cannot be read unless the inferior is stopped. At that point, we
825 are not guaranteed the inferior is stopped and so the read_pc ()
826 call can fail. Setting the prev_pc value here ensures the value is
827 updated correctly when the inferior is stopped. */
828 prev_pc = read_pc ();
830 /* Resume inferior. */
831 resume (oneproc || step || bpstat_should_step (), stop_signal);
833 /* Wait for it to stop (if not standalone)
834 and in any case decode why it stopped, and act accordingly. */
835 /* Do this only if we are not using the event loop, or if the target
836 does not support asynchronous execution. */
837 if (!target_can_async_p ())
839 wait_for_inferior ();
845 /* Start remote-debugging of a machine over a serial link. */
848 start_remote (int from_tty)
851 init_wait_for_inferior ();
852 stop_soon = STOP_QUIETLY_REMOTE;
855 /* Always go on waiting for the target, regardless of the mode. */
856 /* FIXME: cagney/1999-09-23: At present it isn't possible to
857 indicate to wait_for_inferior that a target should timeout if
858 nothing is returned (instead of just blocking). Because of this,
859 targets expecting an immediate response need to, internally, set
860 things up so that the target_wait() is forced to eventually
862 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
863 differentiate to its caller what the state of the target is after
864 the initial open has been performed. Here we're assuming that
865 the target has stopped. It should be possible to eventually have
866 target_open() return to the caller an indication that the target
867 is currently running and GDB state should be set to the same as
869 wait_for_inferior ();
871 /* Now that the inferior has stopped, do any bookkeeping like
872 loading shared libraries. We want to do this before normal_stop,
873 so that the displayed frame is up to date. */
874 post_create_inferior (¤t_target, from_tty);
879 /* Initialize static vars when a new inferior begins. */
882 init_wait_for_inferior (void)
884 /* These are meaningless until the first time through wait_for_inferior. */
887 breakpoints_inserted = 0;
888 breakpoint_init_inferior (inf_starting);
890 /* Don't confuse first call to proceed(). */
891 stop_signal = TARGET_SIGNAL_0;
893 /* The first resume is not following a fork/vfork/exec. */
894 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
896 clear_proceed_status ();
898 stepping_past_singlestep_breakpoint = 0;
899 stepping_past_breakpoint = 0;
902 /* This enum encodes possible reasons for doing a target_wait, so that
903 wfi can call target_wait in one place. (Ultimately the call will be
904 moved out of the infinite loop entirely.) */
908 infwait_normal_state,
909 infwait_thread_hop_state,
910 infwait_step_watch_state,
911 infwait_nonstep_watch_state
914 /* Why did the inferior stop? Used to print the appropriate messages
915 to the interface from within handle_inferior_event(). */
916 enum inferior_stop_reason
918 /* Step, next, nexti, stepi finished. */
920 /* Inferior terminated by signal. */
922 /* Inferior exited. */
924 /* Inferior received signal, and user asked to be notified. */
928 /* This structure contains what used to be local variables in
929 wait_for_inferior. Probably many of them can return to being
930 locals in handle_inferior_event. */
932 struct execution_control_state
934 struct target_waitstatus ws;
935 struct target_waitstatus *wp;
938 CORE_ADDR stop_func_start;
939 CORE_ADDR stop_func_end;
940 char *stop_func_name;
941 struct symtab_and_line sal;
943 struct symtab *current_symtab;
944 int handling_longjmp; /* FIXME */
946 ptid_t saved_inferior_ptid;
947 int step_after_step_resume_breakpoint;
948 int stepping_through_solib_after_catch;
949 bpstat stepping_through_solib_catchpoints;
950 int new_thread_event;
951 struct target_waitstatus tmpstatus;
952 enum infwait_states infwait_state;
957 void init_execution_control_state (struct execution_control_state *ecs);
959 void handle_inferior_event (struct execution_control_state *ecs);
961 static void step_into_function (struct execution_control_state *ecs);
962 static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame);
963 static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
964 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal,
965 struct frame_id sr_id);
966 static void stop_stepping (struct execution_control_state *ecs);
967 static void prepare_to_wait (struct execution_control_state *ecs);
968 static void keep_going (struct execution_control_state *ecs);
969 static void print_stop_reason (enum inferior_stop_reason stop_reason,
972 /* Wait for control to return from inferior to debugger.
973 If inferior gets a signal, we may decide to start it up again
974 instead of returning. That is why there is a loop in this function.
975 When this function actually returns it means the inferior
976 should be left stopped and GDB should read more commands. */
979 wait_for_inferior (void)
981 struct cleanup *old_cleanups;
982 struct execution_control_state ecss;
983 struct execution_control_state *ecs;
986 fprintf_unfiltered (gdb_stdlog, "infrun: wait_for_inferior\n");
988 old_cleanups = make_cleanup (delete_step_resume_breakpoint,
989 &step_resume_breakpoint);
991 /* wfi still stays in a loop, so it's OK just to take the address of
992 a local to get the ecs pointer. */
995 /* Fill in with reasonable starting values. */
996 init_execution_control_state (ecs);
998 /* We'll update this if & when we switch to a new thread. */
999 previous_inferior_ptid = inferior_ptid;
1001 overlay_cache_invalid = 1;
1003 /* We have to invalidate the registers BEFORE calling target_wait
1004 because they can be loaded from the target while in target_wait.
1005 This makes remote debugging a bit more efficient for those
1006 targets that provide critical registers as part of their normal
1007 status mechanism. */
1009 registers_changed ();
1013 if (deprecated_target_wait_hook)
1014 ecs->ptid = deprecated_target_wait_hook (ecs->waiton_ptid, ecs->wp);
1016 ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp);
1018 /* Now figure out what to do with the result of the result. */
1019 handle_inferior_event (ecs);
1021 if (!ecs->wait_some_more)
1024 do_cleanups (old_cleanups);
1027 /* Asynchronous version of wait_for_inferior. It is called by the
1028 event loop whenever a change of state is detected on the file
1029 descriptor corresponding to the target. It can be called more than
1030 once to complete a single execution command. In such cases we need
1031 to keep the state in a global variable ASYNC_ECSS. If it is the
1032 last time that this function is called for a single execution
1033 command, then report to the user that the inferior has stopped, and
1034 do the necessary cleanups. */
1036 struct execution_control_state async_ecss;
1037 struct execution_control_state *async_ecs;
1040 fetch_inferior_event (void *client_data)
1042 static struct cleanup *old_cleanups;
1044 async_ecs = &async_ecss;
1046 if (!async_ecs->wait_some_more)
1048 old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint,
1049 &step_resume_breakpoint);
1051 /* Fill in with reasonable starting values. */
1052 init_execution_control_state (async_ecs);
1054 /* We'll update this if & when we switch to a new thread. */
1055 previous_inferior_ptid = inferior_ptid;
1057 overlay_cache_invalid = 1;
1059 /* We have to invalidate the registers BEFORE calling target_wait
1060 because they can be loaded from the target while in target_wait.
1061 This makes remote debugging a bit more efficient for those
1062 targets that provide critical registers as part of their normal
1063 status mechanism. */
1065 registers_changed ();
1068 if (deprecated_target_wait_hook)
1070 deprecated_target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp);
1072 async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp);
1074 /* Now figure out what to do with the result of the result. */
1075 handle_inferior_event (async_ecs);
1077 if (!async_ecs->wait_some_more)
1079 /* Do only the cleanups that have been added by this
1080 function. Let the continuations for the commands do the rest,
1081 if there are any. */
1082 do_exec_cleanups (old_cleanups);
1084 if (step_multi && stop_step)
1085 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
1087 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1091 /* Prepare an execution control state for looping through a
1092 wait_for_inferior-type loop. */
1095 init_execution_control_state (struct execution_control_state *ecs)
1097 ecs->another_trap = 0;
1098 ecs->random_signal = 0;
1099 ecs->step_after_step_resume_breakpoint = 0;
1100 ecs->handling_longjmp = 0; /* FIXME */
1101 ecs->stepping_through_solib_after_catch = 0;
1102 ecs->stepping_through_solib_catchpoints = NULL;
1103 ecs->sal = find_pc_line (prev_pc, 0);
1104 ecs->current_line = ecs->sal.line;
1105 ecs->current_symtab = ecs->sal.symtab;
1106 ecs->infwait_state = infwait_normal_state;
1107 ecs->waiton_ptid = pid_to_ptid (-1);
1108 ecs->wp = &(ecs->ws);
1111 /* Return the cached copy of the last pid/waitstatus returned by
1112 target_wait()/deprecated_target_wait_hook(). The data is actually
1113 cached by handle_inferior_event(), which gets called immediately
1114 after target_wait()/deprecated_target_wait_hook(). */
1117 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
1119 *ptidp = target_last_wait_ptid;
1120 *status = target_last_waitstatus;
1124 nullify_last_target_wait_ptid (void)
1126 target_last_wait_ptid = minus_one_ptid;
1129 /* Switch thread contexts, maintaining "infrun state". */
1132 context_switch (struct execution_control_state *ecs)
1134 /* Caution: it may happen that the new thread (or the old one!)
1135 is not in the thread list. In this case we must not attempt
1136 to "switch context", or we run the risk that our context may
1137 be lost. This may happen as a result of the target module
1138 mishandling thread creation. */
1142 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
1143 target_pid_to_str (inferior_ptid));
1144 fprintf_unfiltered (gdb_stdlog, "to %s\n",
1145 target_pid_to_str (ecs->ptid));
1148 if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid))
1149 { /* Perform infrun state context switch: */
1150 /* Save infrun state for the old thread. */
1151 save_infrun_state (inferior_ptid, prev_pc,
1152 trap_expected, step_resume_breakpoint,
1154 step_range_end, &step_frame_id,
1155 ecs->handling_longjmp, ecs->another_trap,
1156 ecs->stepping_through_solib_after_catch,
1157 ecs->stepping_through_solib_catchpoints,
1158 ecs->current_line, ecs->current_symtab);
1160 /* Load infrun state for the new thread. */
1161 load_infrun_state (ecs->ptid, &prev_pc,
1162 &trap_expected, &step_resume_breakpoint,
1164 &step_range_end, &step_frame_id,
1165 &ecs->handling_longjmp, &ecs->another_trap,
1166 &ecs->stepping_through_solib_after_catch,
1167 &ecs->stepping_through_solib_catchpoints,
1168 &ecs->current_line, &ecs->current_symtab);
1171 switch_to_thread (ecs->ptid);
1175 adjust_pc_after_break (struct execution_control_state *ecs)
1177 CORE_ADDR breakpoint_pc;
1179 /* If this target does not decrement the PC after breakpoints, then
1180 we have nothing to do. */
1181 if (gdbarch_decr_pc_after_break (current_gdbarch) == 0)
1184 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1185 we aren't, just return.
1187 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1188 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
1189 implemented by software breakpoints should be handled through the normal
1192 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1193 different signals (SIGILL or SIGEMT for instance), but it is less
1194 clear where the PC is pointing afterwards. It may not match
1195 gdbarch_decr_pc_after_break. I don't know any specific target that
1196 generates these signals at breakpoints (the code has been in GDB since at
1197 least 1992) so I can not guess how to handle them here.
1199 In earlier versions of GDB, a target with
1200 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
1201 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
1202 target with both of these set in GDB history, and it seems unlikely to be
1203 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
1205 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
1208 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
1211 /* Find the location where (if we've hit a breakpoint) the
1212 breakpoint would be. */
1213 breakpoint_pc = read_pc_pid (ecs->ptid) - gdbarch_decr_pc_after_break
1216 /* Check whether there actually is a software breakpoint inserted
1217 at that location. */
1218 if (software_breakpoint_inserted_here_p (breakpoint_pc))
1220 /* When using hardware single-step, a SIGTRAP is reported for both
1221 a completed single-step and a software breakpoint. Need to
1222 differentiate between the two, as the latter needs adjusting
1223 but the former does not.
1225 The SIGTRAP can be due to a completed hardware single-step only if
1226 - we didn't insert software single-step breakpoints
1227 - the thread to be examined is still the current thread
1228 - this thread is currently being stepped
1230 If any of these events did not occur, we must have stopped due
1231 to hitting a software breakpoint, and have to back up to the
1234 As a special case, we could have hardware single-stepped a
1235 software breakpoint. In this case (prev_pc == breakpoint_pc),
1236 we also need to back up to the breakpoint address. */
1238 if (singlestep_breakpoints_inserted_p
1239 || !ptid_equal (ecs->ptid, inferior_ptid)
1240 || !currently_stepping (ecs)
1241 || prev_pc == breakpoint_pc)
1242 write_pc_pid (breakpoint_pc, ecs->ptid);
1246 /* Given an execution control state that has been freshly filled in
1247 by an event from the inferior, figure out what it means and take
1248 appropriate action. */
1251 handle_inferior_event (struct execution_control_state *ecs)
1253 int sw_single_step_trap_p = 0;
1254 int stopped_by_watchpoint;
1255 int stepped_after_stopped_by_watchpoint = 0;
1257 /* Cache the last pid/waitstatus. */
1258 target_last_wait_ptid = ecs->ptid;
1259 target_last_waitstatus = *ecs->wp;
1261 adjust_pc_after_break (ecs);
1263 switch (ecs->infwait_state)
1265 case infwait_thread_hop_state:
1267 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
1268 /* Cancel the waiton_ptid. */
1269 ecs->waiton_ptid = pid_to_ptid (-1);
1272 case infwait_normal_state:
1274 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
1277 case infwait_step_watch_state:
1279 fprintf_unfiltered (gdb_stdlog,
1280 "infrun: infwait_step_watch_state\n");
1282 stepped_after_stopped_by_watchpoint = 1;
1285 case infwait_nonstep_watch_state:
1287 fprintf_unfiltered (gdb_stdlog,
1288 "infrun: infwait_nonstep_watch_state\n");
1289 insert_breakpoints ();
1291 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1292 handle things like signals arriving and other things happening
1293 in combination correctly? */
1294 stepped_after_stopped_by_watchpoint = 1;
1298 internal_error (__FILE__, __LINE__, _("bad switch"));
1300 ecs->infwait_state = infwait_normal_state;
1302 reinit_frame_cache ();
1304 /* If it's a new process, add it to the thread database */
1306 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
1307 && !ptid_equal (ecs->ptid, minus_one_ptid)
1308 && !in_thread_list (ecs->ptid));
1310 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1311 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
1313 add_thread (ecs->ptid);
1315 ui_out_text (uiout, "[New ");
1316 ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid));
1317 ui_out_text (uiout, "]\n");
1320 switch (ecs->ws.kind)
1322 case TARGET_WAITKIND_LOADED:
1324 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
1325 /* Ignore gracefully during startup of the inferior, as it might
1326 be the shell which has just loaded some objects, otherwise
1327 add the symbols for the newly loaded objects. Also ignore at
1328 the beginning of an attach or remote session; we will query
1329 the full list of libraries once the connection is
1331 if (stop_soon == NO_STOP_QUIETLY)
1333 int breakpoints_were_inserted;
1335 /* Remove breakpoints, SOLIB_ADD might adjust
1336 breakpoint addresses via breakpoint_re_set. */
1337 breakpoints_were_inserted = breakpoints_inserted;
1338 if (breakpoints_inserted)
1339 remove_breakpoints ();
1340 breakpoints_inserted = 0;
1342 /* Check for any newly added shared libraries if we're
1343 supposed to be adding them automatically. Switch
1344 terminal for any messages produced by
1345 breakpoint_re_set. */
1346 target_terminal_ours_for_output ();
1347 /* NOTE: cagney/2003-11-25: Make certain that the target
1348 stack's section table is kept up-to-date. Architectures,
1349 (e.g., PPC64), use the section table to perform
1350 operations such as address => section name and hence
1351 require the table to contain all sections (including
1352 those found in shared libraries). */
1353 /* NOTE: cagney/2003-11-25: Pass current_target and not
1354 exec_ops to SOLIB_ADD. This is because current GDB is
1355 only tooled to propagate section_table changes out from
1356 the "current_target" (see target_resize_to_sections), and
1357 not up from the exec stratum. This, of course, isn't
1358 right. "infrun.c" should only interact with the
1359 exec/process stratum, instead relying on the target stack
1360 to propagate relevant changes (stop, section table
1361 changed, ...) up to other layers. */
1363 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
1365 solib_add (NULL, 0, ¤t_target, auto_solib_add);
1367 target_terminal_inferior ();
1369 /* If requested, stop when the dynamic linker notifies
1370 gdb of events. This allows the user to get control
1371 and place breakpoints in initializer routines for
1372 dynamically loaded objects (among other things). */
1373 if (stop_on_solib_events)
1375 stop_stepping (ecs);
1379 /* NOTE drow/2007-05-11: This might be a good place to check
1380 for "catch load". */
1382 /* Reinsert breakpoints and continue. */
1383 if (breakpoints_were_inserted)
1385 insert_breakpoints ();
1386 breakpoints_inserted = 1;
1390 /* If we are skipping through a shell, or through shared library
1391 loading that we aren't interested in, resume the program. If
1392 we're running the program normally, also resume. But stop if
1393 we're attaching or setting up a remote connection. */
1394 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
1396 resume (0, TARGET_SIGNAL_0);
1397 prepare_to_wait (ecs);
1403 case TARGET_WAITKIND_SPURIOUS:
1405 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
1406 resume (0, TARGET_SIGNAL_0);
1407 prepare_to_wait (ecs);
1410 case TARGET_WAITKIND_EXITED:
1412 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
1413 target_terminal_ours (); /* Must do this before mourn anyway */
1414 print_stop_reason (EXITED, ecs->ws.value.integer);
1416 /* Record the exit code in the convenience variable $_exitcode, so
1417 that the user can inspect this again later. */
1418 set_internalvar (lookup_internalvar ("_exitcode"),
1419 value_from_longest (builtin_type_int,
1420 (LONGEST) ecs->ws.value.integer));
1421 gdb_flush (gdb_stdout);
1422 target_mourn_inferior ();
1423 singlestep_breakpoints_inserted_p = 0;
1424 stop_print_frame = 0;
1425 stop_stepping (ecs);
1428 case TARGET_WAITKIND_SIGNALLED:
1430 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n");
1431 stop_print_frame = 0;
1432 stop_signal = ecs->ws.value.sig;
1433 target_terminal_ours (); /* Must do this before mourn anyway */
1435 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1436 reach here unless the inferior is dead. However, for years
1437 target_kill() was called here, which hints that fatal signals aren't
1438 really fatal on some systems. If that's true, then some changes
1440 target_mourn_inferior ();
1442 print_stop_reason (SIGNAL_EXITED, stop_signal);
1443 singlestep_breakpoints_inserted_p = 0;
1444 stop_stepping (ecs);
1447 /* The following are the only cases in which we keep going;
1448 the above cases end in a continue or goto. */
1449 case TARGET_WAITKIND_FORKED:
1450 case TARGET_WAITKIND_VFORKED:
1452 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
1453 stop_signal = TARGET_SIGNAL_TRAP;
1454 pending_follow.kind = ecs->ws.kind;
1456 pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid);
1457 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
1459 if (!ptid_equal (ecs->ptid, inferior_ptid))
1461 context_switch (ecs);
1462 reinit_frame_cache ();
1465 stop_pc = read_pc ();
1467 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
1469 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1471 /* If no catchpoint triggered for this, then keep going. */
1472 if (ecs->random_signal)
1474 stop_signal = TARGET_SIGNAL_0;
1478 goto process_event_stop_test;
1480 case TARGET_WAITKIND_EXECD:
1482 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
1483 stop_signal = TARGET_SIGNAL_TRAP;
1485 /* NOTE drow/2002-12-05: This code should be pushed down into the
1486 target_wait function. Until then following vfork on HP/UX 10.20
1487 is probably broken by this. Of course, it's broken anyway. */
1488 /* Is this a target which reports multiple exec events per actual
1489 call to exec()? (HP-UX using ptrace does, for example.) If so,
1490 ignore all but the last one. Just resume the exec'r, and wait
1491 for the next exec event. */
1492 if (inferior_ignoring_leading_exec_events)
1494 inferior_ignoring_leading_exec_events--;
1495 target_resume (ecs->ptid, 0, TARGET_SIGNAL_0);
1496 prepare_to_wait (ecs);
1499 inferior_ignoring_leading_exec_events =
1500 target_reported_exec_events_per_exec_call () - 1;
1502 pending_follow.execd_pathname =
1503 savestring (ecs->ws.value.execd_pathname,
1504 strlen (ecs->ws.value.execd_pathname));
1506 /* This causes the eventpoints and symbol table to be reset. Must
1507 do this now, before trying to determine whether to stop. */
1508 follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname);
1509 xfree (pending_follow.execd_pathname);
1511 stop_pc = read_pc_pid (ecs->ptid);
1512 ecs->saved_inferior_ptid = inferior_ptid;
1513 inferior_ptid = ecs->ptid;
1515 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
1517 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
1518 inferior_ptid = ecs->saved_inferior_ptid;
1520 if (!ptid_equal (ecs->ptid, inferior_ptid))
1522 context_switch (ecs);
1523 reinit_frame_cache ();
1526 /* If no catchpoint triggered for this, then keep going. */
1527 if (ecs->random_signal)
1529 stop_signal = TARGET_SIGNAL_0;
1533 goto process_event_stop_test;
1535 /* Be careful not to try to gather much state about a thread
1536 that's in a syscall. It's frequently a losing proposition. */
1537 case TARGET_WAITKIND_SYSCALL_ENTRY:
1539 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
1540 resume (0, TARGET_SIGNAL_0);
1541 prepare_to_wait (ecs);
1544 /* Before examining the threads further, step this thread to
1545 get it entirely out of the syscall. (We get notice of the
1546 event when the thread is just on the verge of exiting a
1547 syscall. Stepping one instruction seems to get it back
1549 case TARGET_WAITKIND_SYSCALL_RETURN:
1551 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
1552 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
1553 prepare_to_wait (ecs);
1556 case TARGET_WAITKIND_STOPPED:
1558 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
1559 stop_signal = ecs->ws.value.sig;
1562 /* We had an event in the inferior, but we are not interested
1563 in handling it at this level. The lower layers have already
1564 done what needs to be done, if anything.
1566 One of the possible circumstances for this is when the
1567 inferior produces output for the console. The inferior has
1568 not stopped, and we are ignoring the event. Another possible
1569 circumstance is any event which the lower level knows will be
1570 reported multiple times without an intervening resume. */
1571 case TARGET_WAITKIND_IGNORE:
1573 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
1574 prepare_to_wait (ecs);
1578 /* We may want to consider not doing a resume here in order to give
1579 the user a chance to play with the new thread. It might be good
1580 to make that a user-settable option. */
1582 /* At this point, all threads are stopped (happens automatically in
1583 either the OS or the native code). Therefore we need to continue
1584 all threads in order to make progress. */
1585 if (ecs->new_thread_event)
1587 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
1588 prepare_to_wait (ecs);
1592 stop_pc = read_pc_pid (ecs->ptid);
1595 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = 0x%s\n", paddr_nz (stop_pc));
1597 if (stepping_past_singlestep_breakpoint)
1599 gdb_assert (singlestep_breakpoints_inserted_p);
1600 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
1601 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
1603 stepping_past_singlestep_breakpoint = 0;
1605 /* We've either finished single-stepping past the single-step
1606 breakpoint, or stopped for some other reason. It would be nice if
1607 we could tell, but we can't reliably. */
1608 if (stop_signal == TARGET_SIGNAL_TRAP)
1611 fprintf_unfiltered (gdb_stdlog, "infrun: stepping_past_singlestep_breakpoint\n");
1612 /* Pull the single step breakpoints out of the target. */
1613 remove_single_step_breakpoints ();
1614 singlestep_breakpoints_inserted_p = 0;
1616 ecs->random_signal = 0;
1618 ecs->ptid = saved_singlestep_ptid;
1619 context_switch (ecs);
1620 if (deprecated_context_hook)
1621 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
1623 resume (1, TARGET_SIGNAL_0);
1624 prepare_to_wait (ecs);
1629 stepping_past_singlestep_breakpoint = 0;
1631 if (stepping_past_breakpoint)
1633 stepping_past_breakpoint = 0;
1635 /* If we stopped for some other reason than single-stepping, ignore
1636 the fact that we were supposed to switch back. */
1637 if (stop_signal == TARGET_SIGNAL_TRAP)
1640 fprintf_unfiltered (gdb_stdlog,
1641 "infrun: stepping_past_breakpoint\n");
1643 /* Pull the single step breakpoints out of the target. */
1644 if (singlestep_breakpoints_inserted_p)
1646 remove_single_step_breakpoints ();
1647 singlestep_breakpoints_inserted_p = 0;
1650 /* Note: We do not call context_switch at this point, as the
1651 context is already set up for stepping the original thread. */
1652 switch_to_thread (stepping_past_breakpoint_ptid);
1653 /* Suppress spurious "Switching to ..." message. */
1654 previous_inferior_ptid = inferior_ptid;
1656 resume (1, TARGET_SIGNAL_0);
1657 prepare_to_wait (ecs);
1662 /* See if a thread hit a thread-specific breakpoint that was meant for
1663 another thread. If so, then step that thread past the breakpoint,
1666 if (stop_signal == TARGET_SIGNAL_TRAP)
1668 int thread_hop_needed = 0;
1670 /* Check if a regular breakpoint has been hit before checking
1671 for a potential single step breakpoint. Otherwise, GDB will
1672 not see this breakpoint hit when stepping onto breakpoints. */
1673 if (breakpoints_inserted && breakpoint_here_p (stop_pc))
1675 ecs->random_signal = 0;
1676 if (!breakpoint_thread_match (stop_pc, ecs->ptid))
1677 thread_hop_needed = 1;
1679 else if (singlestep_breakpoints_inserted_p)
1681 /* We have not context switched yet, so this should be true
1682 no matter which thread hit the singlestep breakpoint. */
1683 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
1685 fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
1687 target_pid_to_str (ecs->ptid));
1689 ecs->random_signal = 0;
1690 /* The call to in_thread_list is necessary because PTIDs sometimes
1691 change when we go from single-threaded to multi-threaded. If
1692 the singlestep_ptid is still in the list, assume that it is
1693 really different from ecs->ptid. */
1694 if (!ptid_equal (singlestep_ptid, ecs->ptid)
1695 && in_thread_list (singlestep_ptid))
1697 /* If the PC of the thread we were trying to single-step
1698 has changed, discard this event (which we were going
1699 to ignore anyway), and pretend we saw that thread
1700 trap. This prevents us continuously moving the
1701 single-step breakpoint forward, one instruction at a
1702 time. If the PC has changed, then the thread we were
1703 trying to single-step has trapped or been signalled,
1704 but the event has not been reported to GDB yet.
1706 There might be some cases where this loses signal
1707 information, if a signal has arrived at exactly the
1708 same time that the PC changed, but this is the best
1709 we can do with the information available. Perhaps we
1710 should arrange to report all events for all threads
1711 when they stop, or to re-poll the remote looking for
1712 this particular thread (i.e. temporarily enable
1714 if (read_pc_pid (singlestep_ptid) != singlestep_pc)
1717 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
1718 " but expected thread advanced also\n");
1720 /* The current context still belongs to
1721 singlestep_ptid. Don't swap here, since that's
1722 the context we want to use. Just fudge our
1723 state and continue. */
1724 ecs->ptid = singlestep_ptid;
1725 stop_pc = read_pc_pid (ecs->ptid);
1730 fprintf_unfiltered (gdb_stdlog,
1731 "infrun: unexpected thread\n");
1733 thread_hop_needed = 1;
1734 stepping_past_singlestep_breakpoint = 1;
1735 saved_singlestep_ptid = singlestep_ptid;
1740 if (thread_hop_needed)
1745 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
1747 /* Saw a breakpoint, but it was hit by the wrong thread.
1750 if (singlestep_breakpoints_inserted_p)
1752 /* Pull the single step breakpoints out of the target. */
1753 remove_single_step_breakpoints ();
1754 singlestep_breakpoints_inserted_p = 0;
1757 remove_status = remove_breakpoints ();
1758 /* Did we fail to remove breakpoints? If so, try
1759 to set the PC past the bp. (There's at least
1760 one situation in which we can fail to remove
1761 the bp's: On HP-UX's that use ttrace, we can't
1762 change the address space of a vforking child
1763 process until the child exits (well, okay, not
1764 then either :-) or execs. */
1765 if (remove_status != 0)
1767 /* FIXME! This is obviously non-portable! */
1768 write_pc_pid (stop_pc + 4, ecs->ptid);
1769 /* We need to restart all the threads now,
1770 * unles we're running in scheduler-locked mode.
1771 * Use currently_stepping to determine whether to
1774 /* FIXME MVS: is there any reason not to call resume()? */
1775 if (scheduler_mode == schedlock_on)
1776 target_resume (ecs->ptid,
1777 currently_stepping (ecs), TARGET_SIGNAL_0);
1779 target_resume (RESUME_ALL,
1780 currently_stepping (ecs), TARGET_SIGNAL_0);
1781 prepare_to_wait (ecs);
1786 breakpoints_inserted = 0;
1787 if (!ptid_equal (inferior_ptid, ecs->ptid))
1788 context_switch (ecs);
1789 ecs->waiton_ptid = ecs->ptid;
1790 ecs->wp = &(ecs->ws);
1791 ecs->another_trap = 1;
1793 ecs->infwait_state = infwait_thread_hop_state;
1795 registers_changed ();
1799 else if (singlestep_breakpoints_inserted_p)
1801 sw_single_step_trap_p = 1;
1802 ecs->random_signal = 0;
1806 ecs->random_signal = 1;
1808 /* See if something interesting happened to the non-current thread. If
1809 so, then switch to that thread. */
1810 if (!ptid_equal (ecs->ptid, inferior_ptid))
1813 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
1815 context_switch (ecs);
1817 if (deprecated_context_hook)
1818 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
1821 if (singlestep_breakpoints_inserted_p)
1823 /* Pull the single step breakpoints out of the target. */
1824 remove_single_step_breakpoints ();
1825 singlestep_breakpoints_inserted_p = 0;
1828 if (stepped_after_stopped_by_watchpoint)
1829 stopped_by_watchpoint = 0;
1831 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
1833 /* If necessary, step over this watchpoint. We'll be back to display
1835 if (stopped_by_watchpoint
1836 && (HAVE_STEPPABLE_WATCHPOINT
1837 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch)))
1840 fprintf_unfiltered (gdb_stdlog, "infrun: STOPPED_BY_WATCHPOINT\n");
1842 /* At this point, we are stopped at an instruction which has
1843 attempted to write to a piece of memory under control of
1844 a watchpoint. The instruction hasn't actually executed
1845 yet. If we were to evaluate the watchpoint expression
1846 now, we would get the old value, and therefore no change
1847 would seem to have occurred.
1849 In order to make watchpoints work `right', we really need
1850 to complete the memory write, and then evaluate the
1851 watchpoint expression. We do this by single-stepping the
1854 It may not be necessary to disable the watchpoint to stop over
1855 it. For example, the PA can (with some kernel cooperation)
1856 single step over a watchpoint without disabling the watchpoint.
1858 It is far more common to need to disable a watchpoint to step
1859 the inferior over it. If we have non-steppable watchpoints,
1860 we must disable the current watchpoint; it's simplest to
1861 disable all watchpoints and breakpoints. */
1863 if (!HAVE_STEPPABLE_WATCHPOINT)
1864 remove_breakpoints ();
1865 registers_changed ();
1866 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */
1867 ecs->waiton_ptid = ecs->ptid;
1868 if (HAVE_STEPPABLE_WATCHPOINT)
1869 ecs->infwait_state = infwait_step_watch_state;
1871 ecs->infwait_state = infwait_nonstep_watch_state;
1872 prepare_to_wait (ecs);
1876 ecs->stop_func_start = 0;
1877 ecs->stop_func_end = 0;
1878 ecs->stop_func_name = 0;
1879 /* Don't care about return value; stop_func_start and stop_func_name
1880 will both be 0 if it doesn't work. */
1881 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
1882 &ecs->stop_func_start, &ecs->stop_func_end);
1883 ecs->stop_func_start
1884 += gdbarch_deprecated_function_start_offset (current_gdbarch);
1885 ecs->another_trap = 0;
1886 bpstat_clear (&stop_bpstat);
1888 stop_stack_dummy = 0;
1889 stop_print_frame = 1;
1890 ecs->random_signal = 0;
1891 stopped_by_random_signal = 0;
1893 if (stop_signal == TARGET_SIGNAL_TRAP
1895 && gdbarch_single_step_through_delay_p (current_gdbarch)
1896 && currently_stepping (ecs))
1898 /* We're trying to step of a breakpoint. Turns out that we're
1899 also on an instruction that needs to be stepped multiple
1900 times before it's been fully executing. E.g., architectures
1901 with a delay slot. It needs to be stepped twice, once for
1902 the instruction and once for the delay slot. */
1903 int step_through_delay
1904 = gdbarch_single_step_through_delay (current_gdbarch,
1905 get_current_frame ());
1906 if (debug_infrun && step_through_delay)
1907 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
1908 if (step_range_end == 0 && step_through_delay)
1910 /* The user issued a continue when stopped at a breakpoint.
1911 Set up for another trap and get out of here. */
1912 ecs->another_trap = 1;
1916 else if (step_through_delay)
1918 /* The user issued a step when stopped at a breakpoint.
1919 Maybe we should stop, maybe we should not - the delay
1920 slot *might* correspond to a line of source. In any
1921 case, don't decide that here, just set ecs->another_trap,
1922 making sure we single-step again before breakpoints are
1924 ecs->another_trap = 1;
1928 /* Look at the cause of the stop, and decide what to do.
1929 The alternatives are:
1930 1) break; to really stop and return to the debugger,
1931 2) drop through to start up again
1932 (set ecs->another_trap to 1 to single step once)
1933 3) set ecs->random_signal to 1, and the decision between 1 and 2
1934 will be made according to the signal handling tables. */
1936 /* First, distinguish signals caused by the debugger from signals
1937 that have to do with the program's own actions. Note that
1938 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
1939 on the operating system version. Here we detect when a SIGILL or
1940 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
1941 something similar for SIGSEGV, since a SIGSEGV will be generated
1942 when we're trying to execute a breakpoint instruction on a
1943 non-executable stack. This happens for call dummy breakpoints
1944 for architectures like SPARC that place call dummies on the
1947 if (stop_signal == TARGET_SIGNAL_TRAP
1948 || (breakpoints_inserted
1949 && (stop_signal == TARGET_SIGNAL_ILL
1950 || stop_signal == TARGET_SIGNAL_SEGV
1951 || stop_signal == TARGET_SIGNAL_EMT))
1952 || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP
1953 || stop_soon == STOP_QUIETLY_REMOTE)
1955 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
1958 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
1959 stop_print_frame = 0;
1960 stop_stepping (ecs);
1964 /* This is originated from start_remote(), start_inferior() and
1965 shared libraries hook functions. */
1966 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
1969 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
1970 stop_stepping (ecs);
1974 /* This originates from attach_command(). We need to overwrite
1975 the stop_signal here, because some kernels don't ignore a
1976 SIGSTOP in a subsequent ptrace(PTRACE_SONT,SOGSTOP) call.
1977 See more comments in inferior.h. */
1978 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP)
1980 stop_stepping (ecs);
1981 if (stop_signal == TARGET_SIGNAL_STOP)
1982 stop_signal = TARGET_SIGNAL_0;
1986 /* Don't even think about breakpoints if just proceeded over a
1988 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected)
1991 fprintf_unfiltered (gdb_stdlog, "infrun: trap expected\n");
1992 bpstat_clear (&stop_bpstat);
1996 /* See if there is a breakpoint at the current PC. */
1997 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
1999 /* Following in case break condition called a
2001 stop_print_frame = 1;
2004 /* NOTE: cagney/2003-03-29: These two checks for a random signal
2005 at one stage in the past included checks for an inferior
2006 function call's call dummy's return breakpoint. The original
2007 comment, that went with the test, read:
2009 ``End of a stack dummy. Some systems (e.g. Sony news) give
2010 another signal besides SIGTRAP, so check here as well as
2013 If someone ever tries to get get call dummys on a
2014 non-executable stack to work (where the target would stop
2015 with something like a SIGSEGV), then those tests might need
2016 to be re-instated. Given, however, that the tests were only
2017 enabled when momentary breakpoints were not being used, I
2018 suspect that it won't be the case.
2020 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
2021 be necessary for call dummies on a non-executable stack on
2024 if (stop_signal == TARGET_SIGNAL_TRAP)
2026 = !(bpstat_explains_signal (stop_bpstat)
2028 || (step_range_end && step_resume_breakpoint == NULL));
2031 ecs->random_signal = !bpstat_explains_signal (stop_bpstat);
2032 if (!ecs->random_signal)
2033 stop_signal = TARGET_SIGNAL_TRAP;
2037 /* When we reach this point, we've pretty much decided
2038 that the reason for stopping must've been a random
2039 (unexpected) signal. */
2042 ecs->random_signal = 1;
2044 process_event_stop_test:
2045 /* For the program's own signals, act according to
2046 the signal handling tables. */
2048 if (ecs->random_signal)
2050 /* Signal not for debugging purposes. */
2054 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n", stop_signal);
2056 stopped_by_random_signal = 1;
2058 if (signal_print[stop_signal])
2061 target_terminal_ours_for_output ();
2062 print_stop_reason (SIGNAL_RECEIVED, stop_signal);
2064 if (signal_stop[stop_signal])
2066 stop_stepping (ecs);
2069 /* If not going to stop, give terminal back
2070 if we took it away. */
2072 target_terminal_inferior ();
2074 /* Clear the signal if it should not be passed. */
2075 if (signal_program[stop_signal] == 0)
2076 stop_signal = TARGET_SIGNAL_0;
2078 if (prev_pc == read_pc ()
2079 && !breakpoints_inserted
2080 && breakpoint_here_p (read_pc ())
2081 && step_resume_breakpoint == NULL)
2083 /* We were just starting a new sequence, attempting to
2084 single-step off of a breakpoint and expecting a SIGTRAP.
2085 Intead this signal arrives. This signal will take us out
2086 of the stepping range so GDB needs to remember to, when
2087 the signal handler returns, resume stepping off that
2089 /* To simplify things, "continue" is forced to use the same
2090 code paths as single-step - set a breakpoint at the
2091 signal return address and then, once hit, step off that
2094 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2095 ecs->step_after_step_resume_breakpoint = 1;
2100 if (step_range_end != 0
2101 && stop_signal != TARGET_SIGNAL_0
2102 && stop_pc >= step_range_start && stop_pc < step_range_end
2103 && frame_id_eq (get_frame_id (get_current_frame ()),
2105 && step_resume_breakpoint == NULL)
2107 /* The inferior is about to take a signal that will take it
2108 out of the single step range. Set a breakpoint at the
2109 current PC (which is presumably where the signal handler
2110 will eventually return) and then allow the inferior to
2113 Note that this is only needed for a signal delivered
2114 while in the single-step range. Nested signals aren't a
2115 problem as they eventually all return. */
2116 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2121 /* Note: step_resume_breakpoint may be non-NULL. This occures
2122 when either there's a nested signal, or when there's a
2123 pending signal enabled just as the signal handler returns
2124 (leaving the inferior at the step-resume-breakpoint without
2125 actually executing it). Either way continue until the
2126 breakpoint is really hit. */
2131 /* Handle cases caused by hitting a breakpoint. */
2133 CORE_ADDR jmp_buf_pc;
2134 struct bpstat_what what;
2136 what = bpstat_what (stop_bpstat);
2138 if (what.call_dummy)
2140 stop_stack_dummy = 1;
2143 switch (what.main_action)
2145 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2146 /* If we hit the breakpoint at longjmp, disable it for the
2147 duration of this command. Then, install a temporary
2148 breakpoint at the target of the jmp_buf. */
2150 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
2151 disable_longjmp_breakpoint ();
2152 remove_breakpoints ();
2153 breakpoints_inserted = 0;
2154 if (!gdbarch_get_longjmp_target_p (current_gdbarch)
2155 || !gdbarch_get_longjmp_target (current_gdbarch,
2156 get_current_frame (), &jmp_buf_pc))
2162 /* Need to blow away step-resume breakpoint, as it
2163 interferes with us */
2164 if (step_resume_breakpoint != NULL)
2166 delete_step_resume_breakpoint (&step_resume_breakpoint);
2169 set_longjmp_resume_breakpoint (jmp_buf_pc, null_frame_id);
2170 ecs->handling_longjmp = 1; /* FIXME */
2174 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2175 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
2177 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
2178 remove_breakpoints ();
2179 breakpoints_inserted = 0;
2180 disable_longjmp_breakpoint ();
2181 ecs->handling_longjmp = 0; /* FIXME */
2182 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
2184 /* else fallthrough */
2186 case BPSTAT_WHAT_SINGLE:
2188 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
2189 if (breakpoints_inserted)
2190 remove_breakpoints ();
2191 breakpoints_inserted = 0;
2192 ecs->another_trap = 1;
2193 /* Still need to check other stuff, at least the case
2194 where we are stepping and step out of the right range. */
2197 case BPSTAT_WHAT_STOP_NOISY:
2199 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
2200 stop_print_frame = 1;
2202 /* We are about to nuke the step_resume_breakpointt via the
2203 cleanup chain, so no need to worry about it here. */
2205 stop_stepping (ecs);
2208 case BPSTAT_WHAT_STOP_SILENT:
2210 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
2211 stop_print_frame = 0;
2213 /* We are about to nuke the step_resume_breakpoin via the
2214 cleanup chain, so no need to worry about it here. */
2216 stop_stepping (ecs);
2219 case BPSTAT_WHAT_STEP_RESUME:
2220 /* This proably demands a more elegant solution, but, yeah
2223 This function's use of the simple variable
2224 step_resume_breakpoint doesn't seem to accomodate
2225 simultaneously active step-resume bp's, although the
2226 breakpoint list certainly can.
2228 If we reach here and step_resume_breakpoint is already
2229 NULL, then apparently we have multiple active
2230 step-resume bp's. We'll just delete the breakpoint we
2231 stopped at, and carry on.
2233 Correction: what the code currently does is delete a
2234 step-resume bp, but it makes no effort to ensure that
2235 the one deleted is the one currently stopped at. MVS */
2238 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
2240 if (step_resume_breakpoint == NULL)
2242 step_resume_breakpoint =
2243 bpstat_find_step_resume_breakpoint (stop_bpstat);
2245 delete_step_resume_breakpoint (&step_resume_breakpoint);
2246 if (ecs->step_after_step_resume_breakpoint)
2248 /* Back when the step-resume breakpoint was inserted, we
2249 were trying to single-step off a breakpoint. Go back
2251 ecs->step_after_step_resume_breakpoint = 0;
2252 remove_breakpoints ();
2253 breakpoints_inserted = 0;
2254 ecs->another_trap = 1;
2260 case BPSTAT_WHAT_CHECK_SHLIBS:
2261 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2264 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
2265 /* Remove breakpoints, we eventually want to step over the
2266 shlib event breakpoint, and SOLIB_ADD might adjust
2267 breakpoint addresses via breakpoint_re_set. */
2268 if (breakpoints_inserted)
2269 remove_breakpoints ();
2270 breakpoints_inserted = 0;
2272 /* Check for any newly added shared libraries if we're
2273 supposed to be adding them automatically. Switch
2274 terminal for any messages produced by
2275 breakpoint_re_set. */
2276 target_terminal_ours_for_output ();
2277 /* NOTE: cagney/2003-11-25: Make certain that the target
2278 stack's section table is kept up-to-date. Architectures,
2279 (e.g., PPC64), use the section table to perform
2280 operations such as address => section name and hence
2281 require the table to contain all sections (including
2282 those found in shared libraries). */
2283 /* NOTE: cagney/2003-11-25: Pass current_target and not
2284 exec_ops to SOLIB_ADD. This is because current GDB is
2285 only tooled to propagate section_table changes out from
2286 the "current_target" (see target_resize_to_sections), and
2287 not up from the exec stratum. This, of course, isn't
2288 right. "infrun.c" should only interact with the
2289 exec/process stratum, instead relying on the target stack
2290 to propagate relevant changes (stop, section table
2291 changed, ...) up to other layers. */
2293 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
2295 solib_add (NULL, 0, ¤t_target, auto_solib_add);
2297 target_terminal_inferior ();
2299 /* If requested, stop when the dynamic linker notifies
2300 gdb of events. This allows the user to get control
2301 and place breakpoints in initializer routines for
2302 dynamically loaded objects (among other things). */
2303 if (stop_on_solib_events || stop_stack_dummy)
2305 stop_stepping (ecs);
2309 /* If we stopped due to an explicit catchpoint, then the
2310 (see above) call to SOLIB_ADD pulled in any symbols
2311 from a newly-loaded library, if appropriate.
2313 We do want the inferior to stop, but not where it is
2314 now, which is in the dynamic linker callback. Rather,
2315 we would like it stop in the user's program, just after
2316 the call that caused this catchpoint to trigger. That
2317 gives the user a more useful vantage from which to
2318 examine their program's state. */
2319 else if (what.main_action
2320 == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2322 /* ??rehrauer: If I could figure out how to get the
2323 right return PC from here, we could just set a temp
2324 breakpoint and resume. I'm not sure we can without
2325 cracking open the dld's shared libraries and sniffing
2326 their unwind tables and text/data ranges, and that's
2327 not a terribly portable notion.
2329 Until that time, we must step the inferior out of the
2330 dld callback, and also out of the dld itself (and any
2331 code or stubs in libdld.sl, such as "shl_load" and
2332 friends) until we reach non-dld code. At that point,
2333 we can stop stepping. */
2334 bpstat_get_triggered_catchpoints (stop_bpstat,
2336 stepping_through_solib_catchpoints);
2337 ecs->stepping_through_solib_after_catch = 1;
2339 /* Be sure to lift all breakpoints, so the inferior does
2340 actually step past this point... */
2341 ecs->another_trap = 1;
2346 /* We want to step over this breakpoint, then keep going. */
2347 ecs->another_trap = 1;
2353 case BPSTAT_WHAT_LAST:
2354 /* Not a real code, but listed here to shut up gcc -Wall. */
2356 case BPSTAT_WHAT_KEEP_CHECKING:
2361 /* We come here if we hit a breakpoint but should not
2362 stop for it. Possibly we also were stepping
2363 and should stop for that. So fall through and
2364 test for stepping. But, if not stepping,
2367 /* Are we stepping to get the inferior out of the dynamic linker's
2368 hook (and possibly the dld itself) after catching a shlib
2370 if (ecs->stepping_through_solib_after_catch)
2372 #if defined(SOLIB_ADD)
2373 /* Have we reached our destination? If not, keep going. */
2374 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
2377 fprintf_unfiltered (gdb_stdlog, "infrun: stepping in dynamic linker\n");
2378 ecs->another_trap = 1;
2384 fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n");
2385 /* Else, stop and report the catchpoint(s) whose triggering
2386 caused us to begin stepping. */
2387 ecs->stepping_through_solib_after_catch = 0;
2388 bpstat_clear (&stop_bpstat);
2389 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints);
2390 bpstat_clear (&ecs->stepping_through_solib_catchpoints);
2391 stop_print_frame = 1;
2392 stop_stepping (ecs);
2396 if (step_resume_breakpoint)
2399 fprintf_unfiltered (gdb_stdlog,
2400 "infrun: step-resume breakpoint is inserted\n");
2402 /* Having a step-resume breakpoint overrides anything
2403 else having to do with stepping commands until
2404 that breakpoint is reached. */
2409 if (step_range_end == 0)
2412 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
2413 /* Likewise if we aren't even stepping. */
2418 /* If stepping through a line, keep going if still within it.
2420 Note that step_range_end is the address of the first instruction
2421 beyond the step range, and NOT the address of the last instruction
2423 if (stop_pc >= step_range_start && stop_pc < step_range_end)
2426 fprintf_unfiltered (gdb_stdlog, "infrun: stepping inside range [0x%s-0x%s]\n",
2427 paddr_nz (step_range_start),
2428 paddr_nz (step_range_end));
2433 /* We stepped out of the stepping range. */
2435 /* If we are stepping at the source level and entered the runtime
2436 loader dynamic symbol resolution code, we keep on single stepping
2437 until we exit the run time loader code and reach the callee's
2439 if (step_over_calls == STEP_OVER_UNDEBUGGABLE
2440 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
2441 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc)
2443 && in_solib_dynsym_resolve_code (stop_pc)
2447 CORE_ADDR pc_after_resolver =
2448 gdbarch_skip_solib_resolver (current_gdbarch, stop_pc);
2451 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into dynsym resolve code\n");
2453 if (pc_after_resolver)
2455 /* Set up a step-resume breakpoint at the address
2456 indicated by SKIP_SOLIB_RESOLVER. */
2457 struct symtab_and_line sr_sal;
2459 sr_sal.pc = pc_after_resolver;
2461 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
2468 if (step_range_end != 1
2469 && (step_over_calls == STEP_OVER_UNDEBUGGABLE
2470 || step_over_calls == STEP_OVER_ALL)
2471 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME)
2474 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into signal trampoline\n");
2475 /* The inferior, while doing a "step" or "next", has ended up in
2476 a signal trampoline (either by a signal being delivered or by
2477 the signal handler returning). Just single-step until the
2478 inferior leaves the trampoline (either by calling the handler
2484 /* Check for subroutine calls. The check for the current frame
2485 equalling the step ID is not necessary - the check of the
2486 previous frame's ID is sufficient - but it is a common case and
2487 cheaper than checking the previous frame's ID.
2489 NOTE: frame_id_eq will never report two invalid frame IDs as
2490 being equal, so to get into this block, both the current and
2491 previous frame must have valid frame IDs. */
2492 if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id)
2493 && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id))
2495 CORE_ADDR real_stop_pc;
2498 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
2500 if ((step_over_calls == STEP_OVER_NONE)
2501 || ((step_range_end == 1)
2502 && in_prologue (prev_pc, ecs->stop_func_start)))
2504 /* I presume that step_over_calls is only 0 when we're
2505 supposed to be stepping at the assembly language level
2506 ("stepi"). Just stop. */
2507 /* Also, maybe we just did a "nexti" inside a prolog, so we
2508 thought it was a subroutine call but it was not. Stop as
2511 print_stop_reason (END_STEPPING_RANGE, 0);
2512 stop_stepping (ecs);
2516 if (step_over_calls == STEP_OVER_ALL)
2518 /* We're doing a "next", set a breakpoint at callee's return
2519 address (the address at which the caller will
2521 insert_step_resume_breakpoint_at_caller (get_current_frame ());
2526 /* If we are in a function call trampoline (a stub between the
2527 calling routine and the real function), locate the real
2528 function. That's what tells us (a) whether we want to step
2529 into it at all, and (b) what prologue we want to run to the
2530 end of, if we do step into it. */
2531 real_stop_pc = skip_language_trampoline (get_current_frame (), stop_pc);
2532 if (real_stop_pc == 0)
2533 real_stop_pc = gdbarch_skip_trampoline_code
2534 (current_gdbarch, get_current_frame (), stop_pc);
2535 if (real_stop_pc != 0)
2536 ecs->stop_func_start = real_stop_pc;
2539 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
2540 IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs->stop_func_start)
2542 in_solib_dynsym_resolve_code (ecs->stop_func_start)
2546 struct symtab_and_line sr_sal;
2548 sr_sal.pc = ecs->stop_func_start;
2550 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
2555 /* If we have line number information for the function we are
2556 thinking of stepping into, step into it.
2558 If there are several symtabs at that PC (e.g. with include
2559 files), just want to know whether *any* of them have line
2560 numbers. find_pc_line handles this. */
2562 struct symtab_and_line tmp_sal;
2564 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
2565 if (tmp_sal.line != 0)
2567 step_into_function (ecs);
2572 /* If we have no line number and the step-stop-if-no-debug is
2573 set, we stop the step so that the user has a chance to switch
2574 in assembly mode. */
2575 if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug)
2578 print_stop_reason (END_STEPPING_RANGE, 0);
2579 stop_stepping (ecs);
2583 /* Set a breakpoint at callee's return address (the address at
2584 which the caller will resume). */
2585 insert_step_resume_breakpoint_at_caller (get_current_frame ());
2590 /* If we're in the return path from a shared library trampoline,
2591 we want to proceed through the trampoline when stepping. */
2592 if (gdbarch_in_solib_return_trampoline (current_gdbarch,
2593 stop_pc, ecs->stop_func_name))
2595 /* Determine where this trampoline returns. */
2596 CORE_ADDR real_stop_pc;
2597 real_stop_pc = gdbarch_skip_trampoline_code
2598 (current_gdbarch, get_current_frame (), stop_pc);
2601 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into solib return tramp\n");
2603 /* Only proceed through if we know where it's going. */
2606 /* And put the step-breakpoint there and go until there. */
2607 struct symtab_and_line sr_sal;
2609 init_sal (&sr_sal); /* initialize to zeroes */
2610 sr_sal.pc = real_stop_pc;
2611 sr_sal.section = find_pc_overlay (sr_sal.pc);
2613 /* Do not specify what the fp should be when we stop since
2614 on some machines the prologue is where the new fp value
2616 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
2618 /* Restart without fiddling with the step ranges or
2625 ecs->sal = find_pc_line (stop_pc, 0);
2627 /* NOTE: tausq/2004-05-24: This if block used to be done before all
2628 the trampoline processing logic, however, there are some trampolines
2629 that have no names, so we should do trampoline handling first. */
2630 if (step_over_calls == STEP_OVER_UNDEBUGGABLE
2631 && ecs->stop_func_name == NULL
2632 && ecs->sal.line == 0)
2635 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into undebuggable function\n");
2637 /* The inferior just stepped into, or returned to, an
2638 undebuggable function (where there is no debugging information
2639 and no line number corresponding to the address where the
2640 inferior stopped). Since we want to skip this kind of code,
2641 we keep going until the inferior returns from this
2642 function - unless the user has asked us not to (via
2643 set step-mode) or we no longer know how to get back
2644 to the call site. */
2645 if (step_stop_if_no_debug
2646 || !frame_id_p (frame_unwind_id (get_current_frame ())))
2648 /* If we have no line number and the step-stop-if-no-debug
2649 is set, we stop the step so that the user has a chance to
2650 switch in assembly mode. */
2652 print_stop_reason (END_STEPPING_RANGE, 0);
2653 stop_stepping (ecs);
2658 /* Set a breakpoint at callee's return address (the address
2659 at which the caller will resume). */
2660 insert_step_resume_breakpoint_at_caller (get_current_frame ());
2666 if (step_range_end == 1)
2668 /* It is stepi or nexti. We always want to stop stepping after
2671 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
2673 print_stop_reason (END_STEPPING_RANGE, 0);
2674 stop_stepping (ecs);
2678 if (ecs->sal.line == 0)
2680 /* We have no line number information. That means to stop
2681 stepping (does this always happen right after one instruction,
2682 when we do "s" in a function with no line numbers,
2683 or can this happen as a result of a return or longjmp?). */
2685 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
2687 print_stop_reason (END_STEPPING_RANGE, 0);
2688 stop_stepping (ecs);
2692 if ((stop_pc == ecs->sal.pc)
2693 && (ecs->current_line != ecs->sal.line
2694 || ecs->current_symtab != ecs->sal.symtab))
2696 /* We are at the start of a different line. So stop. Note that
2697 we don't stop if we step into the middle of a different line.
2698 That is said to make things like for (;;) statements work
2701 fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different line\n");
2703 print_stop_reason (END_STEPPING_RANGE, 0);
2704 stop_stepping (ecs);
2708 /* We aren't done stepping.
2710 Optimize by setting the stepping range to the line.
2711 (We might not be in the original line, but if we entered a
2712 new line in mid-statement, we continue stepping. This makes
2713 things like for(;;) statements work better.) */
2715 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end)
2717 /* If this is the last line of the function, don't keep stepping
2718 (it would probably step us out of the function).
2719 This is particularly necessary for a one-line function,
2720 in which after skipping the prologue we better stop even though
2721 we will be in mid-line. */
2723 fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different function\n");
2725 print_stop_reason (END_STEPPING_RANGE, 0);
2726 stop_stepping (ecs);
2729 step_range_start = ecs->sal.pc;
2730 step_range_end = ecs->sal.end;
2731 step_frame_id = get_frame_id (get_current_frame ());
2732 ecs->current_line = ecs->sal.line;
2733 ecs->current_symtab = ecs->sal.symtab;
2735 /* In the case where we just stepped out of a function into the
2736 middle of a line of the caller, continue stepping, but
2737 step_frame_id must be modified to current frame */
2739 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
2740 generous. It will trigger on things like a step into a frameless
2741 stackless leaf function. I think the logic should instead look
2742 at the unwound frame ID has that should give a more robust
2743 indication of what happened. */
2744 if (step - ID == current - ID)
2745 still stepping in same function;
2746 else if (step - ID == unwind (current - ID))
2747 stepped into a function;
2749 stepped out of a function;
2750 /* Of course this assumes that the frame ID unwind code is robust
2751 and we're willing to introduce frame unwind logic into this
2752 function. Fortunately, those days are nearly upon us. */
2755 struct frame_info *frame = get_current_frame ();
2756 struct frame_id current_frame = get_frame_id (frame);
2757 if (!(frame_id_inner (get_frame_arch (frame), current_frame,
2759 step_frame_id = current_frame;
2763 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
2767 /* Are we in the middle of stepping? */
2770 currently_stepping (struct execution_control_state *ecs)
2772 return ((!ecs->handling_longjmp
2773 && ((step_range_end && step_resume_breakpoint == NULL)
2775 || ecs->stepping_through_solib_after_catch
2776 || bpstat_should_step ());
2779 /* Subroutine call with source code we should not step over. Do step
2780 to the first line of code in it. */
2783 step_into_function (struct execution_control_state *ecs)
2786 struct symtab_and_line sr_sal;
2788 s = find_pc_symtab (stop_pc);
2789 if (s && s->language != language_asm)
2790 ecs->stop_func_start = gdbarch_skip_prologue
2791 (current_gdbarch, ecs->stop_func_start);
2793 ecs->sal = find_pc_line (ecs->stop_func_start, 0);
2794 /* Use the step_resume_break to step until the end of the prologue,
2795 even if that involves jumps (as it seems to on the vax under
2797 /* If the prologue ends in the middle of a source line, continue to
2798 the end of that source line (if it is still within the function).
2799 Otherwise, just go to end of prologue. */
2801 && ecs->sal.pc != ecs->stop_func_start
2802 && ecs->sal.end < ecs->stop_func_end)
2803 ecs->stop_func_start = ecs->sal.end;
2805 /* Architectures which require breakpoint adjustment might not be able
2806 to place a breakpoint at the computed address. If so, the test
2807 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
2808 ecs->stop_func_start to an address at which a breakpoint may be
2809 legitimately placed.
2811 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
2812 made, GDB will enter an infinite loop when stepping through
2813 optimized code consisting of VLIW instructions which contain
2814 subinstructions corresponding to different source lines. On
2815 FR-V, it's not permitted to place a breakpoint on any but the
2816 first subinstruction of a VLIW instruction. When a breakpoint is
2817 set, GDB will adjust the breakpoint address to the beginning of
2818 the VLIW instruction. Thus, we need to make the corresponding
2819 adjustment here when computing the stop address. */
2821 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch))
2823 ecs->stop_func_start
2824 = gdbarch_adjust_breakpoint_address (current_gdbarch,
2825 ecs->stop_func_start);
2828 if (ecs->stop_func_start == stop_pc)
2830 /* We are already there: stop now. */
2832 print_stop_reason (END_STEPPING_RANGE, 0);
2833 stop_stepping (ecs);
2838 /* Put the step-breakpoint there and go until there. */
2839 init_sal (&sr_sal); /* initialize to zeroes */
2840 sr_sal.pc = ecs->stop_func_start;
2841 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
2843 /* Do not specify what the fp should be when we stop since on
2844 some machines the prologue is where the new fp value is
2846 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
2848 /* And make sure stepping stops right away then. */
2849 step_range_end = step_range_start;
2854 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
2855 This is used to both functions and to skip over code. */
2858 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal,
2859 struct frame_id sr_id)
2861 /* There should never be more than one step-resume breakpoint per
2862 thread, so we should never be setting a new
2863 step_resume_breakpoint when one is already active. */
2864 gdb_assert (step_resume_breakpoint == NULL);
2867 fprintf_unfiltered (gdb_stdlog,
2868 "infrun: inserting step-resume breakpoint at 0x%s\n",
2869 paddr_nz (sr_sal.pc));
2871 step_resume_breakpoint = set_momentary_breakpoint (sr_sal, sr_id,
2873 if (breakpoints_inserted)
2874 insert_breakpoints ();
2877 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
2878 to skip a potential signal handler.
2880 This is called with the interrupted function's frame. The signal
2881 handler, when it returns, will resume the interrupted function at
2885 insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
2887 struct symtab_and_line sr_sal;
2889 gdb_assert (return_frame != NULL);
2890 init_sal (&sr_sal); /* initialize to zeros */
2892 sr_sal.pc = gdbarch_addr_bits_remove
2893 (current_gdbarch, get_frame_pc (return_frame));
2894 sr_sal.section = find_pc_overlay (sr_sal.pc);
2896 insert_step_resume_breakpoint_at_sal (sr_sal, get_frame_id (return_frame));
2899 /* Similar to insert_step_resume_breakpoint_at_frame, except
2900 but a breakpoint at the previous frame's PC. This is used to
2901 skip a function after stepping into it (for "next" or if the called
2902 function has no debugging information).
2904 The current function has almost always been reached by single
2905 stepping a call or return instruction. NEXT_FRAME belongs to the
2906 current function, and the breakpoint will be set at the caller's
2909 This is a separate function rather than reusing
2910 insert_step_resume_breakpoint_at_frame in order to avoid
2911 get_prev_frame, which may stop prematurely (see the implementation
2912 of frame_unwind_id for an example). */
2915 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
2917 struct symtab_and_line sr_sal;
2919 /* We shouldn't have gotten here if we don't know where the call site
2921 gdb_assert (frame_id_p (frame_unwind_id (next_frame)));
2923 init_sal (&sr_sal); /* initialize to zeros */
2925 sr_sal.pc = gdbarch_addr_bits_remove
2926 (current_gdbarch, frame_pc_unwind (next_frame));
2927 sr_sal.section = find_pc_overlay (sr_sal.pc);
2929 insert_step_resume_breakpoint_at_sal (sr_sal, frame_unwind_id (next_frame));
2933 stop_stepping (struct execution_control_state *ecs)
2936 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
2938 /* Let callers know we don't want to wait for the inferior anymore. */
2939 ecs->wait_some_more = 0;
2942 /* This function handles various cases where we need to continue
2943 waiting for the inferior. */
2944 /* (Used to be the keep_going: label in the old wait_for_inferior) */
2947 keep_going (struct execution_control_state *ecs)
2949 /* Save the pc before execution, to compare with pc after stop. */
2950 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
2952 /* If we did not do break;, it means we should keep running the
2953 inferior and not return to debugger. */
2955 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
2957 /* We took a signal (which we are supposed to pass through to
2958 the inferior, else we'd have done a break above) and we
2959 haven't yet gotten our trap. Simply continue. */
2960 resume (currently_stepping (ecs), stop_signal);
2964 /* Either the trap was not expected, but we are continuing
2965 anyway (the user asked that this signal be passed to the
2968 The signal was SIGTRAP, e.g. it was our signal, but we
2969 decided we should resume from it.
2971 We're going to run this baby now! */
2973 if (!breakpoints_inserted && !ecs->another_trap)
2975 /* Stop stepping when inserting breakpoints
2977 if (insert_breakpoints () != 0)
2979 stop_stepping (ecs);
2982 breakpoints_inserted = 1;
2985 trap_expected = ecs->another_trap;
2987 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
2988 specifies that such a signal should be delivered to the
2991 Typically, this would occure when a user is debugging a
2992 target monitor on a simulator: the target monitor sets a
2993 breakpoint; the simulator encounters this break-point and
2994 halts the simulation handing control to GDB; GDB, noteing
2995 that the break-point isn't valid, returns control back to the
2996 simulator; the simulator then delivers the hardware
2997 equivalent of a SIGNAL_TRAP to the program being debugged. */
2999 if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal])
3000 stop_signal = TARGET_SIGNAL_0;
3003 resume (currently_stepping (ecs), stop_signal);
3006 prepare_to_wait (ecs);
3009 /* This function normally comes after a resume, before
3010 handle_inferior_event exits. It takes care of any last bits of
3011 housekeeping, and sets the all-important wait_some_more flag. */
3014 prepare_to_wait (struct execution_control_state *ecs)
3017 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
3018 if (ecs->infwait_state == infwait_normal_state)
3020 overlay_cache_invalid = 1;
3022 /* We have to invalidate the registers BEFORE calling
3023 target_wait because they can be loaded from the target while
3024 in target_wait. This makes remote debugging a bit more
3025 efficient for those targets that provide critical registers
3026 as part of their normal status mechanism. */
3028 registers_changed ();
3029 ecs->waiton_ptid = pid_to_ptid (-1);
3030 ecs->wp = &(ecs->ws);
3032 /* This is the old end of the while loop. Let everybody know we
3033 want to wait for the inferior some more and get called again
3035 ecs->wait_some_more = 1;
3038 /* Print why the inferior has stopped. We always print something when
3039 the inferior exits, or receives a signal. The rest of the cases are
3040 dealt with later on in normal_stop() and print_it_typical(). Ideally
3041 there should be a call to this function from handle_inferior_event()
3042 each time stop_stepping() is called.*/
3044 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
3046 switch (stop_reason)
3048 case END_STEPPING_RANGE:
3049 /* We are done with a step/next/si/ni command. */
3050 /* For now print nothing. */
3051 /* Print a message only if not in the middle of doing a "step n"
3052 operation for n > 1 */
3053 if (!step_multi || !stop_step)
3054 if (ui_out_is_mi_like_p (uiout))
3057 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
3060 /* The inferior was terminated by a signal. */
3061 annotate_signalled ();
3062 if (ui_out_is_mi_like_p (uiout))
3065 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
3066 ui_out_text (uiout, "\nProgram terminated with signal ");
3067 annotate_signal_name ();
3068 ui_out_field_string (uiout, "signal-name",
3069 target_signal_to_name (stop_info));
3070 annotate_signal_name_end ();
3071 ui_out_text (uiout, ", ");
3072 annotate_signal_string ();
3073 ui_out_field_string (uiout, "signal-meaning",
3074 target_signal_to_string (stop_info));
3075 annotate_signal_string_end ();
3076 ui_out_text (uiout, ".\n");
3077 ui_out_text (uiout, "The program no longer exists.\n");
3080 /* The inferior program is finished. */
3081 annotate_exited (stop_info);
3084 if (ui_out_is_mi_like_p (uiout))
3085 ui_out_field_string (uiout, "reason",
3086 async_reason_lookup (EXEC_ASYNC_EXITED));
3087 ui_out_text (uiout, "\nProgram exited with code ");
3088 ui_out_field_fmt (uiout, "exit-code", "0%o",
3089 (unsigned int) stop_info);
3090 ui_out_text (uiout, ".\n");
3094 if (ui_out_is_mi_like_p (uiout))
3097 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
3098 ui_out_text (uiout, "\nProgram exited normally.\n");
3100 /* Support the --return-child-result option. */
3101 return_child_result_value = stop_info;
3103 case SIGNAL_RECEIVED:
3104 /* Signal received. The signal table tells us to print about
3107 ui_out_text (uiout, "\nProgram received signal ");
3108 annotate_signal_name ();
3109 if (ui_out_is_mi_like_p (uiout))
3111 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
3112 ui_out_field_string (uiout, "signal-name",
3113 target_signal_to_name (stop_info));
3114 annotate_signal_name_end ();
3115 ui_out_text (uiout, ", ");
3116 annotate_signal_string ();
3117 ui_out_field_string (uiout, "signal-meaning",
3118 target_signal_to_string (stop_info));
3119 annotate_signal_string_end ();
3120 ui_out_text (uiout, ".\n");
3123 internal_error (__FILE__, __LINE__,
3124 _("print_stop_reason: unrecognized enum value"));
3130 /* Here to return control to GDB when the inferior stops for real.
3131 Print appropriate messages, remove breakpoints, give terminal our modes.
3133 STOP_PRINT_FRAME nonzero means print the executing frame
3134 (pc, function, args, file, line number and line text).
3135 BREAKPOINTS_FAILED nonzero means stop was due to error
3136 attempting to insert breakpoints. */
3141 struct target_waitstatus last;
3144 get_last_target_status (&last_ptid, &last);
3146 /* As with the notification of thread events, we want to delay
3147 notifying the user that we've switched thread context until
3148 the inferior actually stops.
3150 There's no point in saying anything if the inferior has exited.
3151 Note that SIGNALLED here means "exited with a signal", not
3152 "received a signal". */
3153 if (!ptid_equal (previous_inferior_ptid, inferior_ptid)
3154 && target_has_execution
3155 && last.kind != TARGET_WAITKIND_SIGNALLED
3156 && last.kind != TARGET_WAITKIND_EXITED)
3158 target_terminal_ours_for_output ();
3159 printf_filtered (_("[Switching to %s]\n"),
3160 target_pid_or_tid_to_str (inferior_ptid));
3161 previous_inferior_ptid = inferior_ptid;
3164 /* NOTE drow/2004-01-17: Is this still necessary? */
3165 /* Make sure that the current_frame's pc is correct. This
3166 is a correction for setting up the frame info before doing
3167 gdbarch_decr_pc_after_break */
3168 if (target_has_execution)
3169 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3170 gdbarch_decr_pc_after_break, the program counter can change. Ask the
3171 frame code to check for this and sort out any resultant mess.
3172 gdbarch_decr_pc_after_break needs to just go away. */
3173 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3175 if (target_has_execution && breakpoints_inserted)
3177 if (remove_breakpoints ())
3179 target_terminal_ours_for_output ();
3180 printf_filtered (_("\
3181 Cannot remove breakpoints because program is no longer writable.\n\
3182 It might be running in another process.\n\
3183 Further execution is probably impossible.\n"));
3186 breakpoints_inserted = 0;
3188 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3189 Delete any breakpoint that is to be deleted at the next stop. */
3191 breakpoint_auto_delete (stop_bpstat);
3193 /* If an auto-display called a function and that got a signal,
3194 delete that auto-display to avoid an infinite recursion. */
3196 if (stopped_by_random_signal)
3197 disable_current_display ();
3199 /* Don't print a message if in the middle of doing a "step n"
3200 operation for n > 1 */
3201 if (step_multi && stop_step)
3204 target_terminal_ours ();
3206 /* Set the current source location. This will also happen if we
3207 display the frame below, but the current SAL will be incorrect
3208 during a user hook-stop function. */
3209 if (target_has_stack && !stop_stack_dummy)
3210 set_current_sal_from_frame (get_current_frame (), 1);
3212 /* Look up the hook_stop and run it (CLI internally handles problem
3213 of stop_command's pre-hook not existing). */
3215 catch_errors (hook_stop_stub, stop_command,
3216 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3218 if (!target_has_stack)
3224 /* Select innermost stack frame - i.e., current frame is frame 0,
3225 and current location is based on that.
3226 Don't do this on return from a stack dummy routine,
3227 or if the program has exited. */
3229 if (!stop_stack_dummy)
3231 select_frame (get_current_frame ());
3233 /* Print current location without a level number, if
3234 we have changed functions or hit a breakpoint.
3235 Print source line if we have one.
3236 bpstat_print() contains the logic deciding in detail
3237 what to print, based on the event(s) that just occurred. */
3239 if (stop_print_frame)
3243 int do_frame_printing = 1;
3245 bpstat_ret = bpstat_print (stop_bpstat);
3249 /* If we had hit a shared library event breakpoint,
3250 bpstat_print would print out this message. If we hit
3251 an OS-level shared library event, do the same
3253 if (last.kind == TARGET_WAITKIND_LOADED)
3255 printf_filtered (_("Stopped due to shared library event\n"));
3256 source_flag = SRC_LINE; /* something bogus */
3257 do_frame_printing = 0;
3261 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3262 (or should) carry around the function and does (or
3263 should) use that when doing a frame comparison. */
3265 && frame_id_eq (step_frame_id,
3266 get_frame_id (get_current_frame ()))
3267 && step_start_function == find_pc_function (stop_pc))
3268 source_flag = SRC_LINE; /* finished step, just print source line */
3270 source_flag = SRC_AND_LOC; /* print location and source line */
3272 case PRINT_SRC_AND_LOC:
3273 source_flag = SRC_AND_LOC; /* print location and source line */
3275 case PRINT_SRC_ONLY:
3276 source_flag = SRC_LINE;
3279 source_flag = SRC_LINE; /* something bogus */
3280 do_frame_printing = 0;
3283 internal_error (__FILE__, __LINE__, _("Unknown value."));
3286 if (ui_out_is_mi_like_p (uiout))
3287 ui_out_field_int (uiout, "thread-id",
3288 pid_to_thread_id (inferior_ptid));
3289 /* The behavior of this routine with respect to the source
3291 SRC_LINE: Print only source line
3292 LOCATION: Print only location
3293 SRC_AND_LOC: Print location and source line */
3294 if (do_frame_printing)
3295 print_stack_frame (get_selected_frame (NULL), 0, source_flag);
3297 /* Display the auto-display expressions. */
3302 /* Save the function value return registers, if we care.
3303 We might be about to restore their previous contents. */
3304 if (proceed_to_finish)
3306 /* This should not be necessary. */
3308 regcache_xfree (stop_registers);
3310 /* NB: The copy goes through to the target picking up the value of
3311 all the registers. */
3312 stop_registers = regcache_dup (get_current_regcache ());
3315 if (stop_stack_dummy)
3317 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3318 ends with a setting of the current frame, so we can use that
3320 frame_pop (get_current_frame ());
3321 /* Set stop_pc to what it was before we called the function.
3322 Can't rely on restore_inferior_status because that only gets
3323 called if we don't stop in the called function. */
3324 stop_pc = read_pc ();
3325 select_frame (get_current_frame ());
3329 annotate_stopped ();
3330 observer_notify_normal_stop (stop_bpstat);
3334 hook_stop_stub (void *cmd)
3336 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
3341 signal_stop_state (int signo)
3343 return signal_stop[signo];
3347 signal_print_state (int signo)
3349 return signal_print[signo];
3353 signal_pass_state (int signo)
3355 return signal_program[signo];
3359 signal_stop_update (int signo, int state)
3361 int ret = signal_stop[signo];
3362 signal_stop[signo] = state;
3367 signal_print_update (int signo, int state)
3369 int ret = signal_print[signo];
3370 signal_print[signo] = state;
3375 signal_pass_update (int signo, int state)
3377 int ret = signal_program[signo];
3378 signal_program[signo] = state;
3383 sig_print_header (void)
3385 printf_filtered (_("\
3386 Signal Stop\tPrint\tPass to program\tDescription\n"));
3390 sig_print_info (enum target_signal oursig)
3392 char *name = target_signal_to_name (oursig);
3393 int name_padding = 13 - strlen (name);
3395 if (name_padding <= 0)
3398 printf_filtered ("%s", name);
3399 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
3400 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
3401 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
3402 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
3403 printf_filtered ("%s\n", target_signal_to_string (oursig));
3406 /* Specify how various signals in the inferior should be handled. */
3409 handle_command (char *args, int from_tty)
3412 int digits, wordlen;
3413 int sigfirst, signum, siglast;
3414 enum target_signal oursig;
3417 unsigned char *sigs;
3418 struct cleanup *old_chain;
3422 error_no_arg (_("signal to handle"));
3425 /* Allocate and zero an array of flags for which signals to handle. */
3427 nsigs = (int) TARGET_SIGNAL_LAST;
3428 sigs = (unsigned char *) alloca (nsigs);
3429 memset (sigs, 0, nsigs);
3431 /* Break the command line up into args. */
3433 argv = buildargv (args);
3438 old_chain = make_cleanup_freeargv (argv);
3440 /* Walk through the args, looking for signal oursigs, signal names, and
3441 actions. Signal numbers and signal names may be interspersed with
3442 actions, with the actions being performed for all signals cumulatively
3443 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3445 while (*argv != NULL)
3447 wordlen = strlen (*argv);
3448 for (digits = 0; isdigit ((*argv)[digits]); digits++)
3452 sigfirst = siglast = -1;
3454 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
3456 /* Apply action to all signals except those used by the
3457 debugger. Silently skip those. */
3460 siglast = nsigs - 1;
3462 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
3464 SET_SIGS (nsigs, sigs, signal_stop);
3465 SET_SIGS (nsigs, sigs, signal_print);
3467 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
3469 UNSET_SIGS (nsigs, sigs, signal_program);
3471 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
3473 SET_SIGS (nsigs, sigs, signal_print);
3475 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
3477 SET_SIGS (nsigs, sigs, signal_program);
3479 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
3481 UNSET_SIGS (nsigs, sigs, signal_stop);
3483 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
3485 SET_SIGS (nsigs, sigs, signal_program);
3487 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
3489 UNSET_SIGS (nsigs, sigs, signal_print);
3490 UNSET_SIGS (nsigs, sigs, signal_stop);
3492 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
3494 UNSET_SIGS (nsigs, sigs, signal_program);
3496 else if (digits > 0)
3498 /* It is numeric. The numeric signal refers to our own
3499 internal signal numbering from target.h, not to host/target
3500 signal number. This is a feature; users really should be
3501 using symbolic names anyway, and the common ones like
3502 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3504 sigfirst = siglast = (int)
3505 target_signal_from_command (atoi (*argv));
3506 if ((*argv)[digits] == '-')
3509 target_signal_from_command (atoi ((*argv) + digits + 1));
3511 if (sigfirst > siglast)
3513 /* Bet he didn't figure we'd think of this case... */
3521 oursig = target_signal_from_name (*argv);
3522 if (oursig != TARGET_SIGNAL_UNKNOWN)
3524 sigfirst = siglast = (int) oursig;
3528 /* Not a number and not a recognized flag word => complain. */
3529 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
3533 /* If any signal numbers or symbol names were found, set flags for
3534 which signals to apply actions to. */
3536 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
3538 switch ((enum target_signal) signum)
3540 case TARGET_SIGNAL_TRAP:
3541 case TARGET_SIGNAL_INT:
3542 if (!allsigs && !sigs[signum])
3544 if (query ("%s is used by the debugger.\n\
3545 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum)))
3551 printf_unfiltered (_("Not confirmed, unchanged.\n"));
3552 gdb_flush (gdb_stdout);
3556 case TARGET_SIGNAL_0:
3557 case TARGET_SIGNAL_DEFAULT:
3558 case TARGET_SIGNAL_UNKNOWN:
3559 /* Make sure that "all" doesn't print these. */
3570 target_notice_signals (inferior_ptid);
3574 /* Show the results. */
3575 sig_print_header ();
3576 for (signum = 0; signum < nsigs; signum++)
3580 sig_print_info (signum);
3585 do_cleanups (old_chain);
3589 xdb_handle_command (char *args, int from_tty)
3592 struct cleanup *old_chain;
3594 /* Break the command line up into args. */
3596 argv = buildargv (args);
3601 old_chain = make_cleanup_freeargv (argv);
3602 if (argv[1] != (char *) NULL)
3607 bufLen = strlen (argv[0]) + 20;
3608 argBuf = (char *) xmalloc (bufLen);
3612 enum target_signal oursig;
3614 oursig = target_signal_from_name (argv[0]);
3615 memset (argBuf, 0, bufLen);
3616 if (strcmp (argv[1], "Q") == 0)
3617 sprintf (argBuf, "%s %s", argv[0], "noprint");
3620 if (strcmp (argv[1], "s") == 0)
3622 if (!signal_stop[oursig])
3623 sprintf (argBuf, "%s %s", argv[0], "stop");
3625 sprintf (argBuf, "%s %s", argv[0], "nostop");
3627 else if (strcmp (argv[1], "i") == 0)
3629 if (!signal_program[oursig])
3630 sprintf (argBuf, "%s %s", argv[0], "pass");
3632 sprintf (argBuf, "%s %s", argv[0], "nopass");
3634 else if (strcmp (argv[1], "r") == 0)
3636 if (!signal_print[oursig])
3637 sprintf (argBuf, "%s %s", argv[0], "print");
3639 sprintf (argBuf, "%s %s", argv[0], "noprint");
3645 handle_command (argBuf, from_tty);
3647 printf_filtered (_("Invalid signal handling flag.\n"));
3652 do_cleanups (old_chain);
3655 /* Print current contents of the tables set by the handle command.
3656 It is possible we should just be printing signals actually used
3657 by the current target (but for things to work right when switching
3658 targets, all signals should be in the signal tables). */
3661 signals_info (char *signum_exp, int from_tty)
3663 enum target_signal oursig;
3664 sig_print_header ();
3668 /* First see if this is a symbol name. */
3669 oursig = target_signal_from_name (signum_exp);
3670 if (oursig == TARGET_SIGNAL_UNKNOWN)
3672 /* No, try numeric. */
3674 target_signal_from_command (parse_and_eval_long (signum_exp));
3676 sig_print_info (oursig);
3680 printf_filtered ("\n");
3681 /* These ugly casts brought to you by the native VAX compiler. */
3682 for (oursig = TARGET_SIGNAL_FIRST;
3683 (int) oursig < (int) TARGET_SIGNAL_LAST;
3684 oursig = (enum target_signal) ((int) oursig + 1))
3688 if (oursig != TARGET_SIGNAL_UNKNOWN
3689 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
3690 sig_print_info (oursig);
3693 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
3696 struct inferior_status
3698 enum target_signal stop_signal;
3702 int stop_stack_dummy;
3703 int stopped_by_random_signal;
3705 CORE_ADDR step_range_start;
3706 CORE_ADDR step_range_end;
3707 struct frame_id step_frame_id;
3708 enum step_over_calls_kind step_over_calls;
3709 CORE_ADDR step_resume_break_address;
3710 int stop_after_trap;
3713 /* These are here because if call_function_by_hand has written some
3714 registers and then decides to call error(), we better not have changed
3716 struct regcache *registers;
3718 /* A frame unique identifier. */
3719 struct frame_id selected_frame_id;
3721 int breakpoint_proceeded;
3722 int restore_stack_info;
3723 int proceed_to_finish;
3727 write_inferior_status_register (struct inferior_status *inf_status, int regno,
3730 int size = register_size (current_gdbarch, regno);
3731 void *buf = alloca (size);
3732 store_signed_integer (buf, size, val);
3733 regcache_raw_write (inf_status->registers, regno, buf);
3736 /* Save all of the information associated with the inferior<==>gdb
3737 connection. INF_STATUS is a pointer to a "struct inferior_status"
3738 (defined in inferior.h). */
3740 struct inferior_status *
3741 save_inferior_status (int restore_stack_info)
3743 struct inferior_status *inf_status = XMALLOC (struct inferior_status);
3745 inf_status->stop_signal = stop_signal;
3746 inf_status->stop_pc = stop_pc;
3747 inf_status->stop_step = stop_step;
3748 inf_status->stop_stack_dummy = stop_stack_dummy;
3749 inf_status->stopped_by_random_signal = stopped_by_random_signal;
3750 inf_status->trap_expected = trap_expected;
3751 inf_status->step_range_start = step_range_start;
3752 inf_status->step_range_end = step_range_end;
3753 inf_status->step_frame_id = step_frame_id;
3754 inf_status->step_over_calls = step_over_calls;
3755 inf_status->stop_after_trap = stop_after_trap;
3756 inf_status->stop_soon = stop_soon;
3757 /* Save original bpstat chain here; replace it with copy of chain.
3758 If caller's caller is walking the chain, they'll be happier if we
3759 hand them back the original chain when restore_inferior_status is
3761 inf_status->stop_bpstat = stop_bpstat;
3762 stop_bpstat = bpstat_copy (stop_bpstat);
3763 inf_status->breakpoint_proceeded = breakpoint_proceeded;
3764 inf_status->restore_stack_info = restore_stack_info;
3765 inf_status->proceed_to_finish = proceed_to_finish;
3767 inf_status->registers = regcache_dup (get_current_regcache ());
3769 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
3774 restore_selected_frame (void *args)
3776 struct frame_id *fid = (struct frame_id *) args;
3777 struct frame_info *frame;
3779 frame = frame_find_by_id (*fid);
3781 /* If inf_status->selected_frame_id is NULL, there was no previously
3785 warning (_("Unable to restore previously selected frame."));
3789 select_frame (frame);
3795 restore_inferior_status (struct inferior_status *inf_status)
3797 stop_signal = inf_status->stop_signal;
3798 stop_pc = inf_status->stop_pc;
3799 stop_step = inf_status->stop_step;
3800 stop_stack_dummy = inf_status->stop_stack_dummy;
3801 stopped_by_random_signal = inf_status->stopped_by_random_signal;
3802 trap_expected = inf_status->trap_expected;
3803 step_range_start = inf_status->step_range_start;
3804 step_range_end = inf_status->step_range_end;
3805 step_frame_id = inf_status->step_frame_id;
3806 step_over_calls = inf_status->step_over_calls;
3807 stop_after_trap = inf_status->stop_after_trap;
3808 stop_soon = inf_status->stop_soon;
3809 bpstat_clear (&stop_bpstat);
3810 stop_bpstat = inf_status->stop_bpstat;
3811 breakpoint_proceeded = inf_status->breakpoint_proceeded;
3812 proceed_to_finish = inf_status->proceed_to_finish;
3814 /* The inferior can be gone if the user types "print exit(0)"
3815 (and perhaps other times). */
3816 if (target_has_execution)
3817 /* NB: The register write goes through to the target. */
3818 regcache_cpy (get_current_regcache (), inf_status->registers);
3819 regcache_xfree (inf_status->registers);
3821 /* FIXME: If we are being called after stopping in a function which
3822 is called from gdb, we should not be trying to restore the
3823 selected frame; it just prints a spurious error message (The
3824 message is useful, however, in detecting bugs in gdb (like if gdb
3825 clobbers the stack)). In fact, should we be restoring the
3826 inferior status at all in that case? . */
3828 if (target_has_stack && inf_status->restore_stack_info)
3830 /* The point of catch_errors is that if the stack is clobbered,
3831 walking the stack might encounter a garbage pointer and
3832 error() trying to dereference it. */
3834 (restore_selected_frame, &inf_status->selected_frame_id,
3835 "Unable to restore previously selected frame:\n",
3836 RETURN_MASK_ERROR) == 0)
3837 /* Error in restoring the selected frame. Select the innermost
3839 select_frame (get_current_frame ());
3847 do_restore_inferior_status_cleanup (void *sts)
3849 restore_inferior_status (sts);
3853 make_cleanup_restore_inferior_status (struct inferior_status *inf_status)
3855 return make_cleanup (do_restore_inferior_status_cleanup, inf_status);
3859 discard_inferior_status (struct inferior_status *inf_status)
3861 /* See save_inferior_status for info on stop_bpstat. */
3862 bpstat_clear (&inf_status->stop_bpstat);
3863 regcache_xfree (inf_status->registers);
3868 inferior_has_forked (int pid, int *child_pid)
3870 struct target_waitstatus last;
3873 get_last_target_status (&last_ptid, &last);
3875 if (last.kind != TARGET_WAITKIND_FORKED)
3878 if (ptid_get_pid (last_ptid) != pid)
3881 *child_pid = last.value.related_pid;
3886 inferior_has_vforked (int pid, int *child_pid)
3888 struct target_waitstatus last;
3891 get_last_target_status (&last_ptid, &last);
3893 if (last.kind != TARGET_WAITKIND_VFORKED)
3896 if (ptid_get_pid (last_ptid) != pid)
3899 *child_pid = last.value.related_pid;
3904 inferior_has_execd (int pid, char **execd_pathname)
3906 struct target_waitstatus last;
3909 get_last_target_status (&last_ptid, &last);
3911 if (last.kind != TARGET_WAITKIND_EXECD)
3914 if (ptid_get_pid (last_ptid) != pid)
3917 *execd_pathname = xstrdup (last.value.execd_pathname);
3921 /* Oft used ptids */
3923 ptid_t minus_one_ptid;
3925 /* Create a ptid given the necessary PID, LWP, and TID components. */
3928 ptid_build (int pid, long lwp, long tid)
3938 /* Create a ptid from just a pid. */
3941 pid_to_ptid (int pid)
3943 return ptid_build (pid, 0, 0);
3946 /* Fetch the pid (process id) component from a ptid. */
3949 ptid_get_pid (ptid_t ptid)
3954 /* Fetch the lwp (lightweight process) component from a ptid. */
3957 ptid_get_lwp (ptid_t ptid)
3962 /* Fetch the tid (thread id) component from a ptid. */
3965 ptid_get_tid (ptid_t ptid)
3970 /* ptid_equal() is used to test equality of two ptids. */
3973 ptid_equal (ptid_t ptid1, ptid_t ptid2)
3975 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
3976 && ptid1.tid == ptid2.tid);
3979 /* restore_inferior_ptid() will be used by the cleanup machinery
3980 to restore the inferior_ptid value saved in a call to
3981 save_inferior_ptid(). */
3984 restore_inferior_ptid (void *arg)
3986 ptid_t *saved_ptid_ptr = arg;
3987 inferior_ptid = *saved_ptid_ptr;
3991 /* Save the value of inferior_ptid so that it may be restored by a
3992 later call to do_cleanups(). Returns the struct cleanup pointer
3993 needed for later doing the cleanup. */
3996 save_inferior_ptid (void)
3998 ptid_t *saved_ptid_ptr;
4000 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
4001 *saved_ptid_ptr = inferior_ptid;
4002 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
4007 _initialize_infrun (void)
4011 struct cmd_list_element *c;
4013 add_info ("signals", signals_info, _("\
4014 What debugger does when program gets various signals.\n\
4015 Specify a signal as argument to print info on that signal only."));
4016 add_info_alias ("handle", "signals", 0);
4018 add_com ("handle", class_run, handle_command, _("\
4019 Specify how to handle a signal.\n\
4020 Args are signals and actions to apply to those signals.\n\
4021 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4022 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4023 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4024 The special arg \"all\" is recognized to mean all signals except those\n\
4025 used by the debugger, typically SIGTRAP and SIGINT.\n\
4026 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4027 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4028 Stop means reenter debugger if this signal happens (implies print).\n\
4029 Print means print a message if this signal happens.\n\
4030 Pass means let program see this signal; otherwise program doesn't know.\n\
4031 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4032 Pass and Stop may be combined."));
4035 add_com ("lz", class_info, signals_info, _("\
4036 What debugger does when program gets various signals.\n\
4037 Specify a signal as argument to print info on that signal only."));
4038 add_com ("z", class_run, xdb_handle_command, _("\
4039 Specify how to handle a signal.\n\
4040 Args are signals and actions to apply to those signals.\n\
4041 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4042 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4043 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4044 The special arg \"all\" is recognized to mean all signals except those\n\
4045 used by the debugger, typically SIGTRAP and SIGINT.\n\
4046 Recognized actions include \"s\" (toggles between stop and nostop), \n\
4047 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4048 nopass), \"Q\" (noprint)\n\
4049 Stop means reenter debugger if this signal happens (implies print).\n\
4050 Print means print a message if this signal happens.\n\
4051 Pass means let program see this signal; otherwise program doesn't know.\n\
4052 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4053 Pass and Stop may be combined."));
4057 stop_command = add_cmd ("stop", class_obscure,
4058 not_just_help_class_command, _("\
4059 There is no `stop' command, but you can set a hook on `stop'.\n\
4060 This allows you to set a list of commands to be run each time execution\n\
4061 of the program stops."), &cmdlist);
4063 add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
4064 Set inferior debugging."), _("\
4065 Show inferior debugging."), _("\
4066 When non-zero, inferior specific debugging is enabled."),
4069 &setdebuglist, &showdebuglist);
4071 numsigs = (int) TARGET_SIGNAL_LAST;
4072 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
4073 signal_print = (unsigned char *)
4074 xmalloc (sizeof (signal_print[0]) * numsigs);
4075 signal_program = (unsigned char *)
4076 xmalloc (sizeof (signal_program[0]) * numsigs);
4077 for (i = 0; i < numsigs; i++)
4080 signal_print[i] = 1;
4081 signal_program[i] = 1;
4084 /* Signals caused by debugger's own actions
4085 should not be given to the program afterwards. */
4086 signal_program[TARGET_SIGNAL_TRAP] = 0;
4087 signal_program[TARGET_SIGNAL_INT] = 0;
4089 /* Signals that are not errors should not normally enter the debugger. */
4090 signal_stop[TARGET_SIGNAL_ALRM] = 0;
4091 signal_print[TARGET_SIGNAL_ALRM] = 0;
4092 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
4093 signal_print[TARGET_SIGNAL_VTALRM] = 0;
4094 signal_stop[TARGET_SIGNAL_PROF] = 0;
4095 signal_print[TARGET_SIGNAL_PROF] = 0;
4096 signal_stop[TARGET_SIGNAL_CHLD] = 0;
4097 signal_print[TARGET_SIGNAL_CHLD] = 0;
4098 signal_stop[TARGET_SIGNAL_IO] = 0;
4099 signal_print[TARGET_SIGNAL_IO] = 0;
4100 signal_stop[TARGET_SIGNAL_POLL] = 0;
4101 signal_print[TARGET_SIGNAL_POLL] = 0;
4102 signal_stop[TARGET_SIGNAL_URG] = 0;
4103 signal_print[TARGET_SIGNAL_URG] = 0;
4104 signal_stop[TARGET_SIGNAL_WINCH] = 0;
4105 signal_print[TARGET_SIGNAL_WINCH] = 0;
4107 /* These signals are used internally by user-level thread
4108 implementations. (See signal(5) on Solaris.) Like the above
4109 signals, a healthy program receives and handles them as part of
4110 its normal operation. */
4111 signal_stop[TARGET_SIGNAL_LWP] = 0;
4112 signal_print[TARGET_SIGNAL_LWP] = 0;
4113 signal_stop[TARGET_SIGNAL_WAITING] = 0;
4114 signal_print[TARGET_SIGNAL_WAITING] = 0;
4115 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
4116 signal_print[TARGET_SIGNAL_CANCEL] = 0;
4118 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
4119 &stop_on_solib_events, _("\
4120 Set stopping for shared library events."), _("\
4121 Show stopping for shared library events."), _("\
4122 If nonzero, gdb will give control to the user when the dynamic linker\n\
4123 notifies gdb of shared library events. The most common event of interest\n\
4124 to the user would be loading/unloading of a new library."),
4126 show_stop_on_solib_events,
4127 &setlist, &showlist);
4129 add_setshow_enum_cmd ("follow-fork-mode", class_run,
4130 follow_fork_mode_kind_names,
4131 &follow_fork_mode_string, _("\
4132 Set debugger response to a program call of fork or vfork."), _("\
4133 Show debugger response to a program call of fork or vfork."), _("\
4134 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4135 parent - the original process is debugged after a fork\n\
4136 child - the new process is debugged after a fork\n\
4137 The unfollowed process will continue to run.\n\
4138 By default, the debugger will follow the parent process."),
4140 show_follow_fork_mode_string,
4141 &setlist, &showlist);
4143 add_setshow_enum_cmd ("scheduler-locking", class_run,
4144 scheduler_enums, &scheduler_mode, _("\
4145 Set mode for locking scheduler during execution."), _("\
4146 Show mode for locking scheduler during execution."), _("\
4147 off == no locking (threads may preempt at any time)\n\
4148 on == full locking (no thread except the current thread may run)\n\
4149 step == scheduler locked during every single-step operation.\n\
4150 In this mode, no other thread may run during a step command.\n\
4151 Other threads may run while stepping over a function call ('next')."),
4152 set_schedlock_func, /* traps on target vector */
4153 show_scheduler_mode,
4154 &setlist, &showlist);
4156 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
4157 Set mode of the step operation."), _("\
4158 Show mode of the step operation."), _("\
4159 When set, doing a step over a function without debug line information\n\
4160 will stop at the first instruction of that function. Otherwise, the\n\
4161 function is skipped and the step command stops at a different source line."),
4163 show_step_stop_if_no_debug,
4164 &setlist, &showlist);
4166 /* ptid initializations */
4167 null_ptid = ptid_build (0, 0, 0);
4168 minus_one_ptid = ptid_build (-1, 0, 0);
4169 inferior_ptid = null_ptid;
4170 target_last_wait_ptid = minus_one_ptid;