1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
5 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
6 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
29 #include "exceptions.h"
30 #include "breakpoint.h"
34 #include "cli/cli-script.h"
36 #include "gdbthread.h"
48 #include "dictionary.h"
50 #include "gdb_assert.h"
51 #include "mi/mi-common.h"
52 #include "event-top.h"
54 #include "inline-frame.h"
56 #include "tracepoint.h"
57 #include "continuations.h"
60 /* Prototypes for local functions */
62 static void signals_info (char *, int);
64 static void handle_command (char *, int);
66 static void sig_print_info (enum target_signal);
68 static void sig_print_header (void);
70 static void resume_cleanups (void *);
72 static int hook_stop_stub (void *);
74 static int restore_selected_frame (void *);
76 static int follow_fork (void);
78 static void set_schedlock_func (char *args, int from_tty,
79 struct cmd_list_element *c);
81 static int currently_stepping (struct thread_info *tp);
83 static int currently_stepping_or_nexting_callback (struct thread_info *tp,
86 static void xdb_handle_command (char *args, int from_tty);
88 static int prepare_to_proceed (int);
90 static void print_exited_reason (int exitstatus);
92 static void print_signal_exited_reason (enum target_signal siggnal);
94 static void print_no_history_reason (void);
96 static void print_signal_received_reason (enum target_signal siggnal);
98 static void print_end_stepping_range_reason (void);
100 void _initialize_infrun (void);
102 void nullify_last_target_wait_ptid (void);
104 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info *);
106 static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
108 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
110 /* When set, stop the 'step' command if we enter a function which has
111 no line number information. The normal behavior is that we step
112 over such function. */
113 int step_stop_if_no_debug = 0;
115 show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
116 struct cmd_list_element *c, const char *value)
118 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
121 /* In asynchronous mode, but simulating synchronous execution. */
123 int sync_execution = 0;
125 /* wait_for_inferior and normal_stop use this to notify the user
126 when the inferior stopped in a different thread than it had been
129 static ptid_t previous_inferior_ptid;
131 /* Default behavior is to detach newly forked processes (legacy). */
134 int debug_displaced = 0;
136 show_debug_displaced (struct ui_file *file, int from_tty,
137 struct cmd_list_element *c, const char *value)
139 fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value);
142 int debug_infrun = 0;
144 show_debug_infrun (struct ui_file *file, int from_tty,
145 struct cmd_list_element *c, const char *value)
147 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
150 /* If the program uses ELF-style shared libraries, then calls to
151 functions in shared libraries go through stubs, which live in a
152 table called the PLT (Procedure Linkage Table). The first time the
153 function is called, the stub sends control to the dynamic linker,
154 which looks up the function's real address, patches the stub so
155 that future calls will go directly to the function, and then passes
156 control to the function.
158 If we are stepping at the source level, we don't want to see any of
159 this --- we just want to skip over the stub and the dynamic linker.
160 The simple approach is to single-step until control leaves the
163 However, on some systems (e.g., Red Hat's 5.2 distribution) the
164 dynamic linker calls functions in the shared C library, so you
165 can't tell from the PC alone whether the dynamic linker is still
166 running. In this case, we use a step-resume breakpoint to get us
167 past the dynamic linker, as if we were using "next" to step over a
170 in_solib_dynsym_resolve_code() says whether we're in the dynamic
171 linker code or not. Normally, this means we single-step. However,
172 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
173 address where we can place a step-resume breakpoint to get past the
174 linker's symbol resolution function.
176 in_solib_dynsym_resolve_code() can generally be implemented in a
177 pretty portable way, by comparing the PC against the address ranges
178 of the dynamic linker's sections.
180 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
181 it depends on internal details of the dynamic linker. It's usually
182 not too hard to figure out where to put a breakpoint, but it
183 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
184 sanity checking. If it can't figure things out, returning zero and
185 getting the (possibly confusing) stepping behavior is better than
186 signalling an error, which will obscure the change in the
189 /* This function returns TRUE if pc is the address of an instruction
190 that lies within the dynamic linker (such as the event hook, or the
193 This function must be used only when a dynamic linker event has
194 been caught, and the inferior is being stepped out of the hook, or
195 undefined results are guaranteed. */
197 #ifndef SOLIB_IN_DYNAMIC_LINKER
198 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
201 /* "Observer mode" is somewhat like a more extreme version of
202 non-stop, in which all GDB operations that might affect the
203 target's execution have been disabled. */
205 static int non_stop_1 = 0;
207 int observer_mode = 0;
208 static int observer_mode_1 = 0;
211 set_observer_mode (char *args, int from_tty,
212 struct cmd_list_element *c)
214 extern int pagination_enabled;
216 if (target_has_execution)
218 observer_mode_1 = observer_mode;
219 error (_("Cannot change this setting while the inferior is running."));
222 observer_mode = observer_mode_1;
224 may_write_registers = !observer_mode;
225 may_write_memory = !observer_mode;
226 may_insert_breakpoints = !observer_mode;
227 may_insert_tracepoints = !observer_mode;
228 /* We can insert fast tracepoints in or out of observer mode,
229 but enable them if we're going into this mode. */
231 may_insert_fast_tracepoints = 1;
232 may_stop = !observer_mode;
233 update_target_permissions ();
235 /* Going *into* observer mode we must force non-stop, then
236 going out we leave it that way. */
239 target_async_permitted = 1;
240 pagination_enabled = 0;
241 non_stop = non_stop_1 = 1;
245 printf_filtered (_("Observer mode is now %s.\n"),
246 (observer_mode ? "on" : "off"));
250 show_observer_mode (struct ui_file *file, int from_tty,
251 struct cmd_list_element *c, const char *value)
253 fprintf_filtered (file, _("Observer mode is %s.\n"), value);
256 /* This updates the value of observer mode based on changes in
257 permissions. Note that we are deliberately ignoring the values of
258 may-write-registers and may-write-memory, since the user may have
259 reason to enable these during a session, for instance to turn on a
260 debugging-related global. */
263 update_observer_mode (void)
267 newval = (!may_insert_breakpoints
268 && !may_insert_tracepoints
269 && may_insert_fast_tracepoints
273 /* Let the user know if things change. */
274 if (newval != observer_mode)
275 printf_filtered (_("Observer mode is now %s.\n"),
276 (newval ? "on" : "off"));
278 observer_mode = observer_mode_1 = newval;
281 /* Tables of how to react to signals; the user sets them. */
283 static unsigned char *signal_stop;
284 static unsigned char *signal_print;
285 static unsigned char *signal_program;
287 /* Table of signals that the target may silently handle.
288 This is automatically determined from the flags above,
289 and simply cached here. */
290 static unsigned char *signal_pass;
292 #define SET_SIGS(nsigs,sigs,flags) \
294 int signum = (nsigs); \
295 while (signum-- > 0) \
296 if ((sigs)[signum]) \
297 (flags)[signum] = 1; \
300 #define UNSET_SIGS(nsigs,sigs,flags) \
302 int signum = (nsigs); \
303 while (signum-- > 0) \
304 if ((sigs)[signum]) \
305 (flags)[signum] = 0; \
308 /* Value to pass to target_resume() to cause all threads to resume. */
310 #define RESUME_ALL minus_one_ptid
312 /* Command list pointer for the "stop" placeholder. */
314 static struct cmd_list_element *stop_command;
316 /* Function inferior was in as of last step command. */
318 static struct symbol *step_start_function;
320 /* Nonzero if we want to give control to the user when we're notified
321 of shared library events by the dynamic linker. */
322 int stop_on_solib_events;
324 show_stop_on_solib_events (struct ui_file *file, int from_tty,
325 struct cmd_list_element *c, const char *value)
327 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
331 /* Nonzero means expecting a trace trap
332 and should stop the inferior and return silently when it happens. */
336 /* Save register contents here when executing a "finish" command or are
337 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
338 Thus this contains the return value from the called function (assuming
339 values are returned in a register). */
341 struct regcache *stop_registers;
343 /* Nonzero after stop if current stack frame should be printed. */
345 static int stop_print_frame;
347 /* This is a cached copy of the pid/waitstatus of the last event
348 returned by target_wait()/deprecated_target_wait_hook(). This
349 information is returned by get_last_target_status(). */
350 static ptid_t target_last_wait_ptid;
351 static struct target_waitstatus target_last_waitstatus;
353 static void context_switch (ptid_t ptid);
355 void init_thread_stepping_state (struct thread_info *tss);
357 void init_infwait_state (void);
359 static const char follow_fork_mode_child[] = "child";
360 static const char follow_fork_mode_parent[] = "parent";
362 static const char *follow_fork_mode_kind_names[] = {
363 follow_fork_mode_child,
364 follow_fork_mode_parent,
368 static const char *follow_fork_mode_string = follow_fork_mode_parent;
370 show_follow_fork_mode_string (struct ui_file *file, int from_tty,
371 struct cmd_list_element *c, const char *value)
373 fprintf_filtered (file,
374 _("Debugger response to a program "
375 "call of fork or vfork is \"%s\".\n"),
380 /* Tell the target to follow the fork we're stopped at. Returns true
381 if the inferior should be resumed; false, if the target for some
382 reason decided it's best not to resume. */
387 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
388 int should_resume = 1;
389 struct thread_info *tp;
391 /* Copy user stepping state to the new inferior thread. FIXME: the
392 followed fork child thread should have a copy of most of the
393 parent thread structure's run control related fields, not just these.
394 Initialized to avoid "may be used uninitialized" warnings from gcc. */
395 struct breakpoint *step_resume_breakpoint = NULL;
396 struct breakpoint *exception_resume_breakpoint = NULL;
397 CORE_ADDR step_range_start = 0;
398 CORE_ADDR step_range_end = 0;
399 struct frame_id step_frame_id = { 0 };
404 struct target_waitstatus wait_status;
406 /* Get the last target status returned by target_wait(). */
407 get_last_target_status (&wait_ptid, &wait_status);
409 /* If not stopped at a fork event, then there's nothing else to
411 if (wait_status.kind != TARGET_WAITKIND_FORKED
412 && wait_status.kind != TARGET_WAITKIND_VFORKED)
415 /* Check if we switched over from WAIT_PTID, since the event was
417 if (!ptid_equal (wait_ptid, minus_one_ptid)
418 && !ptid_equal (inferior_ptid, wait_ptid))
420 /* We did. Switch back to WAIT_PTID thread, to tell the
421 target to follow it (in either direction). We'll
422 afterwards refuse to resume, and inform the user what
424 switch_to_thread (wait_ptid);
429 tp = inferior_thread ();
431 /* If there were any forks/vforks that were caught and are now to be
432 followed, then do so now. */
433 switch (tp->pending_follow.kind)
435 case TARGET_WAITKIND_FORKED:
436 case TARGET_WAITKIND_VFORKED:
438 ptid_t parent, child;
440 /* If the user did a next/step, etc, over a fork call,
441 preserve the stepping state in the fork child. */
442 if (follow_child && should_resume)
444 step_resume_breakpoint = clone_momentary_breakpoint
445 (tp->control.step_resume_breakpoint);
446 step_range_start = tp->control.step_range_start;
447 step_range_end = tp->control.step_range_end;
448 step_frame_id = tp->control.step_frame_id;
449 exception_resume_breakpoint
450 = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint);
452 /* For now, delete the parent's sr breakpoint, otherwise,
453 parent/child sr breakpoints are considered duplicates,
454 and the child version will not be installed. Remove
455 this when the breakpoints module becomes aware of
456 inferiors and address spaces. */
457 delete_step_resume_breakpoint (tp);
458 tp->control.step_range_start = 0;
459 tp->control.step_range_end = 0;
460 tp->control.step_frame_id = null_frame_id;
461 delete_exception_resume_breakpoint (tp);
464 parent = inferior_ptid;
465 child = tp->pending_follow.value.related_pid;
467 /* Tell the target to do whatever is necessary to follow
468 either parent or child. */
469 if (target_follow_fork (follow_child))
471 /* Target refused to follow, or there's some other reason
472 we shouldn't resume. */
477 /* This pending follow fork event is now handled, one way
478 or another. The previous selected thread may be gone
479 from the lists by now, but if it is still around, need
480 to clear the pending follow request. */
481 tp = find_thread_ptid (parent);
483 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
485 /* This makes sure we don't try to apply the "Switched
486 over from WAIT_PID" logic above. */
487 nullify_last_target_wait_ptid ();
489 /* If we followed the child, switch to it... */
492 switch_to_thread (child);
494 /* ... and preserve the stepping state, in case the
495 user was stepping over the fork call. */
498 tp = inferior_thread ();
499 tp->control.step_resume_breakpoint
500 = step_resume_breakpoint;
501 tp->control.step_range_start = step_range_start;
502 tp->control.step_range_end = step_range_end;
503 tp->control.step_frame_id = step_frame_id;
504 tp->control.exception_resume_breakpoint
505 = exception_resume_breakpoint;
509 /* If we get here, it was because we're trying to
510 resume from a fork catchpoint, but, the user
511 has switched threads away from the thread that
512 forked. In that case, the resume command
513 issued is most likely not applicable to the
514 child, so just warn, and refuse to resume. */
515 warning (_("Not resuming: switched threads "
516 "before following fork child.\n"));
519 /* Reset breakpoints in the child as appropriate. */
520 follow_inferior_reset_breakpoints ();
523 switch_to_thread (parent);
527 case TARGET_WAITKIND_SPURIOUS:
528 /* Nothing to follow. */
531 internal_error (__FILE__, __LINE__,
532 "Unexpected pending_follow.kind %d\n",
533 tp->pending_follow.kind);
537 return should_resume;
541 follow_inferior_reset_breakpoints (void)
543 struct thread_info *tp = inferior_thread ();
545 /* Was there a step_resume breakpoint? (There was if the user
546 did a "next" at the fork() call.) If so, explicitly reset its
549 step_resumes are a form of bp that are made to be per-thread.
550 Since we created the step_resume bp when the parent process
551 was being debugged, and now are switching to the child process,
552 from the breakpoint package's viewpoint, that's a switch of
553 "threads". We must update the bp's notion of which thread
554 it is for, or it'll be ignored when it triggers. */
556 if (tp->control.step_resume_breakpoint)
557 breakpoint_re_set_thread (tp->control.step_resume_breakpoint);
559 if (tp->control.exception_resume_breakpoint)
560 breakpoint_re_set_thread (tp->control.exception_resume_breakpoint);
562 /* Reinsert all breakpoints in the child. The user may have set
563 breakpoints after catching the fork, in which case those
564 were never set in the child, but only in the parent. This makes
565 sure the inserted breakpoints match the breakpoint list. */
567 breakpoint_re_set ();
568 insert_breakpoints ();
571 /* The child has exited or execed: resume threads of the parent the
572 user wanted to be executing. */
575 proceed_after_vfork_done (struct thread_info *thread,
578 int pid = * (int *) arg;
580 if (ptid_get_pid (thread->ptid) == pid
581 && is_running (thread->ptid)
582 && !is_executing (thread->ptid)
583 && !thread->stop_requested
584 && thread->suspend.stop_signal == TARGET_SIGNAL_0)
587 fprintf_unfiltered (gdb_stdlog,
588 "infrun: resuming vfork parent thread %s\n",
589 target_pid_to_str (thread->ptid));
591 switch_to_thread (thread->ptid);
592 clear_proceed_status ();
593 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
599 /* Called whenever we notice an exec or exit event, to handle
600 detaching or resuming a vfork parent. */
603 handle_vfork_child_exec_or_exit (int exec)
605 struct inferior *inf = current_inferior ();
607 if (inf->vfork_parent)
609 int resume_parent = -1;
611 /* This exec or exit marks the end of the shared memory region
612 between the parent and the child. If the user wanted to
613 detach from the parent, now is the time. */
615 if (inf->vfork_parent->pending_detach)
617 struct thread_info *tp;
618 struct cleanup *old_chain;
619 struct program_space *pspace;
620 struct address_space *aspace;
622 /* follow-fork child, detach-on-fork on. */
624 old_chain = make_cleanup_restore_current_thread ();
626 /* We're letting loose of the parent. */
627 tp = any_live_thread_of_process (inf->vfork_parent->pid);
628 switch_to_thread (tp->ptid);
630 /* We're about to detach from the parent, which implicitly
631 removes breakpoints from its address space. There's a
632 catch here: we want to reuse the spaces for the child,
633 but, parent/child are still sharing the pspace at this
634 point, although the exec in reality makes the kernel give
635 the child a fresh set of new pages. The problem here is
636 that the breakpoints module being unaware of this, would
637 likely chose the child process to write to the parent
638 address space. Swapping the child temporarily away from
639 the spaces has the desired effect. Yes, this is "sort
642 pspace = inf->pspace;
643 aspace = inf->aspace;
647 if (debug_infrun || info_verbose)
649 target_terminal_ours ();
652 fprintf_filtered (gdb_stdlog,
653 "Detaching vfork parent process "
654 "%d after child exec.\n",
655 inf->vfork_parent->pid);
657 fprintf_filtered (gdb_stdlog,
658 "Detaching vfork parent process "
659 "%d after child exit.\n",
660 inf->vfork_parent->pid);
663 target_detach (NULL, 0);
666 inf->pspace = pspace;
667 inf->aspace = aspace;
669 do_cleanups (old_chain);
673 /* We're staying attached to the parent, so, really give the
674 child a new address space. */
675 inf->pspace = add_program_space (maybe_new_address_space ());
676 inf->aspace = inf->pspace->aspace;
678 set_current_program_space (inf->pspace);
680 resume_parent = inf->vfork_parent->pid;
682 /* Break the bonds. */
683 inf->vfork_parent->vfork_child = NULL;
687 struct cleanup *old_chain;
688 struct program_space *pspace;
690 /* If this is a vfork child exiting, then the pspace and
691 aspaces were shared with the parent. Since we're
692 reporting the process exit, we'll be mourning all that is
693 found in the address space, and switching to null_ptid,
694 preparing to start a new inferior. But, since we don't
695 want to clobber the parent's address/program spaces, we
696 go ahead and create a new one for this exiting
699 /* Switch to null_ptid, so that clone_program_space doesn't want
700 to read the selected frame of a dead process. */
701 old_chain = save_inferior_ptid ();
702 inferior_ptid = null_ptid;
704 /* This inferior is dead, so avoid giving the breakpoints
705 module the option to write through to it (cloning a
706 program space resets breakpoints). */
709 pspace = add_program_space (maybe_new_address_space ());
710 set_current_program_space (pspace);
712 clone_program_space (pspace, inf->vfork_parent->pspace);
713 inf->pspace = pspace;
714 inf->aspace = pspace->aspace;
716 /* Put back inferior_ptid. We'll continue mourning this
718 do_cleanups (old_chain);
720 resume_parent = inf->vfork_parent->pid;
721 /* Break the bonds. */
722 inf->vfork_parent->vfork_child = NULL;
725 inf->vfork_parent = NULL;
727 gdb_assert (current_program_space == inf->pspace);
729 if (non_stop && resume_parent != -1)
731 /* If the user wanted the parent to be running, let it go
733 struct cleanup *old_chain = make_cleanup_restore_current_thread ();
736 fprintf_unfiltered (gdb_stdlog,
737 "infrun: resuming vfork parent process %d\n",
740 iterate_over_threads (proceed_after_vfork_done, &resume_parent);
742 do_cleanups (old_chain);
747 /* Enum strings for "set|show displaced-stepping". */
749 static const char follow_exec_mode_new[] = "new";
750 static const char follow_exec_mode_same[] = "same";
751 static const char *follow_exec_mode_names[] =
753 follow_exec_mode_new,
754 follow_exec_mode_same,
758 static const char *follow_exec_mode_string = follow_exec_mode_same;
760 show_follow_exec_mode_string (struct ui_file *file, int from_tty,
761 struct cmd_list_element *c, const char *value)
763 fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value);
766 /* EXECD_PATHNAME is assumed to be non-NULL. */
769 follow_exec (ptid_t pid, char *execd_pathname)
771 struct thread_info *th = inferior_thread ();
772 struct inferior *inf = current_inferior ();
774 /* This is an exec event that we actually wish to pay attention to.
775 Refresh our symbol table to the newly exec'd program, remove any
778 If there are breakpoints, they aren't really inserted now,
779 since the exec() transformed our inferior into a fresh set
782 We want to preserve symbolic breakpoints on the list, since
783 we have hopes that they can be reset after the new a.out's
784 symbol table is read.
786 However, any "raw" breakpoints must be removed from the list
787 (e.g., the solib bp's), since their address is probably invalid
790 And, we DON'T want to call delete_breakpoints() here, since
791 that may write the bp's "shadow contents" (the instruction
792 value that was overwritten witha TRAP instruction). Since
793 we now have a new a.out, those shadow contents aren't valid. */
795 mark_breakpoints_out ();
797 update_breakpoints_after_exec ();
799 /* If there was one, it's gone now. We cannot truly step-to-next
800 statement through an exec(). */
801 th->control.step_resume_breakpoint = NULL;
802 th->control.exception_resume_breakpoint = NULL;
803 th->control.step_range_start = 0;
804 th->control.step_range_end = 0;
806 /* The target reports the exec event to the main thread, even if
807 some other thread does the exec, and even if the main thread was
808 already stopped --- if debugging in non-stop mode, it's possible
809 the user had the main thread held stopped in the previous image
810 --- release it now. This is the same behavior as step-over-exec
811 with scheduler-locking on in all-stop mode. */
812 th->stop_requested = 0;
814 /* What is this a.out's name? */
815 printf_unfiltered (_("%s is executing new program: %s\n"),
816 target_pid_to_str (inferior_ptid),
819 /* We've followed the inferior through an exec. Therefore, the
820 inferior has essentially been killed & reborn. */
822 gdb_flush (gdb_stdout);
824 breakpoint_init_inferior (inf_execd);
826 if (gdb_sysroot && *gdb_sysroot)
828 char *name = alloca (strlen (gdb_sysroot)
829 + strlen (execd_pathname)
832 strcpy (name, gdb_sysroot);
833 strcat (name, execd_pathname);
834 execd_pathname = name;
837 /* Reset the shared library package. This ensures that we get a
838 shlib event when the child reaches "_start", at which point the
839 dld will have had a chance to initialize the child. */
840 /* Also, loading a symbol file below may trigger symbol lookups, and
841 we don't want those to be satisfied by the libraries of the
842 previous incarnation of this process. */
843 no_shared_libraries (NULL, 0);
845 if (follow_exec_mode_string == follow_exec_mode_new)
847 struct program_space *pspace;
849 /* The user wants to keep the old inferior and program spaces
850 around. Create a new fresh one, and switch to it. */
852 inf = add_inferior (current_inferior ()->pid);
853 pspace = add_program_space (maybe_new_address_space ());
854 inf->pspace = pspace;
855 inf->aspace = pspace->aspace;
857 exit_inferior_num_silent (current_inferior ()->num);
859 set_current_inferior (inf);
860 set_current_program_space (pspace);
863 gdb_assert (current_program_space == inf->pspace);
865 /* That a.out is now the one to use. */
866 exec_file_attach (execd_pathname, 0);
868 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
869 (Position Independent Executable) main symbol file will get applied by
870 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
871 the breakpoints with the zero displacement. */
873 symbol_file_add (execd_pathname, SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET,
876 set_initial_language ();
878 #ifdef SOLIB_CREATE_INFERIOR_HOOK
879 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
881 solib_create_inferior_hook (0);
884 jit_inferior_created_hook ();
886 breakpoint_re_set ();
888 /* Reinsert all breakpoints. (Those which were symbolic have
889 been reset to the proper address in the new a.out, thanks
890 to symbol_file_command...). */
891 insert_breakpoints ();
893 /* The next resume of this inferior should bring it to the shlib
894 startup breakpoints. (If the user had also set bp's on
895 "main" from the old (parent) process, then they'll auto-
896 matically get reset there in the new process.). */
899 /* Non-zero if we just simulating a single-step. This is needed
900 because we cannot remove the breakpoints in the inferior process
901 until after the `wait' in `wait_for_inferior'. */
902 static int singlestep_breakpoints_inserted_p = 0;
904 /* The thread we inserted single-step breakpoints for. */
905 static ptid_t singlestep_ptid;
907 /* PC when we started this single-step. */
908 static CORE_ADDR singlestep_pc;
910 /* If another thread hit the singlestep breakpoint, we save the original
911 thread here so that we can resume single-stepping it later. */
912 static ptid_t saved_singlestep_ptid;
913 static int stepping_past_singlestep_breakpoint;
915 /* If not equal to null_ptid, this means that after stepping over breakpoint
916 is finished, we need to switch to deferred_step_ptid, and step it.
918 The use case is when one thread has hit a breakpoint, and then the user
919 has switched to another thread and issued 'step'. We need to step over
920 breakpoint in the thread which hit the breakpoint, but then continue
921 stepping the thread user has selected. */
922 static ptid_t deferred_step_ptid;
924 /* Displaced stepping. */
926 /* In non-stop debugging mode, we must take special care to manage
927 breakpoints properly; in particular, the traditional strategy for
928 stepping a thread past a breakpoint it has hit is unsuitable.
929 'Displaced stepping' is a tactic for stepping one thread past a
930 breakpoint it has hit while ensuring that other threads running
931 concurrently will hit the breakpoint as they should.
933 The traditional way to step a thread T off a breakpoint in a
934 multi-threaded program in all-stop mode is as follows:
936 a0) Initially, all threads are stopped, and breakpoints are not
938 a1) We single-step T, leaving breakpoints uninserted.
939 a2) We insert breakpoints, and resume all threads.
941 In non-stop debugging, however, this strategy is unsuitable: we
942 don't want to have to stop all threads in the system in order to
943 continue or step T past a breakpoint. Instead, we use displaced
946 n0) Initially, T is stopped, other threads are running, and
947 breakpoints are inserted.
948 n1) We copy the instruction "under" the breakpoint to a separate
949 location, outside the main code stream, making any adjustments
950 to the instruction, register, and memory state as directed by
952 n2) We single-step T over the instruction at its new location.
953 n3) We adjust the resulting register and memory state as directed
954 by T's architecture. This includes resetting T's PC to point
955 back into the main instruction stream.
958 This approach depends on the following gdbarch methods:
960 - gdbarch_max_insn_length and gdbarch_displaced_step_location
961 indicate where to copy the instruction, and how much space must
962 be reserved there. We use these in step n1.
964 - gdbarch_displaced_step_copy_insn copies a instruction to a new
965 address, and makes any necessary adjustments to the instruction,
966 register contents, and memory. We use this in step n1.
968 - gdbarch_displaced_step_fixup adjusts registers and memory after
969 we have successfuly single-stepped the instruction, to yield the
970 same effect the instruction would have had if we had executed it
971 at its original address. We use this in step n3.
973 - gdbarch_displaced_step_free_closure provides cleanup.
975 The gdbarch_displaced_step_copy_insn and
976 gdbarch_displaced_step_fixup functions must be written so that
977 copying an instruction with gdbarch_displaced_step_copy_insn,
978 single-stepping across the copied instruction, and then applying
979 gdbarch_displaced_insn_fixup should have the same effects on the
980 thread's memory and registers as stepping the instruction in place
981 would have. Exactly which responsibilities fall to the copy and
982 which fall to the fixup is up to the author of those functions.
984 See the comments in gdbarch.sh for details.
986 Note that displaced stepping and software single-step cannot
987 currently be used in combination, although with some care I think
988 they could be made to. Software single-step works by placing
989 breakpoints on all possible subsequent instructions; if the
990 displaced instruction is a PC-relative jump, those breakpoints
991 could fall in very strange places --- on pages that aren't
992 executable, or at addresses that are not proper instruction
993 boundaries. (We do generally let other threads run while we wait
994 to hit the software single-step breakpoint, and they might
995 encounter such a corrupted instruction.) One way to work around
996 this would be to have gdbarch_displaced_step_copy_insn fully
997 simulate the effect of PC-relative instructions (and return NULL)
998 on architectures that use software single-stepping.
1000 In non-stop mode, we can have independent and simultaneous step
1001 requests, so more than one thread may need to simultaneously step
1002 over a breakpoint. The current implementation assumes there is
1003 only one scratch space per process. In this case, we have to
1004 serialize access to the scratch space. If thread A wants to step
1005 over a breakpoint, but we are currently waiting for some other
1006 thread to complete a displaced step, we leave thread A stopped and
1007 place it in the displaced_step_request_queue. Whenever a displaced
1008 step finishes, we pick the next thread in the queue and start a new
1009 displaced step operation on it. See displaced_step_prepare and
1010 displaced_step_fixup for details. */
1012 struct displaced_step_request
1015 struct displaced_step_request *next;
1018 /* Per-inferior displaced stepping state. */
1019 struct displaced_step_inferior_state
1021 /* Pointer to next in linked list. */
1022 struct displaced_step_inferior_state *next;
1024 /* The process this displaced step state refers to. */
1027 /* A queue of pending displaced stepping requests. One entry per
1028 thread that needs to do a displaced step. */
1029 struct displaced_step_request *step_request_queue;
1031 /* If this is not null_ptid, this is the thread carrying out a
1032 displaced single-step in process PID. This thread's state will
1033 require fixing up once it has completed its step. */
1036 /* The architecture the thread had when we stepped it. */
1037 struct gdbarch *step_gdbarch;
1039 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1040 for post-step cleanup. */
1041 struct displaced_step_closure *step_closure;
1043 /* The address of the original instruction, and the copy we
1045 CORE_ADDR step_original, step_copy;
1047 /* Saved contents of copy area. */
1048 gdb_byte *step_saved_copy;
1051 /* The list of states of processes involved in displaced stepping
1053 static struct displaced_step_inferior_state *displaced_step_inferior_states;
1055 /* Get the displaced stepping state of process PID. */
1057 static struct displaced_step_inferior_state *
1058 get_displaced_stepping_state (int pid)
1060 struct displaced_step_inferior_state *state;
1062 for (state = displaced_step_inferior_states;
1064 state = state->next)
1065 if (state->pid == pid)
1071 /* Add a new displaced stepping state for process PID to the displaced
1072 stepping state list, or return a pointer to an already existing
1073 entry, if it already exists. Never returns NULL. */
1075 static struct displaced_step_inferior_state *
1076 add_displaced_stepping_state (int pid)
1078 struct displaced_step_inferior_state *state;
1080 for (state = displaced_step_inferior_states;
1082 state = state->next)
1083 if (state->pid == pid)
1086 state = xcalloc (1, sizeof (*state));
1088 state->next = displaced_step_inferior_states;
1089 displaced_step_inferior_states = state;
1094 /* If inferior is in displaced stepping, and ADDR equals to starting address
1095 of copy area, return corresponding displaced_step_closure. Otherwise,
1098 struct displaced_step_closure*
1099 get_displaced_step_closure_by_addr (CORE_ADDR addr)
1101 struct displaced_step_inferior_state *displaced
1102 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1104 /* If checking the mode of displaced instruction in copy area. */
1105 if (displaced && !ptid_equal (displaced->step_ptid, null_ptid)
1106 && (displaced->step_copy == addr))
1107 return displaced->step_closure;
1112 /* Remove the displaced stepping state of process PID. */
1115 remove_displaced_stepping_state (int pid)
1117 struct displaced_step_inferior_state *it, **prev_next_p;
1119 gdb_assert (pid != 0);
1121 it = displaced_step_inferior_states;
1122 prev_next_p = &displaced_step_inferior_states;
1127 *prev_next_p = it->next;
1132 prev_next_p = &it->next;
1138 infrun_inferior_exit (struct inferior *inf)
1140 remove_displaced_stepping_state (inf->pid);
1143 /* Enum strings for "set|show displaced-stepping". */
1145 static const char can_use_displaced_stepping_auto[] = "auto";
1146 static const char can_use_displaced_stepping_on[] = "on";
1147 static const char can_use_displaced_stepping_off[] = "off";
1148 static const char *can_use_displaced_stepping_enum[] =
1150 can_use_displaced_stepping_auto,
1151 can_use_displaced_stepping_on,
1152 can_use_displaced_stepping_off,
1156 /* If ON, and the architecture supports it, GDB will use displaced
1157 stepping to step over breakpoints. If OFF, or if the architecture
1158 doesn't support it, GDB will instead use the traditional
1159 hold-and-step approach. If AUTO (which is the default), GDB will
1160 decide which technique to use to step over breakpoints depending on
1161 which of all-stop or non-stop mode is active --- displaced stepping
1162 in non-stop mode; hold-and-step in all-stop mode. */
1164 static const char *can_use_displaced_stepping =
1165 can_use_displaced_stepping_auto;
1168 show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
1169 struct cmd_list_element *c,
1172 if (can_use_displaced_stepping == can_use_displaced_stepping_auto)
1173 fprintf_filtered (file,
1174 _("Debugger's willingness to use displaced stepping "
1175 "to step over breakpoints is %s (currently %s).\n"),
1176 value, non_stop ? "on" : "off");
1178 fprintf_filtered (file,
1179 _("Debugger's willingness to use displaced stepping "
1180 "to step over breakpoints is %s.\n"), value);
1183 /* Return non-zero if displaced stepping can/should be used to step
1184 over breakpoints. */
1187 use_displaced_stepping (struct gdbarch *gdbarch)
1189 return (((can_use_displaced_stepping == can_use_displaced_stepping_auto
1191 || can_use_displaced_stepping == can_use_displaced_stepping_on)
1192 && gdbarch_displaced_step_copy_insn_p (gdbarch)
1193 && !RECORD_IS_USED);
1196 /* Clean out any stray displaced stepping state. */
1198 displaced_step_clear (struct displaced_step_inferior_state *displaced)
1200 /* Indicate that there is no cleanup pending. */
1201 displaced->step_ptid = null_ptid;
1203 if (displaced->step_closure)
1205 gdbarch_displaced_step_free_closure (displaced->step_gdbarch,
1206 displaced->step_closure);
1207 displaced->step_closure = NULL;
1212 displaced_step_clear_cleanup (void *arg)
1214 struct displaced_step_inferior_state *state = arg;
1216 displaced_step_clear (state);
1219 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1221 displaced_step_dump_bytes (struct ui_file *file,
1222 const gdb_byte *buf,
1227 for (i = 0; i < len; i++)
1228 fprintf_unfiltered (file, "%02x ", buf[i]);
1229 fputs_unfiltered ("\n", file);
1232 /* Prepare to single-step, using displaced stepping.
1234 Note that we cannot use displaced stepping when we have a signal to
1235 deliver. If we have a signal to deliver and an instruction to step
1236 over, then after the step, there will be no indication from the
1237 target whether the thread entered a signal handler or ignored the
1238 signal and stepped over the instruction successfully --- both cases
1239 result in a simple SIGTRAP. In the first case we mustn't do a
1240 fixup, and in the second case we must --- but we can't tell which.
1241 Comments in the code for 'random signals' in handle_inferior_event
1242 explain how we handle this case instead.
1244 Returns 1 if preparing was successful -- this thread is going to be
1245 stepped now; or 0 if displaced stepping this thread got queued. */
1247 displaced_step_prepare (ptid_t ptid)
1249 struct cleanup *old_cleanups, *ignore_cleanups;
1250 struct regcache *regcache = get_thread_regcache (ptid);
1251 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1252 CORE_ADDR original, copy;
1254 struct displaced_step_closure *closure;
1255 struct displaced_step_inferior_state *displaced;
1257 /* We should never reach this function if the architecture does not
1258 support displaced stepping. */
1259 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
1261 /* We have to displaced step one thread at a time, as we only have
1262 access to a single scratch space per inferior. */
1264 displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
1266 if (!ptid_equal (displaced->step_ptid, null_ptid))
1268 /* Already waiting for a displaced step to finish. Defer this
1269 request and place in queue. */
1270 struct displaced_step_request *req, *new_req;
1272 if (debug_displaced)
1273 fprintf_unfiltered (gdb_stdlog,
1274 "displaced: defering step of %s\n",
1275 target_pid_to_str (ptid));
1277 new_req = xmalloc (sizeof (*new_req));
1278 new_req->ptid = ptid;
1279 new_req->next = NULL;
1281 if (displaced->step_request_queue)
1283 for (req = displaced->step_request_queue;
1287 req->next = new_req;
1290 displaced->step_request_queue = new_req;
1296 if (debug_displaced)
1297 fprintf_unfiltered (gdb_stdlog,
1298 "displaced: stepping %s now\n",
1299 target_pid_to_str (ptid));
1302 displaced_step_clear (displaced);
1304 old_cleanups = save_inferior_ptid ();
1305 inferior_ptid = ptid;
1307 original = regcache_read_pc (regcache);
1309 copy = gdbarch_displaced_step_location (gdbarch);
1310 len = gdbarch_max_insn_length (gdbarch);
1312 /* Save the original contents of the copy area. */
1313 displaced->step_saved_copy = xmalloc (len);
1314 ignore_cleanups = make_cleanup (free_current_contents,
1315 &displaced->step_saved_copy);
1316 read_memory (copy, displaced->step_saved_copy, len);
1317 if (debug_displaced)
1319 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
1320 paddress (gdbarch, copy));
1321 displaced_step_dump_bytes (gdb_stdlog,
1322 displaced->step_saved_copy,
1326 closure = gdbarch_displaced_step_copy_insn (gdbarch,
1327 original, copy, regcache);
1329 /* We don't support the fully-simulated case at present. */
1330 gdb_assert (closure);
1332 /* Save the information we need to fix things up if the step
1334 displaced->step_ptid = ptid;
1335 displaced->step_gdbarch = gdbarch;
1336 displaced->step_closure = closure;
1337 displaced->step_original = original;
1338 displaced->step_copy = copy;
1340 make_cleanup (displaced_step_clear_cleanup, displaced);
1342 /* Resume execution at the copy. */
1343 regcache_write_pc (regcache, copy);
1345 discard_cleanups (ignore_cleanups);
1347 do_cleanups (old_cleanups);
1349 if (debug_displaced)
1350 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
1351 paddress (gdbarch, copy));
1357 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr,
1358 const gdb_byte *myaddr, int len)
1360 struct cleanup *ptid_cleanup = save_inferior_ptid ();
1362 inferior_ptid = ptid;
1363 write_memory (memaddr, myaddr, len);
1364 do_cleanups (ptid_cleanup);
1368 displaced_step_fixup (ptid_t event_ptid, enum target_signal signal)
1370 struct cleanup *old_cleanups;
1371 struct displaced_step_inferior_state *displaced
1372 = get_displaced_stepping_state (ptid_get_pid (event_ptid));
1374 /* Was any thread of this process doing a displaced step? */
1375 if (displaced == NULL)
1378 /* Was this event for the pid we displaced? */
1379 if (ptid_equal (displaced->step_ptid, null_ptid)
1380 || ! ptid_equal (displaced->step_ptid, event_ptid))
1383 old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
1385 /* Restore the contents of the copy area. */
1387 ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
1389 write_memory_ptid (displaced->step_ptid, displaced->step_copy,
1390 displaced->step_saved_copy, len);
1391 if (debug_displaced)
1392 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s\n",
1393 paddress (displaced->step_gdbarch,
1394 displaced->step_copy));
1397 /* Did the instruction complete successfully? */
1398 if (signal == TARGET_SIGNAL_TRAP)
1400 /* Fix up the resulting state. */
1401 gdbarch_displaced_step_fixup (displaced->step_gdbarch,
1402 displaced->step_closure,
1403 displaced->step_original,
1404 displaced->step_copy,
1405 get_thread_regcache (displaced->step_ptid));
1409 /* Since the instruction didn't complete, all we can do is
1411 struct regcache *regcache = get_thread_regcache (event_ptid);
1412 CORE_ADDR pc = regcache_read_pc (regcache);
1414 pc = displaced->step_original + (pc - displaced->step_copy);
1415 regcache_write_pc (regcache, pc);
1418 do_cleanups (old_cleanups);
1420 displaced->step_ptid = null_ptid;
1422 /* Are there any pending displaced stepping requests? If so, run
1423 one now. Leave the state object around, since we're likely to
1424 need it again soon. */
1425 while (displaced->step_request_queue)
1427 struct displaced_step_request *head;
1429 struct regcache *regcache;
1430 struct gdbarch *gdbarch;
1431 CORE_ADDR actual_pc;
1432 struct address_space *aspace;
1434 head = displaced->step_request_queue;
1436 displaced->step_request_queue = head->next;
1439 context_switch (ptid);
1441 regcache = get_thread_regcache (ptid);
1442 actual_pc = regcache_read_pc (regcache);
1443 aspace = get_regcache_aspace (regcache);
1445 if (breakpoint_here_p (aspace, actual_pc))
1447 if (debug_displaced)
1448 fprintf_unfiltered (gdb_stdlog,
1449 "displaced: stepping queued %s now\n",
1450 target_pid_to_str (ptid));
1452 displaced_step_prepare (ptid);
1454 gdbarch = get_regcache_arch (regcache);
1456 if (debug_displaced)
1458 CORE_ADDR actual_pc = regcache_read_pc (regcache);
1461 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1462 paddress (gdbarch, actual_pc));
1463 read_memory (actual_pc, buf, sizeof (buf));
1464 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1467 if (gdbarch_displaced_step_hw_singlestep (gdbarch,
1468 displaced->step_closure))
1469 target_resume (ptid, 1, TARGET_SIGNAL_0);
1471 target_resume (ptid, 0, TARGET_SIGNAL_0);
1473 /* Done, we're stepping a thread. */
1479 struct thread_info *tp = inferior_thread ();
1481 /* The breakpoint we were sitting under has since been
1483 tp->control.trap_expected = 0;
1485 /* Go back to what we were trying to do. */
1486 step = currently_stepping (tp);
1488 if (debug_displaced)
1489 fprintf_unfiltered (gdb_stdlog,
1490 "breakpoint is gone %s: step(%d)\n",
1491 target_pid_to_str (tp->ptid), step);
1493 target_resume (ptid, step, TARGET_SIGNAL_0);
1494 tp->suspend.stop_signal = TARGET_SIGNAL_0;
1496 /* This request was discarded. See if there's any other
1497 thread waiting for its turn. */
1502 /* Update global variables holding ptids to hold NEW_PTID if they were
1503 holding OLD_PTID. */
1505 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
1507 struct displaced_step_request *it;
1508 struct displaced_step_inferior_state *displaced;
1510 if (ptid_equal (inferior_ptid, old_ptid))
1511 inferior_ptid = new_ptid;
1513 if (ptid_equal (singlestep_ptid, old_ptid))
1514 singlestep_ptid = new_ptid;
1516 if (ptid_equal (deferred_step_ptid, old_ptid))
1517 deferred_step_ptid = new_ptid;
1519 for (displaced = displaced_step_inferior_states;
1521 displaced = displaced->next)
1523 if (ptid_equal (displaced->step_ptid, old_ptid))
1524 displaced->step_ptid = new_ptid;
1526 for (it = displaced->step_request_queue; it; it = it->next)
1527 if (ptid_equal (it->ptid, old_ptid))
1528 it->ptid = new_ptid;
1535 /* Things to clean up if we QUIT out of resume (). */
1537 resume_cleanups (void *ignore)
1542 static const char schedlock_off[] = "off";
1543 static const char schedlock_on[] = "on";
1544 static const char schedlock_step[] = "step";
1545 static const char *scheduler_enums[] = {
1551 static const char *scheduler_mode = schedlock_off;
1553 show_scheduler_mode (struct ui_file *file, int from_tty,
1554 struct cmd_list_element *c, const char *value)
1556 fprintf_filtered (file,
1557 _("Mode for locking scheduler "
1558 "during execution is \"%s\".\n"),
1563 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
1565 if (!target_can_lock_scheduler)
1567 scheduler_mode = schedlock_off;
1568 error (_("Target '%s' cannot support this command."), target_shortname);
1572 /* True if execution commands resume all threads of all processes by
1573 default; otherwise, resume only threads of the current inferior
1575 int sched_multi = 0;
1577 /* Try to setup for software single stepping over the specified location.
1578 Return 1 if target_resume() should use hardware single step.
1580 GDBARCH the current gdbarch.
1581 PC the location to step over. */
1584 maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
1588 if (execution_direction == EXEC_FORWARD
1589 && gdbarch_software_single_step_p (gdbarch)
1590 && gdbarch_software_single_step (gdbarch, get_current_frame ()))
1593 /* Do not pull these breakpoints until after a `wait' in
1594 `wait_for_inferior'. */
1595 singlestep_breakpoints_inserted_p = 1;
1596 singlestep_ptid = inferior_ptid;
1602 /* Return a ptid representing the set of threads that we will proceed,
1603 in the perspective of the user/frontend. We may actually resume
1604 fewer threads at first, e.g., if a thread is stopped at a
1605 breakpoint that needs stepping-off, but that should not be visible
1606 to the user/frontend, and neither should the frontend/user be
1607 allowed to proceed any of the threads that happen to be stopped for
1608 internal run control handling, if a previous command wanted them
1612 user_visible_resume_ptid (int step)
1614 /* By default, resume all threads of all processes. */
1615 ptid_t resume_ptid = RESUME_ALL;
1617 /* Maybe resume only all threads of the current process. */
1618 if (!sched_multi && target_supports_multi_process ())
1620 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
1623 /* Maybe resume a single thread after all. */
1626 /* With non-stop mode on, threads are always handled
1628 resume_ptid = inferior_ptid;
1630 else if ((scheduler_mode == schedlock_on)
1631 || (scheduler_mode == schedlock_step
1632 && (step || singlestep_breakpoints_inserted_p)))
1634 /* User-settable 'scheduler' mode requires solo thread resume. */
1635 resume_ptid = inferior_ptid;
1641 /* Resume the inferior, but allow a QUIT. This is useful if the user
1642 wants to interrupt some lengthy single-stepping operation
1643 (for child processes, the SIGINT goes to the inferior, and so
1644 we get a SIGINT random_signal, but for remote debugging and perhaps
1645 other targets, that's not true).
1647 STEP nonzero if we should step (zero to continue instead).
1648 SIG is the signal to give the inferior (zero for none). */
1650 resume (int step, enum target_signal sig)
1652 int should_resume = 1;
1653 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
1654 struct regcache *regcache = get_current_regcache ();
1655 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1656 struct thread_info *tp = inferior_thread ();
1657 CORE_ADDR pc = regcache_read_pc (regcache);
1658 struct address_space *aspace = get_regcache_aspace (regcache);
1662 if (current_inferior ()->waiting_for_vfork_done)
1664 /* Don't try to single-step a vfork parent that is waiting for
1665 the child to get out of the shared memory region (by exec'ing
1666 or exiting). This is particularly important on software
1667 single-step archs, as the child process would trip on the
1668 software single step breakpoint inserted for the parent
1669 process. Since the parent will not actually execute any
1670 instruction until the child is out of the shared region (such
1671 are vfork's semantics), it is safe to simply continue it.
1672 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1673 the parent, and tell it to `keep_going', which automatically
1674 re-sets it stepping. */
1676 fprintf_unfiltered (gdb_stdlog,
1677 "infrun: resume : clear step\n");
1682 fprintf_unfiltered (gdb_stdlog,
1683 "infrun: resume (step=%d, signal=%d), "
1684 "trap_expected=%d, current thread [%s] at %s\n",
1685 step, sig, tp->control.trap_expected,
1686 target_pid_to_str (inferior_ptid),
1687 paddress (gdbarch, pc));
1689 /* Normally, by the time we reach `resume', the breakpoints are either
1690 removed or inserted, as appropriate. The exception is if we're sitting
1691 at a permanent breakpoint; we need to step over it, but permanent
1692 breakpoints can't be removed. So we have to test for it here. */
1693 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
1695 if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
1696 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
1699 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1700 how to step past a permanent breakpoint on this architecture. Try using\n\
1701 a command like `return' or `jump' to continue execution."));
1704 /* If enabled, step over breakpoints by executing a copy of the
1705 instruction at a different address.
1707 We can't use displaced stepping when we have a signal to deliver;
1708 the comments for displaced_step_prepare explain why. The
1709 comments in the handle_inferior event for dealing with 'random
1710 signals' explain what we do instead.
1712 We can't use displaced stepping when we are waiting for vfork_done
1713 event, displaced stepping breaks the vfork child similarly as single
1714 step software breakpoint. */
1715 if (use_displaced_stepping (gdbarch)
1716 && (tp->control.trap_expected
1717 || (step && gdbarch_software_single_step_p (gdbarch)))
1718 && sig == TARGET_SIGNAL_0
1719 && !current_inferior ()->waiting_for_vfork_done)
1721 struct displaced_step_inferior_state *displaced;
1723 if (!displaced_step_prepare (inferior_ptid))
1725 /* Got placed in displaced stepping queue. Will be resumed
1726 later when all the currently queued displaced stepping
1727 requests finish. The thread is not executing at this point,
1728 and the call to set_executing will be made later. But we
1729 need to call set_running here, since from frontend point of view,
1730 the thread is running. */
1731 set_running (inferior_ptid, 1);
1732 discard_cleanups (old_cleanups);
1736 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1737 step = gdbarch_displaced_step_hw_singlestep (gdbarch,
1738 displaced->step_closure);
1741 /* Do we need to do it the hard way, w/temp breakpoints? */
1743 step = maybe_software_singlestep (gdbarch, pc);
1745 /* Currently, our software single-step implementation leads to different
1746 results than hardware single-stepping in one situation: when stepping
1747 into delivering a signal which has an associated signal handler,
1748 hardware single-step will stop at the first instruction of the handler,
1749 while software single-step will simply skip execution of the handler.
1751 For now, this difference in behavior is accepted since there is no
1752 easy way to actually implement single-stepping into a signal handler
1753 without kernel support.
1755 However, there is one scenario where this difference leads to follow-on
1756 problems: if we're stepping off a breakpoint by removing all breakpoints
1757 and then single-stepping. In this case, the software single-step
1758 behavior means that even if there is a *breakpoint* in the signal
1759 handler, GDB still would not stop.
1761 Fortunately, we can at least fix this particular issue. We detect
1762 here the case where we are about to deliver a signal while software
1763 single-stepping with breakpoints removed. In this situation, we
1764 revert the decisions to remove all breakpoints and insert single-
1765 step breakpoints, and instead we install a step-resume breakpoint
1766 at the current address, deliver the signal without stepping, and
1767 once we arrive back at the step-resume breakpoint, actually step
1768 over the breakpoint we originally wanted to step over. */
1769 if (singlestep_breakpoints_inserted_p
1770 && tp->control.trap_expected && sig != TARGET_SIGNAL_0)
1772 /* If we have nested signals or a pending signal is delivered
1773 immediately after a handler returns, might might already have
1774 a step-resume breakpoint set on the earlier handler. We cannot
1775 set another step-resume breakpoint; just continue on until the
1776 original breakpoint is hit. */
1777 if (tp->control.step_resume_breakpoint == NULL)
1779 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1780 tp->step_after_step_resume_breakpoint = 1;
1783 remove_single_step_breakpoints ();
1784 singlestep_breakpoints_inserted_p = 0;
1786 insert_breakpoints ();
1787 tp->control.trap_expected = 0;
1794 /* If STEP is set, it's a request to use hardware stepping
1795 facilities. But in that case, we should never
1796 use singlestep breakpoint. */
1797 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
1799 /* Decide the set of threads to ask the target to resume. Start
1800 by assuming everything will be resumed, than narrow the set
1801 by applying increasingly restricting conditions. */
1802 resume_ptid = user_visible_resume_ptid (step);
1804 /* Maybe resume a single thread after all. */
1805 if (singlestep_breakpoints_inserted_p
1806 && stepping_past_singlestep_breakpoint)
1808 /* The situation here is as follows. In thread T1 we wanted to
1809 single-step. Lacking hardware single-stepping we've
1810 set breakpoint at the PC of the next instruction -- call it
1811 P. After resuming, we've hit that breakpoint in thread T2.
1812 Now we've removed original breakpoint, inserted breakpoint
1813 at P+1, and try to step to advance T2 past breakpoint.
1814 We need to step only T2, as if T1 is allowed to freely run,
1815 it can run past P, and if other threads are allowed to run,
1816 they can hit breakpoint at P+1, and nested hits of single-step
1817 breakpoints is not something we'd want -- that's complicated
1818 to support, and has no value. */
1819 resume_ptid = inferior_ptid;
1821 else if ((step || singlestep_breakpoints_inserted_p)
1822 && tp->control.trap_expected)
1824 /* We're allowing a thread to run past a breakpoint it has
1825 hit, by single-stepping the thread with the breakpoint
1826 removed. In which case, we need to single-step only this
1827 thread, and keep others stopped, as they can miss this
1828 breakpoint if allowed to run.
1830 The current code actually removes all breakpoints when
1831 doing this, not just the one being stepped over, so if we
1832 let other threads run, we can actually miss any
1833 breakpoint, not just the one at PC. */
1834 resume_ptid = inferior_ptid;
1837 if (gdbarch_cannot_step_breakpoint (gdbarch))
1839 /* Most targets can step a breakpoint instruction, thus
1840 executing it normally. But if this one cannot, just
1841 continue and we will hit it anyway. */
1842 if (step && breakpoint_inserted_here_p (aspace, pc))
1847 && use_displaced_stepping (gdbarch)
1848 && tp->control.trap_expected)
1850 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
1851 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
1852 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
1855 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1856 paddress (resume_gdbarch, actual_pc));
1857 read_memory (actual_pc, buf, sizeof (buf));
1858 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1861 /* Install inferior's terminal modes. */
1862 target_terminal_inferior ();
1864 /* Avoid confusing the next resume, if the next stop/resume
1865 happens to apply to another thread. */
1866 tp->suspend.stop_signal = TARGET_SIGNAL_0;
1868 /* Advise target which signals may be handled silently. If we have
1869 removed breakpoints because we are stepping over one (which can
1870 happen only if we are not using displaced stepping), we need to
1871 receive all signals to avoid accidentally skipping a breakpoint
1872 during execution of a signal handler. */
1873 if ((step || singlestep_breakpoints_inserted_p)
1874 && tp->control.trap_expected
1875 && !use_displaced_stepping (gdbarch))
1876 target_pass_signals (0, NULL);
1878 target_pass_signals ((int) TARGET_SIGNAL_LAST, signal_pass);
1880 target_resume (resume_ptid, step, sig);
1883 discard_cleanups (old_cleanups);
1888 /* Clear out all variables saying what to do when inferior is continued.
1889 First do this, then set the ones you want, then call `proceed'. */
1892 clear_proceed_status_thread (struct thread_info *tp)
1895 fprintf_unfiltered (gdb_stdlog,
1896 "infrun: clear_proceed_status_thread (%s)\n",
1897 target_pid_to_str (tp->ptid));
1899 tp->control.trap_expected = 0;
1900 tp->control.step_range_start = 0;
1901 tp->control.step_range_end = 0;
1902 tp->control.step_frame_id = null_frame_id;
1903 tp->control.step_stack_frame_id = null_frame_id;
1904 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
1905 tp->stop_requested = 0;
1907 tp->control.stop_step = 0;
1909 tp->control.proceed_to_finish = 0;
1911 /* Discard any remaining commands or status from previous stop. */
1912 bpstat_clear (&tp->control.stop_bpstat);
1916 clear_proceed_status_callback (struct thread_info *tp, void *data)
1918 if (is_exited (tp->ptid))
1921 clear_proceed_status_thread (tp);
1926 clear_proceed_status (void)
1930 /* In all-stop mode, delete the per-thread status of all
1931 threads, even if inferior_ptid is null_ptid, there may be
1932 threads on the list. E.g., we may be launching a new
1933 process, while selecting the executable. */
1934 iterate_over_threads (clear_proceed_status_callback, NULL);
1937 if (!ptid_equal (inferior_ptid, null_ptid))
1939 struct inferior *inferior;
1943 /* If in non-stop mode, only delete the per-thread status of
1944 the current thread. */
1945 clear_proceed_status_thread (inferior_thread ());
1948 inferior = current_inferior ();
1949 inferior->control.stop_soon = NO_STOP_QUIETLY;
1952 stop_after_trap = 0;
1954 observer_notify_about_to_proceed ();
1958 regcache_xfree (stop_registers);
1959 stop_registers = NULL;
1963 /* Check the current thread against the thread that reported the most recent
1964 event. If a step-over is required return TRUE and set the current thread
1965 to the old thread. Otherwise return FALSE.
1967 This should be suitable for any targets that support threads. */
1970 prepare_to_proceed (int step)
1973 struct target_waitstatus wait_status;
1974 int schedlock_enabled;
1976 /* With non-stop mode on, threads are always handled individually. */
1977 gdb_assert (! non_stop);
1979 /* Get the last target status returned by target_wait(). */
1980 get_last_target_status (&wait_ptid, &wait_status);
1982 /* Make sure we were stopped at a breakpoint. */
1983 if (wait_status.kind != TARGET_WAITKIND_STOPPED
1984 || (wait_status.value.sig != TARGET_SIGNAL_TRAP
1985 && wait_status.value.sig != TARGET_SIGNAL_ILL
1986 && wait_status.value.sig != TARGET_SIGNAL_SEGV
1987 && wait_status.value.sig != TARGET_SIGNAL_EMT))
1992 schedlock_enabled = (scheduler_mode == schedlock_on
1993 || (scheduler_mode == schedlock_step
1996 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
1997 if (schedlock_enabled)
2000 /* Don't switch over if we're about to resume some other process
2001 other than WAIT_PTID's, and schedule-multiple is off. */
2003 && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid))
2006 /* Switched over from WAIT_PID. */
2007 if (!ptid_equal (wait_ptid, minus_one_ptid)
2008 && !ptid_equal (inferior_ptid, wait_ptid))
2010 struct regcache *regcache = get_thread_regcache (wait_ptid);
2012 if (breakpoint_here_p (get_regcache_aspace (regcache),
2013 regcache_read_pc (regcache)))
2015 /* If stepping, remember current thread to switch back to. */
2017 deferred_step_ptid = inferior_ptid;
2019 /* Switch back to WAIT_PID thread. */
2020 switch_to_thread (wait_ptid);
2023 fprintf_unfiltered (gdb_stdlog,
2024 "infrun: prepare_to_proceed (step=%d), "
2025 "switched to [%s]\n",
2026 step, target_pid_to_str (inferior_ptid));
2028 /* We return 1 to indicate that there is a breakpoint here,
2029 so we need to step over it before continuing to avoid
2030 hitting it straight away. */
2038 /* Basic routine for continuing the program in various fashions.
2040 ADDR is the address to resume at, or -1 for resume where stopped.
2041 SIGGNAL is the signal to give it, or 0 for none,
2042 or -1 for act according to how it stopped.
2043 STEP is nonzero if should trap after one instruction.
2044 -1 means return after that and print nothing.
2045 You should probably set various step_... variables
2046 before calling here, if you are stepping.
2048 You should call clear_proceed_status before calling proceed. */
2051 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
2053 struct regcache *regcache;
2054 struct gdbarch *gdbarch;
2055 struct thread_info *tp;
2057 struct address_space *aspace;
2060 /* If we're stopped at a fork/vfork, follow the branch set by the
2061 "set follow-fork-mode" command; otherwise, we'll just proceed
2062 resuming the current thread. */
2063 if (!follow_fork ())
2065 /* The target for some reason decided not to resume. */
2067 if (target_can_async_p ())
2068 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2072 /* We'll update this if & when we switch to a new thread. */
2073 previous_inferior_ptid = inferior_ptid;
2075 regcache = get_current_regcache ();
2076 gdbarch = get_regcache_arch (regcache);
2077 aspace = get_regcache_aspace (regcache);
2078 pc = regcache_read_pc (regcache);
2081 step_start_function = find_pc_function (pc);
2083 stop_after_trap = 1;
2085 if (addr == (CORE_ADDR) -1)
2087 if (pc == stop_pc && breakpoint_here_p (aspace, pc)
2088 && execution_direction != EXEC_REVERSE)
2089 /* There is a breakpoint at the address we will resume at,
2090 step one instruction before inserting breakpoints so that
2091 we do not stop right away (and report a second hit at this
2094 Note, we don't do this in reverse, because we won't
2095 actually be executing the breakpoint insn anyway.
2096 We'll be (un-)executing the previous instruction. */
2099 else if (gdbarch_single_step_through_delay_p (gdbarch)
2100 && gdbarch_single_step_through_delay (gdbarch,
2101 get_current_frame ()))
2102 /* We stepped onto an instruction that needs to be stepped
2103 again before re-inserting the breakpoint, do so. */
2108 regcache_write_pc (regcache, addr);
2112 fprintf_unfiltered (gdb_stdlog,
2113 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
2114 paddress (gdbarch, addr), siggnal, step);
2117 /* In non-stop, each thread is handled individually. The context
2118 must already be set to the right thread here. */
2122 /* In a multi-threaded task we may select another thread and
2123 then continue or step.
2125 But if the old thread was stopped at a breakpoint, it will
2126 immediately cause another breakpoint stop without any
2127 execution (i.e. it will report a breakpoint hit incorrectly).
2128 So we must step over it first.
2130 prepare_to_proceed checks the current thread against the
2131 thread that reported the most recent event. If a step-over
2132 is required it returns TRUE and sets the current thread to
2134 if (prepare_to_proceed (step))
2138 /* prepare_to_proceed may change the current thread. */
2139 tp = inferior_thread ();
2143 tp->control.trap_expected = 1;
2144 /* If displaced stepping is enabled, we can step over the
2145 breakpoint without hitting it, so leave all breakpoints
2146 inserted. Otherwise we need to disable all breakpoints, step
2147 one instruction, and then re-add them when that step is
2149 if (!use_displaced_stepping (gdbarch))
2150 remove_breakpoints ();
2153 /* We can insert breakpoints if we're not trying to step over one,
2154 or if we are stepping over one but we're using displaced stepping
2156 if (! tp->control.trap_expected || use_displaced_stepping (gdbarch))
2157 insert_breakpoints ();
2161 /* Pass the last stop signal to the thread we're resuming,
2162 irrespective of whether the current thread is the thread that
2163 got the last event or not. This was historically GDB's
2164 behaviour before keeping a stop_signal per thread. */
2166 struct thread_info *last_thread;
2168 struct target_waitstatus last_status;
2170 get_last_target_status (&last_ptid, &last_status);
2171 if (!ptid_equal (inferior_ptid, last_ptid)
2172 && !ptid_equal (last_ptid, null_ptid)
2173 && !ptid_equal (last_ptid, minus_one_ptid))
2175 last_thread = find_thread_ptid (last_ptid);
2178 tp->suspend.stop_signal = last_thread->suspend.stop_signal;
2179 last_thread->suspend.stop_signal = TARGET_SIGNAL_0;
2184 if (siggnal != TARGET_SIGNAL_DEFAULT)
2185 tp->suspend.stop_signal = siggnal;
2186 /* If this signal should not be seen by program,
2187 give it zero. Used for debugging signals. */
2188 else if (!signal_program[tp->suspend.stop_signal])
2189 tp->suspend.stop_signal = TARGET_SIGNAL_0;
2191 annotate_starting ();
2193 /* Make sure that output from GDB appears before output from the
2195 gdb_flush (gdb_stdout);
2197 /* Refresh prev_pc value just prior to resuming. This used to be
2198 done in stop_stepping, however, setting prev_pc there did not handle
2199 scenarios such as inferior function calls or returning from
2200 a function via the return command. In those cases, the prev_pc
2201 value was not set properly for subsequent commands. The prev_pc value
2202 is used to initialize the starting line number in the ecs. With an
2203 invalid value, the gdb next command ends up stopping at the position
2204 represented by the next line table entry past our start position.
2205 On platforms that generate one line table entry per line, this
2206 is not a problem. However, on the ia64, the compiler generates
2207 extraneous line table entries that do not increase the line number.
2208 When we issue the gdb next command on the ia64 after an inferior call
2209 or a return command, we often end up a few instructions forward, still
2210 within the original line we started.
2212 An attempt was made to refresh the prev_pc at the same time the
2213 execution_control_state is initialized (for instance, just before
2214 waiting for an inferior event). But this approach did not work
2215 because of platforms that use ptrace, where the pc register cannot
2216 be read unless the inferior is stopped. At that point, we are not
2217 guaranteed the inferior is stopped and so the regcache_read_pc() call
2218 can fail. Setting the prev_pc value here ensures the value is updated
2219 correctly when the inferior is stopped. */
2220 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2222 /* Fill in with reasonable starting values. */
2223 init_thread_stepping_state (tp);
2225 /* Reset to normal state. */
2226 init_infwait_state ();
2228 /* Resume inferior. */
2229 resume (oneproc || step || bpstat_should_step (), tp->suspend.stop_signal);
2231 /* Wait for it to stop (if not standalone)
2232 and in any case decode why it stopped, and act accordingly. */
2233 /* Do this only if we are not using the event loop, or if the target
2234 does not support asynchronous execution. */
2235 if (!target_can_async_p ())
2237 wait_for_inferior ();
2243 /* Start remote-debugging of a machine over a serial link. */
2246 start_remote (int from_tty)
2248 struct inferior *inferior;
2250 inferior = current_inferior ();
2251 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2253 /* Always go on waiting for the target, regardless of the mode. */
2254 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2255 indicate to wait_for_inferior that a target should timeout if
2256 nothing is returned (instead of just blocking). Because of this,
2257 targets expecting an immediate response need to, internally, set
2258 things up so that the target_wait() is forced to eventually
2260 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2261 differentiate to its caller what the state of the target is after
2262 the initial open has been performed. Here we're assuming that
2263 the target has stopped. It should be possible to eventually have
2264 target_open() return to the caller an indication that the target
2265 is currently running and GDB state should be set to the same as
2266 for an async run. */
2267 wait_for_inferior ();
2269 /* Now that the inferior has stopped, do any bookkeeping like
2270 loading shared libraries. We want to do this before normal_stop,
2271 so that the displayed frame is up to date. */
2272 post_create_inferior (¤t_target, from_tty);
2277 /* Initialize static vars when a new inferior begins. */
2280 init_wait_for_inferior (void)
2282 /* These are meaningless until the first time through wait_for_inferior. */
2284 breakpoint_init_inferior (inf_starting);
2286 clear_proceed_status ();
2288 stepping_past_singlestep_breakpoint = 0;
2289 deferred_step_ptid = null_ptid;
2291 target_last_wait_ptid = minus_one_ptid;
2293 previous_inferior_ptid = inferior_ptid;
2294 init_infwait_state ();
2296 /* Discard any skipped inlined frames. */
2297 clear_inline_frame_state (minus_one_ptid);
2301 /* This enum encodes possible reasons for doing a target_wait, so that
2302 wfi can call target_wait in one place. (Ultimately the call will be
2303 moved out of the infinite loop entirely.) */
2307 infwait_normal_state,
2308 infwait_thread_hop_state,
2309 infwait_step_watch_state,
2310 infwait_nonstep_watch_state
2313 /* The PTID we'll do a target_wait on.*/
2316 /* Current inferior wait state. */
2317 enum infwait_states infwait_state;
2319 /* Data to be passed around while handling an event. This data is
2320 discarded between events. */
2321 struct execution_control_state
2324 /* The thread that got the event, if this was a thread event; NULL
2326 struct thread_info *event_thread;
2328 struct target_waitstatus ws;
2330 int stop_func_filled_in;
2331 CORE_ADDR stop_func_start;
2332 CORE_ADDR stop_func_end;
2333 char *stop_func_name;
2334 int new_thread_event;
2338 static void handle_inferior_event (struct execution_control_state *ecs);
2340 static void handle_step_into_function (struct gdbarch *gdbarch,
2341 struct execution_control_state *ecs);
2342 static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2343 struct execution_control_state *ecs);
2344 static void check_exception_resume (struct execution_control_state *,
2345 struct frame_info *, struct symbol *);
2347 static void stop_stepping (struct execution_control_state *ecs);
2348 static void prepare_to_wait (struct execution_control_state *ecs);
2349 static void keep_going (struct execution_control_state *ecs);
2351 /* Callback for iterate over threads. If the thread is stopped, but
2352 the user/frontend doesn't know about that yet, go through
2353 normal_stop, as if the thread had just stopped now. ARG points at
2354 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2355 ptid_is_pid(PTID) is true, applies to all threads of the process
2356 pointed at by PTID. Otherwise, apply only to the thread pointed by
2360 infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2362 ptid_t ptid = * (ptid_t *) arg;
2364 if ((ptid_equal (info->ptid, ptid)
2365 || ptid_equal (minus_one_ptid, ptid)
2366 || (ptid_is_pid (ptid)
2367 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2368 && is_running (info->ptid)
2369 && !is_executing (info->ptid))
2371 struct cleanup *old_chain;
2372 struct execution_control_state ecss;
2373 struct execution_control_state *ecs = &ecss;
2375 memset (ecs, 0, sizeof (*ecs));
2377 old_chain = make_cleanup_restore_current_thread ();
2379 switch_to_thread (info->ptid);
2381 /* Go through handle_inferior_event/normal_stop, so we always
2382 have consistent output as if the stop event had been
2384 ecs->ptid = info->ptid;
2385 ecs->event_thread = find_thread_ptid (info->ptid);
2386 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2387 ecs->ws.value.sig = TARGET_SIGNAL_0;
2389 handle_inferior_event (ecs);
2391 if (!ecs->wait_some_more)
2393 struct thread_info *tp;
2397 /* Finish off the continuations. */
2398 tp = inferior_thread ();
2399 do_all_intermediate_continuations_thread (tp, 1);
2400 do_all_continuations_thread (tp, 1);
2403 do_cleanups (old_chain);
2409 /* This function is attached as a "thread_stop_requested" observer.
2410 Cleanup local state that assumed the PTID was to be resumed, and
2411 report the stop to the frontend. */
2414 infrun_thread_stop_requested (ptid_t ptid)
2416 struct displaced_step_inferior_state *displaced;
2418 /* PTID was requested to stop. Remove it from the displaced
2419 stepping queue, so we don't try to resume it automatically. */
2421 for (displaced = displaced_step_inferior_states;
2423 displaced = displaced->next)
2425 struct displaced_step_request *it, **prev_next_p;
2427 it = displaced->step_request_queue;
2428 prev_next_p = &displaced->step_request_queue;
2431 if (ptid_match (it->ptid, ptid))
2433 *prev_next_p = it->next;
2439 prev_next_p = &it->next;
2446 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2450 infrun_thread_thread_exit (struct thread_info *tp, int silent)
2452 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2453 nullify_last_target_wait_ptid ();
2456 /* Callback for iterate_over_threads. */
2459 delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
2461 if (is_exited (info->ptid))
2464 delete_step_resume_breakpoint (info);
2465 delete_exception_resume_breakpoint (info);
2469 /* In all-stop, delete the step resume breakpoint of any thread that
2470 had one. In non-stop, delete the step resume breakpoint of the
2471 thread that just stopped. */
2474 delete_step_thread_step_resume_breakpoint (void)
2476 if (!target_has_execution
2477 || ptid_equal (inferior_ptid, null_ptid))
2478 /* If the inferior has exited, we have already deleted the step
2479 resume breakpoints out of GDB's lists. */
2484 /* If in non-stop mode, only delete the step-resume or
2485 longjmp-resume breakpoint of the thread that just stopped
2487 struct thread_info *tp = inferior_thread ();
2489 delete_step_resume_breakpoint (tp);
2490 delete_exception_resume_breakpoint (tp);
2493 /* In all-stop mode, delete all step-resume and longjmp-resume
2494 breakpoints of any thread that had them. */
2495 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
2498 /* A cleanup wrapper. */
2501 delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
2503 delete_step_thread_step_resume_breakpoint ();
2506 /* Pretty print the results of target_wait, for debugging purposes. */
2509 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
2510 const struct target_waitstatus *ws)
2512 char *status_string = target_waitstatus_to_string (ws);
2513 struct ui_file *tmp_stream = mem_fileopen ();
2516 /* The text is split over several lines because it was getting too long.
2517 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2518 output as a unit; we want only one timestamp printed if debug_timestamp
2521 fprintf_unfiltered (tmp_stream,
2522 "infrun: target_wait (%d", PIDGET (waiton_ptid));
2523 if (PIDGET (waiton_ptid) != -1)
2524 fprintf_unfiltered (tmp_stream,
2525 " [%s]", target_pid_to_str (waiton_ptid));
2526 fprintf_unfiltered (tmp_stream, ", status) =\n");
2527 fprintf_unfiltered (tmp_stream,
2528 "infrun: %d [%s],\n",
2529 PIDGET (result_ptid), target_pid_to_str (result_ptid));
2530 fprintf_unfiltered (tmp_stream,
2534 text = ui_file_xstrdup (tmp_stream, NULL);
2536 /* This uses %s in part to handle %'s in the text, but also to avoid
2537 a gcc error: the format attribute requires a string literal. */
2538 fprintf_unfiltered (gdb_stdlog, "%s", text);
2540 xfree (status_string);
2542 ui_file_delete (tmp_stream);
2545 /* Prepare and stabilize the inferior for detaching it. E.g.,
2546 detaching while a thread is displaced stepping is a recipe for
2547 crashing it, as nothing would readjust the PC out of the scratch
2551 prepare_for_detach (void)
2553 struct inferior *inf = current_inferior ();
2554 ptid_t pid_ptid = pid_to_ptid (inf->pid);
2555 struct cleanup *old_chain_1;
2556 struct displaced_step_inferior_state *displaced;
2558 displaced = get_displaced_stepping_state (inf->pid);
2560 /* Is any thread of this process displaced stepping? If not,
2561 there's nothing else to do. */
2562 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
2566 fprintf_unfiltered (gdb_stdlog,
2567 "displaced-stepping in-process while detaching");
2569 old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
2572 while (!ptid_equal (displaced->step_ptid, null_ptid))
2574 struct cleanup *old_chain_2;
2575 struct execution_control_state ecss;
2576 struct execution_control_state *ecs;
2579 memset (ecs, 0, sizeof (*ecs));
2581 overlay_cache_invalid = 1;
2583 if (deprecated_target_wait_hook)
2584 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
2586 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
2589 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
2591 /* If an error happens while handling the event, propagate GDB's
2592 knowledge of the executing state to the frontend/user running
2594 old_chain_2 = make_cleanup (finish_thread_state_cleanup,
2597 /* In non-stop mode, each thread is handled individually.
2598 Switch early, so the global state is set correctly for this
2601 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2602 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2603 context_switch (ecs->ptid);
2605 /* Now figure out what to do with the result of the result. */
2606 handle_inferior_event (ecs);
2608 /* No error, don't finish the state yet. */
2609 discard_cleanups (old_chain_2);
2611 /* Breakpoints and watchpoints are not installed on the target
2612 at this point, and signals are passed directly to the
2613 inferior, so this must mean the process is gone. */
2614 if (!ecs->wait_some_more)
2616 discard_cleanups (old_chain_1);
2617 error (_("Program exited while detaching"));
2621 discard_cleanups (old_chain_1);
2624 /* Wait for control to return from inferior to debugger.
2626 If inferior gets a signal, we may decide to start it up again
2627 instead of returning. That is why there is a loop in this function.
2628 When this function actually returns it means the inferior
2629 should be left stopped and GDB should read more commands. */
2632 wait_for_inferior (void)
2634 struct cleanup *old_cleanups;
2635 struct execution_control_state ecss;
2636 struct execution_control_state *ecs;
2640 (gdb_stdlog, "infrun: wait_for_inferior ()\n");
2643 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
2646 memset (ecs, 0, sizeof (*ecs));
2650 struct cleanup *old_chain;
2652 overlay_cache_invalid = 1;
2654 if (deprecated_target_wait_hook)
2655 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
2657 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
2660 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2662 /* If an error happens while handling the event, propagate GDB's
2663 knowledge of the executing state to the frontend/user running
2665 old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2667 if (ecs->ws.kind == TARGET_WAITKIND_SYSCALL_ENTRY
2668 || ecs->ws.kind == TARGET_WAITKIND_SYSCALL_RETURN)
2669 ecs->ws.value.syscall_number = UNKNOWN_SYSCALL;
2671 /* Now figure out what to do with the result of the result. */
2672 handle_inferior_event (ecs);
2674 /* No error, don't finish the state yet. */
2675 discard_cleanups (old_chain);
2677 if (!ecs->wait_some_more)
2681 do_cleanups (old_cleanups);
2684 /* Asynchronous version of wait_for_inferior. It is called by the
2685 event loop whenever a change of state is detected on the file
2686 descriptor corresponding to the target. It can be called more than
2687 once to complete a single execution command. In such cases we need
2688 to keep the state in a global variable ECSS. If it is the last time
2689 that this function is called for a single execution command, then
2690 report to the user that the inferior has stopped, and do the
2691 necessary cleanups. */
2694 fetch_inferior_event (void *client_data)
2696 struct execution_control_state ecss;
2697 struct execution_control_state *ecs = &ecss;
2698 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
2699 struct cleanup *ts_old_chain;
2700 int was_sync = sync_execution;
2703 memset (ecs, 0, sizeof (*ecs));
2705 /* We're handling a live event, so make sure we're doing live
2706 debugging. If we're looking at traceframes while the target is
2707 running, we're going to need to get back to that mode after
2708 handling the event. */
2711 make_cleanup_restore_current_traceframe ();
2712 set_current_traceframe (-1);
2716 /* In non-stop mode, the user/frontend should not notice a thread
2717 switch due to internal events. Make sure we reverse to the
2718 user selected thread and frame after handling the event and
2719 running any breakpoint commands. */
2720 make_cleanup_restore_current_thread ();
2722 overlay_cache_invalid = 1;
2724 make_cleanup_restore_integer (&execution_direction);
2725 execution_direction = target_execution_direction ();
2727 if (deprecated_target_wait_hook)
2729 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2731 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2734 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2737 && ecs->ws.kind != TARGET_WAITKIND_IGNORE
2738 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2739 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2740 /* In non-stop mode, each thread is handled individually. Switch
2741 early, so the global state is set correctly for this
2743 context_switch (ecs->ptid);
2745 /* If an error happens while handling the event, propagate GDB's
2746 knowledge of the executing state to the frontend/user running
2749 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2751 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
2753 /* Get executed before make_cleanup_restore_current_thread above to apply
2754 still for the thread which has thrown the exception. */
2755 make_bpstat_clear_actions_cleanup ();
2757 /* Now figure out what to do with the result of the result. */
2758 handle_inferior_event (ecs);
2760 if (!ecs->wait_some_more)
2762 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2764 delete_step_thread_step_resume_breakpoint ();
2766 /* We may not find an inferior if this was a process exit. */
2767 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
2770 if (target_has_execution
2771 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2772 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2773 && ecs->event_thread->step_multi
2774 && ecs->event_thread->control.stop_step)
2775 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
2778 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2783 /* No error, don't finish the thread states yet. */
2784 discard_cleanups (ts_old_chain);
2786 /* Revert thread and frame. */
2787 do_cleanups (old_chain);
2789 /* If the inferior was in sync execution mode, and now isn't,
2790 restore the prompt (a synchronous execution command has finished,
2791 and we're ready for input). */
2792 if (interpreter_async && was_sync && !sync_execution)
2793 display_gdb_prompt (0);
2797 && exec_done_display_p
2798 && (ptid_equal (inferior_ptid, null_ptid)
2799 || !is_running (inferior_ptid)))
2800 printf_unfiltered (_("completed.\n"));
2803 /* Record the frame and location we're currently stepping through. */
2805 set_step_info (struct frame_info *frame, struct symtab_and_line sal)
2807 struct thread_info *tp = inferior_thread ();
2809 tp->control.step_frame_id = get_frame_id (frame);
2810 tp->control.step_stack_frame_id = get_stack_frame_id (frame);
2812 tp->current_symtab = sal.symtab;
2813 tp->current_line = sal.line;
2816 /* Clear context switchable stepping state. */
2819 init_thread_stepping_state (struct thread_info *tss)
2821 tss->stepping_over_breakpoint = 0;
2822 tss->step_after_step_resume_breakpoint = 0;
2825 /* Return the cached copy of the last pid/waitstatus returned by
2826 target_wait()/deprecated_target_wait_hook(). The data is actually
2827 cached by handle_inferior_event(), which gets called immediately
2828 after target_wait()/deprecated_target_wait_hook(). */
2831 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
2833 *ptidp = target_last_wait_ptid;
2834 *status = target_last_waitstatus;
2838 nullify_last_target_wait_ptid (void)
2840 target_last_wait_ptid = minus_one_ptid;
2843 /* Switch thread contexts. */
2846 context_switch (ptid_t ptid)
2850 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
2851 target_pid_to_str (inferior_ptid));
2852 fprintf_unfiltered (gdb_stdlog, "to %s\n",
2853 target_pid_to_str (ptid));
2856 switch_to_thread (ptid);
2860 adjust_pc_after_break (struct execution_control_state *ecs)
2862 struct regcache *regcache;
2863 struct gdbarch *gdbarch;
2864 struct address_space *aspace;
2865 CORE_ADDR breakpoint_pc;
2867 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2868 we aren't, just return.
2870 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2871 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2872 implemented by software breakpoints should be handled through the normal
2875 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2876 different signals (SIGILL or SIGEMT for instance), but it is less
2877 clear where the PC is pointing afterwards. It may not match
2878 gdbarch_decr_pc_after_break. I don't know any specific target that
2879 generates these signals at breakpoints (the code has been in GDB since at
2880 least 1992) so I can not guess how to handle them here.
2882 In earlier versions of GDB, a target with
2883 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2884 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2885 target with both of these set in GDB history, and it seems unlikely to be
2886 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2888 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
2891 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
2894 /* In reverse execution, when a breakpoint is hit, the instruction
2895 under it has already been de-executed. The reported PC always
2896 points at the breakpoint address, so adjusting it further would
2897 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2900 B1 0x08000000 : INSN1
2901 B2 0x08000001 : INSN2
2903 PC -> 0x08000003 : INSN4
2905 Say you're stopped at 0x08000003 as above. Reverse continuing
2906 from that point should hit B2 as below. Reading the PC when the
2907 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2908 been de-executed already.
2910 B1 0x08000000 : INSN1
2911 B2 PC -> 0x08000001 : INSN2
2915 We can't apply the same logic as for forward execution, because
2916 we would wrongly adjust the PC to 0x08000000, since there's a
2917 breakpoint at PC - 1. We'd then report a hit on B1, although
2918 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2920 if (execution_direction == EXEC_REVERSE)
2923 /* If this target does not decrement the PC after breakpoints, then
2924 we have nothing to do. */
2925 regcache = get_thread_regcache (ecs->ptid);
2926 gdbarch = get_regcache_arch (regcache);
2927 if (gdbarch_decr_pc_after_break (gdbarch) == 0)
2930 aspace = get_regcache_aspace (regcache);
2932 /* Find the location where (if we've hit a breakpoint) the
2933 breakpoint would be. */
2934 breakpoint_pc = regcache_read_pc (regcache)
2935 - gdbarch_decr_pc_after_break (gdbarch);
2937 /* Check whether there actually is a software breakpoint inserted at
2940 If in non-stop mode, a race condition is possible where we've
2941 removed a breakpoint, but stop events for that breakpoint were
2942 already queued and arrive later. To suppress those spurious
2943 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2944 and retire them after a number of stop events are reported. */
2945 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
2946 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
2948 struct cleanup *old_cleanups = NULL;
2951 old_cleanups = record_gdb_operation_disable_set ();
2953 /* When using hardware single-step, a SIGTRAP is reported for both
2954 a completed single-step and a software breakpoint. Need to
2955 differentiate between the two, as the latter needs adjusting
2956 but the former does not.
2958 The SIGTRAP can be due to a completed hardware single-step only if
2959 - we didn't insert software single-step breakpoints
2960 - the thread to be examined is still the current thread
2961 - this thread is currently being stepped
2963 If any of these events did not occur, we must have stopped due
2964 to hitting a software breakpoint, and have to back up to the
2967 As a special case, we could have hardware single-stepped a
2968 software breakpoint. In this case (prev_pc == breakpoint_pc),
2969 we also need to back up to the breakpoint address. */
2971 if (singlestep_breakpoints_inserted_p
2972 || !ptid_equal (ecs->ptid, inferior_ptid)
2973 || !currently_stepping (ecs->event_thread)
2974 || ecs->event_thread->prev_pc == breakpoint_pc)
2975 regcache_write_pc (regcache, breakpoint_pc);
2978 do_cleanups (old_cleanups);
2983 init_infwait_state (void)
2985 waiton_ptid = pid_to_ptid (-1);
2986 infwait_state = infwait_normal_state;
2990 error_is_running (void)
2992 error (_("Cannot execute this command while "
2993 "the selected thread is running."));
2997 ensure_not_running (void)
2999 if (is_running (inferior_ptid))
3000 error_is_running ();
3004 stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
3006 for (frame = get_prev_frame (frame);
3008 frame = get_prev_frame (frame))
3010 if (frame_id_eq (get_frame_id (frame), step_frame_id))
3012 if (get_frame_type (frame) != INLINE_FRAME)
3019 /* Auxiliary function that handles syscall entry/return events.
3020 It returns 1 if the inferior should keep going (and GDB
3021 should ignore the event), or 0 if the event deserves to be
3025 handle_syscall_event (struct execution_control_state *ecs)
3027 struct regcache *regcache;
3028 struct gdbarch *gdbarch;
3031 if (!ptid_equal (ecs->ptid, inferior_ptid))
3032 context_switch (ecs->ptid);
3034 regcache = get_thread_regcache (ecs->ptid);
3035 gdbarch = get_regcache_arch (regcache);
3036 syscall_number = gdbarch_get_syscall_number (gdbarch, ecs->ptid);
3037 stop_pc = regcache_read_pc (regcache);
3039 target_last_waitstatus.value.syscall_number = syscall_number;
3041 if (catch_syscall_enabled () > 0
3042 && catching_syscall_number (syscall_number) > 0)
3045 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
3048 ecs->event_thread->control.stop_bpstat
3049 = bpstat_stop_status (get_regcache_aspace (regcache),
3050 stop_pc, ecs->ptid);
3052 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
3054 if (!ecs->random_signal)
3056 /* Catchpoint hit. */
3057 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3062 /* If no catchpoint triggered for this, then keep going. */
3063 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3068 /* Clear the supplied execution_control_state's stop_func_* fields. */
3071 clear_stop_func (struct execution_control_state *ecs)
3073 ecs->stop_func_filled_in = 0;
3074 ecs->stop_func_start = 0;
3075 ecs->stop_func_end = 0;
3076 ecs->stop_func_name = NULL;
3079 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3082 fill_in_stop_func (struct gdbarch *gdbarch,
3083 struct execution_control_state *ecs)
3085 if (!ecs->stop_func_filled_in)
3087 /* Don't care about return value; stop_func_start and stop_func_name
3088 will both be 0 if it doesn't work. */
3089 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3090 &ecs->stop_func_start, &ecs->stop_func_end);
3091 ecs->stop_func_start
3092 += gdbarch_deprecated_function_start_offset (gdbarch);
3094 ecs->stop_func_filled_in = 1;
3098 /* Given an execution control state that has been freshly filled in
3099 by an event from the inferior, figure out what it means and take
3100 appropriate action. */
3103 handle_inferior_event (struct execution_control_state *ecs)
3105 struct frame_info *frame;
3106 struct gdbarch *gdbarch;
3107 int stopped_by_watchpoint;
3108 int stepped_after_stopped_by_watchpoint = 0;
3109 struct symtab_and_line stop_pc_sal;
3110 enum stop_kind stop_soon;
3112 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
3114 /* We had an event in the inferior, but we are not interested in
3115 handling it at this level. The lower layers have already
3116 done what needs to be done, if anything.
3118 One of the possible circumstances for this is when the
3119 inferior produces output for the console. The inferior has
3120 not stopped, and we are ignoring the event. Another possible
3121 circumstance is any event which the lower level knows will be
3122 reported multiple times without an intervening resume. */
3124 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
3125 prepare_to_wait (ecs);
3129 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3130 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
3132 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
3135 stop_soon = inf->control.stop_soon;
3138 stop_soon = NO_STOP_QUIETLY;
3140 /* Cache the last pid/waitstatus. */
3141 target_last_wait_ptid = ecs->ptid;
3142 target_last_waitstatus = ecs->ws;
3144 /* Always clear state belonging to the previous time we stopped. */
3145 stop_stack_dummy = STOP_NONE;
3147 /* If it's a new process, add it to the thread database. */
3149 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
3150 && !ptid_equal (ecs->ptid, minus_one_ptid)
3151 && !in_thread_list (ecs->ptid));
3153 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3154 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
3155 add_thread (ecs->ptid);
3157 ecs->event_thread = find_thread_ptid (ecs->ptid);
3159 /* Dependent on valid ECS->EVENT_THREAD. */
3160 adjust_pc_after_break (ecs);
3162 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3163 reinit_frame_cache ();
3165 breakpoint_retire_moribund ();
3167 /* First, distinguish signals caused by the debugger from signals
3168 that have to do with the program's own actions. Note that
3169 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3170 on the operating system version. Here we detect when a SIGILL or
3171 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3172 something similar for SIGSEGV, since a SIGSEGV will be generated
3173 when we're trying to execute a breakpoint instruction on a
3174 non-executable stack. This happens for call dummy breakpoints
3175 for architectures like SPARC that place call dummies on the
3177 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
3178 && (ecs->ws.value.sig == TARGET_SIGNAL_ILL
3179 || ecs->ws.value.sig == TARGET_SIGNAL_SEGV
3180 || ecs->ws.value.sig == TARGET_SIGNAL_EMT))
3182 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3184 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3185 regcache_read_pc (regcache)))
3188 fprintf_unfiltered (gdb_stdlog,
3189 "infrun: Treating signal as SIGTRAP\n");
3190 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
3194 /* Mark the non-executing threads accordingly. In all-stop, all
3195 threads of all processes are stopped when we get any event
3196 reported. In non-stop mode, only the event thread stops. If
3197 we're handling a process exit in non-stop mode, there's nothing
3198 to do, as threads of the dead process are gone, and threads of
3199 any other process were left running. */
3201 set_executing (minus_one_ptid, 0);
3202 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3203 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
3204 set_executing (inferior_ptid, 0);
3206 switch (infwait_state)
3208 case infwait_thread_hop_state:
3210 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
3213 case infwait_normal_state:
3215 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
3218 case infwait_step_watch_state:
3220 fprintf_unfiltered (gdb_stdlog,
3221 "infrun: infwait_step_watch_state\n");
3223 stepped_after_stopped_by_watchpoint = 1;
3226 case infwait_nonstep_watch_state:
3228 fprintf_unfiltered (gdb_stdlog,
3229 "infrun: infwait_nonstep_watch_state\n");
3230 insert_breakpoints ();
3232 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3233 handle things like signals arriving and other things happening
3234 in combination correctly? */
3235 stepped_after_stopped_by_watchpoint = 1;
3239 internal_error (__FILE__, __LINE__, _("bad switch"));
3242 infwait_state = infwait_normal_state;
3243 waiton_ptid = pid_to_ptid (-1);
3245 switch (ecs->ws.kind)
3247 case TARGET_WAITKIND_LOADED:
3249 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
3250 /* Ignore gracefully during startup of the inferior, as it might
3251 be the shell which has just loaded some objects, otherwise
3252 add the symbols for the newly loaded objects. Also ignore at
3253 the beginning of an attach or remote session; we will query
3254 the full list of libraries once the connection is
3256 if (stop_soon == NO_STOP_QUIETLY)
3258 /* Check for any newly added shared libraries if we're
3259 supposed to be adding them automatically. Switch
3260 terminal for any messages produced by
3261 breakpoint_re_set. */
3262 target_terminal_ours_for_output ();
3263 /* NOTE: cagney/2003-11-25: Make certain that the target
3264 stack's section table is kept up-to-date. Architectures,
3265 (e.g., PPC64), use the section table to perform
3266 operations such as address => section name and hence
3267 require the table to contain all sections (including
3268 those found in shared libraries). */
3270 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
3272 solib_add (NULL, 0, ¤t_target, auto_solib_add);
3274 target_terminal_inferior ();
3276 /* If requested, stop when the dynamic linker notifies
3277 gdb of events. This allows the user to get control
3278 and place breakpoints in initializer routines for
3279 dynamically loaded objects (among other things). */
3280 if (stop_on_solib_events)
3282 /* Make sure we print "Stopped due to solib-event" in
3284 stop_print_frame = 1;
3286 stop_stepping (ecs);
3290 /* NOTE drow/2007-05-11: This might be a good place to check
3291 for "catch load". */
3294 /* If we are skipping through a shell, or through shared library
3295 loading that we aren't interested in, resume the program. If
3296 we're running the program normally, also resume. But stop if
3297 we're attaching or setting up a remote connection. */
3298 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
3300 /* Loading of shared libraries might have changed breakpoint
3301 addresses. Make sure new breakpoints are inserted. */
3302 if (stop_soon == NO_STOP_QUIETLY
3303 && !breakpoints_always_inserted_mode ())
3304 insert_breakpoints ();
3305 resume (0, TARGET_SIGNAL_0);
3306 prepare_to_wait (ecs);
3312 case TARGET_WAITKIND_SPURIOUS:
3314 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3315 resume (0, TARGET_SIGNAL_0);
3316 prepare_to_wait (ecs);
3319 case TARGET_WAITKIND_EXITED:
3321 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
3322 inferior_ptid = ecs->ptid;
3323 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3324 set_current_program_space (current_inferior ()->pspace);
3325 handle_vfork_child_exec_or_exit (0);
3326 target_terminal_ours (); /* Must do this before mourn anyway. */
3327 print_exited_reason (ecs->ws.value.integer);
3329 /* Record the exit code in the convenience variable $_exitcode, so
3330 that the user can inspect this again later. */
3331 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3332 (LONGEST) ecs->ws.value.integer);
3334 /* Also record this in the inferior itself. */
3335 current_inferior ()->has_exit_code = 1;
3336 current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer;
3338 gdb_flush (gdb_stdout);
3339 target_mourn_inferior ();
3340 singlestep_breakpoints_inserted_p = 0;
3341 cancel_single_step_breakpoints ();
3342 stop_print_frame = 0;
3343 stop_stepping (ecs);
3346 case TARGET_WAITKIND_SIGNALLED:
3348 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n");
3349 inferior_ptid = ecs->ptid;
3350 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3351 set_current_program_space (current_inferior ()->pspace);
3352 handle_vfork_child_exec_or_exit (0);
3353 stop_print_frame = 0;
3354 target_terminal_ours (); /* Must do this before mourn anyway. */
3356 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
3357 reach here unless the inferior is dead. However, for years
3358 target_kill() was called here, which hints that fatal signals aren't
3359 really fatal on some systems. If that's true, then some changes
3361 target_mourn_inferior ();
3363 print_signal_exited_reason (ecs->ws.value.sig);
3364 singlestep_breakpoints_inserted_p = 0;
3365 cancel_single_step_breakpoints ();
3366 stop_stepping (ecs);
3369 /* The following are the only cases in which we keep going;
3370 the above cases end in a continue or goto. */
3371 case TARGET_WAITKIND_FORKED:
3372 case TARGET_WAITKIND_VFORKED:
3374 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3376 if (!ptid_equal (ecs->ptid, inferior_ptid))
3378 context_switch (ecs->ptid);
3379 reinit_frame_cache ();
3382 /* Immediately detach breakpoints from the child before there's
3383 any chance of letting the user delete breakpoints from the
3384 breakpoint lists. If we don't do this early, it's easy to
3385 leave left over traps in the child, vis: "break foo; catch
3386 fork; c; <fork>; del; c; <child calls foo>". We only follow
3387 the fork on the last `continue', and by that time the
3388 breakpoint at "foo" is long gone from the breakpoint table.
3389 If we vforked, then we don't need to unpatch here, since both
3390 parent and child are sharing the same memory pages; we'll
3391 need to unpatch at follow/detach time instead to be certain
3392 that new breakpoints added between catchpoint hit time and
3393 vfork follow are detached. */
3394 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
3396 int child_pid = ptid_get_pid (ecs->ws.value.related_pid);
3398 /* This won't actually modify the breakpoint list, but will
3399 physically remove the breakpoints from the child. */
3400 detach_breakpoints (child_pid);
3403 if (singlestep_breakpoints_inserted_p)
3405 /* Pull the single step breakpoints out of the target. */
3406 remove_single_step_breakpoints ();
3407 singlestep_breakpoints_inserted_p = 0;
3410 /* In case the event is caught by a catchpoint, remember that
3411 the event is to be followed at the next resume of the thread,
3412 and not immediately. */
3413 ecs->event_thread->pending_follow = ecs->ws;
3415 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3417 ecs->event_thread->control.stop_bpstat
3418 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3419 stop_pc, ecs->ptid);
3421 /* Note that we're interested in knowing the bpstat actually
3422 causes a stop, not just if it may explain the signal.
3423 Software watchpoints, for example, always appear in the
3426 = !bpstat_causes_stop (ecs->event_thread->control.stop_bpstat);
3428 /* If no catchpoint triggered for this, then keep going. */
3429 if (ecs->random_signal)
3435 = (follow_fork_mode_string == follow_fork_mode_child);
3437 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3439 should_resume = follow_fork ();
3442 child = ecs->ws.value.related_pid;
3444 /* In non-stop mode, also resume the other branch. */
3445 if (non_stop && !detach_fork)
3448 switch_to_thread (parent);
3450 switch_to_thread (child);
3452 ecs->event_thread = inferior_thread ();
3453 ecs->ptid = inferior_ptid;
3458 switch_to_thread (child);
3460 switch_to_thread (parent);
3462 ecs->event_thread = inferior_thread ();
3463 ecs->ptid = inferior_ptid;
3468 stop_stepping (ecs);
3471 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3472 goto process_event_stop_test;
3474 case TARGET_WAITKIND_VFORK_DONE:
3475 /* Done with the shared memory region. Re-insert breakpoints in
3476 the parent, and keep going. */
3479 fprintf_unfiltered (gdb_stdlog,
3480 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3482 if (!ptid_equal (ecs->ptid, inferior_ptid))
3483 context_switch (ecs->ptid);
3485 current_inferior ()->waiting_for_vfork_done = 0;
3486 current_inferior ()->pspace->breakpoints_not_allowed = 0;
3487 /* This also takes care of reinserting breakpoints in the
3488 previously locked inferior. */
3492 case TARGET_WAITKIND_EXECD:
3494 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
3496 if (!ptid_equal (ecs->ptid, inferior_ptid))
3498 context_switch (ecs->ptid);
3499 reinit_frame_cache ();
3502 singlestep_breakpoints_inserted_p = 0;
3503 cancel_single_step_breakpoints ();
3505 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3507 /* Do whatever is necessary to the parent branch of the vfork. */
3508 handle_vfork_child_exec_or_exit (1);
3510 /* This causes the eventpoints and symbol table to be reset.
3511 Must do this now, before trying to determine whether to
3513 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
3515 ecs->event_thread->control.stop_bpstat
3516 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3517 stop_pc, ecs->ptid);
3519 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
3521 /* Note that this may be referenced from inside
3522 bpstat_stop_status above, through inferior_has_execd. */
3523 xfree (ecs->ws.value.execd_pathname);
3524 ecs->ws.value.execd_pathname = NULL;
3526 /* If no catchpoint triggered for this, then keep going. */
3527 if (ecs->random_signal)
3529 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3533 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3534 goto process_event_stop_test;
3536 /* Be careful not to try to gather much state about a thread
3537 that's in a syscall. It's frequently a losing proposition. */
3538 case TARGET_WAITKIND_SYSCALL_ENTRY:
3540 fprintf_unfiltered (gdb_stdlog,
3541 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3542 /* Getting the current syscall number. */
3543 if (handle_syscall_event (ecs) != 0)
3545 goto process_event_stop_test;
3547 /* Before examining the threads further, step this thread to
3548 get it entirely out of the syscall. (We get notice of the
3549 event when the thread is just on the verge of exiting a
3550 syscall. Stepping one instruction seems to get it back
3552 case TARGET_WAITKIND_SYSCALL_RETURN:
3554 fprintf_unfiltered (gdb_stdlog,
3555 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3556 if (handle_syscall_event (ecs) != 0)
3558 goto process_event_stop_test;
3560 case TARGET_WAITKIND_STOPPED:
3562 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
3563 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
3566 case TARGET_WAITKIND_NO_HISTORY:
3567 /* Reverse execution: target ran out of history info. */
3568 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3569 print_no_history_reason ();
3570 stop_stepping (ecs);
3574 if (ecs->new_thread_event)
3577 /* Non-stop assumes that the target handles adding new threads
3578 to the thread list. */
3579 internal_error (__FILE__, __LINE__,
3580 "targets should add new threads to the thread "
3581 "list themselves in non-stop mode.");
3583 /* We may want to consider not doing a resume here in order to
3584 give the user a chance to play with the new thread. It might
3585 be good to make that a user-settable option. */
3587 /* At this point, all threads are stopped (happens automatically
3588 in either the OS or the native code). Therefore we need to
3589 continue all threads in order to make progress. */
3591 if (!ptid_equal (ecs->ptid, inferior_ptid))
3592 context_switch (ecs->ptid);
3593 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
3594 prepare_to_wait (ecs);
3598 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
3600 /* Do we need to clean up the state of a thread that has
3601 completed a displaced single-step? (Doing so usually affects
3602 the PC, so do it here, before we set stop_pc.) */
3603 displaced_step_fixup (ecs->ptid,
3604 ecs->event_thread->suspend.stop_signal);
3606 /* If we either finished a single-step or hit a breakpoint, but
3607 the user wanted this thread to be stopped, pretend we got a
3608 SIG0 (generic unsignaled stop). */
3610 if (ecs->event_thread->stop_requested
3611 && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3612 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3615 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3619 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3620 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3621 struct cleanup *old_chain = save_inferior_ptid ();
3623 inferior_ptid = ecs->ptid;
3625 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
3626 paddress (gdbarch, stop_pc));
3627 if (target_stopped_by_watchpoint ())
3631 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
3633 if (target_stopped_data_address (¤t_target, &addr))
3634 fprintf_unfiltered (gdb_stdlog,
3635 "infrun: stopped data address = %s\n",
3636 paddress (gdbarch, addr));
3638 fprintf_unfiltered (gdb_stdlog,
3639 "infrun: (no data address available)\n");
3642 do_cleanups (old_chain);
3645 if (stepping_past_singlestep_breakpoint)
3647 gdb_assert (singlestep_breakpoints_inserted_p);
3648 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
3649 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
3651 stepping_past_singlestep_breakpoint = 0;
3653 /* We've either finished single-stepping past the single-step
3654 breakpoint, or stopped for some other reason. It would be nice if
3655 we could tell, but we can't reliably. */
3656 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3659 fprintf_unfiltered (gdb_stdlog,
3660 "infrun: stepping_past_"
3661 "singlestep_breakpoint\n");
3662 /* Pull the single step breakpoints out of the target. */
3663 remove_single_step_breakpoints ();
3664 singlestep_breakpoints_inserted_p = 0;
3666 ecs->random_signal = 0;
3667 ecs->event_thread->control.trap_expected = 0;
3669 context_switch (saved_singlestep_ptid);
3670 if (deprecated_context_hook)
3671 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3673 resume (1, TARGET_SIGNAL_0);
3674 prepare_to_wait (ecs);
3679 if (!ptid_equal (deferred_step_ptid, null_ptid))
3681 /* In non-stop mode, there's never a deferred_step_ptid set. */
3682 gdb_assert (!non_stop);
3684 /* If we stopped for some other reason than single-stepping, ignore
3685 the fact that we were supposed to switch back. */
3686 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3689 fprintf_unfiltered (gdb_stdlog,
3690 "infrun: handling deferred step\n");
3692 /* Pull the single step breakpoints out of the target. */
3693 if (singlestep_breakpoints_inserted_p)
3695 remove_single_step_breakpoints ();
3696 singlestep_breakpoints_inserted_p = 0;
3699 ecs->event_thread->control.trap_expected = 0;
3701 /* Note: We do not call context_switch at this point, as the
3702 context is already set up for stepping the original thread. */
3703 switch_to_thread (deferred_step_ptid);
3704 deferred_step_ptid = null_ptid;
3705 /* Suppress spurious "Switching to ..." message. */
3706 previous_inferior_ptid = inferior_ptid;
3708 resume (1, TARGET_SIGNAL_0);
3709 prepare_to_wait (ecs);
3713 deferred_step_ptid = null_ptid;
3716 /* See if a thread hit a thread-specific breakpoint that was meant for
3717 another thread. If so, then step that thread past the breakpoint,
3720 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3722 int thread_hop_needed = 0;
3723 struct address_space *aspace =
3724 get_regcache_aspace (get_thread_regcache (ecs->ptid));
3726 /* Check if a regular breakpoint has been hit before checking
3727 for a potential single step breakpoint. Otherwise, GDB will
3728 not see this breakpoint hit when stepping onto breakpoints. */
3729 if (regular_breakpoint_inserted_here_p (aspace, stop_pc))
3731 ecs->random_signal = 0;
3732 if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid))
3733 thread_hop_needed = 1;
3735 else if (singlestep_breakpoints_inserted_p)
3737 /* We have not context switched yet, so this should be true
3738 no matter which thread hit the singlestep breakpoint. */
3739 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
3741 fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
3743 target_pid_to_str (ecs->ptid));
3745 ecs->random_signal = 0;
3746 /* The call to in_thread_list is necessary because PTIDs sometimes
3747 change when we go from single-threaded to multi-threaded. If
3748 the singlestep_ptid is still in the list, assume that it is
3749 really different from ecs->ptid. */
3750 if (!ptid_equal (singlestep_ptid, ecs->ptid)
3751 && in_thread_list (singlestep_ptid))
3753 /* If the PC of the thread we were trying to single-step
3754 has changed, discard this event (which we were going
3755 to ignore anyway), and pretend we saw that thread
3756 trap. This prevents us continuously moving the
3757 single-step breakpoint forward, one instruction at a
3758 time. If the PC has changed, then the thread we were
3759 trying to single-step has trapped or been signalled,
3760 but the event has not been reported to GDB yet.
3762 There might be some cases where this loses signal
3763 information, if a signal has arrived at exactly the
3764 same time that the PC changed, but this is the best
3765 we can do with the information available. Perhaps we
3766 should arrange to report all events for all threads
3767 when they stop, or to re-poll the remote looking for
3768 this particular thread (i.e. temporarily enable
3771 CORE_ADDR new_singlestep_pc
3772 = regcache_read_pc (get_thread_regcache (singlestep_ptid));
3774 if (new_singlestep_pc != singlestep_pc)
3776 enum target_signal stop_signal;
3779 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
3780 " but expected thread advanced also\n");
3782 /* The current context still belongs to
3783 singlestep_ptid. Don't swap here, since that's
3784 the context we want to use. Just fudge our
3785 state and continue. */
3786 stop_signal = ecs->event_thread->suspend.stop_signal;
3787 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3788 ecs->ptid = singlestep_ptid;
3789 ecs->event_thread = find_thread_ptid (ecs->ptid);
3790 ecs->event_thread->suspend.stop_signal = stop_signal;
3791 stop_pc = new_singlestep_pc;
3796 fprintf_unfiltered (gdb_stdlog,
3797 "infrun: unexpected thread\n");
3799 thread_hop_needed = 1;
3800 stepping_past_singlestep_breakpoint = 1;
3801 saved_singlestep_ptid = singlestep_ptid;
3806 if (thread_hop_needed)
3808 struct regcache *thread_regcache;
3809 int remove_status = 0;
3812 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
3814 /* Switch context before touching inferior memory, the
3815 previous thread may have exited. */
3816 if (!ptid_equal (inferior_ptid, ecs->ptid))
3817 context_switch (ecs->ptid);
3819 /* Saw a breakpoint, but it was hit by the wrong thread.
3822 if (singlestep_breakpoints_inserted_p)
3824 /* Pull the single step breakpoints out of the target. */
3825 remove_single_step_breakpoints ();
3826 singlestep_breakpoints_inserted_p = 0;
3829 /* If the arch can displace step, don't remove the
3831 thread_regcache = get_thread_regcache (ecs->ptid);
3832 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
3833 remove_status = remove_breakpoints ();
3835 /* Did we fail to remove breakpoints? If so, try
3836 to set the PC past the bp. (There's at least
3837 one situation in which we can fail to remove
3838 the bp's: On HP-UX's that use ttrace, we can't
3839 change the address space of a vforking child
3840 process until the child exits (well, okay, not
3841 then either :-) or execs. */
3842 if (remove_status != 0)
3843 error (_("Cannot step over breakpoint hit in wrong thread"));
3848 /* Only need to require the next event from this
3849 thread in all-stop mode. */
3850 waiton_ptid = ecs->ptid;
3851 infwait_state = infwait_thread_hop_state;
3854 ecs->event_thread->stepping_over_breakpoint = 1;
3859 else if (singlestep_breakpoints_inserted_p)
3861 ecs->random_signal = 0;
3865 ecs->random_signal = 1;
3867 /* See if something interesting happened to the non-current thread. If
3868 so, then switch to that thread. */
3869 if (!ptid_equal (ecs->ptid, inferior_ptid))
3872 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
3874 context_switch (ecs->ptid);
3876 if (deprecated_context_hook)
3877 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3880 /* At this point, get hold of the now-current thread's frame. */
3881 frame = get_current_frame ();
3882 gdbarch = get_frame_arch (frame);
3884 if (singlestep_breakpoints_inserted_p)
3886 /* Pull the single step breakpoints out of the target. */
3887 remove_single_step_breakpoints ();
3888 singlestep_breakpoints_inserted_p = 0;
3891 if (stepped_after_stopped_by_watchpoint)
3892 stopped_by_watchpoint = 0;
3894 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
3896 /* If necessary, step over this watchpoint. We'll be back to display
3898 if (stopped_by_watchpoint
3899 && (target_have_steppable_watchpoint
3900 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
3902 /* At this point, we are stopped at an instruction which has
3903 attempted to write to a piece of memory under control of
3904 a watchpoint. The instruction hasn't actually executed
3905 yet. If we were to evaluate the watchpoint expression
3906 now, we would get the old value, and therefore no change
3907 would seem to have occurred.
3909 In order to make watchpoints work `right', we really need
3910 to complete the memory write, and then evaluate the
3911 watchpoint expression. We do this by single-stepping the
3914 It may not be necessary to disable the watchpoint to stop over
3915 it. For example, the PA can (with some kernel cooperation)
3916 single step over a watchpoint without disabling the watchpoint.
3918 It is far more common to need to disable a watchpoint to step
3919 the inferior over it. If we have non-steppable watchpoints,
3920 we must disable the current watchpoint; it's simplest to
3921 disable all watchpoints and breakpoints. */
3924 if (!target_have_steppable_watchpoint)
3926 remove_breakpoints ();
3927 /* See comment in resume why we need to stop bypassing signals
3928 while breakpoints have been removed. */
3929 target_pass_signals (0, NULL);
3932 hw_step = maybe_software_singlestep (gdbarch, stop_pc);
3933 target_resume (ecs->ptid, hw_step, TARGET_SIGNAL_0);
3934 waiton_ptid = ecs->ptid;
3935 if (target_have_steppable_watchpoint)
3936 infwait_state = infwait_step_watch_state;
3938 infwait_state = infwait_nonstep_watch_state;
3939 prepare_to_wait (ecs);
3943 clear_stop_func (ecs);
3944 ecs->event_thread->stepping_over_breakpoint = 0;
3945 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
3946 ecs->event_thread->control.stop_step = 0;
3947 stop_print_frame = 1;
3948 ecs->random_signal = 0;
3949 stopped_by_random_signal = 0;
3951 /* Hide inlined functions starting here, unless we just performed stepi or
3952 nexti. After stepi and nexti, always show the innermost frame (not any
3953 inline function call sites). */
3954 if (ecs->event_thread->control.step_range_end != 1)
3955 skip_inline_frames (ecs->ptid);
3957 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3958 && ecs->event_thread->control.trap_expected
3959 && gdbarch_single_step_through_delay_p (gdbarch)
3960 && currently_stepping (ecs->event_thread))
3962 /* We're trying to step off a breakpoint. Turns out that we're
3963 also on an instruction that needs to be stepped multiple
3964 times before it's been fully executing. E.g., architectures
3965 with a delay slot. It needs to be stepped twice, once for
3966 the instruction and once for the delay slot. */
3967 int step_through_delay
3968 = gdbarch_single_step_through_delay (gdbarch, frame);
3970 if (debug_infrun && step_through_delay)
3971 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
3972 if (ecs->event_thread->control.step_range_end == 0
3973 && step_through_delay)
3975 /* The user issued a continue when stopped at a breakpoint.
3976 Set up for another trap and get out of here. */
3977 ecs->event_thread->stepping_over_breakpoint = 1;
3981 else if (step_through_delay)
3983 /* The user issued a step when stopped at a breakpoint.
3984 Maybe we should stop, maybe we should not - the delay
3985 slot *might* correspond to a line of source. In any
3986 case, don't decide that here, just set
3987 ecs->stepping_over_breakpoint, making sure we
3988 single-step again before breakpoints are re-inserted. */
3989 ecs->event_thread->stepping_over_breakpoint = 1;
3993 /* Look at the cause of the stop, and decide what to do.
3994 The alternatives are:
3995 1) stop_stepping and return; to really stop and return to the debugger,
3996 2) keep_going and return to start up again
3997 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
3998 3) set ecs->random_signal to 1, and the decision between 1 and 2
3999 will be made according to the signal handling tables. */
4001 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
4002 || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP
4003 || stop_soon == STOP_QUIETLY_REMOTE)
4005 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
4009 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
4010 stop_print_frame = 0;
4011 stop_stepping (ecs);
4015 /* This is originated from start_remote(), start_inferior() and
4016 shared libraries hook functions. */
4017 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
4020 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
4021 stop_stepping (ecs);
4025 /* This originates from attach_command(). We need to overwrite
4026 the stop_signal here, because some kernels don't ignore a
4027 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4028 See more comments in inferior.h. On the other hand, if we
4029 get a non-SIGSTOP, report it to the user - assume the backend
4030 will handle the SIGSTOP if it should show up later.
4032 Also consider that the attach is complete when we see a
4033 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4034 target extended-remote report it instead of a SIGSTOP
4035 (e.g. gdbserver). We already rely on SIGTRAP being our
4036 signal, so this is no exception.
4038 Also consider that the attach is complete when we see a
4039 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4040 the target to stop all threads of the inferior, in case the
4041 low level attach operation doesn't stop them implicitly. If
4042 they weren't stopped implicitly, then the stub will report a
4043 TARGET_SIGNAL_0, meaning: stopped for no particular reason
4044 other than GDB's request. */
4045 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
4046 && (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_STOP
4047 || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
4048 || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_0))
4050 stop_stepping (ecs);
4051 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
4055 /* See if there is a breakpoint at the current PC. */
4056 ecs->event_thread->control.stop_bpstat
4057 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4058 stop_pc, ecs->ptid);
4060 /* Following in case break condition called a
4062 stop_print_frame = 1;
4064 /* This is where we handle "moribund" watchpoints. Unlike
4065 software breakpoints traps, hardware watchpoint traps are
4066 always distinguishable from random traps. If no high-level
4067 watchpoint is associated with the reported stop data address
4068 anymore, then the bpstat does not explain the signal ---
4069 simply make sure to ignore it if `stopped_by_watchpoint' is
4073 && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
4074 && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat)
4075 && stopped_by_watchpoint)
4076 fprintf_unfiltered (gdb_stdlog,
4077 "infrun: no user watchpoint explains "
4078 "watchpoint SIGTRAP, ignoring\n");
4080 /* NOTE: cagney/2003-03-29: These two checks for a random signal
4081 at one stage in the past included checks for an inferior
4082 function call's call dummy's return breakpoint. The original
4083 comment, that went with the test, read:
4085 ``End of a stack dummy. Some systems (e.g. Sony news) give
4086 another signal besides SIGTRAP, so check here as well as
4089 If someone ever tries to get call dummys on a
4090 non-executable stack to work (where the target would stop
4091 with something like a SIGSEGV), then those tests might need
4092 to be re-instated. Given, however, that the tests were only
4093 enabled when momentary breakpoints were not being used, I
4094 suspect that it won't be the case.
4096 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4097 be necessary for call dummies on a non-executable stack on
4100 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
4102 = !(bpstat_explains_signal (ecs->event_thread->control.stop_bpstat)
4103 || stopped_by_watchpoint
4104 || ecs->event_thread->control.trap_expected
4105 || (ecs->event_thread->control.step_range_end
4106 && (ecs->event_thread->control.step_resume_breakpoint
4110 ecs->random_signal = !bpstat_explains_signal
4111 (ecs->event_thread->control.stop_bpstat);
4112 if (!ecs->random_signal)
4113 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
4117 /* When we reach this point, we've pretty much decided
4118 that the reason for stopping must've been a random
4119 (unexpected) signal. */
4122 ecs->random_signal = 1;
4124 process_event_stop_test:
4126 /* Re-fetch current thread's frame in case we did a
4127 "goto process_event_stop_test" above. */
4128 frame = get_current_frame ();
4129 gdbarch = get_frame_arch (frame);
4131 /* For the program's own signals, act according to
4132 the signal handling tables. */
4134 if (ecs->random_signal)
4136 /* Signal not for debugging purposes. */
4138 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
4141 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
4142 ecs->event_thread->suspend.stop_signal);
4144 stopped_by_random_signal = 1;
4146 if (signal_print[ecs->event_thread->suspend.stop_signal])
4149 target_terminal_ours_for_output ();
4150 print_signal_received_reason
4151 (ecs->event_thread->suspend.stop_signal);
4153 /* Always stop on signals if we're either just gaining control
4154 of the program, or the user explicitly requested this thread
4155 to remain stopped. */
4156 if (stop_soon != NO_STOP_QUIETLY
4157 || ecs->event_thread->stop_requested
4159 && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
4161 stop_stepping (ecs);
4164 /* If not going to stop, give terminal back
4165 if we took it away. */
4167 target_terminal_inferior ();
4169 /* Clear the signal if it should not be passed. */
4170 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
4171 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
4173 if (ecs->event_thread->prev_pc == stop_pc
4174 && ecs->event_thread->control.trap_expected
4175 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4177 /* We were just starting a new sequence, attempting to
4178 single-step off of a breakpoint and expecting a SIGTRAP.
4179 Instead this signal arrives. This signal will take us out
4180 of the stepping range so GDB needs to remember to, when
4181 the signal handler returns, resume stepping off that
4183 /* To simplify things, "continue" is forced to use the same
4184 code paths as single-step - set a breakpoint at the
4185 signal return address and then, once hit, step off that
4188 fprintf_unfiltered (gdb_stdlog,
4189 "infrun: signal arrived while stepping over "
4192 insert_hp_step_resume_breakpoint_at_frame (frame);
4193 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4194 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4195 ecs->event_thread->control.trap_expected = 0;
4200 if (ecs->event_thread->control.step_range_end != 0
4201 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_0
4202 && (ecs->event_thread->control.step_range_start <= stop_pc
4203 && stop_pc < ecs->event_thread->control.step_range_end)
4204 && frame_id_eq (get_stack_frame_id (frame),
4205 ecs->event_thread->control.step_stack_frame_id)
4206 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4208 /* The inferior is about to take a signal that will take it
4209 out of the single step range. Set a breakpoint at the
4210 current PC (which is presumably where the signal handler
4211 will eventually return) and then allow the inferior to
4214 Note that this is only needed for a signal delivered
4215 while in the single-step range. Nested signals aren't a
4216 problem as they eventually all return. */
4218 fprintf_unfiltered (gdb_stdlog,
4219 "infrun: signal may take us out of "
4220 "single-step range\n");
4222 insert_hp_step_resume_breakpoint_at_frame (frame);
4223 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4224 ecs->event_thread->control.trap_expected = 0;
4229 /* Note: step_resume_breakpoint may be non-NULL. This occures
4230 when either there's a nested signal, or when there's a
4231 pending signal enabled just as the signal handler returns
4232 (leaving the inferior at the step-resume-breakpoint without
4233 actually executing it). Either way continue until the
4234 breakpoint is really hit. */
4239 /* Handle cases caused by hitting a breakpoint. */
4241 CORE_ADDR jmp_buf_pc;
4242 struct bpstat_what what;
4244 what = bpstat_what (ecs->event_thread->control.stop_bpstat);
4246 if (what.call_dummy)
4248 stop_stack_dummy = what.call_dummy;
4251 /* If we hit an internal event that triggers symbol changes, the
4252 current frame will be invalidated within bpstat_what (e.g., if
4253 we hit an internal solib event). Re-fetch it. */
4254 frame = get_current_frame ();
4255 gdbarch = get_frame_arch (frame);
4257 switch (what.main_action)
4259 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
4260 /* If we hit the breakpoint at longjmp while stepping, we
4261 install a momentary breakpoint at the target of the
4265 fprintf_unfiltered (gdb_stdlog,
4266 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4268 ecs->event_thread->stepping_over_breakpoint = 1;
4270 if (what.is_longjmp)
4272 if (!gdbarch_get_longjmp_target_p (gdbarch)
4273 || !gdbarch_get_longjmp_target (gdbarch,
4274 frame, &jmp_buf_pc))
4277 fprintf_unfiltered (gdb_stdlog,
4278 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4279 "(!gdbarch_get_longjmp_target)\n");
4284 /* We're going to replace the current step-resume breakpoint
4285 with a longjmp-resume breakpoint. */
4286 delete_step_resume_breakpoint (ecs->event_thread);
4288 /* Insert a breakpoint at resume address. */
4289 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4293 struct symbol *func = get_frame_function (frame);
4296 check_exception_resume (ecs, frame, func);
4301 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4303 fprintf_unfiltered (gdb_stdlog,
4304 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4306 if (what.is_longjmp)
4308 gdb_assert (ecs->event_thread->control.step_resume_breakpoint
4310 delete_step_resume_breakpoint (ecs->event_thread);
4314 /* There are several cases to consider.
4316 1. The initiating frame no longer exists. In this case
4317 we must stop, because the exception has gone too far.
4319 2. The initiating frame exists, and is the same as the
4320 current frame. We stop, because the exception has been
4323 3. The initiating frame exists and is different from
4324 the current frame. This means the exception has been
4325 caught beneath the initiating frame, so keep going. */
4326 struct frame_info *init_frame
4327 = frame_find_by_id (ecs->event_thread->initiating_frame);
4329 gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
4331 delete_exception_resume_breakpoint (ecs->event_thread);
4335 struct frame_id current_id
4336 = get_frame_id (get_current_frame ());
4337 if (frame_id_eq (current_id,
4338 ecs->event_thread->initiating_frame))
4340 /* Case 2. Fall through. */
4350 /* For Cases 1 and 2, remove the step-resume breakpoint,
4352 delete_step_resume_breakpoint (ecs->event_thread);
4355 ecs->event_thread->control.stop_step = 1;
4356 print_end_stepping_range_reason ();
4357 stop_stepping (ecs);
4360 case BPSTAT_WHAT_SINGLE:
4362 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
4363 ecs->event_thread->stepping_over_breakpoint = 1;
4364 /* Still need to check other stuff, at least the case
4365 where we are stepping and step out of the right range. */
4368 case BPSTAT_WHAT_STEP_RESUME:
4370 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4372 delete_step_resume_breakpoint (ecs->event_thread);
4373 if (ecs->event_thread->control.proceed_to_finish
4374 && execution_direction == EXEC_REVERSE)
4376 struct thread_info *tp = ecs->event_thread;
4378 /* We are finishing a function in reverse, and just hit
4379 the step-resume breakpoint at the start address of the
4380 function, and we're almost there -- just need to back
4381 up by one more single-step, which should take us back
4382 to the function call. */
4383 tp->control.step_range_start = tp->control.step_range_end = 1;
4387 fill_in_stop_func (gdbarch, ecs);
4388 if (stop_pc == ecs->stop_func_start
4389 && execution_direction == EXEC_REVERSE)
4391 /* We are stepping over a function call in reverse, and
4392 just hit the step-resume breakpoint at the start
4393 address of the function. Go back to single-stepping,
4394 which should take us back to the function call. */
4395 ecs->event_thread->stepping_over_breakpoint = 1;
4401 case BPSTAT_WHAT_STOP_NOISY:
4403 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4404 stop_print_frame = 1;
4406 /* We are about to nuke the step_resume_breakpointt via the
4407 cleanup chain, so no need to worry about it here. */
4409 stop_stepping (ecs);
4412 case BPSTAT_WHAT_STOP_SILENT:
4414 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4415 stop_print_frame = 0;
4417 /* We are about to nuke the step_resume_breakpoin via the
4418 cleanup chain, so no need to worry about it here. */
4420 stop_stepping (ecs);
4423 case BPSTAT_WHAT_HP_STEP_RESUME:
4425 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4427 delete_step_resume_breakpoint (ecs->event_thread);
4428 if (ecs->event_thread->step_after_step_resume_breakpoint)
4430 /* Back when the step-resume breakpoint was inserted, we
4431 were trying to single-step off a breakpoint. Go back
4433 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4434 ecs->event_thread->stepping_over_breakpoint = 1;
4440 case BPSTAT_WHAT_KEEP_CHECKING:
4445 /* We come here if we hit a breakpoint but should not
4446 stop for it. Possibly we also were stepping
4447 and should stop for that. So fall through and
4448 test for stepping. But, if not stepping,
4451 /* In all-stop mode, if we're currently stepping but have stopped in
4452 some other thread, we need to switch back to the stepped thread. */
4455 struct thread_info *tp;
4457 tp = iterate_over_threads (currently_stepping_or_nexting_callback,
4461 /* However, if the current thread is blocked on some internal
4462 breakpoint, and we simply need to step over that breakpoint
4463 to get it going again, do that first. */
4464 if ((ecs->event_thread->control.trap_expected
4465 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP)
4466 || ecs->event_thread->stepping_over_breakpoint)
4472 /* If the stepping thread exited, then don't try to switch
4473 back and resume it, which could fail in several different
4474 ways depending on the target. Instead, just keep going.
4476 We can find a stepping dead thread in the thread list in
4479 - The target supports thread exit events, and when the
4480 target tries to delete the thread from the thread list,
4481 inferior_ptid pointed at the exiting thread. In such
4482 case, calling delete_thread does not really remove the
4483 thread from the list; instead, the thread is left listed,
4484 with 'exited' state.
4486 - The target's debug interface does not support thread
4487 exit events, and so we have no idea whatsoever if the
4488 previously stepping thread is still alive. For that
4489 reason, we need to synchronously query the target
4491 if (is_exited (tp->ptid)
4492 || !target_thread_alive (tp->ptid))
4495 fprintf_unfiltered (gdb_stdlog,
4496 "infrun: not switching back to "
4497 "stepped thread, it has vanished\n");
4499 delete_thread (tp->ptid);
4504 /* Otherwise, we no longer expect a trap in the current thread.
4505 Clear the trap_expected flag before switching back -- this is
4506 what keep_going would do as well, if we called it. */
4507 ecs->event_thread->control.trap_expected = 0;
4510 fprintf_unfiltered (gdb_stdlog,
4511 "infrun: switching back to stepped thread\n");
4513 ecs->event_thread = tp;
4514 ecs->ptid = tp->ptid;
4515 context_switch (ecs->ptid);
4521 if (ecs->event_thread->control.step_resume_breakpoint)
4524 fprintf_unfiltered (gdb_stdlog,
4525 "infrun: step-resume breakpoint is inserted\n");
4527 /* Having a step-resume breakpoint overrides anything
4528 else having to do with stepping commands until
4529 that breakpoint is reached. */
4534 if (ecs->event_thread->control.step_range_end == 0)
4537 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
4538 /* Likewise if we aren't even stepping. */
4543 /* Re-fetch current thread's frame in case the code above caused
4544 the frame cache to be re-initialized, making our FRAME variable
4545 a dangling pointer. */
4546 frame = get_current_frame ();
4547 gdbarch = get_frame_arch (frame);
4548 fill_in_stop_func (gdbarch, ecs);
4550 /* If stepping through a line, keep going if still within it.
4552 Note that step_range_end is the address of the first instruction
4553 beyond the step range, and NOT the address of the last instruction
4556 Note also that during reverse execution, we may be stepping
4557 through a function epilogue and therefore must detect when
4558 the current-frame changes in the middle of a line. */
4560 if (stop_pc >= ecs->event_thread->control.step_range_start
4561 && stop_pc < ecs->event_thread->control.step_range_end
4562 && (execution_direction != EXEC_REVERSE
4563 || frame_id_eq (get_frame_id (frame),
4564 ecs->event_thread->control.step_frame_id)))
4568 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
4569 paddress (gdbarch, ecs->event_thread->control.step_range_start),
4570 paddress (gdbarch, ecs->event_thread->control.step_range_end));
4572 /* When stepping backward, stop at beginning of line range
4573 (unless it's the function entry point, in which case
4574 keep going back to the call point). */
4575 if (stop_pc == ecs->event_thread->control.step_range_start
4576 && stop_pc != ecs->stop_func_start
4577 && execution_direction == EXEC_REVERSE)
4579 ecs->event_thread->control.stop_step = 1;
4580 print_end_stepping_range_reason ();
4581 stop_stepping (ecs);
4589 /* We stepped out of the stepping range. */
4591 /* If we are stepping at the source level and entered the runtime
4592 loader dynamic symbol resolution code...
4594 EXEC_FORWARD: we keep on single stepping until we exit the run
4595 time loader code and reach the callee's address.
4597 EXEC_REVERSE: we've already executed the callee (backward), and
4598 the runtime loader code is handled just like any other
4599 undebuggable function call. Now we need only keep stepping
4600 backward through the trampoline code, and that's handled further
4601 down, so there is nothing for us to do here. */
4603 if (execution_direction != EXEC_REVERSE
4604 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4605 && in_solib_dynsym_resolve_code (stop_pc))
4607 CORE_ADDR pc_after_resolver =
4608 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
4611 fprintf_unfiltered (gdb_stdlog,
4612 "infrun: stepped into dynsym resolve code\n");
4614 if (pc_after_resolver)
4616 /* Set up a step-resume breakpoint at the address
4617 indicated by SKIP_SOLIB_RESOLVER. */
4618 struct symtab_and_line sr_sal;
4621 sr_sal.pc = pc_after_resolver;
4622 sr_sal.pspace = get_frame_program_space (frame);
4624 insert_step_resume_breakpoint_at_sal (gdbarch,
4625 sr_sal, null_frame_id);
4632 if (ecs->event_thread->control.step_range_end != 1
4633 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4634 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4635 && get_frame_type (frame) == SIGTRAMP_FRAME)
4638 fprintf_unfiltered (gdb_stdlog,
4639 "infrun: stepped into signal trampoline\n");
4640 /* The inferior, while doing a "step" or "next", has ended up in
4641 a signal trampoline (either by a signal being delivered or by
4642 the signal handler returning). Just single-step until the
4643 inferior leaves the trampoline (either by calling the handler
4649 /* Check for subroutine calls. The check for the current frame
4650 equalling the step ID is not necessary - the check of the
4651 previous frame's ID is sufficient - but it is a common case and
4652 cheaper than checking the previous frame's ID.
4654 NOTE: frame_id_eq will never report two invalid frame IDs as
4655 being equal, so to get into this block, both the current and
4656 previous frame must have valid frame IDs. */
4657 /* The outer_frame_id check is a heuristic to detect stepping
4658 through startup code. If we step over an instruction which
4659 sets the stack pointer from an invalid value to a valid value,
4660 we may detect that as a subroutine call from the mythical
4661 "outermost" function. This could be fixed by marking
4662 outermost frames as !stack_p,code_p,special_p. Then the
4663 initial outermost frame, before sp was valid, would
4664 have code_addr == &_start. See the comment in frame_id_eq
4666 if (!frame_id_eq (get_stack_frame_id (frame),
4667 ecs->event_thread->control.step_stack_frame_id)
4668 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4669 ecs->event_thread->control.step_stack_frame_id)
4670 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
4672 || step_start_function != find_pc_function (stop_pc))))
4674 CORE_ADDR real_stop_pc;
4677 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
4679 if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
4680 || ((ecs->event_thread->control.step_range_end == 1)
4681 && in_prologue (gdbarch, ecs->event_thread->prev_pc,
4682 ecs->stop_func_start)))
4684 /* I presume that step_over_calls is only 0 when we're
4685 supposed to be stepping at the assembly language level
4686 ("stepi"). Just stop. */
4687 /* Also, maybe we just did a "nexti" inside a prolog, so we
4688 thought it was a subroutine call but it was not. Stop as
4690 /* And this works the same backward as frontward. MVS */
4691 ecs->event_thread->control.stop_step = 1;
4692 print_end_stepping_range_reason ();
4693 stop_stepping (ecs);
4697 /* Reverse stepping through solib trampolines. */
4699 if (execution_direction == EXEC_REVERSE
4700 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
4701 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4702 || (ecs->stop_func_start == 0
4703 && in_solib_dynsym_resolve_code (stop_pc))))
4705 /* Any solib trampoline code can be handled in reverse
4706 by simply continuing to single-step. We have already
4707 executed the solib function (backwards), and a few
4708 steps will take us back through the trampoline to the
4714 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4716 /* We're doing a "next".
4718 Normal (forward) execution: set a breakpoint at the
4719 callee's return address (the address at which the caller
4722 Reverse (backward) execution. set the step-resume
4723 breakpoint at the start of the function that we just
4724 stepped into (backwards), and continue to there. When we
4725 get there, we'll need to single-step back to the caller. */
4727 if (execution_direction == EXEC_REVERSE)
4729 struct symtab_and_line sr_sal;
4731 /* Normal function call return (static or dynamic). */
4733 sr_sal.pc = ecs->stop_func_start;
4734 sr_sal.pspace = get_frame_program_space (frame);
4735 insert_step_resume_breakpoint_at_sal (gdbarch,
4736 sr_sal, null_frame_id);
4739 insert_step_resume_breakpoint_at_caller (frame);
4745 /* If we are in a function call trampoline (a stub between the
4746 calling routine and the real function), locate the real
4747 function. That's what tells us (a) whether we want to step
4748 into it at all, and (b) what prologue we want to run to the
4749 end of, if we do step into it. */
4750 real_stop_pc = skip_language_trampoline (frame, stop_pc);
4751 if (real_stop_pc == 0)
4752 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4753 if (real_stop_pc != 0)
4754 ecs->stop_func_start = real_stop_pc;
4756 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
4758 struct symtab_and_line sr_sal;
4761 sr_sal.pc = ecs->stop_func_start;
4762 sr_sal.pspace = get_frame_program_space (frame);
4764 insert_step_resume_breakpoint_at_sal (gdbarch,
4765 sr_sal, null_frame_id);
4770 /* If we have line number information for the function we are
4771 thinking of stepping into, step into it.
4773 If there are several symtabs at that PC (e.g. with include
4774 files), just want to know whether *any* of them have line
4775 numbers. find_pc_line handles this. */
4777 struct symtab_and_line tmp_sal;
4779 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
4780 if (tmp_sal.line != 0)
4782 if (execution_direction == EXEC_REVERSE)
4783 handle_step_into_function_backward (gdbarch, ecs);
4785 handle_step_into_function (gdbarch, ecs);
4790 /* If we have no line number and the step-stop-if-no-debug is
4791 set, we stop the step so that the user has a chance to switch
4792 in assembly mode. */
4793 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4794 && step_stop_if_no_debug)
4796 ecs->event_thread->control.stop_step = 1;
4797 print_end_stepping_range_reason ();
4798 stop_stepping (ecs);
4802 if (execution_direction == EXEC_REVERSE)
4804 /* Set a breakpoint at callee's start address.
4805 From there we can step once and be back in the caller. */
4806 struct symtab_and_line sr_sal;
4809 sr_sal.pc = ecs->stop_func_start;
4810 sr_sal.pspace = get_frame_program_space (frame);
4811 insert_step_resume_breakpoint_at_sal (gdbarch,
4812 sr_sal, null_frame_id);
4815 /* Set a breakpoint at callee's return address (the address
4816 at which the caller will resume). */
4817 insert_step_resume_breakpoint_at_caller (frame);
4823 /* Reverse stepping through solib trampolines. */
4825 if (execution_direction == EXEC_REVERSE
4826 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
4828 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4829 || (ecs->stop_func_start == 0
4830 && in_solib_dynsym_resolve_code (stop_pc)))
4832 /* Any solib trampoline code can be handled in reverse
4833 by simply continuing to single-step. We have already
4834 executed the solib function (backwards), and a few
4835 steps will take us back through the trampoline to the
4840 else if (in_solib_dynsym_resolve_code (stop_pc))
4842 /* Stepped backward into the solib dynsym resolver.
4843 Set a breakpoint at its start and continue, then
4844 one more step will take us out. */
4845 struct symtab_and_line sr_sal;
4848 sr_sal.pc = ecs->stop_func_start;
4849 sr_sal.pspace = get_frame_program_space (frame);
4850 insert_step_resume_breakpoint_at_sal (gdbarch,
4851 sr_sal, null_frame_id);
4857 /* If we're in the return path from a shared library trampoline,
4858 we want to proceed through the trampoline when stepping. */
4859 if (gdbarch_in_solib_return_trampoline (gdbarch,
4860 stop_pc, ecs->stop_func_name))
4862 /* Determine where this trampoline returns. */
4863 CORE_ADDR real_stop_pc;
4865 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4868 fprintf_unfiltered (gdb_stdlog,
4869 "infrun: stepped into solib return tramp\n");
4871 /* Only proceed through if we know where it's going. */
4874 /* And put the step-breakpoint there and go until there. */
4875 struct symtab_and_line sr_sal;
4877 init_sal (&sr_sal); /* initialize to zeroes */
4878 sr_sal.pc = real_stop_pc;
4879 sr_sal.section = find_pc_overlay (sr_sal.pc);
4880 sr_sal.pspace = get_frame_program_space (frame);
4882 /* Do not specify what the fp should be when we stop since
4883 on some machines the prologue is where the new fp value
4885 insert_step_resume_breakpoint_at_sal (gdbarch,
4886 sr_sal, null_frame_id);
4888 /* Restart without fiddling with the step ranges or
4895 stop_pc_sal = find_pc_line (stop_pc, 0);
4897 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4898 the trampoline processing logic, however, there are some trampolines
4899 that have no names, so we should do trampoline handling first. */
4900 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4901 && ecs->stop_func_name == NULL
4902 && stop_pc_sal.line == 0)
4905 fprintf_unfiltered (gdb_stdlog,
4906 "infrun: stepped into undebuggable function\n");
4908 /* The inferior just stepped into, or returned to, an
4909 undebuggable function (where there is no debugging information
4910 and no line number corresponding to the address where the
4911 inferior stopped). Since we want to skip this kind of code,
4912 we keep going until the inferior returns from this
4913 function - unless the user has asked us not to (via
4914 set step-mode) or we no longer know how to get back
4915 to the call site. */
4916 if (step_stop_if_no_debug
4917 || !frame_id_p (frame_unwind_caller_id (frame)))
4919 /* If we have no line number and the step-stop-if-no-debug
4920 is set, we stop the step so that the user has a chance to
4921 switch in assembly mode. */
4922 ecs->event_thread->control.stop_step = 1;
4923 print_end_stepping_range_reason ();
4924 stop_stepping (ecs);
4929 /* Set a breakpoint at callee's return address (the address
4930 at which the caller will resume). */
4931 insert_step_resume_breakpoint_at_caller (frame);
4937 if (ecs->event_thread->control.step_range_end == 1)
4939 /* It is stepi or nexti. We always want to stop stepping after
4942 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
4943 ecs->event_thread->control.stop_step = 1;
4944 print_end_stepping_range_reason ();
4945 stop_stepping (ecs);
4949 if (stop_pc_sal.line == 0)
4951 /* We have no line number information. That means to stop
4952 stepping (does this always happen right after one instruction,
4953 when we do "s" in a function with no line numbers,
4954 or can this happen as a result of a return or longjmp?). */
4956 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
4957 ecs->event_thread->control.stop_step = 1;
4958 print_end_stepping_range_reason ();
4959 stop_stepping (ecs);
4963 /* Look for "calls" to inlined functions, part one. If the inline
4964 frame machinery detected some skipped call sites, we have entered
4965 a new inline function. */
4967 if (frame_id_eq (get_frame_id (get_current_frame ()),
4968 ecs->event_thread->control.step_frame_id)
4969 && inline_skipped_frames (ecs->ptid))
4971 struct symtab_and_line call_sal;
4974 fprintf_unfiltered (gdb_stdlog,
4975 "infrun: stepped into inlined function\n");
4977 find_frame_sal (get_current_frame (), &call_sal);
4979 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
4981 /* For "step", we're going to stop. But if the call site
4982 for this inlined function is on the same source line as
4983 we were previously stepping, go down into the function
4984 first. Otherwise stop at the call site. */
4986 if (call_sal.line == ecs->event_thread->current_line
4987 && call_sal.symtab == ecs->event_thread->current_symtab)
4988 step_into_inline_frame (ecs->ptid);
4990 ecs->event_thread->control.stop_step = 1;
4991 print_end_stepping_range_reason ();
4992 stop_stepping (ecs);
4997 /* For "next", we should stop at the call site if it is on a
4998 different source line. Otherwise continue through the
4999 inlined function. */
5000 if (call_sal.line == ecs->event_thread->current_line
5001 && call_sal.symtab == ecs->event_thread->current_symtab)
5005 ecs->event_thread->control.stop_step = 1;
5006 print_end_stepping_range_reason ();
5007 stop_stepping (ecs);
5013 /* Look for "calls" to inlined functions, part two. If we are still
5014 in the same real function we were stepping through, but we have
5015 to go further up to find the exact frame ID, we are stepping
5016 through a more inlined call beyond its call site. */
5018 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5019 && !frame_id_eq (get_frame_id (get_current_frame ()),
5020 ecs->event_thread->control.step_frame_id)
5021 && stepped_in_from (get_current_frame (),
5022 ecs->event_thread->control.step_frame_id))
5025 fprintf_unfiltered (gdb_stdlog,
5026 "infrun: stepping through inlined function\n");
5028 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5032 ecs->event_thread->control.stop_step = 1;
5033 print_end_stepping_range_reason ();
5034 stop_stepping (ecs);
5039 if ((stop_pc == stop_pc_sal.pc)
5040 && (ecs->event_thread->current_line != stop_pc_sal.line
5041 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
5043 /* We are at the start of a different line. So stop. Note that
5044 we don't stop if we step into the middle of a different line.
5045 That is said to make things like for (;;) statements work
5048 fprintf_unfiltered (gdb_stdlog,
5049 "infrun: stepped to a different line\n");
5050 ecs->event_thread->control.stop_step = 1;
5051 print_end_stepping_range_reason ();
5052 stop_stepping (ecs);
5056 /* We aren't done stepping.
5058 Optimize by setting the stepping range to the line.
5059 (We might not be in the original line, but if we entered a
5060 new line in mid-statement, we continue stepping. This makes
5061 things like for(;;) statements work better.) */
5063 ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
5064 ecs->event_thread->control.step_range_end = stop_pc_sal.end;
5065 set_step_info (frame, stop_pc_sal);
5068 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
5072 /* Is thread TP in the middle of single-stepping? */
5075 currently_stepping (struct thread_info *tp)
5077 return ((tp->control.step_range_end
5078 && tp->control.step_resume_breakpoint == NULL)
5079 || tp->control.trap_expected
5080 || bpstat_should_step ());
5083 /* Returns true if any thread *but* the one passed in "data" is in the
5084 middle of stepping or of handling a "next". */
5087 currently_stepping_or_nexting_callback (struct thread_info *tp, void *data)
5092 return (tp->control.step_range_end
5093 || tp->control.trap_expected);
5096 /* Inferior has stepped into a subroutine call with source code that
5097 we should not step over. Do step to the first line of code in
5101 handle_step_into_function (struct gdbarch *gdbarch,
5102 struct execution_control_state *ecs)
5105 struct symtab_and_line stop_func_sal, sr_sal;
5107 fill_in_stop_func (gdbarch, ecs);
5109 s = find_pc_symtab (stop_pc);
5110 if (s && s->language != language_asm)
5111 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5112 ecs->stop_func_start);
5114 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
5115 /* Use the step_resume_break to step until the end of the prologue,
5116 even if that involves jumps (as it seems to on the vax under
5118 /* If the prologue ends in the middle of a source line, continue to
5119 the end of that source line (if it is still within the function).
5120 Otherwise, just go to end of prologue. */
5121 if (stop_func_sal.end
5122 && stop_func_sal.pc != ecs->stop_func_start
5123 && stop_func_sal.end < ecs->stop_func_end)
5124 ecs->stop_func_start = stop_func_sal.end;
5126 /* Architectures which require breakpoint adjustment might not be able
5127 to place a breakpoint at the computed address. If so, the test
5128 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5129 ecs->stop_func_start to an address at which a breakpoint may be
5130 legitimately placed.
5132 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5133 made, GDB will enter an infinite loop when stepping through
5134 optimized code consisting of VLIW instructions which contain
5135 subinstructions corresponding to different source lines. On
5136 FR-V, it's not permitted to place a breakpoint on any but the
5137 first subinstruction of a VLIW instruction. When a breakpoint is
5138 set, GDB will adjust the breakpoint address to the beginning of
5139 the VLIW instruction. Thus, we need to make the corresponding
5140 adjustment here when computing the stop address. */
5142 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
5144 ecs->stop_func_start
5145 = gdbarch_adjust_breakpoint_address (gdbarch,
5146 ecs->stop_func_start);
5149 if (ecs->stop_func_start == stop_pc)
5151 /* We are already there: stop now. */
5152 ecs->event_thread->control.stop_step = 1;
5153 print_end_stepping_range_reason ();
5154 stop_stepping (ecs);
5159 /* Put the step-breakpoint there and go until there. */
5160 init_sal (&sr_sal); /* initialize to zeroes */
5161 sr_sal.pc = ecs->stop_func_start;
5162 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
5163 sr_sal.pspace = get_frame_program_space (get_current_frame ());
5165 /* Do not specify what the fp should be when we stop since on
5166 some machines the prologue is where the new fp value is
5168 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
5170 /* And make sure stepping stops right away then. */
5171 ecs->event_thread->control.step_range_end
5172 = ecs->event_thread->control.step_range_start;
5177 /* Inferior has stepped backward into a subroutine call with source
5178 code that we should not step over. Do step to the beginning of the
5179 last line of code in it. */
5182 handle_step_into_function_backward (struct gdbarch *gdbarch,
5183 struct execution_control_state *ecs)
5186 struct symtab_and_line stop_func_sal;
5188 fill_in_stop_func (gdbarch, ecs);
5190 s = find_pc_symtab (stop_pc);
5191 if (s && s->language != language_asm)
5192 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5193 ecs->stop_func_start);
5195 stop_func_sal = find_pc_line (stop_pc, 0);
5197 /* OK, we're just going to keep stepping here. */
5198 if (stop_func_sal.pc == stop_pc)
5200 /* We're there already. Just stop stepping now. */
5201 ecs->event_thread->control.stop_step = 1;
5202 print_end_stepping_range_reason ();
5203 stop_stepping (ecs);
5207 /* Else just reset the step range and keep going.
5208 No step-resume breakpoint, they don't work for
5209 epilogues, which can have multiple entry paths. */
5210 ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5211 ecs->event_thread->control.step_range_end = stop_func_sal.end;
5217 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5218 This is used to both functions and to skip over code. */
5221 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch *gdbarch,
5222 struct symtab_and_line sr_sal,
5223 struct frame_id sr_id,
5224 enum bptype sr_type)
5226 /* There should never be more than one step-resume or longjmp-resume
5227 breakpoint per thread, so we should never be setting a new
5228 step_resume_breakpoint when one is already active. */
5229 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5230 gdb_assert (sr_type == bp_step_resume || sr_type == bp_hp_step_resume);
5233 fprintf_unfiltered (gdb_stdlog,
5234 "infrun: inserting step-resume breakpoint at %s\n",
5235 paddress (gdbarch, sr_sal.pc));
5237 inferior_thread ()->control.step_resume_breakpoint
5238 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type);
5242 insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5243 struct symtab_and_line sr_sal,
5244 struct frame_id sr_id)
5246 insert_step_resume_breakpoint_at_sal_1 (gdbarch,
5251 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5252 This is used to skip a potential signal handler.
5254 This is called with the interrupted function's frame. The signal
5255 handler, when it returns, will resume the interrupted function at
5259 insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
5261 struct symtab_and_line sr_sal;
5262 struct gdbarch *gdbarch;
5264 gdb_assert (return_frame != NULL);
5265 init_sal (&sr_sal); /* initialize to zeros */
5267 gdbarch = get_frame_arch (return_frame);
5268 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
5269 sr_sal.section = find_pc_overlay (sr_sal.pc);
5270 sr_sal.pspace = get_frame_program_space (return_frame);
5272 insert_step_resume_breakpoint_at_sal_1 (gdbarch, sr_sal,
5273 get_stack_frame_id (return_frame),
5277 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5278 is used to skip a function after stepping into it (for "next" or if
5279 the called function has no debugging information).
5281 The current function has almost always been reached by single
5282 stepping a call or return instruction. NEXT_FRAME belongs to the
5283 current function, and the breakpoint will be set at the caller's
5286 This is a separate function rather than reusing
5287 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5288 get_prev_frame, which may stop prematurely (see the implementation
5289 of frame_unwind_caller_id for an example). */
5292 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
5294 struct symtab_and_line sr_sal;
5295 struct gdbarch *gdbarch;
5297 /* We shouldn't have gotten here if we don't know where the call site
5299 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
5301 init_sal (&sr_sal); /* initialize to zeros */
5303 gdbarch = frame_unwind_caller_arch (next_frame);
5304 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
5305 frame_unwind_caller_pc (next_frame));
5306 sr_sal.section = find_pc_overlay (sr_sal.pc);
5307 sr_sal.pspace = frame_unwind_program_space (next_frame);
5309 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5310 frame_unwind_caller_id (next_frame));
5313 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5314 new breakpoint at the target of a jmp_buf. The handling of
5315 longjmp-resume uses the same mechanisms used for handling
5316 "step-resume" breakpoints. */
5319 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
5321 /* There should never be more than one step-resume or longjmp-resume
5322 breakpoint per thread, so we should never be setting a new
5323 longjmp_resume_breakpoint when one is already active. */
5324 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5327 fprintf_unfiltered (gdb_stdlog,
5328 "infrun: inserting longjmp-resume breakpoint at %s\n",
5329 paddress (gdbarch, pc));
5331 inferior_thread ()->control.step_resume_breakpoint =
5332 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
5335 /* Insert an exception resume breakpoint. TP is the thread throwing
5336 the exception. The block B is the block of the unwinder debug hook
5337 function. FRAME is the frame corresponding to the call to this
5338 function. SYM is the symbol of the function argument holding the
5339 target PC of the exception. */
5342 insert_exception_resume_breakpoint (struct thread_info *tp,
5344 struct frame_info *frame,
5347 struct gdb_exception e;
5349 /* We want to ignore errors here. */
5350 TRY_CATCH (e, RETURN_MASK_ERROR)
5352 struct symbol *vsym;
5353 struct value *value;
5355 struct breakpoint *bp;
5357 vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
5358 value = read_var_value (vsym, frame);
5359 /* If the value was optimized out, revert to the old behavior. */
5360 if (! value_optimized_out (value))
5362 handler = value_as_address (value);
5365 fprintf_unfiltered (gdb_stdlog,
5366 "infrun: exception resume at %lx\n",
5367 (unsigned long) handler);
5369 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5370 handler, bp_exception_resume);
5371 bp->thread = tp->num;
5372 inferior_thread ()->control.exception_resume_breakpoint = bp;
5377 /* This is called when an exception has been intercepted. Check to
5378 see whether the exception's destination is of interest, and if so,
5379 set an exception resume breakpoint there. */
5382 check_exception_resume (struct execution_control_state *ecs,
5383 struct frame_info *frame, struct symbol *func)
5385 struct gdb_exception e;
5387 TRY_CATCH (e, RETURN_MASK_ERROR)
5390 struct dict_iterator iter;
5394 /* The exception breakpoint is a thread-specific breakpoint on
5395 the unwinder's debug hook, declared as:
5397 void _Unwind_DebugHook (void *cfa, void *handler);
5399 The CFA argument indicates the frame to which control is
5400 about to be transferred. HANDLER is the destination PC.
5402 We ignore the CFA and set a temporary breakpoint at HANDLER.
5403 This is not extremely efficient but it avoids issues in gdb
5404 with computing the DWARF CFA, and it also works even in weird
5405 cases such as throwing an exception from inside a signal
5408 b = SYMBOL_BLOCK_VALUE (func);
5409 ALL_BLOCK_SYMBOLS (b, iter, sym)
5411 if (!SYMBOL_IS_ARGUMENT (sym))
5418 insert_exception_resume_breakpoint (ecs->event_thread,
5427 stop_stepping (struct execution_control_state *ecs)
5430 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
5432 /* Let callers know we don't want to wait for the inferior anymore. */
5433 ecs->wait_some_more = 0;
5436 /* This function handles various cases where we need to continue
5437 waiting for the inferior. */
5438 /* (Used to be the keep_going: label in the old wait_for_inferior). */
5441 keep_going (struct execution_control_state *ecs)
5443 /* Make sure normal_stop is called if we get a QUIT handled before
5445 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
5447 /* Save the pc before execution, to compare with pc after stop. */
5448 ecs->event_thread->prev_pc
5449 = regcache_read_pc (get_thread_regcache (ecs->ptid));
5451 /* If we did not do break;, it means we should keep running the
5452 inferior and not return to debugger. */
5454 if (ecs->event_thread->control.trap_expected
5455 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP)
5457 /* We took a signal (which we are supposed to pass through to
5458 the inferior, else we'd not get here) and we haven't yet
5459 gotten our trap. Simply continue. */
5461 discard_cleanups (old_cleanups);
5462 resume (currently_stepping (ecs->event_thread),
5463 ecs->event_thread->suspend.stop_signal);
5467 /* Either the trap was not expected, but we are continuing
5468 anyway (the user asked that this signal be passed to the
5471 The signal was SIGTRAP, e.g. it was our signal, but we
5472 decided we should resume from it.
5474 We're going to run this baby now!
5476 Note that insert_breakpoints won't try to re-insert
5477 already inserted breakpoints. Therefore, we don't
5478 care if breakpoints were already inserted, or not. */
5480 if (ecs->event_thread->stepping_over_breakpoint)
5482 struct regcache *thread_regcache = get_thread_regcache (ecs->ptid);
5484 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
5485 /* Since we can't do a displaced step, we have to remove
5486 the breakpoint while we step it. To keep things
5487 simple, we remove them all. */
5488 remove_breakpoints ();
5492 struct gdb_exception e;
5494 /* Stop stepping when inserting breakpoints
5496 TRY_CATCH (e, RETURN_MASK_ERROR)
5498 insert_breakpoints ();
5502 exception_print (gdb_stderr, e);
5503 stop_stepping (ecs);
5508 ecs->event_thread->control.trap_expected
5509 = ecs->event_thread->stepping_over_breakpoint;
5511 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5512 specifies that such a signal should be delivered to the
5515 Typically, this would occure when a user is debugging a
5516 target monitor on a simulator: the target monitor sets a
5517 breakpoint; the simulator encounters this break-point and
5518 halts the simulation handing control to GDB; GDB, noteing
5519 that the break-point isn't valid, returns control back to the
5520 simulator; the simulator then delivers the hardware
5521 equivalent of a SIGNAL_TRAP to the program being debugged. */
5523 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
5524 && !signal_program[ecs->event_thread->suspend.stop_signal])
5525 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
5527 discard_cleanups (old_cleanups);
5528 resume (currently_stepping (ecs->event_thread),
5529 ecs->event_thread->suspend.stop_signal);
5532 prepare_to_wait (ecs);
5535 /* This function normally comes after a resume, before
5536 handle_inferior_event exits. It takes care of any last bits of
5537 housekeeping, and sets the all-important wait_some_more flag. */
5540 prepare_to_wait (struct execution_control_state *ecs)
5543 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
5545 /* This is the old end of the while loop. Let everybody know we
5546 want to wait for the inferior some more and get called again
5548 ecs->wait_some_more = 1;
5551 /* Several print_*_reason functions to print why the inferior has stopped.
5552 We always print something when the inferior exits, or receives a signal.
5553 The rest of the cases are dealt with later on in normal_stop and
5554 print_it_typical. Ideally there should be a call to one of these
5555 print_*_reason functions functions from handle_inferior_event each time
5556 stop_stepping is called. */
5558 /* Print why the inferior has stopped.
5559 We are done with a step/next/si/ni command, print why the inferior has
5560 stopped. For now print nothing. Print a message only if not in the middle
5561 of doing a "step n" operation for n > 1. */
5564 print_end_stepping_range_reason (void)
5566 if ((!inferior_thread ()->step_multi
5567 || !inferior_thread ()->control.stop_step)
5568 && ui_out_is_mi_like_p (current_uiout))
5569 ui_out_field_string (current_uiout, "reason",
5570 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
5573 /* The inferior was terminated by a signal, print why it stopped. */
5576 print_signal_exited_reason (enum target_signal siggnal)
5578 struct ui_out *uiout = current_uiout;
5580 annotate_signalled ();
5581 if (ui_out_is_mi_like_p (uiout))
5583 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
5584 ui_out_text (uiout, "\nProgram terminated with signal ");
5585 annotate_signal_name ();
5586 ui_out_field_string (uiout, "signal-name",
5587 target_signal_to_name (siggnal));
5588 annotate_signal_name_end ();
5589 ui_out_text (uiout, ", ");
5590 annotate_signal_string ();
5591 ui_out_field_string (uiout, "signal-meaning",
5592 target_signal_to_string (siggnal));
5593 annotate_signal_string_end ();
5594 ui_out_text (uiout, ".\n");
5595 ui_out_text (uiout, "The program no longer exists.\n");
5598 /* The inferior program is finished, print why it stopped. */
5601 print_exited_reason (int exitstatus)
5603 struct inferior *inf = current_inferior ();
5604 const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid));
5605 struct ui_out *uiout = current_uiout;
5607 annotate_exited (exitstatus);
5610 if (ui_out_is_mi_like_p (uiout))
5611 ui_out_field_string (uiout, "reason",
5612 async_reason_lookup (EXEC_ASYNC_EXITED));
5613 ui_out_text (uiout, "[Inferior ");
5614 ui_out_text (uiout, plongest (inf->num));
5615 ui_out_text (uiout, " (");
5616 ui_out_text (uiout, pidstr);
5617 ui_out_text (uiout, ") exited with code ");
5618 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
5619 ui_out_text (uiout, "]\n");
5623 if (ui_out_is_mi_like_p (uiout))
5625 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
5626 ui_out_text (uiout, "[Inferior ");
5627 ui_out_text (uiout, plongest (inf->num));
5628 ui_out_text (uiout, " (");
5629 ui_out_text (uiout, pidstr);
5630 ui_out_text (uiout, ") exited normally]\n");
5632 /* Support the --return-child-result option. */
5633 return_child_result_value = exitstatus;
5636 /* Signal received, print why the inferior has stopped. The signal table
5637 tells us to print about it. */
5640 print_signal_received_reason (enum target_signal siggnal)
5642 struct ui_out *uiout = current_uiout;
5646 if (siggnal == TARGET_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
5648 struct thread_info *t = inferior_thread ();
5650 ui_out_text (uiout, "\n[");
5651 ui_out_field_string (uiout, "thread-name",
5652 target_pid_to_str (t->ptid));
5653 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
5654 ui_out_text (uiout, " stopped");
5658 ui_out_text (uiout, "\nProgram received signal ");
5659 annotate_signal_name ();
5660 if (ui_out_is_mi_like_p (uiout))
5662 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
5663 ui_out_field_string (uiout, "signal-name",
5664 target_signal_to_name (siggnal));
5665 annotate_signal_name_end ();
5666 ui_out_text (uiout, ", ");
5667 annotate_signal_string ();
5668 ui_out_field_string (uiout, "signal-meaning",
5669 target_signal_to_string (siggnal));
5670 annotate_signal_string_end ();
5672 ui_out_text (uiout, ".\n");
5675 /* Reverse execution: target ran out of history info, print why the inferior
5679 print_no_history_reason (void)
5681 ui_out_text (current_uiout, "\nNo more reverse-execution history.\n");
5684 /* Here to return control to GDB when the inferior stops for real.
5685 Print appropriate messages, remove breakpoints, give terminal our modes.
5687 STOP_PRINT_FRAME nonzero means print the executing frame
5688 (pc, function, args, file, line number and line text).
5689 BREAKPOINTS_FAILED nonzero means stop was due to error
5690 attempting to insert breakpoints. */
5695 struct target_waitstatus last;
5697 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
5699 get_last_target_status (&last_ptid, &last);
5701 /* If an exception is thrown from this point on, make sure to
5702 propagate GDB's knowledge of the executing state to the
5703 frontend/user running state. A QUIT is an easy exception to see
5704 here, so do this before any filtered output. */
5706 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
5707 else if (last.kind != TARGET_WAITKIND_SIGNALLED
5708 && last.kind != TARGET_WAITKIND_EXITED)
5709 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
5711 /* In non-stop mode, we don't want GDB to switch threads behind the
5712 user's back, to avoid races where the user is typing a command to
5713 apply to thread x, but GDB switches to thread y before the user
5714 finishes entering the command. */
5716 /* As with the notification of thread events, we want to delay
5717 notifying the user that we've switched thread context until
5718 the inferior actually stops.
5720 There's no point in saying anything if the inferior has exited.
5721 Note that SIGNALLED here means "exited with a signal", not
5722 "received a signal". */
5724 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
5725 && target_has_execution
5726 && last.kind != TARGET_WAITKIND_SIGNALLED
5727 && last.kind != TARGET_WAITKIND_EXITED)
5729 target_terminal_ours_for_output ();
5730 printf_filtered (_("[Switching to %s]\n"),
5731 target_pid_to_str (inferior_ptid));
5732 annotate_thread_changed ();
5733 previous_inferior_ptid = inferior_ptid;
5736 if (!breakpoints_always_inserted_mode () && target_has_execution)
5738 if (remove_breakpoints ())
5740 target_terminal_ours_for_output ();
5741 printf_filtered (_("Cannot remove breakpoints because "
5742 "program is no longer writable.\nFurther "
5743 "execution is probably impossible.\n"));
5747 /* If an auto-display called a function and that got a signal,
5748 delete that auto-display to avoid an infinite recursion. */
5750 if (stopped_by_random_signal)
5751 disable_current_display ();
5753 /* Don't print a message if in the middle of doing a "step n"
5754 operation for n > 1 */
5755 if (target_has_execution
5756 && last.kind != TARGET_WAITKIND_SIGNALLED
5757 && last.kind != TARGET_WAITKIND_EXITED
5758 && inferior_thread ()->step_multi
5759 && inferior_thread ()->control.stop_step)
5762 target_terminal_ours ();
5763 async_enable_stdin ();
5765 /* Set the current source location. This will also happen if we
5766 display the frame below, but the current SAL will be incorrect
5767 during a user hook-stop function. */
5768 if (has_stack_frames () && !stop_stack_dummy)
5769 set_current_sal_from_frame (get_current_frame (), 1);
5771 /* Let the user/frontend see the threads as stopped. */
5772 do_cleanups (old_chain);
5774 /* Look up the hook_stop and run it (CLI internally handles problem
5775 of stop_command's pre-hook not existing). */
5777 catch_errors (hook_stop_stub, stop_command,
5778 "Error while running hook_stop:\n", RETURN_MASK_ALL);
5780 if (!has_stack_frames ())
5783 if (last.kind == TARGET_WAITKIND_SIGNALLED
5784 || last.kind == TARGET_WAITKIND_EXITED)
5787 /* Select innermost stack frame - i.e., current frame is frame 0,
5788 and current location is based on that.
5789 Don't do this on return from a stack dummy routine,
5790 or if the program has exited. */
5792 if (!stop_stack_dummy)
5794 select_frame (get_current_frame ());
5796 /* Print current location without a level number, if
5797 we have changed functions or hit a breakpoint.
5798 Print source line if we have one.
5799 bpstat_print() contains the logic deciding in detail
5800 what to print, based on the event(s) that just occurred. */
5802 /* If --batch-silent is enabled then there's no need to print the current
5803 source location, and to try risks causing an error message about
5804 missing source files. */
5805 if (stop_print_frame && !batch_silent)
5809 int do_frame_printing = 1;
5810 struct thread_info *tp = inferior_thread ();
5812 bpstat_ret = bpstat_print (tp->control.stop_bpstat);
5816 /* If we had hit a shared library event breakpoint,
5817 bpstat_print would print out this message. If we hit
5818 an OS-level shared library event, do the same
5820 if (last.kind == TARGET_WAITKIND_LOADED)
5822 printf_filtered (_("Stopped due to shared library event\n"));
5823 source_flag = SRC_LINE; /* something bogus */
5824 do_frame_printing = 0;
5828 /* FIXME: cagney/2002-12-01: Given that a frame ID does
5829 (or should) carry around the function and does (or
5830 should) use that when doing a frame comparison. */
5831 if (tp->control.stop_step
5832 && frame_id_eq (tp->control.step_frame_id,
5833 get_frame_id (get_current_frame ()))
5834 && step_start_function == find_pc_function (stop_pc))
5835 source_flag = SRC_LINE; /* Finished step, just
5836 print source line. */
5838 source_flag = SRC_AND_LOC; /* Print location and
5841 case PRINT_SRC_AND_LOC:
5842 source_flag = SRC_AND_LOC; /* Print location and
5845 case PRINT_SRC_ONLY:
5846 source_flag = SRC_LINE;
5849 source_flag = SRC_LINE; /* something bogus */
5850 do_frame_printing = 0;
5853 internal_error (__FILE__, __LINE__, _("Unknown value."));
5856 /* The behavior of this routine with respect to the source
5858 SRC_LINE: Print only source line
5859 LOCATION: Print only location
5860 SRC_AND_LOC: Print location and source line. */
5861 if (do_frame_printing)
5862 print_stack_frame (get_selected_frame (NULL), 0, source_flag);
5864 /* Display the auto-display expressions. */
5869 /* Save the function value return registers, if we care.
5870 We might be about to restore their previous contents. */
5871 if (inferior_thread ()->control.proceed_to_finish
5872 && execution_direction != EXEC_REVERSE)
5874 /* This should not be necessary. */
5876 regcache_xfree (stop_registers);
5878 /* NB: The copy goes through to the target picking up the value of
5879 all the registers. */
5880 stop_registers = regcache_dup (get_current_regcache ());
5883 if (stop_stack_dummy == STOP_STACK_DUMMY)
5885 /* Pop the empty frame that contains the stack dummy.
5886 This also restores inferior state prior to the call
5887 (struct infcall_suspend_state). */
5888 struct frame_info *frame = get_current_frame ();
5890 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
5892 /* frame_pop() calls reinit_frame_cache as the last thing it
5893 does which means there's currently no selected frame. We
5894 don't need to re-establish a selected frame if the dummy call
5895 returns normally, that will be done by
5896 restore_infcall_control_state. However, we do have to handle
5897 the case where the dummy call is returning after being
5898 stopped (e.g. the dummy call previously hit a breakpoint).
5899 We can't know which case we have so just always re-establish
5900 a selected frame here. */
5901 select_frame (get_current_frame ());
5905 annotate_stopped ();
5907 /* Suppress the stop observer if we're in the middle of:
5909 - a step n (n > 1), as there still more steps to be done.
5911 - a "finish" command, as the observer will be called in
5912 finish_command_continuation, so it can include the inferior
5913 function's return value.
5915 - calling an inferior function, as we pretend we inferior didn't
5916 run at all. The return value of the call is handled by the
5917 expression evaluator, through call_function_by_hand. */
5919 if (!target_has_execution
5920 || last.kind == TARGET_WAITKIND_SIGNALLED
5921 || last.kind == TARGET_WAITKIND_EXITED
5922 || (!inferior_thread ()->step_multi
5923 && !(inferior_thread ()->control.stop_bpstat
5924 && inferior_thread ()->control.proceed_to_finish)
5925 && !inferior_thread ()->control.in_infcall))
5927 if (!ptid_equal (inferior_ptid, null_ptid))
5928 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
5931 observer_notify_normal_stop (NULL, stop_print_frame);
5934 if (target_has_execution)
5936 if (last.kind != TARGET_WAITKIND_SIGNALLED
5937 && last.kind != TARGET_WAITKIND_EXITED)
5938 /* Delete the breakpoint we stopped at, if it wants to be deleted.
5939 Delete any breakpoint that is to be deleted at the next stop. */
5940 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
5943 /* Try to get rid of automatically added inferiors that are no
5944 longer needed. Keeping those around slows down things linearly.
5945 Note that this never removes the current inferior. */
5950 hook_stop_stub (void *cmd)
5952 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
5957 signal_stop_state (int signo)
5959 return signal_stop[signo];
5963 signal_print_state (int signo)
5965 return signal_print[signo];
5969 signal_pass_state (int signo)
5971 return signal_program[signo];
5975 signal_cache_update (int signo)
5979 for (signo = 0; signo < (int) TARGET_SIGNAL_LAST; signo++)
5980 signal_cache_update (signo);
5985 signal_pass[signo] = (signal_stop[signo] == 0
5986 && signal_print[signo] == 0
5987 && signal_program[signo] == 1);
5991 signal_stop_update (int signo, int state)
5993 int ret = signal_stop[signo];
5995 signal_stop[signo] = state;
5996 signal_cache_update (signo);
6001 signal_print_update (int signo, int state)
6003 int ret = signal_print[signo];
6005 signal_print[signo] = state;
6006 signal_cache_update (signo);
6011 signal_pass_update (int signo, int state)
6013 int ret = signal_program[signo];
6015 signal_program[signo] = state;
6016 signal_cache_update (signo);
6021 sig_print_header (void)
6023 printf_filtered (_("Signal Stop\tPrint\tPass "
6024 "to program\tDescription\n"));
6028 sig_print_info (enum target_signal oursig)
6030 const char *name = target_signal_to_name (oursig);
6031 int name_padding = 13 - strlen (name);
6033 if (name_padding <= 0)
6036 printf_filtered ("%s", name);
6037 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
6038 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
6039 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
6040 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
6041 printf_filtered ("%s\n", target_signal_to_string (oursig));
6044 /* Specify how various signals in the inferior should be handled. */
6047 handle_command (char *args, int from_tty)
6050 int digits, wordlen;
6051 int sigfirst, signum, siglast;
6052 enum target_signal oursig;
6055 unsigned char *sigs;
6056 struct cleanup *old_chain;
6060 error_no_arg (_("signal to handle"));
6063 /* Allocate and zero an array of flags for which signals to handle. */
6065 nsigs = (int) TARGET_SIGNAL_LAST;
6066 sigs = (unsigned char *) alloca (nsigs);
6067 memset (sigs, 0, nsigs);
6069 /* Break the command line up into args. */
6071 argv = gdb_buildargv (args);
6072 old_chain = make_cleanup_freeargv (argv);
6074 /* Walk through the args, looking for signal oursigs, signal names, and
6075 actions. Signal numbers and signal names may be interspersed with
6076 actions, with the actions being performed for all signals cumulatively
6077 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6079 while (*argv != NULL)
6081 wordlen = strlen (*argv);
6082 for (digits = 0; isdigit ((*argv)[digits]); digits++)
6086 sigfirst = siglast = -1;
6088 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
6090 /* Apply action to all signals except those used by the
6091 debugger. Silently skip those. */
6094 siglast = nsigs - 1;
6096 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
6098 SET_SIGS (nsigs, sigs, signal_stop);
6099 SET_SIGS (nsigs, sigs, signal_print);
6101 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
6103 UNSET_SIGS (nsigs, sigs, signal_program);
6105 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
6107 SET_SIGS (nsigs, sigs, signal_print);
6109 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
6111 SET_SIGS (nsigs, sigs, signal_program);
6113 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
6115 UNSET_SIGS (nsigs, sigs, signal_stop);
6117 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
6119 SET_SIGS (nsigs, sigs, signal_program);
6121 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
6123 UNSET_SIGS (nsigs, sigs, signal_print);
6124 UNSET_SIGS (nsigs, sigs, signal_stop);
6126 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
6128 UNSET_SIGS (nsigs, sigs, signal_program);
6130 else if (digits > 0)
6132 /* It is numeric. The numeric signal refers to our own
6133 internal signal numbering from target.h, not to host/target
6134 signal number. This is a feature; users really should be
6135 using symbolic names anyway, and the common ones like
6136 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6138 sigfirst = siglast = (int)
6139 target_signal_from_command (atoi (*argv));
6140 if ((*argv)[digits] == '-')
6143 target_signal_from_command (atoi ((*argv) + digits + 1));
6145 if (sigfirst > siglast)
6147 /* Bet he didn't figure we'd think of this case... */
6155 oursig = target_signal_from_name (*argv);
6156 if (oursig != TARGET_SIGNAL_UNKNOWN)
6158 sigfirst = siglast = (int) oursig;
6162 /* Not a number and not a recognized flag word => complain. */
6163 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
6167 /* If any signal numbers or symbol names were found, set flags for
6168 which signals to apply actions to. */
6170 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
6172 switch ((enum target_signal) signum)
6174 case TARGET_SIGNAL_TRAP:
6175 case TARGET_SIGNAL_INT:
6176 if (!allsigs && !sigs[signum])
6178 if (query (_("%s is used by the debugger.\n\
6179 Are you sure you want to change it? "),
6180 target_signal_to_name ((enum target_signal) signum)))
6186 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6187 gdb_flush (gdb_stdout);
6191 case TARGET_SIGNAL_0:
6192 case TARGET_SIGNAL_DEFAULT:
6193 case TARGET_SIGNAL_UNKNOWN:
6194 /* Make sure that "all" doesn't print these. */
6205 for (signum = 0; signum < nsigs; signum++)
6208 signal_cache_update (-1);
6209 target_pass_signals ((int) TARGET_SIGNAL_LAST, signal_pass);
6213 /* Show the results. */
6214 sig_print_header ();
6215 for (; signum < nsigs; signum++)
6217 sig_print_info (signum);
6223 do_cleanups (old_chain);
6227 xdb_handle_command (char *args, int from_tty)
6230 struct cleanup *old_chain;
6233 error_no_arg (_("xdb command"));
6235 /* Break the command line up into args. */
6237 argv = gdb_buildargv (args);
6238 old_chain = make_cleanup_freeargv (argv);
6239 if (argv[1] != (char *) NULL)
6244 bufLen = strlen (argv[0]) + 20;
6245 argBuf = (char *) xmalloc (bufLen);
6249 enum target_signal oursig;
6251 oursig = target_signal_from_name (argv[0]);
6252 memset (argBuf, 0, bufLen);
6253 if (strcmp (argv[1], "Q") == 0)
6254 sprintf (argBuf, "%s %s", argv[0], "noprint");
6257 if (strcmp (argv[1], "s") == 0)
6259 if (!signal_stop[oursig])
6260 sprintf (argBuf, "%s %s", argv[0], "stop");
6262 sprintf (argBuf, "%s %s", argv[0], "nostop");
6264 else if (strcmp (argv[1], "i") == 0)
6266 if (!signal_program[oursig])
6267 sprintf (argBuf, "%s %s", argv[0], "pass");
6269 sprintf (argBuf, "%s %s", argv[0], "nopass");
6271 else if (strcmp (argv[1], "r") == 0)
6273 if (!signal_print[oursig])
6274 sprintf (argBuf, "%s %s", argv[0], "print");
6276 sprintf (argBuf, "%s %s", argv[0], "noprint");
6282 handle_command (argBuf, from_tty);
6284 printf_filtered (_("Invalid signal handling flag.\n"));
6289 do_cleanups (old_chain);
6292 /* Print current contents of the tables set by the handle command.
6293 It is possible we should just be printing signals actually used
6294 by the current target (but for things to work right when switching
6295 targets, all signals should be in the signal tables). */
6298 signals_info (char *signum_exp, int from_tty)
6300 enum target_signal oursig;
6302 sig_print_header ();
6306 /* First see if this is a symbol name. */
6307 oursig = target_signal_from_name (signum_exp);
6308 if (oursig == TARGET_SIGNAL_UNKNOWN)
6310 /* No, try numeric. */
6312 target_signal_from_command (parse_and_eval_long (signum_exp));
6314 sig_print_info (oursig);
6318 printf_filtered ("\n");
6319 /* These ugly casts brought to you by the native VAX compiler. */
6320 for (oursig = TARGET_SIGNAL_FIRST;
6321 (int) oursig < (int) TARGET_SIGNAL_LAST;
6322 oursig = (enum target_signal) ((int) oursig + 1))
6326 if (oursig != TARGET_SIGNAL_UNKNOWN
6327 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
6328 sig_print_info (oursig);
6331 printf_filtered (_("\nUse the \"handle\" command "
6332 "to change these tables.\n"));
6335 /* Check if it makes sense to read $_siginfo from the current thread
6336 at this point. If not, throw an error. */
6339 validate_siginfo_access (void)
6341 /* No current inferior, no siginfo. */
6342 if (ptid_equal (inferior_ptid, null_ptid))
6343 error (_("No thread selected."));
6345 /* Don't try to read from a dead thread. */
6346 if (is_exited (inferior_ptid))
6347 error (_("The current thread has terminated"));
6349 /* ... or from a spinning thread. */
6350 if (is_running (inferior_ptid))
6351 error (_("Selected thread is running."));
6354 /* The $_siginfo convenience variable is a bit special. We don't know
6355 for sure the type of the value until we actually have a chance to
6356 fetch the data. The type can change depending on gdbarch, so it is
6357 also dependent on which thread you have selected.
6359 1. making $_siginfo be an internalvar that creates a new value on
6362 2. making the value of $_siginfo be an lval_computed value. */
6364 /* This function implements the lval_computed support for reading a
6368 siginfo_value_read (struct value *v)
6370 LONGEST transferred;
6372 validate_siginfo_access ();
6375 target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO,
6377 value_contents_all_raw (v),
6379 TYPE_LENGTH (value_type (v)));
6381 if (transferred != TYPE_LENGTH (value_type (v)))
6382 error (_("Unable to read siginfo"));
6385 /* This function implements the lval_computed support for writing a
6389 siginfo_value_write (struct value *v, struct value *fromval)
6391 LONGEST transferred;
6393 validate_siginfo_access ();
6395 transferred = target_write (¤t_target,
6396 TARGET_OBJECT_SIGNAL_INFO,
6398 value_contents_all_raw (fromval),
6400 TYPE_LENGTH (value_type (fromval)));
6402 if (transferred != TYPE_LENGTH (value_type (fromval)))
6403 error (_("Unable to write siginfo"));
6406 static const struct lval_funcs siginfo_value_funcs =
6412 /* Return a new value with the correct type for the siginfo object of
6413 the current thread using architecture GDBARCH. Return a void value
6414 if there's no object available. */
6416 static struct value *
6417 siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var)
6419 if (target_has_stack
6420 && !ptid_equal (inferior_ptid, null_ptid)
6421 && gdbarch_get_siginfo_type_p (gdbarch))
6423 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6425 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
6428 return allocate_value (builtin_type (gdbarch)->builtin_void);
6432 /* infcall_suspend_state contains state about the program itself like its
6433 registers and any signal it received when it last stopped.
6434 This state must be restored regardless of how the inferior function call
6435 ends (either successfully, or after it hits a breakpoint or signal)
6436 if the program is to properly continue where it left off. */
6438 struct infcall_suspend_state
6440 struct thread_suspend_state thread_suspend;
6441 struct inferior_suspend_state inferior_suspend;
6445 struct regcache *registers;
6447 /* Format of SIGINFO_DATA or NULL if it is not present. */
6448 struct gdbarch *siginfo_gdbarch;
6450 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6451 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6452 content would be invalid. */
6453 gdb_byte *siginfo_data;
6456 struct infcall_suspend_state *
6457 save_infcall_suspend_state (void)
6459 struct infcall_suspend_state *inf_state;
6460 struct thread_info *tp = inferior_thread ();
6461 struct inferior *inf = current_inferior ();
6462 struct regcache *regcache = get_current_regcache ();
6463 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6464 gdb_byte *siginfo_data = NULL;
6466 if (gdbarch_get_siginfo_type_p (gdbarch))
6468 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6469 size_t len = TYPE_LENGTH (type);
6470 struct cleanup *back_to;
6472 siginfo_data = xmalloc (len);
6473 back_to = make_cleanup (xfree, siginfo_data);
6475 if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6476 siginfo_data, 0, len) == len)
6477 discard_cleanups (back_to);
6480 /* Errors ignored. */
6481 do_cleanups (back_to);
6482 siginfo_data = NULL;
6486 inf_state = XZALLOC (struct infcall_suspend_state);
6490 inf_state->siginfo_gdbarch = gdbarch;
6491 inf_state->siginfo_data = siginfo_data;
6494 inf_state->thread_suspend = tp->suspend;
6495 inf_state->inferior_suspend = inf->suspend;
6497 /* run_inferior_call will not use the signal due to its `proceed' call with
6498 TARGET_SIGNAL_0 anyway. */
6499 tp->suspend.stop_signal = TARGET_SIGNAL_0;
6501 inf_state->stop_pc = stop_pc;
6503 inf_state->registers = regcache_dup (regcache);
6508 /* Restore inferior session state to INF_STATE. */
6511 restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6513 struct thread_info *tp = inferior_thread ();
6514 struct inferior *inf = current_inferior ();
6515 struct regcache *regcache = get_current_regcache ();
6516 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6518 tp->suspend = inf_state->thread_suspend;
6519 inf->suspend = inf_state->inferior_suspend;
6521 stop_pc = inf_state->stop_pc;
6523 if (inf_state->siginfo_gdbarch == gdbarch)
6525 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6526 size_t len = TYPE_LENGTH (type);
6528 /* Errors ignored. */
6529 target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6530 inf_state->siginfo_data, 0, len);
6533 /* The inferior can be gone if the user types "print exit(0)"
6534 (and perhaps other times). */
6535 if (target_has_execution)
6536 /* NB: The register write goes through to the target. */
6537 regcache_cpy (regcache, inf_state->registers);
6539 discard_infcall_suspend_state (inf_state);
6543 do_restore_infcall_suspend_state_cleanup (void *state)
6545 restore_infcall_suspend_state (state);
6549 make_cleanup_restore_infcall_suspend_state
6550 (struct infcall_suspend_state *inf_state)
6552 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
6556 discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6558 regcache_xfree (inf_state->registers);
6559 xfree (inf_state->siginfo_data);
6564 get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
6566 return inf_state->registers;
6569 /* infcall_control_state contains state regarding gdb's control of the
6570 inferior itself like stepping control. It also contains session state like
6571 the user's currently selected frame. */
6573 struct infcall_control_state
6575 struct thread_control_state thread_control;
6576 struct inferior_control_state inferior_control;
6579 enum stop_stack_kind stop_stack_dummy;
6580 int stopped_by_random_signal;
6581 int stop_after_trap;
6583 /* ID if the selected frame when the inferior function call was made. */
6584 struct frame_id selected_frame_id;
6587 /* Save all of the information associated with the inferior<==>gdb
6590 struct infcall_control_state *
6591 save_infcall_control_state (void)
6593 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
6594 struct thread_info *tp = inferior_thread ();
6595 struct inferior *inf = current_inferior ();
6597 inf_status->thread_control = tp->control;
6598 inf_status->inferior_control = inf->control;
6600 tp->control.step_resume_breakpoint = NULL;
6601 tp->control.exception_resume_breakpoint = NULL;
6603 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6604 chain. If caller's caller is walking the chain, they'll be happier if we
6605 hand them back the original chain when restore_infcall_control_state is
6607 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
6610 inf_status->stop_stack_dummy = stop_stack_dummy;
6611 inf_status->stopped_by_random_signal = stopped_by_random_signal;
6612 inf_status->stop_after_trap = stop_after_trap;
6614 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
6620 restore_selected_frame (void *args)
6622 struct frame_id *fid = (struct frame_id *) args;
6623 struct frame_info *frame;
6625 frame = frame_find_by_id (*fid);
6627 /* If inf_status->selected_frame_id is NULL, there was no previously
6631 warning (_("Unable to restore previously selected frame."));
6635 select_frame (frame);
6640 /* Restore inferior session state to INF_STATUS. */
6643 restore_infcall_control_state (struct infcall_control_state *inf_status)
6645 struct thread_info *tp = inferior_thread ();
6646 struct inferior *inf = current_inferior ();
6648 if (tp->control.step_resume_breakpoint)
6649 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
6651 if (tp->control.exception_resume_breakpoint)
6652 tp->control.exception_resume_breakpoint->disposition
6653 = disp_del_at_next_stop;
6655 /* Handle the bpstat_copy of the chain. */
6656 bpstat_clear (&tp->control.stop_bpstat);
6658 tp->control = inf_status->thread_control;
6659 inf->control = inf_status->inferior_control;
6662 stop_stack_dummy = inf_status->stop_stack_dummy;
6663 stopped_by_random_signal = inf_status->stopped_by_random_signal;
6664 stop_after_trap = inf_status->stop_after_trap;
6666 if (target_has_stack)
6668 /* The point of catch_errors is that if the stack is clobbered,
6669 walking the stack might encounter a garbage pointer and
6670 error() trying to dereference it. */
6672 (restore_selected_frame, &inf_status->selected_frame_id,
6673 "Unable to restore previously selected frame:\n",
6674 RETURN_MASK_ERROR) == 0)
6675 /* Error in restoring the selected frame. Select the innermost
6677 select_frame (get_current_frame ());
6684 do_restore_infcall_control_state_cleanup (void *sts)
6686 restore_infcall_control_state (sts);
6690 make_cleanup_restore_infcall_control_state
6691 (struct infcall_control_state *inf_status)
6693 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
6697 discard_infcall_control_state (struct infcall_control_state *inf_status)
6699 if (inf_status->thread_control.step_resume_breakpoint)
6700 inf_status->thread_control.step_resume_breakpoint->disposition
6701 = disp_del_at_next_stop;
6703 if (inf_status->thread_control.exception_resume_breakpoint)
6704 inf_status->thread_control.exception_resume_breakpoint->disposition
6705 = disp_del_at_next_stop;
6707 /* See save_infcall_control_state for info on stop_bpstat. */
6708 bpstat_clear (&inf_status->thread_control.stop_bpstat);
6714 inferior_has_forked (ptid_t pid, ptid_t *child_pid)
6716 struct target_waitstatus last;
6719 get_last_target_status (&last_ptid, &last);
6721 if (last.kind != TARGET_WAITKIND_FORKED)
6724 if (!ptid_equal (last_ptid, pid))
6727 *child_pid = last.value.related_pid;
6732 inferior_has_vforked (ptid_t pid, ptid_t *child_pid)
6734 struct target_waitstatus last;
6737 get_last_target_status (&last_ptid, &last);
6739 if (last.kind != TARGET_WAITKIND_VFORKED)
6742 if (!ptid_equal (last_ptid, pid))
6745 *child_pid = last.value.related_pid;
6750 inferior_has_execd (ptid_t pid, char **execd_pathname)
6752 struct target_waitstatus last;
6755 get_last_target_status (&last_ptid, &last);
6757 if (last.kind != TARGET_WAITKIND_EXECD)
6760 if (!ptid_equal (last_ptid, pid))
6763 *execd_pathname = xstrdup (last.value.execd_pathname);
6768 inferior_has_called_syscall (ptid_t pid, int *syscall_number)
6770 struct target_waitstatus last;
6773 get_last_target_status (&last_ptid, &last);
6775 if (last.kind != TARGET_WAITKIND_SYSCALL_ENTRY &&
6776 last.kind != TARGET_WAITKIND_SYSCALL_RETURN)
6779 if (!ptid_equal (last_ptid, pid))
6782 *syscall_number = last.value.syscall_number;
6787 ptid_match (ptid_t ptid, ptid_t filter)
6789 if (ptid_equal (filter, minus_one_ptid))
6791 if (ptid_is_pid (filter)
6792 && ptid_get_pid (ptid) == ptid_get_pid (filter))
6794 else if (ptid_equal (ptid, filter))
6800 /* restore_inferior_ptid() will be used by the cleanup machinery
6801 to restore the inferior_ptid value saved in a call to
6802 save_inferior_ptid(). */
6805 restore_inferior_ptid (void *arg)
6807 ptid_t *saved_ptid_ptr = arg;
6809 inferior_ptid = *saved_ptid_ptr;
6813 /* Save the value of inferior_ptid so that it may be restored by a
6814 later call to do_cleanups(). Returns the struct cleanup pointer
6815 needed for later doing the cleanup. */
6818 save_inferior_ptid (void)
6820 ptid_t *saved_ptid_ptr;
6822 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
6823 *saved_ptid_ptr = inferior_ptid;
6824 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
6828 /* User interface for reverse debugging:
6829 Set exec-direction / show exec-direction commands
6830 (returns error unless target implements to_set_exec_direction method). */
6832 int execution_direction = EXEC_FORWARD;
6833 static const char exec_forward[] = "forward";
6834 static const char exec_reverse[] = "reverse";
6835 static const char *exec_direction = exec_forward;
6836 static const char *exec_direction_names[] = {
6843 set_exec_direction_func (char *args, int from_tty,
6844 struct cmd_list_element *cmd)
6846 if (target_can_execute_reverse)
6848 if (!strcmp (exec_direction, exec_forward))
6849 execution_direction = EXEC_FORWARD;
6850 else if (!strcmp (exec_direction, exec_reverse))
6851 execution_direction = EXEC_REVERSE;
6855 exec_direction = exec_forward;
6856 error (_("Target does not support this operation."));
6861 show_exec_direction_func (struct ui_file *out, int from_tty,
6862 struct cmd_list_element *cmd, const char *value)
6864 switch (execution_direction) {
6866 fprintf_filtered (out, _("Forward.\n"));
6869 fprintf_filtered (out, _("Reverse.\n"));
6872 internal_error (__FILE__, __LINE__,
6873 _("bogus execution_direction value: %d"),
6874 (int) execution_direction);
6878 /* User interface for non-stop mode. */
6883 set_non_stop (char *args, int from_tty,
6884 struct cmd_list_element *c)
6886 if (target_has_execution)
6888 non_stop_1 = non_stop;
6889 error (_("Cannot change this setting while the inferior is running."));
6892 non_stop = non_stop_1;
6896 show_non_stop (struct ui_file *file, int from_tty,
6897 struct cmd_list_element *c, const char *value)
6899 fprintf_filtered (file,
6900 _("Controlling the inferior in non-stop mode is %s.\n"),
6905 show_schedule_multiple (struct ui_file *file, int from_tty,
6906 struct cmd_list_element *c, const char *value)
6908 fprintf_filtered (file, _("Resuming the execution of threads "
6909 "of all processes is %s.\n"), value);
6913 _initialize_infrun (void)
6918 add_info ("signals", signals_info, _("\
6919 What debugger does when program gets various signals.\n\
6920 Specify a signal as argument to print info on that signal only."));
6921 add_info_alias ("handle", "signals", 0);
6923 add_com ("handle", class_run, handle_command, _("\
6924 Specify how to handle a signal.\n\
6925 Args are signals and actions to apply to those signals.\n\
6926 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6927 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6928 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6929 The special arg \"all\" is recognized to mean all signals except those\n\
6930 used by the debugger, typically SIGTRAP and SIGINT.\n\
6931 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
6932 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
6933 Stop means reenter debugger if this signal happens (implies print).\n\
6934 Print means print a message if this signal happens.\n\
6935 Pass means let program see this signal; otherwise program doesn't know.\n\
6936 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6937 Pass and Stop may be combined."));
6940 add_com ("lz", class_info, signals_info, _("\
6941 What debugger does when program gets various signals.\n\
6942 Specify a signal as argument to print info on that signal only."));
6943 add_com ("z", class_run, xdb_handle_command, _("\
6944 Specify how to handle a signal.\n\
6945 Args are signals and actions to apply to those signals.\n\
6946 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6947 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6948 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6949 The special arg \"all\" is recognized to mean all signals except those\n\
6950 used by the debugger, typically SIGTRAP and SIGINT.\n\
6951 Recognized actions include \"s\" (toggles between stop and nostop),\n\
6952 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
6953 nopass), \"Q\" (noprint)\n\
6954 Stop means reenter debugger if this signal happens (implies print).\n\
6955 Print means print a message if this signal happens.\n\
6956 Pass means let program see this signal; otherwise program doesn't know.\n\
6957 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6958 Pass and Stop may be combined."));
6962 stop_command = add_cmd ("stop", class_obscure,
6963 not_just_help_class_command, _("\
6964 There is no `stop' command, but you can set a hook on `stop'.\n\
6965 This allows you to set a list of commands to be run each time execution\n\
6966 of the program stops."), &cmdlist);
6968 add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
6969 Set inferior debugging."), _("\
6970 Show inferior debugging."), _("\
6971 When non-zero, inferior specific debugging is enabled."),
6974 &setdebuglist, &showdebuglist);
6976 add_setshow_boolean_cmd ("displaced", class_maintenance,
6977 &debug_displaced, _("\
6978 Set displaced stepping debugging."), _("\
6979 Show displaced stepping debugging."), _("\
6980 When non-zero, displaced stepping specific debugging is enabled."),
6982 show_debug_displaced,
6983 &setdebuglist, &showdebuglist);
6985 add_setshow_boolean_cmd ("non-stop", no_class,
6987 Set whether gdb controls the inferior in non-stop mode."), _("\
6988 Show whether gdb controls the inferior in non-stop mode."), _("\
6989 When debugging a multi-threaded program and this setting is\n\
6990 off (the default, also called all-stop mode), when one thread stops\n\
6991 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
6992 all other threads in the program while you interact with the thread of\n\
6993 interest. When you continue or step a thread, you can allow the other\n\
6994 threads to run, or have them remain stopped, but while you inspect any\n\
6995 thread's state, all threads stop.\n\
6997 In non-stop mode, when one thread stops, other threads can continue\n\
6998 to run freely. You'll be able to step each thread independently,\n\
6999 leave it stopped or free to run as needed."),
7005 numsigs = (int) TARGET_SIGNAL_LAST;
7006 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
7007 signal_print = (unsigned char *)
7008 xmalloc (sizeof (signal_print[0]) * numsigs);
7009 signal_program = (unsigned char *)
7010 xmalloc (sizeof (signal_program[0]) * numsigs);
7011 signal_pass = (unsigned char *)
7012 xmalloc (sizeof (signal_program[0]) * numsigs);
7013 for (i = 0; i < numsigs; i++)
7016 signal_print[i] = 1;
7017 signal_program[i] = 1;
7020 /* Signals caused by debugger's own actions
7021 should not be given to the program afterwards. */
7022 signal_program[TARGET_SIGNAL_TRAP] = 0;
7023 signal_program[TARGET_SIGNAL_INT] = 0;
7025 /* Signals that are not errors should not normally enter the debugger. */
7026 signal_stop[TARGET_SIGNAL_ALRM] = 0;
7027 signal_print[TARGET_SIGNAL_ALRM] = 0;
7028 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
7029 signal_print[TARGET_SIGNAL_VTALRM] = 0;
7030 signal_stop[TARGET_SIGNAL_PROF] = 0;
7031 signal_print[TARGET_SIGNAL_PROF] = 0;
7032 signal_stop[TARGET_SIGNAL_CHLD] = 0;
7033 signal_print[TARGET_SIGNAL_CHLD] = 0;
7034 signal_stop[TARGET_SIGNAL_IO] = 0;
7035 signal_print[TARGET_SIGNAL_IO] = 0;
7036 signal_stop[TARGET_SIGNAL_POLL] = 0;
7037 signal_print[TARGET_SIGNAL_POLL] = 0;
7038 signal_stop[TARGET_SIGNAL_URG] = 0;
7039 signal_print[TARGET_SIGNAL_URG] = 0;
7040 signal_stop[TARGET_SIGNAL_WINCH] = 0;
7041 signal_print[TARGET_SIGNAL_WINCH] = 0;
7042 signal_stop[TARGET_SIGNAL_PRIO] = 0;
7043 signal_print[TARGET_SIGNAL_PRIO] = 0;
7045 /* These signals are used internally by user-level thread
7046 implementations. (See signal(5) on Solaris.) Like the above
7047 signals, a healthy program receives and handles them as part of
7048 its normal operation. */
7049 signal_stop[TARGET_SIGNAL_LWP] = 0;
7050 signal_print[TARGET_SIGNAL_LWP] = 0;
7051 signal_stop[TARGET_SIGNAL_WAITING] = 0;
7052 signal_print[TARGET_SIGNAL_WAITING] = 0;
7053 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
7054 signal_print[TARGET_SIGNAL_CANCEL] = 0;
7056 /* Update cached state. */
7057 signal_cache_update (-1);
7059 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
7060 &stop_on_solib_events, _("\
7061 Set stopping for shared library events."), _("\
7062 Show stopping for shared library events."), _("\
7063 If nonzero, gdb will give control to the user when the dynamic linker\n\
7064 notifies gdb of shared library events. The most common event of interest\n\
7065 to the user would be loading/unloading of a new library."),
7067 show_stop_on_solib_events,
7068 &setlist, &showlist);
7070 add_setshow_enum_cmd ("follow-fork-mode", class_run,
7071 follow_fork_mode_kind_names,
7072 &follow_fork_mode_string, _("\
7073 Set debugger response to a program call of fork or vfork."), _("\
7074 Show debugger response to a program call of fork or vfork."), _("\
7075 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7076 parent - the original process is debugged after a fork\n\
7077 child - the new process is debugged after a fork\n\
7078 The unfollowed process will continue to run.\n\
7079 By default, the debugger will follow the parent process."),
7081 show_follow_fork_mode_string,
7082 &setlist, &showlist);
7084 add_setshow_enum_cmd ("follow-exec-mode", class_run,
7085 follow_exec_mode_names,
7086 &follow_exec_mode_string, _("\
7087 Set debugger response to a program call of exec."), _("\
7088 Show debugger response to a program call of exec."), _("\
7089 An exec call replaces the program image of a process.\n\
7091 follow-exec-mode can be:\n\
7093 new - the debugger creates a new inferior and rebinds the process\n\
7094 to this new inferior. The program the process was running before\n\
7095 the exec call can be restarted afterwards by restarting the original\n\
7098 same - the debugger keeps the process bound to the same inferior.\n\
7099 The new executable image replaces the previous executable loaded in\n\
7100 the inferior. Restarting the inferior after the exec call restarts\n\
7101 the executable the process was running after the exec call.\n\
7103 By default, the debugger will use the same inferior."),
7105 show_follow_exec_mode_string,
7106 &setlist, &showlist);
7108 add_setshow_enum_cmd ("scheduler-locking", class_run,
7109 scheduler_enums, &scheduler_mode, _("\
7110 Set mode for locking scheduler during execution."), _("\
7111 Show mode for locking scheduler during execution."), _("\
7112 off == no locking (threads may preempt at any time)\n\
7113 on == full locking (no thread except the current thread may run)\n\
7114 step == scheduler locked during every single-step operation.\n\
7115 In this mode, no other thread may run during a step command.\n\
7116 Other threads may run while stepping over a function call ('next')."),
7117 set_schedlock_func, /* traps on target vector */
7118 show_scheduler_mode,
7119 &setlist, &showlist);
7121 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
7122 Set mode for resuming threads of all processes."), _("\
7123 Show mode for resuming threads of all processes."), _("\
7124 When on, execution commands (such as 'continue' or 'next') resume all\n\
7125 threads of all processes. When off (which is the default), execution\n\
7126 commands only resume the threads of the current process. The set of\n\
7127 threads that are resumed is further refined by the scheduler-locking\n\
7128 mode (see help set scheduler-locking)."),
7130 show_schedule_multiple,
7131 &setlist, &showlist);
7133 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
7134 Set mode of the step operation."), _("\
7135 Show mode of the step operation."), _("\
7136 When set, doing a step over a function without debug line information\n\
7137 will stop at the first instruction of that function. Otherwise, the\n\
7138 function is skipped and the step command stops at a different source line."),
7140 show_step_stop_if_no_debug,
7141 &setlist, &showlist);
7143 add_setshow_enum_cmd ("displaced-stepping", class_run,
7144 can_use_displaced_stepping_enum,
7145 &can_use_displaced_stepping, _("\
7146 Set debugger's willingness to use displaced stepping."), _("\
7147 Show debugger's willingness to use displaced stepping."), _("\
7148 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7149 supported by the target architecture. If off, gdb will not use displaced\n\
7150 stepping to step over breakpoints, even if such is supported by the target\n\
7151 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7152 if the target architecture supports it and non-stop mode is active, but will not\n\
7153 use it in all-stop mode (see help set non-stop)."),
7155 show_can_use_displaced_stepping,
7156 &setlist, &showlist);
7158 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
7159 &exec_direction, _("Set direction of execution.\n\
7160 Options are 'forward' or 'reverse'."),
7161 _("Show direction of execution (forward/reverse)."),
7162 _("Tells gdb whether to execute forward or backward."),
7163 set_exec_direction_func, show_exec_direction_func,
7164 &setlist, &showlist);
7166 /* Set/show detach-on-fork: user-settable mode. */
7168 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
7169 Set whether gdb will detach the child of a fork."), _("\
7170 Show whether gdb will detach the child of a fork."), _("\
7171 Tells gdb whether to detach the child of a fork."),
7172 NULL, NULL, &setlist, &showlist);
7174 /* ptid initializations */
7175 inferior_ptid = null_ptid;
7176 target_last_wait_ptid = minus_one_ptid;
7178 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
7179 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
7180 observer_attach_thread_exit (infrun_thread_thread_exit);
7181 observer_attach_inferior_exit (infrun_inferior_exit);
7183 /* Explicitly create without lookup, since that tries to create a
7184 value with a void typed value, and when we get here, gdbarch
7185 isn't initialized yet. At this point, we're quite sure there
7186 isn't another convenience variable of the same name. */
7187 create_internalvar_type_lazy ("_siginfo", siginfo_make_value);
7189 add_setshow_boolean_cmd ("observer", no_class,
7190 &observer_mode_1, _("\
7191 Set whether gdb controls the inferior in observer mode."), _("\
7192 Show whether gdb controls the inferior in observer mode."), _("\
7193 In observer mode, GDB can get data from the inferior, but not\n\
7194 affect its execution. Registers and memory may not be changed,\n\
7195 breakpoints may not be set, and the program cannot be interrupted\n\