1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2013 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/>. */
22 #include "gdb_string.h"
27 #include "exceptions.h"
28 #include "breakpoint.h"
32 #include "cli/cli-script.h"
34 #include "gdbthread.h"
46 #include "dictionary.h"
48 #include "gdb_assert.h"
49 #include "mi/mi-common.h"
50 #include "event-top.h"
52 #include "record-full.h"
53 #include "inline-frame.h"
55 #include "tracepoint.h"
56 #include "continuations.h"
61 #include "completer.h"
62 #include "target-descriptions.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 void set_schedlock_func (char *args, int from_tty,
83 struct cmd_list_element *c);
85 static int currently_stepping (struct thread_info *tp);
87 static int currently_stepping_or_nexting_callback (struct thread_info *tp,
90 static void xdb_handle_command (char *args, int from_tty);
92 static int prepare_to_proceed (int);
94 static void print_exited_reason (int exitstatus);
96 static void print_signal_exited_reason (enum gdb_signal siggnal);
98 static void print_no_history_reason (void);
100 static void print_signal_received_reason (enum gdb_signal siggnal);
102 static void print_end_stepping_range_reason (void);
104 void _initialize_infrun (void);
106 void nullify_last_target_wait_ptid (void);
108 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info *);
110 static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
112 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
114 /* When set, stop the 'step' command if we enter a function which has
115 no line number information. The normal behavior is that we step
116 over such function. */
117 int step_stop_if_no_debug = 0;
119 show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
120 struct cmd_list_element *c, const char *value)
122 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
125 /* In asynchronous mode, but simulating synchronous execution. */
127 int sync_execution = 0;
129 /* wait_for_inferior and normal_stop use this to notify the user
130 when the inferior stopped in a different thread than it had been
133 static ptid_t previous_inferior_ptid;
135 /* Default behavior is to detach newly forked processes (legacy). */
138 int debug_displaced = 0;
140 show_debug_displaced (struct ui_file *file, int from_tty,
141 struct cmd_list_element *c, const char *value)
143 fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value);
146 unsigned int debug_infrun = 0;
148 show_debug_infrun (struct ui_file *file, int from_tty,
149 struct cmd_list_element *c, const char *value)
151 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
155 /* Support for disabling address space randomization. */
157 int disable_randomization = 1;
160 show_disable_randomization (struct ui_file *file, int from_tty,
161 struct cmd_list_element *c, const char *value)
163 if (target_supports_disable_randomization ())
164 fprintf_filtered (file,
165 _("Disabling randomization of debuggee's "
166 "virtual address space is %s.\n"),
169 fputs_filtered (_("Disabling randomization of debuggee's "
170 "virtual address space is unsupported on\n"
171 "this platform.\n"), file);
175 set_disable_randomization (char *args, int from_tty,
176 struct cmd_list_element *c)
178 if (!target_supports_disable_randomization ())
179 error (_("Disabling randomization of debuggee's "
180 "virtual address space is unsupported on\n"
185 /* If the program uses ELF-style shared libraries, then calls to
186 functions in shared libraries go through stubs, which live in a
187 table called the PLT (Procedure Linkage Table). The first time the
188 function is called, the stub sends control to the dynamic linker,
189 which looks up the function's real address, patches the stub so
190 that future calls will go directly to the function, and then passes
191 control to the function.
193 If we are stepping at the source level, we don't want to see any of
194 this --- we just want to skip over the stub and the dynamic linker.
195 The simple approach is to single-step until control leaves the
198 However, on some systems (e.g., Red Hat's 5.2 distribution) the
199 dynamic linker calls functions in the shared C library, so you
200 can't tell from the PC alone whether the dynamic linker is still
201 running. In this case, we use a step-resume breakpoint to get us
202 past the dynamic linker, as if we were using "next" to step over a
205 in_solib_dynsym_resolve_code() says whether we're in the dynamic
206 linker code or not. Normally, this means we single-step. However,
207 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
208 address where we can place a step-resume breakpoint to get past the
209 linker's symbol resolution function.
211 in_solib_dynsym_resolve_code() can generally be implemented in a
212 pretty portable way, by comparing the PC against the address ranges
213 of the dynamic linker's sections.
215 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
216 it depends on internal details of the dynamic linker. It's usually
217 not too hard to figure out where to put a breakpoint, but it
218 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
219 sanity checking. If it can't figure things out, returning zero and
220 getting the (possibly confusing) stepping behavior is better than
221 signalling an error, which will obscure the change in the
224 /* This function returns TRUE if pc is the address of an instruction
225 that lies within the dynamic linker (such as the event hook, or the
228 This function must be used only when a dynamic linker event has
229 been caught, and the inferior is being stepped out of the hook, or
230 undefined results are guaranteed. */
232 #ifndef SOLIB_IN_DYNAMIC_LINKER
233 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
236 /* "Observer mode" is somewhat like a more extreme version of
237 non-stop, in which all GDB operations that might affect the
238 target's execution have been disabled. */
240 static int non_stop_1 = 0;
242 int observer_mode = 0;
243 static int observer_mode_1 = 0;
246 set_observer_mode (char *args, int from_tty,
247 struct cmd_list_element *c)
249 extern int pagination_enabled;
251 if (target_has_execution)
253 observer_mode_1 = observer_mode;
254 error (_("Cannot change this setting while the inferior is running."));
257 observer_mode = observer_mode_1;
259 may_write_registers = !observer_mode;
260 may_write_memory = !observer_mode;
261 may_insert_breakpoints = !observer_mode;
262 may_insert_tracepoints = !observer_mode;
263 /* We can insert fast tracepoints in or out of observer mode,
264 but enable them if we're going into this mode. */
266 may_insert_fast_tracepoints = 1;
267 may_stop = !observer_mode;
268 update_target_permissions ();
270 /* Going *into* observer mode we must force non-stop, then
271 going out we leave it that way. */
274 target_async_permitted = 1;
275 pagination_enabled = 0;
276 non_stop = non_stop_1 = 1;
280 printf_filtered (_("Observer mode is now %s.\n"),
281 (observer_mode ? "on" : "off"));
285 show_observer_mode (struct ui_file *file, int from_tty,
286 struct cmd_list_element *c, const char *value)
288 fprintf_filtered (file, _("Observer mode is %s.\n"), value);
291 /* This updates the value of observer mode based on changes in
292 permissions. Note that we are deliberately ignoring the values of
293 may-write-registers and may-write-memory, since the user may have
294 reason to enable these during a session, for instance to turn on a
295 debugging-related global. */
298 update_observer_mode (void)
302 newval = (!may_insert_breakpoints
303 && !may_insert_tracepoints
304 && may_insert_fast_tracepoints
308 /* Let the user know if things change. */
309 if (newval != observer_mode)
310 printf_filtered (_("Observer mode is now %s.\n"),
311 (newval ? "on" : "off"));
313 observer_mode = observer_mode_1 = newval;
316 /* Tables of how to react to signals; the user sets them. */
318 static unsigned char *signal_stop;
319 static unsigned char *signal_print;
320 static unsigned char *signal_program;
322 /* Table of signals that are registered with "catch signal". A
323 non-zero entry indicates that the signal is caught by some "catch
324 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
326 static unsigned char *signal_catch;
328 /* Table of signals that the target may silently handle.
329 This is automatically determined from the flags above,
330 and simply cached here. */
331 static unsigned char *signal_pass;
333 #define SET_SIGS(nsigs,sigs,flags) \
335 int signum = (nsigs); \
336 while (signum-- > 0) \
337 if ((sigs)[signum]) \
338 (flags)[signum] = 1; \
341 #define UNSET_SIGS(nsigs,sigs,flags) \
343 int signum = (nsigs); \
344 while (signum-- > 0) \
345 if ((sigs)[signum]) \
346 (flags)[signum] = 0; \
349 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
350 this function is to avoid exporting `signal_program'. */
353 update_signals_program_target (void)
355 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
358 /* Value to pass to target_resume() to cause all threads to resume. */
360 #define RESUME_ALL minus_one_ptid
362 /* Command list pointer for the "stop" placeholder. */
364 static struct cmd_list_element *stop_command;
366 /* Function inferior was in as of last step command. */
368 static struct symbol *step_start_function;
370 /* Nonzero if we want to give control to the user when we're notified
371 of shared library events by the dynamic linker. */
372 int stop_on_solib_events;
374 /* Enable or disable optional shared library event breakpoints
375 as appropriate when the above flag is changed. */
378 set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c)
380 update_solib_breakpoints ();
384 show_stop_on_solib_events (struct ui_file *file, int from_tty,
385 struct cmd_list_element *c, const char *value)
387 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
391 /* Nonzero means expecting a trace trap
392 and should stop the inferior and return silently when it happens. */
396 /* Save register contents here when executing a "finish" command or are
397 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
398 Thus this contains the return value from the called function (assuming
399 values are returned in a register). */
401 struct regcache *stop_registers;
403 /* Nonzero after stop if current stack frame should be printed. */
405 static int stop_print_frame;
407 /* This is a cached copy of the pid/waitstatus of the last event
408 returned by target_wait()/deprecated_target_wait_hook(). This
409 information is returned by get_last_target_status(). */
410 static ptid_t target_last_wait_ptid;
411 static struct target_waitstatus target_last_waitstatus;
413 static void context_switch (ptid_t ptid);
415 void init_thread_stepping_state (struct thread_info *tss);
417 static void init_infwait_state (void);
419 static const char follow_fork_mode_child[] = "child";
420 static const char follow_fork_mode_parent[] = "parent";
422 static const char *const follow_fork_mode_kind_names[] = {
423 follow_fork_mode_child,
424 follow_fork_mode_parent,
428 static const char *follow_fork_mode_string = follow_fork_mode_parent;
430 show_follow_fork_mode_string (struct ui_file *file, int from_tty,
431 struct cmd_list_element *c, const char *value)
433 fprintf_filtered (file,
434 _("Debugger response to a program "
435 "call of fork or vfork is \"%s\".\n"),
440 /* Tell the target to follow the fork we're stopped at. Returns true
441 if the inferior should be resumed; false, if the target for some
442 reason decided it's best not to resume. */
447 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
448 int should_resume = 1;
449 struct thread_info *tp;
451 /* Copy user stepping state to the new inferior thread. FIXME: the
452 followed fork child thread should have a copy of most of the
453 parent thread structure's run control related fields, not just these.
454 Initialized to avoid "may be used uninitialized" warnings from gcc. */
455 struct breakpoint *step_resume_breakpoint = NULL;
456 struct breakpoint *exception_resume_breakpoint = NULL;
457 CORE_ADDR step_range_start = 0;
458 CORE_ADDR step_range_end = 0;
459 struct frame_id step_frame_id = { 0 };
464 struct target_waitstatus wait_status;
466 /* Get the last target status returned by target_wait(). */
467 get_last_target_status (&wait_ptid, &wait_status);
469 /* If not stopped at a fork event, then there's nothing else to
471 if (wait_status.kind != TARGET_WAITKIND_FORKED
472 && wait_status.kind != TARGET_WAITKIND_VFORKED)
475 /* Check if we switched over from WAIT_PTID, since the event was
477 if (!ptid_equal (wait_ptid, minus_one_ptid)
478 && !ptid_equal (inferior_ptid, wait_ptid))
480 /* We did. Switch back to WAIT_PTID thread, to tell the
481 target to follow it (in either direction). We'll
482 afterwards refuse to resume, and inform the user what
484 switch_to_thread (wait_ptid);
489 tp = inferior_thread ();
491 /* If there were any forks/vforks that were caught and are now to be
492 followed, then do so now. */
493 switch (tp->pending_follow.kind)
495 case TARGET_WAITKIND_FORKED:
496 case TARGET_WAITKIND_VFORKED:
498 ptid_t parent, child;
500 /* If the user did a next/step, etc, over a fork call,
501 preserve the stepping state in the fork child. */
502 if (follow_child && should_resume)
504 step_resume_breakpoint = clone_momentary_breakpoint
505 (tp->control.step_resume_breakpoint);
506 step_range_start = tp->control.step_range_start;
507 step_range_end = tp->control.step_range_end;
508 step_frame_id = tp->control.step_frame_id;
509 exception_resume_breakpoint
510 = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint);
512 /* For now, delete the parent's sr breakpoint, otherwise,
513 parent/child sr breakpoints are considered duplicates,
514 and the child version will not be installed. Remove
515 this when the breakpoints module becomes aware of
516 inferiors and address spaces. */
517 delete_step_resume_breakpoint (tp);
518 tp->control.step_range_start = 0;
519 tp->control.step_range_end = 0;
520 tp->control.step_frame_id = null_frame_id;
521 delete_exception_resume_breakpoint (tp);
524 parent = inferior_ptid;
525 child = tp->pending_follow.value.related_pid;
527 /* Tell the target to do whatever is necessary to follow
528 either parent or child. */
529 if (target_follow_fork (follow_child))
531 /* Target refused to follow, or there's some other reason
532 we shouldn't resume. */
537 /* This pending follow fork event is now handled, one way
538 or another. The previous selected thread may be gone
539 from the lists by now, but if it is still around, need
540 to clear the pending follow request. */
541 tp = find_thread_ptid (parent);
543 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
545 /* This makes sure we don't try to apply the "Switched
546 over from WAIT_PID" logic above. */
547 nullify_last_target_wait_ptid ();
549 /* If we followed the child, switch to it... */
552 switch_to_thread (child);
554 /* ... and preserve the stepping state, in case the
555 user was stepping over the fork call. */
558 tp = inferior_thread ();
559 tp->control.step_resume_breakpoint
560 = step_resume_breakpoint;
561 tp->control.step_range_start = step_range_start;
562 tp->control.step_range_end = step_range_end;
563 tp->control.step_frame_id = step_frame_id;
564 tp->control.exception_resume_breakpoint
565 = exception_resume_breakpoint;
569 /* If we get here, it was because we're trying to
570 resume from a fork catchpoint, but, the user
571 has switched threads away from the thread that
572 forked. In that case, the resume command
573 issued is most likely not applicable to the
574 child, so just warn, and refuse to resume. */
575 warning (_("Not resuming: switched threads "
576 "before following fork child.\n"));
579 /* Reset breakpoints in the child as appropriate. */
580 follow_inferior_reset_breakpoints ();
583 switch_to_thread (parent);
587 case TARGET_WAITKIND_SPURIOUS:
588 /* Nothing to follow. */
591 internal_error (__FILE__, __LINE__,
592 "Unexpected pending_follow.kind %d\n",
593 tp->pending_follow.kind);
597 return should_resume;
601 follow_inferior_reset_breakpoints (void)
603 struct thread_info *tp = inferior_thread ();
605 /* Was there a step_resume breakpoint? (There was if the user
606 did a "next" at the fork() call.) If so, explicitly reset its
609 step_resumes are a form of bp that are made to be per-thread.
610 Since we created the step_resume bp when the parent process
611 was being debugged, and now are switching to the child process,
612 from the breakpoint package's viewpoint, that's a switch of
613 "threads". We must update the bp's notion of which thread
614 it is for, or it'll be ignored when it triggers. */
616 if (tp->control.step_resume_breakpoint)
617 breakpoint_re_set_thread (tp->control.step_resume_breakpoint);
619 if (tp->control.exception_resume_breakpoint)
620 breakpoint_re_set_thread (tp->control.exception_resume_breakpoint);
622 /* Reinsert all breakpoints in the child. The user may have set
623 breakpoints after catching the fork, in which case those
624 were never set in the child, but only in the parent. This makes
625 sure the inserted breakpoints match the breakpoint list. */
627 breakpoint_re_set ();
628 insert_breakpoints ();
631 /* The child has exited or execed: resume threads of the parent the
632 user wanted to be executing. */
635 proceed_after_vfork_done (struct thread_info *thread,
638 int pid = * (int *) arg;
640 if (ptid_get_pid (thread->ptid) == pid
641 && is_running (thread->ptid)
642 && !is_executing (thread->ptid)
643 && !thread->stop_requested
644 && thread->suspend.stop_signal == GDB_SIGNAL_0)
647 fprintf_unfiltered (gdb_stdlog,
648 "infrun: resuming vfork parent thread %s\n",
649 target_pid_to_str (thread->ptid));
651 switch_to_thread (thread->ptid);
652 clear_proceed_status ();
653 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
659 /* Called whenever we notice an exec or exit event, to handle
660 detaching or resuming a vfork parent. */
663 handle_vfork_child_exec_or_exit (int exec)
665 struct inferior *inf = current_inferior ();
667 if (inf->vfork_parent)
669 int resume_parent = -1;
671 /* This exec or exit marks the end of the shared memory region
672 between the parent and the child. If the user wanted to
673 detach from the parent, now is the time. */
675 if (inf->vfork_parent->pending_detach)
677 struct thread_info *tp;
678 struct cleanup *old_chain;
679 struct program_space *pspace;
680 struct address_space *aspace;
682 /* follow-fork child, detach-on-fork on. */
684 inf->vfork_parent->pending_detach = 0;
688 /* If we're handling a child exit, then inferior_ptid
689 points at the inferior's pid, not to a thread. */
690 old_chain = save_inferior_ptid ();
691 save_current_program_space ();
692 save_current_inferior ();
695 old_chain = save_current_space_and_thread ();
697 /* We're letting loose of the parent. */
698 tp = any_live_thread_of_process (inf->vfork_parent->pid);
699 switch_to_thread (tp->ptid);
701 /* We're about to detach from the parent, which implicitly
702 removes breakpoints from its address space. There's a
703 catch here: we want to reuse the spaces for the child,
704 but, parent/child are still sharing the pspace at this
705 point, although the exec in reality makes the kernel give
706 the child a fresh set of new pages. The problem here is
707 that the breakpoints module being unaware of this, would
708 likely chose the child process to write to the parent
709 address space. Swapping the child temporarily away from
710 the spaces has the desired effect. Yes, this is "sort
713 pspace = inf->pspace;
714 aspace = inf->aspace;
718 if (debug_infrun || info_verbose)
720 target_terminal_ours ();
723 fprintf_filtered (gdb_stdlog,
724 "Detaching vfork parent process "
725 "%d after child exec.\n",
726 inf->vfork_parent->pid);
728 fprintf_filtered (gdb_stdlog,
729 "Detaching vfork parent process "
730 "%d after child exit.\n",
731 inf->vfork_parent->pid);
734 target_detach (NULL, 0);
737 inf->pspace = pspace;
738 inf->aspace = aspace;
740 do_cleanups (old_chain);
744 /* We're staying attached to the parent, so, really give the
745 child a new address space. */
746 inf->pspace = add_program_space (maybe_new_address_space ());
747 inf->aspace = inf->pspace->aspace;
749 set_current_program_space (inf->pspace);
751 resume_parent = inf->vfork_parent->pid;
753 /* Break the bonds. */
754 inf->vfork_parent->vfork_child = NULL;
758 struct cleanup *old_chain;
759 struct program_space *pspace;
761 /* If this is a vfork child exiting, then the pspace and
762 aspaces were shared with the parent. Since we're
763 reporting the process exit, we'll be mourning all that is
764 found in the address space, and switching to null_ptid,
765 preparing to start a new inferior. But, since we don't
766 want to clobber the parent's address/program spaces, we
767 go ahead and create a new one for this exiting
770 /* Switch to null_ptid, so that clone_program_space doesn't want
771 to read the selected frame of a dead process. */
772 old_chain = save_inferior_ptid ();
773 inferior_ptid = null_ptid;
775 /* This inferior is dead, so avoid giving the breakpoints
776 module the option to write through to it (cloning a
777 program space resets breakpoints). */
780 pspace = add_program_space (maybe_new_address_space ());
781 set_current_program_space (pspace);
783 inf->symfile_flags = SYMFILE_NO_READ;
784 clone_program_space (pspace, inf->vfork_parent->pspace);
785 inf->pspace = pspace;
786 inf->aspace = pspace->aspace;
788 /* Put back inferior_ptid. We'll continue mourning this
790 do_cleanups (old_chain);
792 resume_parent = inf->vfork_parent->pid;
793 /* Break the bonds. */
794 inf->vfork_parent->vfork_child = NULL;
797 inf->vfork_parent = NULL;
799 gdb_assert (current_program_space == inf->pspace);
801 if (non_stop && resume_parent != -1)
803 /* If the user wanted the parent to be running, let it go
805 struct cleanup *old_chain = make_cleanup_restore_current_thread ();
808 fprintf_unfiltered (gdb_stdlog,
809 "infrun: resuming vfork parent process %d\n",
812 iterate_over_threads (proceed_after_vfork_done, &resume_parent);
814 do_cleanups (old_chain);
819 /* Enum strings for "set|show follow-exec-mode". */
821 static const char follow_exec_mode_new[] = "new";
822 static const char follow_exec_mode_same[] = "same";
823 static const char *const follow_exec_mode_names[] =
825 follow_exec_mode_new,
826 follow_exec_mode_same,
830 static const char *follow_exec_mode_string = follow_exec_mode_same;
832 show_follow_exec_mode_string (struct ui_file *file, int from_tty,
833 struct cmd_list_element *c, const char *value)
835 fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value);
838 /* EXECD_PATHNAME is assumed to be non-NULL. */
841 follow_exec (ptid_t pid, char *execd_pathname)
843 struct thread_info *th = inferior_thread ();
844 struct inferior *inf = current_inferior ();
846 /* This is an exec event that we actually wish to pay attention to.
847 Refresh our symbol table to the newly exec'd program, remove any
850 If there are breakpoints, they aren't really inserted now,
851 since the exec() transformed our inferior into a fresh set
854 We want to preserve symbolic breakpoints on the list, since
855 we have hopes that they can be reset after the new a.out's
856 symbol table is read.
858 However, any "raw" breakpoints must be removed from the list
859 (e.g., the solib bp's), since their address is probably invalid
862 And, we DON'T want to call delete_breakpoints() here, since
863 that may write the bp's "shadow contents" (the instruction
864 value that was overwritten witha TRAP instruction). Since
865 we now have a new a.out, those shadow contents aren't valid. */
867 mark_breakpoints_out ();
869 update_breakpoints_after_exec ();
871 /* If there was one, it's gone now. We cannot truly step-to-next
872 statement through an exec(). */
873 th->control.step_resume_breakpoint = NULL;
874 th->control.exception_resume_breakpoint = NULL;
875 th->control.step_range_start = 0;
876 th->control.step_range_end = 0;
878 /* The target reports the exec event to the main thread, even if
879 some other thread does the exec, and even if the main thread was
880 already stopped --- if debugging in non-stop mode, it's possible
881 the user had the main thread held stopped in the previous image
882 --- release it now. This is the same behavior as step-over-exec
883 with scheduler-locking on in all-stop mode. */
884 th->stop_requested = 0;
886 /* What is this a.out's name? */
887 printf_unfiltered (_("%s is executing new program: %s\n"),
888 target_pid_to_str (inferior_ptid),
891 /* We've followed the inferior through an exec. Therefore, the
892 inferior has essentially been killed & reborn. */
894 gdb_flush (gdb_stdout);
896 breakpoint_init_inferior (inf_execd);
898 if (gdb_sysroot && *gdb_sysroot)
900 char *name = alloca (strlen (gdb_sysroot)
901 + strlen (execd_pathname)
904 strcpy (name, gdb_sysroot);
905 strcat (name, execd_pathname);
906 execd_pathname = name;
909 /* Reset the shared library package. This ensures that we get a
910 shlib event when the child reaches "_start", at which point the
911 dld will have had a chance to initialize the child. */
912 /* Also, loading a symbol file below may trigger symbol lookups, and
913 we don't want those to be satisfied by the libraries of the
914 previous incarnation of this process. */
915 no_shared_libraries (NULL, 0);
917 if (follow_exec_mode_string == follow_exec_mode_new)
919 struct program_space *pspace;
921 /* The user wants to keep the old inferior and program spaces
922 around. Create a new fresh one, and switch to it. */
924 inf = add_inferior (current_inferior ()->pid);
925 pspace = add_program_space (maybe_new_address_space ());
926 inf->pspace = pspace;
927 inf->aspace = pspace->aspace;
929 exit_inferior_num_silent (current_inferior ()->num);
931 set_current_inferior (inf);
932 set_current_program_space (pspace);
936 /* The old description may no longer be fit for the new image.
937 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
938 old description; we'll read a new one below. No need to do
939 this on "follow-exec-mode new", as the old inferior stays
940 around (its description is later cleared/refetched on
942 target_clear_description ();
945 gdb_assert (current_program_space == inf->pspace);
947 /* That a.out is now the one to use. */
948 exec_file_attach (execd_pathname, 0);
950 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
951 (Position Independent Executable) main symbol file will get applied by
952 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
953 the breakpoints with the zero displacement. */
955 symbol_file_add (execd_pathname,
957 | SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET),
960 if ((inf->symfile_flags & SYMFILE_NO_READ) == 0)
961 set_initial_language ();
963 /* If the target can specify a description, read it. Must do this
964 after flipping to the new executable (because the target supplied
965 description must be compatible with the executable's
966 architecture, and the old executable may e.g., be 32-bit, while
967 the new one 64-bit), and before anything involving memory or
969 target_find_description ();
971 solib_create_inferior_hook (0);
973 jit_inferior_created_hook ();
975 breakpoint_re_set ();
977 /* Reinsert all breakpoints. (Those which were symbolic have
978 been reset to the proper address in the new a.out, thanks
979 to symbol_file_command...). */
980 insert_breakpoints ();
982 /* The next resume of this inferior should bring it to the shlib
983 startup breakpoints. (If the user had also set bp's on
984 "main" from the old (parent) process, then they'll auto-
985 matically get reset there in the new process.). */
988 /* Non-zero if we just simulating a single-step. This is needed
989 because we cannot remove the breakpoints in the inferior process
990 until after the `wait' in `wait_for_inferior'. */
991 static int singlestep_breakpoints_inserted_p = 0;
993 /* The thread we inserted single-step breakpoints for. */
994 static ptid_t singlestep_ptid;
996 /* PC when we started this single-step. */
997 static CORE_ADDR singlestep_pc;
999 /* If another thread hit the singlestep breakpoint, we save the original
1000 thread here so that we can resume single-stepping it later. */
1001 static ptid_t saved_singlestep_ptid;
1002 static int stepping_past_singlestep_breakpoint;
1004 /* If not equal to null_ptid, this means that after stepping over breakpoint
1005 is finished, we need to switch to deferred_step_ptid, and step it.
1007 The use case is when one thread has hit a breakpoint, and then the user
1008 has switched to another thread and issued 'step'. We need to step over
1009 breakpoint in the thread which hit the breakpoint, but then continue
1010 stepping the thread user has selected. */
1011 static ptid_t deferred_step_ptid;
1013 /* Displaced stepping. */
1015 /* In non-stop debugging mode, we must take special care to manage
1016 breakpoints properly; in particular, the traditional strategy for
1017 stepping a thread past a breakpoint it has hit is unsuitable.
1018 'Displaced stepping' is a tactic for stepping one thread past a
1019 breakpoint it has hit while ensuring that other threads running
1020 concurrently will hit the breakpoint as they should.
1022 The traditional way to step a thread T off a breakpoint in a
1023 multi-threaded program in all-stop mode is as follows:
1025 a0) Initially, all threads are stopped, and breakpoints are not
1027 a1) We single-step T, leaving breakpoints uninserted.
1028 a2) We insert breakpoints, and resume all threads.
1030 In non-stop debugging, however, this strategy is unsuitable: we
1031 don't want to have to stop all threads in the system in order to
1032 continue or step T past a breakpoint. Instead, we use displaced
1035 n0) Initially, T is stopped, other threads are running, and
1036 breakpoints are inserted.
1037 n1) We copy the instruction "under" the breakpoint to a separate
1038 location, outside the main code stream, making any adjustments
1039 to the instruction, register, and memory state as directed by
1041 n2) We single-step T over the instruction at its new location.
1042 n3) We adjust the resulting register and memory state as directed
1043 by T's architecture. This includes resetting T's PC to point
1044 back into the main instruction stream.
1047 This approach depends on the following gdbarch methods:
1049 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1050 indicate where to copy the instruction, and how much space must
1051 be reserved there. We use these in step n1.
1053 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1054 address, and makes any necessary adjustments to the instruction,
1055 register contents, and memory. We use this in step n1.
1057 - gdbarch_displaced_step_fixup adjusts registers and memory after
1058 we have successfuly single-stepped the instruction, to yield the
1059 same effect the instruction would have had if we had executed it
1060 at its original address. We use this in step n3.
1062 - gdbarch_displaced_step_free_closure provides cleanup.
1064 The gdbarch_displaced_step_copy_insn and
1065 gdbarch_displaced_step_fixup functions must be written so that
1066 copying an instruction with gdbarch_displaced_step_copy_insn,
1067 single-stepping across the copied instruction, and then applying
1068 gdbarch_displaced_insn_fixup should have the same effects on the
1069 thread's memory and registers as stepping the instruction in place
1070 would have. Exactly which responsibilities fall to the copy and
1071 which fall to the fixup is up to the author of those functions.
1073 See the comments in gdbarch.sh for details.
1075 Note that displaced stepping and software single-step cannot
1076 currently be used in combination, although with some care I think
1077 they could be made to. Software single-step works by placing
1078 breakpoints on all possible subsequent instructions; if the
1079 displaced instruction is a PC-relative jump, those breakpoints
1080 could fall in very strange places --- on pages that aren't
1081 executable, or at addresses that are not proper instruction
1082 boundaries. (We do generally let other threads run while we wait
1083 to hit the software single-step breakpoint, and they might
1084 encounter such a corrupted instruction.) One way to work around
1085 this would be to have gdbarch_displaced_step_copy_insn fully
1086 simulate the effect of PC-relative instructions (and return NULL)
1087 on architectures that use software single-stepping.
1089 In non-stop mode, we can have independent and simultaneous step
1090 requests, so more than one thread may need to simultaneously step
1091 over a breakpoint. The current implementation assumes there is
1092 only one scratch space per process. In this case, we have to
1093 serialize access to the scratch space. If thread A wants to step
1094 over a breakpoint, but we are currently waiting for some other
1095 thread to complete a displaced step, we leave thread A stopped and
1096 place it in the displaced_step_request_queue. Whenever a displaced
1097 step finishes, we pick the next thread in the queue and start a new
1098 displaced step operation on it. See displaced_step_prepare and
1099 displaced_step_fixup for details. */
1101 struct displaced_step_request
1104 struct displaced_step_request *next;
1107 /* Per-inferior displaced stepping state. */
1108 struct displaced_step_inferior_state
1110 /* Pointer to next in linked list. */
1111 struct displaced_step_inferior_state *next;
1113 /* The process this displaced step state refers to. */
1116 /* A queue of pending displaced stepping requests. One entry per
1117 thread that needs to do a displaced step. */
1118 struct displaced_step_request *step_request_queue;
1120 /* If this is not null_ptid, this is the thread carrying out a
1121 displaced single-step in process PID. This thread's state will
1122 require fixing up once it has completed its step. */
1125 /* The architecture the thread had when we stepped it. */
1126 struct gdbarch *step_gdbarch;
1128 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1129 for post-step cleanup. */
1130 struct displaced_step_closure *step_closure;
1132 /* The address of the original instruction, and the copy we
1134 CORE_ADDR step_original, step_copy;
1136 /* Saved contents of copy area. */
1137 gdb_byte *step_saved_copy;
1140 /* The list of states of processes involved in displaced stepping
1142 static struct displaced_step_inferior_state *displaced_step_inferior_states;
1144 /* Get the displaced stepping state of process PID. */
1146 static struct displaced_step_inferior_state *
1147 get_displaced_stepping_state (int pid)
1149 struct displaced_step_inferior_state *state;
1151 for (state = displaced_step_inferior_states;
1153 state = state->next)
1154 if (state->pid == pid)
1160 /* Add a new displaced stepping state for process PID to the displaced
1161 stepping state list, or return a pointer to an already existing
1162 entry, if it already exists. Never returns NULL. */
1164 static struct displaced_step_inferior_state *
1165 add_displaced_stepping_state (int pid)
1167 struct displaced_step_inferior_state *state;
1169 for (state = displaced_step_inferior_states;
1171 state = state->next)
1172 if (state->pid == pid)
1175 state = xcalloc (1, sizeof (*state));
1177 state->next = displaced_step_inferior_states;
1178 displaced_step_inferior_states = state;
1183 /* If inferior is in displaced stepping, and ADDR equals to starting address
1184 of copy area, return corresponding displaced_step_closure. Otherwise,
1187 struct displaced_step_closure*
1188 get_displaced_step_closure_by_addr (CORE_ADDR addr)
1190 struct displaced_step_inferior_state *displaced
1191 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1193 /* If checking the mode of displaced instruction in copy area. */
1194 if (displaced && !ptid_equal (displaced->step_ptid, null_ptid)
1195 && (displaced->step_copy == addr))
1196 return displaced->step_closure;
1201 /* Remove the displaced stepping state of process PID. */
1204 remove_displaced_stepping_state (int pid)
1206 struct displaced_step_inferior_state *it, **prev_next_p;
1208 gdb_assert (pid != 0);
1210 it = displaced_step_inferior_states;
1211 prev_next_p = &displaced_step_inferior_states;
1216 *prev_next_p = it->next;
1221 prev_next_p = &it->next;
1227 infrun_inferior_exit (struct inferior *inf)
1229 remove_displaced_stepping_state (inf->pid);
1232 /* If ON, and the architecture supports it, GDB will use displaced
1233 stepping to step over breakpoints. If OFF, or if the architecture
1234 doesn't support it, GDB will instead use the traditional
1235 hold-and-step approach. If AUTO (which is the default), GDB will
1236 decide which technique to use to step over breakpoints depending on
1237 which of all-stop or non-stop mode is active --- displaced stepping
1238 in non-stop mode; hold-and-step in all-stop mode. */
1240 static enum auto_boolean can_use_displaced_stepping = AUTO_BOOLEAN_AUTO;
1243 show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
1244 struct cmd_list_element *c,
1247 if (can_use_displaced_stepping == AUTO_BOOLEAN_AUTO)
1248 fprintf_filtered (file,
1249 _("Debugger's willingness to use displaced stepping "
1250 "to step over breakpoints is %s (currently %s).\n"),
1251 value, non_stop ? "on" : "off");
1253 fprintf_filtered (file,
1254 _("Debugger's willingness to use displaced stepping "
1255 "to step over breakpoints is %s.\n"), value);
1258 /* Return non-zero if displaced stepping can/should be used to step
1259 over breakpoints. */
1262 use_displaced_stepping (struct gdbarch *gdbarch)
1264 return (((can_use_displaced_stepping == AUTO_BOOLEAN_AUTO && non_stop)
1265 || can_use_displaced_stepping == AUTO_BOOLEAN_TRUE)
1266 && gdbarch_displaced_step_copy_insn_p (gdbarch)
1267 && !RECORD_IS_USED);
1270 /* Clean out any stray displaced stepping state. */
1272 displaced_step_clear (struct displaced_step_inferior_state *displaced)
1274 /* Indicate that there is no cleanup pending. */
1275 displaced->step_ptid = null_ptid;
1277 if (displaced->step_closure)
1279 gdbarch_displaced_step_free_closure (displaced->step_gdbarch,
1280 displaced->step_closure);
1281 displaced->step_closure = NULL;
1286 displaced_step_clear_cleanup (void *arg)
1288 struct displaced_step_inferior_state *state = arg;
1290 displaced_step_clear (state);
1293 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1295 displaced_step_dump_bytes (struct ui_file *file,
1296 const gdb_byte *buf,
1301 for (i = 0; i < len; i++)
1302 fprintf_unfiltered (file, "%02x ", buf[i]);
1303 fputs_unfiltered ("\n", file);
1306 /* Prepare to single-step, using displaced stepping.
1308 Note that we cannot use displaced stepping when we have a signal to
1309 deliver. If we have a signal to deliver and an instruction to step
1310 over, then after the step, there will be no indication from the
1311 target whether the thread entered a signal handler or ignored the
1312 signal and stepped over the instruction successfully --- both cases
1313 result in a simple SIGTRAP. In the first case we mustn't do a
1314 fixup, and in the second case we must --- but we can't tell which.
1315 Comments in the code for 'random signals' in handle_inferior_event
1316 explain how we handle this case instead.
1318 Returns 1 if preparing was successful -- this thread is going to be
1319 stepped now; or 0 if displaced stepping this thread got queued. */
1321 displaced_step_prepare (ptid_t ptid)
1323 struct cleanup *old_cleanups, *ignore_cleanups;
1324 struct thread_info *tp = find_thread_ptid (ptid);
1325 struct regcache *regcache = get_thread_regcache (ptid);
1326 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1327 CORE_ADDR original, copy;
1329 struct displaced_step_closure *closure;
1330 struct displaced_step_inferior_state *displaced;
1333 /* We should never reach this function if the architecture does not
1334 support displaced stepping. */
1335 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
1337 /* Disable range stepping while executing in the scratch pad. We
1338 want a single-step even if executing the displaced instruction in
1339 the scratch buffer lands within the stepping range (e.g., a
1341 tp->control.may_range_step = 0;
1343 /* We have to displaced step one thread at a time, as we only have
1344 access to a single scratch space per inferior. */
1346 displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
1348 if (!ptid_equal (displaced->step_ptid, null_ptid))
1350 /* Already waiting for a displaced step to finish. Defer this
1351 request and place in queue. */
1352 struct displaced_step_request *req, *new_req;
1354 if (debug_displaced)
1355 fprintf_unfiltered (gdb_stdlog,
1356 "displaced: defering step of %s\n",
1357 target_pid_to_str (ptid));
1359 new_req = xmalloc (sizeof (*new_req));
1360 new_req->ptid = ptid;
1361 new_req->next = NULL;
1363 if (displaced->step_request_queue)
1365 for (req = displaced->step_request_queue;
1369 req->next = new_req;
1372 displaced->step_request_queue = new_req;
1378 if (debug_displaced)
1379 fprintf_unfiltered (gdb_stdlog,
1380 "displaced: stepping %s now\n",
1381 target_pid_to_str (ptid));
1384 displaced_step_clear (displaced);
1386 old_cleanups = save_inferior_ptid ();
1387 inferior_ptid = ptid;
1389 original = regcache_read_pc (regcache);
1391 copy = gdbarch_displaced_step_location (gdbarch);
1392 len = gdbarch_max_insn_length (gdbarch);
1394 /* Save the original contents of the copy area. */
1395 displaced->step_saved_copy = xmalloc (len);
1396 ignore_cleanups = make_cleanup (free_current_contents,
1397 &displaced->step_saved_copy);
1398 status = target_read_memory (copy, displaced->step_saved_copy, len);
1400 throw_error (MEMORY_ERROR,
1401 _("Error accessing memory address %s (%s) for "
1402 "displaced-stepping scratch space."),
1403 paddress (gdbarch, copy), safe_strerror (status));
1404 if (debug_displaced)
1406 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
1407 paddress (gdbarch, copy));
1408 displaced_step_dump_bytes (gdb_stdlog,
1409 displaced->step_saved_copy,
1413 closure = gdbarch_displaced_step_copy_insn (gdbarch,
1414 original, copy, regcache);
1416 /* We don't support the fully-simulated case at present. */
1417 gdb_assert (closure);
1419 /* Save the information we need to fix things up if the step
1421 displaced->step_ptid = ptid;
1422 displaced->step_gdbarch = gdbarch;
1423 displaced->step_closure = closure;
1424 displaced->step_original = original;
1425 displaced->step_copy = copy;
1427 make_cleanup (displaced_step_clear_cleanup, displaced);
1429 /* Resume execution at the copy. */
1430 regcache_write_pc (regcache, copy);
1432 discard_cleanups (ignore_cleanups);
1434 do_cleanups (old_cleanups);
1436 if (debug_displaced)
1437 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
1438 paddress (gdbarch, copy));
1444 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr,
1445 const gdb_byte *myaddr, int len)
1447 struct cleanup *ptid_cleanup = save_inferior_ptid ();
1449 inferior_ptid = ptid;
1450 write_memory (memaddr, myaddr, len);
1451 do_cleanups (ptid_cleanup);
1454 /* Restore the contents of the copy area for thread PTID. */
1457 displaced_step_restore (struct displaced_step_inferior_state *displaced,
1460 ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
1462 write_memory_ptid (ptid, displaced->step_copy,
1463 displaced->step_saved_copy, len);
1464 if (debug_displaced)
1465 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s %s\n",
1466 target_pid_to_str (ptid),
1467 paddress (displaced->step_gdbarch,
1468 displaced->step_copy));
1472 displaced_step_fixup (ptid_t event_ptid, enum gdb_signal signal)
1474 struct cleanup *old_cleanups;
1475 struct displaced_step_inferior_state *displaced
1476 = get_displaced_stepping_state (ptid_get_pid (event_ptid));
1478 /* Was any thread of this process doing a displaced step? */
1479 if (displaced == NULL)
1482 /* Was this event for the pid we displaced? */
1483 if (ptid_equal (displaced->step_ptid, null_ptid)
1484 || ! ptid_equal (displaced->step_ptid, event_ptid))
1487 old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
1489 displaced_step_restore (displaced, displaced->step_ptid);
1491 /* Did the instruction complete successfully? */
1492 if (signal == GDB_SIGNAL_TRAP)
1494 /* Fix up the resulting state. */
1495 gdbarch_displaced_step_fixup (displaced->step_gdbarch,
1496 displaced->step_closure,
1497 displaced->step_original,
1498 displaced->step_copy,
1499 get_thread_regcache (displaced->step_ptid));
1503 /* Since the instruction didn't complete, all we can do is
1505 struct regcache *regcache = get_thread_regcache (event_ptid);
1506 CORE_ADDR pc = regcache_read_pc (regcache);
1508 pc = displaced->step_original + (pc - displaced->step_copy);
1509 regcache_write_pc (regcache, pc);
1512 do_cleanups (old_cleanups);
1514 displaced->step_ptid = null_ptid;
1516 /* Are there any pending displaced stepping requests? If so, run
1517 one now. Leave the state object around, since we're likely to
1518 need it again soon. */
1519 while (displaced->step_request_queue)
1521 struct displaced_step_request *head;
1523 struct regcache *regcache;
1524 struct gdbarch *gdbarch;
1525 CORE_ADDR actual_pc;
1526 struct address_space *aspace;
1528 head = displaced->step_request_queue;
1530 displaced->step_request_queue = head->next;
1533 context_switch (ptid);
1535 regcache = get_thread_regcache (ptid);
1536 actual_pc = regcache_read_pc (regcache);
1537 aspace = get_regcache_aspace (regcache);
1539 if (breakpoint_here_p (aspace, actual_pc))
1541 if (debug_displaced)
1542 fprintf_unfiltered (gdb_stdlog,
1543 "displaced: stepping queued %s now\n",
1544 target_pid_to_str (ptid));
1546 displaced_step_prepare (ptid);
1548 gdbarch = get_regcache_arch (regcache);
1550 if (debug_displaced)
1552 CORE_ADDR actual_pc = regcache_read_pc (regcache);
1555 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1556 paddress (gdbarch, actual_pc));
1557 read_memory (actual_pc, buf, sizeof (buf));
1558 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1561 if (gdbarch_displaced_step_hw_singlestep (gdbarch,
1562 displaced->step_closure))
1563 target_resume (ptid, 1, GDB_SIGNAL_0);
1565 target_resume (ptid, 0, GDB_SIGNAL_0);
1567 /* Done, we're stepping a thread. */
1573 struct thread_info *tp = inferior_thread ();
1575 /* The breakpoint we were sitting under has since been
1577 tp->control.trap_expected = 0;
1579 /* Go back to what we were trying to do. */
1580 step = currently_stepping (tp);
1582 if (debug_displaced)
1583 fprintf_unfiltered (gdb_stdlog,
1584 "displaced: breakpoint is gone: %s, step(%d)\n",
1585 target_pid_to_str (tp->ptid), step);
1587 target_resume (ptid, step, GDB_SIGNAL_0);
1588 tp->suspend.stop_signal = GDB_SIGNAL_0;
1590 /* This request was discarded. See if there's any other
1591 thread waiting for its turn. */
1596 /* Update global variables holding ptids to hold NEW_PTID if they were
1597 holding OLD_PTID. */
1599 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
1601 struct displaced_step_request *it;
1602 struct displaced_step_inferior_state *displaced;
1604 if (ptid_equal (inferior_ptid, old_ptid))
1605 inferior_ptid = new_ptid;
1607 if (ptid_equal (singlestep_ptid, old_ptid))
1608 singlestep_ptid = new_ptid;
1610 if (ptid_equal (deferred_step_ptid, old_ptid))
1611 deferred_step_ptid = new_ptid;
1613 for (displaced = displaced_step_inferior_states;
1615 displaced = displaced->next)
1617 if (ptid_equal (displaced->step_ptid, old_ptid))
1618 displaced->step_ptid = new_ptid;
1620 for (it = displaced->step_request_queue; it; it = it->next)
1621 if (ptid_equal (it->ptid, old_ptid))
1622 it->ptid = new_ptid;
1629 /* Things to clean up if we QUIT out of resume (). */
1631 resume_cleanups (void *ignore)
1636 static const char schedlock_off[] = "off";
1637 static const char schedlock_on[] = "on";
1638 static const char schedlock_step[] = "step";
1639 static const char *const scheduler_enums[] = {
1645 static const char *scheduler_mode = schedlock_off;
1647 show_scheduler_mode (struct ui_file *file, int from_tty,
1648 struct cmd_list_element *c, const char *value)
1650 fprintf_filtered (file,
1651 _("Mode for locking scheduler "
1652 "during execution is \"%s\".\n"),
1657 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
1659 if (!target_can_lock_scheduler)
1661 scheduler_mode = schedlock_off;
1662 error (_("Target '%s' cannot support this command."), target_shortname);
1666 /* True if execution commands resume all threads of all processes by
1667 default; otherwise, resume only threads of the current inferior
1669 int sched_multi = 0;
1671 /* Try to setup for software single stepping over the specified location.
1672 Return 1 if target_resume() should use hardware single step.
1674 GDBARCH the current gdbarch.
1675 PC the location to step over. */
1678 maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
1682 if (execution_direction == EXEC_FORWARD
1683 && gdbarch_software_single_step_p (gdbarch)
1684 && gdbarch_software_single_step (gdbarch, get_current_frame ()))
1687 /* Do not pull these breakpoints until after a `wait' in
1688 `wait_for_inferior'. */
1689 singlestep_breakpoints_inserted_p = 1;
1690 singlestep_ptid = inferior_ptid;
1696 /* Return a ptid representing the set of threads that we will proceed,
1697 in the perspective of the user/frontend. We may actually resume
1698 fewer threads at first, e.g., if a thread is stopped at a
1699 breakpoint that needs stepping-off, but that should not be visible
1700 to the user/frontend, and neither should the frontend/user be
1701 allowed to proceed any of the threads that happen to be stopped for
1702 internal run control handling, if a previous command wanted them
1706 user_visible_resume_ptid (int step)
1708 /* By default, resume all threads of all processes. */
1709 ptid_t resume_ptid = RESUME_ALL;
1711 /* Maybe resume only all threads of the current process. */
1712 if (!sched_multi && target_supports_multi_process ())
1714 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
1717 /* Maybe resume a single thread after all. */
1720 /* With non-stop mode on, threads are always handled
1722 resume_ptid = inferior_ptid;
1724 else if ((scheduler_mode == schedlock_on)
1725 || (scheduler_mode == schedlock_step
1726 && (step || singlestep_breakpoints_inserted_p)))
1728 /* User-settable 'scheduler' mode requires solo thread resume. */
1729 resume_ptid = inferior_ptid;
1735 /* Resume the inferior, but allow a QUIT. This is useful if the user
1736 wants to interrupt some lengthy single-stepping operation
1737 (for child processes, the SIGINT goes to the inferior, and so
1738 we get a SIGINT random_signal, but for remote debugging and perhaps
1739 other targets, that's not true).
1741 STEP nonzero if we should step (zero to continue instead).
1742 SIG is the signal to give the inferior (zero for none). */
1744 resume (int step, enum gdb_signal sig)
1746 int should_resume = 1;
1747 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
1748 struct regcache *regcache = get_current_regcache ();
1749 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1750 struct thread_info *tp = inferior_thread ();
1751 CORE_ADDR pc = regcache_read_pc (regcache);
1752 struct address_space *aspace = get_regcache_aspace (regcache);
1756 if (current_inferior ()->waiting_for_vfork_done)
1758 /* Don't try to single-step a vfork parent that is waiting for
1759 the child to get out of the shared memory region (by exec'ing
1760 or exiting). This is particularly important on software
1761 single-step archs, as the child process would trip on the
1762 software single step breakpoint inserted for the parent
1763 process. Since the parent will not actually execute any
1764 instruction until the child is out of the shared region (such
1765 are vfork's semantics), it is safe to simply continue it.
1766 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1767 the parent, and tell it to `keep_going', which automatically
1768 re-sets it stepping. */
1770 fprintf_unfiltered (gdb_stdlog,
1771 "infrun: resume : clear step\n");
1776 fprintf_unfiltered (gdb_stdlog,
1777 "infrun: resume (step=%d, signal=%d), "
1778 "trap_expected=%d, current thread [%s] at %s\n",
1779 step, sig, tp->control.trap_expected,
1780 target_pid_to_str (inferior_ptid),
1781 paddress (gdbarch, pc));
1783 /* Normally, by the time we reach `resume', the breakpoints are either
1784 removed or inserted, as appropriate. The exception is if we're sitting
1785 at a permanent breakpoint; we need to step over it, but permanent
1786 breakpoints can't be removed. So we have to test for it here. */
1787 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
1789 if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
1790 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
1793 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1794 how to step past a permanent breakpoint on this architecture. Try using\n\
1795 a command like `return' or `jump' to continue execution."));
1798 /* If we have a breakpoint to step over, make sure to do a single
1799 step only. Same if we have software watchpoints. */
1800 if (tp->control.trap_expected || bpstat_should_step ())
1801 tp->control.may_range_step = 0;
1803 /* If enabled, step over breakpoints by executing a copy of the
1804 instruction at a different address.
1806 We can't use displaced stepping when we have a signal to deliver;
1807 the comments for displaced_step_prepare explain why. The
1808 comments in the handle_inferior event for dealing with 'random
1809 signals' explain what we do instead.
1811 We can't use displaced stepping when we are waiting for vfork_done
1812 event, displaced stepping breaks the vfork child similarly as single
1813 step software breakpoint. */
1814 if (use_displaced_stepping (gdbarch)
1815 && (tp->control.trap_expected
1816 || (step && gdbarch_software_single_step_p (gdbarch)))
1817 && sig == GDB_SIGNAL_0
1818 && !current_inferior ()->waiting_for_vfork_done)
1820 struct displaced_step_inferior_state *displaced;
1822 if (!displaced_step_prepare (inferior_ptid))
1824 /* Got placed in displaced stepping queue. Will be resumed
1825 later when all the currently queued displaced stepping
1826 requests finish. The thread is not executing at this point,
1827 and the call to set_executing will be made later. But we
1828 need to call set_running here, since from frontend point of view,
1829 the thread is running. */
1830 set_running (inferior_ptid, 1);
1831 discard_cleanups (old_cleanups);
1835 /* Update pc to reflect the new address from which we will execute
1836 instructions due to displaced stepping. */
1837 pc = regcache_read_pc (get_thread_regcache (inferior_ptid));
1839 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1840 step = gdbarch_displaced_step_hw_singlestep (gdbarch,
1841 displaced->step_closure);
1844 /* Do we need to do it the hard way, w/temp breakpoints? */
1846 step = maybe_software_singlestep (gdbarch, pc);
1848 /* Currently, our software single-step implementation leads to different
1849 results than hardware single-stepping in one situation: when stepping
1850 into delivering a signal which has an associated signal handler,
1851 hardware single-step will stop at the first instruction of the handler,
1852 while software single-step will simply skip execution of the handler.
1854 For now, this difference in behavior is accepted since there is no
1855 easy way to actually implement single-stepping into a signal handler
1856 without kernel support.
1858 However, there is one scenario where this difference leads to follow-on
1859 problems: if we're stepping off a breakpoint by removing all breakpoints
1860 and then single-stepping. In this case, the software single-step
1861 behavior means that even if there is a *breakpoint* in the signal
1862 handler, GDB still would not stop.
1864 Fortunately, we can at least fix this particular issue. We detect
1865 here the case where we are about to deliver a signal while software
1866 single-stepping with breakpoints removed. In this situation, we
1867 revert the decisions to remove all breakpoints and insert single-
1868 step breakpoints, and instead we install a step-resume breakpoint
1869 at the current address, deliver the signal without stepping, and
1870 once we arrive back at the step-resume breakpoint, actually step
1871 over the breakpoint we originally wanted to step over. */
1872 if (singlestep_breakpoints_inserted_p
1873 && tp->control.trap_expected && sig != GDB_SIGNAL_0)
1875 /* If we have nested signals or a pending signal is delivered
1876 immediately after a handler returns, might might already have
1877 a step-resume breakpoint set on the earlier handler. We cannot
1878 set another step-resume breakpoint; just continue on until the
1879 original breakpoint is hit. */
1880 if (tp->control.step_resume_breakpoint == NULL)
1882 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1883 tp->step_after_step_resume_breakpoint = 1;
1886 remove_single_step_breakpoints ();
1887 singlestep_breakpoints_inserted_p = 0;
1889 insert_breakpoints ();
1890 tp->control.trap_expected = 0;
1897 /* If STEP is set, it's a request to use hardware stepping
1898 facilities. But in that case, we should never
1899 use singlestep breakpoint. */
1900 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
1902 /* Decide the set of threads to ask the target to resume. Start
1903 by assuming everything will be resumed, than narrow the set
1904 by applying increasingly restricting conditions. */
1905 resume_ptid = user_visible_resume_ptid (step);
1907 /* Maybe resume a single thread after all. */
1908 if (singlestep_breakpoints_inserted_p
1909 && stepping_past_singlestep_breakpoint)
1911 /* The situation here is as follows. In thread T1 we wanted to
1912 single-step. Lacking hardware single-stepping we've
1913 set breakpoint at the PC of the next instruction -- call it
1914 P. After resuming, we've hit that breakpoint in thread T2.
1915 Now we've removed original breakpoint, inserted breakpoint
1916 at P+1, and try to step to advance T2 past breakpoint.
1917 We need to step only T2, as if T1 is allowed to freely run,
1918 it can run past P, and if other threads are allowed to run,
1919 they can hit breakpoint at P+1, and nested hits of single-step
1920 breakpoints is not something we'd want -- that's complicated
1921 to support, and has no value. */
1922 resume_ptid = inferior_ptid;
1924 else if ((step || singlestep_breakpoints_inserted_p)
1925 && tp->control.trap_expected)
1927 /* We're allowing a thread to run past a breakpoint it has
1928 hit, by single-stepping the thread with the breakpoint
1929 removed. In which case, we need to single-step only this
1930 thread, and keep others stopped, as they can miss this
1931 breakpoint if allowed to run.
1933 The current code actually removes all breakpoints when
1934 doing this, not just the one being stepped over, so if we
1935 let other threads run, we can actually miss any
1936 breakpoint, not just the one at PC. */
1937 resume_ptid = inferior_ptid;
1940 if (gdbarch_cannot_step_breakpoint (gdbarch))
1942 /* Most targets can step a breakpoint instruction, thus
1943 executing it normally. But if this one cannot, just
1944 continue and we will hit it anyway. */
1945 if (step && breakpoint_inserted_here_p (aspace, pc))
1950 && use_displaced_stepping (gdbarch)
1951 && tp->control.trap_expected)
1953 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
1954 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
1955 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
1958 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1959 paddress (resume_gdbarch, actual_pc));
1960 read_memory (actual_pc, buf, sizeof (buf));
1961 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1964 if (tp->control.may_range_step)
1966 /* If we're resuming a thread with the PC out of the step
1967 range, then we're doing some nested/finer run control
1968 operation, like stepping the thread out of the dynamic
1969 linker or the displaced stepping scratch pad. We
1970 shouldn't have allowed a range step then. */
1971 gdb_assert (pc_in_thread_step_range (pc, tp));
1974 /* Install inferior's terminal modes. */
1975 target_terminal_inferior ();
1977 /* Avoid confusing the next resume, if the next stop/resume
1978 happens to apply to another thread. */
1979 tp->suspend.stop_signal = GDB_SIGNAL_0;
1981 /* Advise target which signals may be handled silently. If we have
1982 removed breakpoints because we are stepping over one (which can
1983 happen only if we are not using displaced stepping), we need to
1984 receive all signals to avoid accidentally skipping a breakpoint
1985 during execution of a signal handler. */
1986 if ((step || singlestep_breakpoints_inserted_p)
1987 && tp->control.trap_expected
1988 && !use_displaced_stepping (gdbarch))
1989 target_pass_signals (0, NULL);
1991 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
1993 target_resume (resume_ptid, step, sig);
1996 discard_cleanups (old_cleanups);
2001 /* Clear out all variables saying what to do when inferior is continued.
2002 First do this, then set the ones you want, then call `proceed'. */
2005 clear_proceed_status_thread (struct thread_info *tp)
2008 fprintf_unfiltered (gdb_stdlog,
2009 "infrun: clear_proceed_status_thread (%s)\n",
2010 target_pid_to_str (tp->ptid));
2012 tp->control.trap_expected = 0;
2013 tp->control.step_range_start = 0;
2014 tp->control.step_range_end = 0;
2015 tp->control.may_range_step = 0;
2016 tp->control.step_frame_id = null_frame_id;
2017 tp->control.step_stack_frame_id = null_frame_id;
2018 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
2019 tp->stop_requested = 0;
2021 tp->control.stop_step = 0;
2023 tp->control.proceed_to_finish = 0;
2025 /* Discard any remaining commands or status from previous stop. */
2026 bpstat_clear (&tp->control.stop_bpstat);
2030 clear_proceed_status_callback (struct thread_info *tp, void *data)
2032 if (is_exited (tp->ptid))
2035 clear_proceed_status_thread (tp);
2040 clear_proceed_status (void)
2044 /* In all-stop mode, delete the per-thread status of all
2045 threads, even if inferior_ptid is null_ptid, there may be
2046 threads on the list. E.g., we may be launching a new
2047 process, while selecting the executable. */
2048 iterate_over_threads (clear_proceed_status_callback, NULL);
2051 if (!ptid_equal (inferior_ptid, null_ptid))
2053 struct inferior *inferior;
2057 /* If in non-stop mode, only delete the per-thread status of
2058 the current thread. */
2059 clear_proceed_status_thread (inferior_thread ());
2062 inferior = current_inferior ();
2063 inferior->control.stop_soon = NO_STOP_QUIETLY;
2066 stop_after_trap = 0;
2068 observer_notify_about_to_proceed ();
2072 regcache_xfree (stop_registers);
2073 stop_registers = NULL;
2077 /* Check the current thread against the thread that reported the most recent
2078 event. If a step-over is required return TRUE and set the current thread
2079 to the old thread. Otherwise return FALSE.
2081 This should be suitable for any targets that support threads. */
2084 prepare_to_proceed (int step)
2087 struct target_waitstatus wait_status;
2088 int schedlock_enabled;
2090 /* With non-stop mode on, threads are always handled individually. */
2091 gdb_assert (! non_stop);
2093 /* Get the last target status returned by target_wait(). */
2094 get_last_target_status (&wait_ptid, &wait_status);
2096 /* Make sure we were stopped at a breakpoint. */
2097 if (wait_status.kind != TARGET_WAITKIND_STOPPED
2098 || (wait_status.value.sig != GDB_SIGNAL_TRAP
2099 && wait_status.value.sig != GDB_SIGNAL_ILL
2100 && wait_status.value.sig != GDB_SIGNAL_SEGV
2101 && wait_status.value.sig != GDB_SIGNAL_EMT))
2106 schedlock_enabled = (scheduler_mode == schedlock_on
2107 || (scheduler_mode == schedlock_step
2110 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
2111 if (schedlock_enabled)
2114 /* Don't switch over if we're about to resume some other process
2115 other than WAIT_PTID's, and schedule-multiple is off. */
2117 && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid))
2120 /* Switched over from WAIT_PID. */
2121 if (!ptid_equal (wait_ptid, minus_one_ptid)
2122 && !ptid_equal (inferior_ptid, wait_ptid))
2124 struct regcache *regcache = get_thread_regcache (wait_ptid);
2126 if (breakpoint_here_p (get_regcache_aspace (regcache),
2127 regcache_read_pc (regcache)))
2129 /* If stepping, remember current thread to switch back to. */
2131 deferred_step_ptid = inferior_ptid;
2133 /* Switch back to WAIT_PID thread. */
2134 switch_to_thread (wait_ptid);
2137 fprintf_unfiltered (gdb_stdlog,
2138 "infrun: prepare_to_proceed (step=%d), "
2139 "switched to [%s]\n",
2140 step, target_pid_to_str (inferior_ptid));
2142 /* We return 1 to indicate that there is a breakpoint here,
2143 so we need to step over it before continuing to avoid
2144 hitting it straight away. */
2152 /* Basic routine for continuing the program in various fashions.
2154 ADDR is the address to resume at, or -1 for resume where stopped.
2155 SIGGNAL is the signal to give it, or 0 for none,
2156 or -1 for act according to how it stopped.
2157 STEP is nonzero if should trap after one instruction.
2158 -1 means return after that and print nothing.
2159 You should probably set various step_... variables
2160 before calling here, if you are stepping.
2162 You should call clear_proceed_status before calling proceed. */
2165 proceed (CORE_ADDR addr, enum gdb_signal siggnal, int step)
2167 struct regcache *regcache;
2168 struct gdbarch *gdbarch;
2169 struct thread_info *tp;
2171 struct address_space *aspace;
2172 /* GDB may force the inferior to step due to various reasons. */
2175 /* If we're stopped at a fork/vfork, follow the branch set by the
2176 "set follow-fork-mode" command; otherwise, we'll just proceed
2177 resuming the current thread. */
2178 if (!follow_fork ())
2180 /* The target for some reason decided not to resume. */
2182 if (target_can_async_p ())
2183 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2187 /* We'll update this if & when we switch to a new thread. */
2188 previous_inferior_ptid = inferior_ptid;
2190 regcache = get_current_regcache ();
2191 gdbarch = get_regcache_arch (regcache);
2192 aspace = get_regcache_aspace (regcache);
2193 pc = regcache_read_pc (regcache);
2196 step_start_function = find_pc_function (pc);
2198 stop_after_trap = 1;
2200 if (addr == (CORE_ADDR) -1)
2202 if (pc == stop_pc && breakpoint_here_p (aspace, pc)
2203 && execution_direction != EXEC_REVERSE)
2204 /* There is a breakpoint at the address we will resume at,
2205 step one instruction before inserting breakpoints so that
2206 we do not stop right away (and report a second hit at this
2209 Note, we don't do this in reverse, because we won't
2210 actually be executing the breakpoint insn anyway.
2211 We'll be (un-)executing the previous instruction. */
2214 else if (gdbarch_single_step_through_delay_p (gdbarch)
2215 && gdbarch_single_step_through_delay (gdbarch,
2216 get_current_frame ()))
2217 /* We stepped onto an instruction that needs to be stepped
2218 again before re-inserting the breakpoint, do so. */
2223 regcache_write_pc (regcache, addr);
2227 fprintf_unfiltered (gdb_stdlog,
2228 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
2229 paddress (gdbarch, addr), siggnal, step);
2232 /* In non-stop, each thread is handled individually. The context
2233 must already be set to the right thread here. */
2237 /* In a multi-threaded task we may select another thread and
2238 then continue or step.
2240 But if the old thread was stopped at a breakpoint, it will
2241 immediately cause another breakpoint stop without any
2242 execution (i.e. it will report a breakpoint hit incorrectly).
2243 So we must step over it first.
2245 prepare_to_proceed checks the current thread against the
2246 thread that reported the most recent event. If a step-over
2247 is required it returns TRUE and sets the current thread to
2249 if (prepare_to_proceed (step))
2253 /* prepare_to_proceed may change the current thread. */
2254 tp = inferior_thread ();
2258 tp->control.trap_expected = 1;
2259 /* If displaced stepping is enabled, we can step over the
2260 breakpoint without hitting it, so leave all breakpoints
2261 inserted. Otherwise we need to disable all breakpoints, step
2262 one instruction, and then re-add them when that step is
2264 if (!use_displaced_stepping (gdbarch))
2265 remove_breakpoints ();
2268 /* We can insert breakpoints if we're not trying to step over one,
2269 or if we are stepping over one but we're using displaced stepping
2271 if (! tp->control.trap_expected || use_displaced_stepping (gdbarch))
2272 insert_breakpoints ();
2276 /* Pass the last stop signal to the thread we're resuming,
2277 irrespective of whether the current thread is the thread that
2278 got the last event or not. This was historically GDB's
2279 behaviour before keeping a stop_signal per thread. */
2281 struct thread_info *last_thread;
2283 struct target_waitstatus last_status;
2285 get_last_target_status (&last_ptid, &last_status);
2286 if (!ptid_equal (inferior_ptid, last_ptid)
2287 && !ptid_equal (last_ptid, null_ptid)
2288 && !ptid_equal (last_ptid, minus_one_ptid))
2290 last_thread = find_thread_ptid (last_ptid);
2293 tp->suspend.stop_signal = last_thread->suspend.stop_signal;
2294 last_thread->suspend.stop_signal = GDB_SIGNAL_0;
2299 if (siggnal != GDB_SIGNAL_DEFAULT)
2300 tp->suspend.stop_signal = siggnal;
2301 /* If this signal should not be seen by program,
2302 give it zero. Used for debugging signals. */
2303 else if (!signal_program[tp->suspend.stop_signal])
2304 tp->suspend.stop_signal = GDB_SIGNAL_0;
2306 annotate_starting ();
2308 /* Make sure that output from GDB appears before output from the
2310 gdb_flush (gdb_stdout);
2312 /* Refresh prev_pc value just prior to resuming. This used to be
2313 done in stop_stepping, however, setting prev_pc there did not handle
2314 scenarios such as inferior function calls or returning from
2315 a function via the return command. In those cases, the prev_pc
2316 value was not set properly for subsequent commands. The prev_pc value
2317 is used to initialize the starting line number in the ecs. With an
2318 invalid value, the gdb next command ends up stopping at the position
2319 represented by the next line table entry past our start position.
2320 On platforms that generate one line table entry per line, this
2321 is not a problem. However, on the ia64, the compiler generates
2322 extraneous line table entries that do not increase the line number.
2323 When we issue the gdb next command on the ia64 after an inferior call
2324 or a return command, we often end up a few instructions forward, still
2325 within the original line we started.
2327 An attempt was made to refresh the prev_pc at the same time the
2328 execution_control_state is initialized (for instance, just before
2329 waiting for an inferior event). But this approach did not work
2330 because of platforms that use ptrace, where the pc register cannot
2331 be read unless the inferior is stopped. At that point, we are not
2332 guaranteed the inferior is stopped and so the regcache_read_pc() call
2333 can fail. Setting the prev_pc value here ensures the value is updated
2334 correctly when the inferior is stopped. */
2335 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2337 /* Fill in with reasonable starting values. */
2338 init_thread_stepping_state (tp);
2340 /* Reset to normal state. */
2341 init_infwait_state ();
2343 /* Resume inferior. */
2344 resume (force_step || step || bpstat_should_step (),
2345 tp->suspend.stop_signal);
2347 /* Wait for it to stop (if not standalone)
2348 and in any case decode why it stopped, and act accordingly. */
2349 /* Do this only if we are not using the event loop, or if the target
2350 does not support asynchronous execution. */
2351 if (!target_can_async_p ())
2353 wait_for_inferior ();
2359 /* Start remote-debugging of a machine over a serial link. */
2362 start_remote (int from_tty)
2364 struct inferior *inferior;
2366 inferior = current_inferior ();
2367 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2369 /* Always go on waiting for the target, regardless of the mode. */
2370 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2371 indicate to wait_for_inferior that a target should timeout if
2372 nothing is returned (instead of just blocking). Because of this,
2373 targets expecting an immediate response need to, internally, set
2374 things up so that the target_wait() is forced to eventually
2376 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2377 differentiate to its caller what the state of the target is after
2378 the initial open has been performed. Here we're assuming that
2379 the target has stopped. It should be possible to eventually have
2380 target_open() return to the caller an indication that the target
2381 is currently running and GDB state should be set to the same as
2382 for an async run. */
2383 wait_for_inferior ();
2385 /* Now that the inferior has stopped, do any bookkeeping like
2386 loading shared libraries. We want to do this before normal_stop,
2387 so that the displayed frame is up to date. */
2388 post_create_inferior (¤t_target, from_tty);
2393 /* Initialize static vars when a new inferior begins. */
2396 init_wait_for_inferior (void)
2398 /* These are meaningless until the first time through wait_for_inferior. */
2400 breakpoint_init_inferior (inf_starting);
2402 clear_proceed_status ();
2404 stepping_past_singlestep_breakpoint = 0;
2405 deferred_step_ptid = null_ptid;
2407 target_last_wait_ptid = minus_one_ptid;
2409 previous_inferior_ptid = inferior_ptid;
2410 init_infwait_state ();
2412 /* Discard any skipped inlined frames. */
2413 clear_inline_frame_state (minus_one_ptid);
2417 /* This enum encodes possible reasons for doing a target_wait, so that
2418 wfi can call target_wait in one place. (Ultimately the call will be
2419 moved out of the infinite loop entirely.) */
2423 infwait_normal_state,
2424 infwait_thread_hop_state,
2425 infwait_step_watch_state,
2426 infwait_nonstep_watch_state
2429 /* The PTID we'll do a target_wait on.*/
2432 /* Current inferior wait state. */
2433 static enum infwait_states infwait_state;
2435 /* Data to be passed around while handling an event. This data is
2436 discarded between events. */
2437 struct execution_control_state
2440 /* The thread that got the event, if this was a thread event; NULL
2442 struct thread_info *event_thread;
2444 struct target_waitstatus ws;
2446 int stop_func_filled_in;
2447 CORE_ADDR stop_func_start;
2448 CORE_ADDR stop_func_end;
2449 const char *stop_func_name;
2453 static void handle_inferior_event (struct execution_control_state *ecs);
2455 static void handle_step_into_function (struct gdbarch *gdbarch,
2456 struct execution_control_state *ecs);
2457 static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2458 struct execution_control_state *ecs);
2459 static void check_exception_resume (struct execution_control_state *,
2460 struct frame_info *);
2462 static void stop_stepping (struct execution_control_state *ecs);
2463 static void prepare_to_wait (struct execution_control_state *ecs);
2464 static void keep_going (struct execution_control_state *ecs);
2466 /* Callback for iterate over threads. If the thread is stopped, but
2467 the user/frontend doesn't know about that yet, go through
2468 normal_stop, as if the thread had just stopped now. ARG points at
2469 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2470 ptid_is_pid(PTID) is true, applies to all threads of the process
2471 pointed at by PTID. Otherwise, apply only to the thread pointed by
2475 infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2477 ptid_t ptid = * (ptid_t *) arg;
2479 if ((ptid_equal (info->ptid, ptid)
2480 || ptid_equal (minus_one_ptid, ptid)
2481 || (ptid_is_pid (ptid)
2482 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2483 && is_running (info->ptid)
2484 && !is_executing (info->ptid))
2486 struct cleanup *old_chain;
2487 struct execution_control_state ecss;
2488 struct execution_control_state *ecs = &ecss;
2490 memset (ecs, 0, sizeof (*ecs));
2492 old_chain = make_cleanup_restore_current_thread ();
2494 /* Go through handle_inferior_event/normal_stop, so we always
2495 have consistent output as if the stop event had been
2497 ecs->ptid = info->ptid;
2498 ecs->event_thread = find_thread_ptid (info->ptid);
2499 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2500 ecs->ws.value.sig = GDB_SIGNAL_0;
2502 handle_inferior_event (ecs);
2504 if (!ecs->wait_some_more)
2506 struct thread_info *tp;
2510 /* Finish off the continuations. */
2511 tp = inferior_thread ();
2512 do_all_intermediate_continuations_thread (tp, 1);
2513 do_all_continuations_thread (tp, 1);
2516 do_cleanups (old_chain);
2522 /* This function is attached as a "thread_stop_requested" observer.
2523 Cleanup local state that assumed the PTID was to be resumed, and
2524 report the stop to the frontend. */
2527 infrun_thread_stop_requested (ptid_t ptid)
2529 struct displaced_step_inferior_state *displaced;
2531 /* PTID was requested to stop. Remove it from the displaced
2532 stepping queue, so we don't try to resume it automatically. */
2534 for (displaced = displaced_step_inferior_states;
2536 displaced = displaced->next)
2538 struct displaced_step_request *it, **prev_next_p;
2540 it = displaced->step_request_queue;
2541 prev_next_p = &displaced->step_request_queue;
2544 if (ptid_match (it->ptid, ptid))
2546 *prev_next_p = it->next;
2552 prev_next_p = &it->next;
2559 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2563 infrun_thread_thread_exit (struct thread_info *tp, int silent)
2565 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2566 nullify_last_target_wait_ptid ();
2569 /* Callback for iterate_over_threads. */
2572 delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
2574 if (is_exited (info->ptid))
2577 delete_step_resume_breakpoint (info);
2578 delete_exception_resume_breakpoint (info);
2582 /* In all-stop, delete the step resume breakpoint of any thread that
2583 had one. In non-stop, delete the step resume breakpoint of the
2584 thread that just stopped. */
2587 delete_step_thread_step_resume_breakpoint (void)
2589 if (!target_has_execution
2590 || ptid_equal (inferior_ptid, null_ptid))
2591 /* If the inferior has exited, we have already deleted the step
2592 resume breakpoints out of GDB's lists. */
2597 /* If in non-stop mode, only delete the step-resume or
2598 longjmp-resume breakpoint of the thread that just stopped
2600 struct thread_info *tp = inferior_thread ();
2602 delete_step_resume_breakpoint (tp);
2603 delete_exception_resume_breakpoint (tp);
2606 /* In all-stop mode, delete all step-resume and longjmp-resume
2607 breakpoints of any thread that had them. */
2608 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
2611 /* A cleanup wrapper. */
2614 delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
2616 delete_step_thread_step_resume_breakpoint ();
2619 /* Pretty print the results of target_wait, for debugging purposes. */
2622 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
2623 const struct target_waitstatus *ws)
2625 char *status_string = target_waitstatus_to_string (ws);
2626 struct ui_file *tmp_stream = mem_fileopen ();
2629 /* The text is split over several lines because it was getting too long.
2630 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2631 output as a unit; we want only one timestamp printed if debug_timestamp
2634 fprintf_unfiltered (tmp_stream,
2635 "infrun: target_wait (%d", PIDGET (waiton_ptid));
2636 if (PIDGET (waiton_ptid) != -1)
2637 fprintf_unfiltered (tmp_stream,
2638 " [%s]", target_pid_to_str (waiton_ptid));
2639 fprintf_unfiltered (tmp_stream, ", status) =\n");
2640 fprintf_unfiltered (tmp_stream,
2641 "infrun: %d [%s],\n",
2642 PIDGET (result_ptid), target_pid_to_str (result_ptid));
2643 fprintf_unfiltered (tmp_stream,
2647 text = ui_file_xstrdup (tmp_stream, NULL);
2649 /* This uses %s in part to handle %'s in the text, but also to avoid
2650 a gcc error: the format attribute requires a string literal. */
2651 fprintf_unfiltered (gdb_stdlog, "%s", text);
2653 xfree (status_string);
2655 ui_file_delete (tmp_stream);
2658 /* Prepare and stabilize the inferior for detaching it. E.g.,
2659 detaching while a thread is displaced stepping is a recipe for
2660 crashing it, as nothing would readjust the PC out of the scratch
2664 prepare_for_detach (void)
2666 struct inferior *inf = current_inferior ();
2667 ptid_t pid_ptid = pid_to_ptid (inf->pid);
2668 struct cleanup *old_chain_1;
2669 struct displaced_step_inferior_state *displaced;
2671 displaced = get_displaced_stepping_state (inf->pid);
2673 /* Is any thread of this process displaced stepping? If not,
2674 there's nothing else to do. */
2675 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
2679 fprintf_unfiltered (gdb_stdlog,
2680 "displaced-stepping in-process while detaching");
2682 old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
2685 while (!ptid_equal (displaced->step_ptid, null_ptid))
2687 struct cleanup *old_chain_2;
2688 struct execution_control_state ecss;
2689 struct execution_control_state *ecs;
2692 memset (ecs, 0, sizeof (*ecs));
2694 overlay_cache_invalid = 1;
2696 if (deprecated_target_wait_hook)
2697 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
2699 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
2702 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
2704 /* If an error happens while handling the event, propagate GDB's
2705 knowledge of the executing state to the frontend/user running
2707 old_chain_2 = make_cleanup (finish_thread_state_cleanup,
2710 /* Now figure out what to do with the result of the result. */
2711 handle_inferior_event (ecs);
2713 /* No error, don't finish the state yet. */
2714 discard_cleanups (old_chain_2);
2716 /* Breakpoints and watchpoints are not installed on the target
2717 at this point, and signals are passed directly to the
2718 inferior, so this must mean the process is gone. */
2719 if (!ecs->wait_some_more)
2721 discard_cleanups (old_chain_1);
2722 error (_("Program exited while detaching"));
2726 discard_cleanups (old_chain_1);
2729 /* Wait for control to return from inferior to debugger.
2731 If inferior gets a signal, we may decide to start it up again
2732 instead of returning. That is why there is a loop in this function.
2733 When this function actually returns it means the inferior
2734 should be left stopped and GDB should read more commands. */
2737 wait_for_inferior (void)
2739 struct cleanup *old_cleanups;
2743 (gdb_stdlog, "infrun: wait_for_inferior ()\n");
2746 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
2750 struct execution_control_state ecss;
2751 struct execution_control_state *ecs = &ecss;
2752 struct cleanup *old_chain;
2754 memset (ecs, 0, sizeof (*ecs));
2756 overlay_cache_invalid = 1;
2758 if (deprecated_target_wait_hook)
2759 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
2761 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
2764 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2766 /* If an error happens while handling the event, propagate GDB's
2767 knowledge of the executing state to the frontend/user running
2769 old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2771 /* Now figure out what to do with the result of the result. */
2772 handle_inferior_event (ecs);
2774 /* No error, don't finish the state yet. */
2775 discard_cleanups (old_chain);
2777 if (!ecs->wait_some_more)
2781 do_cleanups (old_cleanups);
2784 /* Asynchronous version of wait_for_inferior. It is called by the
2785 event loop whenever a change of state is detected on the file
2786 descriptor corresponding to the target. It can be called more than
2787 once to complete a single execution command. In such cases we need
2788 to keep the state in a global variable ECSS. If it is the last time
2789 that this function is called for a single execution command, then
2790 report to the user that the inferior has stopped, and do the
2791 necessary cleanups. */
2794 fetch_inferior_event (void *client_data)
2796 struct execution_control_state ecss;
2797 struct execution_control_state *ecs = &ecss;
2798 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
2799 struct cleanup *ts_old_chain;
2800 int was_sync = sync_execution;
2803 memset (ecs, 0, sizeof (*ecs));
2805 /* We're handling a live event, so make sure we're doing live
2806 debugging. If we're looking at traceframes while the target is
2807 running, we're going to need to get back to that mode after
2808 handling the event. */
2811 make_cleanup_restore_current_traceframe ();
2812 set_current_traceframe (-1);
2816 /* In non-stop mode, the user/frontend should not notice a thread
2817 switch due to internal events. Make sure we reverse to the
2818 user selected thread and frame after handling the event and
2819 running any breakpoint commands. */
2820 make_cleanup_restore_current_thread ();
2822 overlay_cache_invalid = 1;
2824 make_cleanup_restore_integer (&execution_direction);
2825 execution_direction = target_execution_direction ();
2827 if (deprecated_target_wait_hook)
2829 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2831 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2834 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2836 /* If an error happens while handling the event, propagate GDB's
2837 knowledge of the executing state to the frontend/user running
2840 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2842 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
2844 /* Get executed before make_cleanup_restore_current_thread above to apply
2845 still for the thread which has thrown the exception. */
2846 make_bpstat_clear_actions_cleanup ();
2848 /* Now figure out what to do with the result of the result. */
2849 handle_inferior_event (ecs);
2851 if (!ecs->wait_some_more)
2853 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2855 delete_step_thread_step_resume_breakpoint ();
2857 /* We may not find an inferior if this was a process exit. */
2858 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
2861 if (target_has_execution
2862 && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED
2863 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2864 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2865 && ecs->event_thread->step_multi
2866 && ecs->event_thread->control.stop_step)
2867 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
2870 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2875 /* No error, don't finish the thread states yet. */
2876 discard_cleanups (ts_old_chain);
2878 /* Revert thread and frame. */
2879 do_cleanups (old_chain);
2881 /* If the inferior was in sync execution mode, and now isn't,
2882 restore the prompt (a synchronous execution command has finished,
2883 and we're ready for input). */
2884 if (interpreter_async && was_sync && !sync_execution)
2885 display_gdb_prompt (0);
2889 && exec_done_display_p
2890 && (ptid_equal (inferior_ptid, null_ptid)
2891 || !is_running (inferior_ptid)))
2892 printf_unfiltered (_("completed.\n"));
2895 /* Record the frame and location we're currently stepping through. */
2897 set_step_info (struct frame_info *frame, struct symtab_and_line sal)
2899 struct thread_info *tp = inferior_thread ();
2901 tp->control.step_frame_id = get_frame_id (frame);
2902 tp->control.step_stack_frame_id = get_stack_frame_id (frame);
2904 tp->current_symtab = sal.symtab;
2905 tp->current_line = sal.line;
2908 /* Clear context switchable stepping state. */
2911 init_thread_stepping_state (struct thread_info *tss)
2913 tss->stepping_over_breakpoint = 0;
2914 tss->step_after_step_resume_breakpoint = 0;
2917 /* Return the cached copy of the last pid/waitstatus returned by
2918 target_wait()/deprecated_target_wait_hook(). The data is actually
2919 cached by handle_inferior_event(), which gets called immediately
2920 after target_wait()/deprecated_target_wait_hook(). */
2923 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
2925 *ptidp = target_last_wait_ptid;
2926 *status = target_last_waitstatus;
2930 nullify_last_target_wait_ptid (void)
2932 target_last_wait_ptid = minus_one_ptid;
2935 /* Switch thread contexts. */
2938 context_switch (ptid_t ptid)
2940 if (debug_infrun && !ptid_equal (ptid, inferior_ptid))
2942 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
2943 target_pid_to_str (inferior_ptid));
2944 fprintf_unfiltered (gdb_stdlog, "to %s\n",
2945 target_pid_to_str (ptid));
2948 switch_to_thread (ptid);
2952 adjust_pc_after_break (struct execution_control_state *ecs)
2954 struct regcache *regcache;
2955 struct gdbarch *gdbarch;
2956 struct address_space *aspace;
2957 CORE_ADDR breakpoint_pc;
2959 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2960 we aren't, just return.
2962 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2963 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2964 implemented by software breakpoints should be handled through the normal
2967 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2968 different signals (SIGILL or SIGEMT for instance), but it is less
2969 clear where the PC is pointing afterwards. It may not match
2970 gdbarch_decr_pc_after_break. I don't know any specific target that
2971 generates these signals at breakpoints (the code has been in GDB since at
2972 least 1992) so I can not guess how to handle them here.
2974 In earlier versions of GDB, a target with
2975 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2976 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2977 target with both of these set in GDB history, and it seems unlikely to be
2978 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2980 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
2983 if (ecs->ws.value.sig != GDB_SIGNAL_TRAP)
2986 /* In reverse execution, when a breakpoint is hit, the instruction
2987 under it has already been de-executed. The reported PC always
2988 points at the breakpoint address, so adjusting it further would
2989 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2992 B1 0x08000000 : INSN1
2993 B2 0x08000001 : INSN2
2995 PC -> 0x08000003 : INSN4
2997 Say you're stopped at 0x08000003 as above. Reverse continuing
2998 from that point should hit B2 as below. Reading the PC when the
2999 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3000 been de-executed already.
3002 B1 0x08000000 : INSN1
3003 B2 PC -> 0x08000001 : INSN2
3007 We can't apply the same logic as for forward execution, because
3008 we would wrongly adjust the PC to 0x08000000, since there's a
3009 breakpoint at PC - 1. We'd then report a hit on B1, although
3010 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3012 if (execution_direction == EXEC_REVERSE)
3015 /* If this target does not decrement the PC after breakpoints, then
3016 we have nothing to do. */
3017 regcache = get_thread_regcache (ecs->ptid);
3018 gdbarch = get_regcache_arch (regcache);
3019 if (gdbarch_decr_pc_after_break (gdbarch) == 0)
3022 aspace = get_regcache_aspace (regcache);
3024 /* Find the location where (if we've hit a breakpoint) the
3025 breakpoint would be. */
3026 breakpoint_pc = regcache_read_pc (regcache)
3027 - gdbarch_decr_pc_after_break (gdbarch);
3029 /* Check whether there actually is a software breakpoint inserted at
3032 If in non-stop mode, a race condition is possible where we've
3033 removed a breakpoint, but stop events for that breakpoint were
3034 already queued and arrive later. To suppress those spurious
3035 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3036 and retire them after a number of stop events are reported. */
3037 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
3038 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
3040 struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
3043 record_full_gdb_operation_disable_set ();
3045 /* When using hardware single-step, a SIGTRAP is reported for both
3046 a completed single-step and a software breakpoint. Need to
3047 differentiate between the two, as the latter needs adjusting
3048 but the former does not.
3050 The SIGTRAP can be due to a completed hardware single-step only if
3051 - we didn't insert software single-step breakpoints
3052 - the thread to be examined is still the current thread
3053 - this thread is currently being stepped
3055 If any of these events did not occur, we must have stopped due
3056 to hitting a software breakpoint, and have to back up to the
3059 As a special case, we could have hardware single-stepped a
3060 software breakpoint. In this case (prev_pc == breakpoint_pc),
3061 we also need to back up to the breakpoint address. */
3063 if (singlestep_breakpoints_inserted_p
3064 || !ptid_equal (ecs->ptid, inferior_ptid)
3065 || !currently_stepping (ecs->event_thread)
3066 || ecs->event_thread->prev_pc == breakpoint_pc)
3067 regcache_write_pc (regcache, breakpoint_pc);
3069 do_cleanups (old_cleanups);
3074 init_infwait_state (void)
3076 waiton_ptid = pid_to_ptid (-1);
3077 infwait_state = infwait_normal_state;
3081 stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
3083 for (frame = get_prev_frame (frame);
3085 frame = get_prev_frame (frame))
3087 if (frame_id_eq (get_frame_id (frame), step_frame_id))
3089 if (get_frame_type (frame) != INLINE_FRAME)
3096 /* Auxiliary function that handles syscall entry/return events.
3097 It returns 1 if the inferior should keep going (and GDB
3098 should ignore the event), or 0 if the event deserves to be
3102 handle_syscall_event (struct execution_control_state *ecs)
3104 struct regcache *regcache;
3107 if (!ptid_equal (ecs->ptid, inferior_ptid))
3108 context_switch (ecs->ptid);
3110 regcache = get_thread_regcache (ecs->ptid);
3111 syscall_number = ecs->ws.value.syscall_number;
3112 stop_pc = regcache_read_pc (regcache);
3114 if (catch_syscall_enabled () > 0
3115 && catching_syscall_number (syscall_number) > 0)
3117 enum bpstat_signal_value sval;
3120 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
3123 ecs->event_thread->control.stop_bpstat
3124 = bpstat_stop_status (get_regcache_aspace (regcache),
3125 stop_pc, ecs->ptid, &ecs->ws);
3127 sval = bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
3129 ecs->random_signal = sval == BPSTAT_SIGNAL_NO;
3131 if (!ecs->random_signal)
3133 /* Catchpoint hit. */
3134 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP;
3139 /* If no catchpoint triggered for this, then keep going. */
3140 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
3145 /* Clear the supplied execution_control_state's stop_func_* fields. */
3148 clear_stop_func (struct execution_control_state *ecs)
3150 ecs->stop_func_filled_in = 0;
3151 ecs->stop_func_start = 0;
3152 ecs->stop_func_end = 0;
3153 ecs->stop_func_name = NULL;
3156 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3159 fill_in_stop_func (struct gdbarch *gdbarch,
3160 struct execution_control_state *ecs)
3162 if (!ecs->stop_func_filled_in)
3164 /* Don't care about return value; stop_func_start and stop_func_name
3165 will both be 0 if it doesn't work. */
3166 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3167 &ecs->stop_func_start, &ecs->stop_func_end);
3168 ecs->stop_func_start
3169 += gdbarch_deprecated_function_start_offset (gdbarch);
3171 ecs->stop_func_filled_in = 1;
3175 /* Given an execution control state that has been freshly filled in
3176 by an event from the inferior, figure out what it means and take
3177 appropriate action. */
3180 handle_inferior_event (struct execution_control_state *ecs)
3182 struct frame_info *frame;
3183 struct gdbarch *gdbarch;
3184 int stopped_by_watchpoint;
3185 int stepped_after_stopped_by_watchpoint = 0;
3186 struct symtab_and_line stop_pc_sal;
3187 enum stop_kind stop_soon;
3189 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
3191 /* We had an event in the inferior, but we are not interested in
3192 handling it at this level. The lower layers have already
3193 done what needs to be done, if anything.
3195 One of the possible circumstances for this is when the
3196 inferior produces output for the console. The inferior has
3197 not stopped, and we are ignoring the event. Another possible
3198 circumstance is any event which the lower level knows will be
3199 reported multiple times without an intervening resume. */
3201 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
3202 prepare_to_wait (ecs);
3206 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED
3207 && target_can_async_p () && !sync_execution)
3209 /* There were no unwaited-for children left in the target, but,
3210 we're not synchronously waiting for events either. Just
3211 ignore. Otherwise, if we were running a synchronous
3212 execution command, we need to cancel it and give the user
3213 back the terminal. */
3215 fprintf_unfiltered (gdb_stdlog,
3216 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3217 prepare_to_wait (ecs);
3221 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3222 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3223 && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED)
3225 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
3228 stop_soon = inf->control.stop_soon;
3231 stop_soon = NO_STOP_QUIETLY;
3233 /* Cache the last pid/waitstatus. */
3234 target_last_wait_ptid = ecs->ptid;
3235 target_last_waitstatus = ecs->ws;
3237 /* Always clear state belonging to the previous time we stopped. */
3238 stop_stack_dummy = STOP_NONE;
3240 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED)
3242 /* No unwaited-for children left. IOW, all resumed children
3245 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3247 stop_print_frame = 0;
3248 stop_stepping (ecs);
3252 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3253 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
3255 ecs->event_thread = find_thread_ptid (ecs->ptid);
3256 /* If it's a new thread, add it to the thread database. */
3257 if (ecs->event_thread == NULL)
3258 ecs->event_thread = add_thread (ecs->ptid);
3260 /* Disable range stepping. If the next step request could use a
3261 range, this will be end up re-enabled then. */
3262 ecs->event_thread->control.may_range_step = 0;
3265 /* Dependent on valid ECS->EVENT_THREAD. */
3266 adjust_pc_after_break (ecs);
3268 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3269 reinit_frame_cache ();
3271 breakpoint_retire_moribund ();
3273 /* First, distinguish signals caused by the debugger from signals
3274 that have to do with the program's own actions. Note that
3275 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3276 on the operating system version. Here we detect when a SIGILL or
3277 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3278 something similar for SIGSEGV, since a SIGSEGV will be generated
3279 when we're trying to execute a breakpoint instruction on a
3280 non-executable stack. This happens for call dummy breakpoints
3281 for architectures like SPARC that place call dummies on the
3283 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
3284 && (ecs->ws.value.sig == GDB_SIGNAL_ILL
3285 || ecs->ws.value.sig == GDB_SIGNAL_SEGV
3286 || ecs->ws.value.sig == GDB_SIGNAL_EMT))
3288 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3290 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3291 regcache_read_pc (regcache)))
3294 fprintf_unfiltered (gdb_stdlog,
3295 "infrun: Treating signal as SIGTRAP\n");
3296 ecs->ws.value.sig = GDB_SIGNAL_TRAP;
3300 /* Mark the non-executing threads accordingly. In all-stop, all
3301 threads of all processes are stopped when we get any event
3302 reported. In non-stop mode, only the event thread stops. If
3303 we're handling a process exit in non-stop mode, there's nothing
3304 to do, as threads of the dead process are gone, and threads of
3305 any other process were left running. */
3307 set_executing (minus_one_ptid, 0);
3308 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3309 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
3310 set_executing (ecs->ptid, 0);
3312 switch (infwait_state)
3314 case infwait_thread_hop_state:
3316 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
3319 case infwait_normal_state:
3321 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
3324 case infwait_step_watch_state:
3326 fprintf_unfiltered (gdb_stdlog,
3327 "infrun: infwait_step_watch_state\n");
3329 stepped_after_stopped_by_watchpoint = 1;
3332 case infwait_nonstep_watch_state:
3334 fprintf_unfiltered (gdb_stdlog,
3335 "infrun: infwait_nonstep_watch_state\n");
3336 insert_breakpoints ();
3338 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3339 handle things like signals arriving and other things happening
3340 in combination correctly? */
3341 stepped_after_stopped_by_watchpoint = 1;
3345 internal_error (__FILE__, __LINE__, _("bad switch"));
3348 infwait_state = infwait_normal_state;
3349 waiton_ptid = pid_to_ptid (-1);
3351 switch (ecs->ws.kind)
3353 case TARGET_WAITKIND_LOADED:
3355 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
3356 /* Ignore gracefully during startup of the inferior, as it might
3357 be the shell which has just loaded some objects, otherwise
3358 add the symbols for the newly loaded objects. Also ignore at
3359 the beginning of an attach or remote session; we will query
3360 the full list of libraries once the connection is
3362 if (stop_soon == NO_STOP_QUIETLY)
3364 struct regcache *regcache;
3365 enum bpstat_signal_value sval;
3367 if (!ptid_equal (ecs->ptid, inferior_ptid))
3368 context_switch (ecs->ptid);
3369 regcache = get_thread_regcache (ecs->ptid);
3371 handle_solib_event ();
3373 ecs->event_thread->control.stop_bpstat
3374 = bpstat_stop_status (get_regcache_aspace (regcache),
3375 stop_pc, ecs->ptid, &ecs->ws);
3378 = bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
3380 ecs->random_signal = sval == BPSTAT_SIGNAL_NO;
3382 if (!ecs->random_signal)
3384 /* A catchpoint triggered. */
3385 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP;
3386 goto process_event_stop_test;
3389 /* If requested, stop when the dynamic linker notifies
3390 gdb of events. This allows the user to get control
3391 and place breakpoints in initializer routines for
3392 dynamically loaded objects (among other things). */
3393 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
3394 if (stop_on_solib_events)
3396 /* Make sure we print "Stopped due to solib-event" in
3398 stop_print_frame = 1;
3400 stop_stepping (ecs);
3405 /* If we are skipping through a shell, or through shared library
3406 loading that we aren't interested in, resume the program. If
3407 we're running the program normally, also resume. But stop if
3408 we're attaching or setting up a remote connection. */
3409 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
3411 if (!ptid_equal (ecs->ptid, inferior_ptid))
3412 context_switch (ecs->ptid);
3414 /* Loading of shared libraries might have changed breakpoint
3415 addresses. Make sure new breakpoints are inserted. */
3416 if (stop_soon == NO_STOP_QUIETLY
3417 && !breakpoints_always_inserted_mode ())
3418 insert_breakpoints ();
3419 resume (0, GDB_SIGNAL_0);
3420 prepare_to_wait (ecs);
3426 case TARGET_WAITKIND_SPURIOUS:
3428 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3429 if (!ptid_equal (ecs->ptid, inferior_ptid))
3430 context_switch (ecs->ptid);
3431 resume (0, GDB_SIGNAL_0);
3432 prepare_to_wait (ecs);
3435 case TARGET_WAITKIND_EXITED:
3436 case TARGET_WAITKIND_SIGNALLED:
3439 if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3440 fprintf_unfiltered (gdb_stdlog,
3441 "infrun: TARGET_WAITKIND_EXITED\n");
3443 fprintf_unfiltered (gdb_stdlog,
3444 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3447 inferior_ptid = ecs->ptid;
3448 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3449 set_current_program_space (current_inferior ()->pspace);
3450 handle_vfork_child_exec_or_exit (0);
3451 target_terminal_ours (); /* Must do this before mourn anyway. */
3453 if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3455 /* Record the exit code in the convenience variable $_exitcode, so
3456 that the user can inspect this again later. */
3457 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3458 (LONGEST) ecs->ws.value.integer);
3460 /* Also record this in the inferior itself. */
3461 current_inferior ()->has_exit_code = 1;
3462 current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer;
3464 print_exited_reason (ecs->ws.value.integer);
3467 print_signal_exited_reason (ecs->ws.value.sig);
3469 gdb_flush (gdb_stdout);
3470 target_mourn_inferior ();
3471 singlestep_breakpoints_inserted_p = 0;
3472 cancel_single_step_breakpoints ();
3473 stop_print_frame = 0;
3474 stop_stepping (ecs);
3477 /* The following are the only cases in which we keep going;
3478 the above cases end in a continue or goto. */
3479 case TARGET_WAITKIND_FORKED:
3480 case TARGET_WAITKIND_VFORKED:
3483 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3484 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3486 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORKED\n");
3489 /* Check whether the inferior is displaced stepping. */
3491 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3492 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3493 struct displaced_step_inferior_state *displaced
3494 = get_displaced_stepping_state (ptid_get_pid (ecs->ptid));
3496 /* If checking displaced stepping is supported, and thread
3497 ecs->ptid is displaced stepping. */
3498 if (displaced && ptid_equal (displaced->step_ptid, ecs->ptid))
3500 struct inferior *parent_inf
3501 = find_inferior_pid (ptid_get_pid (ecs->ptid));
3502 struct regcache *child_regcache;
3503 CORE_ADDR parent_pc;
3505 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3506 indicating that the displaced stepping of syscall instruction
3507 has been done. Perform cleanup for parent process here. Note
3508 that this operation also cleans up the child process for vfork,
3509 because their pages are shared. */
3510 displaced_step_fixup (ecs->ptid, GDB_SIGNAL_TRAP);
3512 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3514 /* Restore scratch pad for child process. */
3515 displaced_step_restore (displaced, ecs->ws.value.related_pid);
3518 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3519 the child's PC is also within the scratchpad. Set the child's PC
3520 to the parent's PC value, which has already been fixed up.
3521 FIXME: we use the parent's aspace here, although we're touching
3522 the child, because the child hasn't been added to the inferior
3523 list yet at this point. */
3526 = get_thread_arch_aspace_regcache (ecs->ws.value.related_pid,
3528 parent_inf->aspace);
3529 /* Read PC value of parent process. */
3530 parent_pc = regcache_read_pc (regcache);
3532 if (debug_displaced)
3533 fprintf_unfiltered (gdb_stdlog,
3534 "displaced: write child pc from %s to %s\n",
3536 regcache_read_pc (child_regcache)),
3537 paddress (gdbarch, parent_pc));
3539 regcache_write_pc (child_regcache, parent_pc);
3543 if (!ptid_equal (ecs->ptid, inferior_ptid))
3544 context_switch (ecs->ptid);
3546 /* Immediately detach breakpoints from the child before there's
3547 any chance of letting the user delete breakpoints from the
3548 breakpoint lists. If we don't do this early, it's easy to
3549 leave left over traps in the child, vis: "break foo; catch
3550 fork; c; <fork>; del; c; <child calls foo>". We only follow
3551 the fork on the last `continue', and by that time the
3552 breakpoint at "foo" is long gone from the breakpoint table.
3553 If we vforked, then we don't need to unpatch here, since both
3554 parent and child are sharing the same memory pages; we'll
3555 need to unpatch at follow/detach time instead to be certain
3556 that new breakpoints added between catchpoint hit time and
3557 vfork follow are detached. */
3558 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
3560 /* This won't actually modify the breakpoint list, but will
3561 physically remove the breakpoints from the child. */
3562 detach_breakpoints (ecs->ws.value.related_pid);
3565 if (singlestep_breakpoints_inserted_p)
3567 /* Pull the single step breakpoints out of the target. */
3568 remove_single_step_breakpoints ();
3569 singlestep_breakpoints_inserted_p = 0;
3572 /* In case the event is caught by a catchpoint, remember that
3573 the event is to be followed at the next resume of the thread,
3574 and not immediately. */
3575 ecs->event_thread->pending_follow = ecs->ws;
3577 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3579 ecs->event_thread->control.stop_bpstat
3580 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3581 stop_pc, ecs->ptid, &ecs->ws);
3583 /* Note that we're interested in knowing the bpstat actually
3584 causes a stop, not just if it may explain the signal.
3585 Software watchpoints, for example, always appear in the
3588 = !bpstat_causes_stop (ecs->event_thread->control.stop_bpstat);
3590 /* If no catchpoint triggered for this, then keep going. */
3591 if (ecs->random_signal)
3597 = (follow_fork_mode_string == follow_fork_mode_child);
3599 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
3601 should_resume = follow_fork ();
3604 child = ecs->ws.value.related_pid;
3606 /* In non-stop mode, also resume the other branch. */
3607 if (non_stop && !detach_fork)
3610 switch_to_thread (parent);
3612 switch_to_thread (child);
3614 ecs->event_thread = inferior_thread ();
3615 ecs->ptid = inferior_ptid;
3620 switch_to_thread (child);
3622 switch_to_thread (parent);
3624 ecs->event_thread = inferior_thread ();
3625 ecs->ptid = inferior_ptid;
3630 stop_stepping (ecs);
3633 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP;
3634 goto process_event_stop_test;
3636 case TARGET_WAITKIND_VFORK_DONE:
3637 /* Done with the shared memory region. Re-insert breakpoints in
3638 the parent, and keep going. */
3641 fprintf_unfiltered (gdb_stdlog,
3642 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3644 if (!ptid_equal (ecs->ptid, inferior_ptid))
3645 context_switch (ecs->ptid);
3647 current_inferior ()->waiting_for_vfork_done = 0;
3648 current_inferior ()->pspace->breakpoints_not_allowed = 0;
3649 /* This also takes care of reinserting breakpoints in the
3650 previously locked inferior. */
3654 case TARGET_WAITKIND_EXECD:
3656 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
3658 if (!ptid_equal (ecs->ptid, inferior_ptid))
3659 context_switch (ecs->ptid);
3661 singlestep_breakpoints_inserted_p = 0;
3662 cancel_single_step_breakpoints ();
3664 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3666 /* Do whatever is necessary to the parent branch of the vfork. */
3667 handle_vfork_child_exec_or_exit (1);
3669 /* This causes the eventpoints and symbol table to be reset.
3670 Must do this now, before trying to determine whether to
3672 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
3674 ecs->event_thread->control.stop_bpstat
3675 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3676 stop_pc, ecs->ptid, &ecs->ws);
3678 = (bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
3680 == BPSTAT_SIGNAL_NO);
3682 /* Note that this may be referenced from inside
3683 bpstat_stop_status above, through inferior_has_execd. */
3684 xfree (ecs->ws.value.execd_pathname);
3685 ecs->ws.value.execd_pathname = NULL;
3687 /* If no catchpoint triggered for this, then keep going. */
3688 if (ecs->random_signal)
3690 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
3694 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP;
3695 goto process_event_stop_test;
3697 /* Be careful not to try to gather much state about a thread
3698 that's in a syscall. It's frequently a losing proposition. */
3699 case TARGET_WAITKIND_SYSCALL_ENTRY:
3701 fprintf_unfiltered (gdb_stdlog,
3702 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3703 /* Getting the current syscall number. */
3704 if (handle_syscall_event (ecs) != 0)
3706 goto process_event_stop_test;
3708 /* Before examining the threads further, step this thread to
3709 get it entirely out of the syscall. (We get notice of the
3710 event when the thread is just on the verge of exiting a
3711 syscall. Stepping one instruction seems to get it back
3713 case TARGET_WAITKIND_SYSCALL_RETURN:
3715 fprintf_unfiltered (gdb_stdlog,
3716 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3717 if (handle_syscall_event (ecs) != 0)
3719 goto process_event_stop_test;
3721 case TARGET_WAITKIND_STOPPED:
3723 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
3724 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
3727 case TARGET_WAITKIND_NO_HISTORY:
3729 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
3730 /* Reverse execution: target ran out of history info. */
3732 /* Pull the single step breakpoints out of the target. */
3733 if (singlestep_breakpoints_inserted_p)
3735 if (!ptid_equal (ecs->ptid, inferior_ptid))
3736 context_switch (ecs->ptid);
3737 remove_single_step_breakpoints ();
3738 singlestep_breakpoints_inserted_p = 0;
3740 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3741 print_no_history_reason ();
3742 stop_stepping (ecs);
3746 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
3748 /* Do we need to clean up the state of a thread that has
3749 completed a displaced single-step? (Doing so usually affects
3750 the PC, so do it here, before we set stop_pc.) */
3751 displaced_step_fixup (ecs->ptid,
3752 ecs->event_thread->suspend.stop_signal);
3754 /* If we either finished a single-step or hit a breakpoint, but
3755 the user wanted this thread to be stopped, pretend we got a
3756 SIG0 (generic unsignaled stop). */
3758 if (ecs->event_thread->stop_requested
3759 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
3760 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
3763 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3767 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3768 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3769 struct cleanup *old_chain = save_inferior_ptid ();
3771 inferior_ptid = ecs->ptid;
3773 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
3774 paddress (gdbarch, stop_pc));
3775 if (target_stopped_by_watchpoint ())
3779 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
3781 if (target_stopped_data_address (¤t_target, &addr))
3782 fprintf_unfiltered (gdb_stdlog,
3783 "infrun: stopped data address = %s\n",
3784 paddress (gdbarch, addr));
3786 fprintf_unfiltered (gdb_stdlog,
3787 "infrun: (no data address available)\n");
3790 do_cleanups (old_chain);
3793 if (stepping_past_singlestep_breakpoint)
3795 gdb_assert (singlestep_breakpoints_inserted_p);
3796 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
3797 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
3799 stepping_past_singlestep_breakpoint = 0;
3801 /* We've either finished single-stepping past the single-step
3802 breakpoint, or stopped for some other reason. It would be nice if
3803 we could tell, but we can't reliably. */
3804 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
3807 fprintf_unfiltered (gdb_stdlog,
3808 "infrun: stepping_past_"
3809 "singlestep_breakpoint\n");
3810 /* Pull the single step breakpoints out of the target. */
3811 if (!ptid_equal (ecs->ptid, inferior_ptid))
3812 context_switch (ecs->ptid);
3813 remove_single_step_breakpoints ();
3814 singlestep_breakpoints_inserted_p = 0;
3816 ecs->random_signal = 0;
3817 ecs->event_thread->control.trap_expected = 0;
3819 context_switch (saved_singlestep_ptid);
3820 if (deprecated_context_hook)
3821 deprecated_context_hook (pid_to_thread_id (saved_singlestep_ptid));
3823 resume (1, GDB_SIGNAL_0);
3824 prepare_to_wait (ecs);
3829 if (!ptid_equal (deferred_step_ptid, null_ptid))
3831 /* In non-stop mode, there's never a deferred_step_ptid set. */
3832 gdb_assert (!non_stop);
3834 /* If we stopped for some other reason than single-stepping, ignore
3835 the fact that we were supposed to switch back. */
3836 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
3839 fprintf_unfiltered (gdb_stdlog,
3840 "infrun: handling deferred step\n");
3842 /* Pull the single step breakpoints out of the target. */
3843 if (singlestep_breakpoints_inserted_p)
3845 if (!ptid_equal (ecs->ptid, inferior_ptid))
3846 context_switch (ecs->ptid);
3847 remove_single_step_breakpoints ();
3848 singlestep_breakpoints_inserted_p = 0;
3851 ecs->event_thread->control.trap_expected = 0;
3853 context_switch (deferred_step_ptid);
3854 deferred_step_ptid = null_ptid;
3855 /* Suppress spurious "Switching to ..." message. */
3856 previous_inferior_ptid = inferior_ptid;
3858 resume (1, GDB_SIGNAL_0);
3859 prepare_to_wait (ecs);
3863 deferred_step_ptid = null_ptid;
3866 /* See if a thread hit a thread-specific breakpoint that was meant for
3867 another thread. If so, then step that thread past the breakpoint,
3870 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
3872 int thread_hop_needed = 0;
3873 struct address_space *aspace =
3874 get_regcache_aspace (get_thread_regcache (ecs->ptid));
3876 /* Check if a regular breakpoint has been hit before checking
3877 for a potential single step breakpoint. Otherwise, GDB will
3878 not see this breakpoint hit when stepping onto breakpoints. */
3879 if (regular_breakpoint_inserted_here_p (aspace, stop_pc))
3881 ecs->random_signal = 0;
3882 if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid))
3883 thread_hop_needed = 1;
3885 else if (singlestep_breakpoints_inserted_p)
3887 /* We have not context switched yet, so this should be true
3888 no matter which thread hit the singlestep breakpoint. */
3889 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
3891 fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
3893 target_pid_to_str (ecs->ptid));
3895 ecs->random_signal = 0;
3896 /* The call to in_thread_list is necessary because PTIDs sometimes
3897 change when we go from single-threaded to multi-threaded. If
3898 the singlestep_ptid is still in the list, assume that it is
3899 really different from ecs->ptid. */
3900 if (!ptid_equal (singlestep_ptid, ecs->ptid)
3901 && in_thread_list (singlestep_ptid))
3903 /* If the PC of the thread we were trying to single-step
3904 has changed, discard this event (which we were going
3905 to ignore anyway), and pretend we saw that thread
3906 trap. This prevents us continuously moving the
3907 single-step breakpoint forward, one instruction at a
3908 time. If the PC has changed, then the thread we were
3909 trying to single-step has trapped or been signalled,
3910 but the event has not been reported to GDB yet.
3912 There might be some cases where this loses signal
3913 information, if a signal has arrived at exactly the
3914 same time that the PC changed, but this is the best
3915 we can do with the information available. Perhaps we
3916 should arrange to report all events for all threads
3917 when they stop, or to re-poll the remote looking for
3918 this particular thread (i.e. temporarily enable
3921 CORE_ADDR new_singlestep_pc
3922 = regcache_read_pc (get_thread_regcache (singlestep_ptid));
3924 if (new_singlestep_pc != singlestep_pc)
3926 enum gdb_signal stop_signal;
3929 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
3930 " but expected thread advanced also\n");
3932 /* The current context still belongs to
3933 singlestep_ptid. Don't swap here, since that's
3934 the context we want to use. Just fudge our
3935 state and continue. */
3936 stop_signal = ecs->event_thread->suspend.stop_signal;
3937 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
3938 ecs->ptid = singlestep_ptid;
3939 ecs->event_thread = find_thread_ptid (ecs->ptid);
3940 ecs->event_thread->suspend.stop_signal = stop_signal;
3941 stop_pc = new_singlestep_pc;
3946 fprintf_unfiltered (gdb_stdlog,
3947 "infrun: unexpected thread\n");
3949 thread_hop_needed = 1;
3950 stepping_past_singlestep_breakpoint = 1;
3951 saved_singlestep_ptid = singlestep_ptid;
3956 if (thread_hop_needed)
3958 struct regcache *thread_regcache;
3959 int remove_status = 0;
3962 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
3964 /* Switch context before touching inferior memory, the
3965 previous thread may have exited. */
3966 if (!ptid_equal (inferior_ptid, ecs->ptid))
3967 context_switch (ecs->ptid);
3969 /* Saw a breakpoint, but it was hit by the wrong thread.
3972 if (singlestep_breakpoints_inserted_p)
3974 /* Pull the single step breakpoints out of the target. */
3975 remove_single_step_breakpoints ();
3976 singlestep_breakpoints_inserted_p = 0;
3979 /* If the arch can displace step, don't remove the
3981 thread_regcache = get_thread_regcache (ecs->ptid);
3982 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
3983 remove_status = remove_breakpoints ();
3985 /* Did we fail to remove breakpoints? If so, try
3986 to set the PC past the bp. (There's at least
3987 one situation in which we can fail to remove
3988 the bp's: On HP-UX's that use ttrace, we can't
3989 change the address space of a vforking child
3990 process until the child exits (well, okay, not
3991 then either :-) or execs. */
3992 if (remove_status != 0)
3993 error (_("Cannot step over breakpoint hit in wrong thread"));
3998 /* Only need to require the next event from this
3999 thread in all-stop mode. */
4000 waiton_ptid = ecs->ptid;
4001 infwait_state = infwait_thread_hop_state;
4004 ecs->event_thread->stepping_over_breakpoint = 1;
4009 else if (singlestep_breakpoints_inserted_p)
4011 ecs->random_signal = 0;
4015 ecs->random_signal = 1;
4017 /* See if something interesting happened to the non-current thread. If
4018 so, then switch to that thread. */
4019 if (!ptid_equal (ecs->ptid, inferior_ptid))
4022 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
4024 context_switch (ecs->ptid);
4026 if (deprecated_context_hook)
4027 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
4030 /* At this point, get hold of the now-current thread's frame. */
4031 frame = get_current_frame ();
4032 gdbarch = get_frame_arch (frame);
4034 if (singlestep_breakpoints_inserted_p)
4036 /* Pull the single step breakpoints out of the target. */
4037 remove_single_step_breakpoints ();
4038 singlestep_breakpoints_inserted_p = 0;
4041 if (stepped_after_stopped_by_watchpoint)
4042 stopped_by_watchpoint = 0;
4044 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
4046 /* If necessary, step over this watchpoint. We'll be back to display
4048 if (stopped_by_watchpoint
4049 && (target_have_steppable_watchpoint
4050 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
4052 /* At this point, we are stopped at an instruction which has
4053 attempted to write to a piece of memory under control of
4054 a watchpoint. The instruction hasn't actually executed
4055 yet. If we were to evaluate the watchpoint expression
4056 now, we would get the old value, and therefore no change
4057 would seem to have occurred.
4059 In order to make watchpoints work `right', we really need
4060 to complete the memory write, and then evaluate the
4061 watchpoint expression. We do this by single-stepping the
4064 It may not be necessary to disable the watchpoint to stop over
4065 it. For example, the PA can (with some kernel cooperation)
4066 single step over a watchpoint without disabling the watchpoint.
4068 It is far more common to need to disable a watchpoint to step
4069 the inferior over it. If we have non-steppable watchpoints,
4070 we must disable the current watchpoint; it's simplest to
4071 disable all watchpoints and breakpoints. */
4074 if (!target_have_steppable_watchpoint)
4076 remove_breakpoints ();
4077 /* See comment in resume why we need to stop bypassing signals
4078 while breakpoints have been removed. */
4079 target_pass_signals (0, NULL);
4082 hw_step = maybe_software_singlestep (gdbarch, stop_pc);
4083 target_resume (ecs->ptid, hw_step, GDB_SIGNAL_0);
4084 waiton_ptid = ecs->ptid;
4085 if (target_have_steppable_watchpoint)
4086 infwait_state = infwait_step_watch_state;
4088 infwait_state = infwait_nonstep_watch_state;
4089 prepare_to_wait (ecs);
4093 clear_stop_func (ecs);
4094 ecs->event_thread->stepping_over_breakpoint = 0;
4095 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
4096 ecs->event_thread->control.stop_step = 0;
4097 stop_print_frame = 1;
4098 ecs->random_signal = 0;
4099 stopped_by_random_signal = 0;
4101 /* Hide inlined functions starting here, unless we just performed stepi or
4102 nexti. After stepi and nexti, always show the innermost frame (not any
4103 inline function call sites). */
4104 if (ecs->event_thread->control.step_range_end != 1)
4106 struct address_space *aspace =
4107 get_regcache_aspace (get_thread_regcache (ecs->ptid));
4109 /* skip_inline_frames is expensive, so we avoid it if we can
4110 determine that the address is one where functions cannot have
4111 been inlined. This improves performance with inferiors that
4112 load a lot of shared libraries, because the solib event
4113 breakpoint is defined as the address of a function (i.e. not
4114 inline). Note that we have to check the previous PC as well
4115 as the current one to catch cases when we have just
4116 single-stepped off a breakpoint prior to reinstating it.
4117 Note that we're assuming that the code we single-step to is
4118 not inline, but that's not definitive: there's nothing
4119 preventing the event breakpoint function from containing
4120 inlined code, and the single-step ending up there. If the
4121 user had set a breakpoint on that inlined code, the missing
4122 skip_inline_frames call would break things. Fortunately
4123 that's an extremely unlikely scenario. */
4124 if (!pc_at_non_inline_function (aspace, stop_pc, &ecs->ws)
4125 && !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4126 && ecs->event_thread->control.trap_expected
4127 && pc_at_non_inline_function (aspace,
4128 ecs->event_thread->prev_pc,
4131 skip_inline_frames (ecs->ptid);
4133 /* Re-fetch current thread's frame in case that invalidated
4135 frame = get_current_frame ();
4136 gdbarch = get_frame_arch (frame);
4140 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4141 && ecs->event_thread->control.trap_expected
4142 && gdbarch_single_step_through_delay_p (gdbarch)
4143 && currently_stepping (ecs->event_thread))
4145 /* We're trying to step off a breakpoint. Turns out that we're
4146 also on an instruction that needs to be stepped multiple
4147 times before it's been fully executing. E.g., architectures
4148 with a delay slot. It needs to be stepped twice, once for
4149 the instruction and once for the delay slot. */
4150 int step_through_delay
4151 = gdbarch_single_step_through_delay (gdbarch, frame);
4153 if (debug_infrun && step_through_delay)
4154 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
4155 if (ecs->event_thread->control.step_range_end == 0
4156 && step_through_delay)
4158 /* The user issued a continue when stopped at a breakpoint.
4159 Set up for another trap and get out of here. */
4160 ecs->event_thread->stepping_over_breakpoint = 1;
4164 else if (step_through_delay)
4166 /* The user issued a step when stopped at a breakpoint.
4167 Maybe we should stop, maybe we should not - the delay
4168 slot *might* correspond to a line of source. In any
4169 case, don't decide that here, just set
4170 ecs->stepping_over_breakpoint, making sure we
4171 single-step again before breakpoints are re-inserted. */
4172 ecs->event_thread->stepping_over_breakpoint = 1;
4176 /* Look at the cause of the stop, and decide what to do.
4177 The alternatives are:
4178 1) stop_stepping and return; to really stop and return to the debugger,
4179 2) keep_going and return to start up again
4180 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
4181 3) set ecs->random_signal to 1, and the decision between 1 and 2
4182 will be made according to the signal handling tables. */
4184 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4188 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
4189 stop_print_frame = 0;
4190 stop_stepping (ecs);
4194 /* This is originated from start_remote(), start_inferior() and
4195 shared libraries hook functions. */
4196 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
4199 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
4200 stop_stepping (ecs);
4204 /* This originates from attach_command(). We need to overwrite
4205 the stop_signal here, because some kernels don't ignore a
4206 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4207 See more comments in inferior.h. On the other hand, if we
4208 get a non-SIGSTOP, report it to the user - assume the backend
4209 will handle the SIGSTOP if it should show up later.
4211 Also consider that the attach is complete when we see a
4212 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4213 target extended-remote report it instead of a SIGSTOP
4214 (e.g. gdbserver). We already rely on SIGTRAP being our
4215 signal, so this is no exception.
4217 Also consider that the attach is complete when we see a
4218 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4219 the target to stop all threads of the inferior, in case the
4220 low level attach operation doesn't stop them implicitly. If
4221 they weren't stopped implicitly, then the stub will report a
4222 GDB_SIGNAL_0, meaning: stopped for no particular reason
4223 other than GDB's request. */
4224 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
4225 && (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_STOP
4226 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4227 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_0))
4229 stop_stepping (ecs);
4230 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4234 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4235 handles this event. */
4236 ecs->event_thread->control.stop_bpstat
4237 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4238 stop_pc, ecs->ptid, &ecs->ws);
4240 /* Following in case break condition called a
4242 stop_print_frame = 1;
4244 /* This is where we handle "moribund" watchpoints. Unlike
4245 software breakpoints traps, hardware watchpoint traps are
4246 always distinguishable from random traps. If no high-level
4247 watchpoint is associated with the reported stop data address
4248 anymore, then the bpstat does not explain the signal ---
4249 simply make sure to ignore it if `stopped_by_watchpoint' is
4253 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4254 && (bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4256 == BPSTAT_SIGNAL_NO)
4257 && stopped_by_watchpoint)
4258 fprintf_unfiltered (gdb_stdlog,
4259 "infrun: no user watchpoint explains "
4260 "watchpoint SIGTRAP, ignoring\n");
4262 /* NOTE: cagney/2003-03-29: These two checks for a random signal
4263 at one stage in the past included checks for an inferior
4264 function call's call dummy's return breakpoint. The original
4265 comment, that went with the test, read:
4267 ``End of a stack dummy. Some systems (e.g. Sony news) give
4268 another signal besides SIGTRAP, so check here as well as
4271 If someone ever tries to get call dummys on a
4272 non-executable stack to work (where the target would stop
4273 with something like a SIGSEGV), then those tests might need
4274 to be re-instated. Given, however, that the tests were only
4275 enabled when momentary breakpoints were not being used, I
4276 suspect that it won't be the case.
4278 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4279 be necessary for call dummies on a non-executable stack on
4282 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
4284 = !((bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4286 != BPSTAT_SIGNAL_NO)
4287 || stopped_by_watchpoint
4288 || ecs->event_thread->control.trap_expected
4289 || (ecs->event_thread->control.step_range_end
4290 && (ecs->event_thread->control.step_resume_breakpoint
4294 enum bpstat_signal_value sval;
4296 sval = bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4297 ecs->event_thread->suspend.stop_signal);
4298 ecs->random_signal = (sval == BPSTAT_SIGNAL_NO);
4300 if (sval == BPSTAT_SIGNAL_HIDE)
4301 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP;
4304 process_event_stop_test:
4306 /* Re-fetch current thread's frame in case we did a
4307 "goto process_event_stop_test" above. */
4308 frame = get_current_frame ();
4309 gdbarch = get_frame_arch (frame);
4311 /* For the program's own signals, act according to
4312 the signal handling tables. */
4314 if (ecs->random_signal)
4316 /* Signal not for debugging purposes. */
4318 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
4321 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
4322 ecs->event_thread->suspend.stop_signal);
4324 stopped_by_random_signal = 1;
4326 if (signal_print[ecs->event_thread->suspend.stop_signal])
4329 target_terminal_ours_for_output ();
4330 print_signal_received_reason
4331 (ecs->event_thread->suspend.stop_signal);
4333 /* Always stop on signals if we're either just gaining control
4334 of the program, or the user explicitly requested this thread
4335 to remain stopped. */
4336 if (stop_soon != NO_STOP_QUIETLY
4337 || ecs->event_thread->stop_requested
4339 && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
4341 stop_stepping (ecs);
4344 /* If not going to stop, give terminal back
4345 if we took it away. */
4347 target_terminal_inferior ();
4349 /* Clear the signal if it should not be passed. */
4350 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
4351 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4353 if (ecs->event_thread->prev_pc == stop_pc
4354 && ecs->event_thread->control.trap_expected
4355 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4357 /* We were just starting a new sequence, attempting to
4358 single-step off of a breakpoint and expecting a SIGTRAP.
4359 Instead this signal arrives. This signal will take us out
4360 of the stepping range so GDB needs to remember to, when
4361 the signal handler returns, resume stepping off that
4363 /* To simplify things, "continue" is forced to use the same
4364 code paths as single-step - set a breakpoint at the
4365 signal return address and then, once hit, step off that
4368 fprintf_unfiltered (gdb_stdlog,
4369 "infrun: signal arrived while stepping over "
4372 insert_hp_step_resume_breakpoint_at_frame (frame);
4373 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4374 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4375 ecs->event_thread->control.trap_expected = 0;
4380 if (ecs->event_thread->control.step_range_end != 0
4381 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_0
4382 && pc_in_thread_step_range (stop_pc, ecs->event_thread)
4383 && frame_id_eq (get_stack_frame_id (frame),
4384 ecs->event_thread->control.step_stack_frame_id)
4385 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4387 /* The inferior is about to take a signal that will take it
4388 out of the single step range. Set a breakpoint at the
4389 current PC (which is presumably where the signal handler
4390 will eventually return) and then allow the inferior to
4393 Note that this is only needed for a signal delivered
4394 while in the single-step range. Nested signals aren't a
4395 problem as they eventually all return. */
4397 fprintf_unfiltered (gdb_stdlog,
4398 "infrun: signal may take us out of "
4399 "single-step range\n");
4401 insert_hp_step_resume_breakpoint_at_frame (frame);
4402 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4403 ecs->event_thread->control.trap_expected = 0;
4408 /* Note: step_resume_breakpoint may be non-NULL. This occures
4409 when either there's a nested signal, or when there's a
4410 pending signal enabled just as the signal handler returns
4411 (leaving the inferior at the step-resume-breakpoint without
4412 actually executing it). Either way continue until the
4413 breakpoint is really hit. */
4417 /* Handle cases caused by hitting a breakpoint. */
4419 CORE_ADDR jmp_buf_pc;
4420 struct bpstat_what what;
4422 what = bpstat_what (ecs->event_thread->control.stop_bpstat);
4424 if (what.call_dummy)
4426 stop_stack_dummy = what.call_dummy;
4429 /* If we hit an internal event that triggers symbol changes, the
4430 current frame will be invalidated within bpstat_what (e.g.,
4431 if we hit an internal solib event). Re-fetch it. */
4432 frame = get_current_frame ();
4433 gdbarch = get_frame_arch (frame);
4435 switch (what.main_action)
4437 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
4438 /* If we hit the breakpoint at longjmp while stepping, we
4439 install a momentary breakpoint at the target of the
4443 fprintf_unfiltered (gdb_stdlog,
4444 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4446 ecs->event_thread->stepping_over_breakpoint = 1;
4448 if (what.is_longjmp)
4450 struct value *arg_value;
4452 /* If we set the longjmp breakpoint via a SystemTap
4453 probe, then use it to extract the arguments. The
4454 destination PC is the third argument to the
4456 arg_value = probe_safe_evaluate_at_pc (frame, 2);
4458 jmp_buf_pc = value_as_address (arg_value);
4459 else if (!gdbarch_get_longjmp_target_p (gdbarch)
4460 || !gdbarch_get_longjmp_target (gdbarch,
4461 frame, &jmp_buf_pc))
4464 fprintf_unfiltered (gdb_stdlog,
4465 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4466 "(!gdbarch_get_longjmp_target)\n");
4471 /* Insert a breakpoint at resume address. */
4472 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4475 check_exception_resume (ecs, frame);
4479 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4481 struct frame_info *init_frame;
4483 /* There are several cases to consider.
4485 1. The initiating frame no longer exists. In this case
4486 we must stop, because the exception or longjmp has gone
4489 2. The initiating frame exists, and is the same as the
4490 current frame. We stop, because the exception or
4491 longjmp has been caught.
4493 3. The initiating frame exists and is different from
4494 the current frame. This means the exception or longjmp
4495 has been caught beneath the initiating frame, so keep
4498 4. longjmp breakpoint has been placed just to protect
4499 against stale dummy frames and user is not interested
4500 in stopping around longjmps. */
4503 fprintf_unfiltered (gdb_stdlog,
4504 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4506 gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
4508 delete_exception_resume_breakpoint (ecs->event_thread);
4510 if (what.is_longjmp)
4512 check_longjmp_breakpoint_for_call_dummy (ecs->event_thread->num);
4514 if (!frame_id_p (ecs->event_thread->initiating_frame))
4522 init_frame = frame_find_by_id (ecs->event_thread->initiating_frame);
4526 struct frame_id current_id
4527 = get_frame_id (get_current_frame ());
4528 if (frame_id_eq (current_id,
4529 ecs->event_thread->initiating_frame))
4531 /* Case 2. Fall through. */
4541 /* For Cases 1 and 2, remove the step-resume breakpoint,
4543 delete_step_resume_breakpoint (ecs->event_thread);
4545 ecs->event_thread->control.stop_step = 1;
4546 print_end_stepping_range_reason ();
4547 stop_stepping (ecs);
4551 case BPSTAT_WHAT_SINGLE:
4553 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
4554 ecs->event_thread->stepping_over_breakpoint = 1;
4555 /* Still need to check other stuff, at least the case where
4556 we are stepping and step out of the right range. */
4559 case BPSTAT_WHAT_STEP_RESUME:
4561 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4563 delete_step_resume_breakpoint (ecs->event_thread);
4564 if (ecs->event_thread->control.proceed_to_finish
4565 && execution_direction == EXEC_REVERSE)
4567 struct thread_info *tp = ecs->event_thread;
4569 /* We are finishing a function in reverse, and just hit
4570 the step-resume breakpoint at the start address of
4571 the function, and we're almost there -- just need to
4572 back up by one more single-step, which should take us
4573 back to the function call. */
4574 tp->control.step_range_start = tp->control.step_range_end = 1;
4578 fill_in_stop_func (gdbarch, ecs);
4579 if (stop_pc == ecs->stop_func_start
4580 && execution_direction == EXEC_REVERSE)
4582 /* We are stepping over a function call in reverse, and
4583 just hit the step-resume breakpoint at the start
4584 address of the function. Go back to single-stepping,
4585 which should take us back to the function call. */
4586 ecs->event_thread->stepping_over_breakpoint = 1;
4592 case BPSTAT_WHAT_STOP_NOISY:
4594 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4595 stop_print_frame = 1;
4597 /* We are about to nuke the step_resume_breakpointt via the
4598 cleanup chain, so no need to worry about it here. */
4600 stop_stepping (ecs);
4603 case BPSTAT_WHAT_STOP_SILENT:
4605 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4606 stop_print_frame = 0;
4608 /* We are about to nuke the step_resume_breakpoin via the
4609 cleanup chain, so no need to worry about it here. */
4611 stop_stepping (ecs);
4614 case BPSTAT_WHAT_HP_STEP_RESUME:
4616 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4618 delete_step_resume_breakpoint (ecs->event_thread);
4619 if (ecs->event_thread->step_after_step_resume_breakpoint)
4621 /* Back when the step-resume breakpoint was inserted, we
4622 were trying to single-step off a breakpoint. Go back
4624 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4625 ecs->event_thread->stepping_over_breakpoint = 1;
4631 case BPSTAT_WHAT_KEEP_CHECKING:
4636 /* We come here if we hit a breakpoint but should not
4637 stop for it. Possibly we also were stepping
4638 and should stop for that. So fall through and
4639 test for stepping. But, if not stepping,
4642 /* In all-stop mode, if we're currently stepping but have stopped in
4643 some other thread, we need to switch back to the stepped thread. */
4646 struct thread_info *tp;
4648 tp = iterate_over_threads (currently_stepping_or_nexting_callback,
4652 /* However, if the current thread is blocked on some internal
4653 breakpoint, and we simply need to step over that breakpoint
4654 to get it going again, do that first. */
4655 if ((ecs->event_thread->control.trap_expected
4656 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
4657 || ecs->event_thread->stepping_over_breakpoint)
4663 /* If the stepping thread exited, then don't try to switch
4664 back and resume it, which could fail in several different
4665 ways depending on the target. Instead, just keep going.
4667 We can find a stepping dead thread in the thread list in
4670 - The target supports thread exit events, and when the
4671 target tries to delete the thread from the thread list,
4672 inferior_ptid pointed at the exiting thread. In such
4673 case, calling delete_thread does not really remove the
4674 thread from the list; instead, the thread is left listed,
4675 with 'exited' state.
4677 - The target's debug interface does not support thread
4678 exit events, and so we have no idea whatsoever if the
4679 previously stepping thread is still alive. For that
4680 reason, we need to synchronously query the target
4682 if (is_exited (tp->ptid)
4683 || !target_thread_alive (tp->ptid))
4686 fprintf_unfiltered (gdb_stdlog,
4687 "infrun: not switching back to "
4688 "stepped thread, it has vanished\n");
4690 delete_thread (tp->ptid);
4695 /* Otherwise, we no longer expect a trap in the current thread.
4696 Clear the trap_expected flag before switching back -- this is
4697 what keep_going would do as well, if we called it. */
4698 ecs->event_thread->control.trap_expected = 0;
4701 fprintf_unfiltered (gdb_stdlog,
4702 "infrun: switching back to stepped thread\n");
4704 ecs->event_thread = tp;
4705 ecs->ptid = tp->ptid;
4706 context_switch (ecs->ptid);
4712 if (ecs->event_thread->control.step_resume_breakpoint)
4715 fprintf_unfiltered (gdb_stdlog,
4716 "infrun: step-resume breakpoint is inserted\n");
4718 /* Having a step-resume breakpoint overrides anything
4719 else having to do with stepping commands until
4720 that breakpoint is reached. */
4725 if (ecs->event_thread->control.step_range_end == 0)
4728 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
4729 /* Likewise if we aren't even stepping. */
4734 /* Re-fetch current thread's frame in case the code above caused
4735 the frame cache to be re-initialized, making our FRAME variable
4736 a dangling pointer. */
4737 frame = get_current_frame ();
4738 gdbarch = get_frame_arch (frame);
4739 fill_in_stop_func (gdbarch, ecs);
4741 /* If stepping through a line, keep going if still within it.
4743 Note that step_range_end is the address of the first instruction
4744 beyond the step range, and NOT the address of the last instruction
4747 Note also that during reverse execution, we may be stepping
4748 through a function epilogue and therefore must detect when
4749 the current-frame changes in the middle of a line. */
4751 if (pc_in_thread_step_range (stop_pc, ecs->event_thread)
4752 && (execution_direction != EXEC_REVERSE
4753 || frame_id_eq (get_frame_id (frame),
4754 ecs->event_thread->control.step_frame_id)))
4758 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
4759 paddress (gdbarch, ecs->event_thread->control.step_range_start),
4760 paddress (gdbarch, ecs->event_thread->control.step_range_end));
4762 /* Tentatively re-enable range stepping; `resume' disables it if
4763 necessary (e.g., if we're stepping over a breakpoint or we
4764 have software watchpoints). */
4765 ecs->event_thread->control.may_range_step = 1;
4767 /* When stepping backward, stop at beginning of line range
4768 (unless it's the function entry point, in which case
4769 keep going back to the call point). */
4770 if (stop_pc == ecs->event_thread->control.step_range_start
4771 && stop_pc != ecs->stop_func_start
4772 && execution_direction == EXEC_REVERSE)
4774 ecs->event_thread->control.stop_step = 1;
4775 print_end_stepping_range_reason ();
4776 stop_stepping (ecs);
4784 /* We stepped out of the stepping range. */
4786 /* If we are stepping at the source level and entered the runtime
4787 loader dynamic symbol resolution code...
4789 EXEC_FORWARD: we keep on single stepping until we exit the run
4790 time loader code and reach the callee's address.
4792 EXEC_REVERSE: we've already executed the callee (backward), and
4793 the runtime loader code is handled just like any other
4794 undebuggable function call. Now we need only keep stepping
4795 backward through the trampoline code, and that's handled further
4796 down, so there is nothing for us to do here. */
4798 if (execution_direction != EXEC_REVERSE
4799 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4800 && in_solib_dynsym_resolve_code (stop_pc))
4802 CORE_ADDR pc_after_resolver =
4803 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
4806 fprintf_unfiltered (gdb_stdlog,
4807 "infrun: stepped into dynsym resolve code\n");
4809 if (pc_after_resolver)
4811 /* Set up a step-resume breakpoint at the address
4812 indicated by SKIP_SOLIB_RESOLVER. */
4813 struct symtab_and_line sr_sal;
4816 sr_sal.pc = pc_after_resolver;
4817 sr_sal.pspace = get_frame_program_space (frame);
4819 insert_step_resume_breakpoint_at_sal (gdbarch,
4820 sr_sal, null_frame_id);
4827 if (ecs->event_thread->control.step_range_end != 1
4828 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4829 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4830 && get_frame_type (frame) == SIGTRAMP_FRAME)
4833 fprintf_unfiltered (gdb_stdlog,
4834 "infrun: stepped into signal trampoline\n");
4835 /* The inferior, while doing a "step" or "next", has ended up in
4836 a signal trampoline (either by a signal being delivered or by
4837 the signal handler returning). Just single-step until the
4838 inferior leaves the trampoline (either by calling the handler
4844 /* If we're in the return path from a shared library trampoline,
4845 we want to proceed through the trampoline when stepping. */
4846 /* macro/2012-04-25: This needs to come before the subroutine
4847 call check below as on some targets return trampolines look
4848 like subroutine calls (MIPS16 return thunks). */
4849 if (gdbarch_in_solib_return_trampoline (gdbarch,
4850 stop_pc, ecs->stop_func_name)
4851 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
4853 /* Determine where this trampoline returns. */
4854 CORE_ADDR real_stop_pc;
4856 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4859 fprintf_unfiltered (gdb_stdlog,
4860 "infrun: stepped into solib return tramp\n");
4862 /* Only proceed through if we know where it's going. */
4865 /* And put the step-breakpoint there and go until there. */
4866 struct symtab_and_line sr_sal;
4868 init_sal (&sr_sal); /* initialize to zeroes */
4869 sr_sal.pc = real_stop_pc;
4870 sr_sal.section = find_pc_overlay (sr_sal.pc);
4871 sr_sal.pspace = get_frame_program_space (frame);
4873 /* Do not specify what the fp should be when we stop since
4874 on some machines the prologue is where the new fp value
4876 insert_step_resume_breakpoint_at_sal (gdbarch,
4877 sr_sal, null_frame_id);
4879 /* Restart without fiddling with the step ranges or
4886 /* Check for subroutine calls. The check for the current frame
4887 equalling the step ID is not necessary - the check of the
4888 previous frame's ID is sufficient - but it is a common case and
4889 cheaper than checking the previous frame's ID.
4891 NOTE: frame_id_eq will never report two invalid frame IDs as
4892 being equal, so to get into this block, both the current and
4893 previous frame must have valid frame IDs. */
4894 /* The outer_frame_id check is a heuristic to detect stepping
4895 through startup code. If we step over an instruction which
4896 sets the stack pointer from an invalid value to a valid value,
4897 we may detect that as a subroutine call from the mythical
4898 "outermost" function. This could be fixed by marking
4899 outermost frames as !stack_p,code_p,special_p. Then the
4900 initial outermost frame, before sp was valid, would
4901 have code_addr == &_start. See the comment in frame_id_eq
4903 if (!frame_id_eq (get_stack_frame_id (frame),
4904 ecs->event_thread->control.step_stack_frame_id)
4905 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4906 ecs->event_thread->control.step_stack_frame_id)
4907 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
4909 || step_start_function != find_pc_function (stop_pc))))
4911 CORE_ADDR real_stop_pc;
4914 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
4916 if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
4917 || ((ecs->event_thread->control.step_range_end == 1)
4918 && in_prologue (gdbarch, ecs->event_thread->prev_pc,
4919 ecs->stop_func_start)))
4921 /* I presume that step_over_calls is only 0 when we're
4922 supposed to be stepping at the assembly language level
4923 ("stepi"). Just stop. */
4924 /* Also, maybe we just did a "nexti" inside a prolog, so we
4925 thought it was a subroutine call but it was not. Stop as
4927 /* And this works the same backward as frontward. MVS */
4928 ecs->event_thread->control.stop_step = 1;
4929 print_end_stepping_range_reason ();
4930 stop_stepping (ecs);
4934 /* Reverse stepping through solib trampolines. */
4936 if (execution_direction == EXEC_REVERSE
4937 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
4938 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4939 || (ecs->stop_func_start == 0
4940 && in_solib_dynsym_resolve_code (stop_pc))))
4942 /* Any solib trampoline code can be handled in reverse
4943 by simply continuing to single-step. We have already
4944 executed the solib function (backwards), and a few
4945 steps will take us back through the trampoline to the
4951 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4953 /* We're doing a "next".
4955 Normal (forward) execution: set a breakpoint at the
4956 callee's return address (the address at which the caller
4959 Reverse (backward) execution. set the step-resume
4960 breakpoint at the start of the function that we just
4961 stepped into (backwards), and continue to there. When we
4962 get there, we'll need to single-step back to the caller. */
4964 if (execution_direction == EXEC_REVERSE)
4966 /* If we're already at the start of the function, we've either
4967 just stepped backward into a single instruction function,
4968 or stepped back out of a signal handler to the first instruction
4969 of the function. Just keep going, which will single-step back
4971 if (ecs->stop_func_start != stop_pc)
4973 struct symtab_and_line sr_sal;
4975 /* Normal function call return (static or dynamic). */
4977 sr_sal.pc = ecs->stop_func_start;
4978 sr_sal.pspace = get_frame_program_space (frame);
4979 insert_step_resume_breakpoint_at_sal (gdbarch,
4980 sr_sal, null_frame_id);
4984 insert_step_resume_breakpoint_at_caller (frame);
4990 /* If we are in a function call trampoline (a stub between the
4991 calling routine and the real function), locate the real
4992 function. That's what tells us (a) whether we want to step
4993 into it at all, and (b) what prologue we want to run to the
4994 end of, if we do step into it. */
4995 real_stop_pc = skip_language_trampoline (frame, stop_pc);
4996 if (real_stop_pc == 0)
4997 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4998 if (real_stop_pc != 0)
4999 ecs->stop_func_start = real_stop_pc;
5001 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
5003 struct symtab_and_line sr_sal;
5006 sr_sal.pc = ecs->stop_func_start;
5007 sr_sal.pspace = get_frame_program_space (frame);
5009 insert_step_resume_breakpoint_at_sal (gdbarch,
5010 sr_sal, null_frame_id);
5015 /* If we have line number information for the function we are
5016 thinking of stepping into and the function isn't on the skip
5019 If there are several symtabs at that PC (e.g. with include
5020 files), just want to know whether *any* of them have line
5021 numbers. find_pc_line handles this. */
5023 struct symtab_and_line tmp_sal;
5025 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
5026 if (tmp_sal.line != 0
5027 && !function_name_is_marked_for_skip (ecs->stop_func_name,
5030 if (execution_direction == EXEC_REVERSE)
5031 handle_step_into_function_backward (gdbarch, ecs);
5033 handle_step_into_function (gdbarch, ecs);
5038 /* If we have no line number and the step-stop-if-no-debug is
5039 set, we stop the step so that the user has a chance to switch
5040 in assembly mode. */
5041 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5042 && step_stop_if_no_debug)
5044 ecs->event_thread->control.stop_step = 1;
5045 print_end_stepping_range_reason ();
5046 stop_stepping (ecs);
5050 if (execution_direction == EXEC_REVERSE)
5052 /* If we're already at the start of the function, we've either just
5053 stepped backward into a single instruction function without line
5054 number info, or stepped back out of a signal handler to the first
5055 instruction of the function without line number info. Just keep
5056 going, which will single-step back to the caller. */
5057 if (ecs->stop_func_start != stop_pc)
5059 /* Set a breakpoint at callee's start address.
5060 From there we can step once and be back in the caller. */
5061 struct symtab_and_line sr_sal;
5064 sr_sal.pc = ecs->stop_func_start;
5065 sr_sal.pspace = get_frame_program_space (frame);
5066 insert_step_resume_breakpoint_at_sal (gdbarch,
5067 sr_sal, null_frame_id);
5071 /* Set a breakpoint at callee's return address (the address
5072 at which the caller will resume). */
5073 insert_step_resume_breakpoint_at_caller (frame);
5079 /* Reverse stepping through solib trampolines. */
5081 if (execution_direction == EXEC_REVERSE
5082 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
5084 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
5085 || (ecs->stop_func_start == 0
5086 && in_solib_dynsym_resolve_code (stop_pc)))
5088 /* Any solib trampoline code can be handled in reverse
5089 by simply continuing to single-step. We have already
5090 executed the solib function (backwards), and a few
5091 steps will take us back through the trampoline to the
5096 else if (in_solib_dynsym_resolve_code (stop_pc))
5098 /* Stepped backward into the solib dynsym resolver.
5099 Set a breakpoint at its start and continue, then
5100 one more step will take us out. */
5101 struct symtab_and_line sr_sal;
5104 sr_sal.pc = ecs->stop_func_start;
5105 sr_sal.pspace = get_frame_program_space (frame);
5106 insert_step_resume_breakpoint_at_sal (gdbarch,
5107 sr_sal, null_frame_id);
5113 stop_pc_sal = find_pc_line (stop_pc, 0);
5115 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5116 the trampoline processing logic, however, there are some trampolines
5117 that have no names, so we should do trampoline handling first. */
5118 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5119 && ecs->stop_func_name == NULL
5120 && stop_pc_sal.line == 0)
5123 fprintf_unfiltered (gdb_stdlog,
5124 "infrun: stepped into undebuggable function\n");
5126 /* The inferior just stepped into, or returned to, an
5127 undebuggable function (where there is no debugging information
5128 and no line number corresponding to the address where the
5129 inferior stopped). Since we want to skip this kind of code,
5130 we keep going until the inferior returns from this
5131 function - unless the user has asked us not to (via
5132 set step-mode) or we no longer know how to get back
5133 to the call site. */
5134 if (step_stop_if_no_debug
5135 || !frame_id_p (frame_unwind_caller_id (frame)))
5137 /* If we have no line number and the step-stop-if-no-debug
5138 is set, we stop the step so that the user has a chance to
5139 switch in assembly mode. */
5140 ecs->event_thread->control.stop_step = 1;
5141 print_end_stepping_range_reason ();
5142 stop_stepping (ecs);
5147 /* Set a breakpoint at callee's return address (the address
5148 at which the caller will resume). */
5149 insert_step_resume_breakpoint_at_caller (frame);
5155 if (ecs->event_thread->control.step_range_end == 1)
5157 /* It is stepi or nexti. We always want to stop stepping after
5160 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
5161 ecs->event_thread->control.stop_step = 1;
5162 print_end_stepping_range_reason ();
5163 stop_stepping (ecs);
5167 if (stop_pc_sal.line == 0)
5169 /* We have no line number information. That means to stop
5170 stepping (does this always happen right after one instruction,
5171 when we do "s" in a function with no line numbers,
5172 or can this happen as a result of a return or longjmp?). */
5174 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
5175 ecs->event_thread->control.stop_step = 1;
5176 print_end_stepping_range_reason ();
5177 stop_stepping (ecs);
5181 /* Look for "calls" to inlined functions, part one. If the inline
5182 frame machinery detected some skipped call sites, we have entered
5183 a new inline function. */
5185 if (frame_id_eq (get_frame_id (get_current_frame ()),
5186 ecs->event_thread->control.step_frame_id)
5187 && inline_skipped_frames (ecs->ptid))
5189 struct symtab_and_line call_sal;
5192 fprintf_unfiltered (gdb_stdlog,
5193 "infrun: stepped into inlined function\n");
5195 find_frame_sal (get_current_frame (), &call_sal);
5197 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
5199 /* For "step", we're going to stop. But if the call site
5200 for this inlined function is on the same source line as
5201 we were previously stepping, go down into the function
5202 first. Otherwise stop at the call site. */
5204 if (call_sal.line == ecs->event_thread->current_line
5205 && call_sal.symtab == ecs->event_thread->current_symtab)
5206 step_into_inline_frame (ecs->ptid);
5208 ecs->event_thread->control.stop_step = 1;
5209 print_end_stepping_range_reason ();
5210 stop_stepping (ecs);
5215 /* For "next", we should stop at the call site if it is on a
5216 different source line. Otherwise continue through the
5217 inlined function. */
5218 if (call_sal.line == ecs->event_thread->current_line
5219 && call_sal.symtab == ecs->event_thread->current_symtab)
5223 ecs->event_thread->control.stop_step = 1;
5224 print_end_stepping_range_reason ();
5225 stop_stepping (ecs);
5231 /* Look for "calls" to inlined functions, part two. If we are still
5232 in the same real function we were stepping through, but we have
5233 to go further up to find the exact frame ID, we are stepping
5234 through a more inlined call beyond its call site. */
5236 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5237 && !frame_id_eq (get_frame_id (get_current_frame ()),
5238 ecs->event_thread->control.step_frame_id)
5239 && stepped_in_from (get_current_frame (),
5240 ecs->event_thread->control.step_frame_id))
5243 fprintf_unfiltered (gdb_stdlog,
5244 "infrun: stepping through inlined function\n");
5246 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5250 ecs->event_thread->control.stop_step = 1;
5251 print_end_stepping_range_reason ();
5252 stop_stepping (ecs);
5257 if ((stop_pc == stop_pc_sal.pc)
5258 && (ecs->event_thread->current_line != stop_pc_sal.line
5259 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
5261 /* We are at the start of a different line. So stop. Note that
5262 we don't stop if we step into the middle of a different line.
5263 That is said to make things like for (;;) statements work
5266 fprintf_unfiltered (gdb_stdlog,
5267 "infrun: stepped to a different line\n");
5268 ecs->event_thread->control.stop_step = 1;
5269 print_end_stepping_range_reason ();
5270 stop_stepping (ecs);
5274 /* We aren't done stepping.
5276 Optimize by setting the stepping range to the line.
5277 (We might not be in the original line, but if we entered a
5278 new line in mid-statement, we continue stepping. This makes
5279 things like for(;;) statements work better.) */
5281 ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
5282 ecs->event_thread->control.step_range_end = stop_pc_sal.end;
5283 ecs->event_thread->control.may_range_step = 1;
5284 set_step_info (frame, stop_pc_sal);
5287 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
5291 /* Is thread TP in the middle of single-stepping? */
5294 currently_stepping (struct thread_info *tp)
5296 return ((tp->control.step_range_end
5297 && tp->control.step_resume_breakpoint == NULL)
5298 || tp->control.trap_expected
5299 || bpstat_should_step ());
5302 /* Returns true if any thread *but* the one passed in "data" is in the
5303 middle of stepping or of handling a "next". */
5306 currently_stepping_or_nexting_callback (struct thread_info *tp, void *data)
5311 return (tp->control.step_range_end
5312 || tp->control.trap_expected);
5315 /* Inferior has stepped into a subroutine call with source code that
5316 we should not step over. Do step to the first line of code in
5320 handle_step_into_function (struct gdbarch *gdbarch,
5321 struct execution_control_state *ecs)
5324 struct symtab_and_line stop_func_sal, sr_sal;
5326 fill_in_stop_func (gdbarch, ecs);
5328 s = find_pc_symtab (stop_pc);
5329 if (s && s->language != language_asm)
5330 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5331 ecs->stop_func_start);
5333 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
5334 /* Use the step_resume_break to step until the end of the prologue,
5335 even if that involves jumps (as it seems to on the vax under
5337 /* If the prologue ends in the middle of a source line, continue to
5338 the end of that source line (if it is still within the function).
5339 Otherwise, just go to end of prologue. */
5340 if (stop_func_sal.end
5341 && stop_func_sal.pc != ecs->stop_func_start
5342 && stop_func_sal.end < ecs->stop_func_end)
5343 ecs->stop_func_start = stop_func_sal.end;
5345 /* Architectures which require breakpoint adjustment might not be able
5346 to place a breakpoint at the computed address. If so, the test
5347 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5348 ecs->stop_func_start to an address at which a breakpoint may be
5349 legitimately placed.
5351 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5352 made, GDB will enter an infinite loop when stepping through
5353 optimized code consisting of VLIW instructions which contain
5354 subinstructions corresponding to different source lines. On
5355 FR-V, it's not permitted to place a breakpoint on any but the
5356 first subinstruction of a VLIW instruction. When a breakpoint is
5357 set, GDB will adjust the breakpoint address to the beginning of
5358 the VLIW instruction. Thus, we need to make the corresponding
5359 adjustment here when computing the stop address. */
5361 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
5363 ecs->stop_func_start
5364 = gdbarch_adjust_breakpoint_address (gdbarch,
5365 ecs->stop_func_start);
5368 if (ecs->stop_func_start == stop_pc)
5370 /* We are already there: stop now. */
5371 ecs->event_thread->control.stop_step = 1;
5372 print_end_stepping_range_reason ();
5373 stop_stepping (ecs);
5378 /* Put the step-breakpoint there and go until there. */
5379 init_sal (&sr_sal); /* initialize to zeroes */
5380 sr_sal.pc = ecs->stop_func_start;
5381 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
5382 sr_sal.pspace = get_frame_program_space (get_current_frame ());
5384 /* Do not specify what the fp should be when we stop since on
5385 some machines the prologue is where the new fp value is
5387 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
5389 /* And make sure stepping stops right away then. */
5390 ecs->event_thread->control.step_range_end
5391 = ecs->event_thread->control.step_range_start;
5396 /* Inferior has stepped backward into a subroutine call with source
5397 code that we should not step over. Do step to the beginning of the
5398 last line of code in it. */
5401 handle_step_into_function_backward (struct gdbarch *gdbarch,
5402 struct execution_control_state *ecs)
5405 struct symtab_and_line stop_func_sal;
5407 fill_in_stop_func (gdbarch, ecs);
5409 s = find_pc_symtab (stop_pc);
5410 if (s && s->language != language_asm)
5411 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5412 ecs->stop_func_start);
5414 stop_func_sal = find_pc_line (stop_pc, 0);
5416 /* OK, we're just going to keep stepping here. */
5417 if (stop_func_sal.pc == stop_pc)
5419 /* We're there already. Just stop stepping now. */
5420 ecs->event_thread->control.stop_step = 1;
5421 print_end_stepping_range_reason ();
5422 stop_stepping (ecs);
5426 /* Else just reset the step range and keep going.
5427 No step-resume breakpoint, they don't work for
5428 epilogues, which can have multiple entry paths. */
5429 ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5430 ecs->event_thread->control.step_range_end = stop_func_sal.end;
5436 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5437 This is used to both functions and to skip over code. */
5440 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch *gdbarch,
5441 struct symtab_and_line sr_sal,
5442 struct frame_id sr_id,
5443 enum bptype sr_type)
5445 /* There should never be more than one step-resume or longjmp-resume
5446 breakpoint per thread, so we should never be setting a new
5447 step_resume_breakpoint when one is already active. */
5448 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5449 gdb_assert (sr_type == bp_step_resume || sr_type == bp_hp_step_resume);
5452 fprintf_unfiltered (gdb_stdlog,
5453 "infrun: inserting step-resume breakpoint at %s\n",
5454 paddress (gdbarch, sr_sal.pc));
5456 inferior_thread ()->control.step_resume_breakpoint
5457 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type);
5461 insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5462 struct symtab_and_line sr_sal,
5463 struct frame_id sr_id)
5465 insert_step_resume_breakpoint_at_sal_1 (gdbarch,
5470 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5471 This is used to skip a potential signal handler.
5473 This is called with the interrupted function's frame. The signal
5474 handler, when it returns, will resume the interrupted function at
5478 insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
5480 struct symtab_and_line sr_sal;
5481 struct gdbarch *gdbarch;
5483 gdb_assert (return_frame != NULL);
5484 init_sal (&sr_sal); /* initialize to zeros */
5486 gdbarch = get_frame_arch (return_frame);
5487 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
5488 sr_sal.section = find_pc_overlay (sr_sal.pc);
5489 sr_sal.pspace = get_frame_program_space (return_frame);
5491 insert_step_resume_breakpoint_at_sal_1 (gdbarch, sr_sal,
5492 get_stack_frame_id (return_frame),
5496 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5497 is used to skip a function after stepping into it (for "next" or if
5498 the called function has no debugging information).
5500 The current function has almost always been reached by single
5501 stepping a call or return instruction. NEXT_FRAME belongs to the
5502 current function, and the breakpoint will be set at the caller's
5505 This is a separate function rather than reusing
5506 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5507 get_prev_frame, which may stop prematurely (see the implementation
5508 of frame_unwind_caller_id for an example). */
5511 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
5513 struct symtab_and_line sr_sal;
5514 struct gdbarch *gdbarch;
5516 /* We shouldn't have gotten here if we don't know where the call site
5518 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
5520 init_sal (&sr_sal); /* initialize to zeros */
5522 gdbarch = frame_unwind_caller_arch (next_frame);
5523 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
5524 frame_unwind_caller_pc (next_frame));
5525 sr_sal.section = find_pc_overlay (sr_sal.pc);
5526 sr_sal.pspace = frame_unwind_program_space (next_frame);
5528 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5529 frame_unwind_caller_id (next_frame));
5532 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5533 new breakpoint at the target of a jmp_buf. The handling of
5534 longjmp-resume uses the same mechanisms used for handling
5535 "step-resume" breakpoints. */
5538 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
5540 /* There should never be more than one longjmp-resume breakpoint per
5541 thread, so we should never be setting a new
5542 longjmp_resume_breakpoint when one is already active. */
5543 gdb_assert (inferior_thread ()->control.exception_resume_breakpoint == NULL);
5546 fprintf_unfiltered (gdb_stdlog,
5547 "infrun: inserting longjmp-resume breakpoint at %s\n",
5548 paddress (gdbarch, pc));
5550 inferior_thread ()->control.exception_resume_breakpoint =
5551 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
5554 /* Insert an exception resume breakpoint. TP is the thread throwing
5555 the exception. The block B is the block of the unwinder debug hook
5556 function. FRAME is the frame corresponding to the call to this
5557 function. SYM is the symbol of the function argument holding the
5558 target PC of the exception. */
5561 insert_exception_resume_breakpoint (struct thread_info *tp,
5563 struct frame_info *frame,
5566 volatile struct gdb_exception e;
5568 /* We want to ignore errors here. */
5569 TRY_CATCH (e, RETURN_MASK_ERROR)
5571 struct symbol *vsym;
5572 struct value *value;
5574 struct breakpoint *bp;
5576 vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
5577 value = read_var_value (vsym, frame);
5578 /* If the value was optimized out, revert to the old behavior. */
5579 if (! value_optimized_out (value))
5581 handler = value_as_address (value);
5584 fprintf_unfiltered (gdb_stdlog,
5585 "infrun: exception resume at %lx\n",
5586 (unsigned long) handler);
5588 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5589 handler, bp_exception_resume);
5591 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5594 bp->thread = tp->num;
5595 inferior_thread ()->control.exception_resume_breakpoint = bp;
5600 /* A helper for check_exception_resume that sets an
5601 exception-breakpoint based on a SystemTap probe. */
5604 insert_exception_resume_from_probe (struct thread_info *tp,
5605 const struct probe *probe,
5606 struct frame_info *frame)
5608 struct value *arg_value;
5610 struct breakpoint *bp;
5612 arg_value = probe_safe_evaluate_at_pc (frame, 1);
5616 handler = value_as_address (arg_value);
5619 fprintf_unfiltered (gdb_stdlog,
5620 "infrun: exception resume at %s\n",
5621 paddress (get_objfile_arch (probe->objfile),
5624 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5625 handler, bp_exception_resume);
5626 bp->thread = tp->num;
5627 inferior_thread ()->control.exception_resume_breakpoint = bp;
5630 /* This is called when an exception has been intercepted. Check to
5631 see whether the exception's destination is of interest, and if so,
5632 set an exception resume breakpoint there. */
5635 check_exception_resume (struct execution_control_state *ecs,
5636 struct frame_info *frame)
5638 volatile struct gdb_exception e;
5639 const struct probe *probe;
5640 struct symbol *func;
5642 /* First see if this exception unwinding breakpoint was set via a
5643 SystemTap probe point. If so, the probe has two arguments: the
5644 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5645 set a breakpoint there. */
5646 probe = find_probe_by_pc (get_frame_pc (frame));
5649 insert_exception_resume_from_probe (ecs->event_thread, probe, frame);
5653 func = get_frame_function (frame);
5657 TRY_CATCH (e, RETURN_MASK_ERROR)
5660 struct block_iterator iter;
5664 /* The exception breakpoint is a thread-specific breakpoint on
5665 the unwinder's debug hook, declared as:
5667 void _Unwind_DebugHook (void *cfa, void *handler);
5669 The CFA argument indicates the frame to which control is
5670 about to be transferred. HANDLER is the destination PC.
5672 We ignore the CFA and set a temporary breakpoint at HANDLER.
5673 This is not extremely efficient but it avoids issues in gdb
5674 with computing the DWARF CFA, and it also works even in weird
5675 cases such as throwing an exception from inside a signal
5678 b = SYMBOL_BLOCK_VALUE (func);
5679 ALL_BLOCK_SYMBOLS (b, iter, sym)
5681 if (!SYMBOL_IS_ARGUMENT (sym))
5688 insert_exception_resume_breakpoint (ecs->event_thread,
5697 stop_stepping (struct execution_control_state *ecs)
5700 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
5702 /* Let callers know we don't want to wait for the inferior anymore. */
5703 ecs->wait_some_more = 0;
5706 /* This function handles various cases where we need to continue
5707 waiting for the inferior. */
5708 /* (Used to be the keep_going: label in the old wait_for_inferior). */
5711 keep_going (struct execution_control_state *ecs)
5713 /* Make sure normal_stop is called if we get a QUIT handled before
5715 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
5717 /* Save the pc before execution, to compare with pc after stop. */
5718 ecs->event_thread->prev_pc
5719 = regcache_read_pc (get_thread_regcache (ecs->ptid));
5721 /* If we did not do break;, it means we should keep running the
5722 inferior and not return to debugger. */
5724 if (ecs->event_thread->control.trap_expected
5725 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
5727 /* We took a signal (which we are supposed to pass through to
5728 the inferior, else we'd not get here) and we haven't yet
5729 gotten our trap. Simply continue. */
5731 discard_cleanups (old_cleanups);
5732 resume (currently_stepping (ecs->event_thread),
5733 ecs->event_thread->suspend.stop_signal);
5737 /* Either the trap was not expected, but we are continuing
5738 anyway (the user asked that this signal be passed to the
5741 The signal was SIGTRAP, e.g. it was our signal, but we
5742 decided we should resume from it.
5744 We're going to run this baby now!
5746 Note that insert_breakpoints won't try to re-insert
5747 already inserted breakpoints. Therefore, we don't
5748 care if breakpoints were already inserted, or not. */
5750 if (ecs->event_thread->stepping_over_breakpoint)
5752 struct regcache *thread_regcache = get_thread_regcache (ecs->ptid);
5754 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
5755 /* Since we can't do a displaced step, we have to remove
5756 the breakpoint while we step it. To keep things
5757 simple, we remove them all. */
5758 remove_breakpoints ();
5762 volatile struct gdb_exception e;
5764 /* Stop stepping when inserting breakpoints
5766 TRY_CATCH (e, RETURN_MASK_ERROR)
5768 insert_breakpoints ();
5772 exception_print (gdb_stderr, e);
5773 stop_stepping (ecs);
5778 ecs->event_thread->control.trap_expected
5779 = ecs->event_thread->stepping_over_breakpoint;
5781 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5782 specifies that such a signal should be delivered to the
5785 Typically, this would occure when a user is debugging a
5786 target monitor on a simulator: the target monitor sets a
5787 breakpoint; the simulator encounters this break-point and
5788 halts the simulation handing control to GDB; GDB, noteing
5789 that the break-point isn't valid, returns control back to the
5790 simulator; the simulator then delivers the hardware
5791 equivalent of a SIGNAL_TRAP to the program being debugged. */
5793 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
5794 && !signal_program[ecs->event_thread->suspend.stop_signal])
5795 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
5797 discard_cleanups (old_cleanups);
5798 resume (currently_stepping (ecs->event_thread),
5799 ecs->event_thread->suspend.stop_signal);
5802 prepare_to_wait (ecs);
5805 /* This function normally comes after a resume, before
5806 handle_inferior_event exits. It takes care of any last bits of
5807 housekeeping, and sets the all-important wait_some_more flag. */
5810 prepare_to_wait (struct execution_control_state *ecs)
5813 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
5815 /* This is the old end of the while loop. Let everybody know we
5816 want to wait for the inferior some more and get called again
5818 ecs->wait_some_more = 1;
5821 /* Several print_*_reason functions to print why the inferior has stopped.
5822 We always print something when the inferior exits, or receives a signal.
5823 The rest of the cases are dealt with later on in normal_stop and
5824 print_it_typical. Ideally there should be a call to one of these
5825 print_*_reason functions functions from handle_inferior_event each time
5826 stop_stepping is called. */
5828 /* Print why the inferior has stopped.
5829 We are done with a step/next/si/ni command, print why the inferior has
5830 stopped. For now print nothing. Print a message only if not in the middle
5831 of doing a "step n" operation for n > 1. */
5834 print_end_stepping_range_reason (void)
5836 if ((!inferior_thread ()->step_multi
5837 || !inferior_thread ()->control.stop_step)
5838 && ui_out_is_mi_like_p (current_uiout))
5839 ui_out_field_string (current_uiout, "reason",
5840 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
5843 /* The inferior was terminated by a signal, print why it stopped. */
5846 print_signal_exited_reason (enum gdb_signal siggnal)
5848 struct ui_out *uiout = current_uiout;
5850 annotate_signalled ();
5851 if (ui_out_is_mi_like_p (uiout))
5853 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
5854 ui_out_text (uiout, "\nProgram terminated with signal ");
5855 annotate_signal_name ();
5856 ui_out_field_string (uiout, "signal-name",
5857 gdb_signal_to_name (siggnal));
5858 annotate_signal_name_end ();
5859 ui_out_text (uiout, ", ");
5860 annotate_signal_string ();
5861 ui_out_field_string (uiout, "signal-meaning",
5862 gdb_signal_to_string (siggnal));
5863 annotate_signal_string_end ();
5864 ui_out_text (uiout, ".\n");
5865 ui_out_text (uiout, "The program no longer exists.\n");
5868 /* The inferior program is finished, print why it stopped. */
5871 print_exited_reason (int exitstatus)
5873 struct inferior *inf = current_inferior ();
5874 const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid));
5875 struct ui_out *uiout = current_uiout;
5877 annotate_exited (exitstatus);
5880 if (ui_out_is_mi_like_p (uiout))
5881 ui_out_field_string (uiout, "reason",
5882 async_reason_lookup (EXEC_ASYNC_EXITED));
5883 ui_out_text (uiout, "[Inferior ");
5884 ui_out_text (uiout, plongest (inf->num));
5885 ui_out_text (uiout, " (");
5886 ui_out_text (uiout, pidstr);
5887 ui_out_text (uiout, ") exited with code ");
5888 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
5889 ui_out_text (uiout, "]\n");
5893 if (ui_out_is_mi_like_p (uiout))
5895 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
5896 ui_out_text (uiout, "[Inferior ");
5897 ui_out_text (uiout, plongest (inf->num));
5898 ui_out_text (uiout, " (");
5899 ui_out_text (uiout, pidstr);
5900 ui_out_text (uiout, ") exited normally]\n");
5902 /* Support the --return-child-result option. */
5903 return_child_result_value = exitstatus;
5906 /* Signal received, print why the inferior has stopped. The signal table
5907 tells us to print about it. */
5910 print_signal_received_reason (enum gdb_signal siggnal)
5912 struct ui_out *uiout = current_uiout;
5916 if (siggnal == GDB_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
5918 struct thread_info *t = inferior_thread ();
5920 ui_out_text (uiout, "\n[");
5921 ui_out_field_string (uiout, "thread-name",
5922 target_pid_to_str (t->ptid));
5923 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
5924 ui_out_text (uiout, " stopped");
5928 ui_out_text (uiout, "\nProgram received signal ");
5929 annotate_signal_name ();
5930 if (ui_out_is_mi_like_p (uiout))
5932 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
5933 ui_out_field_string (uiout, "signal-name",
5934 gdb_signal_to_name (siggnal));
5935 annotate_signal_name_end ();
5936 ui_out_text (uiout, ", ");
5937 annotate_signal_string ();
5938 ui_out_field_string (uiout, "signal-meaning",
5939 gdb_signal_to_string (siggnal));
5940 annotate_signal_string_end ();
5942 ui_out_text (uiout, ".\n");
5945 /* Reverse execution: target ran out of history info, print why the inferior
5949 print_no_history_reason (void)
5951 ui_out_text (current_uiout, "\nNo more reverse-execution history.\n");
5954 /* Here to return control to GDB when the inferior stops for real.
5955 Print appropriate messages, remove breakpoints, give terminal our modes.
5957 STOP_PRINT_FRAME nonzero means print the executing frame
5958 (pc, function, args, file, line number and line text).
5959 BREAKPOINTS_FAILED nonzero means stop was due to error
5960 attempting to insert breakpoints. */
5965 struct target_waitstatus last;
5967 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
5969 get_last_target_status (&last_ptid, &last);
5971 /* If an exception is thrown from this point on, make sure to
5972 propagate GDB's knowledge of the executing state to the
5973 frontend/user running state. A QUIT is an easy exception to see
5974 here, so do this before any filtered output. */
5976 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
5977 else if (last.kind != TARGET_WAITKIND_SIGNALLED
5978 && last.kind != TARGET_WAITKIND_EXITED
5979 && last.kind != TARGET_WAITKIND_NO_RESUMED)
5980 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
5982 /* In non-stop mode, we don't want GDB to switch threads behind the
5983 user's back, to avoid races where the user is typing a command to
5984 apply to thread x, but GDB switches to thread y before the user
5985 finishes entering the command. */
5987 /* As with the notification of thread events, we want to delay
5988 notifying the user that we've switched thread context until
5989 the inferior actually stops.
5991 There's no point in saying anything if the inferior has exited.
5992 Note that SIGNALLED here means "exited with a signal", not
5993 "received a signal". */
5995 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
5996 && target_has_execution
5997 && last.kind != TARGET_WAITKIND_SIGNALLED
5998 && last.kind != TARGET_WAITKIND_EXITED
5999 && last.kind != TARGET_WAITKIND_NO_RESUMED)
6001 target_terminal_ours_for_output ();
6002 printf_filtered (_("[Switching to %s]\n"),
6003 target_pid_to_str (inferior_ptid));
6004 annotate_thread_changed ();
6005 previous_inferior_ptid = inferior_ptid;
6008 if (last.kind == TARGET_WAITKIND_NO_RESUMED)
6010 gdb_assert (sync_execution || !target_can_async_p ());
6012 target_terminal_ours_for_output ();
6013 printf_filtered (_("No unwaited-for children left.\n"));
6016 if (!breakpoints_always_inserted_mode () && target_has_execution)
6018 if (remove_breakpoints ())
6020 target_terminal_ours_for_output ();
6021 printf_filtered (_("Cannot remove breakpoints because "
6022 "program is no longer writable.\nFurther "
6023 "execution is probably impossible.\n"));
6027 /* If an auto-display called a function and that got a signal,
6028 delete that auto-display to avoid an infinite recursion. */
6030 if (stopped_by_random_signal)
6031 disable_current_display ();
6033 /* Don't print a message if in the middle of doing a "step n"
6034 operation for n > 1 */
6035 if (target_has_execution
6036 && last.kind != TARGET_WAITKIND_SIGNALLED
6037 && last.kind != TARGET_WAITKIND_EXITED
6038 && inferior_thread ()->step_multi
6039 && inferior_thread ()->control.stop_step)
6042 target_terminal_ours ();
6043 async_enable_stdin ();
6045 /* Set the current source location. This will also happen if we
6046 display the frame below, but the current SAL will be incorrect
6047 during a user hook-stop function. */
6048 if (has_stack_frames () && !stop_stack_dummy)
6049 set_current_sal_from_frame (get_current_frame (), 1);
6051 /* Let the user/frontend see the threads as stopped. */
6052 do_cleanups (old_chain);
6054 /* Look up the hook_stop and run it (CLI internally handles problem
6055 of stop_command's pre-hook not existing). */
6057 catch_errors (hook_stop_stub, stop_command,
6058 "Error while running hook_stop:\n", RETURN_MASK_ALL);
6060 if (!has_stack_frames ())
6063 if (last.kind == TARGET_WAITKIND_SIGNALLED
6064 || last.kind == TARGET_WAITKIND_EXITED)
6067 /* Select innermost stack frame - i.e., current frame is frame 0,
6068 and current location is based on that.
6069 Don't do this on return from a stack dummy routine,
6070 or if the program has exited. */
6072 if (!stop_stack_dummy)
6074 select_frame (get_current_frame ());
6076 /* Print current location without a level number, if
6077 we have changed functions or hit a breakpoint.
6078 Print source line if we have one.
6079 bpstat_print() contains the logic deciding in detail
6080 what to print, based on the event(s) that just occurred. */
6082 /* If --batch-silent is enabled then there's no need to print the current
6083 source location, and to try risks causing an error message about
6084 missing source files. */
6085 if (stop_print_frame && !batch_silent)
6089 int do_frame_printing = 1;
6090 struct thread_info *tp = inferior_thread ();
6092 bpstat_ret = bpstat_print (tp->control.stop_bpstat, last.kind);
6096 /* FIXME: cagney/2002-12-01: Given that a frame ID does
6097 (or should) carry around the function and does (or
6098 should) use that when doing a frame comparison. */
6099 if (tp->control.stop_step
6100 && frame_id_eq (tp->control.step_frame_id,
6101 get_frame_id (get_current_frame ()))
6102 && step_start_function == find_pc_function (stop_pc))
6103 source_flag = SRC_LINE; /* Finished step, just
6104 print source line. */
6106 source_flag = SRC_AND_LOC; /* Print location and
6109 case PRINT_SRC_AND_LOC:
6110 source_flag = SRC_AND_LOC; /* Print location and
6113 case PRINT_SRC_ONLY:
6114 source_flag = SRC_LINE;
6117 source_flag = SRC_LINE; /* something bogus */
6118 do_frame_printing = 0;
6121 internal_error (__FILE__, __LINE__, _("Unknown value."));
6124 /* The behavior of this routine with respect to the source
6126 SRC_LINE: Print only source line
6127 LOCATION: Print only location
6128 SRC_AND_LOC: Print location and source line. */
6129 if (do_frame_printing)
6130 print_stack_frame (get_selected_frame (NULL), 0, source_flag);
6132 /* Display the auto-display expressions. */
6137 /* Save the function value return registers, if we care.
6138 We might be about to restore their previous contents. */
6139 if (inferior_thread ()->control.proceed_to_finish
6140 && execution_direction != EXEC_REVERSE)
6142 /* This should not be necessary. */
6144 regcache_xfree (stop_registers);
6146 /* NB: The copy goes through to the target picking up the value of
6147 all the registers. */
6148 stop_registers = regcache_dup (get_current_regcache ());
6151 if (stop_stack_dummy == STOP_STACK_DUMMY)
6153 /* Pop the empty frame that contains the stack dummy.
6154 This also restores inferior state prior to the call
6155 (struct infcall_suspend_state). */
6156 struct frame_info *frame = get_current_frame ();
6158 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
6160 /* frame_pop() calls reinit_frame_cache as the last thing it
6161 does which means there's currently no selected frame. We
6162 don't need to re-establish a selected frame if the dummy call
6163 returns normally, that will be done by
6164 restore_infcall_control_state. However, we do have to handle
6165 the case where the dummy call is returning after being
6166 stopped (e.g. the dummy call previously hit a breakpoint).
6167 We can't know which case we have so just always re-establish
6168 a selected frame here. */
6169 select_frame (get_current_frame ());
6173 annotate_stopped ();
6175 /* Suppress the stop observer if we're in the middle of:
6177 - a step n (n > 1), as there still more steps to be done.
6179 - a "finish" command, as the observer will be called in
6180 finish_command_continuation, so it can include the inferior
6181 function's return value.
6183 - calling an inferior function, as we pretend we inferior didn't
6184 run at all. The return value of the call is handled by the
6185 expression evaluator, through call_function_by_hand. */
6187 if (!target_has_execution
6188 || last.kind == TARGET_WAITKIND_SIGNALLED
6189 || last.kind == TARGET_WAITKIND_EXITED
6190 || last.kind == TARGET_WAITKIND_NO_RESUMED
6191 || (!(inferior_thread ()->step_multi
6192 && inferior_thread ()->control.stop_step)
6193 && !(inferior_thread ()->control.stop_bpstat
6194 && inferior_thread ()->control.proceed_to_finish)
6195 && !inferior_thread ()->control.in_infcall))
6197 if (!ptid_equal (inferior_ptid, null_ptid))
6198 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
6201 observer_notify_normal_stop (NULL, stop_print_frame);
6204 if (target_has_execution)
6206 if (last.kind != TARGET_WAITKIND_SIGNALLED
6207 && last.kind != TARGET_WAITKIND_EXITED)
6208 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6209 Delete any breakpoint that is to be deleted at the next stop. */
6210 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
6213 /* Try to get rid of automatically added inferiors that are no
6214 longer needed. Keeping those around slows down things linearly.
6215 Note that this never removes the current inferior. */
6220 hook_stop_stub (void *cmd)
6222 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
6227 signal_stop_state (int signo)
6229 return signal_stop[signo];
6233 signal_print_state (int signo)
6235 return signal_print[signo];
6239 signal_pass_state (int signo)
6241 return signal_program[signo];
6245 signal_cache_update (int signo)
6249 for (signo = 0; signo < (int) GDB_SIGNAL_LAST; signo++)
6250 signal_cache_update (signo);
6255 signal_pass[signo] = (signal_stop[signo] == 0
6256 && signal_print[signo] == 0
6257 && signal_program[signo] == 1
6258 && signal_catch[signo] == 0);
6262 signal_stop_update (int signo, int state)
6264 int ret = signal_stop[signo];
6266 signal_stop[signo] = state;
6267 signal_cache_update (signo);
6272 signal_print_update (int signo, int state)
6274 int ret = signal_print[signo];
6276 signal_print[signo] = state;
6277 signal_cache_update (signo);
6282 signal_pass_update (int signo, int state)
6284 int ret = signal_program[signo];
6286 signal_program[signo] = state;
6287 signal_cache_update (signo);
6291 /* Update the global 'signal_catch' from INFO and notify the
6295 signal_catch_update (const unsigned int *info)
6299 for (i = 0; i < GDB_SIGNAL_LAST; ++i)
6300 signal_catch[i] = info[i] > 0;
6301 signal_cache_update (-1);
6302 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
6306 sig_print_header (void)
6308 printf_filtered (_("Signal Stop\tPrint\tPass "
6309 "to program\tDescription\n"));
6313 sig_print_info (enum gdb_signal oursig)
6315 const char *name = gdb_signal_to_name (oursig);
6316 int name_padding = 13 - strlen (name);
6318 if (name_padding <= 0)
6321 printf_filtered ("%s", name);
6322 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
6323 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
6324 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
6325 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
6326 printf_filtered ("%s\n", gdb_signal_to_string (oursig));
6329 /* Specify how various signals in the inferior should be handled. */
6332 handle_command (char *args, int from_tty)
6335 int digits, wordlen;
6336 int sigfirst, signum, siglast;
6337 enum gdb_signal oursig;
6340 unsigned char *sigs;
6341 struct cleanup *old_chain;
6345 error_no_arg (_("signal to handle"));
6348 /* Allocate and zero an array of flags for which signals to handle. */
6350 nsigs = (int) GDB_SIGNAL_LAST;
6351 sigs = (unsigned char *) alloca (nsigs);
6352 memset (sigs, 0, nsigs);
6354 /* Break the command line up into args. */
6356 argv = gdb_buildargv (args);
6357 old_chain = make_cleanup_freeargv (argv);
6359 /* Walk through the args, looking for signal oursigs, signal names, and
6360 actions. Signal numbers and signal names may be interspersed with
6361 actions, with the actions being performed for all signals cumulatively
6362 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6364 while (*argv != NULL)
6366 wordlen = strlen (*argv);
6367 for (digits = 0; isdigit ((*argv)[digits]); digits++)
6371 sigfirst = siglast = -1;
6373 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
6375 /* Apply action to all signals except those used by the
6376 debugger. Silently skip those. */
6379 siglast = nsigs - 1;
6381 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
6383 SET_SIGS (nsigs, sigs, signal_stop);
6384 SET_SIGS (nsigs, sigs, signal_print);
6386 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
6388 UNSET_SIGS (nsigs, sigs, signal_program);
6390 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
6392 SET_SIGS (nsigs, sigs, signal_print);
6394 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
6396 SET_SIGS (nsigs, sigs, signal_program);
6398 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
6400 UNSET_SIGS (nsigs, sigs, signal_stop);
6402 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
6404 SET_SIGS (nsigs, sigs, signal_program);
6406 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
6408 UNSET_SIGS (nsigs, sigs, signal_print);
6409 UNSET_SIGS (nsigs, sigs, signal_stop);
6411 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
6413 UNSET_SIGS (nsigs, sigs, signal_program);
6415 else if (digits > 0)
6417 /* It is numeric. The numeric signal refers to our own
6418 internal signal numbering from target.h, not to host/target
6419 signal number. This is a feature; users really should be
6420 using symbolic names anyway, and the common ones like
6421 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6423 sigfirst = siglast = (int)
6424 gdb_signal_from_command (atoi (*argv));
6425 if ((*argv)[digits] == '-')
6428 gdb_signal_from_command (atoi ((*argv) + digits + 1));
6430 if (sigfirst > siglast)
6432 /* Bet he didn't figure we'd think of this case... */
6440 oursig = gdb_signal_from_name (*argv);
6441 if (oursig != GDB_SIGNAL_UNKNOWN)
6443 sigfirst = siglast = (int) oursig;
6447 /* Not a number and not a recognized flag word => complain. */
6448 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
6452 /* If any signal numbers or symbol names were found, set flags for
6453 which signals to apply actions to. */
6455 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
6457 switch ((enum gdb_signal) signum)
6459 case GDB_SIGNAL_TRAP:
6460 case GDB_SIGNAL_INT:
6461 if (!allsigs && !sigs[signum])
6463 if (query (_("%s is used by the debugger.\n\
6464 Are you sure you want to change it? "),
6465 gdb_signal_to_name ((enum gdb_signal) signum)))
6471 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6472 gdb_flush (gdb_stdout);
6477 case GDB_SIGNAL_DEFAULT:
6478 case GDB_SIGNAL_UNKNOWN:
6479 /* Make sure that "all" doesn't print these. */
6490 for (signum = 0; signum < nsigs; signum++)
6493 signal_cache_update (-1);
6494 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
6495 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
6499 /* Show the results. */
6500 sig_print_header ();
6501 for (; signum < nsigs; signum++)
6503 sig_print_info (signum);
6509 do_cleanups (old_chain);
6512 /* Complete the "handle" command. */
6514 static VEC (char_ptr) *
6515 handle_completer (struct cmd_list_element *ignore,
6516 const char *text, const char *word)
6518 VEC (char_ptr) *vec_signals, *vec_keywords, *return_val;
6519 static const char * const keywords[] =
6533 vec_signals = signal_completer (ignore, text, word);
6534 vec_keywords = complete_on_enum (keywords, word, word);
6536 return_val = VEC_merge (char_ptr, vec_signals, vec_keywords);
6537 VEC_free (char_ptr, vec_signals);
6538 VEC_free (char_ptr, vec_keywords);
6543 xdb_handle_command (char *args, int from_tty)
6546 struct cleanup *old_chain;
6549 error_no_arg (_("xdb command"));
6551 /* Break the command line up into args. */
6553 argv = gdb_buildargv (args);
6554 old_chain = make_cleanup_freeargv (argv);
6555 if (argv[1] != (char *) NULL)
6560 bufLen = strlen (argv[0]) + 20;
6561 argBuf = (char *) xmalloc (bufLen);
6565 enum gdb_signal oursig;
6567 oursig = gdb_signal_from_name (argv[0]);
6568 memset (argBuf, 0, bufLen);
6569 if (strcmp (argv[1], "Q") == 0)
6570 sprintf (argBuf, "%s %s", argv[0], "noprint");
6573 if (strcmp (argv[1], "s") == 0)
6575 if (!signal_stop[oursig])
6576 sprintf (argBuf, "%s %s", argv[0], "stop");
6578 sprintf (argBuf, "%s %s", argv[0], "nostop");
6580 else if (strcmp (argv[1], "i") == 0)
6582 if (!signal_program[oursig])
6583 sprintf (argBuf, "%s %s", argv[0], "pass");
6585 sprintf (argBuf, "%s %s", argv[0], "nopass");
6587 else if (strcmp (argv[1], "r") == 0)
6589 if (!signal_print[oursig])
6590 sprintf (argBuf, "%s %s", argv[0], "print");
6592 sprintf (argBuf, "%s %s", argv[0], "noprint");
6598 handle_command (argBuf, from_tty);
6600 printf_filtered (_("Invalid signal handling flag.\n"));
6605 do_cleanups (old_chain);
6609 gdb_signal_from_command (int num)
6611 if (num >= 1 && num <= 15)
6612 return (enum gdb_signal) num;
6613 error (_("Only signals 1-15 are valid as numeric signals.\n\
6614 Use \"info signals\" for a list of symbolic signals."));
6617 /* Print current contents of the tables set by the handle command.
6618 It is possible we should just be printing signals actually used
6619 by the current target (but for things to work right when switching
6620 targets, all signals should be in the signal tables). */
6623 signals_info (char *signum_exp, int from_tty)
6625 enum gdb_signal oursig;
6627 sig_print_header ();
6631 /* First see if this is a symbol name. */
6632 oursig = gdb_signal_from_name (signum_exp);
6633 if (oursig == GDB_SIGNAL_UNKNOWN)
6635 /* No, try numeric. */
6637 gdb_signal_from_command (parse_and_eval_long (signum_exp));
6639 sig_print_info (oursig);
6643 printf_filtered ("\n");
6644 /* These ugly casts brought to you by the native VAX compiler. */
6645 for (oursig = GDB_SIGNAL_FIRST;
6646 (int) oursig < (int) GDB_SIGNAL_LAST;
6647 oursig = (enum gdb_signal) ((int) oursig + 1))
6651 if (oursig != GDB_SIGNAL_UNKNOWN
6652 && oursig != GDB_SIGNAL_DEFAULT && oursig != GDB_SIGNAL_0)
6653 sig_print_info (oursig);
6656 printf_filtered (_("\nUse the \"handle\" command "
6657 "to change these tables.\n"));
6660 /* Check if it makes sense to read $_siginfo from the current thread
6661 at this point. If not, throw an error. */
6664 validate_siginfo_access (void)
6666 /* No current inferior, no siginfo. */
6667 if (ptid_equal (inferior_ptid, null_ptid))
6668 error (_("No thread selected."));
6670 /* Don't try to read from a dead thread. */
6671 if (is_exited (inferior_ptid))
6672 error (_("The current thread has terminated"));
6674 /* ... or from a spinning thread. */
6675 if (is_running (inferior_ptid))
6676 error (_("Selected thread is running."));
6679 /* The $_siginfo convenience variable is a bit special. We don't know
6680 for sure the type of the value until we actually have a chance to
6681 fetch the data. The type can change depending on gdbarch, so it is
6682 also dependent on which thread you have selected.
6684 1. making $_siginfo be an internalvar that creates a new value on
6687 2. making the value of $_siginfo be an lval_computed value. */
6689 /* This function implements the lval_computed support for reading a
6693 siginfo_value_read (struct value *v)
6695 LONGEST transferred;
6697 validate_siginfo_access ();
6700 target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO,
6702 value_contents_all_raw (v),
6704 TYPE_LENGTH (value_type (v)));
6706 if (transferred != TYPE_LENGTH (value_type (v)))
6707 error (_("Unable to read siginfo"));
6710 /* This function implements the lval_computed support for writing a
6714 siginfo_value_write (struct value *v, struct value *fromval)
6716 LONGEST transferred;
6718 validate_siginfo_access ();
6720 transferred = target_write (¤t_target,
6721 TARGET_OBJECT_SIGNAL_INFO,
6723 value_contents_all_raw (fromval),
6725 TYPE_LENGTH (value_type (fromval)));
6727 if (transferred != TYPE_LENGTH (value_type (fromval)))
6728 error (_("Unable to write siginfo"));
6731 static const struct lval_funcs siginfo_value_funcs =
6737 /* Return a new value with the correct type for the siginfo object of
6738 the current thread using architecture GDBARCH. Return a void value
6739 if there's no object available. */
6741 static struct value *
6742 siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var,
6745 if (target_has_stack
6746 && !ptid_equal (inferior_ptid, null_ptid)
6747 && gdbarch_get_siginfo_type_p (gdbarch))
6749 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6751 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
6754 return allocate_value (builtin_type (gdbarch)->builtin_void);
6758 /* infcall_suspend_state contains state about the program itself like its
6759 registers and any signal it received when it last stopped.
6760 This state must be restored regardless of how the inferior function call
6761 ends (either successfully, or after it hits a breakpoint or signal)
6762 if the program is to properly continue where it left off. */
6764 struct infcall_suspend_state
6766 struct thread_suspend_state thread_suspend;
6767 #if 0 /* Currently unused and empty structures are not valid C. */
6768 struct inferior_suspend_state inferior_suspend;
6773 struct regcache *registers;
6775 /* Format of SIGINFO_DATA or NULL if it is not present. */
6776 struct gdbarch *siginfo_gdbarch;
6778 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6779 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6780 content would be invalid. */
6781 gdb_byte *siginfo_data;
6784 struct infcall_suspend_state *
6785 save_infcall_suspend_state (void)
6787 struct infcall_suspend_state *inf_state;
6788 struct thread_info *tp = inferior_thread ();
6790 struct inferior *inf = current_inferior ();
6792 struct regcache *regcache = get_current_regcache ();
6793 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6794 gdb_byte *siginfo_data = NULL;
6796 if (gdbarch_get_siginfo_type_p (gdbarch))
6798 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6799 size_t len = TYPE_LENGTH (type);
6800 struct cleanup *back_to;
6802 siginfo_data = xmalloc (len);
6803 back_to = make_cleanup (xfree, siginfo_data);
6805 if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6806 siginfo_data, 0, len) == len)
6807 discard_cleanups (back_to);
6810 /* Errors ignored. */
6811 do_cleanups (back_to);
6812 siginfo_data = NULL;
6816 inf_state = XZALLOC (struct infcall_suspend_state);
6820 inf_state->siginfo_gdbarch = gdbarch;
6821 inf_state->siginfo_data = siginfo_data;
6824 inf_state->thread_suspend = tp->suspend;
6825 #if 0 /* Currently unused and empty structures are not valid C. */
6826 inf_state->inferior_suspend = inf->suspend;
6829 /* run_inferior_call will not use the signal due to its `proceed' call with
6830 GDB_SIGNAL_0 anyway. */
6831 tp->suspend.stop_signal = GDB_SIGNAL_0;
6833 inf_state->stop_pc = stop_pc;
6835 inf_state->registers = regcache_dup (regcache);
6840 /* Restore inferior session state to INF_STATE. */
6843 restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6845 struct thread_info *tp = inferior_thread ();
6847 struct inferior *inf = current_inferior ();
6849 struct regcache *regcache = get_current_regcache ();
6850 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6852 tp->suspend = inf_state->thread_suspend;
6853 #if 0 /* Currently unused and empty structures are not valid C. */
6854 inf->suspend = inf_state->inferior_suspend;
6857 stop_pc = inf_state->stop_pc;
6859 if (inf_state->siginfo_gdbarch == gdbarch)
6861 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6863 /* Errors ignored. */
6864 target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6865 inf_state->siginfo_data, 0, TYPE_LENGTH (type));
6868 /* The inferior can be gone if the user types "print exit(0)"
6869 (and perhaps other times). */
6870 if (target_has_execution)
6871 /* NB: The register write goes through to the target. */
6872 regcache_cpy (regcache, inf_state->registers);
6874 discard_infcall_suspend_state (inf_state);
6878 do_restore_infcall_suspend_state_cleanup (void *state)
6880 restore_infcall_suspend_state (state);
6884 make_cleanup_restore_infcall_suspend_state
6885 (struct infcall_suspend_state *inf_state)
6887 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
6891 discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6893 regcache_xfree (inf_state->registers);
6894 xfree (inf_state->siginfo_data);
6899 get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
6901 return inf_state->registers;
6904 /* infcall_control_state contains state regarding gdb's control of the
6905 inferior itself like stepping control. It also contains session state like
6906 the user's currently selected frame. */
6908 struct infcall_control_state
6910 struct thread_control_state thread_control;
6911 struct inferior_control_state inferior_control;
6914 enum stop_stack_kind stop_stack_dummy;
6915 int stopped_by_random_signal;
6916 int stop_after_trap;
6918 /* ID if the selected frame when the inferior function call was made. */
6919 struct frame_id selected_frame_id;
6922 /* Save all of the information associated with the inferior<==>gdb
6925 struct infcall_control_state *
6926 save_infcall_control_state (void)
6928 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
6929 struct thread_info *tp = inferior_thread ();
6930 struct inferior *inf = current_inferior ();
6932 inf_status->thread_control = tp->control;
6933 inf_status->inferior_control = inf->control;
6935 tp->control.step_resume_breakpoint = NULL;
6936 tp->control.exception_resume_breakpoint = NULL;
6938 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6939 chain. If caller's caller is walking the chain, they'll be happier if we
6940 hand them back the original chain when restore_infcall_control_state is
6942 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
6945 inf_status->stop_stack_dummy = stop_stack_dummy;
6946 inf_status->stopped_by_random_signal = stopped_by_random_signal;
6947 inf_status->stop_after_trap = stop_after_trap;
6949 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
6955 restore_selected_frame (void *args)
6957 struct frame_id *fid = (struct frame_id *) args;
6958 struct frame_info *frame;
6960 frame = frame_find_by_id (*fid);
6962 /* If inf_status->selected_frame_id is NULL, there was no previously
6966 warning (_("Unable to restore previously selected frame."));
6970 select_frame (frame);
6975 /* Restore inferior session state to INF_STATUS. */
6978 restore_infcall_control_state (struct infcall_control_state *inf_status)
6980 struct thread_info *tp = inferior_thread ();
6981 struct inferior *inf = current_inferior ();
6983 if (tp->control.step_resume_breakpoint)
6984 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
6986 if (tp->control.exception_resume_breakpoint)
6987 tp->control.exception_resume_breakpoint->disposition
6988 = disp_del_at_next_stop;
6990 /* Handle the bpstat_copy of the chain. */
6991 bpstat_clear (&tp->control.stop_bpstat);
6993 tp->control = inf_status->thread_control;
6994 inf->control = inf_status->inferior_control;
6997 stop_stack_dummy = inf_status->stop_stack_dummy;
6998 stopped_by_random_signal = inf_status->stopped_by_random_signal;
6999 stop_after_trap = inf_status->stop_after_trap;
7001 if (target_has_stack)
7003 /* The point of catch_errors is that if the stack is clobbered,
7004 walking the stack might encounter a garbage pointer and
7005 error() trying to dereference it. */
7007 (restore_selected_frame, &inf_status->selected_frame_id,
7008 "Unable to restore previously selected frame:\n",
7009 RETURN_MASK_ERROR) == 0)
7010 /* Error in restoring the selected frame. Select the innermost
7012 select_frame (get_current_frame ());
7019 do_restore_infcall_control_state_cleanup (void *sts)
7021 restore_infcall_control_state (sts);
7025 make_cleanup_restore_infcall_control_state
7026 (struct infcall_control_state *inf_status)
7028 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
7032 discard_infcall_control_state (struct infcall_control_state *inf_status)
7034 if (inf_status->thread_control.step_resume_breakpoint)
7035 inf_status->thread_control.step_resume_breakpoint->disposition
7036 = disp_del_at_next_stop;
7038 if (inf_status->thread_control.exception_resume_breakpoint)
7039 inf_status->thread_control.exception_resume_breakpoint->disposition
7040 = disp_del_at_next_stop;
7042 /* See save_infcall_control_state for info on stop_bpstat. */
7043 bpstat_clear (&inf_status->thread_control.stop_bpstat);
7049 ptid_match (ptid_t ptid, ptid_t filter)
7051 if (ptid_equal (filter, minus_one_ptid))
7053 if (ptid_is_pid (filter)
7054 && ptid_get_pid (ptid) == ptid_get_pid (filter))
7056 else if (ptid_equal (ptid, filter))
7062 /* restore_inferior_ptid() will be used by the cleanup machinery
7063 to restore the inferior_ptid value saved in a call to
7064 save_inferior_ptid(). */
7067 restore_inferior_ptid (void *arg)
7069 ptid_t *saved_ptid_ptr = arg;
7071 inferior_ptid = *saved_ptid_ptr;
7075 /* Save the value of inferior_ptid so that it may be restored by a
7076 later call to do_cleanups(). Returns the struct cleanup pointer
7077 needed for later doing the cleanup. */
7080 save_inferior_ptid (void)
7082 ptid_t *saved_ptid_ptr;
7084 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
7085 *saved_ptid_ptr = inferior_ptid;
7086 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
7090 /* User interface for reverse debugging:
7091 Set exec-direction / show exec-direction commands
7092 (returns error unless target implements to_set_exec_direction method). */
7094 int execution_direction = EXEC_FORWARD;
7095 static const char exec_forward[] = "forward";
7096 static const char exec_reverse[] = "reverse";
7097 static const char *exec_direction = exec_forward;
7098 static const char *const exec_direction_names[] = {
7105 set_exec_direction_func (char *args, int from_tty,
7106 struct cmd_list_element *cmd)
7108 if (target_can_execute_reverse)
7110 if (!strcmp (exec_direction, exec_forward))
7111 execution_direction = EXEC_FORWARD;
7112 else if (!strcmp (exec_direction, exec_reverse))
7113 execution_direction = EXEC_REVERSE;
7117 exec_direction = exec_forward;
7118 error (_("Target does not support this operation."));
7123 show_exec_direction_func (struct ui_file *out, int from_tty,
7124 struct cmd_list_element *cmd, const char *value)
7126 switch (execution_direction) {
7128 fprintf_filtered (out, _("Forward.\n"));
7131 fprintf_filtered (out, _("Reverse.\n"));
7134 internal_error (__FILE__, __LINE__,
7135 _("bogus execution_direction value: %d"),
7136 (int) execution_direction);
7140 /* User interface for non-stop mode. */
7145 set_non_stop (char *args, int from_tty,
7146 struct cmd_list_element *c)
7148 if (target_has_execution)
7150 non_stop_1 = non_stop;
7151 error (_("Cannot change this setting while the inferior is running."));
7154 non_stop = non_stop_1;
7158 show_non_stop (struct ui_file *file, int from_tty,
7159 struct cmd_list_element *c, const char *value)
7161 fprintf_filtered (file,
7162 _("Controlling the inferior in non-stop mode is %s.\n"),
7167 show_schedule_multiple (struct ui_file *file, int from_tty,
7168 struct cmd_list_element *c, const char *value)
7170 fprintf_filtered (file, _("Resuming the execution of threads "
7171 "of all processes is %s.\n"), value);
7174 /* Implementation of `siginfo' variable. */
7176 static const struct internalvar_funcs siginfo_funcs =
7184 _initialize_infrun (void)
7188 struct cmd_list_element *c;
7190 add_info ("signals", signals_info, _("\
7191 What debugger does when program gets various signals.\n\
7192 Specify a signal as argument to print info on that signal only."));
7193 add_info_alias ("handle", "signals", 0);
7195 c = add_com ("handle", class_run, handle_command, _("\
7196 Specify how to handle signals.\n\
7197 Usage: handle SIGNAL [ACTIONS]\n\
7198 Args are signals and actions to apply to those signals.\n\
7199 If no actions are specified, the current settings for the specified signals\n\
7200 will be displayed instead.\n\
7202 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7203 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7204 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7205 The special arg \"all\" is recognized to mean all signals except those\n\
7206 used by the debugger, typically SIGTRAP and SIGINT.\n\
7208 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7209 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7210 Stop means reenter debugger if this signal happens (implies print).\n\
7211 Print means print a message if this signal happens.\n\
7212 Pass means let program see this signal; otherwise program doesn't know.\n\
7213 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7214 Pass and Stop may be combined.\n\
7216 Multiple signals may be specified. Signal numbers and signal names\n\
7217 may be interspersed with actions, with the actions being performed for\n\
7218 all signals cumulatively specified."));
7219 set_cmd_completer (c, handle_completer);
7223 add_com ("lz", class_info, signals_info, _("\
7224 What debugger does when program gets various signals.\n\
7225 Specify a signal as argument to print info on that signal only."));
7226 add_com ("z", class_run, xdb_handle_command, _("\
7227 Specify how to handle a signal.\n\
7228 Args are signals and actions to apply to those signals.\n\
7229 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7230 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7231 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7232 The special arg \"all\" is recognized to mean all signals except those\n\
7233 used by the debugger, typically SIGTRAP and SIGINT.\n\
7234 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7235 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7236 nopass), \"Q\" (noprint)\n\
7237 Stop means reenter debugger if this signal happens (implies print).\n\
7238 Print means print a message if this signal happens.\n\
7239 Pass means let program see this signal; otherwise program doesn't know.\n\
7240 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7241 Pass and Stop may be combined."));
7245 stop_command = add_cmd ("stop", class_obscure,
7246 not_just_help_class_command, _("\
7247 There is no `stop' command, but you can set a hook on `stop'.\n\
7248 This allows you to set a list of commands to be run each time execution\n\
7249 of the program stops."), &cmdlist);
7251 add_setshow_zuinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
7252 Set inferior debugging."), _("\
7253 Show inferior debugging."), _("\
7254 When non-zero, inferior specific debugging is enabled."),
7257 &setdebuglist, &showdebuglist);
7259 add_setshow_boolean_cmd ("displaced", class_maintenance,
7260 &debug_displaced, _("\
7261 Set displaced stepping debugging."), _("\
7262 Show displaced stepping debugging."), _("\
7263 When non-zero, displaced stepping specific debugging is enabled."),
7265 show_debug_displaced,
7266 &setdebuglist, &showdebuglist);
7268 add_setshow_boolean_cmd ("non-stop", no_class,
7270 Set whether gdb controls the inferior in non-stop mode."), _("\
7271 Show whether gdb controls the inferior in non-stop mode."), _("\
7272 When debugging a multi-threaded program and this setting is\n\
7273 off (the default, also called all-stop mode), when one thread stops\n\
7274 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7275 all other threads in the program while you interact with the thread of\n\
7276 interest. When you continue or step a thread, you can allow the other\n\
7277 threads to run, or have them remain stopped, but while you inspect any\n\
7278 thread's state, all threads stop.\n\
7280 In non-stop mode, when one thread stops, other threads can continue\n\
7281 to run freely. You'll be able to step each thread independently,\n\
7282 leave it stopped or free to run as needed."),
7288 numsigs = (int) GDB_SIGNAL_LAST;
7289 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
7290 signal_print = (unsigned char *)
7291 xmalloc (sizeof (signal_print[0]) * numsigs);
7292 signal_program = (unsigned char *)
7293 xmalloc (sizeof (signal_program[0]) * numsigs);
7294 signal_catch = (unsigned char *)
7295 xmalloc (sizeof (signal_catch[0]) * numsigs);
7296 signal_pass = (unsigned char *)
7297 xmalloc (sizeof (signal_program[0]) * numsigs);
7298 for (i = 0; i < numsigs; i++)
7301 signal_print[i] = 1;
7302 signal_program[i] = 1;
7303 signal_catch[i] = 0;
7306 /* Signals caused by debugger's own actions
7307 should not be given to the program afterwards. */
7308 signal_program[GDB_SIGNAL_TRAP] = 0;
7309 signal_program[GDB_SIGNAL_INT] = 0;
7311 /* Signals that are not errors should not normally enter the debugger. */
7312 signal_stop[GDB_SIGNAL_ALRM] = 0;
7313 signal_print[GDB_SIGNAL_ALRM] = 0;
7314 signal_stop[GDB_SIGNAL_VTALRM] = 0;
7315 signal_print[GDB_SIGNAL_VTALRM] = 0;
7316 signal_stop[GDB_SIGNAL_PROF] = 0;
7317 signal_print[GDB_SIGNAL_PROF] = 0;
7318 signal_stop[GDB_SIGNAL_CHLD] = 0;
7319 signal_print[GDB_SIGNAL_CHLD] = 0;
7320 signal_stop[GDB_SIGNAL_IO] = 0;
7321 signal_print[GDB_SIGNAL_IO] = 0;
7322 signal_stop[GDB_SIGNAL_POLL] = 0;
7323 signal_print[GDB_SIGNAL_POLL] = 0;
7324 signal_stop[GDB_SIGNAL_URG] = 0;
7325 signal_print[GDB_SIGNAL_URG] = 0;
7326 signal_stop[GDB_SIGNAL_WINCH] = 0;
7327 signal_print[GDB_SIGNAL_WINCH] = 0;
7328 signal_stop[GDB_SIGNAL_PRIO] = 0;
7329 signal_print[GDB_SIGNAL_PRIO] = 0;
7331 /* These signals are used internally by user-level thread
7332 implementations. (See signal(5) on Solaris.) Like the above
7333 signals, a healthy program receives and handles them as part of
7334 its normal operation. */
7335 signal_stop[GDB_SIGNAL_LWP] = 0;
7336 signal_print[GDB_SIGNAL_LWP] = 0;
7337 signal_stop[GDB_SIGNAL_WAITING] = 0;
7338 signal_print[GDB_SIGNAL_WAITING] = 0;
7339 signal_stop[GDB_SIGNAL_CANCEL] = 0;
7340 signal_print[GDB_SIGNAL_CANCEL] = 0;
7342 /* Update cached state. */
7343 signal_cache_update (-1);
7345 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
7346 &stop_on_solib_events, _("\
7347 Set stopping for shared library events."), _("\
7348 Show stopping for shared library events."), _("\
7349 If nonzero, gdb will give control to the user when the dynamic linker\n\
7350 notifies gdb of shared library events. The most common event of interest\n\
7351 to the user would be loading/unloading of a new library."),
7352 set_stop_on_solib_events,
7353 show_stop_on_solib_events,
7354 &setlist, &showlist);
7356 add_setshow_enum_cmd ("follow-fork-mode", class_run,
7357 follow_fork_mode_kind_names,
7358 &follow_fork_mode_string, _("\
7359 Set debugger response to a program call of fork or vfork."), _("\
7360 Show debugger response to a program call of fork or vfork."), _("\
7361 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7362 parent - the original process is debugged after a fork\n\
7363 child - the new process is debugged after a fork\n\
7364 The unfollowed process will continue to run.\n\
7365 By default, the debugger will follow the parent process."),
7367 show_follow_fork_mode_string,
7368 &setlist, &showlist);
7370 add_setshow_enum_cmd ("follow-exec-mode", class_run,
7371 follow_exec_mode_names,
7372 &follow_exec_mode_string, _("\
7373 Set debugger response to a program call of exec."), _("\
7374 Show debugger response to a program call of exec."), _("\
7375 An exec call replaces the program image of a process.\n\
7377 follow-exec-mode can be:\n\
7379 new - the debugger creates a new inferior and rebinds the process\n\
7380 to this new inferior. The program the process was running before\n\
7381 the exec call can be restarted afterwards by restarting the original\n\
7384 same - the debugger keeps the process bound to the same inferior.\n\
7385 The new executable image replaces the previous executable loaded in\n\
7386 the inferior. Restarting the inferior after the exec call restarts\n\
7387 the executable the process was running after the exec call.\n\
7389 By default, the debugger will use the same inferior."),
7391 show_follow_exec_mode_string,
7392 &setlist, &showlist);
7394 add_setshow_enum_cmd ("scheduler-locking", class_run,
7395 scheduler_enums, &scheduler_mode, _("\
7396 Set mode for locking scheduler during execution."), _("\
7397 Show mode for locking scheduler during execution."), _("\
7398 off == no locking (threads may preempt at any time)\n\
7399 on == full locking (no thread except the current thread may run)\n\
7400 step == scheduler locked during every single-step operation.\n\
7401 In this mode, no other thread may run during a step command.\n\
7402 Other threads may run while stepping over a function call ('next')."),
7403 set_schedlock_func, /* traps on target vector */
7404 show_scheduler_mode,
7405 &setlist, &showlist);
7407 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
7408 Set mode for resuming threads of all processes."), _("\
7409 Show mode for resuming threads of all processes."), _("\
7410 When on, execution commands (such as 'continue' or 'next') resume all\n\
7411 threads of all processes. When off (which is the default), execution\n\
7412 commands only resume the threads of the current process. The set of\n\
7413 threads that are resumed is further refined by the scheduler-locking\n\
7414 mode (see help set scheduler-locking)."),
7416 show_schedule_multiple,
7417 &setlist, &showlist);
7419 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
7420 Set mode of the step operation."), _("\
7421 Show mode of the step operation."), _("\
7422 When set, doing a step over a function without debug line information\n\
7423 will stop at the first instruction of that function. Otherwise, the\n\
7424 function is skipped and the step command stops at a different source line."),
7426 show_step_stop_if_no_debug,
7427 &setlist, &showlist);
7429 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run,
7430 &can_use_displaced_stepping, _("\
7431 Set debugger's willingness to use displaced stepping."), _("\
7432 Show debugger's willingness to use displaced stepping."), _("\
7433 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7434 supported by the target architecture. If off, gdb will not use displaced\n\
7435 stepping to step over breakpoints, even if such is supported by the target\n\
7436 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7437 if the target architecture supports it and non-stop mode is active, but will not\n\
7438 use it in all-stop mode (see help set non-stop)."),
7440 show_can_use_displaced_stepping,
7441 &setlist, &showlist);
7443 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
7444 &exec_direction, _("Set direction of execution.\n\
7445 Options are 'forward' or 'reverse'."),
7446 _("Show direction of execution (forward/reverse)."),
7447 _("Tells gdb whether to execute forward or backward."),
7448 set_exec_direction_func, show_exec_direction_func,
7449 &setlist, &showlist);
7451 /* Set/show detach-on-fork: user-settable mode. */
7453 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
7454 Set whether gdb will detach the child of a fork."), _("\
7455 Show whether gdb will detach the child of a fork."), _("\
7456 Tells gdb whether to detach the child of a fork."),
7457 NULL, NULL, &setlist, &showlist);
7459 /* Set/show disable address space randomization mode. */
7461 add_setshow_boolean_cmd ("disable-randomization", class_support,
7462 &disable_randomization, _("\
7463 Set disabling of debuggee's virtual address space randomization."), _("\
7464 Show disabling of debuggee's virtual address space randomization."), _("\
7465 When this mode is on (which is the default), randomization of the virtual\n\
7466 address space is disabled. Standalone programs run with the randomization\n\
7467 enabled by default on some platforms."),
7468 &set_disable_randomization,
7469 &show_disable_randomization,
7470 &setlist, &showlist);
7472 /* ptid initializations */
7473 inferior_ptid = null_ptid;
7474 target_last_wait_ptid = minus_one_ptid;
7476 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
7477 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
7478 observer_attach_thread_exit (infrun_thread_thread_exit);
7479 observer_attach_inferior_exit (infrun_inferior_exit);
7481 /* Explicitly create without lookup, since that tries to create a
7482 value with a void typed value, and when we get here, gdbarch
7483 isn't initialized yet. At this point, we're quite sure there
7484 isn't another convenience variable of the same name. */
7485 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs, NULL);
7487 add_setshow_boolean_cmd ("observer", no_class,
7488 &observer_mode_1, _("\
7489 Set whether gdb controls the inferior in observer mode."), _("\
7490 Show whether gdb controls the inferior in observer mode."), _("\
7491 In observer mode, GDB can get data from the inferior, but not\n\
7492 affect its execution. Registers and memory may not be changed,\n\
7493 breakpoints may not be set, and the program cannot be interrupted\n\