1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2015 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "breakpoint.h"
31 #include "cli/cli-script.h"
33 #include "gdbthread.h"
45 #include "dictionary.h"
47 #include "mi/mi-common.h"
48 #include "event-top.h"
50 #include "record-full.h"
51 #include "inline-frame.h"
53 #include "tracepoint.h"
54 #include "continuations.h"
59 #include "completer.h"
60 #include "target-descriptions.h"
61 #include "target-dcache.h"
64 /* Prototypes for local functions */
66 static void signals_info (char *, int);
68 static void handle_command (char *, int);
70 static void sig_print_info (enum gdb_signal);
72 static void sig_print_header (void);
74 static void resume_cleanups (void *);
76 static int hook_stop_stub (void *);
78 static int restore_selected_frame (void *);
80 static int follow_fork (void);
82 static int follow_fork_inferior (int follow_child, int detach_fork);
84 static void follow_inferior_reset_breakpoints (void);
86 static void set_schedlock_func (char *args, int from_tty,
87 struct cmd_list_element *c);
89 static int currently_stepping (struct thread_info *tp);
91 static void xdb_handle_command (char *args, int from_tty);
93 void _initialize_infrun (void);
95 void nullify_last_target_wait_ptid (void);
97 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info *);
99 static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
101 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
103 /* When set, stop the 'step' command if we enter a function which has
104 no line number information. The normal behavior is that we step
105 over such function. */
106 int step_stop_if_no_debug = 0;
108 show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
109 struct cmd_list_element *c, const char *value)
111 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
114 /* In asynchronous mode, but simulating synchronous execution. */
116 int sync_execution = 0;
118 /* proceed and normal_stop use this to notify the user when the
119 inferior stopped in a different thread than it had been running
122 static ptid_t previous_inferior_ptid;
124 /* If set (default for legacy reasons), when following a fork, GDB
125 will detach from one of the fork branches, child or parent.
126 Exactly which branch is detached depends on 'set follow-fork-mode'
129 static int detach_fork = 1;
131 int debug_displaced = 0;
133 show_debug_displaced (struct ui_file *file, int from_tty,
134 struct cmd_list_element *c, const char *value)
136 fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value);
139 unsigned int debug_infrun = 0;
141 show_debug_infrun (struct ui_file *file, int from_tty,
142 struct cmd_list_element *c, const char *value)
144 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
148 /* Support for disabling address space randomization. */
150 int disable_randomization = 1;
153 show_disable_randomization (struct ui_file *file, int from_tty,
154 struct cmd_list_element *c, const char *value)
156 if (target_supports_disable_randomization ())
157 fprintf_filtered (file,
158 _("Disabling randomization of debuggee's "
159 "virtual address space is %s.\n"),
162 fputs_filtered (_("Disabling randomization of debuggee's "
163 "virtual address space is unsupported on\n"
164 "this platform.\n"), file);
168 set_disable_randomization (char *args, int from_tty,
169 struct cmd_list_element *c)
171 if (!target_supports_disable_randomization ())
172 error (_("Disabling randomization of debuggee's "
173 "virtual address space is unsupported on\n"
177 /* User interface for non-stop mode. */
180 static int non_stop_1 = 0;
183 set_non_stop (char *args, int from_tty,
184 struct cmd_list_element *c)
186 if (target_has_execution)
188 non_stop_1 = non_stop;
189 error (_("Cannot change this setting while the inferior is running."));
192 non_stop = non_stop_1;
196 show_non_stop (struct ui_file *file, int from_tty,
197 struct cmd_list_element *c, const char *value)
199 fprintf_filtered (file,
200 _("Controlling the inferior in non-stop mode is %s.\n"),
204 /* "Observer mode" is somewhat like a more extreme version of
205 non-stop, in which all GDB operations that might affect the
206 target's execution have been disabled. */
208 int observer_mode = 0;
209 static int observer_mode_1 = 0;
212 set_observer_mode (char *args, int from_tty,
213 struct cmd_list_element *c)
215 if (target_has_execution)
217 observer_mode_1 = observer_mode;
218 error (_("Cannot change this setting while the inferior is running."));
221 observer_mode = observer_mode_1;
223 may_write_registers = !observer_mode;
224 may_write_memory = !observer_mode;
225 may_insert_breakpoints = !observer_mode;
226 may_insert_tracepoints = !observer_mode;
227 /* We can insert fast tracepoints in or out of observer mode,
228 but enable them if we're going into this mode. */
230 may_insert_fast_tracepoints = 1;
231 may_stop = !observer_mode;
232 update_target_permissions ();
234 /* Going *into* observer mode we must force non-stop, then
235 going out we leave it that way. */
238 pagination_enabled = 0;
239 non_stop = non_stop_1 = 1;
243 printf_filtered (_("Observer mode is now %s.\n"),
244 (observer_mode ? "on" : "off"));
248 show_observer_mode (struct ui_file *file, int from_tty,
249 struct cmd_list_element *c, const char *value)
251 fprintf_filtered (file, _("Observer mode is %s.\n"), value);
254 /* This updates the value of observer mode based on changes in
255 permissions. Note that we are deliberately ignoring the values of
256 may-write-registers and may-write-memory, since the user may have
257 reason to enable these during a session, for instance to turn on a
258 debugging-related global. */
261 update_observer_mode (void)
265 newval = (!may_insert_breakpoints
266 && !may_insert_tracepoints
267 && may_insert_fast_tracepoints
271 /* Let the user know if things change. */
272 if (newval != observer_mode)
273 printf_filtered (_("Observer mode is now %s.\n"),
274 (newval ? "on" : "off"));
276 observer_mode = observer_mode_1 = newval;
279 /* Tables of how to react to signals; the user sets them. */
281 static unsigned char *signal_stop;
282 static unsigned char *signal_print;
283 static unsigned char *signal_program;
285 /* Table of signals that are registered with "catch signal". A
286 non-zero entry indicates that the signal is caught by some "catch
287 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
289 static unsigned char *signal_catch;
291 /* Table of signals that the target may silently handle.
292 This is automatically determined from the flags above,
293 and simply cached here. */
294 static unsigned char *signal_pass;
296 #define SET_SIGS(nsigs,sigs,flags) \
298 int signum = (nsigs); \
299 while (signum-- > 0) \
300 if ((sigs)[signum]) \
301 (flags)[signum] = 1; \
304 #define UNSET_SIGS(nsigs,sigs,flags) \
306 int signum = (nsigs); \
307 while (signum-- > 0) \
308 if ((sigs)[signum]) \
309 (flags)[signum] = 0; \
312 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
313 this function is to avoid exporting `signal_program'. */
316 update_signals_program_target (void)
318 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
321 /* Value to pass to target_resume() to cause all threads to resume. */
323 #define RESUME_ALL minus_one_ptid
325 /* Command list pointer for the "stop" placeholder. */
327 static struct cmd_list_element *stop_command;
329 /* Function inferior was in as of last step command. */
331 static struct symbol *step_start_function;
333 /* Nonzero if we want to give control to the user when we're notified
334 of shared library events by the dynamic linker. */
335 int stop_on_solib_events;
337 /* Enable or disable optional shared library event breakpoints
338 as appropriate when the above flag is changed. */
341 set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c)
343 update_solib_breakpoints ();
347 show_stop_on_solib_events (struct ui_file *file, int from_tty,
348 struct cmd_list_element *c, const char *value)
350 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
354 /* Nonzero means expecting a trace trap
355 and should stop the inferior and return silently when it happens. */
359 /* Save register contents here when executing a "finish" command or are
360 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
361 Thus this contains the return value from the called function (assuming
362 values are returned in a register). */
364 struct regcache *stop_registers;
366 /* Nonzero after stop if current stack frame should be printed. */
368 static int stop_print_frame;
370 /* This is a cached copy of the pid/waitstatus of the last event
371 returned by target_wait()/deprecated_target_wait_hook(). This
372 information is returned by get_last_target_status(). */
373 static ptid_t target_last_wait_ptid;
374 static struct target_waitstatus target_last_waitstatus;
376 static void context_switch (ptid_t ptid);
378 void init_thread_stepping_state (struct thread_info *tss);
380 static const char follow_fork_mode_child[] = "child";
381 static const char follow_fork_mode_parent[] = "parent";
383 static const char *const follow_fork_mode_kind_names[] = {
384 follow_fork_mode_child,
385 follow_fork_mode_parent,
389 static const char *follow_fork_mode_string = follow_fork_mode_parent;
391 show_follow_fork_mode_string (struct ui_file *file, int from_tty,
392 struct cmd_list_element *c, const char *value)
394 fprintf_filtered (file,
395 _("Debugger response to a program "
396 "call of fork or vfork is \"%s\".\n"),
401 /* Handle changes to the inferior list based on the type of fork,
402 which process is being followed, and whether the other process
403 should be detached. On entry inferior_ptid must be the ptid of
404 the fork parent. At return inferior_ptid is the ptid of the
405 followed inferior. */
408 follow_fork_inferior (int follow_child, int detach_fork)
411 int parent_pid, child_pid;
413 has_vforked = (inferior_thread ()->pending_follow.kind
414 == TARGET_WAITKIND_VFORKED);
415 parent_pid = ptid_get_lwp (inferior_ptid);
417 parent_pid = ptid_get_pid (inferior_ptid);
419 = ptid_get_pid (inferior_thread ()->pending_follow.value.related_pid);
422 && !non_stop /* Non-stop always resumes both branches. */
423 && (!target_is_async_p () || sync_execution)
424 && !(follow_child || detach_fork || sched_multi))
426 /* The parent stays blocked inside the vfork syscall until the
427 child execs or exits. If we don't let the child run, then
428 the parent stays blocked. If we're telling the parent to run
429 in the foreground, the user will not be able to ctrl-c to get
430 back the terminal, effectively hanging the debug session. */
431 fprintf_filtered (gdb_stderr, _("\
432 Can not resume the parent process over vfork in the foreground while\n\
433 holding the child stopped. Try \"set detach-on-fork\" or \
434 \"set schedule-multiple\".\n"));
435 /* FIXME output string > 80 columns. */
441 /* Detach new forked process? */
444 struct cleanup *old_chain;
446 /* Before detaching from the child, remove all breakpoints
447 from it. If we forked, then this has already been taken
448 care of by infrun.c. If we vforked however, any
449 breakpoint inserted in the parent is visible in the
450 child, even those added while stopped in a vfork
451 catchpoint. This will remove the breakpoints from the
452 parent also, but they'll be reinserted below. */
455 /* Keep breakpoints list in sync. */
456 remove_breakpoints_pid (ptid_get_pid (inferior_ptid));
459 if (info_verbose || debug_infrun)
461 target_terminal_ours_for_output ();
462 fprintf_filtered (gdb_stdlog,
463 _("Detaching after %s from "
464 "child process %d.\n"),
465 has_vforked ? "vfork" : "fork",
471 struct inferior *parent_inf, *child_inf;
472 struct cleanup *old_chain;
474 /* Add process to GDB's tables. */
475 child_inf = add_inferior (child_pid);
477 parent_inf = current_inferior ();
478 child_inf->attach_flag = parent_inf->attach_flag;
479 copy_terminal_info (child_inf, parent_inf);
480 child_inf->gdbarch = parent_inf->gdbarch;
481 copy_inferior_target_desc_info (child_inf, parent_inf);
483 old_chain = save_inferior_ptid ();
484 save_current_program_space ();
486 inferior_ptid = ptid_build (child_pid, child_pid, 0);
487 add_thread (inferior_ptid);
488 child_inf->symfile_flags = SYMFILE_NO_READ;
490 /* If this is a vfork child, then the address-space is
491 shared with the parent. */
494 child_inf->pspace = parent_inf->pspace;
495 child_inf->aspace = parent_inf->aspace;
497 /* The parent will be frozen until the child is done
498 with the shared region. Keep track of the
500 child_inf->vfork_parent = parent_inf;
501 child_inf->pending_detach = 0;
502 parent_inf->vfork_child = child_inf;
503 parent_inf->pending_detach = 0;
507 child_inf->aspace = new_address_space ();
508 child_inf->pspace = add_program_space (child_inf->aspace);
509 child_inf->removable = 1;
510 set_current_program_space (child_inf->pspace);
511 clone_program_space (child_inf->pspace, parent_inf->pspace);
513 /* Let the shared library layer (e.g., solib-svr4) learn
514 about this new process, relocate the cloned exec, pull
515 in shared libraries, and install the solib event
516 breakpoint. If a "cloned-VM" event was propagated
517 better throughout the core, this wouldn't be
519 solib_create_inferior_hook (0);
522 do_cleanups (old_chain);
527 struct inferior *parent_inf;
529 parent_inf = current_inferior ();
531 /* If we detached from the child, then we have to be careful
532 to not insert breakpoints in the parent until the child
533 is done with the shared memory region. However, if we're
534 staying attached to the child, then we can and should
535 insert breakpoints, so that we can debug it. A
536 subsequent child exec or exit is enough to know when does
537 the child stops using the parent's address space. */
538 parent_inf->waiting_for_vfork_done = detach_fork;
539 parent_inf->pspace->breakpoints_not_allowed = detach_fork;
544 /* Follow the child. */
545 struct inferior *parent_inf, *child_inf;
546 struct program_space *parent_pspace;
548 if (info_verbose || debug_infrun)
550 target_terminal_ours_for_output ();
551 fprintf_filtered (gdb_stdlog,
552 _("Attaching after process %d "
553 "%s to child process %d.\n"),
555 has_vforked ? "vfork" : "fork",
559 /* Add the new inferior first, so that the target_detach below
560 doesn't unpush the target. */
562 child_inf = add_inferior (child_pid);
564 parent_inf = current_inferior ();
565 child_inf->attach_flag = parent_inf->attach_flag;
566 copy_terminal_info (child_inf, parent_inf);
567 child_inf->gdbarch = parent_inf->gdbarch;
568 copy_inferior_target_desc_info (child_inf, parent_inf);
570 parent_pspace = parent_inf->pspace;
572 /* If we're vforking, we want to hold on to the parent until the
573 child exits or execs. At child exec or exit time we can
574 remove the old breakpoints from the parent and detach or
575 resume debugging it. Otherwise, detach the parent now; we'll
576 want to reuse it's program/address spaces, but we can't set
577 them to the child before removing breakpoints from the
578 parent, otherwise, the breakpoints module could decide to
579 remove breakpoints from the wrong process (since they'd be
580 assigned to the same address space). */
584 gdb_assert (child_inf->vfork_parent == NULL);
585 gdb_assert (parent_inf->vfork_child == NULL);
586 child_inf->vfork_parent = parent_inf;
587 child_inf->pending_detach = 0;
588 parent_inf->vfork_child = child_inf;
589 parent_inf->pending_detach = detach_fork;
590 parent_inf->waiting_for_vfork_done = 0;
592 else if (detach_fork)
594 if (info_verbose || debug_infrun)
596 target_terminal_ours_for_output ();
597 fprintf_filtered (gdb_stdlog,
598 _("Detaching after fork from "
599 "child process %d.\n"),
603 target_detach (NULL, 0);
606 /* Note that the detach above makes PARENT_INF dangling. */
608 /* Add the child thread to the appropriate lists, and switch to
609 this new thread, before cloning the program space, and
610 informing the solib layer about this new process. */
612 inferior_ptid = ptid_build (child_pid, child_pid, 0);
613 add_thread (inferior_ptid);
615 /* If this is a vfork child, then the address-space is shared
616 with the parent. If we detached from the parent, then we can
617 reuse the parent's program/address spaces. */
618 if (has_vforked || detach_fork)
620 child_inf->pspace = parent_pspace;
621 child_inf->aspace = child_inf->pspace->aspace;
625 child_inf->aspace = new_address_space ();
626 child_inf->pspace = add_program_space (child_inf->aspace);
627 child_inf->removable = 1;
628 child_inf->symfile_flags = SYMFILE_NO_READ;
629 set_current_program_space (child_inf->pspace);
630 clone_program_space (child_inf->pspace, parent_pspace);
632 /* Let the shared library layer (e.g., solib-svr4) learn
633 about this new process, relocate the cloned exec, pull in
634 shared libraries, and install the solib event breakpoint.
635 If a "cloned-VM" event was propagated better throughout
636 the core, this wouldn't be required. */
637 solib_create_inferior_hook (0);
641 return target_follow_fork (follow_child, detach_fork);
644 /* Tell the target to follow the fork we're stopped at. Returns true
645 if the inferior should be resumed; false, if the target for some
646 reason decided it's best not to resume. */
651 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
652 int should_resume = 1;
653 struct thread_info *tp;
655 /* Copy user stepping state to the new inferior thread. FIXME: the
656 followed fork child thread should have a copy of most of the
657 parent thread structure's run control related fields, not just these.
658 Initialized to avoid "may be used uninitialized" warnings from gcc. */
659 struct breakpoint *step_resume_breakpoint = NULL;
660 struct breakpoint *exception_resume_breakpoint = NULL;
661 CORE_ADDR step_range_start = 0;
662 CORE_ADDR step_range_end = 0;
663 struct frame_id step_frame_id = { 0 };
664 struct interp *command_interp = NULL;
669 struct target_waitstatus wait_status;
671 /* Get the last target status returned by target_wait(). */
672 get_last_target_status (&wait_ptid, &wait_status);
674 /* If not stopped at a fork event, then there's nothing else to
676 if (wait_status.kind != TARGET_WAITKIND_FORKED
677 && wait_status.kind != TARGET_WAITKIND_VFORKED)
680 /* Check if we switched over from WAIT_PTID, since the event was
682 if (!ptid_equal (wait_ptid, minus_one_ptid)
683 && !ptid_equal (inferior_ptid, wait_ptid))
685 /* We did. Switch back to WAIT_PTID thread, to tell the
686 target to follow it (in either direction). We'll
687 afterwards refuse to resume, and inform the user what
689 switch_to_thread (wait_ptid);
694 tp = inferior_thread ();
696 /* If there were any forks/vforks that were caught and are now to be
697 followed, then do so now. */
698 switch (tp->pending_follow.kind)
700 case TARGET_WAITKIND_FORKED:
701 case TARGET_WAITKIND_VFORKED:
703 ptid_t parent, child;
705 /* If the user did a next/step, etc, over a fork call,
706 preserve the stepping state in the fork child. */
707 if (follow_child && should_resume)
709 step_resume_breakpoint = clone_momentary_breakpoint
710 (tp->control.step_resume_breakpoint);
711 step_range_start = tp->control.step_range_start;
712 step_range_end = tp->control.step_range_end;
713 step_frame_id = tp->control.step_frame_id;
714 exception_resume_breakpoint
715 = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint);
716 command_interp = tp->control.command_interp;
718 /* For now, delete the parent's sr breakpoint, otherwise,
719 parent/child sr breakpoints are considered duplicates,
720 and the child version will not be installed. Remove
721 this when the breakpoints module becomes aware of
722 inferiors and address spaces. */
723 delete_step_resume_breakpoint (tp);
724 tp->control.step_range_start = 0;
725 tp->control.step_range_end = 0;
726 tp->control.step_frame_id = null_frame_id;
727 delete_exception_resume_breakpoint (tp);
728 tp->control.command_interp = NULL;
731 parent = inferior_ptid;
732 child = tp->pending_follow.value.related_pid;
734 /* Set up inferior(s) as specified by the caller, and tell the
735 target to do whatever is necessary to follow either parent
737 if (follow_fork_inferior (follow_child, detach_fork))
739 /* Target refused to follow, or there's some other reason
740 we shouldn't resume. */
745 /* This pending follow fork event is now handled, one way
746 or another. The previous selected thread may be gone
747 from the lists by now, but if it is still around, need
748 to clear the pending follow request. */
749 tp = find_thread_ptid (parent);
751 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
753 /* This makes sure we don't try to apply the "Switched
754 over from WAIT_PID" logic above. */
755 nullify_last_target_wait_ptid ();
757 /* If we followed the child, switch to it... */
760 switch_to_thread (child);
762 /* ... and preserve the stepping state, in case the
763 user was stepping over the fork call. */
766 tp = inferior_thread ();
767 tp->control.step_resume_breakpoint
768 = step_resume_breakpoint;
769 tp->control.step_range_start = step_range_start;
770 tp->control.step_range_end = step_range_end;
771 tp->control.step_frame_id = step_frame_id;
772 tp->control.exception_resume_breakpoint
773 = exception_resume_breakpoint;
774 tp->control.command_interp = command_interp;
778 /* If we get here, it was because we're trying to
779 resume from a fork catchpoint, but, the user
780 has switched threads away from the thread that
781 forked. In that case, the resume command
782 issued is most likely not applicable to the
783 child, so just warn, and refuse to resume. */
784 warning (_("Not resuming: switched threads "
785 "before following fork child.\n"));
788 /* Reset breakpoints in the child as appropriate. */
789 follow_inferior_reset_breakpoints ();
792 switch_to_thread (parent);
796 case TARGET_WAITKIND_SPURIOUS:
797 /* Nothing to follow. */
800 internal_error (__FILE__, __LINE__,
801 "Unexpected pending_follow.kind %d\n",
802 tp->pending_follow.kind);
806 return should_resume;
810 follow_inferior_reset_breakpoints (void)
812 struct thread_info *tp = inferior_thread ();
814 /* Was there a step_resume breakpoint? (There was if the user
815 did a "next" at the fork() call.) If so, explicitly reset its
816 thread number. Cloned step_resume breakpoints are disabled on
817 creation, so enable it here now that it is associated with the
820 step_resumes are a form of bp that are made to be per-thread.
821 Since we created the step_resume bp when the parent process
822 was being debugged, and now are switching to the child process,
823 from the breakpoint package's viewpoint, that's a switch of
824 "threads". We must update the bp's notion of which thread
825 it is for, or it'll be ignored when it triggers. */
827 if (tp->control.step_resume_breakpoint)
829 breakpoint_re_set_thread (tp->control.step_resume_breakpoint);
830 tp->control.step_resume_breakpoint->loc->enabled = 1;
833 /* Treat exception_resume breakpoints like step_resume breakpoints. */
834 if (tp->control.exception_resume_breakpoint)
836 breakpoint_re_set_thread (tp->control.exception_resume_breakpoint);
837 tp->control.exception_resume_breakpoint->loc->enabled = 1;
840 /* Reinsert all breakpoints in the child. The user may have set
841 breakpoints after catching the fork, in which case those
842 were never set in the child, but only in the parent. This makes
843 sure the inserted breakpoints match the breakpoint list. */
845 breakpoint_re_set ();
846 insert_breakpoints ();
849 /* The child has exited or execed: resume threads of the parent the
850 user wanted to be executing. */
853 proceed_after_vfork_done (struct thread_info *thread,
856 int pid = * (int *) arg;
858 if (ptid_get_pid (thread->ptid) == pid
859 && is_running (thread->ptid)
860 && !is_executing (thread->ptid)
861 && !thread->stop_requested
862 && thread->suspend.stop_signal == GDB_SIGNAL_0)
865 fprintf_unfiltered (gdb_stdlog,
866 "infrun: resuming vfork parent thread %s\n",
867 target_pid_to_str (thread->ptid));
869 switch_to_thread (thread->ptid);
870 clear_proceed_status (0);
871 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
877 /* Called whenever we notice an exec or exit event, to handle
878 detaching or resuming a vfork parent. */
881 handle_vfork_child_exec_or_exit (int exec)
883 struct inferior *inf = current_inferior ();
885 if (inf->vfork_parent)
887 int resume_parent = -1;
889 /* This exec or exit marks the end of the shared memory region
890 between the parent and the child. If the user wanted to
891 detach from the parent, now is the time. */
893 if (inf->vfork_parent->pending_detach)
895 struct thread_info *tp;
896 struct cleanup *old_chain;
897 struct program_space *pspace;
898 struct address_space *aspace;
900 /* follow-fork child, detach-on-fork on. */
902 inf->vfork_parent->pending_detach = 0;
906 /* If we're handling a child exit, then inferior_ptid
907 points at the inferior's pid, not to a thread. */
908 old_chain = save_inferior_ptid ();
909 save_current_program_space ();
910 save_current_inferior ();
913 old_chain = save_current_space_and_thread ();
915 /* We're letting loose of the parent. */
916 tp = any_live_thread_of_process (inf->vfork_parent->pid);
917 switch_to_thread (tp->ptid);
919 /* We're about to detach from the parent, which implicitly
920 removes breakpoints from its address space. There's a
921 catch here: we want to reuse the spaces for the child,
922 but, parent/child are still sharing the pspace at this
923 point, although the exec in reality makes the kernel give
924 the child a fresh set of new pages. The problem here is
925 that the breakpoints module being unaware of this, would
926 likely chose the child process to write to the parent
927 address space. Swapping the child temporarily away from
928 the spaces has the desired effect. Yes, this is "sort
931 pspace = inf->pspace;
932 aspace = inf->aspace;
936 if (debug_infrun || info_verbose)
938 target_terminal_ours_for_output ();
942 fprintf_filtered (gdb_stdlog,
943 _("Detaching vfork parent process "
944 "%d after child exec.\n"),
945 inf->vfork_parent->pid);
949 fprintf_filtered (gdb_stdlog,
950 _("Detaching vfork parent process "
951 "%d after child exit.\n"),
952 inf->vfork_parent->pid);
956 target_detach (NULL, 0);
959 inf->pspace = pspace;
960 inf->aspace = aspace;
962 do_cleanups (old_chain);
966 /* We're staying attached to the parent, so, really give the
967 child a new address space. */
968 inf->pspace = add_program_space (maybe_new_address_space ());
969 inf->aspace = inf->pspace->aspace;
971 set_current_program_space (inf->pspace);
973 resume_parent = inf->vfork_parent->pid;
975 /* Break the bonds. */
976 inf->vfork_parent->vfork_child = NULL;
980 struct cleanup *old_chain;
981 struct program_space *pspace;
983 /* If this is a vfork child exiting, then the pspace and
984 aspaces were shared with the parent. Since we're
985 reporting the process exit, we'll be mourning all that is
986 found in the address space, and switching to null_ptid,
987 preparing to start a new inferior. But, since we don't
988 want to clobber the parent's address/program spaces, we
989 go ahead and create a new one for this exiting
992 /* Switch to null_ptid, so that clone_program_space doesn't want
993 to read the selected frame of a dead process. */
994 old_chain = save_inferior_ptid ();
995 inferior_ptid = null_ptid;
997 /* This inferior is dead, so avoid giving the breakpoints
998 module the option to write through to it (cloning a
999 program space resets breakpoints). */
1002 pspace = add_program_space (maybe_new_address_space ());
1003 set_current_program_space (pspace);
1005 inf->symfile_flags = SYMFILE_NO_READ;
1006 clone_program_space (pspace, inf->vfork_parent->pspace);
1007 inf->pspace = pspace;
1008 inf->aspace = pspace->aspace;
1010 /* Put back inferior_ptid. We'll continue mourning this
1012 do_cleanups (old_chain);
1014 resume_parent = inf->vfork_parent->pid;
1015 /* Break the bonds. */
1016 inf->vfork_parent->vfork_child = NULL;
1019 inf->vfork_parent = NULL;
1021 gdb_assert (current_program_space == inf->pspace);
1023 if (non_stop && resume_parent != -1)
1025 /* If the user wanted the parent to be running, let it go
1027 struct cleanup *old_chain = make_cleanup_restore_current_thread ();
1030 fprintf_unfiltered (gdb_stdlog,
1031 "infrun: resuming vfork parent process %d\n",
1034 iterate_over_threads (proceed_after_vfork_done, &resume_parent);
1036 do_cleanups (old_chain);
1041 /* Enum strings for "set|show follow-exec-mode". */
1043 static const char follow_exec_mode_new[] = "new";
1044 static const char follow_exec_mode_same[] = "same";
1045 static const char *const follow_exec_mode_names[] =
1047 follow_exec_mode_new,
1048 follow_exec_mode_same,
1052 static const char *follow_exec_mode_string = follow_exec_mode_same;
1054 show_follow_exec_mode_string (struct ui_file *file, int from_tty,
1055 struct cmd_list_element *c, const char *value)
1057 fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value);
1060 /* EXECD_PATHNAME is assumed to be non-NULL. */
1063 follow_exec (ptid_t pid, char *execd_pathname)
1065 struct thread_info *th = inferior_thread ();
1066 struct inferior *inf = current_inferior ();
1068 /* This is an exec event that we actually wish to pay attention to.
1069 Refresh our symbol table to the newly exec'd program, remove any
1070 momentary bp's, etc.
1072 If there are breakpoints, they aren't really inserted now,
1073 since the exec() transformed our inferior into a fresh set
1076 We want to preserve symbolic breakpoints on the list, since
1077 we have hopes that they can be reset after the new a.out's
1078 symbol table is read.
1080 However, any "raw" breakpoints must be removed from the list
1081 (e.g., the solib bp's), since their address is probably invalid
1084 And, we DON'T want to call delete_breakpoints() here, since
1085 that may write the bp's "shadow contents" (the instruction
1086 value that was overwritten witha TRAP instruction). Since
1087 we now have a new a.out, those shadow contents aren't valid. */
1089 mark_breakpoints_out ();
1091 update_breakpoints_after_exec ();
1093 /* If there was one, it's gone now. We cannot truly step-to-next
1094 statement through an exec(). */
1095 th->control.step_resume_breakpoint = NULL;
1096 th->control.exception_resume_breakpoint = NULL;
1097 th->control.single_step_breakpoints = NULL;
1098 th->control.step_range_start = 0;
1099 th->control.step_range_end = 0;
1101 /* The target reports the exec event to the main thread, even if
1102 some other thread does the exec, and even if the main thread was
1103 already stopped --- if debugging in non-stop mode, it's possible
1104 the user had the main thread held stopped in the previous image
1105 --- release it now. This is the same behavior as step-over-exec
1106 with scheduler-locking on in all-stop mode. */
1107 th->stop_requested = 0;
1109 /* What is this a.out's name? */
1110 printf_unfiltered (_("%s is executing new program: %s\n"),
1111 target_pid_to_str (inferior_ptid),
1114 /* We've followed the inferior through an exec. Therefore, the
1115 inferior has essentially been killed & reborn. */
1117 gdb_flush (gdb_stdout);
1119 breakpoint_init_inferior (inf_execd);
1121 if (gdb_sysroot && *gdb_sysroot)
1123 char *name = alloca (strlen (gdb_sysroot)
1124 + strlen (execd_pathname)
1127 strcpy (name, gdb_sysroot);
1128 strcat (name, execd_pathname);
1129 execd_pathname = name;
1132 /* Reset the shared library package. This ensures that we get a
1133 shlib event when the child reaches "_start", at which point the
1134 dld will have had a chance to initialize the child. */
1135 /* Also, loading a symbol file below may trigger symbol lookups, and
1136 we don't want those to be satisfied by the libraries of the
1137 previous incarnation of this process. */
1138 no_shared_libraries (NULL, 0);
1140 if (follow_exec_mode_string == follow_exec_mode_new)
1142 struct program_space *pspace;
1144 /* The user wants to keep the old inferior and program spaces
1145 around. Create a new fresh one, and switch to it. */
1147 inf = add_inferior (current_inferior ()->pid);
1148 pspace = add_program_space (maybe_new_address_space ());
1149 inf->pspace = pspace;
1150 inf->aspace = pspace->aspace;
1152 exit_inferior_num_silent (current_inferior ()->num);
1154 set_current_inferior (inf);
1155 set_current_program_space (pspace);
1159 /* The old description may no longer be fit for the new image.
1160 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1161 old description; we'll read a new one below. No need to do
1162 this on "follow-exec-mode new", as the old inferior stays
1163 around (its description is later cleared/refetched on
1165 target_clear_description ();
1168 gdb_assert (current_program_space == inf->pspace);
1170 /* That a.out is now the one to use. */
1171 exec_file_attach (execd_pathname, 0);
1173 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
1174 (Position Independent Executable) main symbol file will get applied by
1175 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
1176 the breakpoints with the zero displacement. */
1178 symbol_file_add (execd_pathname,
1180 | SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET),
1183 if ((inf->symfile_flags & SYMFILE_NO_READ) == 0)
1184 set_initial_language ();
1186 /* If the target can specify a description, read it. Must do this
1187 after flipping to the new executable (because the target supplied
1188 description must be compatible with the executable's
1189 architecture, and the old executable may e.g., be 32-bit, while
1190 the new one 64-bit), and before anything involving memory or
1192 target_find_description ();
1194 solib_create_inferior_hook (0);
1196 jit_inferior_created_hook ();
1198 breakpoint_re_set ();
1200 /* Reinsert all breakpoints. (Those which were symbolic have
1201 been reset to the proper address in the new a.out, thanks
1202 to symbol_file_command...). */
1203 insert_breakpoints ();
1205 /* The next resume of this inferior should bring it to the shlib
1206 startup breakpoints. (If the user had also set bp's on
1207 "main" from the old (parent) process, then they'll auto-
1208 matically get reset there in the new process.). */
1211 /* Info about an instruction that is being stepped over. */
1213 struct step_over_info
1215 /* If we're stepping past a breakpoint, this is the address space
1216 and address of the instruction the breakpoint is set at. We'll
1217 skip inserting all breakpoints here. Valid iff ASPACE is
1219 struct address_space *aspace;
1222 /* The instruction being stepped over triggers a nonsteppable
1223 watchpoint. If true, we'll skip inserting watchpoints. */
1224 int nonsteppable_watchpoint_p;
1227 /* The step-over info of the location that is being stepped over.
1229 Note that with async/breakpoint always-inserted mode, a user might
1230 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1231 being stepped over. As setting a new breakpoint inserts all
1232 breakpoints, we need to make sure the breakpoint being stepped over
1233 isn't inserted then. We do that by only clearing the step-over
1234 info when the step-over is actually finished (or aborted).
1236 Presently GDB can only step over one breakpoint at any given time.
1237 Given threads that can't run code in the same address space as the
1238 breakpoint's can't really miss the breakpoint, GDB could be taught
1239 to step-over at most one breakpoint per address space (so this info
1240 could move to the address space object if/when GDB is extended).
1241 The set of breakpoints being stepped over will normally be much
1242 smaller than the set of all breakpoints, so a flag in the
1243 breakpoint location structure would be wasteful. A separate list
1244 also saves complexity and run-time, as otherwise we'd have to go
1245 through all breakpoint locations clearing their flag whenever we
1246 start a new sequence. Similar considerations weigh against storing
1247 this info in the thread object. Plus, not all step overs actually
1248 have breakpoint locations -- e.g., stepping past a single-step
1249 breakpoint, or stepping to complete a non-continuable
1251 static struct step_over_info step_over_info;
1253 /* Record the address of the breakpoint/instruction we're currently
1257 set_step_over_info (struct address_space *aspace, CORE_ADDR address,
1258 int nonsteppable_watchpoint_p)
1260 step_over_info.aspace = aspace;
1261 step_over_info.address = address;
1262 step_over_info.nonsteppable_watchpoint_p = nonsteppable_watchpoint_p;
1265 /* Called when we're not longer stepping over a breakpoint / an
1266 instruction, so all breakpoints are free to be (re)inserted. */
1269 clear_step_over_info (void)
1271 step_over_info.aspace = NULL;
1272 step_over_info.address = 0;
1273 step_over_info.nonsteppable_watchpoint_p = 0;
1279 stepping_past_instruction_at (struct address_space *aspace,
1282 return (step_over_info.aspace != NULL
1283 && breakpoint_address_match (aspace, address,
1284 step_over_info.aspace,
1285 step_over_info.address));
1291 stepping_past_nonsteppable_watchpoint (void)
1293 return step_over_info.nonsteppable_watchpoint_p;
1296 /* Returns true if step-over info is valid. */
1299 step_over_info_valid_p (void)
1301 return (step_over_info.aspace != NULL
1302 || stepping_past_nonsteppable_watchpoint ());
1306 /* Displaced stepping. */
1308 /* In non-stop debugging mode, we must take special care to manage
1309 breakpoints properly; in particular, the traditional strategy for
1310 stepping a thread past a breakpoint it has hit is unsuitable.
1311 'Displaced stepping' is a tactic for stepping one thread past a
1312 breakpoint it has hit while ensuring that other threads running
1313 concurrently will hit the breakpoint as they should.
1315 The traditional way to step a thread T off a breakpoint in a
1316 multi-threaded program in all-stop mode is as follows:
1318 a0) Initially, all threads are stopped, and breakpoints are not
1320 a1) We single-step T, leaving breakpoints uninserted.
1321 a2) We insert breakpoints, and resume all threads.
1323 In non-stop debugging, however, this strategy is unsuitable: we
1324 don't want to have to stop all threads in the system in order to
1325 continue or step T past a breakpoint. Instead, we use displaced
1328 n0) Initially, T is stopped, other threads are running, and
1329 breakpoints are inserted.
1330 n1) We copy the instruction "under" the breakpoint to a separate
1331 location, outside the main code stream, making any adjustments
1332 to the instruction, register, and memory state as directed by
1334 n2) We single-step T over the instruction at its new location.
1335 n3) We adjust the resulting register and memory state as directed
1336 by T's architecture. This includes resetting T's PC to point
1337 back into the main instruction stream.
1340 This approach depends on the following gdbarch methods:
1342 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1343 indicate where to copy the instruction, and how much space must
1344 be reserved there. We use these in step n1.
1346 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1347 address, and makes any necessary adjustments to the instruction,
1348 register contents, and memory. We use this in step n1.
1350 - gdbarch_displaced_step_fixup adjusts registers and memory after
1351 we have successfuly single-stepped the instruction, to yield the
1352 same effect the instruction would have had if we had executed it
1353 at its original address. We use this in step n3.
1355 - gdbarch_displaced_step_free_closure provides cleanup.
1357 The gdbarch_displaced_step_copy_insn and
1358 gdbarch_displaced_step_fixup functions must be written so that
1359 copying an instruction with gdbarch_displaced_step_copy_insn,
1360 single-stepping across the copied instruction, and then applying
1361 gdbarch_displaced_insn_fixup should have the same effects on the
1362 thread's memory and registers as stepping the instruction in place
1363 would have. Exactly which responsibilities fall to the copy and
1364 which fall to the fixup is up to the author of those functions.
1366 See the comments in gdbarch.sh for details.
1368 Note that displaced stepping and software single-step cannot
1369 currently be used in combination, although with some care I think
1370 they could be made to. Software single-step works by placing
1371 breakpoints on all possible subsequent instructions; if the
1372 displaced instruction is a PC-relative jump, those breakpoints
1373 could fall in very strange places --- on pages that aren't
1374 executable, or at addresses that are not proper instruction
1375 boundaries. (We do generally let other threads run while we wait
1376 to hit the software single-step breakpoint, and they might
1377 encounter such a corrupted instruction.) One way to work around
1378 this would be to have gdbarch_displaced_step_copy_insn fully
1379 simulate the effect of PC-relative instructions (and return NULL)
1380 on architectures that use software single-stepping.
1382 In non-stop mode, we can have independent and simultaneous step
1383 requests, so more than one thread may need to simultaneously step
1384 over a breakpoint. The current implementation assumes there is
1385 only one scratch space per process. In this case, we have to
1386 serialize access to the scratch space. If thread A wants to step
1387 over a breakpoint, but we are currently waiting for some other
1388 thread to complete a displaced step, we leave thread A stopped and
1389 place it in the displaced_step_request_queue. Whenever a displaced
1390 step finishes, we pick the next thread in the queue and start a new
1391 displaced step operation on it. See displaced_step_prepare and
1392 displaced_step_fixup for details. */
1394 struct displaced_step_request
1397 struct displaced_step_request *next;
1400 /* Per-inferior displaced stepping state. */
1401 struct displaced_step_inferior_state
1403 /* Pointer to next in linked list. */
1404 struct displaced_step_inferior_state *next;
1406 /* The process this displaced step state refers to. */
1409 /* A queue of pending displaced stepping requests. One entry per
1410 thread that needs to do a displaced step. */
1411 struct displaced_step_request *step_request_queue;
1413 /* If this is not null_ptid, this is the thread carrying out a
1414 displaced single-step in process PID. This thread's state will
1415 require fixing up once it has completed its step. */
1418 /* The architecture the thread had when we stepped it. */
1419 struct gdbarch *step_gdbarch;
1421 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1422 for post-step cleanup. */
1423 struct displaced_step_closure *step_closure;
1425 /* The address of the original instruction, and the copy we
1427 CORE_ADDR step_original, step_copy;
1429 /* Saved contents of copy area. */
1430 gdb_byte *step_saved_copy;
1433 /* The list of states of processes involved in displaced stepping
1435 static struct displaced_step_inferior_state *displaced_step_inferior_states;
1437 /* Get the displaced stepping state of process PID. */
1439 static struct displaced_step_inferior_state *
1440 get_displaced_stepping_state (int pid)
1442 struct displaced_step_inferior_state *state;
1444 for (state = displaced_step_inferior_states;
1446 state = state->next)
1447 if (state->pid == pid)
1453 /* Add a new displaced stepping state for process PID to the displaced
1454 stepping state list, or return a pointer to an already existing
1455 entry, if it already exists. Never returns NULL. */
1457 static struct displaced_step_inferior_state *
1458 add_displaced_stepping_state (int pid)
1460 struct displaced_step_inferior_state *state;
1462 for (state = displaced_step_inferior_states;
1464 state = state->next)
1465 if (state->pid == pid)
1468 state = xcalloc (1, sizeof (*state));
1470 state->next = displaced_step_inferior_states;
1471 displaced_step_inferior_states = state;
1476 /* If inferior is in displaced stepping, and ADDR equals to starting address
1477 of copy area, return corresponding displaced_step_closure. Otherwise,
1480 struct displaced_step_closure*
1481 get_displaced_step_closure_by_addr (CORE_ADDR addr)
1483 struct displaced_step_inferior_state *displaced
1484 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1486 /* If checking the mode of displaced instruction in copy area. */
1487 if (displaced && !ptid_equal (displaced->step_ptid, null_ptid)
1488 && (displaced->step_copy == addr))
1489 return displaced->step_closure;
1494 /* Remove the displaced stepping state of process PID. */
1497 remove_displaced_stepping_state (int pid)
1499 struct displaced_step_inferior_state *it, **prev_next_p;
1501 gdb_assert (pid != 0);
1503 it = displaced_step_inferior_states;
1504 prev_next_p = &displaced_step_inferior_states;
1509 *prev_next_p = it->next;
1514 prev_next_p = &it->next;
1520 infrun_inferior_exit (struct inferior *inf)
1522 remove_displaced_stepping_state (inf->pid);
1525 /* If ON, and the architecture supports it, GDB will use displaced
1526 stepping to step over breakpoints. If OFF, or if the architecture
1527 doesn't support it, GDB will instead use the traditional
1528 hold-and-step approach. If AUTO (which is the default), GDB will
1529 decide which technique to use to step over breakpoints depending on
1530 which of all-stop or non-stop mode is active --- displaced stepping
1531 in non-stop mode; hold-and-step in all-stop mode. */
1533 static enum auto_boolean can_use_displaced_stepping = AUTO_BOOLEAN_AUTO;
1536 show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
1537 struct cmd_list_element *c,
1540 if (can_use_displaced_stepping == AUTO_BOOLEAN_AUTO)
1541 fprintf_filtered (file,
1542 _("Debugger's willingness to use displaced stepping "
1543 "to step over breakpoints is %s (currently %s).\n"),
1544 value, non_stop ? "on" : "off");
1546 fprintf_filtered (file,
1547 _("Debugger's willingness to use displaced stepping "
1548 "to step over breakpoints is %s.\n"), value);
1551 /* Return non-zero if displaced stepping can/should be used to step
1552 over breakpoints. */
1555 use_displaced_stepping (struct gdbarch *gdbarch)
1557 return (((can_use_displaced_stepping == AUTO_BOOLEAN_AUTO && non_stop)
1558 || can_use_displaced_stepping == AUTO_BOOLEAN_TRUE)
1559 && gdbarch_displaced_step_copy_insn_p (gdbarch)
1560 && find_record_target () == NULL);
1563 /* Clean out any stray displaced stepping state. */
1565 displaced_step_clear (struct displaced_step_inferior_state *displaced)
1567 /* Indicate that there is no cleanup pending. */
1568 displaced->step_ptid = null_ptid;
1570 if (displaced->step_closure)
1572 gdbarch_displaced_step_free_closure (displaced->step_gdbarch,
1573 displaced->step_closure);
1574 displaced->step_closure = NULL;
1579 displaced_step_clear_cleanup (void *arg)
1581 struct displaced_step_inferior_state *state = arg;
1583 displaced_step_clear (state);
1586 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1588 displaced_step_dump_bytes (struct ui_file *file,
1589 const gdb_byte *buf,
1594 for (i = 0; i < len; i++)
1595 fprintf_unfiltered (file, "%02x ", buf[i]);
1596 fputs_unfiltered ("\n", file);
1599 /* Prepare to single-step, using displaced stepping.
1601 Note that we cannot use displaced stepping when we have a signal to
1602 deliver. If we have a signal to deliver and an instruction to step
1603 over, then after the step, there will be no indication from the
1604 target whether the thread entered a signal handler or ignored the
1605 signal and stepped over the instruction successfully --- both cases
1606 result in a simple SIGTRAP. In the first case we mustn't do a
1607 fixup, and in the second case we must --- but we can't tell which.
1608 Comments in the code for 'random signals' in handle_inferior_event
1609 explain how we handle this case instead.
1611 Returns 1 if preparing was successful -- this thread is going to be
1612 stepped now; or 0 if displaced stepping this thread got queued. */
1614 displaced_step_prepare (ptid_t ptid)
1616 struct cleanup *old_cleanups, *ignore_cleanups;
1617 struct thread_info *tp = find_thread_ptid (ptid);
1618 struct regcache *regcache = get_thread_regcache (ptid);
1619 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1620 CORE_ADDR original, copy;
1622 struct displaced_step_closure *closure;
1623 struct displaced_step_inferior_state *displaced;
1626 /* We should never reach this function if the architecture does not
1627 support displaced stepping. */
1628 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
1630 /* Disable range stepping while executing in the scratch pad. We
1631 want a single-step even if executing the displaced instruction in
1632 the scratch buffer lands within the stepping range (e.g., a
1634 tp->control.may_range_step = 0;
1636 /* We have to displaced step one thread at a time, as we only have
1637 access to a single scratch space per inferior. */
1639 displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
1641 if (!ptid_equal (displaced->step_ptid, null_ptid))
1643 /* Already waiting for a displaced step to finish. Defer this
1644 request and place in queue. */
1645 struct displaced_step_request *req, *new_req;
1647 if (debug_displaced)
1648 fprintf_unfiltered (gdb_stdlog,
1649 "displaced: defering step of %s\n",
1650 target_pid_to_str (ptid));
1652 new_req = xmalloc (sizeof (*new_req));
1653 new_req->ptid = ptid;
1654 new_req->next = NULL;
1656 if (displaced->step_request_queue)
1658 for (req = displaced->step_request_queue;
1662 req->next = new_req;
1665 displaced->step_request_queue = new_req;
1671 if (debug_displaced)
1672 fprintf_unfiltered (gdb_stdlog,
1673 "displaced: stepping %s now\n",
1674 target_pid_to_str (ptid));
1677 displaced_step_clear (displaced);
1679 old_cleanups = save_inferior_ptid ();
1680 inferior_ptid = ptid;
1682 original = regcache_read_pc (regcache);
1684 copy = gdbarch_displaced_step_location (gdbarch);
1685 len = gdbarch_max_insn_length (gdbarch);
1687 /* Save the original contents of the copy area. */
1688 displaced->step_saved_copy = xmalloc (len);
1689 ignore_cleanups = make_cleanup (free_current_contents,
1690 &displaced->step_saved_copy);
1691 status = target_read_memory (copy, displaced->step_saved_copy, len);
1693 throw_error (MEMORY_ERROR,
1694 _("Error accessing memory address %s (%s) for "
1695 "displaced-stepping scratch space."),
1696 paddress (gdbarch, copy), safe_strerror (status));
1697 if (debug_displaced)
1699 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
1700 paddress (gdbarch, copy));
1701 displaced_step_dump_bytes (gdb_stdlog,
1702 displaced->step_saved_copy,
1706 closure = gdbarch_displaced_step_copy_insn (gdbarch,
1707 original, copy, regcache);
1709 /* We don't support the fully-simulated case at present. */
1710 gdb_assert (closure);
1712 /* Save the information we need to fix things up if the step
1714 displaced->step_ptid = ptid;
1715 displaced->step_gdbarch = gdbarch;
1716 displaced->step_closure = closure;
1717 displaced->step_original = original;
1718 displaced->step_copy = copy;
1720 make_cleanup (displaced_step_clear_cleanup, displaced);
1722 /* Resume execution at the copy. */
1723 regcache_write_pc (regcache, copy);
1725 discard_cleanups (ignore_cleanups);
1727 do_cleanups (old_cleanups);
1729 if (debug_displaced)
1730 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
1731 paddress (gdbarch, copy));
1737 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr,
1738 const gdb_byte *myaddr, int len)
1740 struct cleanup *ptid_cleanup = save_inferior_ptid ();
1742 inferior_ptid = ptid;
1743 write_memory (memaddr, myaddr, len);
1744 do_cleanups (ptid_cleanup);
1747 /* Restore the contents of the copy area for thread PTID. */
1750 displaced_step_restore (struct displaced_step_inferior_state *displaced,
1753 ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
1755 write_memory_ptid (ptid, displaced->step_copy,
1756 displaced->step_saved_copy, len);
1757 if (debug_displaced)
1758 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s %s\n",
1759 target_pid_to_str (ptid),
1760 paddress (displaced->step_gdbarch,
1761 displaced->step_copy));
1765 displaced_step_fixup (ptid_t event_ptid, enum gdb_signal signal)
1767 struct cleanup *old_cleanups;
1768 struct displaced_step_inferior_state *displaced
1769 = get_displaced_stepping_state (ptid_get_pid (event_ptid));
1771 /* Was any thread of this process doing a displaced step? */
1772 if (displaced == NULL)
1775 /* Was this event for the pid we displaced? */
1776 if (ptid_equal (displaced->step_ptid, null_ptid)
1777 || ! ptid_equal (displaced->step_ptid, event_ptid))
1780 old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
1782 displaced_step_restore (displaced, displaced->step_ptid);
1784 /* Did the instruction complete successfully? */
1785 if (signal == GDB_SIGNAL_TRAP)
1787 /* Fix up the resulting state. */
1788 gdbarch_displaced_step_fixup (displaced->step_gdbarch,
1789 displaced->step_closure,
1790 displaced->step_original,
1791 displaced->step_copy,
1792 get_thread_regcache (displaced->step_ptid));
1796 /* Since the instruction didn't complete, all we can do is
1798 struct regcache *regcache = get_thread_regcache (event_ptid);
1799 CORE_ADDR pc = regcache_read_pc (regcache);
1801 pc = displaced->step_original + (pc - displaced->step_copy);
1802 regcache_write_pc (regcache, pc);
1805 do_cleanups (old_cleanups);
1807 displaced->step_ptid = null_ptid;
1809 /* Are there any pending displaced stepping requests? If so, run
1810 one now. Leave the state object around, since we're likely to
1811 need it again soon. */
1812 while (displaced->step_request_queue)
1814 struct displaced_step_request *head;
1816 struct regcache *regcache;
1817 struct gdbarch *gdbarch;
1818 CORE_ADDR actual_pc;
1819 struct address_space *aspace;
1821 head = displaced->step_request_queue;
1823 displaced->step_request_queue = head->next;
1826 context_switch (ptid);
1828 regcache = get_thread_regcache (ptid);
1829 actual_pc = regcache_read_pc (regcache);
1830 aspace = get_regcache_aspace (regcache);
1832 if (breakpoint_here_p (aspace, actual_pc))
1834 if (debug_displaced)
1835 fprintf_unfiltered (gdb_stdlog,
1836 "displaced: stepping queued %s now\n",
1837 target_pid_to_str (ptid));
1839 displaced_step_prepare (ptid);
1841 gdbarch = get_regcache_arch (regcache);
1843 if (debug_displaced)
1845 CORE_ADDR actual_pc = regcache_read_pc (regcache);
1848 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1849 paddress (gdbarch, actual_pc));
1850 read_memory (actual_pc, buf, sizeof (buf));
1851 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1854 if (gdbarch_displaced_step_hw_singlestep (gdbarch,
1855 displaced->step_closure))
1856 target_resume (ptid, 1, GDB_SIGNAL_0);
1858 target_resume (ptid, 0, GDB_SIGNAL_0);
1860 /* Done, we're stepping a thread. */
1866 struct thread_info *tp = inferior_thread ();
1868 /* The breakpoint we were sitting under has since been
1870 tp->control.trap_expected = 0;
1872 /* Go back to what we were trying to do. */
1873 step = currently_stepping (tp);
1875 if (debug_displaced)
1876 fprintf_unfiltered (gdb_stdlog,
1877 "displaced: breakpoint is gone: %s, step(%d)\n",
1878 target_pid_to_str (tp->ptid), step);
1880 target_resume (ptid, step, GDB_SIGNAL_0);
1881 tp->suspend.stop_signal = GDB_SIGNAL_0;
1883 /* This request was discarded. See if there's any other
1884 thread waiting for its turn. */
1889 /* Update global variables holding ptids to hold NEW_PTID if they were
1890 holding OLD_PTID. */
1892 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
1894 struct displaced_step_request *it;
1895 struct displaced_step_inferior_state *displaced;
1897 if (ptid_equal (inferior_ptid, old_ptid))
1898 inferior_ptid = new_ptid;
1900 for (displaced = displaced_step_inferior_states;
1902 displaced = displaced->next)
1904 if (ptid_equal (displaced->step_ptid, old_ptid))
1905 displaced->step_ptid = new_ptid;
1907 for (it = displaced->step_request_queue; it; it = it->next)
1908 if (ptid_equal (it->ptid, old_ptid))
1909 it->ptid = new_ptid;
1916 /* Things to clean up if we QUIT out of resume (). */
1918 resume_cleanups (void *ignore)
1920 if (!ptid_equal (inferior_ptid, null_ptid))
1921 delete_single_step_breakpoints (inferior_thread ());
1926 static const char schedlock_off[] = "off";
1927 static const char schedlock_on[] = "on";
1928 static const char schedlock_step[] = "step";
1929 static const char *const scheduler_enums[] = {
1935 static const char *scheduler_mode = schedlock_off;
1937 show_scheduler_mode (struct ui_file *file, int from_tty,
1938 struct cmd_list_element *c, const char *value)
1940 fprintf_filtered (file,
1941 _("Mode for locking scheduler "
1942 "during execution is \"%s\".\n"),
1947 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
1949 if (!target_can_lock_scheduler)
1951 scheduler_mode = schedlock_off;
1952 error (_("Target '%s' cannot support this command."), target_shortname);
1956 /* True if execution commands resume all threads of all processes by
1957 default; otherwise, resume only threads of the current inferior
1959 int sched_multi = 0;
1961 /* Try to setup for software single stepping over the specified location.
1962 Return 1 if target_resume() should use hardware single step.
1964 GDBARCH the current gdbarch.
1965 PC the location to step over. */
1968 maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
1972 if (execution_direction == EXEC_FORWARD
1973 && gdbarch_software_single_step_p (gdbarch)
1974 && gdbarch_software_single_step (gdbarch, get_current_frame ()))
1982 user_visible_resume_ptid (int step)
1984 /* By default, resume all threads of all processes. */
1985 ptid_t resume_ptid = RESUME_ALL;
1987 /* Maybe resume only all threads of the current process. */
1988 if (!sched_multi && target_supports_multi_process ())
1990 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
1993 /* Maybe resume a single thread after all. */
1996 /* With non-stop mode on, threads are always handled
1998 resume_ptid = inferior_ptid;
2000 else if ((scheduler_mode == schedlock_on)
2001 || (scheduler_mode == schedlock_step && step))
2003 /* User-settable 'scheduler' mode requires solo thread resume. */
2004 resume_ptid = inferior_ptid;
2007 /* We may actually resume fewer threads at first, e.g., if a thread
2008 is stopped at a breakpoint that needs stepping-off, but that
2009 should not be visible to the user/frontend, and neither should
2010 the frontend/user be allowed to proceed any of the threads that
2011 happen to be stopped for internal run control handling, if a
2012 previous command wanted them resumed. */
2016 /* Resume the inferior, but allow a QUIT. This is useful if the user
2017 wants to interrupt some lengthy single-stepping operation
2018 (for child processes, the SIGINT goes to the inferior, and so
2019 we get a SIGINT random_signal, but for remote debugging and perhaps
2020 other targets, that's not true).
2022 STEP nonzero if we should step (zero to continue instead).
2023 SIG is the signal to give the inferior (zero for none). */
2025 resume (int step, enum gdb_signal sig)
2027 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
2028 struct regcache *regcache = get_current_regcache ();
2029 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2030 struct thread_info *tp = inferior_thread ();
2031 CORE_ADDR pc = regcache_read_pc (regcache);
2032 struct address_space *aspace = get_regcache_aspace (regcache);
2034 /* From here on, this represents the caller's step vs continue
2035 request, while STEP represents what we'll actually request the
2036 target to do. STEP can decay from a step to a continue, if e.g.,
2037 we need to implement single-stepping with breakpoints (software
2038 single-step). When deciding whether "set scheduler-locking step"
2039 applies, it's the callers intention that counts. */
2040 const int entry_step = step;
2042 tp->stepped_breakpoint = 0;
2046 if (current_inferior ()->waiting_for_vfork_done)
2048 /* Don't try to single-step a vfork parent that is waiting for
2049 the child to get out of the shared memory region (by exec'ing
2050 or exiting). This is particularly important on software
2051 single-step archs, as the child process would trip on the
2052 software single step breakpoint inserted for the parent
2053 process. Since the parent will not actually execute any
2054 instruction until the child is out of the shared region (such
2055 are vfork's semantics), it is safe to simply continue it.
2056 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2057 the parent, and tell it to `keep_going', which automatically
2058 re-sets it stepping. */
2060 fprintf_unfiltered (gdb_stdlog,
2061 "infrun: resume : clear step\n");
2066 fprintf_unfiltered (gdb_stdlog,
2067 "infrun: resume (step=%d, signal=%s), "
2068 "trap_expected=%d, current thread [%s] at %s\n",
2069 step, gdb_signal_to_symbol_string (sig),
2070 tp->control.trap_expected,
2071 target_pid_to_str (inferior_ptid),
2072 paddress (gdbarch, pc));
2074 /* Normally, by the time we reach `resume', the breakpoints are either
2075 removed or inserted, as appropriate. The exception is if we're sitting
2076 at a permanent breakpoint; we need to step over it, but permanent
2077 breakpoints can't be removed. So we have to test for it here. */
2078 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
2080 if (sig != GDB_SIGNAL_0)
2082 /* We have a signal to pass to the inferior. The resume
2083 may, or may not take us to the signal handler. If this
2084 is a step, we'll need to stop in the signal handler, if
2085 there's one, (if the target supports stepping into
2086 handlers), or in the next mainline instruction, if
2087 there's no handler. If this is a continue, we need to be
2088 sure to run the handler with all breakpoints inserted.
2089 In all cases, set a breakpoint at the current address
2090 (where the handler returns to), and once that breakpoint
2091 is hit, resume skipping the permanent breakpoint. If
2092 that breakpoint isn't hit, then we've stepped into the
2093 signal handler (or hit some other event). We'll delete
2094 the step-resume breakpoint then. */
2097 fprintf_unfiltered (gdb_stdlog,
2098 "infrun: resume: skipping permanent breakpoint, "
2099 "deliver signal first\n");
2101 clear_step_over_info ();
2102 tp->control.trap_expected = 0;
2104 if (tp->control.step_resume_breakpoint == NULL)
2106 /* Set a "high-priority" step-resume, as we don't want
2107 user breakpoints at PC to trigger (again) when this
2109 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2110 gdb_assert (tp->control.step_resume_breakpoint->loc->permanent);
2112 tp->step_after_step_resume_breakpoint = step;
2115 insert_breakpoints ();
2119 /* There's no signal to pass, we can go ahead and skip the
2120 permanent breakpoint manually. */
2122 fprintf_unfiltered (gdb_stdlog,
2123 "infrun: resume: skipping permanent breakpoint\n");
2124 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
2125 /* Update pc to reflect the new address from which we will
2126 execute instructions. */
2127 pc = regcache_read_pc (regcache);
2131 /* We've already advanced the PC, so the stepping part
2132 is done. Now we need to arrange for a trap to be
2133 reported to handle_inferior_event. Set a breakpoint
2134 at the current PC, and run to it. Don't update
2135 prev_pc, because if we end in
2136 switch_back_to_stepping, we want the "expected thread
2137 advanced also" branch to be taken. IOW, we don't
2138 want this thread to step further from PC
2140 insert_single_step_breakpoint (gdbarch, aspace, pc);
2141 insert_breakpoints ();
2143 tp->suspend.stop_signal = GDB_SIGNAL_0;
2144 /* We're continuing with all breakpoints inserted. It's
2145 safe to let the target bypass signals. */
2146 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
2147 /* ... and safe to let other threads run, according to
2149 resume_ptid = user_visible_resume_ptid (entry_step);
2150 target_resume (resume_ptid, 0, GDB_SIGNAL_0);
2151 discard_cleanups (old_cleanups);
2157 /* If we have a breakpoint to step over, make sure to do a single
2158 step only. Same if we have software watchpoints. */
2159 if (tp->control.trap_expected || bpstat_should_step ())
2160 tp->control.may_range_step = 0;
2162 /* If enabled, step over breakpoints by executing a copy of the
2163 instruction at a different address.
2165 We can't use displaced stepping when we have a signal to deliver;
2166 the comments for displaced_step_prepare explain why. The
2167 comments in the handle_inferior event for dealing with 'random
2168 signals' explain what we do instead.
2170 We can't use displaced stepping when we are waiting for vfork_done
2171 event, displaced stepping breaks the vfork child similarly as single
2172 step software breakpoint. */
2173 if (use_displaced_stepping (gdbarch)
2174 && tp->control.trap_expected
2175 && sig == GDB_SIGNAL_0
2176 && !current_inferior ()->waiting_for_vfork_done)
2178 struct displaced_step_inferior_state *displaced;
2180 if (!displaced_step_prepare (inferior_ptid))
2182 /* Got placed in displaced stepping queue. Will be resumed
2183 later when all the currently queued displaced stepping
2184 requests finish. The thread is not executing at this
2185 point, and the call to set_executing will be made later.
2186 But we need to call set_running here, since from the
2187 user/frontend's point of view, threads were set running.
2188 Unless we're calling an inferior function, as in that
2189 case we pretend the inferior doesn't run at all. */
2190 if (!tp->control.in_infcall)
2191 set_running (user_visible_resume_ptid (entry_step), 1);
2192 discard_cleanups (old_cleanups);
2196 /* Update pc to reflect the new address from which we will execute
2197 instructions due to displaced stepping. */
2198 pc = regcache_read_pc (get_thread_regcache (inferior_ptid));
2200 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
2201 step = gdbarch_displaced_step_hw_singlestep (gdbarch,
2202 displaced->step_closure);
2205 /* Do we need to do it the hard way, w/temp breakpoints? */
2207 step = maybe_software_singlestep (gdbarch, pc);
2209 /* Currently, our software single-step implementation leads to different
2210 results than hardware single-stepping in one situation: when stepping
2211 into delivering a signal which has an associated signal handler,
2212 hardware single-step will stop at the first instruction of the handler,
2213 while software single-step will simply skip execution of the handler.
2215 For now, this difference in behavior is accepted since there is no
2216 easy way to actually implement single-stepping into a signal handler
2217 without kernel support.
2219 However, there is one scenario where this difference leads to follow-on
2220 problems: if we're stepping off a breakpoint by removing all breakpoints
2221 and then single-stepping. In this case, the software single-step
2222 behavior means that even if there is a *breakpoint* in the signal
2223 handler, GDB still would not stop.
2225 Fortunately, we can at least fix this particular issue. We detect
2226 here the case where we are about to deliver a signal while software
2227 single-stepping with breakpoints removed. In this situation, we
2228 revert the decisions to remove all breakpoints and insert single-
2229 step breakpoints, and instead we install a step-resume breakpoint
2230 at the current address, deliver the signal without stepping, and
2231 once we arrive back at the step-resume breakpoint, actually step
2232 over the breakpoint we originally wanted to step over. */
2233 if (thread_has_single_step_breakpoints_set (tp)
2234 && sig != GDB_SIGNAL_0
2235 && step_over_info_valid_p ())
2237 /* If we have nested signals or a pending signal is delivered
2238 immediately after a handler returns, might might already have
2239 a step-resume breakpoint set on the earlier handler. We cannot
2240 set another step-resume breakpoint; just continue on until the
2241 original breakpoint is hit. */
2242 if (tp->control.step_resume_breakpoint == NULL)
2244 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2245 tp->step_after_step_resume_breakpoint = 1;
2248 delete_single_step_breakpoints (tp);
2250 clear_step_over_info ();
2251 tp->control.trap_expected = 0;
2253 insert_breakpoints ();
2256 /* If STEP is set, it's a request to use hardware stepping
2257 facilities. But in that case, we should never
2258 use singlestep breakpoint. */
2259 gdb_assert (!(thread_has_single_step_breakpoints_set (tp) && step));
2261 /* Decide the set of threads to ask the target to resume. Start
2262 by assuming everything will be resumed, than narrow the set
2263 by applying increasingly restricting conditions. */
2264 resume_ptid = user_visible_resume_ptid (entry_step);
2266 /* Even if RESUME_PTID is a wildcard, and we end up resuming less
2267 (e.g., we might need to step over a breakpoint), from the
2268 user/frontend's point of view, all threads in RESUME_PTID are now
2269 running. Unless we're calling an inferior function, as in that
2270 case pretend we inferior doesn't run at all. */
2271 if (!tp->control.in_infcall)
2272 set_running (resume_ptid, 1);
2274 /* Maybe resume a single thread after all. */
2275 if ((step || thread_has_single_step_breakpoints_set (tp))
2276 && tp->control.trap_expected)
2278 /* We're allowing a thread to run past a breakpoint it has
2279 hit, by single-stepping the thread with the breakpoint
2280 removed. In which case, we need to single-step only this
2281 thread, and keep others stopped, as they can miss this
2282 breakpoint if allowed to run. */
2283 resume_ptid = inferior_ptid;
2286 if (execution_direction != EXEC_REVERSE
2287 && step && breakpoint_inserted_here_p (aspace, pc))
2289 /* The only case we currently need to step a breakpoint
2290 instruction is when we have a signal to deliver. See
2291 handle_signal_stop where we handle random signals that could
2292 take out us out of the stepping range. Normally, in that
2293 case we end up continuing (instead of stepping) over the
2294 signal handler with a breakpoint at PC, but there are cases
2295 where we should _always_ single-step, even if we have a
2296 step-resume breakpoint, like when a software watchpoint is
2297 set. Assuming single-stepping and delivering a signal at the
2298 same time would takes us to the signal handler, then we could
2299 have removed the breakpoint at PC to step over it. However,
2300 some hardware step targets (like e.g., Mac OS) can't step
2301 into signal handlers, and for those, we need to leave the
2302 breakpoint at PC inserted, as otherwise if the handler
2303 recurses and executes PC again, it'll miss the breakpoint.
2304 So we leave the breakpoint inserted anyway, but we need to
2305 record that we tried to step a breakpoint instruction, so
2306 that adjust_pc_after_break doesn't end up confused. */
2307 gdb_assert (sig != GDB_SIGNAL_0);
2309 tp->stepped_breakpoint = 1;
2311 /* Most targets can step a breakpoint instruction, thus
2312 executing it normally. But if this one cannot, just
2313 continue and we will hit it anyway. */
2314 if (gdbarch_cannot_step_breakpoint (gdbarch))
2319 && use_displaced_stepping (gdbarch)
2320 && tp->control.trap_expected)
2322 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
2323 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
2324 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
2327 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
2328 paddress (resume_gdbarch, actual_pc));
2329 read_memory (actual_pc, buf, sizeof (buf));
2330 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
2333 if (tp->control.may_range_step)
2335 /* If we're resuming a thread with the PC out of the step
2336 range, then we're doing some nested/finer run control
2337 operation, like stepping the thread out of the dynamic
2338 linker or the displaced stepping scratch pad. We
2339 shouldn't have allowed a range step then. */
2340 gdb_assert (pc_in_thread_step_range (pc, tp));
2343 /* Install inferior's terminal modes. */
2344 target_terminal_inferior ();
2346 /* Avoid confusing the next resume, if the next stop/resume
2347 happens to apply to another thread. */
2348 tp->suspend.stop_signal = GDB_SIGNAL_0;
2350 /* Advise target which signals may be handled silently. If we have
2351 removed breakpoints because we are stepping over one (in any
2352 thread), we need to receive all signals to avoid accidentally
2353 skipping a breakpoint during execution of a signal handler. */
2354 if (step_over_info_valid_p ())
2355 target_pass_signals (0, NULL);
2357 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
2359 target_resume (resume_ptid, step, sig);
2361 discard_cleanups (old_cleanups);
2366 /* Clear out all variables saying what to do when inferior is continued.
2367 First do this, then set the ones you want, then call `proceed'. */
2370 clear_proceed_status_thread (struct thread_info *tp)
2373 fprintf_unfiltered (gdb_stdlog,
2374 "infrun: clear_proceed_status_thread (%s)\n",
2375 target_pid_to_str (tp->ptid));
2377 /* If this signal should not be seen by program, give it zero.
2378 Used for debugging signals. */
2379 if (!signal_pass_state (tp->suspend.stop_signal))
2380 tp->suspend.stop_signal = GDB_SIGNAL_0;
2382 tp->control.trap_expected = 0;
2383 tp->control.step_range_start = 0;
2384 tp->control.step_range_end = 0;
2385 tp->control.may_range_step = 0;
2386 tp->control.step_frame_id = null_frame_id;
2387 tp->control.step_stack_frame_id = null_frame_id;
2388 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
2389 tp->stop_requested = 0;
2391 tp->control.stop_step = 0;
2393 tp->control.proceed_to_finish = 0;
2395 tp->control.command_interp = NULL;
2397 /* Discard any remaining commands or status from previous stop. */
2398 bpstat_clear (&tp->control.stop_bpstat);
2402 clear_proceed_status (int step)
2406 struct thread_info *tp;
2409 resume_ptid = user_visible_resume_ptid (step);
2411 /* In all-stop mode, delete the per-thread status of all threads
2412 we're about to resume, implicitly and explicitly. */
2413 ALL_NON_EXITED_THREADS (tp)
2415 if (!ptid_match (tp->ptid, resume_ptid))
2417 clear_proceed_status_thread (tp);
2421 if (!ptid_equal (inferior_ptid, null_ptid))
2423 struct inferior *inferior;
2427 /* If in non-stop mode, only delete the per-thread status of
2428 the current thread. */
2429 clear_proceed_status_thread (inferior_thread ());
2432 inferior = current_inferior ();
2433 inferior->control.stop_soon = NO_STOP_QUIETLY;
2436 stop_after_trap = 0;
2438 clear_step_over_info ();
2440 observer_notify_about_to_proceed ();
2444 regcache_xfree (stop_registers);
2445 stop_registers = NULL;
2449 /* Returns true if TP is still stopped at a breakpoint that needs
2450 stepping-over in order to make progress. If the breakpoint is gone
2451 meanwhile, we can skip the whole step-over dance. */
2454 thread_still_needs_step_over (struct thread_info *tp)
2456 if (tp->stepping_over_breakpoint)
2458 struct regcache *regcache = get_thread_regcache (tp->ptid);
2460 if (breakpoint_here_p (get_regcache_aspace (regcache),
2461 regcache_read_pc (regcache))
2462 == ordinary_breakpoint_here)
2465 tp->stepping_over_breakpoint = 0;
2471 /* Returns true if scheduler locking applies. STEP indicates whether
2472 we're about to do a step/next-like command to a thread. */
2475 schedlock_applies (int step)
2477 return (scheduler_mode == schedlock_on
2478 || (scheduler_mode == schedlock_step
2482 /* Look a thread other than EXCEPT that has previously reported a
2483 breakpoint event, and thus needs a step-over in order to make
2484 progress. Returns NULL is none is found. STEP indicates whether
2485 we're about to step the current thread, in order to decide whether
2486 "set scheduler-locking step" applies. */
2488 static struct thread_info *
2489 find_thread_needs_step_over (int step, struct thread_info *except)
2491 struct thread_info *tp, *current;
2493 /* With non-stop mode on, threads are always handled individually. */
2494 gdb_assert (! non_stop);
2496 current = inferior_thread ();
2498 /* If scheduler locking applies, we can avoid iterating over all
2500 if (schedlock_applies (step))
2502 if (except != current
2503 && thread_still_needs_step_over (current))
2509 ALL_NON_EXITED_THREADS (tp)
2511 /* Ignore the EXCEPT thread. */
2514 /* Ignore threads of processes we're not resuming. */
2516 && ptid_get_pid (tp->ptid) != ptid_get_pid (inferior_ptid))
2519 if (thread_still_needs_step_over (tp))
2526 /* Basic routine for continuing the program in various fashions.
2528 ADDR is the address to resume at, or -1 for resume where stopped.
2529 SIGGNAL is the signal to give it, or 0 for none,
2530 or -1 for act according to how it stopped.
2531 STEP is nonzero if should trap after one instruction.
2532 -1 means return after that and print nothing.
2533 You should probably set various step_... variables
2534 before calling here, if you are stepping.
2536 You should call clear_proceed_status before calling proceed. */
2539 proceed (CORE_ADDR addr, enum gdb_signal siggnal, int step)
2541 struct regcache *regcache;
2542 struct gdbarch *gdbarch;
2543 struct thread_info *tp;
2545 struct address_space *aspace;
2547 /* If we're stopped at a fork/vfork, follow the branch set by the
2548 "set follow-fork-mode" command; otherwise, we'll just proceed
2549 resuming the current thread. */
2550 if (!follow_fork ())
2552 /* The target for some reason decided not to resume. */
2554 if (target_can_async_p ())
2555 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2559 /* We'll update this if & when we switch to a new thread. */
2560 previous_inferior_ptid = inferior_ptid;
2562 regcache = get_current_regcache ();
2563 gdbarch = get_regcache_arch (regcache);
2564 aspace = get_regcache_aspace (regcache);
2565 pc = regcache_read_pc (regcache);
2566 tp = inferior_thread ();
2569 step_start_function = find_pc_function (pc);
2571 stop_after_trap = 1;
2573 /* Fill in with reasonable starting values. */
2574 init_thread_stepping_state (tp);
2576 if (addr == (CORE_ADDR) -1)
2579 && breakpoint_here_p (aspace, pc) == ordinary_breakpoint_here
2580 && execution_direction != EXEC_REVERSE)
2581 /* There is a breakpoint at the address we will resume at,
2582 step one instruction before inserting breakpoints so that
2583 we do not stop right away (and report a second hit at this
2586 Note, we don't do this in reverse, because we won't
2587 actually be executing the breakpoint insn anyway.
2588 We'll be (un-)executing the previous instruction. */
2589 tp->stepping_over_breakpoint = 1;
2590 else if (gdbarch_single_step_through_delay_p (gdbarch)
2591 && gdbarch_single_step_through_delay (gdbarch,
2592 get_current_frame ()))
2593 /* We stepped onto an instruction that needs to be stepped
2594 again before re-inserting the breakpoint, do so. */
2595 tp->stepping_over_breakpoint = 1;
2599 regcache_write_pc (regcache, addr);
2602 if (siggnal != GDB_SIGNAL_DEFAULT)
2603 tp->suspend.stop_signal = siggnal;
2605 /* Record the interpreter that issued the execution command that
2606 caused this thread to resume. If the top level interpreter is
2607 MI/async, and the execution command was a CLI command
2608 (next/step/etc.), we'll want to print stop event output to the MI
2609 console channel (the stepped-to line, etc.), as if the user
2610 entered the execution command on a real GDB console. */
2611 inferior_thread ()->control.command_interp = command_interp ();
2614 fprintf_unfiltered (gdb_stdlog,
2615 "infrun: proceed (addr=%s, signal=%s, step=%d)\n",
2616 paddress (gdbarch, addr),
2617 gdb_signal_to_symbol_string (siggnal), step);
2620 /* In non-stop, each thread is handled individually. The context
2621 must already be set to the right thread here. */
2625 struct thread_info *step_over;
2627 /* In a multi-threaded task we may select another thread and
2628 then continue or step.
2630 But if the old thread was stopped at a breakpoint, it will
2631 immediately cause another breakpoint stop without any
2632 execution (i.e. it will report a breakpoint hit incorrectly).
2633 So we must step over it first.
2635 Look for a thread other than the current (TP) that reported a
2636 breakpoint hit and hasn't been resumed yet since. */
2637 step_over = find_thread_needs_step_over (step, tp);
2638 if (step_over != NULL)
2641 fprintf_unfiltered (gdb_stdlog,
2642 "infrun: need to step-over [%s] first\n",
2643 target_pid_to_str (step_over->ptid));
2645 /* Store the prev_pc for the stepping thread too, needed by
2646 switch_back_to_stepping thread. */
2647 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2648 switch_to_thread (step_over->ptid);
2653 /* If we need to step over a breakpoint, and we're not using
2654 displaced stepping to do so, insert all breakpoints (watchpoints,
2655 etc.) but the one we're stepping over, step one instruction, and
2656 then re-insert the breakpoint when that step is finished. */
2657 if (tp->stepping_over_breakpoint && !use_displaced_stepping (gdbarch))
2659 struct regcache *regcache = get_current_regcache ();
2661 set_step_over_info (get_regcache_aspace (regcache),
2662 regcache_read_pc (regcache), 0);
2665 clear_step_over_info ();
2667 insert_breakpoints ();
2669 tp->control.trap_expected = tp->stepping_over_breakpoint;
2671 annotate_starting ();
2673 /* Make sure that output from GDB appears before output from the
2675 gdb_flush (gdb_stdout);
2677 /* Refresh prev_pc value just prior to resuming. This used to be
2678 done in stop_waiting, however, setting prev_pc there did not handle
2679 scenarios such as inferior function calls or returning from
2680 a function via the return command. In those cases, the prev_pc
2681 value was not set properly for subsequent commands. The prev_pc value
2682 is used to initialize the starting line number in the ecs. With an
2683 invalid value, the gdb next command ends up stopping at the position
2684 represented by the next line table entry past our start position.
2685 On platforms that generate one line table entry per line, this
2686 is not a problem. However, on the ia64, the compiler generates
2687 extraneous line table entries that do not increase the line number.
2688 When we issue the gdb next command on the ia64 after an inferior call
2689 or a return command, we often end up a few instructions forward, still
2690 within the original line we started.
2692 An attempt was made to refresh the prev_pc at the same time the
2693 execution_control_state is initialized (for instance, just before
2694 waiting for an inferior event). But this approach did not work
2695 because of platforms that use ptrace, where the pc register cannot
2696 be read unless the inferior is stopped. At that point, we are not
2697 guaranteed the inferior is stopped and so the regcache_read_pc() call
2698 can fail. Setting the prev_pc value here ensures the value is updated
2699 correctly when the inferior is stopped. */
2700 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2702 /* Resume inferior. */
2703 resume (tp->control.trap_expected || step || bpstat_should_step (),
2704 tp->suspend.stop_signal);
2706 /* Wait for it to stop (if not standalone)
2707 and in any case decode why it stopped, and act accordingly. */
2708 /* Do this only if we are not using the event loop, or if the target
2709 does not support asynchronous execution. */
2710 if (!target_can_async_p ())
2712 wait_for_inferior ();
2718 /* Start remote-debugging of a machine over a serial link. */
2721 start_remote (int from_tty)
2723 struct inferior *inferior;
2725 inferior = current_inferior ();
2726 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2728 /* Always go on waiting for the target, regardless of the mode. */
2729 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2730 indicate to wait_for_inferior that a target should timeout if
2731 nothing is returned (instead of just blocking). Because of this,
2732 targets expecting an immediate response need to, internally, set
2733 things up so that the target_wait() is forced to eventually
2735 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2736 differentiate to its caller what the state of the target is after
2737 the initial open has been performed. Here we're assuming that
2738 the target has stopped. It should be possible to eventually have
2739 target_open() return to the caller an indication that the target
2740 is currently running and GDB state should be set to the same as
2741 for an async run. */
2742 wait_for_inferior ();
2744 /* Now that the inferior has stopped, do any bookkeeping like
2745 loading shared libraries. We want to do this before normal_stop,
2746 so that the displayed frame is up to date. */
2747 post_create_inferior (¤t_target, from_tty);
2752 /* Initialize static vars when a new inferior begins. */
2755 init_wait_for_inferior (void)
2757 /* These are meaningless until the first time through wait_for_inferior. */
2759 breakpoint_init_inferior (inf_starting);
2761 clear_proceed_status (0);
2763 target_last_wait_ptid = minus_one_ptid;
2765 previous_inferior_ptid = inferior_ptid;
2767 /* Discard any skipped inlined frames. */
2768 clear_inline_frame_state (minus_one_ptid);
2772 /* Data to be passed around while handling an event. This data is
2773 discarded between events. */
2774 struct execution_control_state
2777 /* The thread that got the event, if this was a thread event; NULL
2779 struct thread_info *event_thread;
2781 struct target_waitstatus ws;
2782 int stop_func_filled_in;
2783 CORE_ADDR stop_func_start;
2784 CORE_ADDR stop_func_end;
2785 const char *stop_func_name;
2788 /* True if the event thread hit the single-step breakpoint of
2789 another thread. Thus the event doesn't cause a stop, the thread
2790 needs to be single-stepped past the single-step breakpoint before
2791 we can switch back to the original stepping thread. */
2792 int hit_singlestep_breakpoint;
2795 static void handle_inferior_event (struct execution_control_state *ecs);
2797 static void handle_step_into_function (struct gdbarch *gdbarch,
2798 struct execution_control_state *ecs);
2799 static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2800 struct execution_control_state *ecs);
2801 static void handle_signal_stop (struct execution_control_state *ecs);
2802 static void check_exception_resume (struct execution_control_state *,
2803 struct frame_info *);
2805 static void end_stepping_range (struct execution_control_state *ecs);
2806 static void stop_waiting (struct execution_control_state *ecs);
2807 static void prepare_to_wait (struct execution_control_state *ecs);
2808 static void keep_going (struct execution_control_state *ecs);
2809 static void process_event_stop_test (struct execution_control_state *ecs);
2810 static int switch_back_to_stepped_thread (struct execution_control_state *ecs);
2812 /* Callback for iterate over threads. If the thread is stopped, but
2813 the user/frontend doesn't know about that yet, go through
2814 normal_stop, as if the thread had just stopped now. ARG points at
2815 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2816 ptid_is_pid(PTID) is true, applies to all threads of the process
2817 pointed at by PTID. Otherwise, apply only to the thread pointed by
2821 infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2823 ptid_t ptid = * (ptid_t *) arg;
2825 if ((ptid_equal (info->ptid, ptid)
2826 || ptid_equal (minus_one_ptid, ptid)
2827 || (ptid_is_pid (ptid)
2828 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2829 && is_running (info->ptid)
2830 && !is_executing (info->ptid))
2832 struct cleanup *old_chain;
2833 struct execution_control_state ecss;
2834 struct execution_control_state *ecs = &ecss;
2836 memset (ecs, 0, sizeof (*ecs));
2838 old_chain = make_cleanup_restore_current_thread ();
2840 overlay_cache_invalid = 1;
2841 /* Flush target cache before starting to handle each event.
2842 Target was running and cache could be stale. This is just a
2843 heuristic. Running threads may modify target memory, but we
2844 don't get any event. */
2845 target_dcache_invalidate ();
2847 /* Go through handle_inferior_event/normal_stop, so we always
2848 have consistent output as if the stop event had been
2850 ecs->ptid = info->ptid;
2851 ecs->event_thread = find_thread_ptid (info->ptid);
2852 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2853 ecs->ws.value.sig = GDB_SIGNAL_0;
2855 handle_inferior_event (ecs);
2857 if (!ecs->wait_some_more)
2859 struct thread_info *tp;
2863 /* Finish off the continuations. */
2864 tp = inferior_thread ();
2865 do_all_intermediate_continuations_thread (tp, 1);
2866 do_all_continuations_thread (tp, 1);
2869 do_cleanups (old_chain);
2875 /* This function is attached as a "thread_stop_requested" observer.
2876 Cleanup local state that assumed the PTID was to be resumed, and
2877 report the stop to the frontend. */
2880 infrun_thread_stop_requested (ptid_t ptid)
2882 struct displaced_step_inferior_state *displaced;
2884 /* PTID was requested to stop. Remove it from the displaced
2885 stepping queue, so we don't try to resume it automatically. */
2887 for (displaced = displaced_step_inferior_states;
2889 displaced = displaced->next)
2891 struct displaced_step_request *it, **prev_next_p;
2893 it = displaced->step_request_queue;
2894 prev_next_p = &displaced->step_request_queue;
2897 if (ptid_match (it->ptid, ptid))
2899 *prev_next_p = it->next;
2905 prev_next_p = &it->next;
2912 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2916 infrun_thread_thread_exit (struct thread_info *tp, int silent)
2918 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2919 nullify_last_target_wait_ptid ();
2922 /* Delete the step resume, single-step and longjmp/exception resume
2923 breakpoints of TP. */
2926 delete_thread_infrun_breakpoints (struct thread_info *tp)
2928 delete_step_resume_breakpoint (tp);
2929 delete_exception_resume_breakpoint (tp);
2930 delete_single_step_breakpoints (tp);
2933 /* If the target still has execution, call FUNC for each thread that
2934 just stopped. In all-stop, that's all the non-exited threads; in
2935 non-stop, that's the current thread, only. */
2937 typedef void (*for_each_just_stopped_thread_callback_func)
2938 (struct thread_info *tp);
2941 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func)
2943 if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid))
2948 /* If in non-stop mode, only the current thread stopped. */
2949 func (inferior_thread ());
2953 struct thread_info *tp;
2955 /* In all-stop mode, all threads have stopped. */
2956 ALL_NON_EXITED_THREADS (tp)
2963 /* Delete the step resume and longjmp/exception resume breakpoints of
2964 the threads that just stopped. */
2967 delete_just_stopped_threads_infrun_breakpoints (void)
2969 for_each_just_stopped_thread (delete_thread_infrun_breakpoints);
2972 /* Delete the single-step breakpoints of the threads that just
2976 delete_just_stopped_threads_single_step_breakpoints (void)
2978 for_each_just_stopped_thread (delete_single_step_breakpoints);
2981 /* A cleanup wrapper. */
2984 delete_just_stopped_threads_infrun_breakpoints_cleanup (void *arg)
2986 delete_just_stopped_threads_infrun_breakpoints ();
2989 /* Pretty print the results of target_wait, for debugging purposes. */
2992 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
2993 const struct target_waitstatus *ws)
2995 char *status_string = target_waitstatus_to_string (ws);
2996 struct ui_file *tmp_stream = mem_fileopen ();
2999 /* The text is split over several lines because it was getting too long.
3000 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
3001 output as a unit; we want only one timestamp printed if debug_timestamp
3004 fprintf_unfiltered (tmp_stream,
3005 "infrun: target_wait (%d", ptid_get_pid (waiton_ptid));
3006 if (ptid_get_pid (waiton_ptid) != -1)
3007 fprintf_unfiltered (tmp_stream,
3008 " [%s]", target_pid_to_str (waiton_ptid));
3009 fprintf_unfiltered (tmp_stream, ", status) =\n");
3010 fprintf_unfiltered (tmp_stream,
3011 "infrun: %d [%s],\n",
3012 ptid_get_pid (result_ptid),
3013 target_pid_to_str (result_ptid));
3014 fprintf_unfiltered (tmp_stream,
3018 text = ui_file_xstrdup (tmp_stream, NULL);
3020 /* This uses %s in part to handle %'s in the text, but also to avoid
3021 a gcc error: the format attribute requires a string literal. */
3022 fprintf_unfiltered (gdb_stdlog, "%s", text);
3024 xfree (status_string);
3026 ui_file_delete (tmp_stream);
3029 /* Prepare and stabilize the inferior for detaching it. E.g.,
3030 detaching while a thread is displaced stepping is a recipe for
3031 crashing it, as nothing would readjust the PC out of the scratch
3035 prepare_for_detach (void)
3037 struct inferior *inf = current_inferior ();
3038 ptid_t pid_ptid = pid_to_ptid (inf->pid);
3039 struct cleanup *old_chain_1;
3040 struct displaced_step_inferior_state *displaced;
3042 displaced = get_displaced_stepping_state (inf->pid);
3044 /* Is any thread of this process displaced stepping? If not,
3045 there's nothing else to do. */
3046 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
3050 fprintf_unfiltered (gdb_stdlog,
3051 "displaced-stepping in-process while detaching");
3053 old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
3056 while (!ptid_equal (displaced->step_ptid, null_ptid))
3058 struct cleanup *old_chain_2;
3059 struct execution_control_state ecss;
3060 struct execution_control_state *ecs;
3063 memset (ecs, 0, sizeof (*ecs));
3065 overlay_cache_invalid = 1;
3066 /* Flush target cache before starting to handle each event.
3067 Target was running and cache could be stale. This is just a
3068 heuristic. Running threads may modify target memory, but we
3069 don't get any event. */
3070 target_dcache_invalidate ();
3072 if (deprecated_target_wait_hook)
3073 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
3075 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
3078 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
3080 /* If an error happens while handling the event, propagate GDB's
3081 knowledge of the executing state to the frontend/user running
3083 old_chain_2 = make_cleanup (finish_thread_state_cleanup,
3086 /* Now figure out what to do with the result of the result. */
3087 handle_inferior_event (ecs);
3089 /* No error, don't finish the state yet. */
3090 discard_cleanups (old_chain_2);
3092 /* Breakpoints and watchpoints are not installed on the target
3093 at this point, and signals are passed directly to the
3094 inferior, so this must mean the process is gone. */
3095 if (!ecs->wait_some_more)
3097 discard_cleanups (old_chain_1);
3098 error (_("Program exited while detaching"));
3102 discard_cleanups (old_chain_1);
3105 /* Wait for control to return from inferior to debugger.
3107 If inferior gets a signal, we may decide to start it up again
3108 instead of returning. That is why there is a loop in this function.
3109 When this function actually returns it means the inferior
3110 should be left stopped and GDB should read more commands. */
3113 wait_for_inferior (void)
3115 struct cleanup *old_cleanups;
3119 (gdb_stdlog, "infrun: wait_for_inferior ()\n");
3122 = make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup,
3127 struct execution_control_state ecss;
3128 struct execution_control_state *ecs = &ecss;
3129 struct cleanup *old_chain;
3130 ptid_t waiton_ptid = minus_one_ptid;
3132 memset (ecs, 0, sizeof (*ecs));
3134 overlay_cache_invalid = 1;
3136 /* Flush target cache before starting to handle each event.
3137 Target was running and cache could be stale. This is just a
3138 heuristic. Running threads may modify target memory, but we
3139 don't get any event. */
3140 target_dcache_invalidate ();
3142 if (deprecated_target_wait_hook)
3143 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
3145 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
3148 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
3150 /* If an error happens while handling the event, propagate GDB's
3151 knowledge of the executing state to the frontend/user running
3153 old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
3155 /* Now figure out what to do with the result of the result. */
3156 handle_inferior_event (ecs);
3158 /* No error, don't finish the state yet. */
3159 discard_cleanups (old_chain);
3161 if (!ecs->wait_some_more)
3165 do_cleanups (old_cleanups);
3168 /* Cleanup that reinstalls the readline callback handler, if the
3169 target is running in the background. If while handling the target
3170 event something triggered a secondary prompt, like e.g., a
3171 pagination prompt, we'll have removed the callback handler (see
3172 gdb_readline_wrapper_line). Need to do this as we go back to the
3173 event loop, ready to process further input. Note this has no
3174 effect if the handler hasn't actually been removed, because calling
3175 rl_callback_handler_install resets the line buffer, thus losing
3179 reinstall_readline_callback_handler_cleanup (void *arg)
3181 if (!interpreter_async)
3183 /* We're not going back to the top level event loop yet. Don't
3184 install the readline callback, as it'd prep the terminal,
3185 readline-style (raw, noecho) (e.g., --batch). We'll install
3186 it the next time the prompt is displayed, when we're ready
3191 if (async_command_editing_p && !sync_execution)
3192 gdb_rl_callback_handler_reinstall ();
3195 /* Asynchronous version of wait_for_inferior. It is called by the
3196 event loop whenever a change of state is detected on the file
3197 descriptor corresponding to the target. It can be called more than
3198 once to complete a single execution command. In such cases we need
3199 to keep the state in a global variable ECSS. If it is the last time
3200 that this function is called for a single execution command, then
3201 report to the user that the inferior has stopped, and do the
3202 necessary cleanups. */
3205 fetch_inferior_event (void *client_data)
3207 struct execution_control_state ecss;
3208 struct execution_control_state *ecs = &ecss;
3209 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
3210 struct cleanup *ts_old_chain;
3211 int was_sync = sync_execution;
3213 ptid_t waiton_ptid = minus_one_ptid;
3215 memset (ecs, 0, sizeof (*ecs));
3217 /* End up with readline processing input, if necessary. */
3218 make_cleanup (reinstall_readline_callback_handler_cleanup, NULL);
3220 /* We're handling a live event, so make sure we're doing live
3221 debugging. If we're looking at traceframes while the target is
3222 running, we're going to need to get back to that mode after
3223 handling the event. */
3226 make_cleanup_restore_current_traceframe ();
3227 set_current_traceframe (-1);
3231 /* In non-stop mode, the user/frontend should not notice a thread
3232 switch due to internal events. Make sure we reverse to the
3233 user selected thread and frame after handling the event and
3234 running any breakpoint commands. */
3235 make_cleanup_restore_current_thread ();
3237 overlay_cache_invalid = 1;
3238 /* Flush target cache before starting to handle each event. Target
3239 was running and cache could be stale. This is just a heuristic.
3240 Running threads may modify target memory, but we don't get any
3242 target_dcache_invalidate ();
3244 make_cleanup_restore_integer (&execution_direction);
3245 execution_direction = target_execution_direction ();
3247 if (deprecated_target_wait_hook)
3249 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
3251 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
3254 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
3256 /* If an error happens while handling the event, propagate GDB's
3257 knowledge of the executing state to the frontend/user running
3260 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
3262 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
3264 /* Get executed before make_cleanup_restore_current_thread above to apply
3265 still for the thread which has thrown the exception. */
3266 make_bpstat_clear_actions_cleanup ();
3268 make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup, NULL);
3270 /* Now figure out what to do with the result of the result. */
3271 handle_inferior_event (ecs);
3273 if (!ecs->wait_some_more)
3275 struct inferior *inf = find_inferior_ptid (ecs->ptid);
3277 delete_just_stopped_threads_infrun_breakpoints ();
3279 /* We may not find an inferior if this was a process exit. */
3280 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
3283 if (target_has_execution
3284 && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED
3285 && ecs->ws.kind != TARGET_WAITKIND_EXITED
3286 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3287 && ecs->event_thread->step_multi
3288 && ecs->event_thread->control.stop_step)
3289 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
3292 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
3297 /* No error, don't finish the thread states yet. */
3298 discard_cleanups (ts_old_chain);
3300 /* Revert thread and frame. */
3301 do_cleanups (old_chain);
3303 /* If the inferior was in sync execution mode, and now isn't,
3304 restore the prompt (a synchronous execution command has finished,
3305 and we're ready for input). */
3306 if (interpreter_async && was_sync && !sync_execution)
3307 observer_notify_sync_execution_done ();
3311 && exec_done_display_p
3312 && (ptid_equal (inferior_ptid, null_ptid)
3313 || !is_running (inferior_ptid)))
3314 printf_unfiltered (_("completed.\n"));
3317 /* Record the frame and location we're currently stepping through. */
3319 set_step_info (struct frame_info *frame, struct symtab_and_line sal)
3321 struct thread_info *tp = inferior_thread ();
3323 tp->control.step_frame_id = get_frame_id (frame);
3324 tp->control.step_stack_frame_id = get_stack_frame_id (frame);
3326 tp->current_symtab = sal.symtab;
3327 tp->current_line = sal.line;
3330 /* Clear context switchable stepping state. */
3333 init_thread_stepping_state (struct thread_info *tss)
3335 tss->stepped_breakpoint = 0;
3336 tss->stepping_over_breakpoint = 0;
3337 tss->stepping_over_watchpoint = 0;
3338 tss->step_after_step_resume_breakpoint = 0;
3341 /* Set the cached copy of the last ptid/waitstatus. */
3344 set_last_target_status (ptid_t ptid, struct target_waitstatus status)
3346 target_last_wait_ptid = ptid;
3347 target_last_waitstatus = status;
3350 /* Return the cached copy of the last pid/waitstatus returned by
3351 target_wait()/deprecated_target_wait_hook(). The data is actually
3352 cached by handle_inferior_event(), which gets called immediately
3353 after target_wait()/deprecated_target_wait_hook(). */
3356 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
3358 *ptidp = target_last_wait_ptid;
3359 *status = target_last_waitstatus;
3363 nullify_last_target_wait_ptid (void)
3365 target_last_wait_ptid = minus_one_ptid;
3368 /* Switch thread contexts. */
3371 context_switch (ptid_t ptid)
3373 if (debug_infrun && !ptid_equal (ptid, inferior_ptid))
3375 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
3376 target_pid_to_str (inferior_ptid));
3377 fprintf_unfiltered (gdb_stdlog, "to %s\n",
3378 target_pid_to_str (ptid));
3381 switch_to_thread (ptid);
3385 adjust_pc_after_break (struct execution_control_state *ecs)
3387 struct regcache *regcache;
3388 struct gdbarch *gdbarch;
3389 struct address_space *aspace;
3390 CORE_ADDR breakpoint_pc, decr_pc;
3392 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3393 we aren't, just return.
3395 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
3396 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3397 implemented by software breakpoints should be handled through the normal
3400 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3401 different signals (SIGILL or SIGEMT for instance), but it is less
3402 clear where the PC is pointing afterwards. It may not match
3403 gdbarch_decr_pc_after_break. I don't know any specific target that
3404 generates these signals at breakpoints (the code has been in GDB since at
3405 least 1992) so I can not guess how to handle them here.
3407 In earlier versions of GDB, a target with
3408 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
3409 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3410 target with both of these set in GDB history, and it seems unlikely to be
3411 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
3413 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
3416 if (ecs->ws.value.sig != GDB_SIGNAL_TRAP)
3419 /* In reverse execution, when a breakpoint is hit, the instruction
3420 under it has already been de-executed. The reported PC always
3421 points at the breakpoint address, so adjusting it further would
3422 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3425 B1 0x08000000 : INSN1
3426 B2 0x08000001 : INSN2
3428 PC -> 0x08000003 : INSN4
3430 Say you're stopped at 0x08000003 as above. Reverse continuing
3431 from that point should hit B2 as below. Reading the PC when the
3432 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3433 been de-executed already.
3435 B1 0x08000000 : INSN1
3436 B2 PC -> 0x08000001 : INSN2
3440 We can't apply the same logic as for forward execution, because
3441 we would wrongly adjust the PC to 0x08000000, since there's a
3442 breakpoint at PC - 1. We'd then report a hit on B1, although
3443 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3445 if (execution_direction == EXEC_REVERSE)
3448 /* If this target does not decrement the PC after breakpoints, then
3449 we have nothing to do. */
3450 regcache = get_thread_regcache (ecs->ptid);
3451 gdbarch = get_regcache_arch (regcache);
3453 decr_pc = target_decr_pc_after_break (gdbarch);
3457 aspace = get_regcache_aspace (regcache);
3459 /* Find the location where (if we've hit a breakpoint) the
3460 breakpoint would be. */
3461 breakpoint_pc = regcache_read_pc (regcache) - decr_pc;
3463 /* Check whether there actually is a software breakpoint inserted at
3466 If in non-stop mode, a race condition is possible where we've
3467 removed a breakpoint, but stop events for that breakpoint were
3468 already queued and arrive later. To suppress those spurious
3469 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3470 and retire them after a number of stop events are reported. */
3471 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
3472 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
3474 struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
3476 if (record_full_is_used ())
3477 record_full_gdb_operation_disable_set ();
3479 /* When using hardware single-step, a SIGTRAP is reported for both
3480 a completed single-step and a software breakpoint. Need to
3481 differentiate between the two, as the latter needs adjusting
3482 but the former does not.
3484 The SIGTRAP can be due to a completed hardware single-step only if
3485 - we didn't insert software single-step breakpoints
3486 - the thread to be examined is still the current thread
3487 - this thread is currently being stepped
3489 If any of these events did not occur, we must have stopped due
3490 to hitting a software breakpoint, and have to back up to the
3493 As a special case, we could have hardware single-stepped a
3494 software breakpoint. In this case (prev_pc == breakpoint_pc),
3495 we also need to back up to the breakpoint address. */
3497 if (thread_has_single_step_breakpoints_set (ecs->event_thread)
3498 || !ptid_equal (ecs->ptid, inferior_ptid)
3499 || !currently_stepping (ecs->event_thread)
3500 || (ecs->event_thread->stepped_breakpoint
3501 && ecs->event_thread->prev_pc == breakpoint_pc))
3502 regcache_write_pc (regcache, breakpoint_pc);
3504 do_cleanups (old_cleanups);
3509 stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
3511 for (frame = get_prev_frame (frame);
3513 frame = get_prev_frame (frame))
3515 if (frame_id_eq (get_frame_id (frame), step_frame_id))
3517 if (get_frame_type (frame) != INLINE_FRAME)
3524 /* Auxiliary function that handles syscall entry/return events.
3525 It returns 1 if the inferior should keep going (and GDB
3526 should ignore the event), or 0 if the event deserves to be
3530 handle_syscall_event (struct execution_control_state *ecs)
3532 struct regcache *regcache;
3535 if (!ptid_equal (ecs->ptid, inferior_ptid))
3536 context_switch (ecs->ptid);
3538 regcache = get_thread_regcache (ecs->ptid);
3539 syscall_number = ecs->ws.value.syscall_number;
3540 stop_pc = regcache_read_pc (regcache);
3542 if (catch_syscall_enabled () > 0
3543 && catching_syscall_number (syscall_number) > 0)
3546 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
3549 ecs->event_thread->control.stop_bpstat
3550 = bpstat_stop_status (get_regcache_aspace (regcache),
3551 stop_pc, ecs->ptid, &ecs->ws);
3553 if (bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
3555 /* Catchpoint hit. */
3560 /* If no catchpoint triggered for this, then keep going. */
3565 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3568 fill_in_stop_func (struct gdbarch *gdbarch,
3569 struct execution_control_state *ecs)
3571 if (!ecs->stop_func_filled_in)
3573 /* Don't care about return value; stop_func_start and stop_func_name
3574 will both be 0 if it doesn't work. */
3575 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3576 &ecs->stop_func_start, &ecs->stop_func_end);
3577 ecs->stop_func_start
3578 += gdbarch_deprecated_function_start_offset (gdbarch);
3580 if (gdbarch_skip_entrypoint_p (gdbarch))
3581 ecs->stop_func_start = gdbarch_skip_entrypoint (gdbarch,
3582 ecs->stop_func_start);
3584 ecs->stop_func_filled_in = 1;
3589 /* Return the STOP_SOON field of the inferior pointed at by PTID. */
3591 static enum stop_kind
3592 get_inferior_stop_soon (ptid_t ptid)
3594 struct inferior *inf = find_inferior_ptid (ptid);
3596 gdb_assert (inf != NULL);
3597 return inf->control.stop_soon;
3600 /* Given an execution control state that has been freshly filled in by
3601 an event from the inferior, figure out what it means and take
3604 The alternatives are:
3606 1) stop_waiting and return; to really stop and return to the
3609 2) keep_going and return; to wait for the next event (set
3610 ecs->event_thread->stepping_over_breakpoint to 1 to single step
3614 handle_inferior_event (struct execution_control_state *ecs)
3616 enum stop_kind stop_soon;
3618 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
3620 /* We had an event in the inferior, but we are not interested in
3621 handling it at this level. The lower layers have already
3622 done what needs to be done, if anything.
3624 One of the possible circumstances for this is when the
3625 inferior produces output for the console. The inferior has
3626 not stopped, and we are ignoring the event. Another possible
3627 circumstance is any event which the lower level knows will be
3628 reported multiple times without an intervening resume. */
3630 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
3631 prepare_to_wait (ecs);
3635 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED
3636 && target_can_async_p () && !sync_execution)
3638 /* There were no unwaited-for children left in the target, but,
3639 we're not synchronously waiting for events either. Just
3640 ignore. Otherwise, if we were running a synchronous
3641 execution command, we need to cancel it and give the user
3642 back the terminal. */
3644 fprintf_unfiltered (gdb_stdlog,
3645 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3646 prepare_to_wait (ecs);
3650 /* Cache the last pid/waitstatus. */
3651 set_last_target_status (ecs->ptid, ecs->ws);
3653 /* Always clear state belonging to the previous time we stopped. */
3654 stop_stack_dummy = STOP_NONE;
3656 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED)
3658 /* No unwaited-for children left. IOW, all resumed children
3661 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3663 stop_print_frame = 0;
3668 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3669 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
3671 ecs->event_thread = find_thread_ptid (ecs->ptid);
3672 /* If it's a new thread, add it to the thread database. */
3673 if (ecs->event_thread == NULL)
3674 ecs->event_thread = add_thread (ecs->ptid);
3676 /* Disable range stepping. If the next step request could use a
3677 range, this will be end up re-enabled then. */
3678 ecs->event_thread->control.may_range_step = 0;
3681 /* Dependent on valid ECS->EVENT_THREAD. */
3682 adjust_pc_after_break (ecs);
3684 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3685 reinit_frame_cache ();
3687 breakpoint_retire_moribund ();
3689 /* First, distinguish signals caused by the debugger from signals
3690 that have to do with the program's own actions. Note that
3691 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3692 on the operating system version. Here we detect when a SIGILL or
3693 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3694 something similar for SIGSEGV, since a SIGSEGV will be generated
3695 when we're trying to execute a breakpoint instruction on a
3696 non-executable stack. This happens for call dummy breakpoints
3697 for architectures like SPARC that place call dummies on the
3699 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
3700 && (ecs->ws.value.sig == GDB_SIGNAL_ILL
3701 || ecs->ws.value.sig == GDB_SIGNAL_SEGV
3702 || ecs->ws.value.sig == GDB_SIGNAL_EMT))
3704 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3706 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3707 regcache_read_pc (regcache)))
3710 fprintf_unfiltered (gdb_stdlog,
3711 "infrun: Treating signal as SIGTRAP\n");
3712 ecs->ws.value.sig = GDB_SIGNAL_TRAP;
3716 /* Mark the non-executing threads accordingly. In all-stop, all
3717 threads of all processes are stopped when we get any event
3718 reported. In non-stop mode, only the event thread stops. If
3719 we're handling a process exit in non-stop mode, there's nothing
3720 to do, as threads of the dead process are gone, and threads of
3721 any other process were left running. */
3723 set_executing (minus_one_ptid, 0);
3724 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3725 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
3726 set_executing (ecs->ptid, 0);
3728 switch (ecs->ws.kind)
3730 case TARGET_WAITKIND_LOADED:
3732 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
3733 if (!ptid_equal (ecs->ptid, inferior_ptid))
3734 context_switch (ecs->ptid);
3735 /* Ignore gracefully during startup of the inferior, as it might
3736 be the shell which has just loaded some objects, otherwise
3737 add the symbols for the newly loaded objects. Also ignore at
3738 the beginning of an attach or remote session; we will query
3739 the full list of libraries once the connection is
3742 stop_soon = get_inferior_stop_soon (ecs->ptid);
3743 if (stop_soon == NO_STOP_QUIETLY)
3745 struct regcache *regcache;
3747 regcache = get_thread_regcache (ecs->ptid);
3749 handle_solib_event ();
3751 ecs->event_thread->control.stop_bpstat
3752 = bpstat_stop_status (get_regcache_aspace (regcache),
3753 stop_pc, ecs->ptid, &ecs->ws);
3755 if (bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
3757 /* A catchpoint triggered. */
3758 process_event_stop_test (ecs);
3762 /* If requested, stop when the dynamic linker notifies
3763 gdb of events. This allows the user to get control
3764 and place breakpoints in initializer routines for
3765 dynamically loaded objects (among other things). */
3766 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
3767 if (stop_on_solib_events)
3769 /* Make sure we print "Stopped due to solib-event" in
3771 stop_print_frame = 1;
3778 /* If we are skipping through a shell, or through shared library
3779 loading that we aren't interested in, resume the program. If
3780 we're running the program normally, also resume. */
3781 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
3783 /* Loading of shared libraries might have changed breakpoint
3784 addresses. Make sure new breakpoints are inserted. */
3785 if (stop_soon == NO_STOP_QUIETLY)
3786 insert_breakpoints ();
3787 resume (0, GDB_SIGNAL_0);
3788 prepare_to_wait (ecs);
3792 /* But stop if we're attaching or setting up a remote
3794 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
3795 || stop_soon == STOP_QUIETLY_REMOTE)
3798 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
3803 internal_error (__FILE__, __LINE__,
3804 _("unhandled stop_soon: %d"), (int) stop_soon);
3806 case TARGET_WAITKIND_SPURIOUS:
3808 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3809 if (!ptid_equal (ecs->ptid, inferior_ptid))
3810 context_switch (ecs->ptid);
3811 resume (0, GDB_SIGNAL_0);
3812 prepare_to_wait (ecs);
3815 case TARGET_WAITKIND_EXITED:
3816 case TARGET_WAITKIND_SIGNALLED:
3819 if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3820 fprintf_unfiltered (gdb_stdlog,
3821 "infrun: TARGET_WAITKIND_EXITED\n");
3823 fprintf_unfiltered (gdb_stdlog,
3824 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3827 inferior_ptid = ecs->ptid;
3828 set_current_inferior (find_inferior_ptid (ecs->ptid));
3829 set_current_program_space (current_inferior ()->pspace);
3830 handle_vfork_child_exec_or_exit (0);
3831 target_terminal_ours (); /* Must do this before mourn anyway. */
3833 /* Clearing any previous state of convenience variables. */
3834 clear_exit_convenience_vars ();
3836 if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3838 /* Record the exit code in the convenience variable $_exitcode, so
3839 that the user can inspect this again later. */
3840 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3841 (LONGEST) ecs->ws.value.integer);
3843 /* Also record this in the inferior itself. */
3844 current_inferior ()->has_exit_code = 1;
3845 current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer;
3847 /* Support the --return-child-result option. */
3848 return_child_result_value = ecs->ws.value.integer;
3850 observer_notify_exited (ecs->ws.value.integer);
3854 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3855 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3857 if (gdbarch_gdb_signal_to_target_p (gdbarch))
3859 /* Set the value of the internal variable $_exitsignal,
3860 which holds the signal uncaught by the inferior. */
3861 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
3862 gdbarch_gdb_signal_to_target (gdbarch,
3863 ecs->ws.value.sig));
3867 /* We don't have access to the target's method used for
3868 converting between signal numbers (GDB's internal
3869 representation <-> target's representation).
3870 Therefore, we cannot do a good job at displaying this
3871 information to the user. It's better to just warn
3872 her about it (if infrun debugging is enabled), and
3875 fprintf_filtered (gdb_stdlog, _("\
3876 Cannot fill $_exitsignal with the correct signal number.\n"));
3879 observer_notify_signal_exited (ecs->ws.value.sig);
3882 gdb_flush (gdb_stdout);
3883 target_mourn_inferior ();
3884 stop_print_frame = 0;
3888 /* The following are the only cases in which we keep going;
3889 the above cases end in a continue or goto. */
3890 case TARGET_WAITKIND_FORKED:
3891 case TARGET_WAITKIND_VFORKED:
3894 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3895 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3897 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORKED\n");
3900 /* Check whether the inferior is displaced stepping. */
3902 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3903 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3904 struct displaced_step_inferior_state *displaced
3905 = get_displaced_stepping_state (ptid_get_pid (ecs->ptid));
3907 /* If checking displaced stepping is supported, and thread
3908 ecs->ptid is displaced stepping. */
3909 if (displaced && ptid_equal (displaced->step_ptid, ecs->ptid))
3911 struct inferior *parent_inf
3912 = find_inferior_ptid (ecs->ptid);
3913 struct regcache *child_regcache;
3914 CORE_ADDR parent_pc;
3916 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3917 indicating that the displaced stepping of syscall instruction
3918 has been done. Perform cleanup for parent process here. Note
3919 that this operation also cleans up the child process for vfork,
3920 because their pages are shared. */
3921 displaced_step_fixup (ecs->ptid, GDB_SIGNAL_TRAP);
3923 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3925 /* Restore scratch pad for child process. */
3926 displaced_step_restore (displaced, ecs->ws.value.related_pid);
3929 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3930 the child's PC is also within the scratchpad. Set the child's PC
3931 to the parent's PC value, which has already been fixed up.
3932 FIXME: we use the parent's aspace here, although we're touching
3933 the child, because the child hasn't been added to the inferior
3934 list yet at this point. */
3937 = get_thread_arch_aspace_regcache (ecs->ws.value.related_pid,
3939 parent_inf->aspace);
3940 /* Read PC value of parent process. */
3941 parent_pc = regcache_read_pc (regcache);
3943 if (debug_displaced)
3944 fprintf_unfiltered (gdb_stdlog,
3945 "displaced: write child pc from %s to %s\n",
3947 regcache_read_pc (child_regcache)),
3948 paddress (gdbarch, parent_pc));
3950 regcache_write_pc (child_regcache, parent_pc);
3954 if (!ptid_equal (ecs->ptid, inferior_ptid))
3955 context_switch (ecs->ptid);
3957 /* Immediately detach breakpoints from the child before there's
3958 any chance of letting the user delete breakpoints from the
3959 breakpoint lists. If we don't do this early, it's easy to
3960 leave left over traps in the child, vis: "break foo; catch
3961 fork; c; <fork>; del; c; <child calls foo>". We only follow
3962 the fork on the last `continue', and by that time the
3963 breakpoint at "foo" is long gone from the breakpoint table.
3964 If we vforked, then we don't need to unpatch here, since both
3965 parent and child are sharing the same memory pages; we'll
3966 need to unpatch at follow/detach time instead to be certain
3967 that new breakpoints added between catchpoint hit time and
3968 vfork follow are detached. */
3969 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
3971 /* This won't actually modify the breakpoint list, but will
3972 physically remove the breakpoints from the child. */
3973 detach_breakpoints (ecs->ws.value.related_pid);
3976 delete_just_stopped_threads_single_step_breakpoints ();
3978 /* In case the event is caught by a catchpoint, remember that
3979 the event is to be followed at the next resume of the thread,
3980 and not immediately. */
3981 ecs->event_thread->pending_follow = ecs->ws;
3983 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3985 ecs->event_thread->control.stop_bpstat
3986 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3987 stop_pc, ecs->ptid, &ecs->ws);
3989 /* If no catchpoint triggered for this, then keep going. Note
3990 that we're interested in knowing the bpstat actually causes a
3991 stop, not just if it may explain the signal. Software
3992 watchpoints, for example, always appear in the bpstat. */
3993 if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
3999 = (follow_fork_mode_string == follow_fork_mode_child);
4001 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4003 should_resume = follow_fork ();
4006 child = ecs->ws.value.related_pid;
4008 /* In non-stop mode, also resume the other branch. */
4009 if (non_stop && !detach_fork)
4012 switch_to_thread (parent);
4014 switch_to_thread (child);
4016 ecs->event_thread = inferior_thread ();
4017 ecs->ptid = inferior_ptid;
4022 switch_to_thread (child);
4024 switch_to_thread (parent);
4026 ecs->event_thread = inferior_thread ();
4027 ecs->ptid = inferior_ptid;
4035 process_event_stop_test (ecs);
4038 case TARGET_WAITKIND_VFORK_DONE:
4039 /* Done with the shared memory region. Re-insert breakpoints in
4040 the parent, and keep going. */
4043 fprintf_unfiltered (gdb_stdlog,
4044 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
4046 if (!ptid_equal (ecs->ptid, inferior_ptid))
4047 context_switch (ecs->ptid);
4049 current_inferior ()->waiting_for_vfork_done = 0;
4050 current_inferior ()->pspace->breakpoints_not_allowed = 0;
4051 /* This also takes care of reinserting breakpoints in the
4052 previously locked inferior. */
4056 case TARGET_WAITKIND_EXECD:
4058 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
4060 if (!ptid_equal (ecs->ptid, inferior_ptid))
4061 context_switch (ecs->ptid);
4063 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4065 /* Do whatever is necessary to the parent branch of the vfork. */
4066 handle_vfork_child_exec_or_exit (1);
4068 /* This causes the eventpoints and symbol table to be reset.
4069 Must do this now, before trying to determine whether to
4071 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
4073 ecs->event_thread->control.stop_bpstat
4074 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4075 stop_pc, ecs->ptid, &ecs->ws);
4077 /* Note that this may be referenced from inside
4078 bpstat_stop_status above, through inferior_has_execd. */
4079 xfree (ecs->ws.value.execd_pathname);
4080 ecs->ws.value.execd_pathname = NULL;
4082 /* If no catchpoint triggered for this, then keep going. */
4083 if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
4085 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4089 process_event_stop_test (ecs);
4092 /* Be careful not to try to gather much state about a thread
4093 that's in a syscall. It's frequently a losing proposition. */
4094 case TARGET_WAITKIND_SYSCALL_ENTRY:
4096 fprintf_unfiltered (gdb_stdlog,
4097 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
4098 /* Getting the current syscall number. */
4099 if (handle_syscall_event (ecs) == 0)
4100 process_event_stop_test (ecs);
4103 /* Before examining the threads further, step this thread to
4104 get it entirely out of the syscall. (We get notice of the
4105 event when the thread is just on the verge of exiting a
4106 syscall. Stepping one instruction seems to get it back
4108 case TARGET_WAITKIND_SYSCALL_RETURN:
4110 fprintf_unfiltered (gdb_stdlog,
4111 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
4112 if (handle_syscall_event (ecs) == 0)
4113 process_event_stop_test (ecs);
4116 case TARGET_WAITKIND_STOPPED:
4118 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
4119 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
4120 handle_signal_stop (ecs);
4123 case TARGET_WAITKIND_NO_HISTORY:
4125 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
4126 /* Reverse execution: target ran out of history info. */
4128 delete_just_stopped_threads_single_step_breakpoints ();
4129 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4130 observer_notify_no_history ();
4136 /* Come here when the program has stopped with a signal. */
4139 handle_signal_stop (struct execution_control_state *ecs)
4141 struct frame_info *frame;
4142 struct gdbarch *gdbarch;
4143 int stopped_by_watchpoint;
4144 enum stop_kind stop_soon;
4147 gdb_assert (ecs->ws.kind == TARGET_WAITKIND_STOPPED);
4149 /* Do we need to clean up the state of a thread that has
4150 completed a displaced single-step? (Doing so usually affects
4151 the PC, so do it here, before we set stop_pc.) */
4152 displaced_step_fixup (ecs->ptid,
4153 ecs->event_thread->suspend.stop_signal);
4155 /* If we either finished a single-step or hit a breakpoint, but
4156 the user wanted this thread to be stopped, pretend we got a
4157 SIG0 (generic unsignaled stop). */
4158 if (ecs->event_thread->stop_requested
4159 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
4160 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4162 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4166 struct regcache *regcache = get_thread_regcache (ecs->ptid);
4167 struct gdbarch *gdbarch = get_regcache_arch (regcache);
4168 struct cleanup *old_chain = save_inferior_ptid ();
4170 inferior_ptid = ecs->ptid;
4172 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
4173 paddress (gdbarch, stop_pc));
4174 if (target_stopped_by_watchpoint ())
4178 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
4180 if (target_stopped_data_address (¤t_target, &addr))
4181 fprintf_unfiltered (gdb_stdlog,
4182 "infrun: stopped data address = %s\n",
4183 paddress (gdbarch, addr));
4185 fprintf_unfiltered (gdb_stdlog,
4186 "infrun: (no data address available)\n");
4189 do_cleanups (old_chain);
4192 /* This is originated from start_remote(), start_inferior() and
4193 shared libraries hook functions. */
4194 stop_soon = get_inferior_stop_soon (ecs->ptid);
4195 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
4197 if (!ptid_equal (ecs->ptid, inferior_ptid))
4198 context_switch (ecs->ptid);
4200 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
4201 stop_print_frame = 1;
4206 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4209 if (!ptid_equal (ecs->ptid, inferior_ptid))
4210 context_switch (ecs->ptid);
4212 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
4213 stop_print_frame = 0;
4218 /* This originates from attach_command(). We need to overwrite
4219 the stop_signal here, because some kernels don't ignore a
4220 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4221 See more comments in inferior.h. On the other hand, if we
4222 get a non-SIGSTOP, report it to the user - assume the backend
4223 will handle the SIGSTOP if it should show up later.
4225 Also consider that the attach is complete when we see a
4226 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4227 target extended-remote report it instead of a SIGSTOP
4228 (e.g. gdbserver). We already rely on SIGTRAP being our
4229 signal, so this is no exception.
4231 Also consider that the attach is complete when we see a
4232 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4233 the target to stop all threads of the inferior, in case the
4234 low level attach operation doesn't stop them implicitly. If
4235 they weren't stopped implicitly, then the stub will report a
4236 GDB_SIGNAL_0, meaning: stopped for no particular reason
4237 other than GDB's request. */
4238 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
4239 && (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_STOP
4240 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4241 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_0))
4243 stop_print_frame = 1;
4245 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4249 /* See if something interesting happened to the non-current thread. If
4250 so, then switch to that thread. */
4251 if (!ptid_equal (ecs->ptid, inferior_ptid))
4254 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
4256 context_switch (ecs->ptid);
4258 if (deprecated_context_hook)
4259 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
4262 /* At this point, get hold of the now-current thread's frame. */
4263 frame = get_current_frame ();
4264 gdbarch = get_frame_arch (frame);
4266 /* Pull the single step breakpoints out of the target. */
4267 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
4269 struct regcache *regcache;
4270 struct address_space *aspace;
4273 regcache = get_thread_regcache (ecs->ptid);
4274 aspace = get_regcache_aspace (regcache);
4275 pc = regcache_read_pc (regcache);
4277 /* However, before doing so, if this single-step breakpoint was
4278 actually for another thread, set this thread up for moving
4280 if (!thread_has_single_step_breakpoint_here (ecs->event_thread,
4283 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4287 fprintf_unfiltered (gdb_stdlog,
4288 "infrun: [%s] hit another thread's "
4289 "single-step breakpoint\n",
4290 target_pid_to_str (ecs->ptid));
4292 ecs->hit_singlestep_breakpoint = 1;
4299 fprintf_unfiltered (gdb_stdlog,
4300 "infrun: [%s] hit its "
4301 "single-step breakpoint\n",
4302 target_pid_to_str (ecs->ptid));
4306 delete_just_stopped_threads_single_step_breakpoints ();
4308 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4309 && ecs->event_thread->control.trap_expected
4310 && ecs->event_thread->stepping_over_watchpoint)
4311 stopped_by_watchpoint = 0;
4313 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
4315 /* If necessary, step over this watchpoint. We'll be back to display
4317 if (stopped_by_watchpoint
4318 && (target_have_steppable_watchpoint
4319 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
4321 /* At this point, we are stopped at an instruction which has
4322 attempted to write to a piece of memory under control of
4323 a watchpoint. The instruction hasn't actually executed
4324 yet. If we were to evaluate the watchpoint expression
4325 now, we would get the old value, and therefore no change
4326 would seem to have occurred.
4328 In order to make watchpoints work `right', we really need
4329 to complete the memory write, and then evaluate the
4330 watchpoint expression. We do this by single-stepping the
4333 It may not be necessary to disable the watchpoint to step over
4334 it. For example, the PA can (with some kernel cooperation)
4335 single step over a watchpoint without disabling the watchpoint.
4337 It is far more common to need to disable a watchpoint to step
4338 the inferior over it. If we have non-steppable watchpoints,
4339 we must disable the current watchpoint; it's simplest to
4340 disable all watchpoints.
4342 Any breakpoint at PC must also be stepped over -- if there's
4343 one, it will have already triggered before the watchpoint
4344 triggered, and we either already reported it to the user, or
4345 it didn't cause a stop and we called keep_going. In either
4346 case, if there was a breakpoint at PC, we must be trying to
4348 ecs->event_thread->stepping_over_watchpoint = 1;
4353 ecs->event_thread->stepping_over_breakpoint = 0;
4354 ecs->event_thread->stepping_over_watchpoint = 0;
4355 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
4356 ecs->event_thread->control.stop_step = 0;
4357 stop_print_frame = 1;
4358 stopped_by_random_signal = 0;
4360 /* Hide inlined functions starting here, unless we just performed stepi or
4361 nexti. After stepi and nexti, always show the innermost frame (not any
4362 inline function call sites). */
4363 if (ecs->event_thread->control.step_range_end != 1)
4365 struct address_space *aspace =
4366 get_regcache_aspace (get_thread_regcache (ecs->ptid));
4368 /* skip_inline_frames is expensive, so we avoid it if we can
4369 determine that the address is one where functions cannot have
4370 been inlined. This improves performance with inferiors that
4371 load a lot of shared libraries, because the solib event
4372 breakpoint is defined as the address of a function (i.e. not
4373 inline). Note that we have to check the previous PC as well
4374 as the current one to catch cases when we have just
4375 single-stepped off a breakpoint prior to reinstating it.
4376 Note that we're assuming that the code we single-step to is
4377 not inline, but that's not definitive: there's nothing
4378 preventing the event breakpoint function from containing
4379 inlined code, and the single-step ending up there. If the
4380 user had set a breakpoint on that inlined code, the missing
4381 skip_inline_frames call would break things. Fortunately
4382 that's an extremely unlikely scenario. */
4383 if (!pc_at_non_inline_function (aspace, stop_pc, &ecs->ws)
4384 && !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4385 && ecs->event_thread->control.trap_expected
4386 && pc_at_non_inline_function (aspace,
4387 ecs->event_thread->prev_pc,
4390 skip_inline_frames (ecs->ptid);
4392 /* Re-fetch current thread's frame in case that invalidated
4394 frame = get_current_frame ();
4395 gdbarch = get_frame_arch (frame);
4399 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4400 && ecs->event_thread->control.trap_expected
4401 && gdbarch_single_step_through_delay_p (gdbarch)
4402 && currently_stepping (ecs->event_thread))
4404 /* We're trying to step off a breakpoint. Turns out that we're
4405 also on an instruction that needs to be stepped multiple
4406 times before it's been fully executing. E.g., architectures
4407 with a delay slot. It needs to be stepped twice, once for
4408 the instruction and once for the delay slot. */
4409 int step_through_delay
4410 = gdbarch_single_step_through_delay (gdbarch, frame);
4412 if (debug_infrun && step_through_delay)
4413 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
4414 if (ecs->event_thread->control.step_range_end == 0
4415 && step_through_delay)
4417 /* The user issued a continue when stopped at a breakpoint.
4418 Set up for another trap and get out of here. */
4419 ecs->event_thread->stepping_over_breakpoint = 1;
4423 else if (step_through_delay)
4425 /* The user issued a step when stopped at a breakpoint.
4426 Maybe we should stop, maybe we should not - the delay
4427 slot *might* correspond to a line of source. In any
4428 case, don't decide that here, just set
4429 ecs->stepping_over_breakpoint, making sure we
4430 single-step again before breakpoints are re-inserted. */
4431 ecs->event_thread->stepping_over_breakpoint = 1;
4435 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4436 handles this event. */
4437 ecs->event_thread->control.stop_bpstat
4438 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4439 stop_pc, ecs->ptid, &ecs->ws);
4441 /* Following in case break condition called a
4443 stop_print_frame = 1;
4445 /* This is where we handle "moribund" watchpoints. Unlike
4446 software breakpoints traps, hardware watchpoint traps are
4447 always distinguishable from random traps. If no high-level
4448 watchpoint is associated with the reported stop data address
4449 anymore, then the bpstat does not explain the signal ---
4450 simply make sure to ignore it if `stopped_by_watchpoint' is
4454 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4455 && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4457 && stopped_by_watchpoint)
4458 fprintf_unfiltered (gdb_stdlog,
4459 "infrun: no user watchpoint explains "
4460 "watchpoint SIGTRAP, ignoring\n");
4462 /* NOTE: cagney/2003-03-29: These checks for a random signal
4463 at one stage in the past included checks for an inferior
4464 function call's call dummy's return breakpoint. The original
4465 comment, that went with the test, read:
4467 ``End of a stack dummy. Some systems (e.g. Sony news) give
4468 another signal besides SIGTRAP, so check here as well as
4471 If someone ever tries to get call dummys on a
4472 non-executable stack to work (where the target would stop
4473 with something like a SIGSEGV), then those tests might need
4474 to be re-instated. Given, however, that the tests were only
4475 enabled when momentary breakpoints were not being used, I
4476 suspect that it won't be the case.
4478 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4479 be necessary for call dummies on a non-executable stack on
4482 /* See if the breakpoints module can explain the signal. */
4484 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4485 ecs->event_thread->suspend.stop_signal);
4487 /* If not, perhaps stepping/nexting can. */
4489 random_signal = !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4490 && currently_stepping (ecs->event_thread));
4492 /* Perhaps the thread hit a single-step breakpoint of _another_
4493 thread. Single-step breakpoints are transparent to the
4494 breakpoints module. */
4496 random_signal = !ecs->hit_singlestep_breakpoint;
4498 /* No? Perhaps we got a moribund watchpoint. */
4500 random_signal = !stopped_by_watchpoint;
4502 /* For the program's own signals, act according to
4503 the signal handling tables. */
4507 /* Signal not for debugging purposes. */
4508 struct inferior *inf = find_inferior_ptid (ecs->ptid);
4509 enum gdb_signal stop_signal = ecs->event_thread->suspend.stop_signal;
4512 fprintf_unfiltered (gdb_stdlog, "infrun: random signal (%s)\n",
4513 gdb_signal_to_symbol_string (stop_signal));
4515 stopped_by_random_signal = 1;
4517 /* Always stop on signals if we're either just gaining control
4518 of the program, or the user explicitly requested this thread
4519 to remain stopped. */
4520 if (stop_soon != NO_STOP_QUIETLY
4521 || ecs->event_thread->stop_requested
4523 && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
4529 /* Notify observers the signal has "handle print" set. Note we
4530 returned early above if stopping; normal_stop handles the
4531 printing in that case. */
4532 if (signal_print[ecs->event_thread->suspend.stop_signal])
4534 /* The signal table tells us to print about this signal. */
4535 target_terminal_ours_for_output ();
4536 observer_notify_signal_received (ecs->event_thread->suspend.stop_signal);
4537 target_terminal_inferior ();
4540 /* Clear the signal if it should not be passed. */
4541 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
4542 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4544 if (ecs->event_thread->prev_pc == stop_pc
4545 && ecs->event_thread->control.trap_expected
4546 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4548 /* We were just starting a new sequence, attempting to
4549 single-step off of a breakpoint and expecting a SIGTRAP.
4550 Instead this signal arrives. This signal will take us out
4551 of the stepping range so GDB needs to remember to, when
4552 the signal handler returns, resume stepping off that
4554 /* To simplify things, "continue" is forced to use the same
4555 code paths as single-step - set a breakpoint at the
4556 signal return address and then, once hit, step off that
4559 fprintf_unfiltered (gdb_stdlog,
4560 "infrun: signal arrived while stepping over "
4563 insert_hp_step_resume_breakpoint_at_frame (frame);
4564 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4565 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4566 ecs->event_thread->control.trap_expected = 0;
4568 /* If we were nexting/stepping some other thread, switch to
4569 it, so that we don't continue it, losing control. */
4570 if (!switch_back_to_stepped_thread (ecs))
4575 if (ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_0
4576 && (pc_in_thread_step_range (stop_pc, ecs->event_thread)
4577 || ecs->event_thread->control.step_range_end == 1)
4578 && frame_id_eq (get_stack_frame_id (frame),
4579 ecs->event_thread->control.step_stack_frame_id)
4580 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4582 /* The inferior is about to take a signal that will take it
4583 out of the single step range. Set a breakpoint at the
4584 current PC (which is presumably where the signal handler
4585 will eventually return) and then allow the inferior to
4588 Note that this is only needed for a signal delivered
4589 while in the single-step range. Nested signals aren't a
4590 problem as they eventually all return. */
4592 fprintf_unfiltered (gdb_stdlog,
4593 "infrun: signal may take us out of "
4594 "single-step range\n");
4596 insert_hp_step_resume_breakpoint_at_frame (frame);
4597 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4598 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4599 ecs->event_thread->control.trap_expected = 0;
4604 /* Note: step_resume_breakpoint may be non-NULL. This occures
4605 when either there's a nested signal, or when there's a
4606 pending signal enabled just as the signal handler returns
4607 (leaving the inferior at the step-resume-breakpoint without
4608 actually executing it). Either way continue until the
4609 breakpoint is really hit. */
4611 if (!switch_back_to_stepped_thread (ecs))
4614 fprintf_unfiltered (gdb_stdlog,
4615 "infrun: random signal, keep going\n");
4622 process_event_stop_test (ecs);
4625 /* Come here when we've got some debug event / signal we can explain
4626 (IOW, not a random signal), and test whether it should cause a
4627 stop, or whether we should resume the inferior (transparently).
4628 E.g., could be a breakpoint whose condition evaluates false; we
4629 could be still stepping within the line; etc. */
4632 process_event_stop_test (struct execution_control_state *ecs)
4634 struct symtab_and_line stop_pc_sal;
4635 struct frame_info *frame;
4636 struct gdbarch *gdbarch;
4637 CORE_ADDR jmp_buf_pc;
4638 struct bpstat_what what;
4640 /* Handle cases caused by hitting a breakpoint. */
4642 frame = get_current_frame ();
4643 gdbarch = get_frame_arch (frame);
4645 what = bpstat_what (ecs->event_thread->control.stop_bpstat);
4647 if (what.call_dummy)
4649 stop_stack_dummy = what.call_dummy;
4652 /* If we hit an internal event that triggers symbol changes, the
4653 current frame will be invalidated within bpstat_what (e.g., if we
4654 hit an internal solib event). Re-fetch it. */
4655 frame = get_current_frame ();
4656 gdbarch = get_frame_arch (frame);
4658 switch (what.main_action)
4660 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
4661 /* If we hit the breakpoint at longjmp while stepping, we
4662 install a momentary breakpoint at the target of the
4666 fprintf_unfiltered (gdb_stdlog,
4667 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4669 ecs->event_thread->stepping_over_breakpoint = 1;
4671 if (what.is_longjmp)
4673 struct value *arg_value;
4675 /* If we set the longjmp breakpoint via a SystemTap probe,
4676 then use it to extract the arguments. The destination PC
4677 is the third argument to the probe. */
4678 arg_value = probe_safe_evaluate_at_pc (frame, 2);
4681 jmp_buf_pc = value_as_address (arg_value);
4682 jmp_buf_pc = gdbarch_addr_bits_remove (gdbarch, jmp_buf_pc);
4684 else if (!gdbarch_get_longjmp_target_p (gdbarch)
4685 || !gdbarch_get_longjmp_target (gdbarch,
4686 frame, &jmp_buf_pc))
4689 fprintf_unfiltered (gdb_stdlog,
4690 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4691 "(!gdbarch_get_longjmp_target)\n");
4696 /* Insert a breakpoint at resume address. */
4697 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4700 check_exception_resume (ecs, frame);
4704 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4706 struct frame_info *init_frame;
4708 /* There are several cases to consider.
4710 1. The initiating frame no longer exists. In this case we
4711 must stop, because the exception or longjmp has gone too
4714 2. The initiating frame exists, and is the same as the
4715 current frame. We stop, because the exception or longjmp
4718 3. The initiating frame exists and is different from the
4719 current frame. This means the exception or longjmp has
4720 been caught beneath the initiating frame, so keep going.
4722 4. longjmp breakpoint has been placed just to protect
4723 against stale dummy frames and user is not interested in
4724 stopping around longjmps. */
4727 fprintf_unfiltered (gdb_stdlog,
4728 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4730 gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
4732 delete_exception_resume_breakpoint (ecs->event_thread);
4734 if (what.is_longjmp)
4736 check_longjmp_breakpoint_for_call_dummy (ecs->event_thread);
4738 if (!frame_id_p (ecs->event_thread->initiating_frame))
4746 init_frame = frame_find_by_id (ecs->event_thread->initiating_frame);
4750 struct frame_id current_id
4751 = get_frame_id (get_current_frame ());
4752 if (frame_id_eq (current_id,
4753 ecs->event_thread->initiating_frame))
4755 /* Case 2. Fall through. */
4765 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4767 delete_step_resume_breakpoint (ecs->event_thread);
4769 end_stepping_range (ecs);
4773 case BPSTAT_WHAT_SINGLE:
4775 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
4776 ecs->event_thread->stepping_over_breakpoint = 1;
4777 /* Still need to check other stuff, at least the case where we
4778 are stepping and step out of the right range. */
4781 case BPSTAT_WHAT_STEP_RESUME:
4783 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4785 delete_step_resume_breakpoint (ecs->event_thread);
4786 if (ecs->event_thread->control.proceed_to_finish
4787 && execution_direction == EXEC_REVERSE)
4789 struct thread_info *tp = ecs->event_thread;
4791 /* We are finishing a function in reverse, and just hit the
4792 step-resume breakpoint at the start address of the
4793 function, and we're almost there -- just need to back up
4794 by one more single-step, which should take us back to the
4796 tp->control.step_range_start = tp->control.step_range_end = 1;
4800 fill_in_stop_func (gdbarch, ecs);
4801 if (stop_pc == ecs->stop_func_start
4802 && execution_direction == EXEC_REVERSE)
4804 /* We are stepping over a function call in reverse, and just
4805 hit the step-resume breakpoint at the start address of
4806 the function. Go back to single-stepping, which should
4807 take us back to the function call. */
4808 ecs->event_thread->stepping_over_breakpoint = 1;
4814 case BPSTAT_WHAT_STOP_NOISY:
4816 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4817 stop_print_frame = 1;
4819 /* Assume the thread stopped for a breapoint. We'll still check
4820 whether a/the breakpoint is there when the thread is next
4822 ecs->event_thread->stepping_over_breakpoint = 1;
4827 case BPSTAT_WHAT_STOP_SILENT:
4829 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4830 stop_print_frame = 0;
4832 /* Assume the thread stopped for a breapoint. We'll still check
4833 whether a/the breakpoint is there when the thread is next
4835 ecs->event_thread->stepping_over_breakpoint = 1;
4839 case BPSTAT_WHAT_HP_STEP_RESUME:
4841 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4843 delete_step_resume_breakpoint (ecs->event_thread);
4844 if (ecs->event_thread->step_after_step_resume_breakpoint)
4846 /* Back when the step-resume breakpoint was inserted, we
4847 were trying to single-step off a breakpoint. Go back to
4849 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4850 ecs->event_thread->stepping_over_breakpoint = 1;
4856 case BPSTAT_WHAT_KEEP_CHECKING:
4860 /* If we stepped a permanent breakpoint and we had a high priority
4861 step-resume breakpoint for the address we stepped, but we didn't
4862 hit it, then we must have stepped into the signal handler. The
4863 step-resume was only necessary to catch the case of _not_
4864 stepping into the handler, so delete it, and fall through to
4865 checking whether the step finished. */
4866 if (ecs->event_thread->stepped_breakpoint)
4868 struct breakpoint *sr_bp
4869 = ecs->event_thread->control.step_resume_breakpoint;
4871 if (sr_bp->loc->permanent
4872 && sr_bp->type == bp_hp_step_resume
4873 && sr_bp->loc->address == ecs->event_thread->prev_pc)
4876 fprintf_unfiltered (gdb_stdlog,
4877 "infrun: stepped permanent breakpoint, stopped in "
4879 delete_step_resume_breakpoint (ecs->event_thread);
4880 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4884 /* We come here if we hit a breakpoint but should not stop for it.
4885 Possibly we also were stepping and should stop for that. So fall
4886 through and test for stepping. But, if not stepping, do not
4889 /* In all-stop mode, if we're currently stepping but have stopped in
4890 some other thread, we need to switch back to the stepped thread. */
4891 if (switch_back_to_stepped_thread (ecs))
4894 if (ecs->event_thread->control.step_resume_breakpoint)
4897 fprintf_unfiltered (gdb_stdlog,
4898 "infrun: step-resume breakpoint is inserted\n");
4900 /* Having a step-resume breakpoint overrides anything
4901 else having to do with stepping commands until
4902 that breakpoint is reached. */
4907 if (ecs->event_thread->control.step_range_end == 0)
4910 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
4911 /* Likewise if we aren't even stepping. */
4916 /* Re-fetch current thread's frame in case the code above caused
4917 the frame cache to be re-initialized, making our FRAME variable
4918 a dangling pointer. */
4919 frame = get_current_frame ();
4920 gdbarch = get_frame_arch (frame);
4921 fill_in_stop_func (gdbarch, ecs);
4923 /* If stepping through a line, keep going if still within it.
4925 Note that step_range_end is the address of the first instruction
4926 beyond the step range, and NOT the address of the last instruction
4929 Note also that during reverse execution, we may be stepping
4930 through a function epilogue and therefore must detect when
4931 the current-frame changes in the middle of a line. */
4933 if (pc_in_thread_step_range (stop_pc, ecs->event_thread)
4934 && (execution_direction != EXEC_REVERSE
4935 || frame_id_eq (get_frame_id (frame),
4936 ecs->event_thread->control.step_frame_id)))
4940 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
4941 paddress (gdbarch, ecs->event_thread->control.step_range_start),
4942 paddress (gdbarch, ecs->event_thread->control.step_range_end));
4944 /* Tentatively re-enable range stepping; `resume' disables it if
4945 necessary (e.g., if we're stepping over a breakpoint or we
4946 have software watchpoints). */
4947 ecs->event_thread->control.may_range_step = 1;
4949 /* When stepping backward, stop at beginning of line range
4950 (unless it's the function entry point, in which case
4951 keep going back to the call point). */
4952 if (stop_pc == ecs->event_thread->control.step_range_start
4953 && stop_pc != ecs->stop_func_start
4954 && execution_direction == EXEC_REVERSE)
4955 end_stepping_range (ecs);
4962 /* We stepped out of the stepping range. */
4964 /* If we are stepping at the source level and entered the runtime
4965 loader dynamic symbol resolution code...
4967 EXEC_FORWARD: we keep on single stepping until we exit the run
4968 time loader code and reach the callee's address.
4970 EXEC_REVERSE: we've already executed the callee (backward), and
4971 the runtime loader code is handled just like any other
4972 undebuggable function call. Now we need only keep stepping
4973 backward through the trampoline code, and that's handled further
4974 down, so there is nothing for us to do here. */
4976 if (execution_direction != EXEC_REVERSE
4977 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4978 && in_solib_dynsym_resolve_code (stop_pc))
4980 CORE_ADDR pc_after_resolver =
4981 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
4984 fprintf_unfiltered (gdb_stdlog,
4985 "infrun: stepped into dynsym resolve code\n");
4987 if (pc_after_resolver)
4989 /* Set up a step-resume breakpoint at the address
4990 indicated by SKIP_SOLIB_RESOLVER. */
4991 struct symtab_and_line sr_sal;
4994 sr_sal.pc = pc_after_resolver;
4995 sr_sal.pspace = get_frame_program_space (frame);
4997 insert_step_resume_breakpoint_at_sal (gdbarch,
4998 sr_sal, null_frame_id);
5005 if (ecs->event_thread->control.step_range_end != 1
5006 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5007 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5008 && get_frame_type (frame) == SIGTRAMP_FRAME)
5011 fprintf_unfiltered (gdb_stdlog,
5012 "infrun: stepped into signal trampoline\n");
5013 /* The inferior, while doing a "step" or "next", has ended up in
5014 a signal trampoline (either by a signal being delivered or by
5015 the signal handler returning). Just single-step until the
5016 inferior leaves the trampoline (either by calling the handler
5022 /* If we're in the return path from a shared library trampoline,
5023 we want to proceed through the trampoline when stepping. */
5024 /* macro/2012-04-25: This needs to come before the subroutine
5025 call check below as on some targets return trampolines look
5026 like subroutine calls (MIPS16 return thunks). */
5027 if (gdbarch_in_solib_return_trampoline (gdbarch,
5028 stop_pc, ecs->stop_func_name)
5029 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
5031 /* Determine where this trampoline returns. */
5032 CORE_ADDR real_stop_pc;
5034 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
5037 fprintf_unfiltered (gdb_stdlog,
5038 "infrun: stepped into solib return tramp\n");
5040 /* Only proceed through if we know where it's going. */
5043 /* And put the step-breakpoint there and go until there. */
5044 struct symtab_and_line sr_sal;
5046 init_sal (&sr_sal); /* initialize to zeroes */
5047 sr_sal.pc = real_stop_pc;
5048 sr_sal.section = find_pc_overlay (sr_sal.pc);
5049 sr_sal.pspace = get_frame_program_space (frame);
5051 /* Do not specify what the fp should be when we stop since
5052 on some machines the prologue is where the new fp value
5054 insert_step_resume_breakpoint_at_sal (gdbarch,
5055 sr_sal, null_frame_id);
5057 /* Restart without fiddling with the step ranges or
5064 /* Check for subroutine calls. The check for the current frame
5065 equalling the step ID is not necessary - the check of the
5066 previous frame's ID is sufficient - but it is a common case and
5067 cheaper than checking the previous frame's ID.
5069 NOTE: frame_id_eq will never report two invalid frame IDs as
5070 being equal, so to get into this block, both the current and
5071 previous frame must have valid frame IDs. */
5072 /* The outer_frame_id check is a heuristic to detect stepping
5073 through startup code. If we step over an instruction which
5074 sets the stack pointer from an invalid value to a valid value,
5075 we may detect that as a subroutine call from the mythical
5076 "outermost" function. This could be fixed by marking
5077 outermost frames as !stack_p,code_p,special_p. Then the
5078 initial outermost frame, before sp was valid, would
5079 have code_addr == &_start. See the comment in frame_id_eq
5081 if (!frame_id_eq (get_stack_frame_id (frame),
5082 ecs->event_thread->control.step_stack_frame_id)
5083 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
5084 ecs->event_thread->control.step_stack_frame_id)
5085 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
5087 || step_start_function != find_pc_function (stop_pc))))
5089 CORE_ADDR real_stop_pc;
5092 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
5094 if (ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
5096 /* I presume that step_over_calls is only 0 when we're
5097 supposed to be stepping at the assembly language level
5098 ("stepi"). Just stop. */
5099 /* And this works the same backward as frontward. MVS */
5100 end_stepping_range (ecs);
5104 /* Reverse stepping through solib trampolines. */
5106 if (execution_direction == EXEC_REVERSE
5107 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
5108 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
5109 || (ecs->stop_func_start == 0
5110 && in_solib_dynsym_resolve_code (stop_pc))))
5112 /* Any solib trampoline code can be handled in reverse
5113 by simply continuing to single-step. We have already
5114 executed the solib function (backwards), and a few
5115 steps will take us back through the trampoline to the
5121 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5123 /* We're doing a "next".
5125 Normal (forward) execution: set a breakpoint at the
5126 callee's return address (the address at which the caller
5129 Reverse (backward) execution. set the step-resume
5130 breakpoint at the start of the function that we just
5131 stepped into (backwards), and continue to there. When we
5132 get there, we'll need to single-step back to the caller. */
5134 if (execution_direction == EXEC_REVERSE)
5136 /* If we're already at the start of the function, we've either
5137 just stepped backward into a single instruction function,
5138 or stepped back out of a signal handler to the first instruction
5139 of the function. Just keep going, which will single-step back
5141 if (ecs->stop_func_start != stop_pc && ecs->stop_func_start != 0)
5143 struct symtab_and_line sr_sal;
5145 /* Normal function call return (static or dynamic). */
5147 sr_sal.pc = ecs->stop_func_start;
5148 sr_sal.pspace = get_frame_program_space (frame);
5149 insert_step_resume_breakpoint_at_sal (gdbarch,
5150 sr_sal, null_frame_id);
5154 insert_step_resume_breakpoint_at_caller (frame);
5160 /* If we are in a function call trampoline (a stub between the
5161 calling routine and the real function), locate the real
5162 function. That's what tells us (a) whether we want to step
5163 into it at all, and (b) what prologue we want to run to the
5164 end of, if we do step into it. */
5165 real_stop_pc = skip_language_trampoline (frame, stop_pc);
5166 if (real_stop_pc == 0)
5167 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
5168 if (real_stop_pc != 0)
5169 ecs->stop_func_start = real_stop_pc;
5171 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
5173 struct symtab_and_line sr_sal;
5176 sr_sal.pc = ecs->stop_func_start;
5177 sr_sal.pspace = get_frame_program_space (frame);
5179 insert_step_resume_breakpoint_at_sal (gdbarch,
5180 sr_sal, null_frame_id);
5185 /* If we have line number information for the function we are
5186 thinking of stepping into and the function isn't on the skip
5189 If there are several symtabs at that PC (e.g. with include
5190 files), just want to know whether *any* of them have line
5191 numbers. find_pc_line handles this. */
5193 struct symtab_and_line tmp_sal;
5195 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
5196 if (tmp_sal.line != 0
5197 && !function_name_is_marked_for_skip (ecs->stop_func_name,
5200 if (execution_direction == EXEC_REVERSE)
5201 handle_step_into_function_backward (gdbarch, ecs);
5203 handle_step_into_function (gdbarch, ecs);
5208 /* If we have no line number and the step-stop-if-no-debug is
5209 set, we stop the step so that the user has a chance to switch
5210 in assembly mode. */
5211 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5212 && step_stop_if_no_debug)
5214 end_stepping_range (ecs);
5218 if (execution_direction == EXEC_REVERSE)
5220 /* If we're already at the start of the function, we've either just
5221 stepped backward into a single instruction function without line
5222 number info, or stepped back out of a signal handler to the first
5223 instruction of the function without line number info. Just keep
5224 going, which will single-step back to the caller. */
5225 if (ecs->stop_func_start != stop_pc)
5227 /* Set a breakpoint at callee's start address.
5228 From there we can step once and be back in the caller. */
5229 struct symtab_and_line sr_sal;
5232 sr_sal.pc = ecs->stop_func_start;
5233 sr_sal.pspace = get_frame_program_space (frame);
5234 insert_step_resume_breakpoint_at_sal (gdbarch,
5235 sr_sal, null_frame_id);
5239 /* Set a breakpoint at callee's return address (the address
5240 at which the caller will resume). */
5241 insert_step_resume_breakpoint_at_caller (frame);
5247 /* Reverse stepping through solib trampolines. */
5249 if (execution_direction == EXEC_REVERSE
5250 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
5252 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
5253 || (ecs->stop_func_start == 0
5254 && in_solib_dynsym_resolve_code (stop_pc)))
5256 /* Any solib trampoline code can be handled in reverse
5257 by simply continuing to single-step. We have already
5258 executed the solib function (backwards), and a few
5259 steps will take us back through the trampoline to the
5264 else if (in_solib_dynsym_resolve_code (stop_pc))
5266 /* Stepped backward into the solib dynsym resolver.
5267 Set a breakpoint at its start and continue, then
5268 one more step will take us out. */
5269 struct symtab_and_line sr_sal;
5272 sr_sal.pc = ecs->stop_func_start;
5273 sr_sal.pspace = get_frame_program_space (frame);
5274 insert_step_resume_breakpoint_at_sal (gdbarch,
5275 sr_sal, null_frame_id);
5281 stop_pc_sal = find_pc_line (stop_pc, 0);
5283 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5284 the trampoline processing logic, however, there are some trampolines
5285 that have no names, so we should do trampoline handling first. */
5286 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5287 && ecs->stop_func_name == NULL
5288 && stop_pc_sal.line == 0)
5291 fprintf_unfiltered (gdb_stdlog,
5292 "infrun: stepped into undebuggable function\n");
5294 /* The inferior just stepped into, or returned to, an
5295 undebuggable function (where there is no debugging information
5296 and no line number corresponding to the address where the
5297 inferior stopped). Since we want to skip this kind of code,
5298 we keep going until the inferior returns from this
5299 function - unless the user has asked us not to (via
5300 set step-mode) or we no longer know how to get back
5301 to the call site. */
5302 if (step_stop_if_no_debug
5303 || !frame_id_p (frame_unwind_caller_id (frame)))
5305 /* If we have no line number and the step-stop-if-no-debug
5306 is set, we stop the step so that the user has a chance to
5307 switch in assembly mode. */
5308 end_stepping_range (ecs);
5313 /* Set a breakpoint at callee's return address (the address
5314 at which the caller will resume). */
5315 insert_step_resume_breakpoint_at_caller (frame);
5321 if (ecs->event_thread->control.step_range_end == 1)
5323 /* It is stepi or nexti. We always want to stop stepping after
5326 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
5327 end_stepping_range (ecs);
5331 if (stop_pc_sal.line == 0)
5333 /* We have no line number information. That means to stop
5334 stepping (does this always happen right after one instruction,
5335 when we do "s" in a function with no line numbers,
5336 or can this happen as a result of a return or longjmp?). */
5338 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
5339 end_stepping_range (ecs);
5343 /* Look for "calls" to inlined functions, part one. If the inline
5344 frame machinery detected some skipped call sites, we have entered
5345 a new inline function. */
5347 if (frame_id_eq (get_frame_id (get_current_frame ()),
5348 ecs->event_thread->control.step_frame_id)
5349 && inline_skipped_frames (ecs->ptid))
5351 struct symtab_and_line call_sal;
5354 fprintf_unfiltered (gdb_stdlog,
5355 "infrun: stepped into inlined function\n");
5357 find_frame_sal (get_current_frame (), &call_sal);
5359 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
5361 /* For "step", we're going to stop. But if the call site
5362 for this inlined function is on the same source line as
5363 we were previously stepping, go down into the function
5364 first. Otherwise stop at the call site. */
5366 if (call_sal.line == ecs->event_thread->current_line
5367 && call_sal.symtab == ecs->event_thread->current_symtab)
5368 step_into_inline_frame (ecs->ptid);
5370 end_stepping_range (ecs);
5375 /* For "next", we should stop at the call site if it is on a
5376 different source line. Otherwise continue through the
5377 inlined function. */
5378 if (call_sal.line == ecs->event_thread->current_line
5379 && call_sal.symtab == ecs->event_thread->current_symtab)
5382 end_stepping_range (ecs);
5387 /* Look for "calls" to inlined functions, part two. If we are still
5388 in the same real function we were stepping through, but we have
5389 to go further up to find the exact frame ID, we are stepping
5390 through a more inlined call beyond its call site. */
5392 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5393 && !frame_id_eq (get_frame_id (get_current_frame ()),
5394 ecs->event_thread->control.step_frame_id)
5395 && stepped_in_from (get_current_frame (),
5396 ecs->event_thread->control.step_frame_id))
5399 fprintf_unfiltered (gdb_stdlog,
5400 "infrun: stepping through inlined function\n");
5402 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5405 end_stepping_range (ecs);
5409 if ((stop_pc == stop_pc_sal.pc)
5410 && (ecs->event_thread->current_line != stop_pc_sal.line
5411 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
5413 /* We are at the start of a different line. So stop. Note that
5414 we don't stop if we step into the middle of a different line.
5415 That is said to make things like for (;;) statements work
5418 fprintf_unfiltered (gdb_stdlog,
5419 "infrun: stepped to a different line\n");
5420 end_stepping_range (ecs);
5424 /* We aren't done stepping.
5426 Optimize by setting the stepping range to the line.
5427 (We might not be in the original line, but if we entered a
5428 new line in mid-statement, we continue stepping. This makes
5429 things like for(;;) statements work better.) */
5431 ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
5432 ecs->event_thread->control.step_range_end = stop_pc_sal.end;
5433 ecs->event_thread->control.may_range_step = 1;
5434 set_step_info (frame, stop_pc_sal);
5437 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
5441 /* In all-stop mode, if we're currently stepping but have stopped in
5442 some other thread, we may need to switch back to the stepped
5443 thread. Returns true we set the inferior running, false if we left
5444 it stopped (and the event needs further processing). */
5447 switch_back_to_stepped_thread (struct execution_control_state *ecs)
5451 struct thread_info *tp;
5452 struct thread_info *stepping_thread;
5453 struct thread_info *step_over;
5455 /* If any thread is blocked on some internal breakpoint, and we
5456 simply need to step over that breakpoint to get it going
5457 again, do that first. */
5459 /* However, if we see an event for the stepping thread, then we
5460 know all other threads have been moved past their breakpoints
5461 already. Let the caller check whether the step is finished,
5462 etc., before deciding to move it past a breakpoint. */
5463 if (ecs->event_thread->control.step_range_end != 0)
5466 /* Check if the current thread is blocked on an incomplete
5467 step-over, interrupted by a random signal. */
5468 if (ecs->event_thread->control.trap_expected
5469 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
5473 fprintf_unfiltered (gdb_stdlog,
5474 "infrun: need to finish step-over of [%s]\n",
5475 target_pid_to_str (ecs->event_thread->ptid));
5481 /* Check if the current thread is blocked by a single-step
5482 breakpoint of another thread. */
5483 if (ecs->hit_singlestep_breakpoint)
5487 fprintf_unfiltered (gdb_stdlog,
5488 "infrun: need to step [%s] over single-step "
5490 target_pid_to_str (ecs->ptid));
5496 /* Otherwise, we no longer expect a trap in the current thread.
5497 Clear the trap_expected flag before switching back -- this is
5498 what keep_going does as well, if we call it. */
5499 ecs->event_thread->control.trap_expected = 0;
5501 /* Likewise, clear the signal if it should not be passed. */
5502 if (!signal_program[ecs->event_thread->suspend.stop_signal])
5503 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
5505 /* If scheduler locking applies even if not stepping, there's no
5506 need to walk over threads. Above we've checked whether the
5507 current thread is stepping. If some other thread not the
5508 event thread is stepping, then it must be that scheduler
5509 locking is not in effect. */
5510 if (schedlock_applies (0))
5513 /* Look for the stepping/nexting thread, and check if any other
5514 thread other than the stepping thread needs to start a
5515 step-over. Do all step-overs before actually proceeding with
5517 stepping_thread = NULL;
5519 ALL_NON_EXITED_THREADS (tp)
5521 /* Ignore threads of processes we're not resuming. */
5523 && ptid_get_pid (tp->ptid) != ptid_get_pid (inferior_ptid))
5526 /* When stepping over a breakpoint, we lock all threads
5527 except the one that needs to move past the breakpoint.
5528 If a non-event thread has this set, the "incomplete
5529 step-over" check above should have caught it earlier. */
5530 gdb_assert (!tp->control.trap_expected);
5532 /* Did we find the stepping thread? */
5533 if (tp->control.step_range_end)
5535 /* Yep. There should only one though. */
5536 gdb_assert (stepping_thread == NULL);
5538 /* The event thread is handled at the top, before we
5540 gdb_assert (tp != ecs->event_thread);
5542 /* If some thread other than the event thread is
5543 stepping, then scheduler locking can't be in effect,
5544 otherwise we wouldn't have resumed the current event
5545 thread in the first place. */
5546 gdb_assert (!schedlock_applies (currently_stepping (tp)));
5548 stepping_thread = tp;
5550 else if (thread_still_needs_step_over (tp))
5554 /* At the top we've returned early if the event thread
5555 is stepping. If some other thread not the event
5556 thread is stepping, then scheduler locking can't be
5557 in effect, and we can resume this thread. No need to
5558 keep looking for the stepping thread then. */
5563 if (step_over != NULL)
5568 fprintf_unfiltered (gdb_stdlog,
5569 "infrun: need to step-over [%s]\n",
5570 target_pid_to_str (tp->ptid));
5573 /* Only the stepping thread should have this set. */
5574 gdb_assert (tp->control.step_range_end == 0);
5576 ecs->ptid = tp->ptid;
5577 ecs->event_thread = tp;
5578 switch_to_thread (ecs->ptid);
5583 if (stepping_thread != NULL)
5585 struct frame_info *frame;
5586 struct gdbarch *gdbarch;
5588 tp = stepping_thread;
5590 /* If the stepping thread exited, then don't try to switch
5591 back and resume it, which could fail in several different
5592 ways depending on the target. Instead, just keep going.
5594 We can find a stepping dead thread in the thread list in
5597 - The target supports thread exit events, and when the
5598 target tries to delete the thread from the thread list,
5599 inferior_ptid pointed at the exiting thread. In such
5600 case, calling delete_thread does not really remove the
5601 thread from the list; instead, the thread is left listed,
5602 with 'exited' state.
5604 - The target's debug interface does not support thread
5605 exit events, and so we have no idea whatsoever if the
5606 previously stepping thread is still alive. For that
5607 reason, we need to synchronously query the target
5609 if (is_exited (tp->ptid)
5610 || !target_thread_alive (tp->ptid))
5613 fprintf_unfiltered (gdb_stdlog,
5614 "infrun: not switching back to "
5615 "stepped thread, it has vanished\n");
5617 delete_thread (tp->ptid);
5623 fprintf_unfiltered (gdb_stdlog,
5624 "infrun: switching back to stepped thread\n");
5626 ecs->event_thread = tp;
5627 ecs->ptid = tp->ptid;
5628 context_switch (ecs->ptid);
5630 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
5631 frame = get_current_frame ();
5632 gdbarch = get_frame_arch (frame);
5634 /* If the PC of the thread we were trying to single-step has
5635 changed, then that thread has trapped or been signaled,
5636 but the event has not been reported to GDB yet. Re-poll
5637 the target looking for this particular thread's event
5638 (i.e. temporarily enable schedlock) by:
5640 - setting a break at the current PC
5641 - resuming that particular thread, only (by setting
5644 This prevents us continuously moving the single-step
5645 breakpoint forward, one instruction at a time,
5648 if (stop_pc != tp->prev_pc)
5651 fprintf_unfiltered (gdb_stdlog,
5652 "infrun: expected thread advanced also\n");
5654 /* Clear the info of the previous step-over, as it's no
5655 longer valid. It's what keep_going would do too, if
5656 we called it. Must do this before trying to insert
5657 the sss breakpoint, otherwise if we were previously
5658 trying to step over this exact address in another
5659 thread, the breakpoint ends up not installed. */
5660 clear_step_over_info ();
5662 insert_single_step_breakpoint (get_frame_arch (frame),
5663 get_frame_address_space (frame),
5665 ecs->event_thread->control.trap_expected = 1;
5667 resume (0, GDB_SIGNAL_0);
5668 prepare_to_wait (ecs);
5673 fprintf_unfiltered (gdb_stdlog,
5674 "infrun: expected thread still "
5675 "hasn't advanced\n");
5685 /* Is thread TP in the middle of single-stepping? */
5688 currently_stepping (struct thread_info *tp)
5690 return ((tp->control.step_range_end
5691 && tp->control.step_resume_breakpoint == NULL)
5692 || tp->control.trap_expected
5693 || tp->stepped_breakpoint
5694 || bpstat_should_step ());
5697 /* Inferior has stepped into a subroutine call with source code that
5698 we should not step over. Do step to the first line of code in
5702 handle_step_into_function (struct gdbarch *gdbarch,
5703 struct execution_control_state *ecs)
5705 struct compunit_symtab *cust;
5706 struct symtab_and_line stop_func_sal, sr_sal;
5708 fill_in_stop_func (gdbarch, ecs);
5710 cust = find_pc_compunit_symtab (stop_pc);
5711 if (cust != NULL && compunit_language (cust) != language_asm)
5712 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5713 ecs->stop_func_start);
5715 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
5716 /* Use the step_resume_break to step until the end of the prologue,
5717 even if that involves jumps (as it seems to on the vax under
5719 /* If the prologue ends in the middle of a source line, continue to
5720 the end of that source line (if it is still within the function).
5721 Otherwise, just go to end of prologue. */
5722 if (stop_func_sal.end
5723 && stop_func_sal.pc != ecs->stop_func_start
5724 && stop_func_sal.end < ecs->stop_func_end)
5725 ecs->stop_func_start = stop_func_sal.end;
5727 /* Architectures which require breakpoint adjustment might not be able
5728 to place a breakpoint at the computed address. If so, the test
5729 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5730 ecs->stop_func_start to an address at which a breakpoint may be
5731 legitimately placed.
5733 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5734 made, GDB will enter an infinite loop when stepping through
5735 optimized code consisting of VLIW instructions which contain
5736 subinstructions corresponding to different source lines. On
5737 FR-V, it's not permitted to place a breakpoint on any but the
5738 first subinstruction of a VLIW instruction. When a breakpoint is
5739 set, GDB will adjust the breakpoint address to the beginning of
5740 the VLIW instruction. Thus, we need to make the corresponding
5741 adjustment here when computing the stop address. */
5743 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
5745 ecs->stop_func_start
5746 = gdbarch_adjust_breakpoint_address (gdbarch,
5747 ecs->stop_func_start);
5750 if (ecs->stop_func_start == stop_pc)
5752 /* We are already there: stop now. */
5753 end_stepping_range (ecs);
5758 /* Put the step-breakpoint there and go until there. */
5759 init_sal (&sr_sal); /* initialize to zeroes */
5760 sr_sal.pc = ecs->stop_func_start;
5761 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
5762 sr_sal.pspace = get_frame_program_space (get_current_frame ());
5764 /* Do not specify what the fp should be when we stop since on
5765 some machines the prologue is where the new fp value is
5767 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
5769 /* And make sure stepping stops right away then. */
5770 ecs->event_thread->control.step_range_end
5771 = ecs->event_thread->control.step_range_start;
5776 /* Inferior has stepped backward into a subroutine call with source
5777 code that we should not step over. Do step to the beginning of the
5778 last line of code in it. */
5781 handle_step_into_function_backward (struct gdbarch *gdbarch,
5782 struct execution_control_state *ecs)
5784 struct compunit_symtab *cust;
5785 struct symtab_and_line stop_func_sal;
5787 fill_in_stop_func (gdbarch, ecs);
5789 cust = find_pc_compunit_symtab (stop_pc);
5790 if (cust != NULL && compunit_language (cust) != language_asm)
5791 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5792 ecs->stop_func_start);
5794 stop_func_sal = find_pc_line (stop_pc, 0);
5796 /* OK, we're just going to keep stepping here. */
5797 if (stop_func_sal.pc == stop_pc)
5799 /* We're there already. Just stop stepping now. */
5800 end_stepping_range (ecs);
5804 /* Else just reset the step range and keep going.
5805 No step-resume breakpoint, they don't work for
5806 epilogues, which can have multiple entry paths. */
5807 ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5808 ecs->event_thread->control.step_range_end = stop_func_sal.end;
5814 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5815 This is used to both functions and to skip over code. */
5818 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch *gdbarch,
5819 struct symtab_and_line sr_sal,
5820 struct frame_id sr_id,
5821 enum bptype sr_type)
5823 /* There should never be more than one step-resume or longjmp-resume
5824 breakpoint per thread, so we should never be setting a new
5825 step_resume_breakpoint when one is already active. */
5826 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5827 gdb_assert (sr_type == bp_step_resume || sr_type == bp_hp_step_resume);
5830 fprintf_unfiltered (gdb_stdlog,
5831 "infrun: inserting step-resume breakpoint at %s\n",
5832 paddress (gdbarch, sr_sal.pc));
5834 inferior_thread ()->control.step_resume_breakpoint
5835 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type);
5839 insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5840 struct symtab_and_line sr_sal,
5841 struct frame_id sr_id)
5843 insert_step_resume_breakpoint_at_sal_1 (gdbarch,
5848 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5849 This is used to skip a potential signal handler.
5851 This is called with the interrupted function's frame. The signal
5852 handler, when it returns, will resume the interrupted function at
5856 insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
5858 struct symtab_and_line sr_sal;
5859 struct gdbarch *gdbarch;
5861 gdb_assert (return_frame != NULL);
5862 init_sal (&sr_sal); /* initialize to zeros */
5864 gdbarch = get_frame_arch (return_frame);
5865 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
5866 sr_sal.section = find_pc_overlay (sr_sal.pc);
5867 sr_sal.pspace = get_frame_program_space (return_frame);
5869 insert_step_resume_breakpoint_at_sal_1 (gdbarch, sr_sal,
5870 get_stack_frame_id (return_frame),
5874 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5875 is used to skip a function after stepping into it (for "next" or if
5876 the called function has no debugging information).
5878 The current function has almost always been reached by single
5879 stepping a call or return instruction. NEXT_FRAME belongs to the
5880 current function, and the breakpoint will be set at the caller's
5883 This is a separate function rather than reusing
5884 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5885 get_prev_frame, which may stop prematurely (see the implementation
5886 of frame_unwind_caller_id for an example). */
5889 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
5891 struct symtab_and_line sr_sal;
5892 struct gdbarch *gdbarch;
5894 /* We shouldn't have gotten here if we don't know where the call site
5896 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
5898 init_sal (&sr_sal); /* initialize to zeros */
5900 gdbarch = frame_unwind_caller_arch (next_frame);
5901 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
5902 frame_unwind_caller_pc (next_frame));
5903 sr_sal.section = find_pc_overlay (sr_sal.pc);
5904 sr_sal.pspace = frame_unwind_program_space (next_frame);
5906 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5907 frame_unwind_caller_id (next_frame));
5910 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5911 new breakpoint at the target of a jmp_buf. The handling of
5912 longjmp-resume uses the same mechanisms used for handling
5913 "step-resume" breakpoints. */
5916 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
5918 /* There should never be more than one longjmp-resume breakpoint per
5919 thread, so we should never be setting a new
5920 longjmp_resume_breakpoint when one is already active. */
5921 gdb_assert (inferior_thread ()->control.exception_resume_breakpoint == NULL);
5924 fprintf_unfiltered (gdb_stdlog,
5925 "infrun: inserting longjmp-resume breakpoint at %s\n",
5926 paddress (gdbarch, pc));
5928 inferior_thread ()->control.exception_resume_breakpoint =
5929 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
5932 /* Insert an exception resume breakpoint. TP is the thread throwing
5933 the exception. The block B is the block of the unwinder debug hook
5934 function. FRAME is the frame corresponding to the call to this
5935 function. SYM is the symbol of the function argument holding the
5936 target PC of the exception. */
5939 insert_exception_resume_breakpoint (struct thread_info *tp,
5940 const struct block *b,
5941 struct frame_info *frame,
5944 volatile struct gdb_exception e;
5946 /* We want to ignore errors here. */
5947 TRY_CATCH (e, RETURN_MASK_ERROR)
5949 struct symbol *vsym;
5950 struct value *value;
5952 struct breakpoint *bp;
5954 vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
5955 value = read_var_value (vsym, frame);
5956 /* If the value was optimized out, revert to the old behavior. */
5957 if (! value_optimized_out (value))
5959 handler = value_as_address (value);
5962 fprintf_unfiltered (gdb_stdlog,
5963 "infrun: exception resume at %lx\n",
5964 (unsigned long) handler);
5966 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5967 handler, bp_exception_resume);
5969 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5972 bp->thread = tp->num;
5973 inferior_thread ()->control.exception_resume_breakpoint = bp;
5978 /* A helper for check_exception_resume that sets an
5979 exception-breakpoint based on a SystemTap probe. */
5982 insert_exception_resume_from_probe (struct thread_info *tp,
5983 const struct bound_probe *probe,
5984 struct frame_info *frame)
5986 struct value *arg_value;
5988 struct breakpoint *bp;
5990 arg_value = probe_safe_evaluate_at_pc (frame, 1);
5994 handler = value_as_address (arg_value);
5997 fprintf_unfiltered (gdb_stdlog,
5998 "infrun: exception resume at %s\n",
5999 paddress (get_objfile_arch (probe->objfile),
6002 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
6003 handler, bp_exception_resume);
6004 bp->thread = tp->num;
6005 inferior_thread ()->control.exception_resume_breakpoint = bp;
6008 /* This is called when an exception has been intercepted. Check to
6009 see whether the exception's destination is of interest, and if so,
6010 set an exception resume breakpoint there. */
6013 check_exception_resume (struct execution_control_state *ecs,
6014 struct frame_info *frame)
6016 volatile struct gdb_exception e;
6017 struct bound_probe probe;
6018 struct symbol *func;
6020 /* First see if this exception unwinding breakpoint was set via a
6021 SystemTap probe point. If so, the probe has two arguments: the
6022 CFA and the HANDLER. We ignore the CFA, extract the handler, and
6023 set a breakpoint there. */
6024 probe = find_probe_by_pc (get_frame_pc (frame));
6027 insert_exception_resume_from_probe (ecs->event_thread, &probe, frame);
6031 func = get_frame_function (frame);
6035 TRY_CATCH (e, RETURN_MASK_ERROR)
6037 const struct block *b;
6038 struct block_iterator iter;
6042 /* The exception breakpoint is a thread-specific breakpoint on
6043 the unwinder's debug hook, declared as:
6045 void _Unwind_DebugHook (void *cfa, void *handler);
6047 The CFA argument indicates the frame to which control is
6048 about to be transferred. HANDLER is the destination PC.
6050 We ignore the CFA and set a temporary breakpoint at HANDLER.
6051 This is not extremely efficient but it avoids issues in gdb
6052 with computing the DWARF CFA, and it also works even in weird
6053 cases such as throwing an exception from inside a signal
6056 b = SYMBOL_BLOCK_VALUE (func);
6057 ALL_BLOCK_SYMBOLS (b, iter, sym)
6059 if (!SYMBOL_IS_ARGUMENT (sym))
6066 insert_exception_resume_breakpoint (ecs->event_thread,
6075 stop_waiting (struct execution_control_state *ecs)
6078 fprintf_unfiltered (gdb_stdlog, "infrun: stop_waiting\n");
6080 clear_step_over_info ();
6082 /* Let callers know we don't want to wait for the inferior anymore. */
6083 ecs->wait_some_more = 0;
6086 /* Called when we should continue running the inferior, because the
6087 current event doesn't cause a user visible stop. This does the
6088 resuming part; waiting for the next event is done elsewhere. */
6091 keep_going (struct execution_control_state *ecs)
6093 /* Make sure normal_stop is called if we get a QUIT handled before
6095 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
6097 /* Save the pc before execution, to compare with pc after stop. */
6098 ecs->event_thread->prev_pc
6099 = regcache_read_pc (get_thread_regcache (ecs->ptid));
6101 if (ecs->event_thread->control.trap_expected
6102 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
6104 /* We haven't yet gotten our trap, and either: intercepted a
6105 non-signal event (e.g., a fork); or took a signal which we
6106 are supposed to pass through to the inferior. Simply
6108 discard_cleanups (old_cleanups);
6109 resume (currently_stepping (ecs->event_thread),
6110 ecs->event_thread->suspend.stop_signal);
6114 volatile struct gdb_exception e;
6115 struct regcache *regcache = get_current_regcache ();
6119 /* Either the trap was not expected, but we are continuing
6120 anyway (if we got a signal, the user asked it be passed to
6123 We got our expected trap, but decided we should resume from
6126 We're going to run this baby now!
6128 Note that insert_breakpoints won't try to re-insert
6129 already inserted breakpoints. Therefore, we don't
6130 care if breakpoints were already inserted, or not. */
6132 /* If we need to step over a breakpoint, and we're not using
6133 displaced stepping to do so, insert all breakpoints
6134 (watchpoints, etc.) but the one we're stepping over, step one
6135 instruction, and then re-insert the breakpoint when that step
6138 remove_bp = (ecs->hit_singlestep_breakpoint
6139 || thread_still_needs_step_over (ecs->event_thread));
6140 remove_wps = (ecs->event_thread->stepping_over_watchpoint
6141 && !target_have_steppable_watchpoint);
6143 if (remove_bp && !use_displaced_stepping (get_regcache_arch (regcache)))
6145 set_step_over_info (get_regcache_aspace (regcache),
6146 regcache_read_pc (regcache), remove_wps);
6148 else if (remove_wps)
6149 set_step_over_info (NULL, 0, remove_wps);
6151 clear_step_over_info ();
6153 /* Stop stepping if inserting breakpoints fails. */
6154 TRY_CATCH (e, RETURN_MASK_ERROR)
6156 insert_breakpoints ();
6160 exception_print (gdb_stderr, e);
6165 ecs->event_thread->control.trap_expected = (remove_bp || remove_wps);
6167 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
6168 explicitly specifies that such a signal should be delivered
6169 to the target program). Typically, that would occur when a
6170 user is debugging a target monitor on a simulator: the target
6171 monitor sets a breakpoint; the simulator encounters this
6172 breakpoint and halts the simulation handing control to GDB;
6173 GDB, noting that the stop address doesn't map to any known
6174 breakpoint, returns control back to the simulator; the
6175 simulator then delivers the hardware equivalent of a
6176 GDB_SIGNAL_TRAP to the program being debugged. */
6177 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
6178 && !signal_program[ecs->event_thread->suspend.stop_signal])
6179 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
6181 discard_cleanups (old_cleanups);
6182 resume (currently_stepping (ecs->event_thread),
6183 ecs->event_thread->suspend.stop_signal);
6186 prepare_to_wait (ecs);
6189 /* This function normally comes after a resume, before
6190 handle_inferior_event exits. It takes care of any last bits of
6191 housekeeping, and sets the all-important wait_some_more flag. */
6194 prepare_to_wait (struct execution_control_state *ecs)
6197 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
6199 /* This is the old end of the while loop. Let everybody know we
6200 want to wait for the inferior some more and get called again
6202 ecs->wait_some_more = 1;
6205 /* We are done with the step range of a step/next/si/ni command.
6206 Called once for each n of a "step n" operation. */
6209 end_stepping_range (struct execution_control_state *ecs)
6211 ecs->event_thread->control.stop_step = 1;
6215 /* Several print_*_reason functions to print why the inferior has stopped.
6216 We always print something when the inferior exits, or receives a signal.
6217 The rest of the cases are dealt with later on in normal_stop and
6218 print_it_typical. Ideally there should be a call to one of these
6219 print_*_reason functions functions from handle_inferior_event each time
6220 stop_waiting is called.
6222 Note that we don't call these directly, instead we delegate that to
6223 the interpreters, through observers. Interpreters then call these
6224 with whatever uiout is right. */
6227 print_end_stepping_range_reason (struct ui_out *uiout)
6229 /* For CLI-like interpreters, print nothing. */
6231 if (ui_out_is_mi_like_p (uiout))
6233 ui_out_field_string (uiout, "reason",
6234 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
6239 print_signal_exited_reason (struct ui_out *uiout, enum gdb_signal siggnal)
6241 annotate_signalled ();
6242 if (ui_out_is_mi_like_p (uiout))
6244 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
6245 ui_out_text (uiout, "\nProgram terminated with signal ");
6246 annotate_signal_name ();
6247 ui_out_field_string (uiout, "signal-name",
6248 gdb_signal_to_name (siggnal));
6249 annotate_signal_name_end ();
6250 ui_out_text (uiout, ", ");
6251 annotate_signal_string ();
6252 ui_out_field_string (uiout, "signal-meaning",
6253 gdb_signal_to_string (siggnal));
6254 annotate_signal_string_end ();
6255 ui_out_text (uiout, ".\n");
6256 ui_out_text (uiout, "The program no longer exists.\n");
6260 print_exited_reason (struct ui_out *uiout, int exitstatus)
6262 struct inferior *inf = current_inferior ();
6263 const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid));
6265 annotate_exited (exitstatus);
6268 if (ui_out_is_mi_like_p (uiout))
6269 ui_out_field_string (uiout, "reason",
6270 async_reason_lookup (EXEC_ASYNC_EXITED));
6271 ui_out_text (uiout, "[Inferior ");
6272 ui_out_text (uiout, plongest (inf->num));
6273 ui_out_text (uiout, " (");
6274 ui_out_text (uiout, pidstr);
6275 ui_out_text (uiout, ") exited with code ");
6276 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
6277 ui_out_text (uiout, "]\n");
6281 if (ui_out_is_mi_like_p (uiout))
6283 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
6284 ui_out_text (uiout, "[Inferior ");
6285 ui_out_text (uiout, plongest (inf->num));
6286 ui_out_text (uiout, " (");
6287 ui_out_text (uiout, pidstr);
6288 ui_out_text (uiout, ") exited normally]\n");
6293 print_signal_received_reason (struct ui_out *uiout, enum gdb_signal siggnal)
6297 if (siggnal == GDB_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
6299 struct thread_info *t = inferior_thread ();
6301 ui_out_text (uiout, "\n[");
6302 ui_out_field_string (uiout, "thread-name",
6303 target_pid_to_str (t->ptid));
6304 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
6305 ui_out_text (uiout, " stopped");
6309 ui_out_text (uiout, "\nProgram received signal ");
6310 annotate_signal_name ();
6311 if (ui_out_is_mi_like_p (uiout))
6313 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
6314 ui_out_field_string (uiout, "signal-name",
6315 gdb_signal_to_name (siggnal));
6316 annotate_signal_name_end ();
6317 ui_out_text (uiout, ", ");
6318 annotate_signal_string ();
6319 ui_out_field_string (uiout, "signal-meaning",
6320 gdb_signal_to_string (siggnal));
6321 annotate_signal_string_end ();
6323 ui_out_text (uiout, ".\n");
6327 print_no_history_reason (struct ui_out *uiout)
6329 ui_out_text (uiout, "\nNo more reverse-execution history.\n");
6332 /* Print current location without a level number, if we have changed
6333 functions or hit a breakpoint. Print source line if we have one.
6334 bpstat_print contains the logic deciding in detail what to print,
6335 based on the event(s) that just occurred. */
6338 print_stop_event (struct target_waitstatus *ws)
6342 int do_frame_printing = 1;
6343 struct thread_info *tp = inferior_thread ();
6345 bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws->kind);
6349 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
6350 should) carry around the function and does (or should) use
6351 that when doing a frame comparison. */
6352 if (tp->control.stop_step
6353 && frame_id_eq (tp->control.step_frame_id,
6354 get_frame_id (get_current_frame ()))
6355 && step_start_function == find_pc_function (stop_pc))
6357 /* Finished step, just print source line. */
6358 source_flag = SRC_LINE;
6362 /* Print location and source line. */
6363 source_flag = SRC_AND_LOC;
6366 case PRINT_SRC_AND_LOC:
6367 /* Print location and source line. */
6368 source_flag = SRC_AND_LOC;
6370 case PRINT_SRC_ONLY:
6371 source_flag = SRC_LINE;
6374 /* Something bogus. */
6375 source_flag = SRC_LINE;
6376 do_frame_printing = 0;
6379 internal_error (__FILE__, __LINE__, _("Unknown value."));
6382 /* The behavior of this routine with respect to the source
6384 SRC_LINE: Print only source line
6385 LOCATION: Print only location
6386 SRC_AND_LOC: Print location and source line. */
6387 if (do_frame_printing)
6388 print_stack_frame (get_selected_frame (NULL), 0, source_flag, 1);
6390 /* Display the auto-display expressions. */
6394 /* Here to return control to GDB when the inferior stops for real.
6395 Print appropriate messages, remove breakpoints, give terminal our modes.
6397 STOP_PRINT_FRAME nonzero means print the executing frame
6398 (pc, function, args, file, line number and line text).
6399 BREAKPOINTS_FAILED nonzero means stop was due to error
6400 attempting to insert breakpoints. */
6405 struct target_waitstatus last;
6407 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
6409 get_last_target_status (&last_ptid, &last);
6411 /* If an exception is thrown from this point on, make sure to
6412 propagate GDB's knowledge of the executing state to the
6413 frontend/user running state. A QUIT is an easy exception to see
6414 here, so do this before any filtered output. */
6416 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
6417 else if (last.kind != TARGET_WAITKIND_SIGNALLED
6418 && last.kind != TARGET_WAITKIND_EXITED
6419 && last.kind != TARGET_WAITKIND_NO_RESUMED)
6420 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
6422 /* As we're presenting a stop, and potentially removing breakpoints,
6423 update the thread list so we can tell whether there are threads
6424 running on the target. With target remote, for example, we can
6425 only learn about new threads when we explicitly update the thread
6426 list. Do this before notifying the interpreters about signal
6427 stops, end of stepping ranges, etc., so that the "new thread"
6428 output is emitted before e.g., "Program received signal FOO",
6429 instead of after. */
6430 update_thread_list ();
6432 if (last.kind == TARGET_WAITKIND_STOPPED && stopped_by_random_signal)
6433 observer_notify_signal_received (inferior_thread ()->suspend.stop_signal);
6435 /* As with the notification of thread events, we want to delay
6436 notifying the user that we've switched thread context until
6437 the inferior actually stops.
6439 There's no point in saying anything if the inferior has exited.
6440 Note that SIGNALLED here means "exited with a signal", not
6441 "received a signal".
6443 Also skip saying anything in non-stop mode. In that mode, as we
6444 don't want GDB to switch threads behind the user's back, to avoid
6445 races where the user is typing a command to apply to thread x,
6446 but GDB switches to thread y before the user finishes entering
6447 the command, fetch_inferior_event installs a cleanup to restore
6448 the current thread back to the thread the user had selected right
6449 after this event is handled, so we're not really switching, only
6450 informing of a stop. */
6452 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
6453 && target_has_execution
6454 && last.kind != TARGET_WAITKIND_SIGNALLED
6455 && last.kind != TARGET_WAITKIND_EXITED
6456 && last.kind != TARGET_WAITKIND_NO_RESUMED)
6458 target_terminal_ours_for_output ();
6459 printf_filtered (_("[Switching to %s]\n"),
6460 target_pid_to_str (inferior_ptid));
6461 annotate_thread_changed ();
6462 previous_inferior_ptid = inferior_ptid;
6465 if (last.kind == TARGET_WAITKIND_NO_RESUMED)
6467 gdb_assert (sync_execution || !target_can_async_p ());
6469 target_terminal_ours_for_output ();
6470 printf_filtered (_("No unwaited-for children left.\n"));
6473 /* Note: this depends on the update_thread_list call above. */
6474 if (!breakpoints_should_be_inserted_now () && target_has_execution)
6476 if (remove_breakpoints ())
6478 target_terminal_ours_for_output ();
6479 printf_filtered (_("Cannot remove breakpoints because "
6480 "program is no longer writable.\nFurther "
6481 "execution is probably impossible.\n"));
6485 /* If an auto-display called a function and that got a signal,
6486 delete that auto-display to avoid an infinite recursion. */
6488 if (stopped_by_random_signal)
6489 disable_current_display ();
6491 /* Notify observers if we finished a "step"-like command, etc. */
6492 if (target_has_execution
6493 && last.kind != TARGET_WAITKIND_SIGNALLED
6494 && last.kind != TARGET_WAITKIND_EXITED
6495 && inferior_thread ()->control.stop_step)
6497 /* But not if in the middle of doing a "step n" operation for
6499 if (inferior_thread ()->step_multi)
6502 observer_notify_end_stepping_range ();
6505 target_terminal_ours ();
6506 async_enable_stdin ();
6508 /* Set the current source location. This will also happen if we
6509 display the frame below, but the current SAL will be incorrect
6510 during a user hook-stop function. */
6511 if (has_stack_frames () && !stop_stack_dummy)
6512 set_current_sal_from_frame (get_current_frame ());
6514 /* Let the user/frontend see the threads as stopped, but do nothing
6515 if the thread was running an infcall. We may be e.g., evaluating
6516 a breakpoint condition. In that case, the thread had state
6517 THREAD_RUNNING before the infcall, and shall remain set to
6518 running, all without informing the user/frontend about state
6519 transition changes. If this is actually a call command, then the
6520 thread was originally already stopped, so there's no state to
6522 if (target_has_execution && inferior_thread ()->control.in_infcall)
6523 discard_cleanups (old_chain);
6525 do_cleanups (old_chain);
6527 /* Look up the hook_stop and run it (CLI internally handles problem
6528 of stop_command's pre-hook not existing). */
6530 catch_errors (hook_stop_stub, stop_command,
6531 "Error while running hook_stop:\n", RETURN_MASK_ALL);
6533 if (!has_stack_frames ())
6536 if (last.kind == TARGET_WAITKIND_SIGNALLED
6537 || last.kind == TARGET_WAITKIND_EXITED)
6540 /* Select innermost stack frame - i.e., current frame is frame 0,
6541 and current location is based on that.
6542 Don't do this on return from a stack dummy routine,
6543 or if the program has exited. */
6545 if (!stop_stack_dummy)
6547 select_frame (get_current_frame ());
6549 /* If --batch-silent is enabled then there's no need to print the current
6550 source location, and to try risks causing an error message about
6551 missing source files. */
6552 if (stop_print_frame && !batch_silent)
6553 print_stop_event (&last);
6556 /* Save the function value return registers, if we care.
6557 We might be about to restore their previous contents. */
6558 if (inferior_thread ()->control.proceed_to_finish
6559 && execution_direction != EXEC_REVERSE)
6561 /* This should not be necessary. */
6563 regcache_xfree (stop_registers);
6565 /* NB: The copy goes through to the target picking up the value of
6566 all the registers. */
6567 stop_registers = regcache_dup (get_current_regcache ());
6570 if (stop_stack_dummy == STOP_STACK_DUMMY)
6572 /* Pop the empty frame that contains the stack dummy.
6573 This also restores inferior state prior to the call
6574 (struct infcall_suspend_state). */
6575 struct frame_info *frame = get_current_frame ();
6577 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
6579 /* frame_pop() calls reinit_frame_cache as the last thing it
6580 does which means there's currently no selected frame. We
6581 don't need to re-establish a selected frame if the dummy call
6582 returns normally, that will be done by
6583 restore_infcall_control_state. However, we do have to handle
6584 the case where the dummy call is returning after being
6585 stopped (e.g. the dummy call previously hit a breakpoint).
6586 We can't know which case we have so just always re-establish
6587 a selected frame here. */
6588 select_frame (get_current_frame ());
6592 annotate_stopped ();
6594 /* Suppress the stop observer if we're in the middle of:
6596 - a step n (n > 1), as there still more steps to be done.
6598 - a "finish" command, as the observer will be called in
6599 finish_command_continuation, so it can include the inferior
6600 function's return value.
6602 - calling an inferior function, as we pretend we inferior didn't
6603 run at all. The return value of the call is handled by the
6604 expression evaluator, through call_function_by_hand. */
6606 if (!target_has_execution
6607 || last.kind == TARGET_WAITKIND_SIGNALLED
6608 || last.kind == TARGET_WAITKIND_EXITED
6609 || last.kind == TARGET_WAITKIND_NO_RESUMED
6610 || (!(inferior_thread ()->step_multi
6611 && inferior_thread ()->control.stop_step)
6612 && !(inferior_thread ()->control.stop_bpstat
6613 && inferior_thread ()->control.proceed_to_finish)
6614 && !inferior_thread ()->control.in_infcall))
6616 if (!ptid_equal (inferior_ptid, null_ptid))
6617 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
6620 observer_notify_normal_stop (NULL, stop_print_frame);
6623 if (target_has_execution)
6625 if (last.kind != TARGET_WAITKIND_SIGNALLED
6626 && last.kind != TARGET_WAITKIND_EXITED)
6627 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6628 Delete any breakpoint that is to be deleted at the next stop. */
6629 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
6632 /* Try to get rid of automatically added inferiors that are no
6633 longer needed. Keeping those around slows down things linearly.
6634 Note that this never removes the current inferior. */
6639 hook_stop_stub (void *cmd)
6641 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
6646 signal_stop_state (int signo)
6648 return signal_stop[signo];
6652 signal_print_state (int signo)
6654 return signal_print[signo];
6658 signal_pass_state (int signo)
6660 return signal_program[signo];
6664 signal_cache_update (int signo)
6668 for (signo = 0; signo < (int) GDB_SIGNAL_LAST; signo++)
6669 signal_cache_update (signo);
6674 signal_pass[signo] = (signal_stop[signo] == 0
6675 && signal_print[signo] == 0
6676 && signal_program[signo] == 1
6677 && signal_catch[signo] == 0);
6681 signal_stop_update (int signo, int state)
6683 int ret = signal_stop[signo];
6685 signal_stop[signo] = state;
6686 signal_cache_update (signo);
6691 signal_print_update (int signo, int state)
6693 int ret = signal_print[signo];
6695 signal_print[signo] = state;
6696 signal_cache_update (signo);
6701 signal_pass_update (int signo, int state)
6703 int ret = signal_program[signo];
6705 signal_program[signo] = state;
6706 signal_cache_update (signo);
6710 /* Update the global 'signal_catch' from INFO and notify the
6714 signal_catch_update (const unsigned int *info)
6718 for (i = 0; i < GDB_SIGNAL_LAST; ++i)
6719 signal_catch[i] = info[i] > 0;
6720 signal_cache_update (-1);
6721 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
6725 sig_print_header (void)
6727 printf_filtered (_("Signal Stop\tPrint\tPass "
6728 "to program\tDescription\n"));
6732 sig_print_info (enum gdb_signal oursig)
6734 const char *name = gdb_signal_to_name (oursig);
6735 int name_padding = 13 - strlen (name);
6737 if (name_padding <= 0)
6740 printf_filtered ("%s", name);
6741 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
6742 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
6743 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
6744 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
6745 printf_filtered ("%s\n", gdb_signal_to_string (oursig));
6748 /* Specify how various signals in the inferior should be handled. */
6751 handle_command (char *args, int from_tty)
6754 int digits, wordlen;
6755 int sigfirst, signum, siglast;
6756 enum gdb_signal oursig;
6759 unsigned char *sigs;
6760 struct cleanup *old_chain;
6764 error_no_arg (_("signal to handle"));
6767 /* Allocate and zero an array of flags for which signals to handle. */
6769 nsigs = (int) GDB_SIGNAL_LAST;
6770 sigs = (unsigned char *) alloca (nsigs);
6771 memset (sigs, 0, nsigs);
6773 /* Break the command line up into args. */
6775 argv = gdb_buildargv (args);
6776 old_chain = make_cleanup_freeargv (argv);
6778 /* Walk through the args, looking for signal oursigs, signal names, and
6779 actions. Signal numbers and signal names may be interspersed with
6780 actions, with the actions being performed for all signals cumulatively
6781 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6783 while (*argv != NULL)
6785 wordlen = strlen (*argv);
6786 for (digits = 0; isdigit ((*argv)[digits]); digits++)
6790 sigfirst = siglast = -1;
6792 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
6794 /* Apply action to all signals except those used by the
6795 debugger. Silently skip those. */
6798 siglast = nsigs - 1;
6800 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
6802 SET_SIGS (nsigs, sigs, signal_stop);
6803 SET_SIGS (nsigs, sigs, signal_print);
6805 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
6807 UNSET_SIGS (nsigs, sigs, signal_program);
6809 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
6811 SET_SIGS (nsigs, sigs, signal_print);
6813 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
6815 SET_SIGS (nsigs, sigs, signal_program);
6817 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
6819 UNSET_SIGS (nsigs, sigs, signal_stop);
6821 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
6823 SET_SIGS (nsigs, sigs, signal_program);
6825 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
6827 UNSET_SIGS (nsigs, sigs, signal_print);
6828 UNSET_SIGS (nsigs, sigs, signal_stop);
6830 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
6832 UNSET_SIGS (nsigs, sigs, signal_program);
6834 else if (digits > 0)
6836 /* It is numeric. The numeric signal refers to our own
6837 internal signal numbering from target.h, not to host/target
6838 signal number. This is a feature; users really should be
6839 using symbolic names anyway, and the common ones like
6840 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6842 sigfirst = siglast = (int)
6843 gdb_signal_from_command (atoi (*argv));
6844 if ((*argv)[digits] == '-')
6847 gdb_signal_from_command (atoi ((*argv) + digits + 1));
6849 if (sigfirst > siglast)
6851 /* Bet he didn't figure we'd think of this case... */
6859 oursig = gdb_signal_from_name (*argv);
6860 if (oursig != GDB_SIGNAL_UNKNOWN)
6862 sigfirst = siglast = (int) oursig;
6866 /* Not a number and not a recognized flag word => complain. */
6867 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
6871 /* If any signal numbers or symbol names were found, set flags for
6872 which signals to apply actions to. */
6874 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
6876 switch ((enum gdb_signal) signum)
6878 case GDB_SIGNAL_TRAP:
6879 case GDB_SIGNAL_INT:
6880 if (!allsigs && !sigs[signum])
6882 if (query (_("%s is used by the debugger.\n\
6883 Are you sure you want to change it? "),
6884 gdb_signal_to_name ((enum gdb_signal) signum)))
6890 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6891 gdb_flush (gdb_stdout);
6896 case GDB_SIGNAL_DEFAULT:
6897 case GDB_SIGNAL_UNKNOWN:
6898 /* Make sure that "all" doesn't print these. */
6909 for (signum = 0; signum < nsigs; signum++)
6912 signal_cache_update (-1);
6913 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
6914 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
6918 /* Show the results. */
6919 sig_print_header ();
6920 for (; signum < nsigs; signum++)
6922 sig_print_info (signum);
6928 do_cleanups (old_chain);
6931 /* Complete the "handle" command. */
6933 static VEC (char_ptr) *
6934 handle_completer (struct cmd_list_element *ignore,
6935 const char *text, const char *word)
6937 VEC (char_ptr) *vec_signals, *vec_keywords, *return_val;
6938 static const char * const keywords[] =
6952 vec_signals = signal_completer (ignore, text, word);
6953 vec_keywords = complete_on_enum (keywords, word, word);
6955 return_val = VEC_merge (char_ptr, vec_signals, vec_keywords);
6956 VEC_free (char_ptr, vec_signals);
6957 VEC_free (char_ptr, vec_keywords);
6962 xdb_handle_command (char *args, int from_tty)
6965 struct cleanup *old_chain;
6968 error_no_arg (_("xdb command"));
6970 /* Break the command line up into args. */
6972 argv = gdb_buildargv (args);
6973 old_chain = make_cleanup_freeargv (argv);
6974 if (argv[1] != (char *) NULL)
6979 bufLen = strlen (argv[0]) + 20;
6980 argBuf = (char *) xmalloc (bufLen);
6984 enum gdb_signal oursig;
6986 oursig = gdb_signal_from_name (argv[0]);
6987 memset (argBuf, 0, bufLen);
6988 if (strcmp (argv[1], "Q") == 0)
6989 sprintf (argBuf, "%s %s", argv[0], "noprint");
6992 if (strcmp (argv[1], "s") == 0)
6994 if (!signal_stop[oursig])
6995 sprintf (argBuf, "%s %s", argv[0], "stop");
6997 sprintf (argBuf, "%s %s", argv[0], "nostop");
6999 else if (strcmp (argv[1], "i") == 0)
7001 if (!signal_program[oursig])
7002 sprintf (argBuf, "%s %s", argv[0], "pass");
7004 sprintf (argBuf, "%s %s", argv[0], "nopass");
7006 else if (strcmp (argv[1], "r") == 0)
7008 if (!signal_print[oursig])
7009 sprintf (argBuf, "%s %s", argv[0], "print");
7011 sprintf (argBuf, "%s %s", argv[0], "noprint");
7017 handle_command (argBuf, from_tty);
7019 printf_filtered (_("Invalid signal handling flag.\n"));
7024 do_cleanups (old_chain);
7028 gdb_signal_from_command (int num)
7030 if (num >= 1 && num <= 15)
7031 return (enum gdb_signal) num;
7032 error (_("Only signals 1-15 are valid as numeric signals.\n\
7033 Use \"info signals\" for a list of symbolic signals."));
7036 /* Print current contents of the tables set by the handle command.
7037 It is possible we should just be printing signals actually used
7038 by the current target (but for things to work right when switching
7039 targets, all signals should be in the signal tables). */
7042 signals_info (char *signum_exp, int from_tty)
7044 enum gdb_signal oursig;
7046 sig_print_header ();
7050 /* First see if this is a symbol name. */
7051 oursig = gdb_signal_from_name (signum_exp);
7052 if (oursig == GDB_SIGNAL_UNKNOWN)
7054 /* No, try numeric. */
7056 gdb_signal_from_command (parse_and_eval_long (signum_exp));
7058 sig_print_info (oursig);
7062 printf_filtered ("\n");
7063 /* These ugly casts brought to you by the native VAX compiler. */
7064 for (oursig = GDB_SIGNAL_FIRST;
7065 (int) oursig < (int) GDB_SIGNAL_LAST;
7066 oursig = (enum gdb_signal) ((int) oursig + 1))
7070 if (oursig != GDB_SIGNAL_UNKNOWN
7071 && oursig != GDB_SIGNAL_DEFAULT && oursig != GDB_SIGNAL_0)
7072 sig_print_info (oursig);
7075 printf_filtered (_("\nUse the \"handle\" command "
7076 "to change these tables.\n"));
7079 /* Check if it makes sense to read $_siginfo from the current thread
7080 at this point. If not, throw an error. */
7083 validate_siginfo_access (void)
7085 /* No current inferior, no siginfo. */
7086 if (ptid_equal (inferior_ptid, null_ptid))
7087 error (_("No thread selected."));
7089 /* Don't try to read from a dead thread. */
7090 if (is_exited (inferior_ptid))
7091 error (_("The current thread has terminated"));
7093 /* ... or from a spinning thread. */
7094 if (is_running (inferior_ptid))
7095 error (_("Selected thread is running."));
7098 /* The $_siginfo convenience variable is a bit special. We don't know
7099 for sure the type of the value until we actually have a chance to
7100 fetch the data. The type can change depending on gdbarch, so it is
7101 also dependent on which thread you have selected.
7103 1. making $_siginfo be an internalvar that creates a new value on
7106 2. making the value of $_siginfo be an lval_computed value. */
7108 /* This function implements the lval_computed support for reading a
7112 siginfo_value_read (struct value *v)
7114 LONGEST transferred;
7116 validate_siginfo_access ();
7119 target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO,
7121 value_contents_all_raw (v),
7123 TYPE_LENGTH (value_type (v)));
7125 if (transferred != TYPE_LENGTH (value_type (v)))
7126 error (_("Unable to read siginfo"));
7129 /* This function implements the lval_computed support for writing a
7133 siginfo_value_write (struct value *v, struct value *fromval)
7135 LONGEST transferred;
7137 validate_siginfo_access ();
7139 transferred = target_write (¤t_target,
7140 TARGET_OBJECT_SIGNAL_INFO,
7142 value_contents_all_raw (fromval),
7144 TYPE_LENGTH (value_type (fromval)));
7146 if (transferred != TYPE_LENGTH (value_type (fromval)))
7147 error (_("Unable to write siginfo"));
7150 static const struct lval_funcs siginfo_value_funcs =
7156 /* Return a new value with the correct type for the siginfo object of
7157 the current thread using architecture GDBARCH. Return a void value
7158 if there's no object available. */
7160 static struct value *
7161 siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var,
7164 if (target_has_stack
7165 && !ptid_equal (inferior_ptid, null_ptid)
7166 && gdbarch_get_siginfo_type_p (gdbarch))
7168 struct type *type = gdbarch_get_siginfo_type (gdbarch);
7170 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
7173 return allocate_value (builtin_type (gdbarch)->builtin_void);
7177 /* infcall_suspend_state contains state about the program itself like its
7178 registers and any signal it received when it last stopped.
7179 This state must be restored regardless of how the inferior function call
7180 ends (either successfully, or after it hits a breakpoint or signal)
7181 if the program is to properly continue where it left off. */
7183 struct infcall_suspend_state
7185 struct thread_suspend_state thread_suspend;
7186 #if 0 /* Currently unused and empty structures are not valid C. */
7187 struct inferior_suspend_state inferior_suspend;
7192 struct regcache *registers;
7194 /* Format of SIGINFO_DATA or NULL if it is not present. */
7195 struct gdbarch *siginfo_gdbarch;
7197 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
7198 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
7199 content would be invalid. */
7200 gdb_byte *siginfo_data;
7203 struct infcall_suspend_state *
7204 save_infcall_suspend_state (void)
7206 struct infcall_suspend_state *inf_state;
7207 struct thread_info *tp = inferior_thread ();
7209 struct inferior *inf = current_inferior ();
7211 struct regcache *regcache = get_current_regcache ();
7212 struct gdbarch *gdbarch = get_regcache_arch (regcache);
7213 gdb_byte *siginfo_data = NULL;
7215 if (gdbarch_get_siginfo_type_p (gdbarch))
7217 struct type *type = gdbarch_get_siginfo_type (gdbarch);
7218 size_t len = TYPE_LENGTH (type);
7219 struct cleanup *back_to;
7221 siginfo_data = xmalloc (len);
7222 back_to = make_cleanup (xfree, siginfo_data);
7224 if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
7225 siginfo_data, 0, len) == len)
7226 discard_cleanups (back_to);
7229 /* Errors ignored. */
7230 do_cleanups (back_to);
7231 siginfo_data = NULL;
7235 inf_state = XCNEW (struct infcall_suspend_state);
7239 inf_state->siginfo_gdbarch = gdbarch;
7240 inf_state->siginfo_data = siginfo_data;
7243 inf_state->thread_suspend = tp->suspend;
7244 #if 0 /* Currently unused and empty structures are not valid C. */
7245 inf_state->inferior_suspend = inf->suspend;
7248 /* run_inferior_call will not use the signal due to its `proceed' call with
7249 GDB_SIGNAL_0 anyway. */
7250 tp->suspend.stop_signal = GDB_SIGNAL_0;
7252 inf_state->stop_pc = stop_pc;
7254 inf_state->registers = regcache_dup (regcache);
7259 /* Restore inferior session state to INF_STATE. */
7262 restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
7264 struct thread_info *tp = inferior_thread ();
7266 struct inferior *inf = current_inferior ();
7268 struct regcache *regcache = get_current_regcache ();
7269 struct gdbarch *gdbarch = get_regcache_arch (regcache);
7271 tp->suspend = inf_state->thread_suspend;
7272 #if 0 /* Currently unused and empty structures are not valid C. */
7273 inf->suspend = inf_state->inferior_suspend;
7276 stop_pc = inf_state->stop_pc;
7278 if (inf_state->siginfo_gdbarch == gdbarch)
7280 struct type *type = gdbarch_get_siginfo_type (gdbarch);
7282 /* Errors ignored. */
7283 target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
7284 inf_state->siginfo_data, 0, TYPE_LENGTH (type));
7287 /* The inferior can be gone if the user types "print exit(0)"
7288 (and perhaps other times). */
7289 if (target_has_execution)
7290 /* NB: The register write goes through to the target. */
7291 regcache_cpy (regcache, inf_state->registers);
7293 discard_infcall_suspend_state (inf_state);
7297 do_restore_infcall_suspend_state_cleanup (void *state)
7299 restore_infcall_suspend_state (state);
7303 make_cleanup_restore_infcall_suspend_state
7304 (struct infcall_suspend_state *inf_state)
7306 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
7310 discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
7312 regcache_xfree (inf_state->registers);
7313 xfree (inf_state->siginfo_data);
7318 get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
7320 return inf_state->registers;
7323 /* infcall_control_state contains state regarding gdb's control of the
7324 inferior itself like stepping control. It also contains session state like
7325 the user's currently selected frame. */
7327 struct infcall_control_state
7329 struct thread_control_state thread_control;
7330 struct inferior_control_state inferior_control;
7333 enum stop_stack_kind stop_stack_dummy;
7334 int stopped_by_random_signal;
7335 int stop_after_trap;
7337 /* ID if the selected frame when the inferior function call was made. */
7338 struct frame_id selected_frame_id;
7341 /* Save all of the information associated with the inferior<==>gdb
7344 struct infcall_control_state *
7345 save_infcall_control_state (void)
7347 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
7348 struct thread_info *tp = inferior_thread ();
7349 struct inferior *inf = current_inferior ();
7351 inf_status->thread_control = tp->control;
7352 inf_status->inferior_control = inf->control;
7354 tp->control.step_resume_breakpoint = NULL;
7355 tp->control.exception_resume_breakpoint = NULL;
7357 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
7358 chain. If caller's caller is walking the chain, they'll be happier if we
7359 hand them back the original chain when restore_infcall_control_state is
7361 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
7364 inf_status->stop_stack_dummy = stop_stack_dummy;
7365 inf_status->stopped_by_random_signal = stopped_by_random_signal;
7366 inf_status->stop_after_trap = stop_after_trap;
7368 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
7374 restore_selected_frame (void *args)
7376 struct frame_id *fid = (struct frame_id *) args;
7377 struct frame_info *frame;
7379 frame = frame_find_by_id (*fid);
7381 /* If inf_status->selected_frame_id is NULL, there was no previously
7385 warning (_("Unable to restore previously selected frame."));
7389 select_frame (frame);
7394 /* Restore inferior session state to INF_STATUS. */
7397 restore_infcall_control_state (struct infcall_control_state *inf_status)
7399 struct thread_info *tp = inferior_thread ();
7400 struct inferior *inf = current_inferior ();
7402 if (tp->control.step_resume_breakpoint)
7403 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
7405 if (tp->control.exception_resume_breakpoint)
7406 tp->control.exception_resume_breakpoint->disposition
7407 = disp_del_at_next_stop;
7409 /* Handle the bpstat_copy of the chain. */
7410 bpstat_clear (&tp->control.stop_bpstat);
7412 tp->control = inf_status->thread_control;
7413 inf->control = inf_status->inferior_control;
7416 stop_stack_dummy = inf_status->stop_stack_dummy;
7417 stopped_by_random_signal = inf_status->stopped_by_random_signal;
7418 stop_after_trap = inf_status->stop_after_trap;
7420 if (target_has_stack)
7422 /* The point of catch_errors is that if the stack is clobbered,
7423 walking the stack might encounter a garbage pointer and
7424 error() trying to dereference it. */
7426 (restore_selected_frame, &inf_status->selected_frame_id,
7427 "Unable to restore previously selected frame:\n",
7428 RETURN_MASK_ERROR) == 0)
7429 /* Error in restoring the selected frame. Select the innermost
7431 select_frame (get_current_frame ());
7438 do_restore_infcall_control_state_cleanup (void *sts)
7440 restore_infcall_control_state (sts);
7444 make_cleanup_restore_infcall_control_state
7445 (struct infcall_control_state *inf_status)
7447 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
7451 discard_infcall_control_state (struct infcall_control_state *inf_status)
7453 if (inf_status->thread_control.step_resume_breakpoint)
7454 inf_status->thread_control.step_resume_breakpoint->disposition
7455 = disp_del_at_next_stop;
7457 if (inf_status->thread_control.exception_resume_breakpoint)
7458 inf_status->thread_control.exception_resume_breakpoint->disposition
7459 = disp_del_at_next_stop;
7461 /* See save_infcall_control_state for info on stop_bpstat. */
7462 bpstat_clear (&inf_status->thread_control.stop_bpstat);
7467 /* restore_inferior_ptid() will be used by the cleanup machinery
7468 to restore the inferior_ptid value saved in a call to
7469 save_inferior_ptid(). */
7472 restore_inferior_ptid (void *arg)
7474 ptid_t *saved_ptid_ptr = arg;
7476 inferior_ptid = *saved_ptid_ptr;
7480 /* Save the value of inferior_ptid so that it may be restored by a
7481 later call to do_cleanups(). Returns the struct cleanup pointer
7482 needed for later doing the cleanup. */
7485 save_inferior_ptid (void)
7487 ptid_t *saved_ptid_ptr;
7489 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
7490 *saved_ptid_ptr = inferior_ptid;
7491 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
7497 clear_exit_convenience_vars (void)
7499 clear_internalvar (lookup_internalvar ("_exitsignal"));
7500 clear_internalvar (lookup_internalvar ("_exitcode"));
7504 /* User interface for reverse debugging:
7505 Set exec-direction / show exec-direction commands
7506 (returns error unless target implements to_set_exec_direction method). */
7508 int execution_direction = EXEC_FORWARD;
7509 static const char exec_forward[] = "forward";
7510 static const char exec_reverse[] = "reverse";
7511 static const char *exec_direction = exec_forward;
7512 static const char *const exec_direction_names[] = {
7519 set_exec_direction_func (char *args, int from_tty,
7520 struct cmd_list_element *cmd)
7522 if (target_can_execute_reverse)
7524 if (!strcmp (exec_direction, exec_forward))
7525 execution_direction = EXEC_FORWARD;
7526 else if (!strcmp (exec_direction, exec_reverse))
7527 execution_direction = EXEC_REVERSE;
7531 exec_direction = exec_forward;
7532 error (_("Target does not support this operation."));
7537 show_exec_direction_func (struct ui_file *out, int from_tty,
7538 struct cmd_list_element *cmd, const char *value)
7540 switch (execution_direction) {
7542 fprintf_filtered (out, _("Forward.\n"));
7545 fprintf_filtered (out, _("Reverse.\n"));
7548 internal_error (__FILE__, __LINE__,
7549 _("bogus execution_direction value: %d"),
7550 (int) execution_direction);
7555 show_schedule_multiple (struct ui_file *file, int from_tty,
7556 struct cmd_list_element *c, const char *value)
7558 fprintf_filtered (file, _("Resuming the execution of threads "
7559 "of all processes is %s.\n"), value);
7562 /* Implementation of `siginfo' variable. */
7564 static const struct internalvar_funcs siginfo_funcs =
7572 _initialize_infrun (void)
7576 struct cmd_list_element *c;
7578 add_info ("signals", signals_info, _("\
7579 What debugger does when program gets various signals.\n\
7580 Specify a signal as argument to print info on that signal only."));
7581 add_info_alias ("handle", "signals", 0);
7583 c = add_com ("handle", class_run, handle_command, _("\
7584 Specify how to handle signals.\n\
7585 Usage: handle SIGNAL [ACTIONS]\n\
7586 Args are signals and actions to apply to those signals.\n\
7587 If no actions are specified, the current settings for the specified signals\n\
7588 will be displayed instead.\n\
7590 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7591 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7592 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7593 The special arg \"all\" is recognized to mean all signals except those\n\
7594 used by the debugger, typically SIGTRAP and SIGINT.\n\
7596 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7597 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7598 Stop means reenter debugger if this signal happens (implies print).\n\
7599 Print means print a message if this signal happens.\n\
7600 Pass means let program see this signal; otherwise program doesn't know.\n\
7601 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7602 Pass and Stop may be combined.\n\
7604 Multiple signals may be specified. Signal numbers and signal names\n\
7605 may be interspersed with actions, with the actions being performed for\n\
7606 all signals cumulatively specified."));
7607 set_cmd_completer (c, handle_completer);
7611 add_com ("lz", class_info, signals_info, _("\
7612 What debugger does when program gets various signals.\n\
7613 Specify a signal as argument to print info on that signal only."));
7614 add_com ("z", class_run, xdb_handle_command, _("\
7615 Specify how to handle a signal.\n\
7616 Args are signals and actions to apply to those signals.\n\
7617 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7618 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7619 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7620 The special arg \"all\" is recognized to mean all signals except those\n\
7621 used by the debugger, typically SIGTRAP and SIGINT.\n\
7622 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7623 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7624 nopass), \"Q\" (noprint)\n\
7625 Stop means reenter debugger if this signal happens (implies print).\n\
7626 Print means print a message if this signal happens.\n\
7627 Pass means let program see this signal; otherwise program doesn't know.\n\
7628 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7629 Pass and Stop may be combined."));
7633 stop_command = add_cmd ("stop", class_obscure,
7634 not_just_help_class_command, _("\
7635 There is no `stop' command, but you can set a hook on `stop'.\n\
7636 This allows you to set a list of commands to be run each time execution\n\
7637 of the program stops."), &cmdlist);
7639 add_setshow_zuinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
7640 Set inferior debugging."), _("\
7641 Show inferior debugging."), _("\
7642 When non-zero, inferior specific debugging is enabled."),
7645 &setdebuglist, &showdebuglist);
7647 add_setshow_boolean_cmd ("displaced", class_maintenance,
7648 &debug_displaced, _("\
7649 Set displaced stepping debugging."), _("\
7650 Show displaced stepping debugging."), _("\
7651 When non-zero, displaced stepping specific debugging is enabled."),
7653 show_debug_displaced,
7654 &setdebuglist, &showdebuglist);
7656 add_setshow_boolean_cmd ("non-stop", no_class,
7658 Set whether gdb controls the inferior in non-stop mode."), _("\
7659 Show whether gdb controls the inferior in non-stop mode."), _("\
7660 When debugging a multi-threaded program and this setting is\n\
7661 off (the default, also called all-stop mode), when one thread stops\n\
7662 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7663 all other threads in the program while you interact with the thread of\n\
7664 interest. When you continue or step a thread, you can allow the other\n\
7665 threads to run, or have them remain stopped, but while you inspect any\n\
7666 thread's state, all threads stop.\n\
7668 In non-stop mode, when one thread stops, other threads can continue\n\
7669 to run freely. You'll be able to step each thread independently,\n\
7670 leave it stopped or free to run as needed."),
7676 numsigs = (int) GDB_SIGNAL_LAST;
7677 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
7678 signal_print = (unsigned char *)
7679 xmalloc (sizeof (signal_print[0]) * numsigs);
7680 signal_program = (unsigned char *)
7681 xmalloc (sizeof (signal_program[0]) * numsigs);
7682 signal_catch = (unsigned char *)
7683 xmalloc (sizeof (signal_catch[0]) * numsigs);
7684 signal_pass = (unsigned char *)
7685 xmalloc (sizeof (signal_pass[0]) * numsigs);
7686 for (i = 0; i < numsigs; i++)
7689 signal_print[i] = 1;
7690 signal_program[i] = 1;
7691 signal_catch[i] = 0;
7694 /* Signals caused by debugger's own actions
7695 should not be given to the program afterwards. */
7696 signal_program[GDB_SIGNAL_TRAP] = 0;
7697 signal_program[GDB_SIGNAL_INT] = 0;
7699 /* Signals that are not errors should not normally enter the debugger. */
7700 signal_stop[GDB_SIGNAL_ALRM] = 0;
7701 signal_print[GDB_SIGNAL_ALRM] = 0;
7702 signal_stop[GDB_SIGNAL_VTALRM] = 0;
7703 signal_print[GDB_SIGNAL_VTALRM] = 0;
7704 signal_stop[GDB_SIGNAL_PROF] = 0;
7705 signal_print[GDB_SIGNAL_PROF] = 0;
7706 signal_stop[GDB_SIGNAL_CHLD] = 0;
7707 signal_print[GDB_SIGNAL_CHLD] = 0;
7708 signal_stop[GDB_SIGNAL_IO] = 0;
7709 signal_print[GDB_SIGNAL_IO] = 0;
7710 signal_stop[GDB_SIGNAL_POLL] = 0;
7711 signal_print[GDB_SIGNAL_POLL] = 0;
7712 signal_stop[GDB_SIGNAL_URG] = 0;
7713 signal_print[GDB_SIGNAL_URG] = 0;
7714 signal_stop[GDB_SIGNAL_WINCH] = 0;
7715 signal_print[GDB_SIGNAL_WINCH] = 0;
7716 signal_stop[GDB_SIGNAL_PRIO] = 0;
7717 signal_print[GDB_SIGNAL_PRIO] = 0;
7719 /* These signals are used internally by user-level thread
7720 implementations. (See signal(5) on Solaris.) Like the above
7721 signals, a healthy program receives and handles them as part of
7722 its normal operation. */
7723 signal_stop[GDB_SIGNAL_LWP] = 0;
7724 signal_print[GDB_SIGNAL_LWP] = 0;
7725 signal_stop[GDB_SIGNAL_WAITING] = 0;
7726 signal_print[GDB_SIGNAL_WAITING] = 0;
7727 signal_stop[GDB_SIGNAL_CANCEL] = 0;
7728 signal_print[GDB_SIGNAL_CANCEL] = 0;
7730 /* Update cached state. */
7731 signal_cache_update (-1);
7733 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
7734 &stop_on_solib_events, _("\
7735 Set stopping for shared library events."), _("\
7736 Show stopping for shared library events."), _("\
7737 If nonzero, gdb will give control to the user when the dynamic linker\n\
7738 notifies gdb of shared library events. The most common event of interest\n\
7739 to the user would be loading/unloading of a new library."),
7740 set_stop_on_solib_events,
7741 show_stop_on_solib_events,
7742 &setlist, &showlist);
7744 add_setshow_enum_cmd ("follow-fork-mode", class_run,
7745 follow_fork_mode_kind_names,
7746 &follow_fork_mode_string, _("\
7747 Set debugger response to a program call of fork or vfork."), _("\
7748 Show debugger response to a program call of fork or vfork."), _("\
7749 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7750 parent - the original process is debugged after a fork\n\
7751 child - the new process is debugged after a fork\n\
7752 The unfollowed process will continue to run.\n\
7753 By default, the debugger will follow the parent process."),
7755 show_follow_fork_mode_string,
7756 &setlist, &showlist);
7758 add_setshow_enum_cmd ("follow-exec-mode", class_run,
7759 follow_exec_mode_names,
7760 &follow_exec_mode_string, _("\
7761 Set debugger response to a program call of exec."), _("\
7762 Show debugger response to a program call of exec."), _("\
7763 An exec call replaces the program image of a process.\n\
7765 follow-exec-mode can be:\n\
7767 new - the debugger creates a new inferior and rebinds the process\n\
7768 to this new inferior. The program the process was running before\n\
7769 the exec call can be restarted afterwards by restarting the original\n\
7772 same - the debugger keeps the process bound to the same inferior.\n\
7773 The new executable image replaces the previous executable loaded in\n\
7774 the inferior. Restarting the inferior after the exec call restarts\n\
7775 the executable the process was running after the exec call.\n\
7777 By default, the debugger will use the same inferior."),
7779 show_follow_exec_mode_string,
7780 &setlist, &showlist);
7782 add_setshow_enum_cmd ("scheduler-locking", class_run,
7783 scheduler_enums, &scheduler_mode, _("\
7784 Set mode for locking scheduler during execution."), _("\
7785 Show mode for locking scheduler during execution."), _("\
7786 off == no locking (threads may preempt at any time)\n\
7787 on == full locking (no thread except the current thread may run)\n\
7788 step == scheduler locked during every single-step operation.\n\
7789 In this mode, no other thread may run during a step command.\n\
7790 Other threads may run while stepping over a function call ('next')."),
7791 set_schedlock_func, /* traps on target vector */
7792 show_scheduler_mode,
7793 &setlist, &showlist);
7795 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
7796 Set mode for resuming threads of all processes."), _("\
7797 Show mode for resuming threads of all processes."), _("\
7798 When on, execution commands (such as 'continue' or 'next') resume all\n\
7799 threads of all processes. When off (which is the default), execution\n\
7800 commands only resume the threads of the current process. The set of\n\
7801 threads that are resumed is further refined by the scheduler-locking\n\
7802 mode (see help set scheduler-locking)."),
7804 show_schedule_multiple,
7805 &setlist, &showlist);
7807 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
7808 Set mode of the step operation."), _("\
7809 Show mode of the step operation."), _("\
7810 When set, doing a step over a function without debug line information\n\
7811 will stop at the first instruction of that function. Otherwise, the\n\
7812 function is skipped and the step command stops at a different source line."),
7814 show_step_stop_if_no_debug,
7815 &setlist, &showlist);
7817 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run,
7818 &can_use_displaced_stepping, _("\
7819 Set debugger's willingness to use displaced stepping."), _("\
7820 Show debugger's willingness to use displaced stepping."), _("\
7821 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7822 supported by the target architecture. If off, gdb will not use displaced\n\
7823 stepping to step over breakpoints, even if such is supported by the target\n\
7824 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7825 if the target architecture supports it and non-stop mode is active, but will not\n\
7826 use it in all-stop mode (see help set non-stop)."),
7828 show_can_use_displaced_stepping,
7829 &setlist, &showlist);
7831 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
7832 &exec_direction, _("Set direction of execution.\n\
7833 Options are 'forward' or 'reverse'."),
7834 _("Show direction of execution (forward/reverse)."),
7835 _("Tells gdb whether to execute forward or backward."),
7836 set_exec_direction_func, show_exec_direction_func,
7837 &setlist, &showlist);
7839 /* Set/show detach-on-fork: user-settable mode. */
7841 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
7842 Set whether gdb will detach the child of a fork."), _("\
7843 Show whether gdb will detach the child of a fork."), _("\
7844 Tells gdb whether to detach the child of a fork."),
7845 NULL, NULL, &setlist, &showlist);
7847 /* Set/show disable address space randomization mode. */
7849 add_setshow_boolean_cmd ("disable-randomization", class_support,
7850 &disable_randomization, _("\
7851 Set disabling of debuggee's virtual address space randomization."), _("\
7852 Show disabling of debuggee's virtual address space randomization."), _("\
7853 When this mode is on (which is the default), randomization of the virtual\n\
7854 address space is disabled. Standalone programs run with the randomization\n\
7855 enabled by default on some platforms."),
7856 &set_disable_randomization,
7857 &show_disable_randomization,
7858 &setlist, &showlist);
7860 /* ptid initializations */
7861 inferior_ptid = null_ptid;
7862 target_last_wait_ptid = minus_one_ptid;
7864 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
7865 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
7866 observer_attach_thread_exit (infrun_thread_thread_exit);
7867 observer_attach_inferior_exit (infrun_inferior_exit);
7869 /* Explicitly create without lookup, since that tries to create a
7870 value with a void typed value, and when we get here, gdbarch
7871 isn't initialized yet. At this point, we're quite sure there
7872 isn't another convenience variable of the same name. */
7873 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs, NULL);
7875 add_setshow_boolean_cmd ("observer", no_class,
7876 &observer_mode_1, _("\
7877 Set whether gdb controls the inferior in observer mode."), _("\
7878 Show whether gdb controls the inferior in observer mode."), _("\
7879 In observer mode, GDB can get data from the inferior, but not\n\
7880 affect its execution. Registers and memory may not be changed,\n\
7881 breakpoints may not be set, and the program cannot be interrupted\n\