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 /* Nonzero if we want to give control to the user when we're notified
330 of shared library events by the dynamic linker. */
331 int stop_on_solib_events;
333 /* Enable or disable optional shared library event breakpoints
334 as appropriate when the above flag is changed. */
337 set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c)
339 update_solib_breakpoints ();
343 show_stop_on_solib_events (struct ui_file *file, int from_tty,
344 struct cmd_list_element *c, const char *value)
346 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
350 /* Nonzero means expecting a trace trap
351 and should stop the inferior and return silently when it happens. */
355 /* Save register contents here when executing a "finish" command or are
356 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
357 Thus this contains the return value from the called function (assuming
358 values are returned in a register). */
360 struct regcache *stop_registers;
362 /* Nonzero after stop if current stack frame should be printed. */
364 static int stop_print_frame;
366 /* This is a cached copy of the pid/waitstatus of the last event
367 returned by target_wait()/deprecated_target_wait_hook(). This
368 information is returned by get_last_target_status(). */
369 static ptid_t target_last_wait_ptid;
370 static struct target_waitstatus target_last_waitstatus;
372 static void context_switch (ptid_t ptid);
374 void init_thread_stepping_state (struct thread_info *tss);
376 static const char follow_fork_mode_child[] = "child";
377 static const char follow_fork_mode_parent[] = "parent";
379 static const char *const follow_fork_mode_kind_names[] = {
380 follow_fork_mode_child,
381 follow_fork_mode_parent,
385 static const char *follow_fork_mode_string = follow_fork_mode_parent;
387 show_follow_fork_mode_string (struct ui_file *file, int from_tty,
388 struct cmd_list_element *c, const char *value)
390 fprintf_filtered (file,
391 _("Debugger response to a program "
392 "call of fork or vfork is \"%s\".\n"),
397 /* Handle changes to the inferior list based on the type of fork,
398 which process is being followed, and whether the other process
399 should be detached. On entry inferior_ptid must be the ptid of
400 the fork parent. At return inferior_ptid is the ptid of the
401 followed inferior. */
404 follow_fork_inferior (int follow_child, int detach_fork)
407 ptid_t parent_ptid, child_ptid;
409 has_vforked = (inferior_thread ()->pending_follow.kind
410 == TARGET_WAITKIND_VFORKED);
411 parent_ptid = inferior_ptid;
412 child_ptid = inferior_thread ()->pending_follow.value.related_pid;
415 && !non_stop /* Non-stop always resumes both branches. */
416 && (!target_is_async_p () || sync_execution)
417 && !(follow_child || detach_fork || sched_multi))
419 /* The parent stays blocked inside the vfork syscall until the
420 child execs or exits. If we don't let the child run, then
421 the parent stays blocked. If we're telling the parent to run
422 in the foreground, the user will not be able to ctrl-c to get
423 back the terminal, effectively hanging the debug session. */
424 fprintf_filtered (gdb_stderr, _("\
425 Can not resume the parent process over vfork in the foreground while\n\
426 holding the child stopped. Try \"set detach-on-fork\" or \
427 \"set schedule-multiple\".\n"));
428 /* FIXME output string > 80 columns. */
434 /* Detach new forked process? */
437 struct cleanup *old_chain;
439 /* Before detaching from the child, remove all breakpoints
440 from it. If we forked, then this has already been taken
441 care of by infrun.c. If we vforked however, any
442 breakpoint inserted in the parent is visible in the
443 child, even those added while stopped in a vfork
444 catchpoint. This will remove the breakpoints from the
445 parent also, but they'll be reinserted below. */
448 /* Keep breakpoints list in sync. */
449 remove_breakpoints_pid (ptid_get_pid (inferior_ptid));
452 if (info_verbose || debug_infrun)
454 target_terminal_ours_for_output ();
455 fprintf_filtered (gdb_stdlog,
456 _("Detaching after %s from child %s.\n"),
457 has_vforked ? "vfork" : "fork",
458 target_pid_to_str (child_ptid));
463 struct inferior *parent_inf, *child_inf;
464 struct cleanup *old_chain;
466 /* Add process to GDB's tables. */
467 child_inf = add_inferior (ptid_get_pid (child_ptid));
469 parent_inf = current_inferior ();
470 child_inf->attach_flag = parent_inf->attach_flag;
471 copy_terminal_info (child_inf, parent_inf);
472 child_inf->gdbarch = parent_inf->gdbarch;
473 copy_inferior_target_desc_info (child_inf, parent_inf);
475 old_chain = save_inferior_ptid ();
476 save_current_program_space ();
478 inferior_ptid = child_ptid;
479 add_thread (inferior_ptid);
480 child_inf->symfile_flags = SYMFILE_NO_READ;
482 /* If this is a vfork child, then the address-space is
483 shared with the parent. */
486 child_inf->pspace = parent_inf->pspace;
487 child_inf->aspace = parent_inf->aspace;
489 /* The parent will be frozen until the child is done
490 with the shared region. Keep track of the
492 child_inf->vfork_parent = parent_inf;
493 child_inf->pending_detach = 0;
494 parent_inf->vfork_child = child_inf;
495 parent_inf->pending_detach = 0;
499 child_inf->aspace = new_address_space ();
500 child_inf->pspace = add_program_space (child_inf->aspace);
501 child_inf->removable = 1;
502 set_current_program_space (child_inf->pspace);
503 clone_program_space (child_inf->pspace, parent_inf->pspace);
505 /* Let the shared library layer (e.g., solib-svr4) learn
506 about this new process, relocate the cloned exec, pull
507 in shared libraries, and install the solib event
508 breakpoint. If a "cloned-VM" event was propagated
509 better throughout the core, this wouldn't be
511 solib_create_inferior_hook (0);
514 do_cleanups (old_chain);
519 struct inferior *parent_inf;
521 parent_inf = current_inferior ();
523 /* If we detached from the child, then we have to be careful
524 to not insert breakpoints in the parent until the child
525 is done with the shared memory region. However, if we're
526 staying attached to the child, then we can and should
527 insert breakpoints, so that we can debug it. A
528 subsequent child exec or exit is enough to know when does
529 the child stops using the parent's address space. */
530 parent_inf->waiting_for_vfork_done = detach_fork;
531 parent_inf->pspace->breakpoints_not_allowed = detach_fork;
536 /* Follow the child. */
537 struct inferior *parent_inf, *child_inf;
538 struct program_space *parent_pspace;
540 if (info_verbose || debug_infrun)
542 target_terminal_ours_for_output ();
543 fprintf_filtered (gdb_stdlog,
544 _("Attaching after %s %s to child %s.\n"),
545 target_pid_to_str (parent_ptid),
546 has_vforked ? "vfork" : "fork",
547 target_pid_to_str (child_ptid));
550 /* Add the new inferior first, so that the target_detach below
551 doesn't unpush the target. */
553 child_inf = add_inferior (ptid_get_pid (child_ptid));
555 parent_inf = current_inferior ();
556 child_inf->attach_flag = parent_inf->attach_flag;
557 copy_terminal_info (child_inf, parent_inf);
558 child_inf->gdbarch = parent_inf->gdbarch;
559 copy_inferior_target_desc_info (child_inf, parent_inf);
561 parent_pspace = parent_inf->pspace;
563 /* If we're vforking, we want to hold on to the parent until the
564 child exits or execs. At child exec or exit time we can
565 remove the old breakpoints from the parent and detach or
566 resume debugging it. Otherwise, detach the parent now; we'll
567 want to reuse it's program/address spaces, but we can't set
568 them to the child before removing breakpoints from the
569 parent, otherwise, the breakpoints module could decide to
570 remove breakpoints from the wrong process (since they'd be
571 assigned to the same address space). */
575 gdb_assert (child_inf->vfork_parent == NULL);
576 gdb_assert (parent_inf->vfork_child == NULL);
577 child_inf->vfork_parent = parent_inf;
578 child_inf->pending_detach = 0;
579 parent_inf->vfork_child = child_inf;
580 parent_inf->pending_detach = detach_fork;
581 parent_inf->waiting_for_vfork_done = 0;
583 else if (detach_fork)
585 if (info_verbose || debug_infrun)
587 target_terminal_ours_for_output ();
588 fprintf_filtered (gdb_stdlog,
589 _("Detaching after fork from "
591 target_pid_to_str (child_ptid));
594 target_detach (NULL, 0);
597 /* Note that the detach above makes PARENT_INF dangling. */
599 /* Add the child thread to the appropriate lists, and switch to
600 this new thread, before cloning the program space, and
601 informing the solib layer about this new process. */
603 inferior_ptid = child_ptid;
604 add_thread (inferior_ptid);
606 /* If this is a vfork child, then the address-space is shared
607 with the parent. If we detached from the parent, then we can
608 reuse the parent's program/address spaces. */
609 if (has_vforked || detach_fork)
611 child_inf->pspace = parent_pspace;
612 child_inf->aspace = child_inf->pspace->aspace;
616 child_inf->aspace = new_address_space ();
617 child_inf->pspace = add_program_space (child_inf->aspace);
618 child_inf->removable = 1;
619 child_inf->symfile_flags = SYMFILE_NO_READ;
620 set_current_program_space (child_inf->pspace);
621 clone_program_space (child_inf->pspace, parent_pspace);
623 /* Let the shared library layer (e.g., solib-svr4) learn
624 about this new process, relocate the cloned exec, pull in
625 shared libraries, and install the solib event breakpoint.
626 If a "cloned-VM" event was propagated better throughout
627 the core, this wouldn't be required. */
628 solib_create_inferior_hook (0);
632 return target_follow_fork (follow_child, detach_fork);
635 /* Tell the target to follow the fork we're stopped at. Returns true
636 if the inferior should be resumed; false, if the target for some
637 reason decided it's best not to resume. */
642 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
643 int should_resume = 1;
644 struct thread_info *tp;
646 /* Copy user stepping state to the new inferior thread. FIXME: the
647 followed fork child thread should have a copy of most of the
648 parent thread structure's run control related fields, not just these.
649 Initialized to avoid "may be used uninitialized" warnings from gcc. */
650 struct breakpoint *step_resume_breakpoint = NULL;
651 struct breakpoint *exception_resume_breakpoint = NULL;
652 CORE_ADDR step_range_start = 0;
653 CORE_ADDR step_range_end = 0;
654 struct frame_id step_frame_id = { 0 };
655 struct interp *command_interp = NULL;
660 struct target_waitstatus wait_status;
662 /* Get the last target status returned by target_wait(). */
663 get_last_target_status (&wait_ptid, &wait_status);
665 /* If not stopped at a fork event, then there's nothing else to
667 if (wait_status.kind != TARGET_WAITKIND_FORKED
668 && wait_status.kind != TARGET_WAITKIND_VFORKED)
671 /* Check if we switched over from WAIT_PTID, since the event was
673 if (!ptid_equal (wait_ptid, minus_one_ptid)
674 && !ptid_equal (inferior_ptid, wait_ptid))
676 /* We did. Switch back to WAIT_PTID thread, to tell the
677 target to follow it (in either direction). We'll
678 afterwards refuse to resume, and inform the user what
680 switch_to_thread (wait_ptid);
685 tp = inferior_thread ();
687 /* If there were any forks/vforks that were caught and are now to be
688 followed, then do so now. */
689 switch (tp->pending_follow.kind)
691 case TARGET_WAITKIND_FORKED:
692 case TARGET_WAITKIND_VFORKED:
694 ptid_t parent, child;
696 /* If the user did a next/step, etc, over a fork call,
697 preserve the stepping state in the fork child. */
698 if (follow_child && should_resume)
700 step_resume_breakpoint = clone_momentary_breakpoint
701 (tp->control.step_resume_breakpoint);
702 step_range_start = tp->control.step_range_start;
703 step_range_end = tp->control.step_range_end;
704 step_frame_id = tp->control.step_frame_id;
705 exception_resume_breakpoint
706 = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint);
707 command_interp = tp->control.command_interp;
709 /* For now, delete the parent's sr breakpoint, otherwise,
710 parent/child sr breakpoints are considered duplicates,
711 and the child version will not be installed. Remove
712 this when the breakpoints module becomes aware of
713 inferiors and address spaces. */
714 delete_step_resume_breakpoint (tp);
715 tp->control.step_range_start = 0;
716 tp->control.step_range_end = 0;
717 tp->control.step_frame_id = null_frame_id;
718 delete_exception_resume_breakpoint (tp);
719 tp->control.command_interp = NULL;
722 parent = inferior_ptid;
723 child = tp->pending_follow.value.related_pid;
725 /* Set up inferior(s) as specified by the caller, and tell the
726 target to do whatever is necessary to follow either parent
728 if (follow_fork_inferior (follow_child, detach_fork))
730 /* Target refused to follow, or there's some other reason
731 we shouldn't resume. */
736 /* This pending follow fork event is now handled, one way
737 or another. The previous selected thread may be gone
738 from the lists by now, but if it is still around, need
739 to clear the pending follow request. */
740 tp = find_thread_ptid (parent);
742 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
744 /* This makes sure we don't try to apply the "Switched
745 over from WAIT_PID" logic above. */
746 nullify_last_target_wait_ptid ();
748 /* If we followed the child, switch to it... */
751 switch_to_thread (child);
753 /* ... and preserve the stepping state, in case the
754 user was stepping over the fork call. */
757 tp = inferior_thread ();
758 tp->control.step_resume_breakpoint
759 = step_resume_breakpoint;
760 tp->control.step_range_start = step_range_start;
761 tp->control.step_range_end = step_range_end;
762 tp->control.step_frame_id = step_frame_id;
763 tp->control.exception_resume_breakpoint
764 = exception_resume_breakpoint;
765 tp->control.command_interp = command_interp;
769 /* If we get here, it was because we're trying to
770 resume from a fork catchpoint, but, the user
771 has switched threads away from the thread that
772 forked. In that case, the resume command
773 issued is most likely not applicable to the
774 child, so just warn, and refuse to resume. */
775 warning (_("Not resuming: switched threads "
776 "before following fork child.\n"));
779 /* Reset breakpoints in the child as appropriate. */
780 follow_inferior_reset_breakpoints ();
783 switch_to_thread (parent);
787 case TARGET_WAITKIND_SPURIOUS:
788 /* Nothing to follow. */
791 internal_error (__FILE__, __LINE__,
792 "Unexpected pending_follow.kind %d\n",
793 tp->pending_follow.kind);
797 return should_resume;
801 follow_inferior_reset_breakpoints (void)
803 struct thread_info *tp = inferior_thread ();
805 /* Was there a step_resume breakpoint? (There was if the user
806 did a "next" at the fork() call.) If so, explicitly reset its
807 thread number. Cloned step_resume breakpoints are disabled on
808 creation, so enable it here now that it is associated with the
811 step_resumes are a form of bp that are made to be per-thread.
812 Since we created the step_resume bp when the parent process
813 was being debugged, and now are switching to the child process,
814 from the breakpoint package's viewpoint, that's a switch of
815 "threads". We must update the bp's notion of which thread
816 it is for, or it'll be ignored when it triggers. */
818 if (tp->control.step_resume_breakpoint)
820 breakpoint_re_set_thread (tp->control.step_resume_breakpoint);
821 tp->control.step_resume_breakpoint->loc->enabled = 1;
824 /* Treat exception_resume breakpoints like step_resume breakpoints. */
825 if (tp->control.exception_resume_breakpoint)
827 breakpoint_re_set_thread (tp->control.exception_resume_breakpoint);
828 tp->control.exception_resume_breakpoint->loc->enabled = 1;
831 /* Reinsert all breakpoints in the child. The user may have set
832 breakpoints after catching the fork, in which case those
833 were never set in the child, but only in the parent. This makes
834 sure the inserted breakpoints match the breakpoint list. */
836 breakpoint_re_set ();
837 insert_breakpoints ();
840 /* The child has exited or execed: resume threads of the parent the
841 user wanted to be executing. */
844 proceed_after_vfork_done (struct thread_info *thread,
847 int pid = * (int *) arg;
849 if (ptid_get_pid (thread->ptid) == pid
850 && is_running (thread->ptid)
851 && !is_executing (thread->ptid)
852 && !thread->stop_requested
853 && thread->suspend.stop_signal == GDB_SIGNAL_0)
856 fprintf_unfiltered (gdb_stdlog,
857 "infrun: resuming vfork parent thread %s\n",
858 target_pid_to_str (thread->ptid));
860 switch_to_thread (thread->ptid);
861 clear_proceed_status (0);
862 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
868 /* Called whenever we notice an exec or exit event, to handle
869 detaching or resuming a vfork parent. */
872 handle_vfork_child_exec_or_exit (int exec)
874 struct inferior *inf = current_inferior ();
876 if (inf->vfork_parent)
878 int resume_parent = -1;
880 /* This exec or exit marks the end of the shared memory region
881 between the parent and the child. If the user wanted to
882 detach from the parent, now is the time. */
884 if (inf->vfork_parent->pending_detach)
886 struct thread_info *tp;
887 struct cleanup *old_chain;
888 struct program_space *pspace;
889 struct address_space *aspace;
891 /* follow-fork child, detach-on-fork on. */
893 inf->vfork_parent->pending_detach = 0;
897 /* If we're handling a child exit, then inferior_ptid
898 points at the inferior's pid, not to a thread. */
899 old_chain = save_inferior_ptid ();
900 save_current_program_space ();
901 save_current_inferior ();
904 old_chain = save_current_space_and_thread ();
906 /* We're letting loose of the parent. */
907 tp = any_live_thread_of_process (inf->vfork_parent->pid);
908 switch_to_thread (tp->ptid);
910 /* We're about to detach from the parent, which implicitly
911 removes breakpoints from its address space. There's a
912 catch here: we want to reuse the spaces for the child,
913 but, parent/child are still sharing the pspace at this
914 point, although the exec in reality makes the kernel give
915 the child a fresh set of new pages. The problem here is
916 that the breakpoints module being unaware of this, would
917 likely chose the child process to write to the parent
918 address space. Swapping the child temporarily away from
919 the spaces has the desired effect. Yes, this is "sort
922 pspace = inf->pspace;
923 aspace = inf->aspace;
927 if (debug_infrun || info_verbose)
929 target_terminal_ours_for_output ();
933 fprintf_filtered (gdb_stdlog,
934 _("Detaching vfork parent process "
935 "%d after child exec.\n"),
936 inf->vfork_parent->pid);
940 fprintf_filtered (gdb_stdlog,
941 _("Detaching vfork parent process "
942 "%d after child exit.\n"),
943 inf->vfork_parent->pid);
947 target_detach (NULL, 0);
950 inf->pspace = pspace;
951 inf->aspace = aspace;
953 do_cleanups (old_chain);
957 /* We're staying attached to the parent, so, really give the
958 child a new address space. */
959 inf->pspace = add_program_space (maybe_new_address_space ());
960 inf->aspace = inf->pspace->aspace;
962 set_current_program_space (inf->pspace);
964 resume_parent = inf->vfork_parent->pid;
966 /* Break the bonds. */
967 inf->vfork_parent->vfork_child = NULL;
971 struct cleanup *old_chain;
972 struct program_space *pspace;
974 /* If this is a vfork child exiting, then the pspace and
975 aspaces were shared with the parent. Since we're
976 reporting the process exit, we'll be mourning all that is
977 found in the address space, and switching to null_ptid,
978 preparing to start a new inferior. But, since we don't
979 want to clobber the parent's address/program spaces, we
980 go ahead and create a new one for this exiting
983 /* Switch to null_ptid, so that clone_program_space doesn't want
984 to read the selected frame of a dead process. */
985 old_chain = save_inferior_ptid ();
986 inferior_ptid = null_ptid;
988 /* This inferior is dead, so avoid giving the breakpoints
989 module the option to write through to it (cloning a
990 program space resets breakpoints). */
993 pspace = add_program_space (maybe_new_address_space ());
994 set_current_program_space (pspace);
996 inf->symfile_flags = SYMFILE_NO_READ;
997 clone_program_space (pspace, inf->vfork_parent->pspace);
998 inf->pspace = pspace;
999 inf->aspace = pspace->aspace;
1001 /* Put back inferior_ptid. We'll continue mourning this
1003 do_cleanups (old_chain);
1005 resume_parent = inf->vfork_parent->pid;
1006 /* Break the bonds. */
1007 inf->vfork_parent->vfork_child = NULL;
1010 inf->vfork_parent = NULL;
1012 gdb_assert (current_program_space == inf->pspace);
1014 if (non_stop && resume_parent != -1)
1016 /* If the user wanted the parent to be running, let it go
1018 struct cleanup *old_chain = make_cleanup_restore_current_thread ();
1021 fprintf_unfiltered (gdb_stdlog,
1022 "infrun: resuming vfork parent process %d\n",
1025 iterate_over_threads (proceed_after_vfork_done, &resume_parent);
1027 do_cleanups (old_chain);
1032 /* Enum strings for "set|show follow-exec-mode". */
1034 static const char follow_exec_mode_new[] = "new";
1035 static const char follow_exec_mode_same[] = "same";
1036 static const char *const follow_exec_mode_names[] =
1038 follow_exec_mode_new,
1039 follow_exec_mode_same,
1043 static const char *follow_exec_mode_string = follow_exec_mode_same;
1045 show_follow_exec_mode_string (struct ui_file *file, int from_tty,
1046 struct cmd_list_element *c, const char *value)
1048 fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value);
1051 /* EXECD_PATHNAME is assumed to be non-NULL. */
1054 follow_exec (ptid_t ptid, char *execd_pathname)
1056 struct thread_info *th, *tmp;
1057 struct inferior *inf = current_inferior ();
1058 int pid = ptid_get_pid (ptid);
1060 /* This is an exec event that we actually wish to pay attention to.
1061 Refresh our symbol table to the newly exec'd program, remove any
1062 momentary bp's, etc.
1064 If there are breakpoints, they aren't really inserted now,
1065 since the exec() transformed our inferior into a fresh set
1068 We want to preserve symbolic breakpoints on the list, since
1069 we have hopes that they can be reset after the new a.out's
1070 symbol table is read.
1072 However, any "raw" breakpoints must be removed from the list
1073 (e.g., the solib bp's), since their address is probably invalid
1076 And, we DON'T want to call delete_breakpoints() here, since
1077 that may write the bp's "shadow contents" (the instruction
1078 value that was overwritten witha TRAP instruction). Since
1079 we now have a new a.out, those shadow contents aren't valid. */
1081 mark_breakpoints_out ();
1083 /* The target reports the exec event to the main thread, even if
1084 some other thread does the exec, and even if the main thread was
1085 stopped or already gone. We may still have non-leader threads of
1086 the process on our list. E.g., on targets that don't have thread
1087 exit events (like remote); or on native Linux in non-stop mode if
1088 there were only two threads in the inferior and the non-leader
1089 one is the one that execs (and nothing forces an update of the
1090 thread list up to here). When debugging remotely, it's best to
1091 avoid extra traffic, when possible, so avoid syncing the thread
1092 list with the target, and instead go ahead and delete all threads
1093 of the process but one that reported the event. Note this must
1094 be done before calling update_breakpoints_after_exec, as
1095 otherwise clearing the threads' resources would reference stale
1096 thread breakpoints -- it may have been one of these threads that
1097 stepped across the exec. We could just clear their stepping
1098 states, but as long as we're iterating, might as well delete
1099 them. Deleting them now rather than at the next user-visible
1100 stop provides a nicer sequence of events for user and MI
1102 ALL_NON_EXITED_THREADS_SAFE (th, tmp)
1103 if (ptid_get_pid (th->ptid) == pid && !ptid_equal (th->ptid, ptid))
1104 delete_thread (th->ptid);
1106 /* We also need to clear any left over stale state for the
1107 leader/event thread. E.g., if there was any step-resume
1108 breakpoint or similar, it's gone now. We cannot truly
1109 step-to-next statement through an exec(). */
1110 th = inferior_thread ();
1111 th->control.step_resume_breakpoint = NULL;
1112 th->control.exception_resume_breakpoint = NULL;
1113 th->control.single_step_breakpoints = NULL;
1114 th->control.step_range_start = 0;
1115 th->control.step_range_end = 0;
1117 /* The user may have had the main thread held stopped in the
1118 previous image (e.g., schedlock on, or non-stop). Release
1120 th->stop_requested = 0;
1122 update_breakpoints_after_exec ();
1124 /* What is this a.out's name? */
1125 printf_unfiltered (_("%s is executing new program: %s\n"),
1126 target_pid_to_str (inferior_ptid),
1129 /* We've followed the inferior through an exec. Therefore, the
1130 inferior has essentially been killed & reborn. */
1132 gdb_flush (gdb_stdout);
1134 breakpoint_init_inferior (inf_execd);
1136 if (gdb_sysroot && *gdb_sysroot)
1138 char *name = alloca (strlen (gdb_sysroot)
1139 + strlen (execd_pathname)
1142 strcpy (name, gdb_sysroot);
1143 strcat (name, execd_pathname);
1144 execd_pathname = name;
1147 /* Reset the shared library package. This ensures that we get a
1148 shlib event when the child reaches "_start", at which point the
1149 dld will have had a chance to initialize the child. */
1150 /* Also, loading a symbol file below may trigger symbol lookups, and
1151 we don't want those to be satisfied by the libraries of the
1152 previous incarnation of this process. */
1153 no_shared_libraries (NULL, 0);
1155 if (follow_exec_mode_string == follow_exec_mode_new)
1157 struct program_space *pspace;
1159 /* The user wants to keep the old inferior and program spaces
1160 around. Create a new fresh one, and switch to it. */
1162 inf = add_inferior (current_inferior ()->pid);
1163 pspace = add_program_space (maybe_new_address_space ());
1164 inf->pspace = pspace;
1165 inf->aspace = pspace->aspace;
1167 exit_inferior_num_silent (current_inferior ()->num);
1169 set_current_inferior (inf);
1170 set_current_program_space (pspace);
1174 /* The old description may no longer be fit for the new image.
1175 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1176 old description; we'll read a new one below. No need to do
1177 this on "follow-exec-mode new", as the old inferior stays
1178 around (its description is later cleared/refetched on
1180 target_clear_description ();
1183 gdb_assert (current_program_space == inf->pspace);
1185 /* That a.out is now the one to use. */
1186 exec_file_attach (execd_pathname, 0);
1188 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
1189 (Position Independent Executable) main symbol file will get applied by
1190 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
1191 the breakpoints with the zero displacement. */
1193 symbol_file_add (execd_pathname,
1195 | SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET),
1198 if ((inf->symfile_flags & SYMFILE_NO_READ) == 0)
1199 set_initial_language ();
1201 /* If the target can specify a description, read it. Must do this
1202 after flipping to the new executable (because the target supplied
1203 description must be compatible with the executable's
1204 architecture, and the old executable may e.g., be 32-bit, while
1205 the new one 64-bit), and before anything involving memory or
1207 target_find_description ();
1209 solib_create_inferior_hook (0);
1211 jit_inferior_created_hook ();
1213 breakpoint_re_set ();
1215 /* Reinsert all breakpoints. (Those which were symbolic have
1216 been reset to the proper address in the new a.out, thanks
1217 to symbol_file_command...). */
1218 insert_breakpoints ();
1220 /* The next resume of this inferior should bring it to the shlib
1221 startup breakpoints. (If the user had also set bp's on
1222 "main" from the old (parent) process, then they'll auto-
1223 matically get reset there in the new process.). */
1226 /* Info about an instruction that is being stepped over. */
1228 struct step_over_info
1230 /* If we're stepping past a breakpoint, this is the address space
1231 and address of the instruction the breakpoint is set at. We'll
1232 skip inserting all breakpoints here. Valid iff ASPACE is
1234 struct address_space *aspace;
1237 /* The instruction being stepped over triggers a nonsteppable
1238 watchpoint. If true, we'll skip inserting watchpoints. */
1239 int nonsteppable_watchpoint_p;
1242 /* The step-over info of the location that is being stepped over.
1244 Note that with async/breakpoint always-inserted mode, a user might
1245 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1246 being stepped over. As setting a new breakpoint inserts all
1247 breakpoints, we need to make sure the breakpoint being stepped over
1248 isn't inserted then. We do that by only clearing the step-over
1249 info when the step-over is actually finished (or aborted).
1251 Presently GDB can only step over one breakpoint at any given time.
1252 Given threads that can't run code in the same address space as the
1253 breakpoint's can't really miss the breakpoint, GDB could be taught
1254 to step-over at most one breakpoint per address space (so this info
1255 could move to the address space object if/when GDB is extended).
1256 The set of breakpoints being stepped over will normally be much
1257 smaller than the set of all breakpoints, so a flag in the
1258 breakpoint location structure would be wasteful. A separate list
1259 also saves complexity and run-time, as otherwise we'd have to go
1260 through all breakpoint locations clearing their flag whenever we
1261 start a new sequence. Similar considerations weigh against storing
1262 this info in the thread object. Plus, not all step overs actually
1263 have breakpoint locations -- e.g., stepping past a single-step
1264 breakpoint, or stepping to complete a non-continuable
1266 static struct step_over_info step_over_info;
1268 /* Record the address of the breakpoint/instruction we're currently
1272 set_step_over_info (struct address_space *aspace, CORE_ADDR address,
1273 int nonsteppable_watchpoint_p)
1275 step_over_info.aspace = aspace;
1276 step_over_info.address = address;
1277 step_over_info.nonsteppable_watchpoint_p = nonsteppable_watchpoint_p;
1280 /* Called when we're not longer stepping over a breakpoint / an
1281 instruction, so all breakpoints are free to be (re)inserted. */
1284 clear_step_over_info (void)
1286 step_over_info.aspace = NULL;
1287 step_over_info.address = 0;
1288 step_over_info.nonsteppable_watchpoint_p = 0;
1294 stepping_past_instruction_at (struct address_space *aspace,
1297 return (step_over_info.aspace != NULL
1298 && breakpoint_address_match (aspace, address,
1299 step_over_info.aspace,
1300 step_over_info.address));
1306 stepping_past_nonsteppable_watchpoint (void)
1308 return step_over_info.nonsteppable_watchpoint_p;
1311 /* Returns true if step-over info is valid. */
1314 step_over_info_valid_p (void)
1316 return (step_over_info.aspace != NULL
1317 || stepping_past_nonsteppable_watchpoint ());
1321 /* Displaced stepping. */
1323 /* In non-stop debugging mode, we must take special care to manage
1324 breakpoints properly; in particular, the traditional strategy for
1325 stepping a thread past a breakpoint it has hit is unsuitable.
1326 'Displaced stepping' is a tactic for stepping one thread past a
1327 breakpoint it has hit while ensuring that other threads running
1328 concurrently will hit the breakpoint as they should.
1330 The traditional way to step a thread T off a breakpoint in a
1331 multi-threaded program in all-stop mode is as follows:
1333 a0) Initially, all threads are stopped, and breakpoints are not
1335 a1) We single-step T, leaving breakpoints uninserted.
1336 a2) We insert breakpoints, and resume all threads.
1338 In non-stop debugging, however, this strategy is unsuitable: we
1339 don't want to have to stop all threads in the system in order to
1340 continue or step T past a breakpoint. Instead, we use displaced
1343 n0) Initially, T is stopped, other threads are running, and
1344 breakpoints are inserted.
1345 n1) We copy the instruction "under" the breakpoint to a separate
1346 location, outside the main code stream, making any adjustments
1347 to the instruction, register, and memory state as directed by
1349 n2) We single-step T over the instruction at its new location.
1350 n3) We adjust the resulting register and memory state as directed
1351 by T's architecture. This includes resetting T's PC to point
1352 back into the main instruction stream.
1355 This approach depends on the following gdbarch methods:
1357 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1358 indicate where to copy the instruction, and how much space must
1359 be reserved there. We use these in step n1.
1361 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1362 address, and makes any necessary adjustments to the instruction,
1363 register contents, and memory. We use this in step n1.
1365 - gdbarch_displaced_step_fixup adjusts registers and memory after
1366 we have successfuly single-stepped the instruction, to yield the
1367 same effect the instruction would have had if we had executed it
1368 at its original address. We use this in step n3.
1370 - gdbarch_displaced_step_free_closure provides cleanup.
1372 The gdbarch_displaced_step_copy_insn and
1373 gdbarch_displaced_step_fixup functions must be written so that
1374 copying an instruction with gdbarch_displaced_step_copy_insn,
1375 single-stepping across the copied instruction, and then applying
1376 gdbarch_displaced_insn_fixup should have the same effects on the
1377 thread's memory and registers as stepping the instruction in place
1378 would have. Exactly which responsibilities fall to the copy and
1379 which fall to the fixup is up to the author of those functions.
1381 See the comments in gdbarch.sh for details.
1383 Note that displaced stepping and software single-step cannot
1384 currently be used in combination, although with some care I think
1385 they could be made to. Software single-step works by placing
1386 breakpoints on all possible subsequent instructions; if the
1387 displaced instruction is a PC-relative jump, those breakpoints
1388 could fall in very strange places --- on pages that aren't
1389 executable, or at addresses that are not proper instruction
1390 boundaries. (We do generally let other threads run while we wait
1391 to hit the software single-step breakpoint, and they might
1392 encounter such a corrupted instruction.) One way to work around
1393 this would be to have gdbarch_displaced_step_copy_insn fully
1394 simulate the effect of PC-relative instructions (and return NULL)
1395 on architectures that use software single-stepping.
1397 In non-stop mode, we can have independent and simultaneous step
1398 requests, so more than one thread may need to simultaneously step
1399 over a breakpoint. The current implementation assumes there is
1400 only one scratch space per process. In this case, we have to
1401 serialize access to the scratch space. If thread A wants to step
1402 over a breakpoint, but we are currently waiting for some other
1403 thread to complete a displaced step, we leave thread A stopped and
1404 place it in the displaced_step_request_queue. Whenever a displaced
1405 step finishes, we pick the next thread in the queue and start a new
1406 displaced step operation on it. See displaced_step_prepare and
1407 displaced_step_fixup for details. */
1409 struct displaced_step_request
1412 struct displaced_step_request *next;
1415 /* Per-inferior displaced stepping state. */
1416 struct displaced_step_inferior_state
1418 /* Pointer to next in linked list. */
1419 struct displaced_step_inferior_state *next;
1421 /* The process this displaced step state refers to. */
1424 /* A queue of pending displaced stepping requests. One entry per
1425 thread that needs to do a displaced step. */
1426 struct displaced_step_request *step_request_queue;
1428 /* If this is not null_ptid, this is the thread carrying out a
1429 displaced single-step in process PID. This thread's state will
1430 require fixing up once it has completed its step. */
1433 /* The architecture the thread had when we stepped it. */
1434 struct gdbarch *step_gdbarch;
1436 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1437 for post-step cleanup. */
1438 struct displaced_step_closure *step_closure;
1440 /* The address of the original instruction, and the copy we
1442 CORE_ADDR step_original, step_copy;
1444 /* Saved contents of copy area. */
1445 gdb_byte *step_saved_copy;
1448 /* The list of states of processes involved in displaced stepping
1450 static struct displaced_step_inferior_state *displaced_step_inferior_states;
1452 /* Get the displaced stepping state of process PID. */
1454 static struct displaced_step_inferior_state *
1455 get_displaced_stepping_state (int pid)
1457 struct displaced_step_inferior_state *state;
1459 for (state = displaced_step_inferior_states;
1461 state = state->next)
1462 if (state->pid == pid)
1468 /* Add a new displaced stepping state for process PID to the displaced
1469 stepping state list, or return a pointer to an already existing
1470 entry, if it already exists. Never returns NULL. */
1472 static struct displaced_step_inferior_state *
1473 add_displaced_stepping_state (int pid)
1475 struct displaced_step_inferior_state *state;
1477 for (state = displaced_step_inferior_states;
1479 state = state->next)
1480 if (state->pid == pid)
1483 state = xcalloc (1, sizeof (*state));
1485 state->next = displaced_step_inferior_states;
1486 displaced_step_inferior_states = state;
1491 /* If inferior is in displaced stepping, and ADDR equals to starting address
1492 of copy area, return corresponding displaced_step_closure. Otherwise,
1495 struct displaced_step_closure*
1496 get_displaced_step_closure_by_addr (CORE_ADDR addr)
1498 struct displaced_step_inferior_state *displaced
1499 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1501 /* If checking the mode of displaced instruction in copy area. */
1502 if (displaced && !ptid_equal (displaced->step_ptid, null_ptid)
1503 && (displaced->step_copy == addr))
1504 return displaced->step_closure;
1509 /* Remove the displaced stepping state of process PID. */
1512 remove_displaced_stepping_state (int pid)
1514 struct displaced_step_inferior_state *it, **prev_next_p;
1516 gdb_assert (pid != 0);
1518 it = displaced_step_inferior_states;
1519 prev_next_p = &displaced_step_inferior_states;
1524 *prev_next_p = it->next;
1529 prev_next_p = &it->next;
1535 infrun_inferior_exit (struct inferior *inf)
1537 remove_displaced_stepping_state (inf->pid);
1540 /* If ON, and the architecture supports it, GDB will use displaced
1541 stepping to step over breakpoints. If OFF, or if the architecture
1542 doesn't support it, GDB will instead use the traditional
1543 hold-and-step approach. If AUTO (which is the default), GDB will
1544 decide which technique to use to step over breakpoints depending on
1545 which of all-stop or non-stop mode is active --- displaced stepping
1546 in non-stop mode; hold-and-step in all-stop mode. */
1548 static enum auto_boolean can_use_displaced_stepping = AUTO_BOOLEAN_AUTO;
1551 show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
1552 struct cmd_list_element *c,
1555 if (can_use_displaced_stepping == AUTO_BOOLEAN_AUTO)
1556 fprintf_filtered (file,
1557 _("Debugger's willingness to use displaced stepping "
1558 "to step over breakpoints is %s (currently %s).\n"),
1559 value, non_stop ? "on" : "off");
1561 fprintf_filtered (file,
1562 _("Debugger's willingness to use displaced stepping "
1563 "to step over breakpoints is %s.\n"), value);
1566 /* Return non-zero if displaced stepping can/should be used to step
1567 over breakpoints. */
1570 use_displaced_stepping (struct gdbarch *gdbarch)
1572 return (((can_use_displaced_stepping == AUTO_BOOLEAN_AUTO && non_stop)
1573 || can_use_displaced_stepping == AUTO_BOOLEAN_TRUE)
1574 && gdbarch_displaced_step_copy_insn_p (gdbarch)
1575 && find_record_target () == NULL);
1578 /* Clean out any stray displaced stepping state. */
1580 displaced_step_clear (struct displaced_step_inferior_state *displaced)
1582 /* Indicate that there is no cleanup pending. */
1583 displaced->step_ptid = null_ptid;
1585 if (displaced->step_closure)
1587 gdbarch_displaced_step_free_closure (displaced->step_gdbarch,
1588 displaced->step_closure);
1589 displaced->step_closure = NULL;
1594 displaced_step_clear_cleanup (void *arg)
1596 struct displaced_step_inferior_state *state = arg;
1598 displaced_step_clear (state);
1601 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1603 displaced_step_dump_bytes (struct ui_file *file,
1604 const gdb_byte *buf,
1609 for (i = 0; i < len; i++)
1610 fprintf_unfiltered (file, "%02x ", buf[i]);
1611 fputs_unfiltered ("\n", file);
1614 /* Prepare to single-step, using displaced stepping.
1616 Note that we cannot use displaced stepping when we have a signal to
1617 deliver. If we have a signal to deliver and an instruction to step
1618 over, then after the step, there will be no indication from the
1619 target whether the thread entered a signal handler or ignored the
1620 signal and stepped over the instruction successfully --- both cases
1621 result in a simple SIGTRAP. In the first case we mustn't do a
1622 fixup, and in the second case we must --- but we can't tell which.
1623 Comments in the code for 'random signals' in handle_inferior_event
1624 explain how we handle this case instead.
1626 Returns 1 if preparing was successful -- this thread is going to be
1627 stepped now; or 0 if displaced stepping this thread got queued. */
1629 displaced_step_prepare (ptid_t ptid)
1631 struct cleanup *old_cleanups, *ignore_cleanups;
1632 struct thread_info *tp = find_thread_ptid (ptid);
1633 struct regcache *regcache = get_thread_regcache (ptid);
1634 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1635 CORE_ADDR original, copy;
1637 struct displaced_step_closure *closure;
1638 struct displaced_step_inferior_state *displaced;
1641 /* We should never reach this function if the architecture does not
1642 support displaced stepping. */
1643 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
1645 /* Disable range stepping while executing in the scratch pad. We
1646 want a single-step even if executing the displaced instruction in
1647 the scratch buffer lands within the stepping range (e.g., a
1649 tp->control.may_range_step = 0;
1651 /* We have to displaced step one thread at a time, as we only have
1652 access to a single scratch space per inferior. */
1654 displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
1656 if (!ptid_equal (displaced->step_ptid, null_ptid))
1658 /* Already waiting for a displaced step to finish. Defer this
1659 request and place in queue. */
1660 struct displaced_step_request *req, *new_req;
1662 if (debug_displaced)
1663 fprintf_unfiltered (gdb_stdlog,
1664 "displaced: defering step of %s\n",
1665 target_pid_to_str (ptid));
1667 new_req = xmalloc (sizeof (*new_req));
1668 new_req->ptid = ptid;
1669 new_req->next = NULL;
1671 if (displaced->step_request_queue)
1673 for (req = displaced->step_request_queue;
1677 req->next = new_req;
1680 displaced->step_request_queue = new_req;
1686 if (debug_displaced)
1687 fprintf_unfiltered (gdb_stdlog,
1688 "displaced: stepping %s now\n",
1689 target_pid_to_str (ptid));
1692 displaced_step_clear (displaced);
1694 old_cleanups = save_inferior_ptid ();
1695 inferior_ptid = ptid;
1697 original = regcache_read_pc (regcache);
1699 copy = gdbarch_displaced_step_location (gdbarch);
1700 len = gdbarch_max_insn_length (gdbarch);
1702 /* Save the original contents of the copy area. */
1703 displaced->step_saved_copy = xmalloc (len);
1704 ignore_cleanups = make_cleanup (free_current_contents,
1705 &displaced->step_saved_copy);
1706 status = target_read_memory (copy, displaced->step_saved_copy, len);
1708 throw_error (MEMORY_ERROR,
1709 _("Error accessing memory address %s (%s) for "
1710 "displaced-stepping scratch space."),
1711 paddress (gdbarch, copy), safe_strerror (status));
1712 if (debug_displaced)
1714 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
1715 paddress (gdbarch, copy));
1716 displaced_step_dump_bytes (gdb_stdlog,
1717 displaced->step_saved_copy,
1721 closure = gdbarch_displaced_step_copy_insn (gdbarch,
1722 original, copy, regcache);
1724 /* We don't support the fully-simulated case at present. */
1725 gdb_assert (closure);
1727 /* Save the information we need to fix things up if the step
1729 displaced->step_ptid = ptid;
1730 displaced->step_gdbarch = gdbarch;
1731 displaced->step_closure = closure;
1732 displaced->step_original = original;
1733 displaced->step_copy = copy;
1735 make_cleanup (displaced_step_clear_cleanup, displaced);
1737 /* Resume execution at the copy. */
1738 regcache_write_pc (regcache, copy);
1740 discard_cleanups (ignore_cleanups);
1742 do_cleanups (old_cleanups);
1744 if (debug_displaced)
1745 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
1746 paddress (gdbarch, copy));
1752 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr,
1753 const gdb_byte *myaddr, int len)
1755 struct cleanup *ptid_cleanup = save_inferior_ptid ();
1757 inferior_ptid = ptid;
1758 write_memory (memaddr, myaddr, len);
1759 do_cleanups (ptid_cleanup);
1762 /* Restore the contents of the copy area for thread PTID. */
1765 displaced_step_restore (struct displaced_step_inferior_state *displaced,
1768 ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
1770 write_memory_ptid (ptid, displaced->step_copy,
1771 displaced->step_saved_copy, len);
1772 if (debug_displaced)
1773 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s %s\n",
1774 target_pid_to_str (ptid),
1775 paddress (displaced->step_gdbarch,
1776 displaced->step_copy));
1780 displaced_step_fixup (ptid_t event_ptid, enum gdb_signal signal)
1782 struct cleanup *old_cleanups;
1783 struct displaced_step_inferior_state *displaced
1784 = get_displaced_stepping_state (ptid_get_pid (event_ptid));
1786 /* Was any thread of this process doing a displaced step? */
1787 if (displaced == NULL)
1790 /* Was this event for the pid we displaced? */
1791 if (ptid_equal (displaced->step_ptid, null_ptid)
1792 || ! ptid_equal (displaced->step_ptid, event_ptid))
1795 old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
1797 displaced_step_restore (displaced, displaced->step_ptid);
1799 /* Did the instruction complete successfully? */
1800 if (signal == GDB_SIGNAL_TRAP)
1802 /* Fixup may need to read memory/registers. Switch to the
1803 thread that we're fixing up. */
1804 switch_to_thread (event_ptid);
1806 /* Fix up the resulting state. */
1807 gdbarch_displaced_step_fixup (displaced->step_gdbarch,
1808 displaced->step_closure,
1809 displaced->step_original,
1810 displaced->step_copy,
1811 get_thread_regcache (displaced->step_ptid));
1815 /* Since the instruction didn't complete, all we can do is
1817 struct regcache *regcache = get_thread_regcache (event_ptid);
1818 CORE_ADDR pc = regcache_read_pc (regcache);
1820 pc = displaced->step_original + (pc - displaced->step_copy);
1821 regcache_write_pc (regcache, pc);
1824 do_cleanups (old_cleanups);
1826 displaced->step_ptid = null_ptid;
1828 /* Are there any pending displaced stepping requests? If so, run
1829 one now. Leave the state object around, since we're likely to
1830 need it again soon. */
1831 while (displaced->step_request_queue)
1833 struct displaced_step_request *head;
1835 struct regcache *regcache;
1836 struct gdbarch *gdbarch;
1837 CORE_ADDR actual_pc;
1838 struct address_space *aspace;
1840 head = displaced->step_request_queue;
1842 displaced->step_request_queue = head->next;
1845 context_switch (ptid);
1847 regcache = get_thread_regcache (ptid);
1848 actual_pc = regcache_read_pc (regcache);
1849 aspace = get_regcache_aspace (regcache);
1851 if (breakpoint_here_p (aspace, actual_pc))
1853 if (debug_displaced)
1854 fprintf_unfiltered (gdb_stdlog,
1855 "displaced: stepping queued %s now\n",
1856 target_pid_to_str (ptid));
1858 displaced_step_prepare (ptid);
1860 gdbarch = get_regcache_arch (regcache);
1862 if (debug_displaced)
1864 CORE_ADDR actual_pc = regcache_read_pc (regcache);
1867 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1868 paddress (gdbarch, actual_pc));
1869 read_memory (actual_pc, buf, sizeof (buf));
1870 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1873 if (gdbarch_displaced_step_hw_singlestep (gdbarch,
1874 displaced->step_closure))
1875 target_resume (ptid, 1, GDB_SIGNAL_0);
1877 target_resume (ptid, 0, GDB_SIGNAL_0);
1879 /* Done, we're stepping a thread. */
1885 struct thread_info *tp = inferior_thread ();
1887 /* The breakpoint we were sitting under has since been
1889 tp->control.trap_expected = 0;
1891 /* Go back to what we were trying to do. */
1892 step = currently_stepping (tp);
1894 if (debug_displaced)
1895 fprintf_unfiltered (gdb_stdlog,
1896 "displaced: breakpoint is gone: %s, step(%d)\n",
1897 target_pid_to_str (tp->ptid), step);
1899 target_resume (ptid, step, GDB_SIGNAL_0);
1900 tp->suspend.stop_signal = GDB_SIGNAL_0;
1902 /* This request was discarded. See if there's any other
1903 thread waiting for its turn. */
1908 /* Update global variables holding ptids to hold NEW_PTID if they were
1909 holding OLD_PTID. */
1911 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
1913 struct displaced_step_request *it;
1914 struct displaced_step_inferior_state *displaced;
1916 if (ptid_equal (inferior_ptid, old_ptid))
1917 inferior_ptid = new_ptid;
1919 for (displaced = displaced_step_inferior_states;
1921 displaced = displaced->next)
1923 if (ptid_equal (displaced->step_ptid, old_ptid))
1924 displaced->step_ptid = new_ptid;
1926 for (it = displaced->step_request_queue; it; it = it->next)
1927 if (ptid_equal (it->ptid, old_ptid))
1928 it->ptid = new_ptid;
1935 /* Things to clean up if we QUIT out of resume (). */
1937 resume_cleanups (void *ignore)
1939 if (!ptid_equal (inferior_ptid, null_ptid))
1940 delete_single_step_breakpoints (inferior_thread ());
1945 static const char schedlock_off[] = "off";
1946 static const char schedlock_on[] = "on";
1947 static const char schedlock_step[] = "step";
1948 static const char *const scheduler_enums[] = {
1954 static const char *scheduler_mode = schedlock_off;
1956 show_scheduler_mode (struct ui_file *file, int from_tty,
1957 struct cmd_list_element *c, const char *value)
1959 fprintf_filtered (file,
1960 _("Mode for locking scheduler "
1961 "during execution is \"%s\".\n"),
1966 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
1968 if (!target_can_lock_scheduler)
1970 scheduler_mode = schedlock_off;
1971 error (_("Target '%s' cannot support this command."), target_shortname);
1975 /* True if execution commands resume all threads of all processes by
1976 default; otherwise, resume only threads of the current inferior
1978 int sched_multi = 0;
1980 /* Try to setup for software single stepping over the specified location.
1981 Return 1 if target_resume() should use hardware single step.
1983 GDBARCH the current gdbarch.
1984 PC the location to step over. */
1987 maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
1991 if (execution_direction == EXEC_FORWARD
1992 && gdbarch_software_single_step_p (gdbarch)
1993 && gdbarch_software_single_step (gdbarch, get_current_frame ()))
2003 user_visible_resume_ptid (int step)
2009 /* With non-stop mode on, threads are always handled
2011 resume_ptid = inferior_ptid;
2013 else if ((scheduler_mode == schedlock_on)
2014 || (scheduler_mode == schedlock_step && step))
2016 /* User-settable 'scheduler' mode requires solo thread
2018 resume_ptid = inferior_ptid;
2020 else if (!sched_multi && target_supports_multi_process ())
2022 /* Resume all threads of the current process (and none of other
2024 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
2028 /* Resume all threads of all processes. */
2029 resume_ptid = RESUME_ALL;
2035 /* Wrapper for target_resume, that handles infrun-specific
2039 do_target_resume (ptid_t resume_ptid, int step, enum gdb_signal sig)
2041 struct thread_info *tp = inferior_thread ();
2043 /* Install inferior's terminal modes. */
2044 target_terminal_inferior ();
2046 /* Avoid confusing the next resume, if the next stop/resume
2047 happens to apply to another thread. */
2048 tp->suspend.stop_signal = GDB_SIGNAL_0;
2050 /* Advise target which signals may be handled silently. If we have
2051 removed breakpoints because we are stepping over one (in any
2052 thread), we need to receive all signals to avoid accidentally
2053 skipping a breakpoint during execution of a signal handler. */
2054 if (step_over_info_valid_p ())
2055 target_pass_signals (0, NULL);
2057 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
2059 target_resume (resume_ptid, step, sig);
2062 /* Resume the inferior, but allow a QUIT. This is useful if the user
2063 wants to interrupt some lengthy single-stepping operation
2064 (for child processes, the SIGINT goes to the inferior, and so
2065 we get a SIGINT random_signal, but for remote debugging and perhaps
2066 other targets, that's not true).
2068 SIG is the signal to give the inferior (zero for none). */
2070 resume (enum gdb_signal sig)
2072 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
2073 struct regcache *regcache = get_current_regcache ();
2074 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2075 struct thread_info *tp = inferior_thread ();
2076 CORE_ADDR pc = regcache_read_pc (regcache);
2077 struct address_space *aspace = get_regcache_aspace (regcache);
2079 /* This represents the user's step vs continue request. When
2080 deciding whether "set scheduler-locking step" applies, it's the
2081 user's intention that counts. */
2082 const int user_step = tp->control.stepping_command;
2083 /* This represents what we'll actually request the target to do.
2084 This can decay from a step to a continue, if e.g., we need to
2085 implement single-stepping with breakpoints (software
2089 tp->stepped_breakpoint = 0;
2093 /* Depends on stepped_breakpoint. */
2094 step = currently_stepping (tp);
2096 if (current_inferior ()->waiting_for_vfork_done)
2098 /* Don't try to single-step a vfork parent that is waiting for
2099 the child to get out of the shared memory region (by exec'ing
2100 or exiting). This is particularly important on software
2101 single-step archs, as the child process would trip on the
2102 software single step breakpoint inserted for the parent
2103 process. Since the parent will not actually execute any
2104 instruction until the child is out of the shared region (such
2105 are vfork's semantics), it is safe to simply continue it.
2106 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2107 the parent, and tell it to `keep_going', which automatically
2108 re-sets it stepping. */
2110 fprintf_unfiltered (gdb_stdlog,
2111 "infrun: resume : clear step\n");
2116 fprintf_unfiltered (gdb_stdlog,
2117 "infrun: resume (step=%d, signal=%s), "
2118 "trap_expected=%d, current thread [%s] at %s\n",
2119 step, gdb_signal_to_symbol_string (sig),
2120 tp->control.trap_expected,
2121 target_pid_to_str (inferior_ptid),
2122 paddress (gdbarch, pc));
2124 /* Normally, by the time we reach `resume', the breakpoints are either
2125 removed or inserted, as appropriate. The exception is if we're sitting
2126 at a permanent breakpoint; we need to step over it, but permanent
2127 breakpoints can't be removed. So we have to test for it here. */
2128 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
2130 if (sig != GDB_SIGNAL_0)
2132 /* We have a signal to pass to the inferior. The resume
2133 may, or may not take us to the signal handler. If this
2134 is a step, we'll need to stop in the signal handler, if
2135 there's one, (if the target supports stepping into
2136 handlers), or in the next mainline instruction, if
2137 there's no handler. If this is a continue, we need to be
2138 sure to run the handler with all breakpoints inserted.
2139 In all cases, set a breakpoint at the current address
2140 (where the handler returns to), and once that breakpoint
2141 is hit, resume skipping the permanent breakpoint. If
2142 that breakpoint isn't hit, then we've stepped into the
2143 signal handler (or hit some other event). We'll delete
2144 the step-resume breakpoint then. */
2147 fprintf_unfiltered (gdb_stdlog,
2148 "infrun: resume: skipping permanent breakpoint, "
2149 "deliver signal first\n");
2151 clear_step_over_info ();
2152 tp->control.trap_expected = 0;
2154 if (tp->control.step_resume_breakpoint == NULL)
2156 /* Set a "high-priority" step-resume, as we don't want
2157 user breakpoints at PC to trigger (again) when this
2159 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2160 gdb_assert (tp->control.step_resume_breakpoint->loc->permanent);
2162 tp->step_after_step_resume_breakpoint = step;
2165 insert_breakpoints ();
2169 /* There's no signal to pass, we can go ahead and skip the
2170 permanent breakpoint manually. */
2172 fprintf_unfiltered (gdb_stdlog,
2173 "infrun: resume: skipping permanent breakpoint\n");
2174 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
2175 /* Update pc to reflect the new address from which we will
2176 execute instructions. */
2177 pc = regcache_read_pc (regcache);
2181 /* We've already advanced the PC, so the stepping part
2182 is done. Now we need to arrange for a trap to be
2183 reported to handle_inferior_event. Set a breakpoint
2184 at the current PC, and run to it. Don't update
2185 prev_pc, because if we end in
2186 switch_back_to_stepped_thread, we want the "expected
2187 thread advanced also" branch to be taken. IOW, we
2188 don't want this thread to step further from PC
2190 gdb_assert (!step_over_info_valid_p ());
2191 insert_single_step_breakpoint (gdbarch, aspace, pc);
2192 insert_breakpoints ();
2194 resume_ptid = user_visible_resume_ptid (user_step);
2195 do_target_resume (resume_ptid, 0, GDB_SIGNAL_0);
2196 discard_cleanups (old_cleanups);
2202 /* If we have a breakpoint to step over, make sure to do a single
2203 step only. Same if we have software watchpoints. */
2204 if (tp->control.trap_expected || bpstat_should_step ())
2205 tp->control.may_range_step = 0;
2207 /* If enabled, step over breakpoints by executing a copy of the
2208 instruction at a different address.
2210 We can't use displaced stepping when we have a signal to deliver;
2211 the comments for displaced_step_prepare explain why. The
2212 comments in the handle_inferior event for dealing with 'random
2213 signals' explain what we do instead.
2215 We can't use displaced stepping when we are waiting for vfork_done
2216 event, displaced stepping breaks the vfork child similarly as single
2217 step software breakpoint. */
2218 if (use_displaced_stepping (gdbarch)
2219 && tp->control.trap_expected
2220 && sig == GDB_SIGNAL_0
2221 && !current_inferior ()->waiting_for_vfork_done)
2223 struct displaced_step_inferior_state *displaced;
2225 if (!displaced_step_prepare (inferior_ptid))
2227 /* Got placed in displaced stepping queue. Will be resumed
2228 later when all the currently queued displaced stepping
2229 requests finish. The thread is not executing at this
2230 point, and the call to set_executing will be made later.
2231 But we need to call set_running here, since from the
2232 user/frontend's point of view, threads were set running.
2233 Unless we're calling an inferior function, as in that
2234 case we pretend the inferior doesn't run at all. */
2235 if (!tp->control.in_infcall)
2236 set_running (user_visible_resume_ptid (user_step), 1);
2237 discard_cleanups (old_cleanups);
2241 /* Update pc to reflect the new address from which we will execute
2242 instructions due to displaced stepping. */
2243 pc = regcache_read_pc (get_thread_regcache (inferior_ptid));
2245 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
2246 step = gdbarch_displaced_step_hw_singlestep (gdbarch,
2247 displaced->step_closure);
2250 /* Do we need to do it the hard way, w/temp breakpoints? */
2252 step = maybe_software_singlestep (gdbarch, pc);
2254 /* Currently, our software single-step implementation leads to different
2255 results than hardware single-stepping in one situation: when stepping
2256 into delivering a signal which has an associated signal handler,
2257 hardware single-step will stop at the first instruction of the handler,
2258 while software single-step will simply skip execution of the handler.
2260 For now, this difference in behavior is accepted since there is no
2261 easy way to actually implement single-stepping into a signal handler
2262 without kernel support.
2264 However, there is one scenario where this difference leads to follow-on
2265 problems: if we're stepping off a breakpoint by removing all breakpoints
2266 and then single-stepping. In this case, the software single-step
2267 behavior means that even if there is a *breakpoint* in the signal
2268 handler, GDB still would not stop.
2270 Fortunately, we can at least fix this particular issue. We detect
2271 here the case where we are about to deliver a signal while software
2272 single-stepping with breakpoints removed. In this situation, we
2273 revert the decisions to remove all breakpoints and insert single-
2274 step breakpoints, and instead we install a step-resume breakpoint
2275 at the current address, deliver the signal without stepping, and
2276 once we arrive back at the step-resume breakpoint, actually step
2277 over the breakpoint we originally wanted to step over. */
2278 if (thread_has_single_step_breakpoints_set (tp)
2279 && sig != GDB_SIGNAL_0
2280 && step_over_info_valid_p ())
2282 /* If we have nested signals or a pending signal is delivered
2283 immediately after a handler returns, might might already have
2284 a step-resume breakpoint set on the earlier handler. We cannot
2285 set another step-resume breakpoint; just continue on until the
2286 original breakpoint is hit. */
2287 if (tp->control.step_resume_breakpoint == NULL)
2289 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2290 tp->step_after_step_resume_breakpoint = 1;
2293 delete_single_step_breakpoints (tp);
2295 clear_step_over_info ();
2296 tp->control.trap_expected = 0;
2298 insert_breakpoints ();
2301 /* If STEP is set, it's a request to use hardware stepping
2302 facilities. But in that case, we should never
2303 use singlestep breakpoint. */
2304 gdb_assert (!(thread_has_single_step_breakpoints_set (tp) && step));
2306 /* Decide the set of threads to ask the target to resume. Start
2307 by assuming everything will be resumed, than narrow the set
2308 by applying increasingly restricting conditions. */
2309 resume_ptid = user_visible_resume_ptid (user_step);
2311 /* Even if RESUME_PTID is a wildcard, and we end up resuming less
2312 (e.g., we might need to step over a breakpoint), from the
2313 user/frontend's point of view, all threads in RESUME_PTID are now
2314 running. Unless we're calling an inferior function, as in that
2315 case pretend we inferior doesn't run at all. */
2316 if (!tp->control.in_infcall)
2317 set_running (resume_ptid, 1);
2319 /* Maybe resume a single thread after all. */
2320 if ((step || thread_has_single_step_breakpoints_set (tp))
2321 && tp->control.trap_expected)
2323 /* We're allowing a thread to run past a breakpoint it has
2324 hit, by single-stepping the thread with the breakpoint
2325 removed. In which case, we need to single-step only this
2326 thread, and keep others stopped, as they can miss this
2327 breakpoint if allowed to run. */
2328 resume_ptid = inferior_ptid;
2331 if (execution_direction != EXEC_REVERSE
2332 && step && breakpoint_inserted_here_p (aspace, pc))
2334 /* The only case we currently need to step a breakpoint
2335 instruction is when we have a signal to deliver. See
2336 handle_signal_stop where we handle random signals that could
2337 take out us out of the stepping range. Normally, in that
2338 case we end up continuing (instead of stepping) over the
2339 signal handler with a breakpoint at PC, but there are cases
2340 where we should _always_ single-step, even if we have a
2341 step-resume breakpoint, like when a software watchpoint is
2342 set. Assuming single-stepping and delivering a signal at the
2343 same time would takes us to the signal handler, then we could
2344 have removed the breakpoint at PC to step over it. However,
2345 some hardware step targets (like e.g., Mac OS) can't step
2346 into signal handlers, and for those, we need to leave the
2347 breakpoint at PC inserted, as otherwise if the handler
2348 recurses and executes PC again, it'll miss the breakpoint.
2349 So we leave the breakpoint inserted anyway, but we need to
2350 record that we tried to step a breakpoint instruction, so
2351 that adjust_pc_after_break doesn't end up confused. */
2352 gdb_assert (sig != GDB_SIGNAL_0);
2354 tp->stepped_breakpoint = 1;
2356 /* Most targets can step a breakpoint instruction, thus
2357 executing it normally. But if this one cannot, just
2358 continue and we will hit it anyway. */
2359 if (gdbarch_cannot_step_breakpoint (gdbarch))
2364 && use_displaced_stepping (gdbarch)
2365 && tp->control.trap_expected)
2367 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
2368 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
2369 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
2372 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
2373 paddress (resume_gdbarch, actual_pc));
2374 read_memory (actual_pc, buf, sizeof (buf));
2375 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
2378 if (tp->control.may_range_step)
2380 /* If we're resuming a thread with the PC out of the step
2381 range, then we're doing some nested/finer run control
2382 operation, like stepping the thread out of the dynamic
2383 linker or the displaced stepping scratch pad. We
2384 shouldn't have allowed a range step then. */
2385 gdb_assert (pc_in_thread_step_range (pc, tp));
2388 do_target_resume (resume_ptid, step, sig);
2389 discard_cleanups (old_cleanups);
2394 /* Clear out all variables saying what to do when inferior is continued.
2395 First do this, then set the ones you want, then call `proceed'. */
2398 clear_proceed_status_thread (struct thread_info *tp)
2401 fprintf_unfiltered (gdb_stdlog,
2402 "infrun: clear_proceed_status_thread (%s)\n",
2403 target_pid_to_str (tp->ptid));
2405 /* If this signal should not be seen by program, give it zero.
2406 Used for debugging signals. */
2407 if (!signal_pass_state (tp->suspend.stop_signal))
2408 tp->suspend.stop_signal = GDB_SIGNAL_0;
2410 tp->control.trap_expected = 0;
2411 tp->control.step_range_start = 0;
2412 tp->control.step_range_end = 0;
2413 tp->control.may_range_step = 0;
2414 tp->control.step_frame_id = null_frame_id;
2415 tp->control.step_stack_frame_id = null_frame_id;
2416 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
2417 tp->control.step_start_function = NULL;
2418 tp->stop_requested = 0;
2420 tp->control.stop_step = 0;
2422 tp->control.proceed_to_finish = 0;
2424 tp->control.command_interp = NULL;
2425 tp->control.stepping_command = 0;
2427 /* Discard any remaining commands or status from previous stop. */
2428 bpstat_clear (&tp->control.stop_bpstat);
2432 clear_proceed_status (int step)
2436 struct thread_info *tp;
2439 resume_ptid = user_visible_resume_ptid (step);
2441 /* In all-stop mode, delete the per-thread status of all threads
2442 we're about to resume, implicitly and explicitly. */
2443 ALL_NON_EXITED_THREADS (tp)
2445 if (!ptid_match (tp->ptid, resume_ptid))
2447 clear_proceed_status_thread (tp);
2451 if (!ptid_equal (inferior_ptid, null_ptid))
2453 struct inferior *inferior;
2457 /* If in non-stop mode, only delete the per-thread status of
2458 the current thread. */
2459 clear_proceed_status_thread (inferior_thread ());
2462 inferior = current_inferior ();
2463 inferior->control.stop_soon = NO_STOP_QUIETLY;
2466 stop_after_trap = 0;
2468 clear_step_over_info ();
2470 observer_notify_about_to_proceed ();
2474 regcache_xfree (stop_registers);
2475 stop_registers = NULL;
2479 /* Returns true if TP is still stopped at a breakpoint that needs
2480 stepping-over in order to make progress. If the breakpoint is gone
2481 meanwhile, we can skip the whole step-over dance. */
2484 thread_still_needs_step_over (struct thread_info *tp)
2486 if (tp->stepping_over_breakpoint)
2488 struct regcache *regcache = get_thread_regcache (tp->ptid);
2490 if (breakpoint_here_p (get_regcache_aspace (regcache),
2491 regcache_read_pc (regcache))
2492 == ordinary_breakpoint_here)
2495 tp->stepping_over_breakpoint = 0;
2501 /* Returns true if scheduler locking applies. STEP indicates whether
2502 we're about to do a step/next-like command to a thread. */
2505 schedlock_applies (struct thread_info *tp)
2507 return (scheduler_mode == schedlock_on
2508 || (scheduler_mode == schedlock_step
2509 && tp->control.stepping_command));
2512 /* Look a thread other than EXCEPT that has previously reported a
2513 breakpoint event, and thus needs a step-over in order to make
2514 progress. Returns NULL is none is found. */
2516 static struct thread_info *
2517 find_thread_needs_step_over (struct thread_info *except)
2519 struct thread_info *tp, *current;
2521 /* With non-stop mode on, threads are always handled individually. */
2522 gdb_assert (! non_stop);
2524 current = inferior_thread ();
2526 /* If scheduler locking applies, we can avoid iterating over all
2528 if (schedlock_applies (except))
2530 if (except != current
2531 && thread_still_needs_step_over (current))
2537 ALL_NON_EXITED_THREADS (tp)
2539 /* Ignore the EXCEPT thread. */
2542 /* Ignore threads of processes we're not resuming. */
2544 && ptid_get_pid (tp->ptid) != ptid_get_pid (inferior_ptid))
2547 if (thread_still_needs_step_over (tp))
2554 /* Basic routine for continuing the program in various fashions.
2556 ADDR is the address to resume at, or -1 for resume where stopped.
2557 SIGGNAL is the signal to give it, or 0 for none,
2558 or -1 for act according to how it stopped.
2559 STEP is nonzero if should trap after one instruction.
2560 -1 means return after that and print nothing.
2561 You should probably set various step_... variables
2562 before calling here, if you are stepping.
2564 You should call clear_proceed_status before calling proceed. */
2567 proceed (CORE_ADDR addr, enum gdb_signal siggnal)
2569 struct regcache *regcache;
2570 struct gdbarch *gdbarch;
2571 struct thread_info *tp;
2573 struct address_space *aspace;
2575 /* If we're stopped at a fork/vfork, follow the branch set by the
2576 "set follow-fork-mode" command; otherwise, we'll just proceed
2577 resuming the current thread. */
2578 if (!follow_fork ())
2580 /* The target for some reason decided not to resume. */
2582 if (target_can_async_p ())
2583 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2587 /* We'll update this if & when we switch to a new thread. */
2588 previous_inferior_ptid = inferior_ptid;
2590 regcache = get_current_regcache ();
2591 gdbarch = get_regcache_arch (regcache);
2592 aspace = get_regcache_aspace (regcache);
2593 pc = regcache_read_pc (regcache);
2594 tp = inferior_thread ();
2596 /* Fill in with reasonable starting values. */
2597 init_thread_stepping_state (tp);
2599 if (addr == (CORE_ADDR) -1)
2602 && breakpoint_here_p (aspace, pc) == ordinary_breakpoint_here
2603 && execution_direction != EXEC_REVERSE)
2604 /* There is a breakpoint at the address we will resume at,
2605 step one instruction before inserting breakpoints so that
2606 we do not stop right away (and report a second hit at this
2609 Note, we don't do this in reverse, because we won't
2610 actually be executing the breakpoint insn anyway.
2611 We'll be (un-)executing the previous instruction. */
2612 tp->stepping_over_breakpoint = 1;
2613 else if (gdbarch_single_step_through_delay_p (gdbarch)
2614 && gdbarch_single_step_through_delay (gdbarch,
2615 get_current_frame ()))
2616 /* We stepped onto an instruction that needs to be stepped
2617 again before re-inserting the breakpoint, do so. */
2618 tp->stepping_over_breakpoint = 1;
2622 regcache_write_pc (regcache, addr);
2625 if (siggnal != GDB_SIGNAL_DEFAULT)
2626 tp->suspend.stop_signal = siggnal;
2628 /* Record the interpreter that issued the execution command that
2629 caused this thread to resume. If the top level interpreter is
2630 MI/async, and the execution command was a CLI command
2631 (next/step/etc.), we'll want to print stop event output to the MI
2632 console channel (the stepped-to line, etc.), as if the user
2633 entered the execution command on a real GDB console. */
2634 inferior_thread ()->control.command_interp = command_interp ();
2637 fprintf_unfiltered (gdb_stdlog,
2638 "infrun: proceed (addr=%s, signal=%s)\n",
2639 paddress (gdbarch, addr),
2640 gdb_signal_to_symbol_string (siggnal));
2643 /* In non-stop, each thread is handled individually. The context
2644 must already be set to the right thread here. */
2648 struct thread_info *step_over;
2650 /* In a multi-threaded task we may select another thread and
2651 then continue or step.
2653 But if the old thread was stopped at a breakpoint, it will
2654 immediately cause another breakpoint stop without any
2655 execution (i.e. it will report a breakpoint hit incorrectly).
2656 So we must step over it first.
2658 Look for a thread other than the current (TP) that reported a
2659 breakpoint hit and hasn't been resumed yet since. */
2660 step_over = find_thread_needs_step_over (tp);
2661 if (step_over != NULL)
2664 fprintf_unfiltered (gdb_stdlog,
2665 "infrun: need to step-over [%s] first\n",
2666 target_pid_to_str (step_over->ptid));
2668 /* Store the prev_pc for the stepping thread too, needed by
2669 switch_back_to_stepped_thread. */
2670 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2671 switch_to_thread (step_over->ptid);
2676 /* If we need to step over a breakpoint, and we're not using
2677 displaced stepping to do so, insert all breakpoints (watchpoints,
2678 etc.) but the one we're stepping over, step one instruction, and
2679 then re-insert the breakpoint when that step is finished. */
2680 if (tp->stepping_over_breakpoint && !use_displaced_stepping (gdbarch))
2682 struct regcache *regcache = get_current_regcache ();
2684 set_step_over_info (get_regcache_aspace (regcache),
2685 regcache_read_pc (regcache), 0);
2688 clear_step_over_info ();
2690 insert_breakpoints ();
2692 tp->control.trap_expected = tp->stepping_over_breakpoint;
2694 annotate_starting ();
2696 /* Make sure that output from GDB appears before output from the
2698 gdb_flush (gdb_stdout);
2700 /* Refresh prev_pc value just prior to resuming. This used to be
2701 done in stop_waiting, however, setting prev_pc there did not handle
2702 scenarios such as inferior function calls or returning from
2703 a function via the return command. In those cases, the prev_pc
2704 value was not set properly for subsequent commands. The prev_pc value
2705 is used to initialize the starting line number in the ecs. With an
2706 invalid value, the gdb next command ends up stopping at the position
2707 represented by the next line table entry past our start position.
2708 On platforms that generate one line table entry per line, this
2709 is not a problem. However, on the ia64, the compiler generates
2710 extraneous line table entries that do not increase the line number.
2711 When we issue the gdb next command on the ia64 after an inferior call
2712 or a return command, we often end up a few instructions forward, still
2713 within the original line we started.
2715 An attempt was made to refresh the prev_pc at the same time the
2716 execution_control_state is initialized (for instance, just before
2717 waiting for an inferior event). But this approach did not work
2718 because of platforms that use ptrace, where the pc register cannot
2719 be read unless the inferior is stopped. At that point, we are not
2720 guaranteed the inferior is stopped and so the regcache_read_pc() call
2721 can fail. Setting the prev_pc value here ensures the value is updated
2722 correctly when the inferior is stopped. */
2723 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2725 /* Resume inferior. */
2726 resume (tp->suspend.stop_signal);
2728 /* Wait for it to stop (if not standalone)
2729 and in any case decode why it stopped, and act accordingly. */
2730 /* Do this only if we are not using the event loop, or if the target
2731 does not support asynchronous execution. */
2732 if (!target_can_async_p ())
2734 wait_for_inferior ();
2740 /* Start remote-debugging of a machine over a serial link. */
2743 start_remote (int from_tty)
2745 struct inferior *inferior;
2747 inferior = current_inferior ();
2748 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2750 /* Always go on waiting for the target, regardless of the mode. */
2751 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2752 indicate to wait_for_inferior that a target should timeout if
2753 nothing is returned (instead of just blocking). Because of this,
2754 targets expecting an immediate response need to, internally, set
2755 things up so that the target_wait() is forced to eventually
2757 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2758 differentiate to its caller what the state of the target is after
2759 the initial open has been performed. Here we're assuming that
2760 the target has stopped. It should be possible to eventually have
2761 target_open() return to the caller an indication that the target
2762 is currently running and GDB state should be set to the same as
2763 for an async run. */
2764 wait_for_inferior ();
2766 /* Now that the inferior has stopped, do any bookkeeping like
2767 loading shared libraries. We want to do this before normal_stop,
2768 so that the displayed frame is up to date. */
2769 post_create_inferior (¤t_target, from_tty);
2774 /* Initialize static vars when a new inferior begins. */
2777 init_wait_for_inferior (void)
2779 /* These are meaningless until the first time through wait_for_inferior. */
2781 breakpoint_init_inferior (inf_starting);
2783 clear_proceed_status (0);
2785 target_last_wait_ptid = minus_one_ptid;
2787 previous_inferior_ptid = inferior_ptid;
2789 /* Discard any skipped inlined frames. */
2790 clear_inline_frame_state (minus_one_ptid);
2794 /* Data to be passed around while handling an event. This data is
2795 discarded between events. */
2796 struct execution_control_state
2799 /* The thread that got the event, if this was a thread event; NULL
2801 struct thread_info *event_thread;
2803 struct target_waitstatus ws;
2804 int stop_func_filled_in;
2805 CORE_ADDR stop_func_start;
2806 CORE_ADDR stop_func_end;
2807 const char *stop_func_name;
2810 /* True if the event thread hit the single-step breakpoint of
2811 another thread. Thus the event doesn't cause a stop, the thread
2812 needs to be single-stepped past the single-step breakpoint before
2813 we can switch back to the original stepping thread. */
2814 int hit_singlestep_breakpoint;
2817 static void handle_inferior_event (struct execution_control_state *ecs);
2819 static void handle_step_into_function (struct gdbarch *gdbarch,
2820 struct execution_control_state *ecs);
2821 static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2822 struct execution_control_state *ecs);
2823 static void handle_signal_stop (struct execution_control_state *ecs);
2824 static void check_exception_resume (struct execution_control_state *,
2825 struct frame_info *);
2827 static void end_stepping_range (struct execution_control_state *ecs);
2828 static void stop_waiting (struct execution_control_state *ecs);
2829 static void prepare_to_wait (struct execution_control_state *ecs);
2830 static void keep_going (struct execution_control_state *ecs);
2831 static void process_event_stop_test (struct execution_control_state *ecs);
2832 static int switch_back_to_stepped_thread (struct execution_control_state *ecs);
2834 /* Callback for iterate over threads. If the thread is stopped, but
2835 the user/frontend doesn't know about that yet, go through
2836 normal_stop, as if the thread had just stopped now. ARG points at
2837 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2838 ptid_is_pid(PTID) is true, applies to all threads of the process
2839 pointed at by PTID. Otherwise, apply only to the thread pointed by
2843 infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2845 ptid_t ptid = * (ptid_t *) arg;
2847 if ((ptid_equal (info->ptid, ptid)
2848 || ptid_equal (minus_one_ptid, ptid)
2849 || (ptid_is_pid (ptid)
2850 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2851 && is_running (info->ptid)
2852 && !is_executing (info->ptid))
2854 struct cleanup *old_chain;
2855 struct execution_control_state ecss;
2856 struct execution_control_state *ecs = &ecss;
2858 memset (ecs, 0, sizeof (*ecs));
2860 old_chain = make_cleanup_restore_current_thread ();
2862 overlay_cache_invalid = 1;
2863 /* Flush target cache before starting to handle each event.
2864 Target was running and cache could be stale. This is just a
2865 heuristic. Running threads may modify target memory, but we
2866 don't get any event. */
2867 target_dcache_invalidate ();
2869 /* Go through handle_inferior_event/normal_stop, so we always
2870 have consistent output as if the stop event had been
2872 ecs->ptid = info->ptid;
2873 ecs->event_thread = find_thread_ptid (info->ptid);
2874 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2875 ecs->ws.value.sig = GDB_SIGNAL_0;
2877 handle_inferior_event (ecs);
2879 if (!ecs->wait_some_more)
2881 struct thread_info *tp;
2885 /* Finish off the continuations. */
2886 tp = inferior_thread ();
2887 do_all_intermediate_continuations_thread (tp, 1);
2888 do_all_continuations_thread (tp, 1);
2891 do_cleanups (old_chain);
2897 /* This function is attached as a "thread_stop_requested" observer.
2898 Cleanup local state that assumed the PTID was to be resumed, and
2899 report the stop to the frontend. */
2902 infrun_thread_stop_requested (ptid_t ptid)
2904 struct displaced_step_inferior_state *displaced;
2906 /* PTID was requested to stop. Remove it from the displaced
2907 stepping queue, so we don't try to resume it automatically. */
2909 for (displaced = displaced_step_inferior_states;
2911 displaced = displaced->next)
2913 struct displaced_step_request *it, **prev_next_p;
2915 it = displaced->step_request_queue;
2916 prev_next_p = &displaced->step_request_queue;
2919 if (ptid_match (it->ptid, ptid))
2921 *prev_next_p = it->next;
2927 prev_next_p = &it->next;
2934 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2938 infrun_thread_thread_exit (struct thread_info *tp, int silent)
2940 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2941 nullify_last_target_wait_ptid ();
2944 /* Delete the step resume, single-step and longjmp/exception resume
2945 breakpoints of TP. */
2948 delete_thread_infrun_breakpoints (struct thread_info *tp)
2950 delete_step_resume_breakpoint (tp);
2951 delete_exception_resume_breakpoint (tp);
2952 delete_single_step_breakpoints (tp);
2955 /* If the target still has execution, call FUNC for each thread that
2956 just stopped. In all-stop, that's all the non-exited threads; in
2957 non-stop, that's the current thread, only. */
2959 typedef void (*for_each_just_stopped_thread_callback_func)
2960 (struct thread_info *tp);
2963 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func)
2965 if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid))
2970 /* If in non-stop mode, only the current thread stopped. */
2971 func (inferior_thread ());
2975 struct thread_info *tp;
2977 /* In all-stop mode, all threads have stopped. */
2978 ALL_NON_EXITED_THREADS (tp)
2985 /* Delete the step resume and longjmp/exception resume breakpoints of
2986 the threads that just stopped. */
2989 delete_just_stopped_threads_infrun_breakpoints (void)
2991 for_each_just_stopped_thread (delete_thread_infrun_breakpoints);
2994 /* Delete the single-step breakpoints of the threads that just
2998 delete_just_stopped_threads_single_step_breakpoints (void)
3000 for_each_just_stopped_thread (delete_single_step_breakpoints);
3003 /* A cleanup wrapper. */
3006 delete_just_stopped_threads_infrun_breakpoints_cleanup (void *arg)
3008 delete_just_stopped_threads_infrun_breakpoints ();
3011 /* Pretty print the results of target_wait, for debugging purposes. */
3014 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
3015 const struct target_waitstatus *ws)
3017 char *status_string = target_waitstatus_to_string (ws);
3018 struct ui_file *tmp_stream = mem_fileopen ();
3021 /* The text is split over several lines because it was getting too long.
3022 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
3023 output as a unit; we want only one timestamp printed if debug_timestamp
3026 fprintf_unfiltered (tmp_stream,
3027 "infrun: target_wait (%d.%ld.%ld",
3028 ptid_get_pid (waiton_ptid),
3029 ptid_get_lwp (waiton_ptid),
3030 ptid_get_tid (waiton_ptid));
3031 if (ptid_get_pid (waiton_ptid) != -1)
3032 fprintf_unfiltered (tmp_stream,
3033 " [%s]", target_pid_to_str (waiton_ptid));
3034 fprintf_unfiltered (tmp_stream, ", status) =\n");
3035 fprintf_unfiltered (tmp_stream,
3036 "infrun: %d.%ld.%ld [%s],\n",
3037 ptid_get_pid (result_ptid),
3038 ptid_get_lwp (result_ptid),
3039 ptid_get_tid (result_ptid),
3040 target_pid_to_str (result_ptid));
3041 fprintf_unfiltered (tmp_stream,
3045 text = ui_file_xstrdup (tmp_stream, NULL);
3047 /* This uses %s in part to handle %'s in the text, but also to avoid
3048 a gcc error: the format attribute requires a string literal. */
3049 fprintf_unfiltered (gdb_stdlog, "%s", text);
3051 xfree (status_string);
3053 ui_file_delete (tmp_stream);
3056 /* Prepare and stabilize the inferior for detaching it. E.g.,
3057 detaching while a thread is displaced stepping is a recipe for
3058 crashing it, as nothing would readjust the PC out of the scratch
3062 prepare_for_detach (void)
3064 struct inferior *inf = current_inferior ();
3065 ptid_t pid_ptid = pid_to_ptid (inf->pid);
3066 struct cleanup *old_chain_1;
3067 struct displaced_step_inferior_state *displaced;
3069 displaced = get_displaced_stepping_state (inf->pid);
3071 /* Is any thread of this process displaced stepping? If not,
3072 there's nothing else to do. */
3073 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
3077 fprintf_unfiltered (gdb_stdlog,
3078 "displaced-stepping in-process while detaching");
3080 old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
3083 while (!ptid_equal (displaced->step_ptid, null_ptid))
3085 struct cleanup *old_chain_2;
3086 struct execution_control_state ecss;
3087 struct execution_control_state *ecs;
3090 memset (ecs, 0, sizeof (*ecs));
3092 overlay_cache_invalid = 1;
3093 /* Flush target cache before starting to handle each event.
3094 Target was running and cache could be stale. This is just a
3095 heuristic. Running threads may modify target memory, but we
3096 don't get any event. */
3097 target_dcache_invalidate ();
3099 if (deprecated_target_wait_hook)
3100 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
3102 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
3105 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
3107 /* If an error happens while handling the event, propagate GDB's
3108 knowledge of the executing state to the frontend/user running
3110 old_chain_2 = make_cleanup (finish_thread_state_cleanup,
3113 /* Now figure out what to do with the result of the result. */
3114 handle_inferior_event (ecs);
3116 /* No error, don't finish the state yet. */
3117 discard_cleanups (old_chain_2);
3119 /* Breakpoints and watchpoints are not installed on the target
3120 at this point, and signals are passed directly to the
3121 inferior, so this must mean the process is gone. */
3122 if (!ecs->wait_some_more)
3124 discard_cleanups (old_chain_1);
3125 error (_("Program exited while detaching"));
3129 discard_cleanups (old_chain_1);
3132 /* Wait for control to return from inferior to debugger.
3134 If inferior gets a signal, we may decide to start it up again
3135 instead of returning. That is why there is a loop in this function.
3136 When this function actually returns it means the inferior
3137 should be left stopped and GDB should read more commands. */
3140 wait_for_inferior (void)
3142 struct cleanup *old_cleanups;
3143 struct cleanup *thread_state_chain;
3147 (gdb_stdlog, "infrun: wait_for_inferior ()\n");
3150 = make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup,
3153 /* If an error happens while handling the event, propagate GDB's
3154 knowledge of the executing state to the frontend/user running
3156 thread_state_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
3160 struct execution_control_state ecss;
3161 struct execution_control_state *ecs = &ecss;
3162 ptid_t waiton_ptid = minus_one_ptid;
3164 memset (ecs, 0, sizeof (*ecs));
3166 overlay_cache_invalid = 1;
3168 /* Flush target cache before starting to handle each event.
3169 Target was running and cache could be stale. This is just a
3170 heuristic. Running threads may modify target memory, but we
3171 don't get any event. */
3172 target_dcache_invalidate ();
3174 if (deprecated_target_wait_hook)
3175 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
3177 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
3180 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
3182 /* Now figure out what to do with the result of the result. */
3183 handle_inferior_event (ecs);
3185 if (!ecs->wait_some_more)
3189 /* No error, don't finish the state yet. */
3190 discard_cleanups (thread_state_chain);
3192 do_cleanups (old_cleanups);
3195 /* Cleanup that reinstalls the readline callback handler, if the
3196 target is running in the background. If while handling the target
3197 event something triggered a secondary prompt, like e.g., a
3198 pagination prompt, we'll have removed the callback handler (see
3199 gdb_readline_wrapper_line). Need to do this as we go back to the
3200 event loop, ready to process further input. Note this has no
3201 effect if the handler hasn't actually been removed, because calling
3202 rl_callback_handler_install resets the line buffer, thus losing
3206 reinstall_readline_callback_handler_cleanup (void *arg)
3208 if (!interpreter_async)
3210 /* We're not going back to the top level event loop yet. Don't
3211 install the readline callback, as it'd prep the terminal,
3212 readline-style (raw, noecho) (e.g., --batch). We'll install
3213 it the next time the prompt is displayed, when we're ready
3218 if (async_command_editing_p && !sync_execution)
3219 gdb_rl_callback_handler_reinstall ();
3222 /* Asynchronous version of wait_for_inferior. It is called by the
3223 event loop whenever a change of state is detected on the file
3224 descriptor corresponding to the target. It can be called more than
3225 once to complete a single execution command. In such cases we need
3226 to keep the state in a global variable ECSS. If it is the last time
3227 that this function is called for a single execution command, then
3228 report to the user that the inferior has stopped, and do the
3229 necessary cleanups. */
3232 fetch_inferior_event (void *client_data)
3234 struct execution_control_state ecss;
3235 struct execution_control_state *ecs = &ecss;
3236 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
3237 struct cleanup *ts_old_chain;
3238 int was_sync = sync_execution;
3240 ptid_t waiton_ptid = minus_one_ptid;
3242 memset (ecs, 0, sizeof (*ecs));
3244 /* End up with readline processing input, if necessary. */
3245 make_cleanup (reinstall_readline_callback_handler_cleanup, NULL);
3247 /* We're handling a live event, so make sure we're doing live
3248 debugging. If we're looking at traceframes while the target is
3249 running, we're going to need to get back to that mode after
3250 handling the event. */
3253 make_cleanup_restore_current_traceframe ();
3254 set_current_traceframe (-1);
3258 /* In non-stop mode, the user/frontend should not notice a thread
3259 switch due to internal events. Make sure we reverse to the
3260 user selected thread and frame after handling the event and
3261 running any breakpoint commands. */
3262 make_cleanup_restore_current_thread ();
3264 overlay_cache_invalid = 1;
3265 /* Flush target cache before starting to handle each event. Target
3266 was running and cache could be stale. This is just a heuristic.
3267 Running threads may modify target memory, but we don't get any
3269 target_dcache_invalidate ();
3271 make_cleanup_restore_integer (&execution_direction);
3272 execution_direction = target_execution_direction ();
3274 if (deprecated_target_wait_hook)
3276 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
3278 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
3281 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
3283 /* If an error happens while handling the event, propagate GDB's
3284 knowledge of the executing state to the frontend/user running
3287 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
3289 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
3291 /* Get executed before make_cleanup_restore_current_thread above to apply
3292 still for the thread which has thrown the exception. */
3293 make_bpstat_clear_actions_cleanup ();
3295 make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup, NULL);
3297 /* Now figure out what to do with the result of the result. */
3298 handle_inferior_event (ecs);
3300 if (!ecs->wait_some_more)
3302 struct inferior *inf = find_inferior_ptid (ecs->ptid);
3304 delete_just_stopped_threads_infrun_breakpoints ();
3306 /* We may not find an inferior if this was a process exit. */
3307 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
3310 if (target_has_execution
3311 && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED
3312 && ecs->ws.kind != TARGET_WAITKIND_EXITED
3313 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3314 && ecs->event_thread->step_multi
3315 && ecs->event_thread->control.stop_step)
3316 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
3319 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
3324 /* No error, don't finish the thread states yet. */
3325 discard_cleanups (ts_old_chain);
3327 /* Revert thread and frame. */
3328 do_cleanups (old_chain);
3330 /* If the inferior was in sync execution mode, and now isn't,
3331 restore the prompt (a synchronous execution command has finished,
3332 and we're ready for input). */
3333 if (interpreter_async && was_sync && !sync_execution)
3334 observer_notify_sync_execution_done ();
3338 && exec_done_display_p
3339 && (ptid_equal (inferior_ptid, null_ptid)
3340 || !is_running (inferior_ptid)))
3341 printf_unfiltered (_("completed.\n"));
3344 /* Record the frame and location we're currently stepping through. */
3346 set_step_info (struct frame_info *frame, struct symtab_and_line sal)
3348 struct thread_info *tp = inferior_thread ();
3350 tp->control.step_frame_id = get_frame_id (frame);
3351 tp->control.step_stack_frame_id = get_stack_frame_id (frame);
3353 tp->current_symtab = sal.symtab;
3354 tp->current_line = sal.line;
3357 /* Clear context switchable stepping state. */
3360 init_thread_stepping_state (struct thread_info *tss)
3362 tss->stepped_breakpoint = 0;
3363 tss->stepping_over_breakpoint = 0;
3364 tss->stepping_over_watchpoint = 0;
3365 tss->step_after_step_resume_breakpoint = 0;
3368 /* Set the cached copy of the last ptid/waitstatus. */
3371 set_last_target_status (ptid_t ptid, struct target_waitstatus status)
3373 target_last_wait_ptid = ptid;
3374 target_last_waitstatus = status;
3377 /* Return the cached copy of the last pid/waitstatus returned by
3378 target_wait()/deprecated_target_wait_hook(). The data is actually
3379 cached by handle_inferior_event(), which gets called immediately
3380 after target_wait()/deprecated_target_wait_hook(). */
3383 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
3385 *ptidp = target_last_wait_ptid;
3386 *status = target_last_waitstatus;
3390 nullify_last_target_wait_ptid (void)
3392 target_last_wait_ptid = minus_one_ptid;
3395 /* Switch thread contexts. */
3398 context_switch (ptid_t ptid)
3400 if (debug_infrun && !ptid_equal (ptid, inferior_ptid))
3402 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
3403 target_pid_to_str (inferior_ptid));
3404 fprintf_unfiltered (gdb_stdlog, "to %s\n",
3405 target_pid_to_str (ptid));
3408 switch_to_thread (ptid);
3412 adjust_pc_after_break (struct execution_control_state *ecs)
3414 struct regcache *regcache;
3415 struct gdbarch *gdbarch;
3416 struct address_space *aspace;
3417 CORE_ADDR breakpoint_pc, decr_pc;
3419 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3420 we aren't, just return.
3422 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
3423 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3424 implemented by software breakpoints should be handled through the normal
3427 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3428 different signals (SIGILL or SIGEMT for instance), but it is less
3429 clear where the PC is pointing afterwards. It may not match
3430 gdbarch_decr_pc_after_break. I don't know any specific target that
3431 generates these signals at breakpoints (the code has been in GDB since at
3432 least 1992) so I can not guess how to handle them here.
3434 In earlier versions of GDB, a target with
3435 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
3436 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3437 target with both of these set in GDB history, and it seems unlikely to be
3438 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
3440 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
3443 if (ecs->ws.value.sig != GDB_SIGNAL_TRAP)
3446 /* In reverse execution, when a breakpoint is hit, the instruction
3447 under it has already been de-executed. The reported PC always
3448 points at the breakpoint address, so adjusting it further would
3449 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3452 B1 0x08000000 : INSN1
3453 B2 0x08000001 : INSN2
3455 PC -> 0x08000003 : INSN4
3457 Say you're stopped at 0x08000003 as above. Reverse continuing
3458 from that point should hit B2 as below. Reading the PC when the
3459 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3460 been de-executed already.
3462 B1 0x08000000 : INSN1
3463 B2 PC -> 0x08000001 : INSN2
3467 We can't apply the same logic as for forward execution, because
3468 we would wrongly adjust the PC to 0x08000000, since there's a
3469 breakpoint at PC - 1. We'd then report a hit on B1, although
3470 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3472 if (execution_direction == EXEC_REVERSE)
3475 /* If the target can tell whether the thread hit a SW breakpoint,
3476 trust it. Targets that can tell also adjust the PC
3478 if (target_supports_stopped_by_sw_breakpoint ())
3481 /* Note that relying on whether a breakpoint is planted in memory to
3482 determine this can fail. E.g,. the breakpoint could have been
3483 removed since. Or the thread could have been told to step an
3484 instruction the size of a breakpoint instruction, and only
3485 _after_ was a breakpoint inserted at its address. */
3487 /* If this target does not decrement the PC after breakpoints, then
3488 we have nothing to do. */
3489 regcache = get_thread_regcache (ecs->ptid);
3490 gdbarch = get_regcache_arch (regcache);
3492 decr_pc = gdbarch_decr_pc_after_break (gdbarch);
3496 aspace = get_regcache_aspace (regcache);
3498 /* Find the location where (if we've hit a breakpoint) the
3499 breakpoint would be. */
3500 breakpoint_pc = regcache_read_pc (regcache) - decr_pc;
3502 /* If the target can't tell whether a software breakpoint triggered,
3503 fallback to figuring it out based on breakpoints we think were
3504 inserted in the target, and on whether the thread was stepped or
3507 /* Check whether there actually is a software breakpoint inserted at
3510 If in non-stop mode, a race condition is possible where we've
3511 removed a breakpoint, but stop events for that breakpoint were
3512 already queued and arrive later. To suppress those spurious
3513 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3514 and retire them after a number of stop events are reported. Note
3515 this is an heuristic and can thus get confused. The real fix is
3516 to get the "stopped by SW BP and needs adjustment" info out of
3517 the target/kernel (and thus never reach here; see above). */
3518 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
3519 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
3521 struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
3523 if (record_full_is_used ())
3524 record_full_gdb_operation_disable_set ();
3526 /* When using hardware single-step, a SIGTRAP is reported for both
3527 a completed single-step and a software breakpoint. Need to
3528 differentiate between the two, as the latter needs adjusting
3529 but the former does not.
3531 The SIGTRAP can be due to a completed hardware single-step only if
3532 - we didn't insert software single-step breakpoints
3533 - this thread is currently being stepped
3535 If any of these events did not occur, we must have stopped due
3536 to hitting a software breakpoint, and have to back up to the
3539 As a special case, we could have hardware single-stepped a
3540 software breakpoint. In this case (prev_pc == breakpoint_pc),
3541 we also need to back up to the breakpoint address. */
3543 if (thread_has_single_step_breakpoints_set (ecs->event_thread)
3544 || !currently_stepping (ecs->event_thread)
3545 || (ecs->event_thread->stepped_breakpoint
3546 && ecs->event_thread->prev_pc == breakpoint_pc))
3547 regcache_write_pc (regcache, breakpoint_pc);
3549 do_cleanups (old_cleanups);
3554 stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
3556 for (frame = get_prev_frame (frame);
3558 frame = get_prev_frame (frame))
3560 if (frame_id_eq (get_frame_id (frame), step_frame_id))
3562 if (get_frame_type (frame) != INLINE_FRAME)
3569 /* Auxiliary function that handles syscall entry/return events.
3570 It returns 1 if the inferior should keep going (and GDB
3571 should ignore the event), or 0 if the event deserves to be
3575 handle_syscall_event (struct execution_control_state *ecs)
3577 struct regcache *regcache;
3580 if (!ptid_equal (ecs->ptid, inferior_ptid))
3581 context_switch (ecs->ptid);
3583 regcache = get_thread_regcache (ecs->ptid);
3584 syscall_number = ecs->ws.value.syscall_number;
3585 stop_pc = regcache_read_pc (regcache);
3587 if (catch_syscall_enabled () > 0
3588 && catching_syscall_number (syscall_number) > 0)
3591 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
3594 ecs->event_thread->control.stop_bpstat
3595 = bpstat_stop_status (get_regcache_aspace (regcache),
3596 stop_pc, ecs->ptid, &ecs->ws);
3598 if (bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
3600 /* Catchpoint hit. */
3605 /* If no catchpoint triggered for this, then keep going. */
3610 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3613 fill_in_stop_func (struct gdbarch *gdbarch,
3614 struct execution_control_state *ecs)
3616 if (!ecs->stop_func_filled_in)
3618 /* Don't care about return value; stop_func_start and stop_func_name
3619 will both be 0 if it doesn't work. */
3620 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3621 &ecs->stop_func_start, &ecs->stop_func_end);
3622 ecs->stop_func_start
3623 += gdbarch_deprecated_function_start_offset (gdbarch);
3625 if (gdbarch_skip_entrypoint_p (gdbarch))
3626 ecs->stop_func_start = gdbarch_skip_entrypoint (gdbarch,
3627 ecs->stop_func_start);
3629 ecs->stop_func_filled_in = 1;
3634 /* Return the STOP_SOON field of the inferior pointed at by PTID. */
3636 static enum stop_kind
3637 get_inferior_stop_soon (ptid_t ptid)
3639 struct inferior *inf = find_inferior_ptid (ptid);
3641 gdb_assert (inf != NULL);
3642 return inf->control.stop_soon;
3645 /* Given an execution control state that has been freshly filled in by
3646 an event from the inferior, figure out what it means and take
3649 The alternatives are:
3651 1) stop_waiting and return; to really stop and return to the
3654 2) keep_going and return; to wait for the next event (set
3655 ecs->event_thread->stepping_over_breakpoint to 1 to single step
3659 handle_inferior_event (struct execution_control_state *ecs)
3661 enum stop_kind stop_soon;
3663 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
3665 /* We had an event in the inferior, but we are not interested in
3666 handling it at this level. The lower layers have already
3667 done what needs to be done, if anything.
3669 One of the possible circumstances for this is when the
3670 inferior produces output for the console. The inferior has
3671 not stopped, and we are ignoring the event. Another possible
3672 circumstance is any event which the lower level knows will be
3673 reported multiple times without an intervening resume. */
3675 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
3676 prepare_to_wait (ecs);
3680 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED
3681 && target_can_async_p () && !sync_execution)
3683 /* There were no unwaited-for children left in the target, but,
3684 we're not synchronously waiting for events either. Just
3685 ignore. Otherwise, if we were running a synchronous
3686 execution command, we need to cancel it and give the user
3687 back the terminal. */
3689 fprintf_unfiltered (gdb_stdlog,
3690 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3691 prepare_to_wait (ecs);
3695 /* Cache the last pid/waitstatus. */
3696 set_last_target_status (ecs->ptid, ecs->ws);
3698 /* Always clear state belonging to the previous time we stopped. */
3699 stop_stack_dummy = STOP_NONE;
3701 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED)
3703 /* No unwaited-for children left. IOW, all resumed children
3706 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3708 stop_print_frame = 0;
3713 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3714 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
3716 ecs->event_thread = find_thread_ptid (ecs->ptid);
3717 /* If it's a new thread, add it to the thread database. */
3718 if (ecs->event_thread == NULL)
3719 ecs->event_thread = add_thread (ecs->ptid);
3721 /* Disable range stepping. If the next step request could use a
3722 range, this will be end up re-enabled then. */
3723 ecs->event_thread->control.may_range_step = 0;
3726 /* Dependent on valid ECS->EVENT_THREAD. */
3727 adjust_pc_after_break (ecs);
3729 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3730 reinit_frame_cache ();
3732 breakpoint_retire_moribund ();
3734 /* First, distinguish signals caused by the debugger from signals
3735 that have to do with the program's own actions. Note that
3736 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3737 on the operating system version. Here we detect when a SIGILL or
3738 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3739 something similar for SIGSEGV, since a SIGSEGV will be generated
3740 when we're trying to execute a breakpoint instruction on a
3741 non-executable stack. This happens for call dummy breakpoints
3742 for architectures like SPARC that place call dummies on the
3744 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
3745 && (ecs->ws.value.sig == GDB_SIGNAL_ILL
3746 || ecs->ws.value.sig == GDB_SIGNAL_SEGV
3747 || ecs->ws.value.sig == GDB_SIGNAL_EMT))
3749 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3751 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3752 regcache_read_pc (regcache)))
3755 fprintf_unfiltered (gdb_stdlog,
3756 "infrun: Treating signal as SIGTRAP\n");
3757 ecs->ws.value.sig = GDB_SIGNAL_TRAP;
3761 /* Mark the non-executing threads accordingly. In all-stop, all
3762 threads of all processes are stopped when we get any event
3763 reported. In non-stop mode, only the event thread stops. If
3764 we're handling a process exit in non-stop mode, there's nothing
3765 to do, as threads of the dead process are gone, and threads of
3766 any other process were left running. */
3768 set_executing (minus_one_ptid, 0);
3769 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3770 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
3771 set_executing (ecs->ptid, 0);
3773 switch (ecs->ws.kind)
3775 case TARGET_WAITKIND_LOADED:
3777 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
3778 if (!ptid_equal (ecs->ptid, inferior_ptid))
3779 context_switch (ecs->ptid);
3780 /* Ignore gracefully during startup of the inferior, as it might
3781 be the shell which has just loaded some objects, otherwise
3782 add the symbols for the newly loaded objects. Also ignore at
3783 the beginning of an attach or remote session; we will query
3784 the full list of libraries once the connection is
3787 stop_soon = get_inferior_stop_soon (ecs->ptid);
3788 if (stop_soon == NO_STOP_QUIETLY)
3790 struct regcache *regcache;
3792 regcache = get_thread_regcache (ecs->ptid);
3794 handle_solib_event ();
3796 ecs->event_thread->control.stop_bpstat
3797 = bpstat_stop_status (get_regcache_aspace (regcache),
3798 stop_pc, ecs->ptid, &ecs->ws);
3800 if (bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
3802 /* A catchpoint triggered. */
3803 process_event_stop_test (ecs);
3807 /* If requested, stop when the dynamic linker notifies
3808 gdb of events. This allows the user to get control
3809 and place breakpoints in initializer routines for
3810 dynamically loaded objects (among other things). */
3811 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
3812 if (stop_on_solib_events)
3814 /* Make sure we print "Stopped due to solib-event" in
3816 stop_print_frame = 1;
3823 /* If we are skipping through a shell, or through shared library
3824 loading that we aren't interested in, resume the program. If
3825 we're running the program normally, also resume. */
3826 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
3828 /* Loading of shared libraries might have changed breakpoint
3829 addresses. Make sure new breakpoints are inserted. */
3830 if (stop_soon == NO_STOP_QUIETLY)
3831 insert_breakpoints ();
3832 resume (GDB_SIGNAL_0);
3833 prepare_to_wait (ecs);
3837 /* But stop if we're attaching or setting up a remote
3839 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
3840 || stop_soon == STOP_QUIETLY_REMOTE)
3843 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
3848 internal_error (__FILE__, __LINE__,
3849 _("unhandled stop_soon: %d"), (int) stop_soon);
3851 case TARGET_WAITKIND_SPURIOUS:
3853 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3854 if (!ptid_equal (ecs->ptid, inferior_ptid))
3855 context_switch (ecs->ptid);
3856 resume (GDB_SIGNAL_0);
3857 prepare_to_wait (ecs);
3860 case TARGET_WAITKIND_EXITED:
3861 case TARGET_WAITKIND_SIGNALLED:
3864 if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3865 fprintf_unfiltered (gdb_stdlog,
3866 "infrun: TARGET_WAITKIND_EXITED\n");
3868 fprintf_unfiltered (gdb_stdlog,
3869 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3872 inferior_ptid = ecs->ptid;
3873 set_current_inferior (find_inferior_ptid (ecs->ptid));
3874 set_current_program_space (current_inferior ()->pspace);
3875 handle_vfork_child_exec_or_exit (0);
3876 target_terminal_ours (); /* Must do this before mourn anyway. */
3878 /* Clearing any previous state of convenience variables. */
3879 clear_exit_convenience_vars ();
3881 if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3883 /* Record the exit code in the convenience variable $_exitcode, so
3884 that the user can inspect this again later. */
3885 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3886 (LONGEST) ecs->ws.value.integer);
3888 /* Also record this in the inferior itself. */
3889 current_inferior ()->has_exit_code = 1;
3890 current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer;
3892 /* Support the --return-child-result option. */
3893 return_child_result_value = ecs->ws.value.integer;
3895 observer_notify_exited (ecs->ws.value.integer);
3899 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3900 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3902 if (gdbarch_gdb_signal_to_target_p (gdbarch))
3904 /* Set the value of the internal variable $_exitsignal,
3905 which holds the signal uncaught by the inferior. */
3906 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
3907 gdbarch_gdb_signal_to_target (gdbarch,
3908 ecs->ws.value.sig));
3912 /* We don't have access to the target's method used for
3913 converting between signal numbers (GDB's internal
3914 representation <-> target's representation).
3915 Therefore, we cannot do a good job at displaying this
3916 information to the user. It's better to just warn
3917 her about it (if infrun debugging is enabled), and
3920 fprintf_filtered (gdb_stdlog, _("\
3921 Cannot fill $_exitsignal with the correct signal number.\n"));
3924 observer_notify_signal_exited (ecs->ws.value.sig);
3927 gdb_flush (gdb_stdout);
3928 target_mourn_inferior ();
3929 stop_print_frame = 0;
3933 /* The following are the only cases in which we keep going;
3934 the above cases end in a continue or goto. */
3935 case TARGET_WAITKIND_FORKED:
3936 case TARGET_WAITKIND_VFORKED:
3939 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3940 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3942 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORKED\n");
3945 /* Check whether the inferior is displaced stepping. */
3947 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3948 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3949 struct displaced_step_inferior_state *displaced
3950 = get_displaced_stepping_state (ptid_get_pid (ecs->ptid));
3952 /* If checking displaced stepping is supported, and thread
3953 ecs->ptid is displaced stepping. */
3954 if (displaced && ptid_equal (displaced->step_ptid, ecs->ptid))
3956 struct inferior *parent_inf
3957 = find_inferior_ptid (ecs->ptid);
3958 struct regcache *child_regcache;
3959 CORE_ADDR parent_pc;
3961 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3962 indicating that the displaced stepping of syscall instruction
3963 has been done. Perform cleanup for parent process here. Note
3964 that this operation also cleans up the child process for vfork,
3965 because their pages are shared. */
3966 displaced_step_fixup (ecs->ptid, GDB_SIGNAL_TRAP);
3968 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3970 /* Restore scratch pad for child process. */
3971 displaced_step_restore (displaced, ecs->ws.value.related_pid);
3974 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3975 the child's PC is also within the scratchpad. Set the child's PC
3976 to the parent's PC value, which has already been fixed up.
3977 FIXME: we use the parent's aspace here, although we're touching
3978 the child, because the child hasn't been added to the inferior
3979 list yet at this point. */
3982 = get_thread_arch_aspace_regcache (ecs->ws.value.related_pid,
3984 parent_inf->aspace);
3985 /* Read PC value of parent process. */
3986 parent_pc = regcache_read_pc (regcache);
3988 if (debug_displaced)
3989 fprintf_unfiltered (gdb_stdlog,
3990 "displaced: write child pc from %s to %s\n",
3992 regcache_read_pc (child_regcache)),
3993 paddress (gdbarch, parent_pc));
3995 regcache_write_pc (child_regcache, parent_pc);
3999 if (!ptid_equal (ecs->ptid, inferior_ptid))
4000 context_switch (ecs->ptid);
4002 /* Immediately detach breakpoints from the child before there's
4003 any chance of letting the user delete breakpoints from the
4004 breakpoint lists. If we don't do this early, it's easy to
4005 leave left over traps in the child, vis: "break foo; catch
4006 fork; c; <fork>; del; c; <child calls foo>". We only follow
4007 the fork on the last `continue', and by that time the
4008 breakpoint at "foo" is long gone from the breakpoint table.
4009 If we vforked, then we don't need to unpatch here, since both
4010 parent and child are sharing the same memory pages; we'll
4011 need to unpatch at follow/detach time instead to be certain
4012 that new breakpoints added between catchpoint hit time and
4013 vfork follow are detached. */
4014 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
4016 /* This won't actually modify the breakpoint list, but will
4017 physically remove the breakpoints from the child. */
4018 detach_breakpoints (ecs->ws.value.related_pid);
4021 delete_just_stopped_threads_single_step_breakpoints ();
4023 /* In case the event is caught by a catchpoint, remember that
4024 the event is to be followed at the next resume of the thread,
4025 and not immediately. */
4026 ecs->event_thread->pending_follow = ecs->ws;
4028 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4030 ecs->event_thread->control.stop_bpstat
4031 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4032 stop_pc, ecs->ptid, &ecs->ws);
4034 /* If no catchpoint triggered for this, then keep going. Note
4035 that we're interested in knowing the bpstat actually causes a
4036 stop, not just if it may explain the signal. Software
4037 watchpoints, for example, always appear in the bpstat. */
4038 if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
4044 = (follow_fork_mode_string == follow_fork_mode_child);
4046 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4048 should_resume = follow_fork ();
4051 child = ecs->ws.value.related_pid;
4053 /* In non-stop mode, also resume the other branch. */
4054 if (non_stop && !detach_fork)
4057 switch_to_thread (parent);
4059 switch_to_thread (child);
4061 ecs->event_thread = inferior_thread ();
4062 ecs->ptid = inferior_ptid;
4067 switch_to_thread (child);
4069 switch_to_thread (parent);
4071 ecs->event_thread = inferior_thread ();
4072 ecs->ptid = inferior_ptid;
4080 process_event_stop_test (ecs);
4083 case TARGET_WAITKIND_VFORK_DONE:
4084 /* Done with the shared memory region. Re-insert breakpoints in
4085 the parent, and keep going. */
4088 fprintf_unfiltered (gdb_stdlog,
4089 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
4091 if (!ptid_equal (ecs->ptid, inferior_ptid))
4092 context_switch (ecs->ptid);
4094 current_inferior ()->waiting_for_vfork_done = 0;
4095 current_inferior ()->pspace->breakpoints_not_allowed = 0;
4096 /* This also takes care of reinserting breakpoints in the
4097 previously locked inferior. */
4101 case TARGET_WAITKIND_EXECD:
4103 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
4105 if (!ptid_equal (ecs->ptid, inferior_ptid))
4106 context_switch (ecs->ptid);
4108 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4110 /* Do whatever is necessary to the parent branch of the vfork. */
4111 handle_vfork_child_exec_or_exit (1);
4113 /* This causes the eventpoints and symbol table to be reset.
4114 Must do this now, before trying to determine whether to
4116 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
4118 ecs->event_thread->control.stop_bpstat
4119 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4120 stop_pc, ecs->ptid, &ecs->ws);
4122 /* Note that this may be referenced from inside
4123 bpstat_stop_status above, through inferior_has_execd. */
4124 xfree (ecs->ws.value.execd_pathname);
4125 ecs->ws.value.execd_pathname = NULL;
4127 /* If no catchpoint triggered for this, then keep going. */
4128 if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
4130 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4134 process_event_stop_test (ecs);
4137 /* Be careful not to try to gather much state about a thread
4138 that's in a syscall. It's frequently a losing proposition. */
4139 case TARGET_WAITKIND_SYSCALL_ENTRY:
4141 fprintf_unfiltered (gdb_stdlog,
4142 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
4143 /* Getting the current syscall number. */
4144 if (handle_syscall_event (ecs) == 0)
4145 process_event_stop_test (ecs);
4148 /* Before examining the threads further, step this thread to
4149 get it entirely out of the syscall. (We get notice of the
4150 event when the thread is just on the verge of exiting a
4151 syscall. Stepping one instruction seems to get it back
4153 case TARGET_WAITKIND_SYSCALL_RETURN:
4155 fprintf_unfiltered (gdb_stdlog,
4156 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
4157 if (handle_syscall_event (ecs) == 0)
4158 process_event_stop_test (ecs);
4161 case TARGET_WAITKIND_STOPPED:
4163 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
4164 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
4165 handle_signal_stop (ecs);
4168 case TARGET_WAITKIND_NO_HISTORY:
4170 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
4171 /* Reverse execution: target ran out of history info. */
4173 delete_just_stopped_threads_single_step_breakpoints ();
4174 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4175 observer_notify_no_history ();
4181 /* Come here when the program has stopped with a signal. */
4184 handle_signal_stop (struct execution_control_state *ecs)
4186 struct frame_info *frame;
4187 struct gdbarch *gdbarch;
4188 int stopped_by_watchpoint;
4189 enum stop_kind stop_soon;
4192 gdb_assert (ecs->ws.kind == TARGET_WAITKIND_STOPPED);
4194 /* Do we need to clean up the state of a thread that has
4195 completed a displaced single-step? (Doing so usually affects
4196 the PC, so do it here, before we set stop_pc.) */
4197 displaced_step_fixup (ecs->ptid,
4198 ecs->event_thread->suspend.stop_signal);
4200 /* If we either finished a single-step or hit a breakpoint, but
4201 the user wanted this thread to be stopped, pretend we got a
4202 SIG0 (generic unsignaled stop). */
4203 if (ecs->event_thread->stop_requested
4204 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
4205 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4207 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4211 struct regcache *regcache = get_thread_regcache (ecs->ptid);
4212 struct gdbarch *gdbarch = get_regcache_arch (regcache);
4213 struct cleanup *old_chain = save_inferior_ptid ();
4215 inferior_ptid = ecs->ptid;
4217 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
4218 paddress (gdbarch, stop_pc));
4219 if (target_stopped_by_watchpoint ())
4223 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
4225 if (target_stopped_data_address (¤t_target, &addr))
4226 fprintf_unfiltered (gdb_stdlog,
4227 "infrun: stopped data address = %s\n",
4228 paddress (gdbarch, addr));
4230 fprintf_unfiltered (gdb_stdlog,
4231 "infrun: (no data address available)\n");
4234 do_cleanups (old_chain);
4237 /* This is originated from start_remote(), start_inferior() and
4238 shared libraries hook functions. */
4239 stop_soon = get_inferior_stop_soon (ecs->ptid);
4240 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
4242 if (!ptid_equal (ecs->ptid, inferior_ptid))
4243 context_switch (ecs->ptid);
4245 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
4246 stop_print_frame = 1;
4251 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4254 if (!ptid_equal (ecs->ptid, inferior_ptid))
4255 context_switch (ecs->ptid);
4257 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
4258 stop_print_frame = 0;
4263 /* This originates from attach_command(). We need to overwrite
4264 the stop_signal here, because some kernels don't ignore a
4265 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4266 See more comments in inferior.h. On the other hand, if we
4267 get a non-SIGSTOP, report it to the user - assume the backend
4268 will handle the SIGSTOP if it should show up later.
4270 Also consider that the attach is complete when we see a
4271 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4272 target extended-remote report it instead of a SIGSTOP
4273 (e.g. gdbserver). We already rely on SIGTRAP being our
4274 signal, so this is no exception.
4276 Also consider that the attach is complete when we see a
4277 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4278 the target to stop all threads of the inferior, in case the
4279 low level attach operation doesn't stop them implicitly. If
4280 they weren't stopped implicitly, then the stub will report a
4281 GDB_SIGNAL_0, meaning: stopped for no particular reason
4282 other than GDB's request. */
4283 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
4284 && (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_STOP
4285 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4286 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_0))
4288 stop_print_frame = 1;
4290 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4294 /* See if something interesting happened to the non-current thread. If
4295 so, then switch to that thread. */
4296 if (!ptid_equal (ecs->ptid, inferior_ptid))
4299 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
4301 context_switch (ecs->ptid);
4303 if (deprecated_context_hook)
4304 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
4307 /* At this point, get hold of the now-current thread's frame. */
4308 frame = get_current_frame ();
4309 gdbarch = get_frame_arch (frame);
4311 /* Pull the single step breakpoints out of the target. */
4312 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
4314 struct regcache *regcache;
4315 struct address_space *aspace;
4318 regcache = get_thread_regcache (ecs->ptid);
4319 aspace = get_regcache_aspace (regcache);
4320 pc = regcache_read_pc (regcache);
4322 /* However, before doing so, if this single-step breakpoint was
4323 actually for another thread, set this thread up for moving
4325 if (!thread_has_single_step_breakpoint_here (ecs->event_thread,
4328 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4332 fprintf_unfiltered (gdb_stdlog,
4333 "infrun: [%s] hit another thread's "
4334 "single-step breakpoint\n",
4335 target_pid_to_str (ecs->ptid));
4337 ecs->hit_singlestep_breakpoint = 1;
4344 fprintf_unfiltered (gdb_stdlog,
4345 "infrun: [%s] hit its "
4346 "single-step breakpoint\n",
4347 target_pid_to_str (ecs->ptid));
4351 delete_just_stopped_threads_single_step_breakpoints ();
4353 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4354 && ecs->event_thread->control.trap_expected
4355 && ecs->event_thread->stepping_over_watchpoint)
4356 stopped_by_watchpoint = 0;
4358 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
4360 /* If necessary, step over this watchpoint. We'll be back to display
4362 if (stopped_by_watchpoint
4363 && (target_have_steppable_watchpoint
4364 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
4366 /* At this point, we are stopped at an instruction which has
4367 attempted to write to a piece of memory under control of
4368 a watchpoint. The instruction hasn't actually executed
4369 yet. If we were to evaluate the watchpoint expression
4370 now, we would get the old value, and therefore no change
4371 would seem to have occurred.
4373 In order to make watchpoints work `right', we really need
4374 to complete the memory write, and then evaluate the
4375 watchpoint expression. We do this by single-stepping the
4378 It may not be necessary to disable the watchpoint to step over
4379 it. For example, the PA can (with some kernel cooperation)
4380 single step over a watchpoint without disabling the watchpoint.
4382 It is far more common to need to disable a watchpoint to step
4383 the inferior over it. If we have non-steppable watchpoints,
4384 we must disable the current watchpoint; it's simplest to
4385 disable all watchpoints.
4387 Any breakpoint at PC must also be stepped over -- if there's
4388 one, it will have already triggered before the watchpoint
4389 triggered, and we either already reported it to the user, or
4390 it didn't cause a stop and we called keep_going. In either
4391 case, if there was a breakpoint at PC, we must be trying to
4393 ecs->event_thread->stepping_over_watchpoint = 1;
4398 ecs->event_thread->stepping_over_breakpoint = 0;
4399 ecs->event_thread->stepping_over_watchpoint = 0;
4400 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
4401 ecs->event_thread->control.stop_step = 0;
4402 stop_print_frame = 1;
4403 stopped_by_random_signal = 0;
4405 /* Hide inlined functions starting here, unless we just performed stepi or
4406 nexti. After stepi and nexti, always show the innermost frame (not any
4407 inline function call sites). */
4408 if (ecs->event_thread->control.step_range_end != 1)
4410 struct address_space *aspace =
4411 get_regcache_aspace (get_thread_regcache (ecs->ptid));
4413 /* skip_inline_frames is expensive, so we avoid it if we can
4414 determine that the address is one where functions cannot have
4415 been inlined. This improves performance with inferiors that
4416 load a lot of shared libraries, because the solib event
4417 breakpoint is defined as the address of a function (i.e. not
4418 inline). Note that we have to check the previous PC as well
4419 as the current one to catch cases when we have just
4420 single-stepped off a breakpoint prior to reinstating it.
4421 Note that we're assuming that the code we single-step to is
4422 not inline, but that's not definitive: there's nothing
4423 preventing the event breakpoint function from containing
4424 inlined code, and the single-step ending up there. If the
4425 user had set a breakpoint on that inlined code, the missing
4426 skip_inline_frames call would break things. Fortunately
4427 that's an extremely unlikely scenario. */
4428 if (!pc_at_non_inline_function (aspace, stop_pc, &ecs->ws)
4429 && !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4430 && ecs->event_thread->control.trap_expected
4431 && pc_at_non_inline_function (aspace,
4432 ecs->event_thread->prev_pc,
4435 skip_inline_frames (ecs->ptid);
4437 /* Re-fetch current thread's frame in case that invalidated
4439 frame = get_current_frame ();
4440 gdbarch = get_frame_arch (frame);
4444 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4445 && ecs->event_thread->control.trap_expected
4446 && gdbarch_single_step_through_delay_p (gdbarch)
4447 && currently_stepping (ecs->event_thread))
4449 /* We're trying to step off a breakpoint. Turns out that we're
4450 also on an instruction that needs to be stepped multiple
4451 times before it's been fully executing. E.g., architectures
4452 with a delay slot. It needs to be stepped twice, once for
4453 the instruction and once for the delay slot. */
4454 int step_through_delay
4455 = gdbarch_single_step_through_delay (gdbarch, frame);
4457 if (debug_infrun && step_through_delay)
4458 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
4459 if (ecs->event_thread->control.step_range_end == 0
4460 && step_through_delay)
4462 /* The user issued a continue when stopped at a breakpoint.
4463 Set up for another trap and get out of here. */
4464 ecs->event_thread->stepping_over_breakpoint = 1;
4468 else if (step_through_delay)
4470 /* The user issued a step when stopped at a breakpoint.
4471 Maybe we should stop, maybe we should not - the delay
4472 slot *might* correspond to a line of source. In any
4473 case, don't decide that here, just set
4474 ecs->stepping_over_breakpoint, making sure we
4475 single-step again before breakpoints are re-inserted. */
4476 ecs->event_thread->stepping_over_breakpoint = 1;
4480 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4481 handles this event. */
4482 ecs->event_thread->control.stop_bpstat
4483 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4484 stop_pc, ecs->ptid, &ecs->ws);
4486 /* Following in case break condition called a
4488 stop_print_frame = 1;
4490 /* This is where we handle "moribund" watchpoints. Unlike
4491 software breakpoints traps, hardware watchpoint traps are
4492 always distinguishable from random traps. If no high-level
4493 watchpoint is associated with the reported stop data address
4494 anymore, then the bpstat does not explain the signal ---
4495 simply make sure to ignore it if `stopped_by_watchpoint' is
4499 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4500 && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4502 && stopped_by_watchpoint)
4503 fprintf_unfiltered (gdb_stdlog,
4504 "infrun: no user watchpoint explains "
4505 "watchpoint SIGTRAP, ignoring\n");
4507 /* NOTE: cagney/2003-03-29: These checks for a random signal
4508 at one stage in the past included checks for an inferior
4509 function call's call dummy's return breakpoint. The original
4510 comment, that went with the test, read:
4512 ``End of a stack dummy. Some systems (e.g. Sony news) give
4513 another signal besides SIGTRAP, so check here as well as
4516 If someone ever tries to get call dummys on a
4517 non-executable stack to work (where the target would stop
4518 with something like a SIGSEGV), then those tests might need
4519 to be re-instated. Given, however, that the tests were only
4520 enabled when momentary breakpoints were not being used, I
4521 suspect that it won't be the case.
4523 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4524 be necessary for call dummies on a non-executable stack on
4527 /* See if the breakpoints module can explain the signal. */
4529 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4530 ecs->event_thread->suspend.stop_signal);
4532 /* Maybe this was a trap for a software breakpoint that has since
4534 if (random_signal && target_stopped_by_sw_breakpoint ())
4536 if (program_breakpoint_here_p (gdbarch, stop_pc))
4538 struct regcache *regcache;
4541 /* Re-adjust PC to what the program would see if GDB was not
4543 regcache = get_thread_regcache (ecs->event_thread->ptid);
4544 decr_pc = gdbarch_decr_pc_after_break (gdbarch);
4547 struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
4549 if (record_full_is_used ())
4550 record_full_gdb_operation_disable_set ();
4552 regcache_write_pc (regcache, stop_pc + decr_pc);
4554 do_cleanups (old_cleanups);
4559 /* A delayed software breakpoint event. Ignore the trap. */
4561 fprintf_unfiltered (gdb_stdlog,
4562 "infrun: delayed software breakpoint "
4563 "trap, ignoring\n");
4568 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
4569 has since been removed. */
4570 if (random_signal && target_stopped_by_hw_breakpoint ())
4572 /* A delayed hardware breakpoint event. Ignore the trap. */
4574 fprintf_unfiltered (gdb_stdlog,
4575 "infrun: delayed hardware breakpoint/watchpoint "
4576 "trap, ignoring\n");
4580 /* If not, perhaps stepping/nexting can. */
4582 random_signal = !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4583 && currently_stepping (ecs->event_thread));
4585 /* Perhaps the thread hit a single-step breakpoint of _another_
4586 thread. Single-step breakpoints are transparent to the
4587 breakpoints module. */
4589 random_signal = !ecs->hit_singlestep_breakpoint;
4591 /* No? Perhaps we got a moribund watchpoint. */
4593 random_signal = !stopped_by_watchpoint;
4595 /* For the program's own signals, act according to
4596 the signal handling tables. */
4600 /* Signal not for debugging purposes. */
4601 struct inferior *inf = find_inferior_ptid (ecs->ptid);
4602 enum gdb_signal stop_signal = ecs->event_thread->suspend.stop_signal;
4605 fprintf_unfiltered (gdb_stdlog, "infrun: random signal (%s)\n",
4606 gdb_signal_to_symbol_string (stop_signal));
4608 stopped_by_random_signal = 1;
4610 /* Always stop on signals if we're either just gaining control
4611 of the program, or the user explicitly requested this thread
4612 to remain stopped. */
4613 if (stop_soon != NO_STOP_QUIETLY
4614 || ecs->event_thread->stop_requested
4616 && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
4622 /* Notify observers the signal has "handle print" set. Note we
4623 returned early above if stopping; normal_stop handles the
4624 printing in that case. */
4625 if (signal_print[ecs->event_thread->suspend.stop_signal])
4627 /* The signal table tells us to print about this signal. */
4628 target_terminal_ours_for_output ();
4629 observer_notify_signal_received (ecs->event_thread->suspend.stop_signal);
4630 target_terminal_inferior ();
4633 /* Clear the signal if it should not be passed. */
4634 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
4635 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4637 if (ecs->event_thread->prev_pc == stop_pc
4638 && ecs->event_thread->control.trap_expected
4639 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4641 /* We were just starting a new sequence, attempting to
4642 single-step off of a breakpoint and expecting a SIGTRAP.
4643 Instead this signal arrives. This signal will take us out
4644 of the stepping range so GDB needs to remember to, when
4645 the signal handler returns, resume stepping off that
4647 /* To simplify things, "continue" is forced to use the same
4648 code paths as single-step - set a breakpoint at the
4649 signal return address and then, once hit, step off that
4652 fprintf_unfiltered (gdb_stdlog,
4653 "infrun: signal arrived while stepping over "
4656 insert_hp_step_resume_breakpoint_at_frame (frame);
4657 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4658 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4659 ecs->event_thread->control.trap_expected = 0;
4661 /* If we were nexting/stepping some other thread, switch to
4662 it, so that we don't continue it, losing control. */
4663 if (!switch_back_to_stepped_thread (ecs))
4668 if (ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_0
4669 && (pc_in_thread_step_range (stop_pc, ecs->event_thread)
4670 || ecs->event_thread->control.step_range_end == 1)
4671 && frame_id_eq (get_stack_frame_id (frame),
4672 ecs->event_thread->control.step_stack_frame_id)
4673 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4675 /* The inferior is about to take a signal that will take it
4676 out of the single step range. Set a breakpoint at the
4677 current PC (which is presumably where the signal handler
4678 will eventually return) and then allow the inferior to
4681 Note that this is only needed for a signal delivered
4682 while in the single-step range. Nested signals aren't a
4683 problem as they eventually all return. */
4685 fprintf_unfiltered (gdb_stdlog,
4686 "infrun: signal may take us out of "
4687 "single-step range\n");
4689 insert_hp_step_resume_breakpoint_at_frame (frame);
4690 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4691 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4692 ecs->event_thread->control.trap_expected = 0;
4697 /* Note: step_resume_breakpoint may be non-NULL. This occures
4698 when either there's a nested signal, or when there's a
4699 pending signal enabled just as the signal handler returns
4700 (leaving the inferior at the step-resume-breakpoint without
4701 actually executing it). Either way continue until the
4702 breakpoint is really hit. */
4704 if (!switch_back_to_stepped_thread (ecs))
4707 fprintf_unfiltered (gdb_stdlog,
4708 "infrun: random signal, keep going\n");
4715 process_event_stop_test (ecs);
4718 /* Come here when we've got some debug event / signal we can explain
4719 (IOW, not a random signal), and test whether it should cause a
4720 stop, or whether we should resume the inferior (transparently).
4721 E.g., could be a breakpoint whose condition evaluates false; we
4722 could be still stepping within the line; etc. */
4725 process_event_stop_test (struct execution_control_state *ecs)
4727 struct symtab_and_line stop_pc_sal;
4728 struct frame_info *frame;
4729 struct gdbarch *gdbarch;
4730 CORE_ADDR jmp_buf_pc;
4731 struct bpstat_what what;
4733 /* Handle cases caused by hitting a breakpoint. */
4735 frame = get_current_frame ();
4736 gdbarch = get_frame_arch (frame);
4738 what = bpstat_what (ecs->event_thread->control.stop_bpstat);
4740 if (what.call_dummy)
4742 stop_stack_dummy = what.call_dummy;
4745 /* If we hit an internal event that triggers symbol changes, the
4746 current frame will be invalidated within bpstat_what (e.g., if we
4747 hit an internal solib event). Re-fetch it. */
4748 frame = get_current_frame ();
4749 gdbarch = get_frame_arch (frame);
4751 switch (what.main_action)
4753 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
4754 /* If we hit the breakpoint at longjmp while stepping, we
4755 install a momentary breakpoint at the target of the
4759 fprintf_unfiltered (gdb_stdlog,
4760 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4762 ecs->event_thread->stepping_over_breakpoint = 1;
4764 if (what.is_longjmp)
4766 struct value *arg_value;
4768 /* If we set the longjmp breakpoint via a SystemTap probe,
4769 then use it to extract the arguments. The destination PC
4770 is the third argument to the probe. */
4771 arg_value = probe_safe_evaluate_at_pc (frame, 2);
4774 jmp_buf_pc = value_as_address (arg_value);
4775 jmp_buf_pc = gdbarch_addr_bits_remove (gdbarch, jmp_buf_pc);
4777 else if (!gdbarch_get_longjmp_target_p (gdbarch)
4778 || !gdbarch_get_longjmp_target (gdbarch,
4779 frame, &jmp_buf_pc))
4782 fprintf_unfiltered (gdb_stdlog,
4783 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4784 "(!gdbarch_get_longjmp_target)\n");
4789 /* Insert a breakpoint at resume address. */
4790 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4793 check_exception_resume (ecs, frame);
4797 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4799 struct frame_info *init_frame;
4801 /* There are several cases to consider.
4803 1. The initiating frame no longer exists. In this case we
4804 must stop, because the exception or longjmp has gone too
4807 2. The initiating frame exists, and is the same as the
4808 current frame. We stop, because the exception or longjmp
4811 3. The initiating frame exists and is different from the
4812 current frame. This means the exception or longjmp has
4813 been caught beneath the initiating frame, so keep going.
4815 4. longjmp breakpoint has been placed just to protect
4816 against stale dummy frames and user is not interested in
4817 stopping around longjmps. */
4820 fprintf_unfiltered (gdb_stdlog,
4821 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4823 gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
4825 delete_exception_resume_breakpoint (ecs->event_thread);
4827 if (what.is_longjmp)
4829 check_longjmp_breakpoint_for_call_dummy (ecs->event_thread);
4831 if (!frame_id_p (ecs->event_thread->initiating_frame))
4839 init_frame = frame_find_by_id (ecs->event_thread->initiating_frame);
4843 struct frame_id current_id
4844 = get_frame_id (get_current_frame ());
4845 if (frame_id_eq (current_id,
4846 ecs->event_thread->initiating_frame))
4848 /* Case 2. Fall through. */
4858 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4860 delete_step_resume_breakpoint (ecs->event_thread);
4862 end_stepping_range (ecs);
4866 case BPSTAT_WHAT_SINGLE:
4868 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
4869 ecs->event_thread->stepping_over_breakpoint = 1;
4870 /* Still need to check other stuff, at least the case where we
4871 are stepping and step out of the right range. */
4874 case BPSTAT_WHAT_STEP_RESUME:
4876 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4878 delete_step_resume_breakpoint (ecs->event_thread);
4879 if (ecs->event_thread->control.proceed_to_finish
4880 && execution_direction == EXEC_REVERSE)
4882 struct thread_info *tp = ecs->event_thread;
4884 /* We are finishing a function in reverse, and just hit the
4885 step-resume breakpoint at the start address of the
4886 function, and we're almost there -- just need to back up
4887 by one more single-step, which should take us back to the
4889 tp->control.step_range_start = tp->control.step_range_end = 1;
4893 fill_in_stop_func (gdbarch, ecs);
4894 if (stop_pc == ecs->stop_func_start
4895 && execution_direction == EXEC_REVERSE)
4897 /* We are stepping over a function call in reverse, and just
4898 hit the step-resume breakpoint at the start address of
4899 the function. Go back to single-stepping, which should
4900 take us back to the function call. */
4901 ecs->event_thread->stepping_over_breakpoint = 1;
4907 case BPSTAT_WHAT_STOP_NOISY:
4909 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4910 stop_print_frame = 1;
4912 /* Assume the thread stopped for a breapoint. We'll still check
4913 whether a/the breakpoint is there when the thread is next
4915 ecs->event_thread->stepping_over_breakpoint = 1;
4920 case BPSTAT_WHAT_STOP_SILENT:
4922 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4923 stop_print_frame = 0;
4925 /* Assume the thread stopped for a breapoint. We'll still check
4926 whether a/the breakpoint is there when the thread is next
4928 ecs->event_thread->stepping_over_breakpoint = 1;
4932 case BPSTAT_WHAT_HP_STEP_RESUME:
4934 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4936 delete_step_resume_breakpoint (ecs->event_thread);
4937 if (ecs->event_thread->step_after_step_resume_breakpoint)
4939 /* Back when the step-resume breakpoint was inserted, we
4940 were trying to single-step off a breakpoint. Go back to
4942 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4943 ecs->event_thread->stepping_over_breakpoint = 1;
4949 case BPSTAT_WHAT_KEEP_CHECKING:
4953 /* If we stepped a permanent breakpoint and we had a high priority
4954 step-resume breakpoint for the address we stepped, but we didn't
4955 hit it, then we must have stepped into the signal handler. The
4956 step-resume was only necessary to catch the case of _not_
4957 stepping into the handler, so delete it, and fall through to
4958 checking whether the step finished. */
4959 if (ecs->event_thread->stepped_breakpoint)
4961 struct breakpoint *sr_bp
4962 = ecs->event_thread->control.step_resume_breakpoint;
4964 if (sr_bp->loc->permanent
4965 && sr_bp->type == bp_hp_step_resume
4966 && sr_bp->loc->address == ecs->event_thread->prev_pc)
4969 fprintf_unfiltered (gdb_stdlog,
4970 "infrun: stepped permanent breakpoint, stopped in "
4972 delete_step_resume_breakpoint (ecs->event_thread);
4973 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4977 /* We come here if we hit a breakpoint but should not stop for it.
4978 Possibly we also were stepping and should stop for that. So fall
4979 through and test for stepping. But, if not stepping, do not
4982 /* In all-stop mode, if we're currently stepping but have stopped in
4983 some other thread, we need to switch back to the stepped thread. */
4984 if (switch_back_to_stepped_thread (ecs))
4987 if (ecs->event_thread->control.step_resume_breakpoint)
4990 fprintf_unfiltered (gdb_stdlog,
4991 "infrun: step-resume breakpoint is inserted\n");
4993 /* Having a step-resume breakpoint overrides anything
4994 else having to do with stepping commands until
4995 that breakpoint is reached. */
5000 if (ecs->event_thread->control.step_range_end == 0)
5003 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
5004 /* Likewise if we aren't even stepping. */
5009 /* Re-fetch current thread's frame in case the code above caused
5010 the frame cache to be re-initialized, making our FRAME variable
5011 a dangling pointer. */
5012 frame = get_current_frame ();
5013 gdbarch = get_frame_arch (frame);
5014 fill_in_stop_func (gdbarch, ecs);
5016 /* If stepping through a line, keep going if still within it.
5018 Note that step_range_end is the address of the first instruction
5019 beyond the step range, and NOT the address of the last instruction
5022 Note also that during reverse execution, we may be stepping
5023 through a function epilogue and therefore must detect when
5024 the current-frame changes in the middle of a line. */
5026 if (pc_in_thread_step_range (stop_pc, ecs->event_thread)
5027 && (execution_direction != EXEC_REVERSE
5028 || frame_id_eq (get_frame_id (frame),
5029 ecs->event_thread->control.step_frame_id)))
5033 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
5034 paddress (gdbarch, ecs->event_thread->control.step_range_start),
5035 paddress (gdbarch, ecs->event_thread->control.step_range_end));
5037 /* Tentatively re-enable range stepping; `resume' disables it if
5038 necessary (e.g., if we're stepping over a breakpoint or we
5039 have software watchpoints). */
5040 ecs->event_thread->control.may_range_step = 1;
5042 /* When stepping backward, stop at beginning of line range
5043 (unless it's the function entry point, in which case
5044 keep going back to the call point). */
5045 if (stop_pc == ecs->event_thread->control.step_range_start
5046 && stop_pc != ecs->stop_func_start
5047 && execution_direction == EXEC_REVERSE)
5048 end_stepping_range (ecs);
5055 /* We stepped out of the stepping range. */
5057 /* If we are stepping at the source level and entered the runtime
5058 loader dynamic symbol resolution code...
5060 EXEC_FORWARD: we keep on single stepping until we exit the run
5061 time loader code and reach the callee's address.
5063 EXEC_REVERSE: we've already executed the callee (backward), and
5064 the runtime loader code is handled just like any other
5065 undebuggable function call. Now we need only keep stepping
5066 backward through the trampoline code, and that's handled further
5067 down, so there is nothing for us to do here. */
5069 if (execution_direction != EXEC_REVERSE
5070 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5071 && in_solib_dynsym_resolve_code (stop_pc))
5073 CORE_ADDR pc_after_resolver =
5074 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
5077 fprintf_unfiltered (gdb_stdlog,
5078 "infrun: stepped into dynsym resolve code\n");
5080 if (pc_after_resolver)
5082 /* Set up a step-resume breakpoint at the address
5083 indicated by SKIP_SOLIB_RESOLVER. */
5084 struct symtab_and_line sr_sal;
5087 sr_sal.pc = pc_after_resolver;
5088 sr_sal.pspace = get_frame_program_space (frame);
5090 insert_step_resume_breakpoint_at_sal (gdbarch,
5091 sr_sal, null_frame_id);
5098 if (ecs->event_thread->control.step_range_end != 1
5099 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5100 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5101 && get_frame_type (frame) == SIGTRAMP_FRAME)
5104 fprintf_unfiltered (gdb_stdlog,
5105 "infrun: stepped into signal trampoline\n");
5106 /* The inferior, while doing a "step" or "next", has ended up in
5107 a signal trampoline (either by a signal being delivered or by
5108 the signal handler returning). Just single-step until the
5109 inferior leaves the trampoline (either by calling the handler
5115 /* If we're in the return path from a shared library trampoline,
5116 we want to proceed through the trampoline when stepping. */
5117 /* macro/2012-04-25: This needs to come before the subroutine
5118 call check below as on some targets return trampolines look
5119 like subroutine calls (MIPS16 return thunks). */
5120 if (gdbarch_in_solib_return_trampoline (gdbarch,
5121 stop_pc, ecs->stop_func_name)
5122 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
5124 /* Determine where this trampoline returns. */
5125 CORE_ADDR real_stop_pc;
5127 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
5130 fprintf_unfiltered (gdb_stdlog,
5131 "infrun: stepped into solib return tramp\n");
5133 /* Only proceed through if we know where it's going. */
5136 /* And put the step-breakpoint there and go until there. */
5137 struct symtab_and_line sr_sal;
5139 init_sal (&sr_sal); /* initialize to zeroes */
5140 sr_sal.pc = real_stop_pc;
5141 sr_sal.section = find_pc_overlay (sr_sal.pc);
5142 sr_sal.pspace = get_frame_program_space (frame);
5144 /* Do not specify what the fp should be when we stop since
5145 on some machines the prologue is where the new fp value
5147 insert_step_resume_breakpoint_at_sal (gdbarch,
5148 sr_sal, null_frame_id);
5150 /* Restart without fiddling with the step ranges or
5157 /* Check for subroutine calls. The check for the current frame
5158 equalling the step ID is not necessary - the check of the
5159 previous frame's ID is sufficient - but it is a common case and
5160 cheaper than checking the previous frame's ID.
5162 NOTE: frame_id_eq will never report two invalid frame IDs as
5163 being equal, so to get into this block, both the current and
5164 previous frame must have valid frame IDs. */
5165 /* The outer_frame_id check is a heuristic to detect stepping
5166 through startup code. If we step over an instruction which
5167 sets the stack pointer from an invalid value to a valid value,
5168 we may detect that as a subroutine call from the mythical
5169 "outermost" function. This could be fixed by marking
5170 outermost frames as !stack_p,code_p,special_p. Then the
5171 initial outermost frame, before sp was valid, would
5172 have code_addr == &_start. See the comment in frame_id_eq
5174 if (!frame_id_eq (get_stack_frame_id (frame),
5175 ecs->event_thread->control.step_stack_frame_id)
5176 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
5177 ecs->event_thread->control.step_stack_frame_id)
5178 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
5180 || (ecs->event_thread->control.step_start_function
5181 != find_pc_function (stop_pc)))))
5183 CORE_ADDR real_stop_pc;
5186 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
5188 if (ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
5190 /* I presume that step_over_calls is only 0 when we're
5191 supposed to be stepping at the assembly language level
5192 ("stepi"). Just stop. */
5193 /* And this works the same backward as frontward. MVS */
5194 end_stepping_range (ecs);
5198 /* Reverse stepping through solib trampolines. */
5200 if (execution_direction == EXEC_REVERSE
5201 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
5202 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
5203 || (ecs->stop_func_start == 0
5204 && in_solib_dynsym_resolve_code (stop_pc))))
5206 /* Any solib trampoline code can be handled in reverse
5207 by simply continuing to single-step. We have already
5208 executed the solib function (backwards), and a few
5209 steps will take us back through the trampoline to the
5215 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5217 /* We're doing a "next".
5219 Normal (forward) execution: set a breakpoint at the
5220 callee's return address (the address at which the caller
5223 Reverse (backward) execution. set the step-resume
5224 breakpoint at the start of the function that we just
5225 stepped into (backwards), and continue to there. When we
5226 get there, we'll need to single-step back to the caller. */
5228 if (execution_direction == EXEC_REVERSE)
5230 /* If we're already at the start of the function, we've either
5231 just stepped backward into a single instruction function,
5232 or stepped back out of a signal handler to the first instruction
5233 of the function. Just keep going, which will single-step back
5235 if (ecs->stop_func_start != stop_pc && ecs->stop_func_start != 0)
5237 struct symtab_and_line sr_sal;
5239 /* Normal function call return (static or dynamic). */
5241 sr_sal.pc = ecs->stop_func_start;
5242 sr_sal.pspace = get_frame_program_space (frame);
5243 insert_step_resume_breakpoint_at_sal (gdbarch,
5244 sr_sal, null_frame_id);
5248 insert_step_resume_breakpoint_at_caller (frame);
5254 /* If we are in a function call trampoline (a stub between the
5255 calling routine and the real function), locate the real
5256 function. That's what tells us (a) whether we want to step
5257 into it at all, and (b) what prologue we want to run to the
5258 end of, if we do step into it. */
5259 real_stop_pc = skip_language_trampoline (frame, stop_pc);
5260 if (real_stop_pc == 0)
5261 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
5262 if (real_stop_pc != 0)
5263 ecs->stop_func_start = real_stop_pc;
5265 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
5267 struct symtab_and_line sr_sal;
5270 sr_sal.pc = ecs->stop_func_start;
5271 sr_sal.pspace = get_frame_program_space (frame);
5273 insert_step_resume_breakpoint_at_sal (gdbarch,
5274 sr_sal, null_frame_id);
5279 /* If we have line number information for the function we are
5280 thinking of stepping into and the function isn't on the skip
5283 If there are several symtabs at that PC (e.g. with include
5284 files), just want to know whether *any* of them have line
5285 numbers. find_pc_line handles this. */
5287 struct symtab_and_line tmp_sal;
5289 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
5290 if (tmp_sal.line != 0
5291 && !function_name_is_marked_for_skip (ecs->stop_func_name,
5294 if (execution_direction == EXEC_REVERSE)
5295 handle_step_into_function_backward (gdbarch, ecs);
5297 handle_step_into_function (gdbarch, ecs);
5302 /* If we have no line number and the step-stop-if-no-debug is
5303 set, we stop the step so that the user has a chance to switch
5304 in assembly mode. */
5305 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5306 && step_stop_if_no_debug)
5308 end_stepping_range (ecs);
5312 if (execution_direction == EXEC_REVERSE)
5314 /* If we're already at the start of the function, we've either just
5315 stepped backward into a single instruction function without line
5316 number info, or stepped back out of a signal handler to the first
5317 instruction of the function without line number info. Just keep
5318 going, which will single-step back to the caller. */
5319 if (ecs->stop_func_start != stop_pc)
5321 /* Set a breakpoint at callee's start address.
5322 From there we can step once and be back in the caller. */
5323 struct symtab_and_line sr_sal;
5326 sr_sal.pc = ecs->stop_func_start;
5327 sr_sal.pspace = get_frame_program_space (frame);
5328 insert_step_resume_breakpoint_at_sal (gdbarch,
5329 sr_sal, null_frame_id);
5333 /* Set a breakpoint at callee's return address (the address
5334 at which the caller will resume). */
5335 insert_step_resume_breakpoint_at_caller (frame);
5341 /* Reverse stepping through solib trampolines. */
5343 if (execution_direction == EXEC_REVERSE
5344 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
5346 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
5347 || (ecs->stop_func_start == 0
5348 && in_solib_dynsym_resolve_code (stop_pc)))
5350 /* Any solib trampoline code can be handled in reverse
5351 by simply continuing to single-step. We have already
5352 executed the solib function (backwards), and a few
5353 steps will take us back through the trampoline to the
5358 else if (in_solib_dynsym_resolve_code (stop_pc))
5360 /* Stepped backward into the solib dynsym resolver.
5361 Set a breakpoint at its start and continue, then
5362 one more step will take us out. */
5363 struct symtab_and_line sr_sal;
5366 sr_sal.pc = ecs->stop_func_start;
5367 sr_sal.pspace = get_frame_program_space (frame);
5368 insert_step_resume_breakpoint_at_sal (gdbarch,
5369 sr_sal, null_frame_id);
5375 stop_pc_sal = find_pc_line (stop_pc, 0);
5377 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5378 the trampoline processing logic, however, there are some trampolines
5379 that have no names, so we should do trampoline handling first. */
5380 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5381 && ecs->stop_func_name == NULL
5382 && stop_pc_sal.line == 0)
5385 fprintf_unfiltered (gdb_stdlog,
5386 "infrun: stepped into undebuggable function\n");
5388 /* The inferior just stepped into, or returned to, an
5389 undebuggable function (where there is no debugging information
5390 and no line number corresponding to the address where the
5391 inferior stopped). Since we want to skip this kind of code,
5392 we keep going until the inferior returns from this
5393 function - unless the user has asked us not to (via
5394 set step-mode) or we no longer know how to get back
5395 to the call site. */
5396 if (step_stop_if_no_debug
5397 || !frame_id_p (frame_unwind_caller_id (frame)))
5399 /* If we have no line number and the step-stop-if-no-debug
5400 is set, we stop the step so that the user has a chance to
5401 switch in assembly mode. */
5402 end_stepping_range (ecs);
5407 /* Set a breakpoint at callee's return address (the address
5408 at which the caller will resume). */
5409 insert_step_resume_breakpoint_at_caller (frame);
5415 if (ecs->event_thread->control.step_range_end == 1)
5417 /* It is stepi or nexti. We always want to stop stepping after
5420 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
5421 end_stepping_range (ecs);
5425 if (stop_pc_sal.line == 0)
5427 /* We have no line number information. That means to stop
5428 stepping (does this always happen right after one instruction,
5429 when we do "s" in a function with no line numbers,
5430 or can this happen as a result of a return or longjmp?). */
5432 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
5433 end_stepping_range (ecs);
5437 /* Look for "calls" to inlined functions, part one. If the inline
5438 frame machinery detected some skipped call sites, we have entered
5439 a new inline function. */
5441 if (frame_id_eq (get_frame_id (get_current_frame ()),
5442 ecs->event_thread->control.step_frame_id)
5443 && inline_skipped_frames (ecs->ptid))
5445 struct symtab_and_line call_sal;
5448 fprintf_unfiltered (gdb_stdlog,
5449 "infrun: stepped into inlined function\n");
5451 find_frame_sal (get_current_frame (), &call_sal);
5453 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
5455 /* For "step", we're going to stop. But if the call site
5456 for this inlined function is on the same source line as
5457 we were previously stepping, go down into the function
5458 first. Otherwise stop at the call site. */
5460 if (call_sal.line == ecs->event_thread->current_line
5461 && call_sal.symtab == ecs->event_thread->current_symtab)
5462 step_into_inline_frame (ecs->ptid);
5464 end_stepping_range (ecs);
5469 /* For "next", we should stop at the call site if it is on a
5470 different source line. Otherwise continue through the
5471 inlined function. */
5472 if (call_sal.line == ecs->event_thread->current_line
5473 && call_sal.symtab == ecs->event_thread->current_symtab)
5476 end_stepping_range (ecs);
5481 /* Look for "calls" to inlined functions, part two. If we are still
5482 in the same real function we were stepping through, but we have
5483 to go further up to find the exact frame ID, we are stepping
5484 through a more inlined call beyond its call site. */
5486 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5487 && !frame_id_eq (get_frame_id (get_current_frame ()),
5488 ecs->event_thread->control.step_frame_id)
5489 && stepped_in_from (get_current_frame (),
5490 ecs->event_thread->control.step_frame_id))
5493 fprintf_unfiltered (gdb_stdlog,
5494 "infrun: stepping through inlined function\n");
5496 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5499 end_stepping_range (ecs);
5503 if ((stop_pc == stop_pc_sal.pc)
5504 && (ecs->event_thread->current_line != stop_pc_sal.line
5505 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
5507 /* We are at the start of a different line. So stop. Note that
5508 we don't stop if we step into the middle of a different line.
5509 That is said to make things like for (;;) statements work
5512 fprintf_unfiltered (gdb_stdlog,
5513 "infrun: stepped to a different line\n");
5514 end_stepping_range (ecs);
5518 /* We aren't done stepping.
5520 Optimize by setting the stepping range to the line.
5521 (We might not be in the original line, but if we entered a
5522 new line in mid-statement, we continue stepping. This makes
5523 things like for(;;) statements work better.) */
5525 ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
5526 ecs->event_thread->control.step_range_end = stop_pc_sal.end;
5527 ecs->event_thread->control.may_range_step = 1;
5528 set_step_info (frame, stop_pc_sal);
5531 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
5535 /* In all-stop mode, if we're currently stepping but have stopped in
5536 some other thread, we may need to switch back to the stepped
5537 thread. Returns true we set the inferior running, false if we left
5538 it stopped (and the event needs further processing). */
5541 switch_back_to_stepped_thread (struct execution_control_state *ecs)
5545 struct thread_info *tp;
5546 struct thread_info *stepping_thread;
5547 struct thread_info *step_over;
5549 /* If any thread is blocked on some internal breakpoint, and we
5550 simply need to step over that breakpoint to get it going
5551 again, do that first. */
5553 /* However, if we see an event for the stepping thread, then we
5554 know all other threads have been moved past their breakpoints
5555 already. Let the caller check whether the step is finished,
5556 etc., before deciding to move it past a breakpoint. */
5557 if (ecs->event_thread->control.step_range_end != 0)
5560 /* Check if the current thread is blocked on an incomplete
5561 step-over, interrupted by a random signal. */
5562 if (ecs->event_thread->control.trap_expected
5563 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
5567 fprintf_unfiltered (gdb_stdlog,
5568 "infrun: need to finish step-over of [%s]\n",
5569 target_pid_to_str (ecs->event_thread->ptid));
5575 /* Check if the current thread is blocked by a single-step
5576 breakpoint of another thread. */
5577 if (ecs->hit_singlestep_breakpoint)
5581 fprintf_unfiltered (gdb_stdlog,
5582 "infrun: need to step [%s] over single-step "
5584 target_pid_to_str (ecs->ptid));
5590 /* Otherwise, we no longer expect a trap in the current thread.
5591 Clear the trap_expected flag before switching back -- this is
5592 what keep_going does as well, if we call it. */
5593 ecs->event_thread->control.trap_expected = 0;
5595 /* Likewise, clear the signal if it should not be passed. */
5596 if (!signal_program[ecs->event_thread->suspend.stop_signal])
5597 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
5599 /* If scheduler locking applies even if not stepping, there's no
5600 need to walk over threads. Above we've checked whether the
5601 current thread is stepping. If some other thread not the
5602 event thread is stepping, then it must be that scheduler
5603 locking is not in effect. */
5604 if (schedlock_applies (ecs->event_thread))
5607 /* Look for the stepping/nexting thread, and check if any other
5608 thread other than the stepping thread needs to start a
5609 step-over. Do all step-overs before actually proceeding with
5611 stepping_thread = NULL;
5613 ALL_NON_EXITED_THREADS (tp)
5615 /* Ignore threads of processes we're not resuming. */
5617 && ptid_get_pid (tp->ptid) != ptid_get_pid (inferior_ptid))
5620 /* When stepping over a breakpoint, we lock all threads
5621 except the one that needs to move past the breakpoint.
5622 If a non-event thread has this set, the "incomplete
5623 step-over" check above should have caught it earlier. */
5624 gdb_assert (!tp->control.trap_expected);
5626 /* Did we find the stepping thread? */
5627 if (tp->control.step_range_end)
5629 /* Yep. There should only one though. */
5630 gdb_assert (stepping_thread == NULL);
5632 /* The event thread is handled at the top, before we
5634 gdb_assert (tp != ecs->event_thread);
5636 /* If some thread other than the event thread is
5637 stepping, then scheduler locking can't be in effect,
5638 otherwise we wouldn't have resumed the current event
5639 thread in the first place. */
5640 gdb_assert (!schedlock_applies (tp));
5642 stepping_thread = tp;
5644 else if (thread_still_needs_step_over (tp))
5648 /* At the top we've returned early if the event thread
5649 is stepping. If some other thread not the event
5650 thread is stepping, then scheduler locking can't be
5651 in effect, and we can resume this thread. No need to
5652 keep looking for the stepping thread then. */
5657 if (step_over != NULL)
5662 fprintf_unfiltered (gdb_stdlog,
5663 "infrun: need to step-over [%s]\n",
5664 target_pid_to_str (tp->ptid));
5667 /* Only the stepping thread should have this set. */
5668 gdb_assert (tp->control.step_range_end == 0);
5670 ecs->ptid = tp->ptid;
5671 ecs->event_thread = tp;
5672 switch_to_thread (ecs->ptid);
5677 if (stepping_thread != NULL)
5679 struct frame_info *frame;
5680 struct gdbarch *gdbarch;
5682 tp = stepping_thread;
5684 /* If the stepping thread exited, then don't try to switch
5685 back and resume it, which could fail in several different
5686 ways depending on the target. Instead, just keep going.
5688 We can find a stepping dead thread in the thread list in
5691 - The target supports thread exit events, and when the
5692 target tries to delete the thread from the thread list,
5693 inferior_ptid pointed at the exiting thread. In such
5694 case, calling delete_thread does not really remove the
5695 thread from the list; instead, the thread is left listed,
5696 with 'exited' state.
5698 - The target's debug interface does not support thread
5699 exit events, and so we have no idea whatsoever if the
5700 previously stepping thread is still alive. For that
5701 reason, we need to synchronously query the target
5703 if (is_exited (tp->ptid)
5704 || !target_thread_alive (tp->ptid))
5707 fprintf_unfiltered (gdb_stdlog,
5708 "infrun: not switching back to "
5709 "stepped thread, it has vanished\n");
5711 delete_thread (tp->ptid);
5717 fprintf_unfiltered (gdb_stdlog,
5718 "infrun: switching back to stepped thread\n");
5720 ecs->event_thread = tp;
5721 ecs->ptid = tp->ptid;
5722 context_switch (ecs->ptid);
5724 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
5725 frame = get_current_frame ();
5726 gdbarch = get_frame_arch (frame);
5728 /* If the PC of the thread we were trying to single-step has
5729 changed, then that thread has trapped or been signaled,
5730 but the event has not been reported to GDB yet. Re-poll
5731 the target looking for this particular thread's event
5732 (i.e. temporarily enable schedlock) by:
5734 - setting a break at the current PC
5735 - resuming that particular thread, only (by setting
5738 This prevents us continuously moving the single-step
5739 breakpoint forward, one instruction at a time,
5742 if (stop_pc != tp->prev_pc)
5747 fprintf_unfiltered (gdb_stdlog,
5748 "infrun: expected thread advanced also\n");
5750 /* Clear the info of the previous step-over, as it's no
5751 longer valid. It's what keep_going would do too, if
5752 we called it. Must do this before trying to insert
5753 the sss breakpoint, otherwise if we were previously
5754 trying to step over this exact address in another
5755 thread, the breakpoint ends up not installed. */
5756 clear_step_over_info ();
5758 insert_single_step_breakpoint (get_frame_arch (frame),
5759 get_frame_address_space (frame),
5762 resume_ptid = user_visible_resume_ptid (tp->control.stepping_command);
5763 do_target_resume (resume_ptid,
5764 currently_stepping (tp), GDB_SIGNAL_0);
5765 prepare_to_wait (ecs);
5770 fprintf_unfiltered (gdb_stdlog,
5771 "infrun: expected thread still "
5772 "hasn't advanced\n");
5782 /* Is thread TP in the middle of single-stepping? */
5785 currently_stepping (struct thread_info *tp)
5787 return ((tp->control.step_range_end
5788 && tp->control.step_resume_breakpoint == NULL)
5789 || tp->control.trap_expected
5790 || tp->stepped_breakpoint
5791 || bpstat_should_step ());
5794 /* Inferior has stepped into a subroutine call with source code that
5795 we should not step over. Do step to the first line of code in
5799 handle_step_into_function (struct gdbarch *gdbarch,
5800 struct execution_control_state *ecs)
5802 struct compunit_symtab *cust;
5803 struct symtab_and_line stop_func_sal, sr_sal;
5805 fill_in_stop_func (gdbarch, ecs);
5807 cust = find_pc_compunit_symtab (stop_pc);
5808 if (cust != NULL && compunit_language (cust) != language_asm)
5809 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5810 ecs->stop_func_start);
5812 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
5813 /* Use the step_resume_break to step until the end of the prologue,
5814 even if that involves jumps (as it seems to on the vax under
5816 /* If the prologue ends in the middle of a source line, continue to
5817 the end of that source line (if it is still within the function).
5818 Otherwise, just go to end of prologue. */
5819 if (stop_func_sal.end
5820 && stop_func_sal.pc != ecs->stop_func_start
5821 && stop_func_sal.end < ecs->stop_func_end)
5822 ecs->stop_func_start = stop_func_sal.end;
5824 /* Architectures which require breakpoint adjustment might not be able
5825 to place a breakpoint at the computed address. If so, the test
5826 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5827 ecs->stop_func_start to an address at which a breakpoint may be
5828 legitimately placed.
5830 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5831 made, GDB will enter an infinite loop when stepping through
5832 optimized code consisting of VLIW instructions which contain
5833 subinstructions corresponding to different source lines. On
5834 FR-V, it's not permitted to place a breakpoint on any but the
5835 first subinstruction of a VLIW instruction. When a breakpoint is
5836 set, GDB will adjust the breakpoint address to the beginning of
5837 the VLIW instruction. Thus, we need to make the corresponding
5838 adjustment here when computing the stop address. */
5840 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
5842 ecs->stop_func_start
5843 = gdbarch_adjust_breakpoint_address (gdbarch,
5844 ecs->stop_func_start);
5847 if (ecs->stop_func_start == stop_pc)
5849 /* We are already there: stop now. */
5850 end_stepping_range (ecs);
5855 /* Put the step-breakpoint there and go until there. */
5856 init_sal (&sr_sal); /* initialize to zeroes */
5857 sr_sal.pc = ecs->stop_func_start;
5858 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
5859 sr_sal.pspace = get_frame_program_space (get_current_frame ());
5861 /* Do not specify what the fp should be when we stop since on
5862 some machines the prologue is where the new fp value is
5864 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
5866 /* And make sure stepping stops right away then. */
5867 ecs->event_thread->control.step_range_end
5868 = ecs->event_thread->control.step_range_start;
5873 /* Inferior has stepped backward into a subroutine call with source
5874 code that we should not step over. Do step to the beginning of the
5875 last line of code in it. */
5878 handle_step_into_function_backward (struct gdbarch *gdbarch,
5879 struct execution_control_state *ecs)
5881 struct compunit_symtab *cust;
5882 struct symtab_and_line stop_func_sal;
5884 fill_in_stop_func (gdbarch, ecs);
5886 cust = find_pc_compunit_symtab (stop_pc);
5887 if (cust != NULL && compunit_language (cust) != language_asm)
5888 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5889 ecs->stop_func_start);
5891 stop_func_sal = find_pc_line (stop_pc, 0);
5893 /* OK, we're just going to keep stepping here. */
5894 if (stop_func_sal.pc == stop_pc)
5896 /* We're there already. Just stop stepping now. */
5897 end_stepping_range (ecs);
5901 /* Else just reset the step range and keep going.
5902 No step-resume breakpoint, they don't work for
5903 epilogues, which can have multiple entry paths. */
5904 ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5905 ecs->event_thread->control.step_range_end = stop_func_sal.end;
5911 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5912 This is used to both functions and to skip over code. */
5915 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch *gdbarch,
5916 struct symtab_and_line sr_sal,
5917 struct frame_id sr_id,
5918 enum bptype sr_type)
5920 /* There should never be more than one step-resume or longjmp-resume
5921 breakpoint per thread, so we should never be setting a new
5922 step_resume_breakpoint when one is already active. */
5923 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5924 gdb_assert (sr_type == bp_step_resume || sr_type == bp_hp_step_resume);
5927 fprintf_unfiltered (gdb_stdlog,
5928 "infrun: inserting step-resume breakpoint at %s\n",
5929 paddress (gdbarch, sr_sal.pc));
5931 inferior_thread ()->control.step_resume_breakpoint
5932 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type);
5936 insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5937 struct symtab_and_line sr_sal,
5938 struct frame_id sr_id)
5940 insert_step_resume_breakpoint_at_sal_1 (gdbarch,
5945 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5946 This is used to skip a potential signal handler.
5948 This is called with the interrupted function's frame. The signal
5949 handler, when it returns, will resume the interrupted function at
5953 insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
5955 struct symtab_and_line sr_sal;
5956 struct gdbarch *gdbarch;
5958 gdb_assert (return_frame != NULL);
5959 init_sal (&sr_sal); /* initialize to zeros */
5961 gdbarch = get_frame_arch (return_frame);
5962 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
5963 sr_sal.section = find_pc_overlay (sr_sal.pc);
5964 sr_sal.pspace = get_frame_program_space (return_frame);
5966 insert_step_resume_breakpoint_at_sal_1 (gdbarch, sr_sal,
5967 get_stack_frame_id (return_frame),
5971 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5972 is used to skip a function after stepping into it (for "next" or if
5973 the called function has no debugging information).
5975 The current function has almost always been reached by single
5976 stepping a call or return instruction. NEXT_FRAME belongs to the
5977 current function, and the breakpoint will be set at the caller's
5980 This is a separate function rather than reusing
5981 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5982 get_prev_frame, which may stop prematurely (see the implementation
5983 of frame_unwind_caller_id for an example). */
5986 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
5988 struct symtab_and_line sr_sal;
5989 struct gdbarch *gdbarch;
5991 /* We shouldn't have gotten here if we don't know where the call site
5993 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
5995 init_sal (&sr_sal); /* initialize to zeros */
5997 gdbarch = frame_unwind_caller_arch (next_frame);
5998 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
5999 frame_unwind_caller_pc (next_frame));
6000 sr_sal.section = find_pc_overlay (sr_sal.pc);
6001 sr_sal.pspace = frame_unwind_program_space (next_frame);
6003 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
6004 frame_unwind_caller_id (next_frame));
6007 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
6008 new breakpoint at the target of a jmp_buf. The handling of
6009 longjmp-resume uses the same mechanisms used for handling
6010 "step-resume" breakpoints. */
6013 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
6015 /* There should never be more than one longjmp-resume breakpoint per
6016 thread, so we should never be setting a new
6017 longjmp_resume_breakpoint when one is already active. */
6018 gdb_assert (inferior_thread ()->control.exception_resume_breakpoint == NULL);
6021 fprintf_unfiltered (gdb_stdlog,
6022 "infrun: inserting longjmp-resume breakpoint at %s\n",
6023 paddress (gdbarch, pc));
6025 inferior_thread ()->control.exception_resume_breakpoint =
6026 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
6029 /* Insert an exception resume breakpoint. TP is the thread throwing
6030 the exception. The block B is the block of the unwinder debug hook
6031 function. FRAME is the frame corresponding to the call to this
6032 function. SYM is the symbol of the function argument holding the
6033 target PC of the exception. */
6036 insert_exception_resume_breakpoint (struct thread_info *tp,
6037 const struct block *b,
6038 struct frame_info *frame,
6043 struct symbol *vsym;
6044 struct value *value;
6046 struct breakpoint *bp;
6048 vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
6049 value = read_var_value (vsym, frame);
6050 /* If the value was optimized out, revert to the old behavior. */
6051 if (! value_optimized_out (value))
6053 handler = value_as_address (value);
6056 fprintf_unfiltered (gdb_stdlog,
6057 "infrun: exception resume at %lx\n",
6058 (unsigned long) handler);
6060 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
6061 handler, bp_exception_resume);
6063 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
6066 bp->thread = tp->num;
6067 inferior_thread ()->control.exception_resume_breakpoint = bp;
6070 CATCH (e, RETURN_MASK_ERROR)
6072 /* We want to ignore errors here. */
6077 /* A helper for check_exception_resume that sets an
6078 exception-breakpoint based on a SystemTap probe. */
6081 insert_exception_resume_from_probe (struct thread_info *tp,
6082 const struct bound_probe *probe,
6083 struct frame_info *frame)
6085 struct value *arg_value;
6087 struct breakpoint *bp;
6089 arg_value = probe_safe_evaluate_at_pc (frame, 1);
6093 handler = value_as_address (arg_value);
6096 fprintf_unfiltered (gdb_stdlog,
6097 "infrun: exception resume at %s\n",
6098 paddress (get_objfile_arch (probe->objfile),
6101 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
6102 handler, bp_exception_resume);
6103 bp->thread = tp->num;
6104 inferior_thread ()->control.exception_resume_breakpoint = bp;
6107 /* This is called when an exception has been intercepted. Check to
6108 see whether the exception's destination is of interest, and if so,
6109 set an exception resume breakpoint there. */
6112 check_exception_resume (struct execution_control_state *ecs,
6113 struct frame_info *frame)
6115 struct bound_probe probe;
6116 struct symbol *func;
6118 /* First see if this exception unwinding breakpoint was set via a
6119 SystemTap probe point. If so, the probe has two arguments: the
6120 CFA and the HANDLER. We ignore the CFA, extract the handler, and
6121 set a breakpoint there. */
6122 probe = find_probe_by_pc (get_frame_pc (frame));
6125 insert_exception_resume_from_probe (ecs->event_thread, &probe, frame);
6129 func = get_frame_function (frame);
6135 const struct block *b;
6136 struct block_iterator iter;
6140 /* The exception breakpoint is a thread-specific breakpoint on
6141 the unwinder's debug hook, declared as:
6143 void _Unwind_DebugHook (void *cfa, void *handler);
6145 The CFA argument indicates the frame to which control is
6146 about to be transferred. HANDLER is the destination PC.
6148 We ignore the CFA and set a temporary breakpoint at HANDLER.
6149 This is not extremely efficient but it avoids issues in gdb
6150 with computing the DWARF CFA, and it also works even in weird
6151 cases such as throwing an exception from inside a signal
6154 b = SYMBOL_BLOCK_VALUE (func);
6155 ALL_BLOCK_SYMBOLS (b, iter, sym)
6157 if (!SYMBOL_IS_ARGUMENT (sym))
6164 insert_exception_resume_breakpoint (ecs->event_thread,
6170 CATCH (e, RETURN_MASK_ERROR)
6177 stop_waiting (struct execution_control_state *ecs)
6180 fprintf_unfiltered (gdb_stdlog, "infrun: stop_waiting\n");
6182 clear_step_over_info ();
6184 /* Let callers know we don't want to wait for the inferior anymore. */
6185 ecs->wait_some_more = 0;
6188 /* Called when we should continue running the inferior, because the
6189 current event doesn't cause a user visible stop. This does the
6190 resuming part; waiting for the next event is done elsewhere. */
6193 keep_going (struct execution_control_state *ecs)
6195 /* Make sure normal_stop is called if we get a QUIT handled before
6197 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
6199 /* Save the pc before execution, to compare with pc after stop. */
6200 ecs->event_thread->prev_pc
6201 = regcache_read_pc (get_thread_regcache (ecs->ptid));
6203 if (ecs->event_thread->control.trap_expected
6204 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
6206 /* We haven't yet gotten our trap, and either: intercepted a
6207 non-signal event (e.g., a fork); or took a signal which we
6208 are supposed to pass through to the inferior. Simply
6210 discard_cleanups (old_cleanups);
6211 resume (ecs->event_thread->suspend.stop_signal);
6215 struct regcache *regcache = get_current_regcache ();
6219 /* Either the trap was not expected, but we are continuing
6220 anyway (if we got a signal, the user asked it be passed to
6223 We got our expected trap, but decided we should resume from
6226 We're going to run this baby now!
6228 Note that insert_breakpoints won't try to re-insert
6229 already inserted breakpoints. Therefore, we don't
6230 care if breakpoints were already inserted, or not. */
6232 /* If we need to step over a breakpoint, and we're not using
6233 displaced stepping to do so, insert all breakpoints
6234 (watchpoints, etc.) but the one we're stepping over, step one
6235 instruction, and then re-insert the breakpoint when that step
6238 remove_bp = (ecs->hit_singlestep_breakpoint
6239 || thread_still_needs_step_over (ecs->event_thread));
6240 remove_wps = (ecs->event_thread->stepping_over_watchpoint
6241 && !target_have_steppable_watchpoint);
6243 if (remove_bp && !use_displaced_stepping (get_regcache_arch (regcache)))
6245 set_step_over_info (get_regcache_aspace (regcache),
6246 regcache_read_pc (regcache), remove_wps);
6248 else if (remove_wps)
6249 set_step_over_info (NULL, 0, remove_wps);
6251 clear_step_over_info ();
6253 /* Stop stepping if inserting breakpoints fails. */
6256 insert_breakpoints ();
6258 CATCH (e, RETURN_MASK_ERROR)
6260 exception_print (gdb_stderr, e);
6262 discard_cleanups (old_cleanups);
6267 ecs->event_thread->control.trap_expected = (remove_bp || remove_wps);
6269 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
6270 explicitly specifies that such a signal should be delivered
6271 to the target program). Typically, that would occur when a
6272 user is debugging a target monitor on a simulator: the target
6273 monitor sets a breakpoint; the simulator encounters this
6274 breakpoint and halts the simulation handing control to GDB;
6275 GDB, noting that the stop address doesn't map to any known
6276 breakpoint, returns control back to the simulator; the
6277 simulator then delivers the hardware equivalent of a
6278 GDB_SIGNAL_TRAP to the program being debugged. */
6279 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
6280 && !signal_program[ecs->event_thread->suspend.stop_signal])
6281 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
6283 discard_cleanups (old_cleanups);
6284 resume (ecs->event_thread->suspend.stop_signal);
6287 prepare_to_wait (ecs);
6290 /* This function normally comes after a resume, before
6291 handle_inferior_event exits. It takes care of any last bits of
6292 housekeeping, and sets the all-important wait_some_more flag. */
6295 prepare_to_wait (struct execution_control_state *ecs)
6298 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
6300 /* This is the old end of the while loop. Let everybody know we
6301 want to wait for the inferior some more and get called again
6303 ecs->wait_some_more = 1;
6306 /* We are done with the step range of a step/next/si/ni command.
6307 Called once for each n of a "step n" operation. */
6310 end_stepping_range (struct execution_control_state *ecs)
6312 ecs->event_thread->control.stop_step = 1;
6316 /* Several print_*_reason functions to print why the inferior has stopped.
6317 We always print something when the inferior exits, or receives a signal.
6318 The rest of the cases are dealt with later on in normal_stop and
6319 print_it_typical. Ideally there should be a call to one of these
6320 print_*_reason functions functions from handle_inferior_event each time
6321 stop_waiting is called.
6323 Note that we don't call these directly, instead we delegate that to
6324 the interpreters, through observers. Interpreters then call these
6325 with whatever uiout is right. */
6328 print_end_stepping_range_reason (struct ui_out *uiout)
6330 /* For CLI-like interpreters, print nothing. */
6332 if (ui_out_is_mi_like_p (uiout))
6334 ui_out_field_string (uiout, "reason",
6335 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
6340 print_signal_exited_reason (struct ui_out *uiout, enum gdb_signal siggnal)
6342 annotate_signalled ();
6343 if (ui_out_is_mi_like_p (uiout))
6345 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
6346 ui_out_text (uiout, "\nProgram terminated with signal ");
6347 annotate_signal_name ();
6348 ui_out_field_string (uiout, "signal-name",
6349 gdb_signal_to_name (siggnal));
6350 annotate_signal_name_end ();
6351 ui_out_text (uiout, ", ");
6352 annotate_signal_string ();
6353 ui_out_field_string (uiout, "signal-meaning",
6354 gdb_signal_to_string (siggnal));
6355 annotate_signal_string_end ();
6356 ui_out_text (uiout, ".\n");
6357 ui_out_text (uiout, "The program no longer exists.\n");
6361 print_exited_reason (struct ui_out *uiout, int exitstatus)
6363 struct inferior *inf = current_inferior ();
6364 const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid));
6366 annotate_exited (exitstatus);
6369 if (ui_out_is_mi_like_p (uiout))
6370 ui_out_field_string (uiout, "reason",
6371 async_reason_lookup (EXEC_ASYNC_EXITED));
6372 ui_out_text (uiout, "[Inferior ");
6373 ui_out_text (uiout, plongest (inf->num));
6374 ui_out_text (uiout, " (");
6375 ui_out_text (uiout, pidstr);
6376 ui_out_text (uiout, ") exited with code ");
6377 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
6378 ui_out_text (uiout, "]\n");
6382 if (ui_out_is_mi_like_p (uiout))
6384 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
6385 ui_out_text (uiout, "[Inferior ");
6386 ui_out_text (uiout, plongest (inf->num));
6387 ui_out_text (uiout, " (");
6388 ui_out_text (uiout, pidstr);
6389 ui_out_text (uiout, ") exited normally]\n");
6394 print_signal_received_reason (struct ui_out *uiout, enum gdb_signal siggnal)
6398 if (siggnal == GDB_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
6400 struct thread_info *t = inferior_thread ();
6402 ui_out_text (uiout, "\n[");
6403 ui_out_field_string (uiout, "thread-name",
6404 target_pid_to_str (t->ptid));
6405 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
6406 ui_out_text (uiout, " stopped");
6410 ui_out_text (uiout, "\nProgram received signal ");
6411 annotate_signal_name ();
6412 if (ui_out_is_mi_like_p (uiout))
6414 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
6415 ui_out_field_string (uiout, "signal-name",
6416 gdb_signal_to_name (siggnal));
6417 annotate_signal_name_end ();
6418 ui_out_text (uiout, ", ");
6419 annotate_signal_string ();
6420 ui_out_field_string (uiout, "signal-meaning",
6421 gdb_signal_to_string (siggnal));
6422 annotate_signal_string_end ();
6424 ui_out_text (uiout, ".\n");
6428 print_no_history_reason (struct ui_out *uiout)
6430 ui_out_text (uiout, "\nNo more reverse-execution history.\n");
6433 /* Print current location without a level number, if we have changed
6434 functions or hit a breakpoint. Print source line if we have one.
6435 bpstat_print contains the logic deciding in detail what to print,
6436 based on the event(s) that just occurred. */
6439 print_stop_event (struct target_waitstatus *ws)
6443 int do_frame_printing = 1;
6444 struct thread_info *tp = inferior_thread ();
6446 bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws->kind);
6450 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
6451 should) carry around the function and does (or should) use
6452 that when doing a frame comparison. */
6453 if (tp->control.stop_step
6454 && frame_id_eq (tp->control.step_frame_id,
6455 get_frame_id (get_current_frame ()))
6456 && tp->control.step_start_function == find_pc_function (stop_pc))
6458 /* Finished step, just print source line. */
6459 source_flag = SRC_LINE;
6463 /* Print location and source line. */
6464 source_flag = SRC_AND_LOC;
6467 case PRINT_SRC_AND_LOC:
6468 /* Print location and source line. */
6469 source_flag = SRC_AND_LOC;
6471 case PRINT_SRC_ONLY:
6472 source_flag = SRC_LINE;
6475 /* Something bogus. */
6476 source_flag = SRC_LINE;
6477 do_frame_printing = 0;
6480 internal_error (__FILE__, __LINE__, _("Unknown value."));
6483 /* The behavior of this routine with respect to the source
6485 SRC_LINE: Print only source line
6486 LOCATION: Print only location
6487 SRC_AND_LOC: Print location and source line. */
6488 if (do_frame_printing)
6489 print_stack_frame (get_selected_frame (NULL), 0, source_flag, 1);
6491 /* Display the auto-display expressions. */
6495 /* Here to return control to GDB when the inferior stops for real.
6496 Print appropriate messages, remove breakpoints, give terminal our modes.
6498 STOP_PRINT_FRAME nonzero means print the executing frame
6499 (pc, function, args, file, line number and line text).
6500 BREAKPOINTS_FAILED nonzero means stop was due to error
6501 attempting to insert breakpoints. */
6506 struct target_waitstatus last;
6508 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
6510 get_last_target_status (&last_ptid, &last);
6512 /* If an exception is thrown from this point on, make sure to
6513 propagate GDB's knowledge of the executing state to the
6514 frontend/user running state. A QUIT is an easy exception to see
6515 here, so do this before any filtered output. */
6517 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
6518 else if (last.kind != TARGET_WAITKIND_SIGNALLED
6519 && last.kind != TARGET_WAITKIND_EXITED
6520 && last.kind != TARGET_WAITKIND_NO_RESUMED)
6521 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
6523 /* As we're presenting a stop, and potentially removing breakpoints,
6524 update the thread list so we can tell whether there are threads
6525 running on the target. With target remote, for example, we can
6526 only learn about new threads when we explicitly update the thread
6527 list. Do this before notifying the interpreters about signal
6528 stops, end of stepping ranges, etc., so that the "new thread"
6529 output is emitted before e.g., "Program received signal FOO",
6530 instead of after. */
6531 update_thread_list ();
6533 if (last.kind == TARGET_WAITKIND_STOPPED && stopped_by_random_signal)
6534 observer_notify_signal_received (inferior_thread ()->suspend.stop_signal);
6536 /* As with the notification of thread events, we want to delay
6537 notifying the user that we've switched thread context until
6538 the inferior actually stops.
6540 There's no point in saying anything if the inferior has exited.
6541 Note that SIGNALLED here means "exited with a signal", not
6542 "received a signal".
6544 Also skip saying anything in non-stop mode. In that mode, as we
6545 don't want GDB to switch threads behind the user's back, to avoid
6546 races where the user is typing a command to apply to thread x,
6547 but GDB switches to thread y before the user finishes entering
6548 the command, fetch_inferior_event installs a cleanup to restore
6549 the current thread back to the thread the user had selected right
6550 after this event is handled, so we're not really switching, only
6551 informing of a stop. */
6553 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
6554 && target_has_execution
6555 && last.kind != TARGET_WAITKIND_SIGNALLED
6556 && last.kind != TARGET_WAITKIND_EXITED
6557 && last.kind != TARGET_WAITKIND_NO_RESUMED)
6559 target_terminal_ours_for_output ();
6560 printf_filtered (_("[Switching to %s]\n"),
6561 target_pid_to_str (inferior_ptid));
6562 annotate_thread_changed ();
6563 previous_inferior_ptid = inferior_ptid;
6566 if (last.kind == TARGET_WAITKIND_NO_RESUMED)
6568 gdb_assert (sync_execution || !target_can_async_p ());
6570 target_terminal_ours_for_output ();
6571 printf_filtered (_("No unwaited-for children left.\n"));
6574 /* Note: this depends on the update_thread_list call above. */
6575 if (!breakpoints_should_be_inserted_now () && target_has_execution)
6577 if (remove_breakpoints ())
6579 target_terminal_ours_for_output ();
6580 printf_filtered (_("Cannot remove breakpoints because "
6581 "program is no longer writable.\nFurther "
6582 "execution is probably impossible.\n"));
6586 /* If an auto-display called a function and that got a signal,
6587 delete that auto-display to avoid an infinite recursion. */
6589 if (stopped_by_random_signal)
6590 disable_current_display ();
6592 /* Notify observers if we finished a "step"-like command, etc. */
6593 if (target_has_execution
6594 && last.kind != TARGET_WAITKIND_SIGNALLED
6595 && last.kind != TARGET_WAITKIND_EXITED
6596 && inferior_thread ()->control.stop_step)
6598 /* But not if in the middle of doing a "step n" operation for
6600 if (inferior_thread ()->step_multi)
6603 observer_notify_end_stepping_range ();
6606 target_terminal_ours ();
6607 async_enable_stdin ();
6609 /* Set the current source location. This will also happen if we
6610 display the frame below, but the current SAL will be incorrect
6611 during a user hook-stop function. */
6612 if (has_stack_frames () && !stop_stack_dummy)
6613 set_current_sal_from_frame (get_current_frame ());
6615 /* Let the user/frontend see the threads as stopped, but do nothing
6616 if the thread was running an infcall. We may be e.g., evaluating
6617 a breakpoint condition. In that case, the thread had state
6618 THREAD_RUNNING before the infcall, and shall remain set to
6619 running, all without informing the user/frontend about state
6620 transition changes. If this is actually a call command, then the
6621 thread was originally already stopped, so there's no state to
6623 if (target_has_execution && inferior_thread ()->control.in_infcall)
6624 discard_cleanups (old_chain);
6626 do_cleanups (old_chain);
6628 /* Look up the hook_stop and run it (CLI internally handles problem
6629 of stop_command's pre-hook not existing). */
6631 catch_errors (hook_stop_stub, stop_command,
6632 "Error while running hook_stop:\n", RETURN_MASK_ALL);
6634 if (!has_stack_frames ())
6637 if (last.kind == TARGET_WAITKIND_SIGNALLED
6638 || last.kind == TARGET_WAITKIND_EXITED)
6641 /* Select innermost stack frame - i.e., current frame is frame 0,
6642 and current location is based on that.
6643 Don't do this on return from a stack dummy routine,
6644 or if the program has exited. */
6646 if (!stop_stack_dummy)
6648 select_frame (get_current_frame ());
6650 /* If --batch-silent is enabled then there's no need to print the current
6651 source location, and to try risks causing an error message about
6652 missing source files. */
6653 if (stop_print_frame && !batch_silent)
6654 print_stop_event (&last);
6657 /* Save the function value return registers, if we care.
6658 We might be about to restore their previous contents. */
6659 if (inferior_thread ()->control.proceed_to_finish
6660 && execution_direction != EXEC_REVERSE)
6662 /* This should not be necessary. */
6664 regcache_xfree (stop_registers);
6666 /* NB: The copy goes through to the target picking up the value of
6667 all the registers. */
6668 stop_registers = regcache_dup (get_current_regcache ());
6671 if (stop_stack_dummy == STOP_STACK_DUMMY)
6673 /* Pop the empty frame that contains the stack dummy.
6674 This also restores inferior state prior to the call
6675 (struct infcall_suspend_state). */
6676 struct frame_info *frame = get_current_frame ();
6678 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
6680 /* frame_pop() calls reinit_frame_cache as the last thing it
6681 does which means there's currently no selected frame. We
6682 don't need to re-establish a selected frame if the dummy call
6683 returns normally, that will be done by
6684 restore_infcall_control_state. However, we do have to handle
6685 the case where the dummy call is returning after being
6686 stopped (e.g. the dummy call previously hit a breakpoint).
6687 We can't know which case we have so just always re-establish
6688 a selected frame here. */
6689 select_frame (get_current_frame ());
6693 annotate_stopped ();
6695 /* Suppress the stop observer if we're in the middle of:
6697 - a step n (n > 1), as there still more steps to be done.
6699 - a "finish" command, as the observer will be called in
6700 finish_command_continuation, so it can include the inferior
6701 function's return value.
6703 - calling an inferior function, as we pretend we inferior didn't
6704 run at all. The return value of the call is handled by the
6705 expression evaluator, through call_function_by_hand. */
6707 if (!target_has_execution
6708 || last.kind == TARGET_WAITKIND_SIGNALLED
6709 || last.kind == TARGET_WAITKIND_EXITED
6710 || last.kind == TARGET_WAITKIND_NO_RESUMED
6711 || (!(inferior_thread ()->step_multi
6712 && inferior_thread ()->control.stop_step)
6713 && !(inferior_thread ()->control.stop_bpstat
6714 && inferior_thread ()->control.proceed_to_finish)
6715 && !inferior_thread ()->control.in_infcall))
6717 if (!ptid_equal (inferior_ptid, null_ptid))
6718 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
6721 observer_notify_normal_stop (NULL, stop_print_frame);
6724 if (target_has_execution)
6726 if (last.kind != TARGET_WAITKIND_SIGNALLED
6727 && last.kind != TARGET_WAITKIND_EXITED)
6728 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6729 Delete any breakpoint that is to be deleted at the next stop. */
6730 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
6733 /* Try to get rid of automatically added inferiors that are no
6734 longer needed. Keeping those around slows down things linearly.
6735 Note that this never removes the current inferior. */
6740 hook_stop_stub (void *cmd)
6742 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
6747 signal_stop_state (int signo)
6749 return signal_stop[signo];
6753 signal_print_state (int signo)
6755 return signal_print[signo];
6759 signal_pass_state (int signo)
6761 return signal_program[signo];
6765 signal_cache_update (int signo)
6769 for (signo = 0; signo < (int) GDB_SIGNAL_LAST; signo++)
6770 signal_cache_update (signo);
6775 signal_pass[signo] = (signal_stop[signo] == 0
6776 && signal_print[signo] == 0
6777 && signal_program[signo] == 1
6778 && signal_catch[signo] == 0);
6782 signal_stop_update (int signo, int state)
6784 int ret = signal_stop[signo];
6786 signal_stop[signo] = state;
6787 signal_cache_update (signo);
6792 signal_print_update (int signo, int state)
6794 int ret = signal_print[signo];
6796 signal_print[signo] = state;
6797 signal_cache_update (signo);
6802 signal_pass_update (int signo, int state)
6804 int ret = signal_program[signo];
6806 signal_program[signo] = state;
6807 signal_cache_update (signo);
6811 /* Update the global 'signal_catch' from INFO and notify the
6815 signal_catch_update (const unsigned int *info)
6819 for (i = 0; i < GDB_SIGNAL_LAST; ++i)
6820 signal_catch[i] = info[i] > 0;
6821 signal_cache_update (-1);
6822 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
6826 sig_print_header (void)
6828 printf_filtered (_("Signal Stop\tPrint\tPass "
6829 "to program\tDescription\n"));
6833 sig_print_info (enum gdb_signal oursig)
6835 const char *name = gdb_signal_to_name (oursig);
6836 int name_padding = 13 - strlen (name);
6838 if (name_padding <= 0)
6841 printf_filtered ("%s", name);
6842 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
6843 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
6844 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
6845 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
6846 printf_filtered ("%s\n", gdb_signal_to_string (oursig));
6849 /* Specify how various signals in the inferior should be handled. */
6852 handle_command (char *args, int from_tty)
6855 int digits, wordlen;
6856 int sigfirst, signum, siglast;
6857 enum gdb_signal oursig;
6860 unsigned char *sigs;
6861 struct cleanup *old_chain;
6865 error_no_arg (_("signal to handle"));
6868 /* Allocate and zero an array of flags for which signals to handle. */
6870 nsigs = (int) GDB_SIGNAL_LAST;
6871 sigs = (unsigned char *) alloca (nsigs);
6872 memset (sigs, 0, nsigs);
6874 /* Break the command line up into args. */
6876 argv = gdb_buildargv (args);
6877 old_chain = make_cleanup_freeargv (argv);
6879 /* Walk through the args, looking for signal oursigs, signal names, and
6880 actions. Signal numbers and signal names may be interspersed with
6881 actions, with the actions being performed for all signals cumulatively
6882 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6884 while (*argv != NULL)
6886 wordlen = strlen (*argv);
6887 for (digits = 0; isdigit ((*argv)[digits]); digits++)
6891 sigfirst = siglast = -1;
6893 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
6895 /* Apply action to all signals except those used by the
6896 debugger. Silently skip those. */
6899 siglast = nsigs - 1;
6901 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
6903 SET_SIGS (nsigs, sigs, signal_stop);
6904 SET_SIGS (nsigs, sigs, signal_print);
6906 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
6908 UNSET_SIGS (nsigs, sigs, signal_program);
6910 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
6912 SET_SIGS (nsigs, sigs, signal_print);
6914 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
6916 SET_SIGS (nsigs, sigs, signal_program);
6918 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
6920 UNSET_SIGS (nsigs, sigs, signal_stop);
6922 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
6924 SET_SIGS (nsigs, sigs, signal_program);
6926 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
6928 UNSET_SIGS (nsigs, sigs, signal_print);
6929 UNSET_SIGS (nsigs, sigs, signal_stop);
6931 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
6933 UNSET_SIGS (nsigs, sigs, signal_program);
6935 else if (digits > 0)
6937 /* It is numeric. The numeric signal refers to our own
6938 internal signal numbering from target.h, not to host/target
6939 signal number. This is a feature; users really should be
6940 using symbolic names anyway, and the common ones like
6941 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6943 sigfirst = siglast = (int)
6944 gdb_signal_from_command (atoi (*argv));
6945 if ((*argv)[digits] == '-')
6948 gdb_signal_from_command (atoi ((*argv) + digits + 1));
6950 if (sigfirst > siglast)
6952 /* Bet he didn't figure we'd think of this case... */
6960 oursig = gdb_signal_from_name (*argv);
6961 if (oursig != GDB_SIGNAL_UNKNOWN)
6963 sigfirst = siglast = (int) oursig;
6967 /* Not a number and not a recognized flag word => complain. */
6968 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
6972 /* If any signal numbers or symbol names were found, set flags for
6973 which signals to apply actions to. */
6975 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
6977 switch ((enum gdb_signal) signum)
6979 case GDB_SIGNAL_TRAP:
6980 case GDB_SIGNAL_INT:
6981 if (!allsigs && !sigs[signum])
6983 if (query (_("%s is used by the debugger.\n\
6984 Are you sure you want to change it? "),
6985 gdb_signal_to_name ((enum gdb_signal) signum)))
6991 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6992 gdb_flush (gdb_stdout);
6997 case GDB_SIGNAL_DEFAULT:
6998 case GDB_SIGNAL_UNKNOWN:
6999 /* Make sure that "all" doesn't print these. */
7010 for (signum = 0; signum < nsigs; signum++)
7013 signal_cache_update (-1);
7014 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
7015 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
7019 /* Show the results. */
7020 sig_print_header ();
7021 for (; signum < nsigs; signum++)
7023 sig_print_info (signum);
7029 do_cleanups (old_chain);
7032 /* Complete the "handle" command. */
7034 static VEC (char_ptr) *
7035 handle_completer (struct cmd_list_element *ignore,
7036 const char *text, const char *word)
7038 VEC (char_ptr) *vec_signals, *vec_keywords, *return_val;
7039 static const char * const keywords[] =
7053 vec_signals = signal_completer (ignore, text, word);
7054 vec_keywords = complete_on_enum (keywords, word, word);
7056 return_val = VEC_merge (char_ptr, vec_signals, vec_keywords);
7057 VEC_free (char_ptr, vec_signals);
7058 VEC_free (char_ptr, vec_keywords);
7063 xdb_handle_command (char *args, int from_tty)
7066 struct cleanup *old_chain;
7069 error_no_arg (_("xdb command"));
7071 /* Break the command line up into args. */
7073 argv = gdb_buildargv (args);
7074 old_chain = make_cleanup_freeargv (argv);
7075 if (argv[1] != (char *) NULL)
7080 bufLen = strlen (argv[0]) + 20;
7081 argBuf = (char *) xmalloc (bufLen);
7085 enum gdb_signal oursig;
7087 oursig = gdb_signal_from_name (argv[0]);
7088 memset (argBuf, 0, bufLen);
7089 if (strcmp (argv[1], "Q") == 0)
7090 sprintf (argBuf, "%s %s", argv[0], "noprint");
7093 if (strcmp (argv[1], "s") == 0)
7095 if (!signal_stop[oursig])
7096 sprintf (argBuf, "%s %s", argv[0], "stop");
7098 sprintf (argBuf, "%s %s", argv[0], "nostop");
7100 else if (strcmp (argv[1], "i") == 0)
7102 if (!signal_program[oursig])
7103 sprintf (argBuf, "%s %s", argv[0], "pass");
7105 sprintf (argBuf, "%s %s", argv[0], "nopass");
7107 else if (strcmp (argv[1], "r") == 0)
7109 if (!signal_print[oursig])
7110 sprintf (argBuf, "%s %s", argv[0], "print");
7112 sprintf (argBuf, "%s %s", argv[0], "noprint");
7118 handle_command (argBuf, from_tty);
7120 printf_filtered (_("Invalid signal handling flag.\n"));
7125 do_cleanups (old_chain);
7129 gdb_signal_from_command (int num)
7131 if (num >= 1 && num <= 15)
7132 return (enum gdb_signal) num;
7133 error (_("Only signals 1-15 are valid as numeric signals.\n\
7134 Use \"info signals\" for a list of symbolic signals."));
7137 /* Print current contents of the tables set by the handle command.
7138 It is possible we should just be printing signals actually used
7139 by the current target (but for things to work right when switching
7140 targets, all signals should be in the signal tables). */
7143 signals_info (char *signum_exp, int from_tty)
7145 enum gdb_signal oursig;
7147 sig_print_header ();
7151 /* First see if this is a symbol name. */
7152 oursig = gdb_signal_from_name (signum_exp);
7153 if (oursig == GDB_SIGNAL_UNKNOWN)
7155 /* No, try numeric. */
7157 gdb_signal_from_command (parse_and_eval_long (signum_exp));
7159 sig_print_info (oursig);
7163 printf_filtered ("\n");
7164 /* These ugly casts brought to you by the native VAX compiler. */
7165 for (oursig = GDB_SIGNAL_FIRST;
7166 (int) oursig < (int) GDB_SIGNAL_LAST;
7167 oursig = (enum gdb_signal) ((int) oursig + 1))
7171 if (oursig != GDB_SIGNAL_UNKNOWN
7172 && oursig != GDB_SIGNAL_DEFAULT && oursig != GDB_SIGNAL_0)
7173 sig_print_info (oursig);
7176 printf_filtered (_("\nUse the \"handle\" command "
7177 "to change these tables.\n"));
7180 /* Check if it makes sense to read $_siginfo from the current thread
7181 at this point. If not, throw an error. */
7184 validate_siginfo_access (void)
7186 /* No current inferior, no siginfo. */
7187 if (ptid_equal (inferior_ptid, null_ptid))
7188 error (_("No thread selected."));
7190 /* Don't try to read from a dead thread. */
7191 if (is_exited (inferior_ptid))
7192 error (_("The current thread has terminated"));
7194 /* ... or from a spinning thread. */
7195 if (is_running (inferior_ptid))
7196 error (_("Selected thread is running."));
7199 /* The $_siginfo convenience variable is a bit special. We don't know
7200 for sure the type of the value until we actually have a chance to
7201 fetch the data. The type can change depending on gdbarch, so it is
7202 also dependent on which thread you have selected.
7204 1. making $_siginfo be an internalvar that creates a new value on
7207 2. making the value of $_siginfo be an lval_computed value. */
7209 /* This function implements the lval_computed support for reading a
7213 siginfo_value_read (struct value *v)
7215 LONGEST transferred;
7217 validate_siginfo_access ();
7220 target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO,
7222 value_contents_all_raw (v),
7224 TYPE_LENGTH (value_type (v)));
7226 if (transferred != TYPE_LENGTH (value_type (v)))
7227 error (_("Unable to read siginfo"));
7230 /* This function implements the lval_computed support for writing a
7234 siginfo_value_write (struct value *v, struct value *fromval)
7236 LONGEST transferred;
7238 validate_siginfo_access ();
7240 transferred = target_write (¤t_target,
7241 TARGET_OBJECT_SIGNAL_INFO,
7243 value_contents_all_raw (fromval),
7245 TYPE_LENGTH (value_type (fromval)));
7247 if (transferred != TYPE_LENGTH (value_type (fromval)))
7248 error (_("Unable to write siginfo"));
7251 static const struct lval_funcs siginfo_value_funcs =
7257 /* Return a new value with the correct type for the siginfo object of
7258 the current thread using architecture GDBARCH. Return a void value
7259 if there's no object available. */
7261 static struct value *
7262 siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var,
7265 if (target_has_stack
7266 && !ptid_equal (inferior_ptid, null_ptid)
7267 && gdbarch_get_siginfo_type_p (gdbarch))
7269 struct type *type = gdbarch_get_siginfo_type (gdbarch);
7271 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
7274 return allocate_value (builtin_type (gdbarch)->builtin_void);
7278 /* infcall_suspend_state contains state about the program itself like its
7279 registers and any signal it received when it last stopped.
7280 This state must be restored regardless of how the inferior function call
7281 ends (either successfully, or after it hits a breakpoint or signal)
7282 if the program is to properly continue where it left off. */
7284 struct infcall_suspend_state
7286 struct thread_suspend_state thread_suspend;
7287 #if 0 /* Currently unused and empty structures are not valid C. */
7288 struct inferior_suspend_state inferior_suspend;
7293 struct regcache *registers;
7295 /* Format of SIGINFO_DATA or NULL if it is not present. */
7296 struct gdbarch *siginfo_gdbarch;
7298 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
7299 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
7300 content would be invalid. */
7301 gdb_byte *siginfo_data;
7304 struct infcall_suspend_state *
7305 save_infcall_suspend_state (void)
7307 struct infcall_suspend_state *inf_state;
7308 struct thread_info *tp = inferior_thread ();
7310 struct inferior *inf = current_inferior ();
7312 struct regcache *regcache = get_current_regcache ();
7313 struct gdbarch *gdbarch = get_regcache_arch (regcache);
7314 gdb_byte *siginfo_data = NULL;
7316 if (gdbarch_get_siginfo_type_p (gdbarch))
7318 struct type *type = gdbarch_get_siginfo_type (gdbarch);
7319 size_t len = TYPE_LENGTH (type);
7320 struct cleanup *back_to;
7322 siginfo_data = xmalloc (len);
7323 back_to = make_cleanup (xfree, siginfo_data);
7325 if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
7326 siginfo_data, 0, len) == len)
7327 discard_cleanups (back_to);
7330 /* Errors ignored. */
7331 do_cleanups (back_to);
7332 siginfo_data = NULL;
7336 inf_state = XCNEW (struct infcall_suspend_state);
7340 inf_state->siginfo_gdbarch = gdbarch;
7341 inf_state->siginfo_data = siginfo_data;
7344 inf_state->thread_suspend = tp->suspend;
7345 #if 0 /* Currently unused and empty structures are not valid C. */
7346 inf_state->inferior_suspend = inf->suspend;
7349 /* run_inferior_call will not use the signal due to its `proceed' call with
7350 GDB_SIGNAL_0 anyway. */
7351 tp->suspend.stop_signal = GDB_SIGNAL_0;
7353 inf_state->stop_pc = stop_pc;
7355 inf_state->registers = regcache_dup (regcache);
7360 /* Restore inferior session state to INF_STATE. */
7363 restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
7365 struct thread_info *tp = inferior_thread ();
7367 struct inferior *inf = current_inferior ();
7369 struct regcache *regcache = get_current_regcache ();
7370 struct gdbarch *gdbarch = get_regcache_arch (regcache);
7372 tp->suspend = inf_state->thread_suspend;
7373 #if 0 /* Currently unused and empty structures are not valid C. */
7374 inf->suspend = inf_state->inferior_suspend;
7377 stop_pc = inf_state->stop_pc;
7379 if (inf_state->siginfo_gdbarch == gdbarch)
7381 struct type *type = gdbarch_get_siginfo_type (gdbarch);
7383 /* Errors ignored. */
7384 target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
7385 inf_state->siginfo_data, 0, TYPE_LENGTH (type));
7388 /* The inferior can be gone if the user types "print exit(0)"
7389 (and perhaps other times). */
7390 if (target_has_execution)
7391 /* NB: The register write goes through to the target. */
7392 regcache_cpy (regcache, inf_state->registers);
7394 discard_infcall_suspend_state (inf_state);
7398 do_restore_infcall_suspend_state_cleanup (void *state)
7400 restore_infcall_suspend_state (state);
7404 make_cleanup_restore_infcall_suspend_state
7405 (struct infcall_suspend_state *inf_state)
7407 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
7411 discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
7413 regcache_xfree (inf_state->registers);
7414 xfree (inf_state->siginfo_data);
7419 get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
7421 return inf_state->registers;
7424 /* infcall_control_state contains state regarding gdb's control of the
7425 inferior itself like stepping control. It also contains session state like
7426 the user's currently selected frame. */
7428 struct infcall_control_state
7430 struct thread_control_state thread_control;
7431 struct inferior_control_state inferior_control;
7434 enum stop_stack_kind stop_stack_dummy;
7435 int stopped_by_random_signal;
7436 int stop_after_trap;
7438 /* ID if the selected frame when the inferior function call was made. */
7439 struct frame_id selected_frame_id;
7442 /* Save all of the information associated with the inferior<==>gdb
7445 struct infcall_control_state *
7446 save_infcall_control_state (void)
7448 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
7449 struct thread_info *tp = inferior_thread ();
7450 struct inferior *inf = current_inferior ();
7452 inf_status->thread_control = tp->control;
7453 inf_status->inferior_control = inf->control;
7455 tp->control.step_resume_breakpoint = NULL;
7456 tp->control.exception_resume_breakpoint = NULL;
7458 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
7459 chain. If caller's caller is walking the chain, they'll be happier if we
7460 hand them back the original chain when restore_infcall_control_state is
7462 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
7465 inf_status->stop_stack_dummy = stop_stack_dummy;
7466 inf_status->stopped_by_random_signal = stopped_by_random_signal;
7467 inf_status->stop_after_trap = stop_after_trap;
7469 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
7475 restore_selected_frame (void *args)
7477 struct frame_id *fid = (struct frame_id *) args;
7478 struct frame_info *frame;
7480 frame = frame_find_by_id (*fid);
7482 /* If inf_status->selected_frame_id is NULL, there was no previously
7486 warning (_("Unable to restore previously selected frame."));
7490 select_frame (frame);
7495 /* Restore inferior session state to INF_STATUS. */
7498 restore_infcall_control_state (struct infcall_control_state *inf_status)
7500 struct thread_info *tp = inferior_thread ();
7501 struct inferior *inf = current_inferior ();
7503 if (tp->control.step_resume_breakpoint)
7504 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
7506 if (tp->control.exception_resume_breakpoint)
7507 tp->control.exception_resume_breakpoint->disposition
7508 = disp_del_at_next_stop;
7510 /* Handle the bpstat_copy of the chain. */
7511 bpstat_clear (&tp->control.stop_bpstat);
7513 tp->control = inf_status->thread_control;
7514 inf->control = inf_status->inferior_control;
7517 stop_stack_dummy = inf_status->stop_stack_dummy;
7518 stopped_by_random_signal = inf_status->stopped_by_random_signal;
7519 stop_after_trap = inf_status->stop_after_trap;
7521 if (target_has_stack)
7523 /* The point of catch_errors is that if the stack is clobbered,
7524 walking the stack might encounter a garbage pointer and
7525 error() trying to dereference it. */
7527 (restore_selected_frame, &inf_status->selected_frame_id,
7528 "Unable to restore previously selected frame:\n",
7529 RETURN_MASK_ERROR) == 0)
7530 /* Error in restoring the selected frame. Select the innermost
7532 select_frame (get_current_frame ());
7539 do_restore_infcall_control_state_cleanup (void *sts)
7541 restore_infcall_control_state (sts);
7545 make_cleanup_restore_infcall_control_state
7546 (struct infcall_control_state *inf_status)
7548 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
7552 discard_infcall_control_state (struct infcall_control_state *inf_status)
7554 if (inf_status->thread_control.step_resume_breakpoint)
7555 inf_status->thread_control.step_resume_breakpoint->disposition
7556 = disp_del_at_next_stop;
7558 if (inf_status->thread_control.exception_resume_breakpoint)
7559 inf_status->thread_control.exception_resume_breakpoint->disposition
7560 = disp_del_at_next_stop;
7562 /* See save_infcall_control_state for info on stop_bpstat. */
7563 bpstat_clear (&inf_status->thread_control.stop_bpstat);
7568 /* restore_inferior_ptid() will be used by the cleanup machinery
7569 to restore the inferior_ptid value saved in a call to
7570 save_inferior_ptid(). */
7573 restore_inferior_ptid (void *arg)
7575 ptid_t *saved_ptid_ptr = arg;
7577 inferior_ptid = *saved_ptid_ptr;
7581 /* Save the value of inferior_ptid so that it may be restored by a
7582 later call to do_cleanups(). Returns the struct cleanup pointer
7583 needed for later doing the cleanup. */
7586 save_inferior_ptid (void)
7588 ptid_t *saved_ptid_ptr;
7590 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
7591 *saved_ptid_ptr = inferior_ptid;
7592 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
7598 clear_exit_convenience_vars (void)
7600 clear_internalvar (lookup_internalvar ("_exitsignal"));
7601 clear_internalvar (lookup_internalvar ("_exitcode"));
7605 /* User interface for reverse debugging:
7606 Set exec-direction / show exec-direction commands
7607 (returns error unless target implements to_set_exec_direction method). */
7609 int execution_direction = EXEC_FORWARD;
7610 static const char exec_forward[] = "forward";
7611 static const char exec_reverse[] = "reverse";
7612 static const char *exec_direction = exec_forward;
7613 static const char *const exec_direction_names[] = {
7620 set_exec_direction_func (char *args, int from_tty,
7621 struct cmd_list_element *cmd)
7623 if (target_can_execute_reverse)
7625 if (!strcmp (exec_direction, exec_forward))
7626 execution_direction = EXEC_FORWARD;
7627 else if (!strcmp (exec_direction, exec_reverse))
7628 execution_direction = EXEC_REVERSE;
7632 exec_direction = exec_forward;
7633 error (_("Target does not support this operation."));
7638 show_exec_direction_func (struct ui_file *out, int from_tty,
7639 struct cmd_list_element *cmd, const char *value)
7641 switch (execution_direction) {
7643 fprintf_filtered (out, _("Forward.\n"));
7646 fprintf_filtered (out, _("Reverse.\n"));
7649 internal_error (__FILE__, __LINE__,
7650 _("bogus execution_direction value: %d"),
7651 (int) execution_direction);
7656 show_schedule_multiple (struct ui_file *file, int from_tty,
7657 struct cmd_list_element *c, const char *value)
7659 fprintf_filtered (file, _("Resuming the execution of threads "
7660 "of all processes is %s.\n"), value);
7663 /* Implementation of `siginfo' variable. */
7665 static const struct internalvar_funcs siginfo_funcs =
7673 _initialize_infrun (void)
7677 struct cmd_list_element *c;
7679 add_info ("signals", signals_info, _("\
7680 What debugger does when program gets various signals.\n\
7681 Specify a signal as argument to print info on that signal only."));
7682 add_info_alias ("handle", "signals", 0);
7684 c = add_com ("handle", class_run, handle_command, _("\
7685 Specify how to handle signals.\n\
7686 Usage: handle SIGNAL [ACTIONS]\n\
7687 Args are signals and actions to apply to those signals.\n\
7688 If no actions are specified, the current settings for the specified signals\n\
7689 will be displayed instead.\n\
7691 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7692 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7693 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7694 The special arg \"all\" is recognized to mean all signals except those\n\
7695 used by the debugger, typically SIGTRAP and SIGINT.\n\
7697 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7698 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7699 Stop means reenter debugger if this signal happens (implies print).\n\
7700 Print means print a message if this signal happens.\n\
7701 Pass means let program see this signal; otherwise program doesn't know.\n\
7702 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7703 Pass and Stop may be combined.\n\
7705 Multiple signals may be specified. Signal numbers and signal names\n\
7706 may be interspersed with actions, with the actions being performed for\n\
7707 all signals cumulatively specified."));
7708 set_cmd_completer (c, handle_completer);
7712 add_com ("lz", class_info, signals_info, _("\
7713 What debugger does when program gets various signals.\n\
7714 Specify a signal as argument to print info on that signal only."));
7715 add_com ("z", class_run, xdb_handle_command, _("\
7716 Specify how to handle a signal.\n\
7717 Args are signals and actions to apply to those signals.\n\
7718 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7719 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7720 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7721 The special arg \"all\" is recognized to mean all signals except those\n\
7722 used by the debugger, typically SIGTRAP and SIGINT.\n\
7723 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7724 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7725 nopass), \"Q\" (noprint)\n\
7726 Stop means reenter debugger if this signal happens (implies print).\n\
7727 Print means print a message if this signal happens.\n\
7728 Pass means let program see this signal; otherwise program doesn't know.\n\
7729 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7730 Pass and Stop may be combined."));
7734 stop_command = add_cmd ("stop", class_obscure,
7735 not_just_help_class_command, _("\
7736 There is no `stop' command, but you can set a hook on `stop'.\n\
7737 This allows you to set a list of commands to be run each time execution\n\
7738 of the program stops."), &cmdlist);
7740 add_setshow_zuinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
7741 Set inferior debugging."), _("\
7742 Show inferior debugging."), _("\
7743 When non-zero, inferior specific debugging is enabled."),
7746 &setdebuglist, &showdebuglist);
7748 add_setshow_boolean_cmd ("displaced", class_maintenance,
7749 &debug_displaced, _("\
7750 Set displaced stepping debugging."), _("\
7751 Show displaced stepping debugging."), _("\
7752 When non-zero, displaced stepping specific debugging is enabled."),
7754 show_debug_displaced,
7755 &setdebuglist, &showdebuglist);
7757 add_setshow_boolean_cmd ("non-stop", no_class,
7759 Set whether gdb controls the inferior in non-stop mode."), _("\
7760 Show whether gdb controls the inferior in non-stop mode."), _("\
7761 When debugging a multi-threaded program and this setting is\n\
7762 off (the default, also called all-stop mode), when one thread stops\n\
7763 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7764 all other threads in the program while you interact with the thread of\n\
7765 interest. When you continue or step a thread, you can allow the other\n\
7766 threads to run, or have them remain stopped, but while you inspect any\n\
7767 thread's state, all threads stop.\n\
7769 In non-stop mode, when one thread stops, other threads can continue\n\
7770 to run freely. You'll be able to step each thread independently,\n\
7771 leave it stopped or free to run as needed."),
7777 numsigs = (int) GDB_SIGNAL_LAST;
7778 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
7779 signal_print = (unsigned char *)
7780 xmalloc (sizeof (signal_print[0]) * numsigs);
7781 signal_program = (unsigned char *)
7782 xmalloc (sizeof (signal_program[0]) * numsigs);
7783 signal_catch = (unsigned char *)
7784 xmalloc (sizeof (signal_catch[0]) * numsigs);
7785 signal_pass = (unsigned char *)
7786 xmalloc (sizeof (signal_pass[0]) * numsigs);
7787 for (i = 0; i < numsigs; i++)
7790 signal_print[i] = 1;
7791 signal_program[i] = 1;
7792 signal_catch[i] = 0;
7795 /* Signals caused by debugger's own actions
7796 should not be given to the program afterwards. */
7797 signal_program[GDB_SIGNAL_TRAP] = 0;
7798 signal_program[GDB_SIGNAL_INT] = 0;
7800 /* Signals that are not errors should not normally enter the debugger. */
7801 signal_stop[GDB_SIGNAL_ALRM] = 0;
7802 signal_print[GDB_SIGNAL_ALRM] = 0;
7803 signal_stop[GDB_SIGNAL_VTALRM] = 0;
7804 signal_print[GDB_SIGNAL_VTALRM] = 0;
7805 signal_stop[GDB_SIGNAL_PROF] = 0;
7806 signal_print[GDB_SIGNAL_PROF] = 0;
7807 signal_stop[GDB_SIGNAL_CHLD] = 0;
7808 signal_print[GDB_SIGNAL_CHLD] = 0;
7809 signal_stop[GDB_SIGNAL_IO] = 0;
7810 signal_print[GDB_SIGNAL_IO] = 0;
7811 signal_stop[GDB_SIGNAL_POLL] = 0;
7812 signal_print[GDB_SIGNAL_POLL] = 0;
7813 signal_stop[GDB_SIGNAL_URG] = 0;
7814 signal_print[GDB_SIGNAL_URG] = 0;
7815 signal_stop[GDB_SIGNAL_WINCH] = 0;
7816 signal_print[GDB_SIGNAL_WINCH] = 0;
7817 signal_stop[GDB_SIGNAL_PRIO] = 0;
7818 signal_print[GDB_SIGNAL_PRIO] = 0;
7820 /* These signals are used internally by user-level thread
7821 implementations. (See signal(5) on Solaris.) Like the above
7822 signals, a healthy program receives and handles them as part of
7823 its normal operation. */
7824 signal_stop[GDB_SIGNAL_LWP] = 0;
7825 signal_print[GDB_SIGNAL_LWP] = 0;
7826 signal_stop[GDB_SIGNAL_WAITING] = 0;
7827 signal_print[GDB_SIGNAL_WAITING] = 0;
7828 signal_stop[GDB_SIGNAL_CANCEL] = 0;
7829 signal_print[GDB_SIGNAL_CANCEL] = 0;
7831 /* Update cached state. */
7832 signal_cache_update (-1);
7834 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
7835 &stop_on_solib_events, _("\
7836 Set stopping for shared library events."), _("\
7837 Show stopping for shared library events."), _("\
7838 If nonzero, gdb will give control to the user when the dynamic linker\n\
7839 notifies gdb of shared library events. The most common event of interest\n\
7840 to the user would be loading/unloading of a new library."),
7841 set_stop_on_solib_events,
7842 show_stop_on_solib_events,
7843 &setlist, &showlist);
7845 add_setshow_enum_cmd ("follow-fork-mode", class_run,
7846 follow_fork_mode_kind_names,
7847 &follow_fork_mode_string, _("\
7848 Set debugger response to a program call of fork or vfork."), _("\
7849 Show debugger response to a program call of fork or vfork."), _("\
7850 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7851 parent - the original process is debugged after a fork\n\
7852 child - the new process is debugged after a fork\n\
7853 The unfollowed process will continue to run.\n\
7854 By default, the debugger will follow the parent process."),
7856 show_follow_fork_mode_string,
7857 &setlist, &showlist);
7859 add_setshow_enum_cmd ("follow-exec-mode", class_run,
7860 follow_exec_mode_names,
7861 &follow_exec_mode_string, _("\
7862 Set debugger response to a program call of exec."), _("\
7863 Show debugger response to a program call of exec."), _("\
7864 An exec call replaces the program image of a process.\n\
7866 follow-exec-mode can be:\n\
7868 new - the debugger creates a new inferior and rebinds the process\n\
7869 to this new inferior. The program the process was running before\n\
7870 the exec call can be restarted afterwards by restarting the original\n\
7873 same - the debugger keeps the process bound to the same inferior.\n\
7874 The new executable image replaces the previous executable loaded in\n\
7875 the inferior. Restarting the inferior after the exec call restarts\n\
7876 the executable the process was running after the exec call.\n\
7878 By default, the debugger will use the same inferior."),
7880 show_follow_exec_mode_string,
7881 &setlist, &showlist);
7883 add_setshow_enum_cmd ("scheduler-locking", class_run,
7884 scheduler_enums, &scheduler_mode, _("\
7885 Set mode for locking scheduler during execution."), _("\
7886 Show mode for locking scheduler during execution."), _("\
7887 off == no locking (threads may preempt at any time)\n\
7888 on == full locking (no thread except the current thread may run)\n\
7889 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
7890 In this mode, other threads may run during other commands."),
7891 set_schedlock_func, /* traps on target vector */
7892 show_scheduler_mode,
7893 &setlist, &showlist);
7895 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
7896 Set mode for resuming threads of all processes."), _("\
7897 Show mode for resuming threads of all processes."), _("\
7898 When on, execution commands (such as 'continue' or 'next') resume all\n\
7899 threads of all processes. When off (which is the default), execution\n\
7900 commands only resume the threads of the current process. The set of\n\
7901 threads that are resumed is further refined by the scheduler-locking\n\
7902 mode (see help set scheduler-locking)."),
7904 show_schedule_multiple,
7905 &setlist, &showlist);
7907 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
7908 Set mode of the step operation."), _("\
7909 Show mode of the step operation."), _("\
7910 When set, doing a step over a function without debug line information\n\
7911 will stop at the first instruction of that function. Otherwise, the\n\
7912 function is skipped and the step command stops at a different source line."),
7914 show_step_stop_if_no_debug,
7915 &setlist, &showlist);
7917 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run,
7918 &can_use_displaced_stepping, _("\
7919 Set debugger's willingness to use displaced stepping."), _("\
7920 Show debugger's willingness to use displaced stepping."), _("\
7921 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7922 supported by the target architecture. If off, gdb will not use displaced\n\
7923 stepping to step over breakpoints, even if such is supported by the target\n\
7924 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7925 if the target architecture supports it and non-stop mode is active, but will not\n\
7926 use it in all-stop mode (see help set non-stop)."),
7928 show_can_use_displaced_stepping,
7929 &setlist, &showlist);
7931 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
7932 &exec_direction, _("Set direction of execution.\n\
7933 Options are 'forward' or 'reverse'."),
7934 _("Show direction of execution (forward/reverse)."),
7935 _("Tells gdb whether to execute forward or backward."),
7936 set_exec_direction_func, show_exec_direction_func,
7937 &setlist, &showlist);
7939 /* Set/show detach-on-fork: user-settable mode. */
7941 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
7942 Set whether gdb will detach the child of a fork."), _("\
7943 Show whether gdb will detach the child of a fork."), _("\
7944 Tells gdb whether to detach the child of a fork."),
7945 NULL, NULL, &setlist, &showlist);
7947 /* Set/show disable address space randomization mode. */
7949 add_setshow_boolean_cmd ("disable-randomization", class_support,
7950 &disable_randomization, _("\
7951 Set disabling of debuggee's virtual address space randomization."), _("\
7952 Show disabling of debuggee's virtual address space randomization."), _("\
7953 When this mode is on (which is the default), randomization of the virtual\n\
7954 address space is disabled. Standalone programs run with the randomization\n\
7955 enabled by default on some platforms."),
7956 &set_disable_randomization,
7957 &show_disable_randomization,
7958 &setlist, &showlist);
7960 /* ptid initializations */
7961 inferior_ptid = null_ptid;
7962 target_last_wait_ptid = minus_one_ptid;
7964 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
7965 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
7966 observer_attach_thread_exit (infrun_thread_thread_exit);
7967 observer_attach_inferior_exit (infrun_inferior_exit);
7969 /* Explicitly create without lookup, since that tries to create a
7970 value with a void typed value, and when we get here, gdbarch
7971 isn't initialized yet. At this point, we're quite sure there
7972 isn't another convenience variable of the same name. */
7973 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs, NULL);
7975 add_setshow_boolean_cmd ("observer", no_class,
7976 &observer_mode_1, _("\
7977 Set whether gdb controls the inferior in observer mode."), _("\
7978 Show whether gdb controls the inferior in observer mode."), _("\
7979 In observer mode, GDB can get data from the inferior, but not\n\
7980 affect its execution. Registers and memory may not be changed,\n\
7981 breakpoints may not be set, and the program cannot be interrupted\n\