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 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 "gdb_assert.h"
49 #include "mi/mi-common.h"
50 #include "event-top.h"
52 #include "inline-frame.h"
54 #include "tracepoint.h"
56 /* Prototypes for local functions */
58 static void signals_info (char *, int);
60 static void handle_command (char *, int);
62 static void sig_print_info (enum target_signal);
64 static void sig_print_header (void);
66 static void resume_cleanups (void *);
68 static int hook_stop_stub (void *);
70 static int restore_selected_frame (void *);
72 static int follow_fork (void);
74 static void set_schedlock_func (char *args, int from_tty,
75 struct cmd_list_element *c);
77 static int currently_stepping (struct thread_info *tp);
79 static int currently_stepping_or_nexting_callback (struct thread_info *tp,
82 static void xdb_handle_command (char *args, int from_tty);
84 static int prepare_to_proceed (int);
86 static void print_exited_reason (int exitstatus);
88 static void print_signal_exited_reason (enum target_signal siggnal);
90 static void print_no_history_reason (void);
92 static void print_signal_received_reason (enum target_signal siggnal);
94 static void print_end_stepping_range_reason (void);
96 void _initialize_infrun (void);
98 void nullify_last_target_wait_ptid (void);
100 /* When set, stop the 'step' command if we enter a function which has
101 no line number information. The normal behavior is that we step
102 over such function. */
103 int step_stop_if_no_debug = 0;
105 show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
106 struct cmd_list_element *c, const char *value)
108 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
111 /* In asynchronous mode, but simulating synchronous execution. */
113 int sync_execution = 0;
115 /* wait_for_inferior and normal_stop use this to notify the user
116 when the inferior stopped in a different thread than it had been
119 static ptid_t previous_inferior_ptid;
121 /* Default behavior is to detach newly forked processes (legacy). */
124 int debug_displaced = 0;
126 show_debug_displaced (struct ui_file *file, int from_tty,
127 struct cmd_list_element *c, const char *value)
129 fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value);
132 int debug_infrun = 0;
134 show_debug_infrun (struct ui_file *file, int from_tty,
135 struct cmd_list_element *c, const char *value)
137 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
140 /* If the program uses ELF-style shared libraries, then calls to
141 functions in shared libraries go through stubs, which live in a
142 table called the PLT (Procedure Linkage Table). The first time the
143 function is called, the stub sends control to the dynamic linker,
144 which looks up the function's real address, patches the stub so
145 that future calls will go directly to the function, and then passes
146 control to the function.
148 If we are stepping at the source level, we don't want to see any of
149 this --- we just want to skip over the stub and the dynamic linker.
150 The simple approach is to single-step until control leaves the
153 However, on some systems (e.g., Red Hat's 5.2 distribution) the
154 dynamic linker calls functions in the shared C library, so you
155 can't tell from the PC alone whether the dynamic linker is still
156 running. In this case, we use a step-resume breakpoint to get us
157 past the dynamic linker, as if we were using "next" to step over a
160 in_solib_dynsym_resolve_code() says whether we're in the dynamic
161 linker code or not. Normally, this means we single-step. However,
162 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
163 address where we can place a step-resume breakpoint to get past the
164 linker's symbol resolution function.
166 in_solib_dynsym_resolve_code() can generally be implemented in a
167 pretty portable way, by comparing the PC against the address ranges
168 of the dynamic linker's sections.
170 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
171 it depends on internal details of the dynamic linker. It's usually
172 not too hard to figure out where to put a breakpoint, but it
173 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
174 sanity checking. If it can't figure things out, returning zero and
175 getting the (possibly confusing) stepping behavior is better than
176 signalling an error, which will obscure the change in the
179 /* This function returns TRUE if pc is the address of an instruction
180 that lies within the dynamic linker (such as the event hook, or the
183 This function must be used only when a dynamic linker event has
184 been caught, and the inferior is being stepped out of the hook, or
185 undefined results are guaranteed. */
187 #ifndef SOLIB_IN_DYNAMIC_LINKER
188 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
191 /* "Observer mode" is somewhat like a more extreme version of
192 non-stop, in which all GDB operations that might affect the
193 target's execution have been disabled. */
195 static int non_stop_1 = 0;
197 int observer_mode = 0;
198 static int observer_mode_1 = 0;
201 set_observer_mode (char *args, int from_tty,
202 struct cmd_list_element *c)
204 extern int pagination_enabled;
206 if (target_has_execution)
208 observer_mode_1 = observer_mode;
209 error (_("Cannot change this setting while the inferior is running."));
212 observer_mode = observer_mode_1;
214 may_write_registers = !observer_mode;
215 may_write_memory = !observer_mode;
216 may_insert_breakpoints = !observer_mode;
217 may_insert_tracepoints = !observer_mode;
218 /* We can insert fast tracepoints in or out of observer mode,
219 but enable them if we're going into this mode. */
221 may_insert_fast_tracepoints = 1;
222 may_stop = !observer_mode;
223 update_target_permissions ();
225 /* Going *into* observer mode we must force non-stop, then
226 going out we leave it that way. */
229 target_async_permitted = 1;
230 pagination_enabled = 0;
231 non_stop = non_stop_1 = 1;
235 printf_filtered (_("Observer mode is now %s.\n"),
236 (observer_mode ? "on" : "off"));
240 show_observer_mode (struct ui_file *file, int from_tty,
241 struct cmd_list_element *c, const char *value)
243 fprintf_filtered (file, _("Observer mode is %s.\n"), value);
246 /* This updates the value of observer mode based on changes in
247 permissions. Note that we are deliberately ignoring the values of
248 may-write-registers and may-write-memory, since the user may have
249 reason to enable these during a session, for instance to turn on a
250 debugging-related global. */
253 update_observer_mode (void)
257 newval = (!may_insert_breakpoints
258 && !may_insert_tracepoints
259 && may_insert_fast_tracepoints
263 /* Let the user know if things change. */
264 if (newval != observer_mode)
265 printf_filtered (_("Observer mode is now %s.\n"),
266 (newval ? "on" : "off"));
268 observer_mode = observer_mode_1 = newval;
271 /* Tables of how to react to signals; the user sets them. */
273 static unsigned char *signal_stop;
274 static unsigned char *signal_print;
275 static unsigned char *signal_program;
277 #define SET_SIGS(nsigs,sigs,flags) \
279 int signum = (nsigs); \
280 while (signum-- > 0) \
281 if ((sigs)[signum]) \
282 (flags)[signum] = 1; \
285 #define UNSET_SIGS(nsigs,sigs,flags) \
287 int signum = (nsigs); \
288 while (signum-- > 0) \
289 if ((sigs)[signum]) \
290 (flags)[signum] = 0; \
293 /* Value to pass to target_resume() to cause all threads to resume */
295 #define RESUME_ALL minus_one_ptid
297 /* Command list pointer for the "stop" placeholder. */
299 static struct cmd_list_element *stop_command;
301 /* Function inferior was in as of last step command. */
303 static struct symbol *step_start_function;
305 /* Nonzero if we want to give control to the user when we're notified
306 of shared library events by the dynamic linker. */
307 int stop_on_solib_events;
309 show_stop_on_solib_events (struct ui_file *file, int from_tty,
310 struct cmd_list_element *c, const char *value)
312 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
316 /* Nonzero means expecting a trace trap
317 and should stop the inferior and return silently when it happens. */
321 /* Save register contents here when executing a "finish" command or are
322 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
323 Thus this contains the return value from the called function (assuming
324 values are returned in a register). */
326 struct regcache *stop_registers;
328 /* Nonzero after stop if current stack frame should be printed. */
330 static int stop_print_frame;
332 /* This is a cached copy of the pid/waitstatus of the last event
333 returned by target_wait()/deprecated_target_wait_hook(). This
334 information is returned by get_last_target_status(). */
335 static ptid_t target_last_wait_ptid;
336 static struct target_waitstatus target_last_waitstatus;
338 static void context_switch (ptid_t ptid);
340 void init_thread_stepping_state (struct thread_info *tss);
342 void init_infwait_state (void);
344 static const char follow_fork_mode_child[] = "child";
345 static const char follow_fork_mode_parent[] = "parent";
347 static const char *follow_fork_mode_kind_names[] = {
348 follow_fork_mode_child,
349 follow_fork_mode_parent,
353 static const char *follow_fork_mode_string = follow_fork_mode_parent;
355 show_follow_fork_mode_string (struct ui_file *file, int from_tty,
356 struct cmd_list_element *c, const char *value)
358 fprintf_filtered (file, _("\
359 Debugger response to a program call of fork or vfork is \"%s\".\n"),
364 /* Tell the target to follow the fork we're stopped at. Returns true
365 if the inferior should be resumed; false, if the target for some
366 reason decided it's best not to resume. */
371 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
372 int should_resume = 1;
373 struct thread_info *tp;
375 /* Copy user stepping state to the new inferior thread. FIXME: the
376 followed fork child thread should have a copy of most of the
377 parent thread structure's run control related fields, not just these.
378 Initialized to avoid "may be used uninitialized" warnings from gcc. */
379 struct breakpoint *step_resume_breakpoint = NULL;
380 CORE_ADDR step_range_start = 0;
381 CORE_ADDR step_range_end = 0;
382 struct frame_id step_frame_id = { 0 };
387 struct target_waitstatus wait_status;
389 /* Get the last target status returned by target_wait(). */
390 get_last_target_status (&wait_ptid, &wait_status);
392 /* If not stopped at a fork event, then there's nothing else to
394 if (wait_status.kind != TARGET_WAITKIND_FORKED
395 && wait_status.kind != TARGET_WAITKIND_VFORKED)
398 /* Check if we switched over from WAIT_PTID, since the event was
400 if (!ptid_equal (wait_ptid, minus_one_ptid)
401 && !ptid_equal (inferior_ptid, wait_ptid))
403 /* We did. Switch back to WAIT_PTID thread, to tell the
404 target to follow it (in either direction). We'll
405 afterwards refuse to resume, and inform the user what
407 switch_to_thread (wait_ptid);
412 tp = inferior_thread ();
414 /* If there were any forks/vforks that were caught and are now to be
415 followed, then do so now. */
416 switch (tp->pending_follow.kind)
418 case TARGET_WAITKIND_FORKED:
419 case TARGET_WAITKIND_VFORKED:
421 ptid_t parent, child;
423 /* If the user did a next/step, etc, over a fork call,
424 preserve the stepping state in the fork child. */
425 if (follow_child && should_resume)
427 step_resume_breakpoint = clone_momentary_breakpoint
428 (tp->control.step_resume_breakpoint);
429 step_range_start = tp->control.step_range_start;
430 step_range_end = tp->control.step_range_end;
431 step_frame_id = tp->control.step_frame_id;
433 /* For now, delete the parent's sr breakpoint, otherwise,
434 parent/child sr breakpoints are considered duplicates,
435 and the child version will not be installed. Remove
436 this when the breakpoints module becomes aware of
437 inferiors and address spaces. */
438 delete_step_resume_breakpoint (tp);
439 tp->control.step_range_start = 0;
440 tp->control.step_range_end = 0;
441 tp->control.step_frame_id = null_frame_id;
444 parent = inferior_ptid;
445 child = tp->pending_follow.value.related_pid;
447 /* Tell the target to do whatever is necessary to follow
448 either parent or child. */
449 if (target_follow_fork (follow_child))
451 /* Target refused to follow, or there's some other reason
452 we shouldn't resume. */
457 /* This pending follow fork event is now handled, one way
458 or another. The previous selected thread may be gone
459 from the lists by now, but if it is still around, need
460 to clear the pending follow request. */
461 tp = find_thread_ptid (parent);
463 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
465 /* This makes sure we don't try to apply the "Switched
466 over from WAIT_PID" logic above. */
467 nullify_last_target_wait_ptid ();
469 /* If we followed the child, switch to it... */
472 switch_to_thread (child);
474 /* ... and preserve the stepping state, in case the
475 user was stepping over the fork call. */
478 tp = inferior_thread ();
479 tp->control.step_resume_breakpoint
480 = step_resume_breakpoint;
481 tp->control.step_range_start = step_range_start;
482 tp->control.step_range_end = step_range_end;
483 tp->control.step_frame_id = step_frame_id;
487 /* If we get here, it was because we're trying to
488 resume from a fork catchpoint, but, the user
489 has switched threads away from the thread that
490 forked. In that case, the resume command
491 issued is most likely not applicable to the
492 child, so just warn, and refuse to resume. */
494 Not resuming: switched threads before following fork child.\n"));
497 /* Reset breakpoints in the child as appropriate. */
498 follow_inferior_reset_breakpoints ();
501 switch_to_thread (parent);
505 case TARGET_WAITKIND_SPURIOUS:
506 /* Nothing to follow. */
509 internal_error (__FILE__, __LINE__,
510 "Unexpected pending_follow.kind %d\n",
511 tp->pending_follow.kind);
515 return should_resume;
519 follow_inferior_reset_breakpoints (void)
521 struct thread_info *tp = inferior_thread ();
523 /* Was there a step_resume breakpoint? (There was if the user
524 did a "next" at the fork() call.) If so, explicitly reset its
527 step_resumes are a form of bp that are made to be per-thread.
528 Since we created the step_resume bp when the parent process
529 was being debugged, and now are switching to the child process,
530 from the breakpoint package's viewpoint, that's a switch of
531 "threads". We must update the bp's notion of which thread
532 it is for, or it'll be ignored when it triggers. */
534 if (tp->control.step_resume_breakpoint)
535 breakpoint_re_set_thread (tp->control.step_resume_breakpoint);
537 /* Reinsert all breakpoints in the child. The user may have set
538 breakpoints after catching the fork, in which case those
539 were never set in the child, but only in the parent. This makes
540 sure the inserted breakpoints match the breakpoint list. */
542 breakpoint_re_set ();
543 insert_breakpoints ();
546 /* The child has exited or execed: resume threads of the parent the
547 user wanted to be executing. */
550 proceed_after_vfork_done (struct thread_info *thread,
553 int pid = * (int *) arg;
555 if (ptid_get_pid (thread->ptid) == pid
556 && is_running (thread->ptid)
557 && !is_executing (thread->ptid)
558 && !thread->stop_requested
559 && thread->suspend.stop_signal == TARGET_SIGNAL_0)
562 fprintf_unfiltered (gdb_stdlog,
563 "infrun: resuming vfork parent thread %s\n",
564 target_pid_to_str (thread->ptid));
566 switch_to_thread (thread->ptid);
567 clear_proceed_status ();
568 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
574 /* Called whenever we notice an exec or exit event, to handle
575 detaching or resuming a vfork parent. */
578 handle_vfork_child_exec_or_exit (int exec)
580 struct inferior *inf = current_inferior ();
582 if (inf->vfork_parent)
584 int resume_parent = -1;
586 /* This exec or exit marks the end of the shared memory region
587 between the parent and the child. If the user wanted to
588 detach from the parent, now is the time. */
590 if (inf->vfork_parent->pending_detach)
592 struct thread_info *tp;
593 struct cleanup *old_chain;
594 struct program_space *pspace;
595 struct address_space *aspace;
597 /* follow-fork child, detach-on-fork on */
599 old_chain = make_cleanup_restore_current_thread ();
601 /* We're letting loose of the parent. */
602 tp = any_live_thread_of_process (inf->vfork_parent->pid);
603 switch_to_thread (tp->ptid);
605 /* We're about to detach from the parent, which implicitly
606 removes breakpoints from its address space. There's a
607 catch here: we want to reuse the spaces for the child,
608 but, parent/child are still sharing the pspace at this
609 point, although the exec in reality makes the kernel give
610 the child a fresh set of new pages. The problem here is
611 that the breakpoints module being unaware of this, would
612 likely chose the child process to write to the parent
613 address space. Swapping the child temporarily away from
614 the spaces has the desired effect. Yes, this is "sort
617 pspace = inf->pspace;
618 aspace = inf->aspace;
622 if (debug_infrun || info_verbose)
624 target_terminal_ours ();
627 fprintf_filtered (gdb_stdlog,
628 "Detaching vfork parent process %d after child exec.\n",
629 inf->vfork_parent->pid);
631 fprintf_filtered (gdb_stdlog,
632 "Detaching vfork parent process %d after child exit.\n",
633 inf->vfork_parent->pid);
636 target_detach (NULL, 0);
639 inf->pspace = pspace;
640 inf->aspace = aspace;
642 do_cleanups (old_chain);
646 /* We're staying attached to the parent, so, really give the
647 child a new address space. */
648 inf->pspace = add_program_space (maybe_new_address_space ());
649 inf->aspace = inf->pspace->aspace;
651 set_current_program_space (inf->pspace);
653 resume_parent = inf->vfork_parent->pid;
655 /* Break the bonds. */
656 inf->vfork_parent->vfork_child = NULL;
660 struct cleanup *old_chain;
661 struct program_space *pspace;
663 /* If this is a vfork child exiting, then the pspace and
664 aspaces were shared with the parent. Since we're
665 reporting the process exit, we'll be mourning all that is
666 found in the address space, and switching to null_ptid,
667 preparing to start a new inferior. But, since we don't
668 want to clobber the parent's address/program spaces, we
669 go ahead and create a new one for this exiting
672 /* Switch to null_ptid, so that clone_program_space doesn't want
673 to read the selected frame of a dead process. */
674 old_chain = save_inferior_ptid ();
675 inferior_ptid = null_ptid;
677 /* This inferior is dead, so avoid giving the breakpoints
678 module the option to write through to it (cloning a
679 program space resets breakpoints). */
682 pspace = add_program_space (maybe_new_address_space ());
683 set_current_program_space (pspace);
685 clone_program_space (pspace, inf->vfork_parent->pspace);
686 inf->pspace = pspace;
687 inf->aspace = pspace->aspace;
689 /* Put back inferior_ptid. We'll continue mourning this
691 do_cleanups (old_chain);
693 resume_parent = inf->vfork_parent->pid;
694 /* Break the bonds. */
695 inf->vfork_parent->vfork_child = NULL;
698 inf->vfork_parent = NULL;
700 gdb_assert (current_program_space == inf->pspace);
702 if (non_stop && resume_parent != -1)
704 /* If the user wanted the parent to be running, let it go
706 struct cleanup *old_chain = make_cleanup_restore_current_thread ();
709 fprintf_unfiltered (gdb_stdlog, "infrun: resuming vfork parent process %d\n",
712 iterate_over_threads (proceed_after_vfork_done, &resume_parent);
714 do_cleanups (old_chain);
719 /* Enum strings for "set|show displaced-stepping". */
721 static const char follow_exec_mode_new[] = "new";
722 static const char follow_exec_mode_same[] = "same";
723 static const char *follow_exec_mode_names[] =
725 follow_exec_mode_new,
726 follow_exec_mode_same,
730 static const char *follow_exec_mode_string = follow_exec_mode_same;
732 show_follow_exec_mode_string (struct ui_file *file, int from_tty,
733 struct cmd_list_element *c, const char *value)
735 fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value);
738 /* EXECD_PATHNAME is assumed to be non-NULL. */
741 follow_exec (ptid_t pid, char *execd_pathname)
743 struct thread_info *th = inferior_thread ();
744 struct inferior *inf = current_inferior ();
746 /* This is an exec event that we actually wish to pay attention to.
747 Refresh our symbol table to the newly exec'd program, remove any
750 If there are breakpoints, they aren't really inserted now,
751 since the exec() transformed our inferior into a fresh set
754 We want to preserve symbolic breakpoints on the list, since
755 we have hopes that they can be reset after the new a.out's
756 symbol table is read.
758 However, any "raw" breakpoints must be removed from the list
759 (e.g., the solib bp's), since their address is probably invalid
762 And, we DON'T want to call delete_breakpoints() here, since
763 that may write the bp's "shadow contents" (the instruction
764 value that was overwritten witha TRAP instruction). Since
765 we now have a new a.out, those shadow contents aren't valid. */
767 mark_breakpoints_out ();
769 update_breakpoints_after_exec ();
771 /* If there was one, it's gone now. We cannot truly step-to-next
772 statement through an exec(). */
773 th->control.step_resume_breakpoint = NULL;
774 th->control.step_range_start = 0;
775 th->control.step_range_end = 0;
777 /* The target reports the exec event to the main thread, even if
778 some other thread does the exec, and even if the main thread was
779 already stopped --- if debugging in non-stop mode, it's possible
780 the user had the main thread held stopped in the previous image
781 --- release it now. This is the same behavior as step-over-exec
782 with scheduler-locking on in all-stop mode. */
783 th->stop_requested = 0;
785 /* What is this a.out's name? */
786 printf_unfiltered (_("%s is executing new program: %s\n"),
787 target_pid_to_str (inferior_ptid),
790 /* We've followed the inferior through an exec. Therefore, the
791 inferior has essentially been killed & reborn. */
793 gdb_flush (gdb_stdout);
795 breakpoint_init_inferior (inf_execd);
797 if (gdb_sysroot && *gdb_sysroot)
799 char *name = alloca (strlen (gdb_sysroot)
800 + strlen (execd_pathname)
803 strcpy (name, gdb_sysroot);
804 strcat (name, execd_pathname);
805 execd_pathname = name;
808 /* Reset the shared library package. This ensures that we get a
809 shlib event when the child reaches "_start", at which point the
810 dld will have had a chance to initialize the child. */
811 /* Also, loading a symbol file below may trigger symbol lookups, and
812 we don't want those to be satisfied by the libraries of the
813 previous incarnation of this process. */
814 no_shared_libraries (NULL, 0);
816 if (follow_exec_mode_string == follow_exec_mode_new)
818 struct program_space *pspace;
820 /* The user wants to keep the old inferior and program spaces
821 around. Create a new fresh one, and switch to it. */
823 inf = add_inferior (current_inferior ()->pid);
824 pspace = add_program_space (maybe_new_address_space ());
825 inf->pspace = pspace;
826 inf->aspace = pspace->aspace;
828 exit_inferior_num_silent (current_inferior ()->num);
830 set_current_inferior (inf);
831 set_current_program_space (pspace);
834 gdb_assert (current_program_space == inf->pspace);
836 /* That a.out is now the one to use. */
837 exec_file_attach (execd_pathname, 0);
839 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
840 (Position Independent Executable) main symbol file will get applied by
841 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
842 the breakpoints with the zero displacement. */
844 symbol_file_add (execd_pathname, SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET,
847 set_initial_language ();
849 #ifdef SOLIB_CREATE_INFERIOR_HOOK
850 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
852 solib_create_inferior_hook (0);
855 jit_inferior_created_hook ();
857 breakpoint_re_set ();
859 /* Reinsert all breakpoints. (Those which were symbolic have
860 been reset to the proper address in the new a.out, thanks
861 to symbol_file_command...) */
862 insert_breakpoints ();
864 /* The next resume of this inferior should bring it to the shlib
865 startup breakpoints. (If the user had also set bp's on
866 "main" from the old (parent) process, then they'll auto-
867 matically get reset there in the new process.) */
870 /* Non-zero if we just simulating a single-step. This is needed
871 because we cannot remove the breakpoints in the inferior process
872 until after the `wait' in `wait_for_inferior'. */
873 static int singlestep_breakpoints_inserted_p = 0;
875 /* The thread we inserted single-step breakpoints for. */
876 static ptid_t singlestep_ptid;
878 /* PC when we started this single-step. */
879 static CORE_ADDR singlestep_pc;
881 /* If another thread hit the singlestep breakpoint, we save the original
882 thread here so that we can resume single-stepping it later. */
883 static ptid_t saved_singlestep_ptid;
884 static int stepping_past_singlestep_breakpoint;
886 /* If not equal to null_ptid, this means that after stepping over breakpoint
887 is finished, we need to switch to deferred_step_ptid, and step it.
889 The use case is when one thread has hit a breakpoint, and then the user
890 has switched to another thread and issued 'step'. We need to step over
891 breakpoint in the thread which hit the breakpoint, but then continue
892 stepping the thread user has selected. */
893 static ptid_t deferred_step_ptid;
895 /* Displaced stepping. */
897 /* In non-stop debugging mode, we must take special care to manage
898 breakpoints properly; in particular, the traditional strategy for
899 stepping a thread past a breakpoint it has hit is unsuitable.
900 'Displaced stepping' is a tactic for stepping one thread past a
901 breakpoint it has hit while ensuring that other threads running
902 concurrently will hit the breakpoint as they should.
904 The traditional way to step a thread T off a breakpoint in a
905 multi-threaded program in all-stop mode is as follows:
907 a0) Initially, all threads are stopped, and breakpoints are not
909 a1) We single-step T, leaving breakpoints uninserted.
910 a2) We insert breakpoints, and resume all threads.
912 In non-stop debugging, however, this strategy is unsuitable: we
913 don't want to have to stop all threads in the system in order to
914 continue or step T past a breakpoint. Instead, we use displaced
917 n0) Initially, T is stopped, other threads are running, and
918 breakpoints are inserted.
919 n1) We copy the instruction "under" the breakpoint to a separate
920 location, outside the main code stream, making any adjustments
921 to the instruction, register, and memory state as directed by
923 n2) We single-step T over the instruction at its new location.
924 n3) We adjust the resulting register and memory state as directed
925 by T's architecture. This includes resetting T's PC to point
926 back into the main instruction stream.
929 This approach depends on the following gdbarch methods:
931 - gdbarch_max_insn_length and gdbarch_displaced_step_location
932 indicate where to copy the instruction, and how much space must
933 be reserved there. We use these in step n1.
935 - gdbarch_displaced_step_copy_insn copies a instruction to a new
936 address, and makes any necessary adjustments to the instruction,
937 register contents, and memory. We use this in step n1.
939 - gdbarch_displaced_step_fixup adjusts registers and memory after
940 we have successfuly single-stepped the instruction, to yield the
941 same effect the instruction would have had if we had executed it
942 at its original address. We use this in step n3.
944 - gdbarch_displaced_step_free_closure provides cleanup.
946 The gdbarch_displaced_step_copy_insn and
947 gdbarch_displaced_step_fixup functions must be written so that
948 copying an instruction with gdbarch_displaced_step_copy_insn,
949 single-stepping across the copied instruction, and then applying
950 gdbarch_displaced_insn_fixup should have the same effects on the
951 thread's memory and registers as stepping the instruction in place
952 would have. Exactly which responsibilities fall to the copy and
953 which fall to the fixup is up to the author of those functions.
955 See the comments in gdbarch.sh for details.
957 Note that displaced stepping and software single-step cannot
958 currently be used in combination, although with some care I think
959 they could be made to. Software single-step works by placing
960 breakpoints on all possible subsequent instructions; if the
961 displaced instruction is a PC-relative jump, those breakpoints
962 could fall in very strange places --- on pages that aren't
963 executable, or at addresses that are not proper instruction
964 boundaries. (We do generally let other threads run while we wait
965 to hit the software single-step breakpoint, and they might
966 encounter such a corrupted instruction.) One way to work around
967 this would be to have gdbarch_displaced_step_copy_insn fully
968 simulate the effect of PC-relative instructions (and return NULL)
969 on architectures that use software single-stepping.
971 In non-stop mode, we can have independent and simultaneous step
972 requests, so more than one thread may need to simultaneously step
973 over a breakpoint. The current implementation assumes there is
974 only one scratch space per process. In this case, we have to
975 serialize access to the scratch space. If thread A wants to step
976 over a breakpoint, but we are currently waiting for some other
977 thread to complete a displaced step, we leave thread A stopped and
978 place it in the displaced_step_request_queue. Whenever a displaced
979 step finishes, we pick the next thread in the queue and start a new
980 displaced step operation on it. See displaced_step_prepare and
981 displaced_step_fixup for details. */
983 struct displaced_step_request
986 struct displaced_step_request *next;
989 /* Per-inferior displaced stepping state. */
990 struct displaced_step_inferior_state
992 /* Pointer to next in linked list. */
993 struct displaced_step_inferior_state *next;
995 /* The process this displaced step state refers to. */
998 /* A queue of pending displaced stepping requests. One entry per
999 thread that needs to do a displaced step. */
1000 struct displaced_step_request *step_request_queue;
1002 /* If this is not null_ptid, this is the thread carrying out a
1003 displaced single-step in process PID. This thread's state will
1004 require fixing up once it has completed its step. */
1007 /* The architecture the thread had when we stepped it. */
1008 struct gdbarch *step_gdbarch;
1010 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1011 for post-step cleanup. */
1012 struct displaced_step_closure *step_closure;
1014 /* The address of the original instruction, and the copy we
1016 CORE_ADDR step_original, step_copy;
1018 /* Saved contents of copy area. */
1019 gdb_byte *step_saved_copy;
1022 /* The list of states of processes involved in displaced stepping
1024 static struct displaced_step_inferior_state *displaced_step_inferior_states;
1026 /* Get the displaced stepping state of process PID. */
1028 static struct displaced_step_inferior_state *
1029 get_displaced_stepping_state (int pid)
1031 struct displaced_step_inferior_state *state;
1033 for (state = displaced_step_inferior_states;
1035 state = state->next)
1036 if (state->pid == pid)
1042 /* Add a new displaced stepping state for process PID to the displaced
1043 stepping state list, or return a pointer to an already existing
1044 entry, if it already exists. Never returns NULL. */
1046 static struct displaced_step_inferior_state *
1047 add_displaced_stepping_state (int pid)
1049 struct displaced_step_inferior_state *state;
1051 for (state = displaced_step_inferior_states;
1053 state = state->next)
1054 if (state->pid == pid)
1057 state = xcalloc (1, sizeof (*state));
1059 state->next = displaced_step_inferior_states;
1060 displaced_step_inferior_states = state;
1065 /* Remove the displaced stepping state of process PID. */
1068 remove_displaced_stepping_state (int pid)
1070 struct displaced_step_inferior_state *it, **prev_next_p;
1072 gdb_assert (pid != 0);
1074 it = displaced_step_inferior_states;
1075 prev_next_p = &displaced_step_inferior_states;
1080 *prev_next_p = it->next;
1085 prev_next_p = &it->next;
1091 infrun_inferior_exit (struct inferior *inf)
1093 remove_displaced_stepping_state (inf->pid);
1096 /* Enum strings for "set|show displaced-stepping". */
1098 static const char can_use_displaced_stepping_auto[] = "auto";
1099 static const char can_use_displaced_stepping_on[] = "on";
1100 static const char can_use_displaced_stepping_off[] = "off";
1101 static const char *can_use_displaced_stepping_enum[] =
1103 can_use_displaced_stepping_auto,
1104 can_use_displaced_stepping_on,
1105 can_use_displaced_stepping_off,
1109 /* If ON, and the architecture supports it, GDB will use displaced
1110 stepping to step over breakpoints. If OFF, or if the architecture
1111 doesn't support it, GDB will instead use the traditional
1112 hold-and-step approach. If AUTO (which is the default), GDB will
1113 decide which technique to use to step over breakpoints depending on
1114 which of all-stop or non-stop mode is active --- displaced stepping
1115 in non-stop mode; hold-and-step in all-stop mode. */
1117 static const char *can_use_displaced_stepping =
1118 can_use_displaced_stepping_auto;
1121 show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
1122 struct cmd_list_element *c,
1125 if (can_use_displaced_stepping == can_use_displaced_stepping_auto)
1126 fprintf_filtered (file, _("\
1127 Debugger's willingness to use displaced stepping to step over \
1128 breakpoints is %s (currently %s).\n"),
1129 value, non_stop ? "on" : "off");
1131 fprintf_filtered (file, _("\
1132 Debugger's willingness to use displaced stepping to step over \
1133 breakpoints is %s.\n"), value);
1136 /* Return non-zero if displaced stepping can/should be used to step
1137 over breakpoints. */
1140 use_displaced_stepping (struct gdbarch *gdbarch)
1142 return (((can_use_displaced_stepping == can_use_displaced_stepping_auto
1144 || can_use_displaced_stepping == can_use_displaced_stepping_on)
1145 && gdbarch_displaced_step_copy_insn_p (gdbarch)
1146 && !RECORD_IS_USED);
1149 /* Clean out any stray displaced stepping state. */
1151 displaced_step_clear (struct displaced_step_inferior_state *displaced)
1153 /* Indicate that there is no cleanup pending. */
1154 displaced->step_ptid = null_ptid;
1156 if (displaced->step_closure)
1158 gdbarch_displaced_step_free_closure (displaced->step_gdbarch,
1159 displaced->step_closure);
1160 displaced->step_closure = NULL;
1165 displaced_step_clear_cleanup (void *arg)
1167 struct displaced_step_inferior_state *state = arg;
1169 displaced_step_clear (state);
1172 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1174 displaced_step_dump_bytes (struct ui_file *file,
1175 const gdb_byte *buf,
1180 for (i = 0; i < len; i++)
1181 fprintf_unfiltered (file, "%02x ", buf[i]);
1182 fputs_unfiltered ("\n", file);
1185 /* Prepare to single-step, using displaced stepping.
1187 Note that we cannot use displaced stepping when we have a signal to
1188 deliver. If we have a signal to deliver and an instruction to step
1189 over, then after the step, there will be no indication from the
1190 target whether the thread entered a signal handler or ignored the
1191 signal and stepped over the instruction successfully --- both cases
1192 result in a simple SIGTRAP. In the first case we mustn't do a
1193 fixup, and in the second case we must --- but we can't tell which.
1194 Comments in the code for 'random signals' in handle_inferior_event
1195 explain how we handle this case instead.
1197 Returns 1 if preparing was successful -- this thread is going to be
1198 stepped now; or 0 if displaced stepping this thread got queued. */
1200 displaced_step_prepare (ptid_t ptid)
1202 struct cleanup *old_cleanups, *ignore_cleanups;
1203 struct regcache *regcache = get_thread_regcache (ptid);
1204 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1205 CORE_ADDR original, copy;
1207 struct displaced_step_closure *closure;
1208 struct displaced_step_inferior_state *displaced;
1210 /* We should never reach this function if the architecture does not
1211 support displaced stepping. */
1212 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
1214 /* We have to displaced step one thread at a time, as we only have
1215 access to a single scratch space per inferior. */
1217 displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
1219 if (!ptid_equal (displaced->step_ptid, null_ptid))
1221 /* Already waiting for a displaced step to finish. Defer this
1222 request and place in queue. */
1223 struct displaced_step_request *req, *new_req;
1225 if (debug_displaced)
1226 fprintf_unfiltered (gdb_stdlog,
1227 "displaced: defering step of %s\n",
1228 target_pid_to_str (ptid));
1230 new_req = xmalloc (sizeof (*new_req));
1231 new_req->ptid = ptid;
1232 new_req->next = NULL;
1234 if (displaced->step_request_queue)
1236 for (req = displaced->step_request_queue;
1240 req->next = new_req;
1243 displaced->step_request_queue = new_req;
1249 if (debug_displaced)
1250 fprintf_unfiltered (gdb_stdlog,
1251 "displaced: stepping %s now\n",
1252 target_pid_to_str (ptid));
1255 displaced_step_clear (displaced);
1257 old_cleanups = save_inferior_ptid ();
1258 inferior_ptid = ptid;
1260 original = regcache_read_pc (regcache);
1262 copy = gdbarch_displaced_step_location (gdbarch);
1263 len = gdbarch_max_insn_length (gdbarch);
1265 /* Save the original contents of the copy area. */
1266 displaced->step_saved_copy = xmalloc (len);
1267 ignore_cleanups = make_cleanup (free_current_contents,
1268 &displaced->step_saved_copy);
1269 read_memory (copy, displaced->step_saved_copy, len);
1270 if (debug_displaced)
1272 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
1273 paddress (gdbarch, copy));
1274 displaced_step_dump_bytes (gdb_stdlog,
1275 displaced->step_saved_copy,
1279 closure = gdbarch_displaced_step_copy_insn (gdbarch,
1280 original, copy, regcache);
1282 /* We don't support the fully-simulated case at present. */
1283 gdb_assert (closure);
1285 /* Save the information we need to fix things up if the step
1287 displaced->step_ptid = ptid;
1288 displaced->step_gdbarch = gdbarch;
1289 displaced->step_closure = closure;
1290 displaced->step_original = original;
1291 displaced->step_copy = copy;
1293 make_cleanup (displaced_step_clear_cleanup, displaced);
1295 /* Resume execution at the copy. */
1296 regcache_write_pc (regcache, copy);
1298 discard_cleanups (ignore_cleanups);
1300 do_cleanups (old_cleanups);
1302 if (debug_displaced)
1303 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
1304 paddress (gdbarch, copy));
1310 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
1312 struct cleanup *ptid_cleanup = save_inferior_ptid ();
1314 inferior_ptid = ptid;
1315 write_memory (memaddr, myaddr, len);
1316 do_cleanups (ptid_cleanup);
1320 displaced_step_fixup (ptid_t event_ptid, enum target_signal signal)
1322 struct cleanup *old_cleanups;
1323 struct displaced_step_inferior_state *displaced
1324 = get_displaced_stepping_state (ptid_get_pid (event_ptid));
1326 /* Was any thread of this process doing a displaced step? */
1327 if (displaced == NULL)
1330 /* Was this event for the pid we displaced? */
1331 if (ptid_equal (displaced->step_ptid, null_ptid)
1332 || ! ptid_equal (displaced->step_ptid, event_ptid))
1335 old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
1337 /* Restore the contents of the copy area. */
1339 ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
1341 write_memory_ptid (displaced->step_ptid, displaced->step_copy,
1342 displaced->step_saved_copy, len);
1343 if (debug_displaced)
1344 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s\n",
1345 paddress (displaced->step_gdbarch,
1346 displaced->step_copy));
1349 /* Did the instruction complete successfully? */
1350 if (signal == TARGET_SIGNAL_TRAP)
1352 /* Fix up the resulting state. */
1353 gdbarch_displaced_step_fixup (displaced->step_gdbarch,
1354 displaced->step_closure,
1355 displaced->step_original,
1356 displaced->step_copy,
1357 get_thread_regcache (displaced->step_ptid));
1361 /* Since the instruction didn't complete, all we can do is
1363 struct regcache *regcache = get_thread_regcache (event_ptid);
1364 CORE_ADDR pc = regcache_read_pc (regcache);
1366 pc = displaced->step_original + (pc - displaced->step_copy);
1367 regcache_write_pc (regcache, pc);
1370 do_cleanups (old_cleanups);
1372 displaced->step_ptid = null_ptid;
1374 /* Are there any pending displaced stepping requests? If so, run
1375 one now. Leave the state object around, since we're likely to
1376 need it again soon. */
1377 while (displaced->step_request_queue)
1379 struct displaced_step_request *head;
1381 struct regcache *regcache;
1382 struct gdbarch *gdbarch;
1383 CORE_ADDR actual_pc;
1384 struct address_space *aspace;
1386 head = displaced->step_request_queue;
1388 displaced->step_request_queue = head->next;
1391 context_switch (ptid);
1393 regcache = get_thread_regcache (ptid);
1394 actual_pc = regcache_read_pc (regcache);
1395 aspace = get_regcache_aspace (regcache);
1397 if (breakpoint_here_p (aspace, actual_pc))
1399 if (debug_displaced)
1400 fprintf_unfiltered (gdb_stdlog,
1401 "displaced: stepping queued %s now\n",
1402 target_pid_to_str (ptid));
1404 displaced_step_prepare (ptid);
1406 gdbarch = get_regcache_arch (regcache);
1408 if (debug_displaced)
1410 CORE_ADDR actual_pc = regcache_read_pc (regcache);
1413 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1414 paddress (gdbarch, actual_pc));
1415 read_memory (actual_pc, buf, sizeof (buf));
1416 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1419 if (gdbarch_displaced_step_hw_singlestep (gdbarch,
1420 displaced->step_closure))
1421 target_resume (ptid, 1, TARGET_SIGNAL_0);
1423 target_resume (ptid, 0, TARGET_SIGNAL_0);
1425 /* Done, we're stepping a thread. */
1431 struct thread_info *tp = inferior_thread ();
1433 /* The breakpoint we were sitting under has since been
1435 tp->control.trap_expected = 0;
1437 /* Go back to what we were trying to do. */
1438 step = currently_stepping (tp);
1440 if (debug_displaced)
1441 fprintf_unfiltered (gdb_stdlog, "breakpoint is gone %s: step(%d)\n",
1442 target_pid_to_str (tp->ptid), step);
1444 target_resume (ptid, step, TARGET_SIGNAL_0);
1445 tp->suspend.stop_signal = TARGET_SIGNAL_0;
1447 /* This request was discarded. See if there's any other
1448 thread waiting for its turn. */
1453 /* Update global variables holding ptids to hold NEW_PTID if they were
1454 holding OLD_PTID. */
1456 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
1458 struct displaced_step_request *it;
1459 struct displaced_step_inferior_state *displaced;
1461 if (ptid_equal (inferior_ptid, old_ptid))
1462 inferior_ptid = new_ptid;
1464 if (ptid_equal (singlestep_ptid, old_ptid))
1465 singlestep_ptid = new_ptid;
1467 if (ptid_equal (deferred_step_ptid, old_ptid))
1468 deferred_step_ptid = new_ptid;
1470 for (displaced = displaced_step_inferior_states;
1472 displaced = displaced->next)
1474 if (ptid_equal (displaced->step_ptid, old_ptid))
1475 displaced->step_ptid = new_ptid;
1477 for (it = displaced->step_request_queue; it; it = it->next)
1478 if (ptid_equal (it->ptid, old_ptid))
1479 it->ptid = new_ptid;
1486 /* Things to clean up if we QUIT out of resume (). */
1488 resume_cleanups (void *ignore)
1493 static const char schedlock_off[] = "off";
1494 static const char schedlock_on[] = "on";
1495 static const char schedlock_step[] = "step";
1496 static const char *scheduler_enums[] = {
1502 static const char *scheduler_mode = schedlock_off;
1504 show_scheduler_mode (struct ui_file *file, int from_tty,
1505 struct cmd_list_element *c, const char *value)
1507 fprintf_filtered (file, _("\
1508 Mode for locking scheduler during execution is \"%s\".\n"),
1513 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
1515 if (!target_can_lock_scheduler)
1517 scheduler_mode = schedlock_off;
1518 error (_("Target '%s' cannot support this command."), target_shortname);
1522 /* True if execution commands resume all threads of all processes by
1523 default; otherwise, resume only threads of the current inferior
1525 int sched_multi = 0;
1527 /* Try to setup for software single stepping over the specified location.
1528 Return 1 if target_resume() should use hardware single step.
1530 GDBARCH the current gdbarch.
1531 PC the location to step over. */
1534 maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
1538 if (execution_direction == EXEC_FORWARD
1539 && gdbarch_software_single_step_p (gdbarch)
1540 && gdbarch_software_single_step (gdbarch, get_current_frame ()))
1543 /* Do not pull these breakpoints until after a `wait' in
1544 `wait_for_inferior' */
1545 singlestep_breakpoints_inserted_p = 1;
1546 singlestep_ptid = inferior_ptid;
1552 /* Resume the inferior, but allow a QUIT. This is useful if the user
1553 wants to interrupt some lengthy single-stepping operation
1554 (for child processes, the SIGINT goes to the inferior, and so
1555 we get a SIGINT random_signal, but for remote debugging and perhaps
1556 other targets, that's not true).
1558 STEP nonzero if we should step (zero to continue instead).
1559 SIG is the signal to give the inferior (zero for none). */
1561 resume (int step, enum target_signal sig)
1563 int should_resume = 1;
1564 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
1565 struct regcache *regcache = get_current_regcache ();
1566 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1567 struct thread_info *tp = inferior_thread ();
1568 CORE_ADDR pc = regcache_read_pc (regcache);
1569 struct address_space *aspace = get_regcache_aspace (regcache);
1573 if (current_inferior ()->waiting_for_vfork_done)
1575 /* Don't try to single-step a vfork parent that is waiting for
1576 the child to get out of the shared memory region (by exec'ing
1577 or exiting). This is particularly important on software
1578 single-step archs, as the child process would trip on the
1579 software single step breakpoint inserted for the parent
1580 process. Since the parent will not actually execute any
1581 instruction until the child is out of the shared region (such
1582 are vfork's semantics), it is safe to simply continue it.
1583 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1584 the parent, and tell it to `keep_going', which automatically
1585 re-sets it stepping. */
1587 fprintf_unfiltered (gdb_stdlog,
1588 "infrun: resume : clear step\n");
1593 fprintf_unfiltered (gdb_stdlog,
1594 "infrun: resume (step=%d, signal=%d), "
1595 "trap_expected=%d\n",
1596 step, sig, tp->control.trap_expected);
1598 /* Normally, by the time we reach `resume', the breakpoints are either
1599 removed or inserted, as appropriate. The exception is if we're sitting
1600 at a permanent breakpoint; we need to step over it, but permanent
1601 breakpoints can't be removed. So we have to test for it here. */
1602 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
1604 if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
1605 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
1608 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1609 how to step past a permanent breakpoint on this architecture. Try using\n\
1610 a command like `return' or `jump' to continue execution."));
1613 /* If enabled, step over breakpoints by executing a copy of the
1614 instruction at a different address.
1616 We can't use displaced stepping when we have a signal to deliver;
1617 the comments for displaced_step_prepare explain why. The
1618 comments in the handle_inferior event for dealing with 'random
1619 signals' explain what we do instead.
1621 We can't use displaced stepping when we are waiting for vfork_done
1622 event, displaced stepping breaks the vfork child similarly as single
1623 step software breakpoint. */
1624 if (use_displaced_stepping (gdbarch)
1625 && (tp->control.trap_expected
1626 || (step && gdbarch_software_single_step_p (gdbarch)))
1627 && sig == TARGET_SIGNAL_0
1628 && !current_inferior ()->waiting_for_vfork_done)
1630 struct displaced_step_inferior_state *displaced;
1632 if (!displaced_step_prepare (inferior_ptid))
1634 /* Got placed in displaced stepping queue. Will be resumed
1635 later when all the currently queued displaced stepping
1636 requests finish. The thread is not executing at this point,
1637 and the call to set_executing will be made later. But we
1638 need to call set_running here, since from frontend point of view,
1639 the thread is running. */
1640 set_running (inferior_ptid, 1);
1641 discard_cleanups (old_cleanups);
1645 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1646 step = gdbarch_displaced_step_hw_singlestep (gdbarch,
1647 displaced->step_closure);
1650 /* Do we need to do it the hard way, w/temp breakpoints? */
1652 step = maybe_software_singlestep (gdbarch, pc);
1658 /* If STEP is set, it's a request to use hardware stepping
1659 facilities. But in that case, we should never
1660 use singlestep breakpoint. */
1661 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
1663 /* Decide the set of threads to ask the target to resume. Start
1664 by assuming everything will be resumed, than narrow the set
1665 by applying increasingly restricting conditions. */
1667 /* By default, resume all threads of all processes. */
1668 resume_ptid = RESUME_ALL;
1670 /* Maybe resume only all threads of the current process. */
1671 if (!sched_multi && target_supports_multi_process ())
1673 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
1676 /* Maybe resume a single thread after all. */
1677 if (singlestep_breakpoints_inserted_p
1678 && stepping_past_singlestep_breakpoint)
1680 /* The situation here is as follows. In thread T1 we wanted to
1681 single-step. Lacking hardware single-stepping we've
1682 set breakpoint at the PC of the next instruction -- call it
1683 P. After resuming, we've hit that breakpoint in thread T2.
1684 Now we've removed original breakpoint, inserted breakpoint
1685 at P+1, and try to step to advance T2 past breakpoint.
1686 We need to step only T2, as if T1 is allowed to freely run,
1687 it can run past P, and if other threads are allowed to run,
1688 they can hit breakpoint at P+1, and nested hits of single-step
1689 breakpoints is not something we'd want -- that's complicated
1690 to support, and has no value. */
1691 resume_ptid = inferior_ptid;
1693 else if ((step || singlestep_breakpoints_inserted_p)
1694 && tp->control.trap_expected)
1696 /* We're allowing a thread to run past a breakpoint it has
1697 hit, by single-stepping the thread with the breakpoint
1698 removed. In which case, we need to single-step only this
1699 thread, and keep others stopped, as they can miss this
1700 breakpoint if allowed to run.
1702 The current code actually removes all breakpoints when
1703 doing this, not just the one being stepped over, so if we
1704 let other threads run, we can actually miss any
1705 breakpoint, not just the one at PC. */
1706 resume_ptid = inferior_ptid;
1710 /* With non-stop mode on, threads are always handled
1712 resume_ptid = inferior_ptid;
1714 else if ((scheduler_mode == schedlock_on)
1715 || (scheduler_mode == schedlock_step
1716 && (step || singlestep_breakpoints_inserted_p)))
1718 /* User-settable 'scheduler' mode requires solo thread resume. */
1719 resume_ptid = inferior_ptid;
1722 if (gdbarch_cannot_step_breakpoint (gdbarch))
1724 /* Most targets can step a breakpoint instruction, thus
1725 executing it normally. But if this one cannot, just
1726 continue and we will hit it anyway. */
1727 if (step && breakpoint_inserted_here_p (aspace, pc))
1732 && use_displaced_stepping (gdbarch)
1733 && tp->control.trap_expected)
1735 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
1736 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
1737 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
1740 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1741 paddress (resume_gdbarch, actual_pc));
1742 read_memory (actual_pc, buf, sizeof (buf));
1743 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1746 /* Install inferior's terminal modes. */
1747 target_terminal_inferior ();
1749 /* Avoid confusing the next resume, if the next stop/resume
1750 happens to apply to another thread. */
1751 tp->suspend.stop_signal = TARGET_SIGNAL_0;
1753 target_resume (resume_ptid, step, sig);
1756 discard_cleanups (old_cleanups);
1761 /* Clear out all variables saying what to do when inferior is continued.
1762 First do this, then set the ones you want, then call `proceed'. */
1765 clear_proceed_status_thread (struct thread_info *tp)
1768 fprintf_unfiltered (gdb_stdlog,
1769 "infrun: clear_proceed_status_thread (%s)\n",
1770 target_pid_to_str (tp->ptid));
1772 tp->control.trap_expected = 0;
1773 tp->control.step_range_start = 0;
1774 tp->control.step_range_end = 0;
1775 tp->control.step_frame_id = null_frame_id;
1776 tp->control.step_stack_frame_id = null_frame_id;
1777 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
1778 tp->stop_requested = 0;
1780 tp->control.stop_step = 0;
1782 tp->control.proceed_to_finish = 0;
1784 /* Discard any remaining commands or status from previous stop. */
1785 bpstat_clear (&tp->control.stop_bpstat);
1789 clear_proceed_status_callback (struct thread_info *tp, void *data)
1791 if (is_exited (tp->ptid))
1794 clear_proceed_status_thread (tp);
1799 clear_proceed_status (void)
1803 /* In all-stop mode, delete the per-thread status of all
1804 threads, even if inferior_ptid is null_ptid, there may be
1805 threads on the list. E.g., we may be launching a new
1806 process, while selecting the executable. */
1807 iterate_over_threads (clear_proceed_status_callback, NULL);
1810 if (!ptid_equal (inferior_ptid, null_ptid))
1812 struct inferior *inferior;
1816 /* If in non-stop mode, only delete the per-thread status of
1817 the current thread. */
1818 clear_proceed_status_thread (inferior_thread ());
1821 inferior = current_inferior ();
1822 inferior->control.stop_soon = NO_STOP_QUIETLY;
1825 stop_after_trap = 0;
1827 observer_notify_about_to_proceed ();
1831 regcache_xfree (stop_registers);
1832 stop_registers = NULL;
1836 /* Check the current thread against the thread that reported the most recent
1837 event. If a step-over is required return TRUE and set the current thread
1838 to the old thread. Otherwise return FALSE.
1840 This should be suitable for any targets that support threads. */
1843 prepare_to_proceed (int step)
1846 struct target_waitstatus wait_status;
1847 int schedlock_enabled;
1849 /* With non-stop mode on, threads are always handled individually. */
1850 gdb_assert (! non_stop);
1852 /* Get the last target status returned by target_wait(). */
1853 get_last_target_status (&wait_ptid, &wait_status);
1855 /* Make sure we were stopped at a breakpoint. */
1856 if (wait_status.kind != TARGET_WAITKIND_STOPPED
1857 || (wait_status.value.sig != TARGET_SIGNAL_TRAP
1858 && wait_status.value.sig != TARGET_SIGNAL_ILL
1859 && wait_status.value.sig != TARGET_SIGNAL_SEGV
1860 && wait_status.value.sig != TARGET_SIGNAL_EMT))
1865 schedlock_enabled = (scheduler_mode == schedlock_on
1866 || (scheduler_mode == schedlock_step
1869 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
1870 if (schedlock_enabled)
1873 /* Don't switch over if we're about to resume some other process
1874 other than WAIT_PTID's, and schedule-multiple is off. */
1876 && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid))
1879 /* Switched over from WAIT_PID. */
1880 if (!ptid_equal (wait_ptid, minus_one_ptid)
1881 && !ptid_equal (inferior_ptid, wait_ptid))
1883 struct regcache *regcache = get_thread_regcache (wait_ptid);
1885 if (breakpoint_here_p (get_regcache_aspace (regcache),
1886 regcache_read_pc (regcache)))
1888 /* If stepping, remember current thread to switch back to. */
1890 deferred_step_ptid = inferior_ptid;
1892 /* Switch back to WAIT_PID thread. */
1893 switch_to_thread (wait_ptid);
1895 /* We return 1 to indicate that there is a breakpoint here,
1896 so we need to step over it before continuing to avoid
1897 hitting it straight away. */
1905 /* Basic routine for continuing the program in various fashions.
1907 ADDR is the address to resume at, or -1 for resume where stopped.
1908 SIGGNAL is the signal to give it, or 0 for none,
1909 or -1 for act according to how it stopped.
1910 STEP is nonzero if should trap after one instruction.
1911 -1 means return after that and print nothing.
1912 You should probably set various step_... variables
1913 before calling here, if you are stepping.
1915 You should call clear_proceed_status before calling proceed. */
1918 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
1920 struct regcache *regcache;
1921 struct gdbarch *gdbarch;
1922 struct thread_info *tp;
1924 struct address_space *aspace;
1927 /* If we're stopped at a fork/vfork, follow the branch set by the
1928 "set follow-fork-mode" command; otherwise, we'll just proceed
1929 resuming the current thread. */
1930 if (!follow_fork ())
1932 /* The target for some reason decided not to resume. */
1937 regcache = get_current_regcache ();
1938 gdbarch = get_regcache_arch (regcache);
1939 aspace = get_regcache_aspace (regcache);
1940 pc = regcache_read_pc (regcache);
1943 step_start_function = find_pc_function (pc);
1945 stop_after_trap = 1;
1947 if (addr == (CORE_ADDR) -1)
1949 if (pc == stop_pc && breakpoint_here_p (aspace, pc)
1950 && execution_direction != EXEC_REVERSE)
1951 /* There is a breakpoint at the address we will resume at,
1952 step one instruction before inserting breakpoints so that
1953 we do not stop right away (and report a second hit at this
1956 Note, we don't do this in reverse, because we won't
1957 actually be executing the breakpoint insn anyway.
1958 We'll be (un-)executing the previous instruction. */
1961 else if (gdbarch_single_step_through_delay_p (gdbarch)
1962 && gdbarch_single_step_through_delay (gdbarch,
1963 get_current_frame ()))
1964 /* We stepped onto an instruction that needs to be stepped
1965 again before re-inserting the breakpoint, do so. */
1970 regcache_write_pc (regcache, addr);
1974 fprintf_unfiltered (gdb_stdlog,
1975 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
1976 paddress (gdbarch, addr), siggnal, step);
1978 /* We're handling a live event, so make sure we're doing live
1979 debugging. If we're looking at traceframes while the target is
1980 running, we're going to need to get back to that mode after
1981 handling the event. */
1984 make_cleanup_restore_current_traceframe ();
1985 set_traceframe_number (-1);
1989 /* In non-stop, each thread is handled individually. The context
1990 must already be set to the right thread here. */
1994 /* In a multi-threaded task we may select another thread and
1995 then continue or step.
1997 But if the old thread was stopped at a breakpoint, it will
1998 immediately cause another breakpoint stop without any
1999 execution (i.e. it will report a breakpoint hit incorrectly).
2000 So we must step over it first.
2002 prepare_to_proceed checks the current thread against the
2003 thread that reported the most recent event. If a step-over
2004 is required it returns TRUE and sets the current thread to
2006 if (prepare_to_proceed (step))
2010 /* prepare_to_proceed may change the current thread. */
2011 tp = inferior_thread ();
2015 tp->control.trap_expected = 1;
2016 /* If displaced stepping is enabled, we can step over the
2017 breakpoint without hitting it, so leave all breakpoints
2018 inserted. Otherwise we need to disable all breakpoints, step
2019 one instruction, and then re-add them when that step is
2021 if (!use_displaced_stepping (gdbarch))
2022 remove_breakpoints ();
2025 /* We can insert breakpoints if we're not trying to step over one,
2026 or if we are stepping over one but we're using displaced stepping
2028 if (! tp->control.trap_expected || use_displaced_stepping (gdbarch))
2029 insert_breakpoints ();
2033 /* Pass the last stop signal to the thread we're resuming,
2034 irrespective of whether the current thread is the thread that
2035 got the last event or not. This was historically GDB's
2036 behaviour before keeping a stop_signal per thread. */
2038 struct thread_info *last_thread;
2040 struct target_waitstatus last_status;
2042 get_last_target_status (&last_ptid, &last_status);
2043 if (!ptid_equal (inferior_ptid, last_ptid)
2044 && !ptid_equal (last_ptid, null_ptid)
2045 && !ptid_equal (last_ptid, minus_one_ptid))
2047 last_thread = find_thread_ptid (last_ptid);
2050 tp->suspend.stop_signal = last_thread->suspend.stop_signal;
2051 last_thread->suspend.stop_signal = TARGET_SIGNAL_0;
2056 if (siggnal != TARGET_SIGNAL_DEFAULT)
2057 tp->suspend.stop_signal = siggnal;
2058 /* If this signal should not be seen by program,
2059 give it zero. Used for debugging signals. */
2060 else if (!signal_program[tp->suspend.stop_signal])
2061 tp->suspend.stop_signal = TARGET_SIGNAL_0;
2063 annotate_starting ();
2065 /* Make sure that output from GDB appears before output from the
2067 gdb_flush (gdb_stdout);
2069 /* Refresh prev_pc value just prior to resuming. This used to be
2070 done in stop_stepping, however, setting prev_pc there did not handle
2071 scenarios such as inferior function calls or returning from
2072 a function via the return command. In those cases, the prev_pc
2073 value was not set properly for subsequent commands. The prev_pc value
2074 is used to initialize the starting line number in the ecs. With an
2075 invalid value, the gdb next command ends up stopping at the position
2076 represented by the next line table entry past our start position.
2077 On platforms that generate one line table entry per line, this
2078 is not a problem. However, on the ia64, the compiler generates
2079 extraneous line table entries that do not increase the line number.
2080 When we issue the gdb next command on the ia64 after an inferior call
2081 or a return command, we often end up a few instructions forward, still
2082 within the original line we started.
2084 An attempt was made to refresh the prev_pc at the same time the
2085 execution_control_state is initialized (for instance, just before
2086 waiting for an inferior event). But this approach did not work
2087 because of platforms that use ptrace, where the pc register cannot
2088 be read unless the inferior is stopped. At that point, we are not
2089 guaranteed the inferior is stopped and so the regcache_read_pc() call
2090 can fail. Setting the prev_pc value here ensures the value is updated
2091 correctly when the inferior is stopped. */
2092 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2094 /* Fill in with reasonable starting values. */
2095 init_thread_stepping_state (tp);
2097 /* Reset to normal state. */
2098 init_infwait_state ();
2100 /* Resume inferior. */
2101 resume (oneproc || step || bpstat_should_step (), tp->suspend.stop_signal);
2103 /* Wait for it to stop (if not standalone)
2104 and in any case decode why it stopped, and act accordingly. */
2105 /* Do this only if we are not using the event loop, or if the target
2106 does not support asynchronous execution. */
2107 if (!target_can_async_p ())
2109 wait_for_inferior (0);
2115 /* Start remote-debugging of a machine over a serial link. */
2118 start_remote (int from_tty)
2120 struct inferior *inferior;
2122 init_wait_for_inferior ();
2123 inferior = current_inferior ();
2124 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2126 /* Always go on waiting for the target, regardless of the mode. */
2127 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2128 indicate to wait_for_inferior that a target should timeout if
2129 nothing is returned (instead of just blocking). Because of this,
2130 targets expecting an immediate response need to, internally, set
2131 things up so that the target_wait() is forced to eventually
2133 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2134 differentiate to its caller what the state of the target is after
2135 the initial open has been performed. Here we're assuming that
2136 the target has stopped. It should be possible to eventually have
2137 target_open() return to the caller an indication that the target
2138 is currently running and GDB state should be set to the same as
2139 for an async run. */
2140 wait_for_inferior (0);
2142 /* Now that the inferior has stopped, do any bookkeeping like
2143 loading shared libraries. We want to do this before normal_stop,
2144 so that the displayed frame is up to date. */
2145 post_create_inferior (¤t_target, from_tty);
2150 /* Initialize static vars when a new inferior begins. */
2153 init_wait_for_inferior (void)
2155 /* These are meaningless until the first time through wait_for_inferior. */
2157 breakpoint_init_inferior (inf_starting);
2159 clear_proceed_status ();
2161 stepping_past_singlestep_breakpoint = 0;
2162 deferred_step_ptid = null_ptid;
2164 target_last_wait_ptid = minus_one_ptid;
2166 previous_inferior_ptid = null_ptid;
2167 init_infwait_state ();
2169 /* Discard any skipped inlined frames. */
2170 clear_inline_frame_state (minus_one_ptid);
2174 /* This enum encodes possible reasons for doing a target_wait, so that
2175 wfi can call target_wait in one place. (Ultimately the call will be
2176 moved out of the infinite loop entirely.) */
2180 infwait_normal_state,
2181 infwait_thread_hop_state,
2182 infwait_step_watch_state,
2183 infwait_nonstep_watch_state
2186 /* The PTID we'll do a target_wait on.*/
2189 /* Current inferior wait state. */
2190 enum infwait_states infwait_state;
2192 /* Data to be passed around while handling an event. This data is
2193 discarded between events. */
2194 struct execution_control_state
2197 /* The thread that got the event, if this was a thread event; NULL
2199 struct thread_info *event_thread;
2201 struct target_waitstatus ws;
2203 CORE_ADDR stop_func_start;
2204 CORE_ADDR stop_func_end;
2205 char *stop_func_name;
2206 int new_thread_event;
2210 static void handle_inferior_event (struct execution_control_state *ecs);
2212 static void handle_step_into_function (struct gdbarch *gdbarch,
2213 struct execution_control_state *ecs);
2214 static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2215 struct execution_control_state *ecs);
2216 static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame);
2217 static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
2218 static void insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
2219 struct symtab_and_line sr_sal,
2220 struct frame_id sr_id);
2221 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
2223 static void stop_stepping (struct execution_control_state *ecs);
2224 static void prepare_to_wait (struct execution_control_state *ecs);
2225 static void keep_going (struct execution_control_state *ecs);
2227 /* Callback for iterate over threads. If the thread is stopped, but
2228 the user/frontend doesn't know about that yet, go through
2229 normal_stop, as if the thread had just stopped now. ARG points at
2230 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2231 ptid_is_pid(PTID) is true, applies to all threads of the process
2232 pointed at by PTID. Otherwise, apply only to the thread pointed by
2236 infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2238 ptid_t ptid = * (ptid_t *) arg;
2240 if ((ptid_equal (info->ptid, ptid)
2241 || ptid_equal (minus_one_ptid, ptid)
2242 || (ptid_is_pid (ptid)
2243 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2244 && is_running (info->ptid)
2245 && !is_executing (info->ptid))
2247 struct cleanup *old_chain;
2248 struct execution_control_state ecss;
2249 struct execution_control_state *ecs = &ecss;
2251 memset (ecs, 0, sizeof (*ecs));
2253 old_chain = make_cleanup_restore_current_thread ();
2255 switch_to_thread (info->ptid);
2257 /* Go through handle_inferior_event/normal_stop, so we always
2258 have consistent output as if the stop event had been
2260 ecs->ptid = info->ptid;
2261 ecs->event_thread = find_thread_ptid (info->ptid);
2262 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2263 ecs->ws.value.sig = TARGET_SIGNAL_0;
2265 handle_inferior_event (ecs);
2267 if (!ecs->wait_some_more)
2269 struct thread_info *tp;
2273 /* Finish off the continuations. The continations
2274 themselves are responsible for realising the thread
2275 didn't finish what it was supposed to do. */
2276 tp = inferior_thread ();
2277 do_all_intermediate_continuations_thread (tp);
2278 do_all_continuations_thread (tp);
2281 do_cleanups (old_chain);
2287 /* This function is attached as a "thread_stop_requested" observer.
2288 Cleanup local state that assumed the PTID was to be resumed, and
2289 report the stop to the frontend. */
2292 infrun_thread_stop_requested (ptid_t ptid)
2294 struct displaced_step_inferior_state *displaced;
2296 /* PTID was requested to stop. Remove it from the displaced
2297 stepping queue, so we don't try to resume it automatically. */
2299 for (displaced = displaced_step_inferior_states;
2301 displaced = displaced->next)
2303 struct displaced_step_request *it, **prev_next_p;
2305 it = displaced->step_request_queue;
2306 prev_next_p = &displaced->step_request_queue;
2309 if (ptid_match (it->ptid, ptid))
2311 *prev_next_p = it->next;
2317 prev_next_p = &it->next;
2324 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2328 infrun_thread_thread_exit (struct thread_info *tp, int silent)
2330 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2331 nullify_last_target_wait_ptid ();
2334 /* Callback for iterate_over_threads. */
2337 delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
2339 if (is_exited (info->ptid))
2342 delete_step_resume_breakpoint (info);
2346 /* In all-stop, delete the step resume breakpoint of any thread that
2347 had one. In non-stop, delete the step resume breakpoint of the
2348 thread that just stopped. */
2351 delete_step_thread_step_resume_breakpoint (void)
2353 if (!target_has_execution
2354 || ptid_equal (inferior_ptid, null_ptid))
2355 /* If the inferior has exited, we have already deleted the step
2356 resume breakpoints out of GDB's lists. */
2361 /* If in non-stop mode, only delete the step-resume or
2362 longjmp-resume breakpoint of the thread that just stopped
2364 struct thread_info *tp = inferior_thread ();
2366 delete_step_resume_breakpoint (tp);
2369 /* In all-stop mode, delete all step-resume and longjmp-resume
2370 breakpoints of any thread that had them. */
2371 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
2374 /* A cleanup wrapper. */
2377 delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
2379 delete_step_thread_step_resume_breakpoint ();
2382 /* Pretty print the results of target_wait, for debugging purposes. */
2385 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
2386 const struct target_waitstatus *ws)
2388 char *status_string = target_waitstatus_to_string (ws);
2389 struct ui_file *tmp_stream = mem_fileopen ();
2392 /* The text is split over several lines because it was getting too long.
2393 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2394 output as a unit; we want only one timestamp printed if debug_timestamp
2397 fprintf_unfiltered (tmp_stream,
2398 "infrun: target_wait (%d", PIDGET (waiton_ptid));
2399 if (PIDGET (waiton_ptid) != -1)
2400 fprintf_unfiltered (tmp_stream,
2401 " [%s]", target_pid_to_str (waiton_ptid));
2402 fprintf_unfiltered (tmp_stream, ", status) =\n");
2403 fprintf_unfiltered (tmp_stream,
2404 "infrun: %d [%s],\n",
2405 PIDGET (result_ptid), target_pid_to_str (result_ptid));
2406 fprintf_unfiltered (tmp_stream,
2410 text = ui_file_xstrdup (tmp_stream, NULL);
2412 /* This uses %s in part to handle %'s in the text, but also to avoid
2413 a gcc error: the format attribute requires a string literal. */
2414 fprintf_unfiltered (gdb_stdlog, "%s", text);
2416 xfree (status_string);
2418 ui_file_delete (tmp_stream);
2421 /* Prepare and stabilize the inferior for detaching it. E.g.,
2422 detaching while a thread is displaced stepping is a recipe for
2423 crashing it, as nothing would readjust the PC out of the scratch
2427 prepare_for_detach (void)
2429 struct inferior *inf = current_inferior ();
2430 ptid_t pid_ptid = pid_to_ptid (inf->pid);
2431 struct cleanup *old_chain_1;
2432 struct displaced_step_inferior_state *displaced;
2434 displaced = get_displaced_stepping_state (inf->pid);
2436 /* Is any thread of this process displaced stepping? If not,
2437 there's nothing else to do. */
2438 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
2442 fprintf_unfiltered (gdb_stdlog,
2443 "displaced-stepping in-process while detaching");
2445 old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
2448 while (!ptid_equal (displaced->step_ptid, null_ptid))
2450 struct cleanup *old_chain_2;
2451 struct execution_control_state ecss;
2452 struct execution_control_state *ecs;
2455 memset (ecs, 0, sizeof (*ecs));
2457 overlay_cache_invalid = 1;
2459 /* We have to invalidate the registers BEFORE calling
2460 target_wait because they can be loaded from the target while
2461 in target_wait. This makes remote debugging a bit more
2462 efficient for those targets that provide critical registers
2463 as part of their normal status mechanism. */
2465 registers_changed ();
2467 if (deprecated_target_wait_hook)
2468 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
2470 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
2473 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
2475 /* If an error happens while handling the event, propagate GDB's
2476 knowledge of the executing state to the frontend/user running
2478 old_chain_2 = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2480 /* In non-stop mode, each thread is handled individually.
2481 Switch early, so the global state is set correctly for this
2484 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2485 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2486 context_switch (ecs->ptid);
2488 /* Now figure out what to do with the result of the result. */
2489 handle_inferior_event (ecs);
2491 /* No error, don't finish the state yet. */
2492 discard_cleanups (old_chain_2);
2494 /* Breakpoints and watchpoints are not installed on the target
2495 at this point, and signals are passed directly to the
2496 inferior, so this must mean the process is gone. */
2497 if (!ecs->wait_some_more)
2499 discard_cleanups (old_chain_1);
2500 error (_("Program exited while detaching"));
2504 discard_cleanups (old_chain_1);
2507 /* Wait for control to return from inferior to debugger.
2509 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
2510 as if they were SIGTRAP signals. This can be useful during
2511 the startup sequence on some targets such as HP/UX, where
2512 we receive an EXEC event instead of the expected SIGTRAP.
2514 If inferior gets a signal, we may decide to start it up again
2515 instead of returning. That is why there is a loop in this function.
2516 When this function actually returns it means the inferior
2517 should be left stopped and GDB should read more commands. */
2520 wait_for_inferior (int treat_exec_as_sigtrap)
2522 struct cleanup *old_cleanups;
2523 struct execution_control_state ecss;
2524 struct execution_control_state *ecs;
2528 (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
2529 treat_exec_as_sigtrap);
2532 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
2535 memset (ecs, 0, sizeof (*ecs));
2537 /* We'll update this if & when we switch to a new thread. */
2538 previous_inferior_ptid = inferior_ptid;
2542 struct cleanup *old_chain;
2544 /* We have to invalidate the registers BEFORE calling target_wait
2545 because they can be loaded from the target while in target_wait.
2546 This makes remote debugging a bit more efficient for those
2547 targets that provide critical registers as part of their normal
2548 status mechanism. */
2550 overlay_cache_invalid = 1;
2551 registers_changed ();
2553 if (deprecated_target_wait_hook)
2554 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
2556 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
2559 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2561 if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD)
2563 xfree (ecs->ws.value.execd_pathname);
2564 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2565 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
2568 /* If an error happens while handling the event, propagate GDB's
2569 knowledge of the executing state to the frontend/user running
2571 old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2573 if (ecs->ws.kind == TARGET_WAITKIND_SYSCALL_ENTRY
2574 || ecs->ws.kind == TARGET_WAITKIND_SYSCALL_RETURN)
2575 ecs->ws.value.syscall_number = UNKNOWN_SYSCALL;
2577 /* Now figure out what to do with the result of the result. */
2578 handle_inferior_event (ecs);
2580 /* No error, don't finish the state yet. */
2581 discard_cleanups (old_chain);
2583 if (!ecs->wait_some_more)
2587 do_cleanups (old_cleanups);
2590 /* Asynchronous version of wait_for_inferior. It is called by the
2591 event loop whenever a change of state is detected on the file
2592 descriptor corresponding to the target. It can be called more than
2593 once to complete a single execution command. In such cases we need
2594 to keep the state in a global variable ECSS. If it is the last time
2595 that this function is called for a single execution command, then
2596 report to the user that the inferior has stopped, and do the
2597 necessary cleanups. */
2600 fetch_inferior_event (void *client_data)
2602 struct execution_control_state ecss;
2603 struct execution_control_state *ecs = &ecss;
2604 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
2605 struct cleanup *ts_old_chain;
2606 int was_sync = sync_execution;
2608 memset (ecs, 0, sizeof (*ecs));
2610 /* We'll update this if & when we switch to a new thread. */
2611 previous_inferior_ptid = inferior_ptid;
2614 /* In non-stop mode, the user/frontend should not notice a thread
2615 switch due to internal events. Make sure we reverse to the
2616 user selected thread and frame after handling the event and
2617 running any breakpoint commands. */
2618 make_cleanup_restore_current_thread ();
2620 /* We have to invalidate the registers BEFORE calling target_wait
2621 because they can be loaded from the target while in target_wait.
2622 This makes remote debugging a bit more efficient for those
2623 targets that provide critical registers as part of their normal
2624 status mechanism. */
2626 overlay_cache_invalid = 1;
2627 registers_changed ();
2629 if (deprecated_target_wait_hook)
2631 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2633 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2636 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2639 && ecs->ws.kind != TARGET_WAITKIND_IGNORE
2640 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2641 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2642 /* In non-stop mode, each thread is handled individually. Switch
2643 early, so the global state is set correctly for this
2645 context_switch (ecs->ptid);
2647 /* If an error happens while handling the event, propagate GDB's
2648 knowledge of the executing state to the frontend/user running
2651 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2653 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
2655 /* Now figure out what to do with the result of the result. */
2656 handle_inferior_event (ecs);
2658 if (!ecs->wait_some_more)
2660 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2662 delete_step_thread_step_resume_breakpoint ();
2664 /* We may not find an inferior if this was a process exit. */
2665 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
2668 if (target_has_execution
2669 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2670 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2671 && ecs->event_thread->step_multi
2672 && ecs->event_thread->control.stop_step)
2673 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
2675 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2678 /* No error, don't finish the thread states yet. */
2679 discard_cleanups (ts_old_chain);
2681 /* Revert thread and frame. */
2682 do_cleanups (old_chain);
2684 /* If the inferior was in sync execution mode, and now isn't,
2685 restore the prompt. */
2686 if (was_sync && !sync_execution)
2687 display_gdb_prompt (0);
2690 /* Record the frame and location we're currently stepping through. */
2692 set_step_info (struct frame_info *frame, struct symtab_and_line sal)
2694 struct thread_info *tp = inferior_thread ();
2696 tp->control.step_frame_id = get_frame_id (frame);
2697 tp->control.step_stack_frame_id = get_stack_frame_id (frame);
2699 tp->current_symtab = sal.symtab;
2700 tp->current_line = sal.line;
2703 /* Clear context switchable stepping state. */
2706 init_thread_stepping_state (struct thread_info *tss)
2708 tss->stepping_over_breakpoint = 0;
2709 tss->step_after_step_resume_breakpoint = 0;
2710 tss->stepping_through_solib_after_catch = 0;
2711 tss->stepping_through_solib_catchpoints = NULL;
2714 /* Return the cached copy of the last pid/waitstatus returned by
2715 target_wait()/deprecated_target_wait_hook(). The data is actually
2716 cached by handle_inferior_event(), which gets called immediately
2717 after target_wait()/deprecated_target_wait_hook(). */
2720 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
2722 *ptidp = target_last_wait_ptid;
2723 *status = target_last_waitstatus;
2727 nullify_last_target_wait_ptid (void)
2729 target_last_wait_ptid = minus_one_ptid;
2732 /* Switch thread contexts. */
2735 context_switch (ptid_t ptid)
2739 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
2740 target_pid_to_str (inferior_ptid));
2741 fprintf_unfiltered (gdb_stdlog, "to %s\n",
2742 target_pid_to_str (ptid));
2745 switch_to_thread (ptid);
2749 adjust_pc_after_break (struct execution_control_state *ecs)
2751 struct regcache *regcache;
2752 struct gdbarch *gdbarch;
2753 struct address_space *aspace;
2754 CORE_ADDR breakpoint_pc;
2756 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2757 we aren't, just return.
2759 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2760 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2761 implemented by software breakpoints should be handled through the normal
2764 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2765 different signals (SIGILL or SIGEMT for instance), but it is less
2766 clear where the PC is pointing afterwards. It may not match
2767 gdbarch_decr_pc_after_break. I don't know any specific target that
2768 generates these signals at breakpoints (the code has been in GDB since at
2769 least 1992) so I can not guess how to handle them here.
2771 In earlier versions of GDB, a target with
2772 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2773 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2774 target with both of these set in GDB history, and it seems unlikely to be
2775 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2777 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
2780 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
2783 /* In reverse execution, when a breakpoint is hit, the instruction
2784 under it has already been de-executed. The reported PC always
2785 points at the breakpoint address, so adjusting it further would
2786 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2789 B1 0x08000000 : INSN1
2790 B2 0x08000001 : INSN2
2792 PC -> 0x08000003 : INSN4
2794 Say you're stopped at 0x08000003 as above. Reverse continuing
2795 from that point should hit B2 as below. Reading the PC when the
2796 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2797 been de-executed already.
2799 B1 0x08000000 : INSN1
2800 B2 PC -> 0x08000001 : INSN2
2804 We can't apply the same logic as for forward execution, because
2805 we would wrongly adjust the PC to 0x08000000, since there's a
2806 breakpoint at PC - 1. We'd then report a hit on B1, although
2807 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2809 if (execution_direction == EXEC_REVERSE)
2812 /* If this target does not decrement the PC after breakpoints, then
2813 we have nothing to do. */
2814 regcache = get_thread_regcache (ecs->ptid);
2815 gdbarch = get_regcache_arch (regcache);
2816 if (gdbarch_decr_pc_after_break (gdbarch) == 0)
2819 aspace = get_regcache_aspace (regcache);
2821 /* Find the location where (if we've hit a breakpoint) the
2822 breakpoint would be. */
2823 breakpoint_pc = regcache_read_pc (regcache)
2824 - gdbarch_decr_pc_after_break (gdbarch);
2826 /* Check whether there actually is a software breakpoint inserted at
2829 If in non-stop mode, a race condition is possible where we've
2830 removed a breakpoint, but stop events for that breakpoint were
2831 already queued and arrive later. To suppress those spurious
2832 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2833 and retire them after a number of stop events are reported. */
2834 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
2835 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
2837 struct cleanup *old_cleanups = NULL;
2840 old_cleanups = record_gdb_operation_disable_set ();
2842 /* When using hardware single-step, a SIGTRAP is reported for both
2843 a completed single-step and a software breakpoint. Need to
2844 differentiate between the two, as the latter needs adjusting
2845 but the former does not.
2847 The SIGTRAP can be due to a completed hardware single-step only if
2848 - we didn't insert software single-step breakpoints
2849 - the thread to be examined is still the current thread
2850 - this thread is currently being stepped
2852 If any of these events did not occur, we must have stopped due
2853 to hitting a software breakpoint, and have to back up to the
2856 As a special case, we could have hardware single-stepped a
2857 software breakpoint. In this case (prev_pc == breakpoint_pc),
2858 we also need to back up to the breakpoint address. */
2860 if (singlestep_breakpoints_inserted_p
2861 || !ptid_equal (ecs->ptid, inferior_ptid)
2862 || !currently_stepping (ecs->event_thread)
2863 || ecs->event_thread->prev_pc == breakpoint_pc)
2864 regcache_write_pc (regcache, breakpoint_pc);
2867 do_cleanups (old_cleanups);
2872 init_infwait_state (void)
2874 waiton_ptid = pid_to_ptid (-1);
2875 infwait_state = infwait_normal_state;
2879 error_is_running (void)
2882 Cannot execute this command while the selected thread is running."));
2886 ensure_not_running (void)
2888 if (is_running (inferior_ptid))
2889 error_is_running ();
2893 stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
2895 for (frame = get_prev_frame (frame);
2897 frame = get_prev_frame (frame))
2899 if (frame_id_eq (get_frame_id (frame), step_frame_id))
2901 if (get_frame_type (frame) != INLINE_FRAME)
2908 /* Auxiliary function that handles syscall entry/return events.
2909 It returns 1 if the inferior should keep going (and GDB
2910 should ignore the event), or 0 if the event deserves to be
2914 handle_syscall_event (struct execution_control_state *ecs)
2916 struct regcache *regcache;
2917 struct gdbarch *gdbarch;
2920 if (!ptid_equal (ecs->ptid, inferior_ptid))
2921 context_switch (ecs->ptid);
2923 regcache = get_thread_regcache (ecs->ptid);
2924 gdbarch = get_regcache_arch (regcache);
2925 syscall_number = gdbarch_get_syscall_number (gdbarch, ecs->ptid);
2926 stop_pc = regcache_read_pc (regcache);
2928 target_last_waitstatus.value.syscall_number = syscall_number;
2930 if (catch_syscall_enabled () > 0
2931 && catching_syscall_number (syscall_number) > 0)
2934 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
2937 ecs->event_thread->control.stop_bpstat
2938 = bpstat_stop_status (get_regcache_aspace (regcache),
2939 stop_pc, ecs->ptid);
2941 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
2943 if (!ecs->random_signal)
2945 /* Catchpoint hit. */
2946 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
2951 /* If no catchpoint triggered for this, then keep going. */
2952 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
2957 /* Given an execution control state that has been freshly filled in
2958 by an event from the inferior, figure out what it means and take
2959 appropriate action. */
2962 handle_inferior_event (struct execution_control_state *ecs)
2964 struct frame_info *frame;
2965 struct gdbarch *gdbarch;
2966 int sw_single_step_trap_p = 0;
2967 int stopped_by_watchpoint;
2968 int stepped_after_stopped_by_watchpoint = 0;
2969 struct symtab_and_line stop_pc_sal;
2970 enum stop_kind stop_soon;
2972 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
2974 /* We had an event in the inferior, but we are not interested in
2975 handling it at this level. The lower layers have already
2976 done what needs to be done, if anything.
2978 One of the possible circumstances for this is when the
2979 inferior produces output for the console. The inferior has
2980 not stopped, and we are ignoring the event. Another possible
2981 circumstance is any event which the lower level knows will be
2982 reported multiple times without an intervening resume. */
2984 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
2985 prepare_to_wait (ecs);
2989 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
2990 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2992 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2995 stop_soon = inf->control.stop_soon;
2998 stop_soon = NO_STOP_QUIETLY;
3000 /* Cache the last pid/waitstatus. */
3001 target_last_wait_ptid = ecs->ptid;
3002 target_last_waitstatus = ecs->ws;
3004 /* Always clear state belonging to the previous time we stopped. */
3005 stop_stack_dummy = STOP_NONE;
3007 /* If it's a new process, add it to the thread database */
3009 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
3010 && !ptid_equal (ecs->ptid, minus_one_ptid)
3011 && !in_thread_list (ecs->ptid));
3013 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3014 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
3015 add_thread (ecs->ptid);
3017 ecs->event_thread = find_thread_ptid (ecs->ptid);
3019 /* Dependent on valid ECS->EVENT_THREAD. */
3020 adjust_pc_after_break (ecs);
3022 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3023 reinit_frame_cache ();
3025 breakpoint_retire_moribund ();
3027 /* First, distinguish signals caused by the debugger from signals
3028 that have to do with the program's own actions. Note that
3029 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3030 on the operating system version. Here we detect when a SIGILL or
3031 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3032 something similar for SIGSEGV, since a SIGSEGV will be generated
3033 when we're trying to execute a breakpoint instruction on a
3034 non-executable stack. This happens for call dummy breakpoints
3035 for architectures like SPARC that place call dummies on the
3037 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
3038 && (ecs->ws.value.sig == TARGET_SIGNAL_ILL
3039 || ecs->ws.value.sig == TARGET_SIGNAL_SEGV
3040 || ecs->ws.value.sig == TARGET_SIGNAL_EMT))
3042 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3044 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3045 regcache_read_pc (regcache)))
3048 fprintf_unfiltered (gdb_stdlog,
3049 "infrun: Treating signal as SIGTRAP\n");
3050 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
3054 /* Mark the non-executing threads accordingly. In all-stop, all
3055 threads of all processes are stopped when we get any event
3056 reported. In non-stop mode, only the event thread stops. If
3057 we're handling a process exit in non-stop mode, there's nothing
3058 to do, as threads of the dead process are gone, and threads of
3059 any other process were left running. */
3061 set_executing (minus_one_ptid, 0);
3062 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3063 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
3064 set_executing (inferior_ptid, 0);
3066 switch (infwait_state)
3068 case infwait_thread_hop_state:
3070 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
3073 case infwait_normal_state:
3075 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
3078 case infwait_step_watch_state:
3080 fprintf_unfiltered (gdb_stdlog,
3081 "infrun: infwait_step_watch_state\n");
3083 stepped_after_stopped_by_watchpoint = 1;
3086 case infwait_nonstep_watch_state:
3088 fprintf_unfiltered (gdb_stdlog,
3089 "infrun: infwait_nonstep_watch_state\n");
3090 insert_breakpoints ();
3092 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3093 handle things like signals arriving and other things happening
3094 in combination correctly? */
3095 stepped_after_stopped_by_watchpoint = 1;
3099 internal_error (__FILE__, __LINE__, _("bad switch"));
3102 infwait_state = infwait_normal_state;
3103 waiton_ptid = pid_to_ptid (-1);
3105 switch (ecs->ws.kind)
3107 case TARGET_WAITKIND_LOADED:
3109 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
3110 /* Ignore gracefully during startup of the inferior, as it might
3111 be the shell which has just loaded some objects, otherwise
3112 add the symbols for the newly loaded objects. Also ignore at
3113 the beginning of an attach or remote session; we will query
3114 the full list of libraries once the connection is
3116 if (stop_soon == NO_STOP_QUIETLY)
3118 /* Check for any newly added shared libraries if we're
3119 supposed to be adding them automatically. Switch
3120 terminal for any messages produced by
3121 breakpoint_re_set. */
3122 target_terminal_ours_for_output ();
3123 /* NOTE: cagney/2003-11-25: Make certain that the target
3124 stack's section table is kept up-to-date. Architectures,
3125 (e.g., PPC64), use the section table to perform
3126 operations such as address => section name and hence
3127 require the table to contain all sections (including
3128 those found in shared libraries). */
3130 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
3132 solib_add (NULL, 0, ¤t_target, auto_solib_add);
3134 target_terminal_inferior ();
3136 /* If requested, stop when the dynamic linker notifies
3137 gdb of events. This allows the user to get control
3138 and place breakpoints in initializer routines for
3139 dynamically loaded objects (among other things). */
3140 if (stop_on_solib_events)
3142 /* Make sure we print "Stopped due to solib-event" in
3144 stop_print_frame = 1;
3146 stop_stepping (ecs);
3150 /* NOTE drow/2007-05-11: This might be a good place to check
3151 for "catch load". */
3154 /* If we are skipping through a shell, or through shared library
3155 loading that we aren't interested in, resume the program. If
3156 we're running the program normally, also resume. But stop if
3157 we're attaching or setting up a remote connection. */
3158 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
3160 /* Loading of shared libraries might have changed breakpoint
3161 addresses. Make sure new breakpoints are inserted. */
3162 if (stop_soon == NO_STOP_QUIETLY
3163 && !breakpoints_always_inserted_mode ())
3164 insert_breakpoints ();
3165 resume (0, TARGET_SIGNAL_0);
3166 prepare_to_wait (ecs);
3172 case TARGET_WAITKIND_SPURIOUS:
3174 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3175 resume (0, TARGET_SIGNAL_0);
3176 prepare_to_wait (ecs);
3179 case TARGET_WAITKIND_EXITED:
3181 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
3182 inferior_ptid = ecs->ptid;
3183 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3184 set_current_program_space (current_inferior ()->pspace);
3185 handle_vfork_child_exec_or_exit (0);
3186 target_terminal_ours (); /* Must do this before mourn anyway */
3187 print_exited_reason (ecs->ws.value.integer);
3189 /* Record the exit code in the convenience variable $_exitcode, so
3190 that the user can inspect this again later. */
3191 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3192 (LONGEST) ecs->ws.value.integer);
3193 gdb_flush (gdb_stdout);
3194 target_mourn_inferior ();
3195 singlestep_breakpoints_inserted_p = 0;
3196 cancel_single_step_breakpoints ();
3197 stop_print_frame = 0;
3198 stop_stepping (ecs);
3201 case TARGET_WAITKIND_SIGNALLED:
3203 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n");
3204 inferior_ptid = ecs->ptid;
3205 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3206 set_current_program_space (current_inferior ()->pspace);
3207 handle_vfork_child_exec_or_exit (0);
3208 stop_print_frame = 0;
3209 target_terminal_ours (); /* Must do this before mourn anyway */
3211 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
3212 reach here unless the inferior is dead. However, for years
3213 target_kill() was called here, which hints that fatal signals aren't
3214 really fatal on some systems. If that's true, then some changes
3216 target_mourn_inferior ();
3218 print_signal_exited_reason (ecs->ws.value.sig);
3219 singlestep_breakpoints_inserted_p = 0;
3220 cancel_single_step_breakpoints ();
3221 stop_stepping (ecs);
3224 /* The following are the only cases in which we keep going;
3225 the above cases end in a continue or goto. */
3226 case TARGET_WAITKIND_FORKED:
3227 case TARGET_WAITKIND_VFORKED:
3229 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3231 if (!ptid_equal (ecs->ptid, inferior_ptid))
3233 context_switch (ecs->ptid);
3234 reinit_frame_cache ();
3237 /* Immediately detach breakpoints from the child before there's
3238 any chance of letting the user delete breakpoints from the
3239 breakpoint lists. If we don't do this early, it's easy to
3240 leave left over traps in the child, vis: "break foo; catch
3241 fork; c; <fork>; del; c; <child calls foo>". We only follow
3242 the fork on the last `continue', and by that time the
3243 breakpoint at "foo" is long gone from the breakpoint table.
3244 If we vforked, then we don't need to unpatch here, since both
3245 parent and child are sharing the same memory pages; we'll
3246 need to unpatch at follow/detach time instead to be certain
3247 that new breakpoints added between catchpoint hit time and
3248 vfork follow are detached. */
3249 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
3251 int child_pid = ptid_get_pid (ecs->ws.value.related_pid);
3253 /* This won't actually modify the breakpoint list, but will
3254 physically remove the breakpoints from the child. */
3255 detach_breakpoints (child_pid);
3258 if (singlestep_breakpoints_inserted_p)
3260 /* Pull the single step breakpoints out of the target. */
3261 remove_single_step_breakpoints ();
3262 singlestep_breakpoints_inserted_p = 0;
3265 /* In case the event is caught by a catchpoint, remember that
3266 the event is to be followed at the next resume of the thread,
3267 and not immediately. */
3268 ecs->event_thread->pending_follow = ecs->ws;
3270 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3272 ecs->event_thread->control.stop_bpstat
3273 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3274 stop_pc, ecs->ptid);
3276 /* Note that we're interested in knowing the bpstat actually
3277 causes a stop, not just if it may explain the signal.
3278 Software watchpoints, for example, always appear in the
3281 = !bpstat_causes_stop (ecs->event_thread->control.stop_bpstat);
3283 /* If no catchpoint triggered for this, then keep going. */
3284 if (ecs->random_signal)
3289 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
3291 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3293 should_resume = follow_fork ();
3296 child = ecs->ws.value.related_pid;
3298 /* In non-stop mode, also resume the other branch. */
3299 if (non_stop && !detach_fork)
3302 switch_to_thread (parent);
3304 switch_to_thread (child);
3306 ecs->event_thread = inferior_thread ();
3307 ecs->ptid = inferior_ptid;
3312 switch_to_thread (child);
3314 switch_to_thread (parent);
3316 ecs->event_thread = inferior_thread ();
3317 ecs->ptid = inferior_ptid;
3322 stop_stepping (ecs);
3325 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3326 goto process_event_stop_test;
3328 case TARGET_WAITKIND_VFORK_DONE:
3329 /* Done with the shared memory region. Re-insert breakpoints in
3330 the parent, and keep going. */
3333 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3335 if (!ptid_equal (ecs->ptid, inferior_ptid))
3336 context_switch (ecs->ptid);
3338 current_inferior ()->waiting_for_vfork_done = 0;
3339 current_inferior ()->pspace->breakpoints_not_allowed = 0;
3340 /* This also takes care of reinserting breakpoints in the
3341 previously locked inferior. */
3345 case TARGET_WAITKIND_EXECD:
3347 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
3349 if (!ptid_equal (ecs->ptid, inferior_ptid))
3351 context_switch (ecs->ptid);
3352 reinit_frame_cache ();
3355 singlestep_breakpoints_inserted_p = 0;
3356 cancel_single_step_breakpoints ();
3358 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3360 /* Do whatever is necessary to the parent branch of the vfork. */
3361 handle_vfork_child_exec_or_exit (1);
3363 /* This causes the eventpoints and symbol table to be reset.
3364 Must do this now, before trying to determine whether to
3366 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
3368 ecs->event_thread->control.stop_bpstat
3369 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3370 stop_pc, ecs->ptid);
3372 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
3374 /* Note that this may be referenced from inside
3375 bpstat_stop_status above, through inferior_has_execd. */
3376 xfree (ecs->ws.value.execd_pathname);
3377 ecs->ws.value.execd_pathname = NULL;
3379 /* If no catchpoint triggered for this, then keep going. */
3380 if (ecs->random_signal)
3382 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3386 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3387 goto process_event_stop_test;
3389 /* Be careful not to try to gather much state about a thread
3390 that's in a syscall. It's frequently a losing proposition. */
3391 case TARGET_WAITKIND_SYSCALL_ENTRY:
3393 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3394 /* Getting the current syscall number */
3395 if (handle_syscall_event (ecs) != 0)
3397 goto process_event_stop_test;
3399 /* Before examining the threads further, step this thread to
3400 get it entirely out of the syscall. (We get notice of the
3401 event when the thread is just on the verge of exiting a
3402 syscall. Stepping one instruction seems to get it back
3404 case TARGET_WAITKIND_SYSCALL_RETURN:
3406 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3407 if (handle_syscall_event (ecs) != 0)
3409 goto process_event_stop_test;
3411 case TARGET_WAITKIND_STOPPED:
3413 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
3414 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
3417 case TARGET_WAITKIND_NO_HISTORY:
3418 /* Reverse execution: target ran out of history info. */
3419 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3420 print_no_history_reason ();
3421 stop_stepping (ecs);
3425 if (ecs->new_thread_event)
3428 /* Non-stop assumes that the target handles adding new threads
3429 to the thread list. */
3430 internal_error (__FILE__, __LINE__, "\
3431 targets should add new threads to the thread list themselves in non-stop mode.");
3433 /* We may want to consider not doing a resume here in order to
3434 give the user a chance to play with the new thread. It might
3435 be good to make that a user-settable option. */
3437 /* At this point, all threads are stopped (happens automatically
3438 in either the OS or the native code). Therefore we need to
3439 continue all threads in order to make progress. */
3441 if (!ptid_equal (ecs->ptid, inferior_ptid))
3442 context_switch (ecs->ptid);
3443 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
3444 prepare_to_wait (ecs);
3448 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
3450 /* Do we need to clean up the state of a thread that has
3451 completed a displaced single-step? (Doing so usually affects
3452 the PC, so do it here, before we set stop_pc.) */
3453 displaced_step_fixup (ecs->ptid,
3454 ecs->event_thread->suspend.stop_signal);
3456 /* If we either finished a single-step or hit a breakpoint, but
3457 the user wanted this thread to be stopped, pretend we got a
3458 SIG0 (generic unsignaled stop). */
3460 if (ecs->event_thread->stop_requested
3461 && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3462 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3465 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3469 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3470 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3471 struct cleanup *old_chain = save_inferior_ptid ();
3473 inferior_ptid = ecs->ptid;
3475 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
3476 paddress (gdbarch, stop_pc));
3477 if (target_stopped_by_watchpoint ())
3481 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
3483 if (target_stopped_data_address (¤t_target, &addr))
3484 fprintf_unfiltered (gdb_stdlog,
3485 "infrun: stopped data address = %s\n",
3486 paddress (gdbarch, addr));
3488 fprintf_unfiltered (gdb_stdlog,
3489 "infrun: (no data address available)\n");
3492 do_cleanups (old_chain);
3495 if (stepping_past_singlestep_breakpoint)
3497 gdb_assert (singlestep_breakpoints_inserted_p);
3498 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
3499 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
3501 stepping_past_singlestep_breakpoint = 0;
3503 /* We've either finished single-stepping past the single-step
3504 breakpoint, or stopped for some other reason. It would be nice if
3505 we could tell, but we can't reliably. */
3506 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3509 fprintf_unfiltered (gdb_stdlog, "infrun: stepping_past_singlestep_breakpoint\n");
3510 /* Pull the single step breakpoints out of the target. */
3511 remove_single_step_breakpoints ();
3512 singlestep_breakpoints_inserted_p = 0;
3514 ecs->random_signal = 0;
3515 ecs->event_thread->control.trap_expected = 0;
3517 context_switch (saved_singlestep_ptid);
3518 if (deprecated_context_hook)
3519 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3521 resume (1, TARGET_SIGNAL_0);
3522 prepare_to_wait (ecs);
3527 if (!ptid_equal (deferred_step_ptid, null_ptid))
3529 /* In non-stop mode, there's never a deferred_step_ptid set. */
3530 gdb_assert (!non_stop);
3532 /* If we stopped for some other reason than single-stepping, ignore
3533 the fact that we were supposed to switch back. */
3534 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3537 fprintf_unfiltered (gdb_stdlog,
3538 "infrun: handling deferred step\n");
3540 /* Pull the single step breakpoints out of the target. */
3541 if (singlestep_breakpoints_inserted_p)
3543 remove_single_step_breakpoints ();
3544 singlestep_breakpoints_inserted_p = 0;
3547 /* Note: We do not call context_switch at this point, as the
3548 context is already set up for stepping the original thread. */
3549 switch_to_thread (deferred_step_ptid);
3550 deferred_step_ptid = null_ptid;
3551 /* Suppress spurious "Switching to ..." message. */
3552 previous_inferior_ptid = inferior_ptid;
3554 resume (1, TARGET_SIGNAL_0);
3555 prepare_to_wait (ecs);
3559 deferred_step_ptid = null_ptid;
3562 /* See if a thread hit a thread-specific breakpoint that was meant for
3563 another thread. If so, then step that thread past the breakpoint,
3566 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3568 int thread_hop_needed = 0;
3569 struct address_space *aspace =
3570 get_regcache_aspace (get_thread_regcache (ecs->ptid));
3572 /* Check if a regular breakpoint has been hit before checking
3573 for a potential single step breakpoint. Otherwise, GDB will
3574 not see this breakpoint hit when stepping onto breakpoints. */
3575 if (regular_breakpoint_inserted_here_p (aspace, stop_pc))
3577 ecs->random_signal = 0;
3578 if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid))
3579 thread_hop_needed = 1;
3581 else if (singlestep_breakpoints_inserted_p)
3583 /* We have not context switched yet, so this should be true
3584 no matter which thread hit the singlestep breakpoint. */
3585 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
3587 fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
3589 target_pid_to_str (ecs->ptid));
3591 ecs->random_signal = 0;
3592 /* The call to in_thread_list is necessary because PTIDs sometimes
3593 change when we go from single-threaded to multi-threaded. If
3594 the singlestep_ptid is still in the list, assume that it is
3595 really different from ecs->ptid. */
3596 if (!ptid_equal (singlestep_ptid, ecs->ptid)
3597 && in_thread_list (singlestep_ptid))
3599 /* If the PC of the thread we were trying to single-step
3600 has changed, discard this event (which we were going
3601 to ignore anyway), and pretend we saw that thread
3602 trap. This prevents us continuously moving the
3603 single-step breakpoint forward, one instruction at a
3604 time. If the PC has changed, then the thread we were
3605 trying to single-step has trapped or been signalled,
3606 but the event has not been reported to GDB yet.
3608 There might be some cases where this loses signal
3609 information, if a signal has arrived at exactly the
3610 same time that the PC changed, but this is the best
3611 we can do with the information available. Perhaps we
3612 should arrange to report all events for all threads
3613 when they stop, or to re-poll the remote looking for
3614 this particular thread (i.e. temporarily enable
3617 CORE_ADDR new_singlestep_pc
3618 = regcache_read_pc (get_thread_regcache (singlestep_ptid));
3620 if (new_singlestep_pc != singlestep_pc)
3622 enum target_signal stop_signal;
3625 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
3626 " but expected thread advanced also\n");
3628 /* The current context still belongs to
3629 singlestep_ptid. Don't swap here, since that's
3630 the context we want to use. Just fudge our
3631 state and continue. */
3632 stop_signal = ecs->event_thread->suspend.stop_signal;
3633 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3634 ecs->ptid = singlestep_ptid;
3635 ecs->event_thread = find_thread_ptid (ecs->ptid);
3636 ecs->event_thread->suspend.stop_signal = stop_signal;
3637 stop_pc = new_singlestep_pc;
3642 fprintf_unfiltered (gdb_stdlog,
3643 "infrun: unexpected thread\n");
3645 thread_hop_needed = 1;
3646 stepping_past_singlestep_breakpoint = 1;
3647 saved_singlestep_ptid = singlestep_ptid;
3652 if (thread_hop_needed)
3654 struct regcache *thread_regcache;
3655 int remove_status = 0;
3658 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
3660 /* Switch context before touching inferior memory, the
3661 previous thread may have exited. */
3662 if (!ptid_equal (inferior_ptid, ecs->ptid))
3663 context_switch (ecs->ptid);
3665 /* Saw a breakpoint, but it was hit by the wrong thread.
3668 if (singlestep_breakpoints_inserted_p)
3670 /* Pull the single step breakpoints out of the target. */
3671 remove_single_step_breakpoints ();
3672 singlestep_breakpoints_inserted_p = 0;
3675 /* If the arch can displace step, don't remove the
3677 thread_regcache = get_thread_regcache (ecs->ptid);
3678 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
3679 remove_status = remove_breakpoints ();
3681 /* Did we fail to remove breakpoints? If so, try
3682 to set the PC past the bp. (There's at least
3683 one situation in which we can fail to remove
3684 the bp's: On HP-UX's that use ttrace, we can't
3685 change the address space of a vforking child
3686 process until the child exits (well, okay, not
3687 then either :-) or execs. */
3688 if (remove_status != 0)
3689 error (_("Cannot step over breakpoint hit in wrong thread"));
3694 /* Only need to require the next event from this
3695 thread in all-stop mode. */
3696 waiton_ptid = ecs->ptid;
3697 infwait_state = infwait_thread_hop_state;
3700 ecs->event_thread->stepping_over_breakpoint = 1;
3705 else if (singlestep_breakpoints_inserted_p)
3707 sw_single_step_trap_p = 1;
3708 ecs->random_signal = 0;
3712 ecs->random_signal = 1;
3714 /* See if something interesting happened to the non-current thread. If
3715 so, then switch to that thread. */
3716 if (!ptid_equal (ecs->ptid, inferior_ptid))
3719 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
3721 context_switch (ecs->ptid);
3723 if (deprecated_context_hook)
3724 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3727 /* At this point, get hold of the now-current thread's frame. */
3728 frame = get_current_frame ();
3729 gdbarch = get_frame_arch (frame);
3731 if (singlestep_breakpoints_inserted_p)
3733 /* Pull the single step breakpoints out of the target. */
3734 remove_single_step_breakpoints ();
3735 singlestep_breakpoints_inserted_p = 0;
3738 if (stepped_after_stopped_by_watchpoint)
3739 stopped_by_watchpoint = 0;
3741 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
3743 /* If necessary, step over this watchpoint. We'll be back to display
3745 if (stopped_by_watchpoint
3746 && (target_have_steppable_watchpoint
3747 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
3749 /* At this point, we are stopped at an instruction which has
3750 attempted to write to a piece of memory under control of
3751 a watchpoint. The instruction hasn't actually executed
3752 yet. If we were to evaluate the watchpoint expression
3753 now, we would get the old value, and therefore no change
3754 would seem to have occurred.
3756 In order to make watchpoints work `right', we really need
3757 to complete the memory write, and then evaluate the
3758 watchpoint expression. We do this by single-stepping the
3761 It may not be necessary to disable the watchpoint to stop over
3762 it. For example, the PA can (with some kernel cooperation)
3763 single step over a watchpoint without disabling the watchpoint.
3765 It is far more common to need to disable a watchpoint to step
3766 the inferior over it. If we have non-steppable watchpoints,
3767 we must disable the current watchpoint; it's simplest to
3768 disable all watchpoints and breakpoints. */
3771 if (!target_have_steppable_watchpoint)
3772 remove_breakpoints ();
3774 hw_step = maybe_software_singlestep (gdbarch, stop_pc);
3775 target_resume (ecs->ptid, hw_step, TARGET_SIGNAL_0);
3776 waiton_ptid = ecs->ptid;
3777 if (target_have_steppable_watchpoint)
3778 infwait_state = infwait_step_watch_state;
3780 infwait_state = infwait_nonstep_watch_state;
3781 prepare_to_wait (ecs);
3785 ecs->stop_func_start = 0;
3786 ecs->stop_func_end = 0;
3787 ecs->stop_func_name = 0;
3788 /* Don't care about return value; stop_func_start and stop_func_name
3789 will both be 0 if it doesn't work. */
3790 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3791 &ecs->stop_func_start, &ecs->stop_func_end);
3792 ecs->stop_func_start
3793 += gdbarch_deprecated_function_start_offset (gdbarch);
3794 ecs->event_thread->stepping_over_breakpoint = 0;
3795 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
3796 ecs->event_thread->control.stop_step = 0;
3797 stop_print_frame = 1;
3798 ecs->random_signal = 0;
3799 stopped_by_random_signal = 0;
3801 /* Hide inlined functions starting here, unless we just performed stepi or
3802 nexti. After stepi and nexti, always show the innermost frame (not any
3803 inline function call sites). */
3804 if (ecs->event_thread->control.step_range_end != 1)
3805 skip_inline_frames (ecs->ptid);
3807 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3808 && ecs->event_thread->control.trap_expected
3809 && gdbarch_single_step_through_delay_p (gdbarch)
3810 && currently_stepping (ecs->event_thread))
3812 /* We're trying to step off a breakpoint. Turns out that we're
3813 also on an instruction that needs to be stepped multiple
3814 times before it's been fully executing. E.g., architectures
3815 with a delay slot. It needs to be stepped twice, once for
3816 the instruction and once for the delay slot. */
3817 int step_through_delay
3818 = gdbarch_single_step_through_delay (gdbarch, frame);
3820 if (debug_infrun && step_through_delay)
3821 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
3822 if (ecs->event_thread->control.step_range_end == 0
3823 && step_through_delay)
3825 /* The user issued a continue when stopped at a breakpoint.
3826 Set up for another trap and get out of here. */
3827 ecs->event_thread->stepping_over_breakpoint = 1;
3831 else if (step_through_delay)
3833 /* The user issued a step when stopped at a breakpoint.
3834 Maybe we should stop, maybe we should not - the delay
3835 slot *might* correspond to a line of source. In any
3836 case, don't decide that here, just set
3837 ecs->stepping_over_breakpoint, making sure we
3838 single-step again before breakpoints are re-inserted. */
3839 ecs->event_thread->stepping_over_breakpoint = 1;
3843 /* Look at the cause of the stop, and decide what to do.
3844 The alternatives are:
3845 1) stop_stepping and return; to really stop and return to the debugger,
3846 2) keep_going and return to start up again
3847 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
3848 3) set ecs->random_signal to 1, and the decision between 1 and 2
3849 will be made according to the signal handling tables. */
3851 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3852 || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP
3853 || stop_soon == STOP_QUIETLY_REMOTE)
3855 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3859 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
3860 stop_print_frame = 0;
3861 stop_stepping (ecs);
3865 /* This is originated from start_remote(), start_inferior() and
3866 shared libraries hook functions. */
3867 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
3870 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
3871 stop_stepping (ecs);
3875 /* This originates from attach_command(). We need to overwrite
3876 the stop_signal here, because some kernels don't ignore a
3877 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3878 See more comments in inferior.h. On the other hand, if we
3879 get a non-SIGSTOP, report it to the user - assume the backend
3880 will handle the SIGSTOP if it should show up later.
3882 Also consider that the attach is complete when we see a
3883 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3884 target extended-remote report it instead of a SIGSTOP
3885 (e.g. gdbserver). We already rely on SIGTRAP being our
3886 signal, so this is no exception.
3888 Also consider that the attach is complete when we see a
3889 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3890 the target to stop all threads of the inferior, in case the
3891 low level attach operation doesn't stop them implicitly. If
3892 they weren't stopped implicitly, then the stub will report a
3893 TARGET_SIGNAL_0, meaning: stopped for no particular reason
3894 other than GDB's request. */
3895 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
3896 && (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_STOP
3897 || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3898 || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_0))
3900 stop_stepping (ecs);
3901 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3905 /* See if there is a breakpoint at the current PC. */
3906 ecs->event_thread->control.stop_bpstat
3907 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3908 stop_pc, ecs->ptid);
3910 /* Following in case break condition called a
3912 stop_print_frame = 1;
3914 /* This is where we handle "moribund" watchpoints. Unlike
3915 software breakpoints traps, hardware watchpoint traps are
3916 always distinguishable from random traps. If no high-level
3917 watchpoint is associated with the reported stop data address
3918 anymore, then the bpstat does not explain the signal ---
3919 simply make sure to ignore it if `stopped_by_watchpoint' is
3923 && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3924 && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat)
3925 && stopped_by_watchpoint)
3926 fprintf_unfiltered (gdb_stdlog, "\
3927 infrun: no user watchpoint explains watchpoint SIGTRAP, ignoring\n");
3929 /* NOTE: cagney/2003-03-29: These two checks for a random signal
3930 at one stage in the past included checks for an inferior
3931 function call's call dummy's return breakpoint. The original
3932 comment, that went with the test, read:
3934 ``End of a stack dummy. Some systems (e.g. Sony news) give
3935 another signal besides SIGTRAP, so check here as well as
3938 If someone ever tries to get call dummys on a
3939 non-executable stack to work (where the target would stop
3940 with something like a SIGSEGV), then those tests might need
3941 to be re-instated. Given, however, that the tests were only
3942 enabled when momentary breakpoints were not being used, I
3943 suspect that it won't be the case.
3945 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
3946 be necessary for call dummies on a non-executable stack on
3949 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3951 = !(bpstat_explains_signal (ecs->event_thread->control.stop_bpstat)
3952 || stopped_by_watchpoint
3953 || ecs->event_thread->control.trap_expected
3954 || (ecs->event_thread->control.step_range_end
3955 && (ecs->event_thread->control.step_resume_breakpoint
3959 ecs->random_signal = !bpstat_explains_signal
3960 (ecs->event_thread->control.stop_bpstat);
3961 if (!ecs->random_signal)
3962 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3966 /* When we reach this point, we've pretty much decided
3967 that the reason for stopping must've been a random
3968 (unexpected) signal. */
3971 ecs->random_signal = 1;
3973 process_event_stop_test:
3975 /* Re-fetch current thread's frame in case we did a
3976 "goto process_event_stop_test" above. */
3977 frame = get_current_frame ();
3978 gdbarch = get_frame_arch (frame);
3980 /* For the program's own signals, act according to
3981 the signal handling tables. */
3983 if (ecs->random_signal)
3985 /* Signal not for debugging purposes. */
3987 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
3990 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
3991 ecs->event_thread->suspend.stop_signal);
3993 stopped_by_random_signal = 1;
3995 if (signal_print[ecs->event_thread->suspend.stop_signal])
3998 target_terminal_ours_for_output ();
3999 print_signal_received_reason
4000 (ecs->event_thread->suspend.stop_signal);
4002 /* Always stop on signals if we're either just gaining control
4003 of the program, or the user explicitly requested this thread
4004 to remain stopped. */
4005 if (stop_soon != NO_STOP_QUIETLY
4006 || ecs->event_thread->stop_requested
4008 && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
4010 stop_stepping (ecs);
4013 /* If not going to stop, give terminal back
4014 if we took it away. */
4016 target_terminal_inferior ();
4018 /* Clear the signal if it should not be passed. */
4019 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
4020 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
4022 if (ecs->event_thread->prev_pc == stop_pc
4023 && ecs->event_thread->control.trap_expected
4024 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4026 /* We were just starting a new sequence, attempting to
4027 single-step off of a breakpoint and expecting a SIGTRAP.
4028 Instead this signal arrives. This signal will take us out
4029 of the stepping range so GDB needs to remember to, when
4030 the signal handler returns, resume stepping off that
4032 /* To simplify things, "continue" is forced to use the same
4033 code paths as single-step - set a breakpoint at the
4034 signal return address and then, once hit, step off that
4037 fprintf_unfiltered (gdb_stdlog,
4038 "infrun: signal arrived while stepping over "
4041 insert_step_resume_breakpoint_at_frame (frame);
4042 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4047 if (ecs->event_thread->control.step_range_end != 0
4048 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_0
4049 && (ecs->event_thread->control.step_range_start <= stop_pc
4050 && stop_pc < ecs->event_thread->control.step_range_end)
4051 && frame_id_eq (get_stack_frame_id (frame),
4052 ecs->event_thread->control.step_stack_frame_id)
4053 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4055 /* The inferior is about to take a signal that will take it
4056 out of the single step range. Set a breakpoint at the
4057 current PC (which is presumably where the signal handler
4058 will eventually return) and then allow the inferior to
4061 Note that this is only needed for a signal delivered
4062 while in the single-step range. Nested signals aren't a
4063 problem as they eventually all return. */
4065 fprintf_unfiltered (gdb_stdlog,
4066 "infrun: signal may take us out of "
4067 "single-step range\n");
4069 insert_step_resume_breakpoint_at_frame (frame);
4074 /* Note: step_resume_breakpoint may be non-NULL. This occures
4075 when either there's a nested signal, or when there's a
4076 pending signal enabled just as the signal handler returns
4077 (leaving the inferior at the step-resume-breakpoint without
4078 actually executing it). Either way continue until the
4079 breakpoint is really hit. */
4084 /* Handle cases caused by hitting a breakpoint. */
4086 CORE_ADDR jmp_buf_pc;
4087 struct bpstat_what what;
4089 what = bpstat_what (ecs->event_thread->control.stop_bpstat);
4091 if (what.call_dummy)
4093 stop_stack_dummy = what.call_dummy;
4096 /* If we hit an internal event that triggers symbol changes, the
4097 current frame will be invalidated within bpstat_what (e.g., if
4098 we hit an internal solib event). Re-fetch it. */
4099 frame = get_current_frame ();
4100 gdbarch = get_frame_arch (frame);
4102 switch (what.main_action)
4104 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
4105 /* If we hit the breakpoint at longjmp while stepping, we
4106 install a momentary breakpoint at the target of the
4110 fprintf_unfiltered (gdb_stdlog,
4111 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4113 ecs->event_thread->stepping_over_breakpoint = 1;
4115 if (!gdbarch_get_longjmp_target_p (gdbarch)
4116 || !gdbarch_get_longjmp_target (gdbarch, frame, &jmp_buf_pc))
4119 fprintf_unfiltered (gdb_stdlog, "\
4120 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
4125 /* We're going to replace the current step-resume breakpoint
4126 with a longjmp-resume breakpoint. */
4127 delete_step_resume_breakpoint (ecs->event_thread);
4129 /* Insert a breakpoint at resume address. */
4130 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4135 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4137 fprintf_unfiltered (gdb_stdlog,
4138 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4140 gdb_assert (ecs->event_thread->control.step_resume_breakpoint
4142 delete_step_resume_breakpoint (ecs->event_thread);
4144 ecs->event_thread->control.stop_step = 1;
4145 print_end_stepping_range_reason ();
4146 stop_stepping (ecs);
4149 case BPSTAT_WHAT_SINGLE:
4151 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
4152 ecs->event_thread->stepping_over_breakpoint = 1;
4153 /* Still need to check other stuff, at least the case
4154 where we are stepping and step out of the right range. */
4157 case BPSTAT_WHAT_STOP_NOISY:
4159 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4160 stop_print_frame = 1;
4162 /* We are about to nuke the step_resume_breakpointt via the
4163 cleanup chain, so no need to worry about it here. */
4165 stop_stepping (ecs);
4168 case BPSTAT_WHAT_STOP_SILENT:
4170 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4171 stop_print_frame = 0;
4173 /* We are about to nuke the step_resume_breakpoin via the
4174 cleanup chain, so no need to worry about it here. */
4176 stop_stepping (ecs);
4179 case BPSTAT_WHAT_STEP_RESUME:
4181 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4183 delete_step_resume_breakpoint (ecs->event_thread);
4184 if (ecs->event_thread->step_after_step_resume_breakpoint)
4186 /* Back when the step-resume breakpoint was inserted, we
4187 were trying to single-step off a breakpoint. Go back
4189 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4190 ecs->event_thread->stepping_over_breakpoint = 1;
4194 if (stop_pc == ecs->stop_func_start
4195 && execution_direction == EXEC_REVERSE)
4197 /* We are stepping over a function call in reverse, and
4198 just hit the step-resume breakpoint at the start
4199 address of the function. Go back to single-stepping,
4200 which should take us back to the function call. */
4201 ecs->event_thread->stepping_over_breakpoint = 1;
4207 case BPSTAT_WHAT_KEEP_CHECKING:
4212 /* We come here if we hit a breakpoint but should not
4213 stop for it. Possibly we also were stepping
4214 and should stop for that. So fall through and
4215 test for stepping. But, if not stepping,
4218 /* In all-stop mode, if we're currently stepping but have stopped in
4219 some other thread, we need to switch back to the stepped thread. */
4222 struct thread_info *tp;
4224 tp = iterate_over_threads (currently_stepping_or_nexting_callback,
4228 /* However, if the current thread is blocked on some internal
4229 breakpoint, and we simply need to step over that breakpoint
4230 to get it going again, do that first. */
4231 if ((ecs->event_thread->control.trap_expected
4232 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP)
4233 || ecs->event_thread->stepping_over_breakpoint)
4239 /* If the stepping thread exited, then don't try to switch
4240 back and resume it, which could fail in several different
4241 ways depending on the target. Instead, just keep going.
4243 We can find a stepping dead thread in the thread list in
4246 - The target supports thread exit events, and when the
4247 target tries to delete the thread from the thread list,
4248 inferior_ptid pointed at the exiting thread. In such
4249 case, calling delete_thread does not really remove the
4250 thread from the list; instead, the thread is left listed,
4251 with 'exited' state.
4253 - The target's debug interface does not support thread
4254 exit events, and so we have no idea whatsoever if the
4255 previously stepping thread is still alive. For that
4256 reason, we need to synchronously query the target
4258 if (is_exited (tp->ptid)
4259 || !target_thread_alive (tp->ptid))
4262 fprintf_unfiltered (gdb_stdlog, "\
4263 infrun: not switching back to stepped thread, it has vanished\n");
4265 delete_thread (tp->ptid);
4270 /* Otherwise, we no longer expect a trap in the current thread.
4271 Clear the trap_expected flag before switching back -- this is
4272 what keep_going would do as well, if we called it. */
4273 ecs->event_thread->control.trap_expected = 0;
4276 fprintf_unfiltered (gdb_stdlog,
4277 "infrun: switching back to stepped thread\n");
4279 ecs->event_thread = tp;
4280 ecs->ptid = tp->ptid;
4281 context_switch (ecs->ptid);
4287 /* Are we stepping to get the inferior out of the dynamic linker's
4288 hook (and possibly the dld itself) after catching a shlib
4290 if (ecs->event_thread->stepping_through_solib_after_catch)
4292 #if defined(SOLIB_ADD)
4293 /* Have we reached our destination? If not, keep going. */
4294 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
4297 fprintf_unfiltered (gdb_stdlog, "infrun: stepping in dynamic linker\n");
4298 ecs->event_thread->stepping_over_breakpoint = 1;
4304 fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n");
4305 /* Else, stop and report the catchpoint(s) whose triggering
4306 caused us to begin stepping. */
4307 ecs->event_thread->stepping_through_solib_after_catch = 0;
4308 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
4309 ecs->event_thread->control.stop_bpstat
4310 = bpstat_copy (ecs->event_thread->stepping_through_solib_catchpoints);
4311 bpstat_clear (&ecs->event_thread->stepping_through_solib_catchpoints);
4312 stop_print_frame = 1;
4313 stop_stepping (ecs);
4317 if (ecs->event_thread->control.step_resume_breakpoint)
4320 fprintf_unfiltered (gdb_stdlog,
4321 "infrun: step-resume breakpoint is inserted\n");
4323 /* Having a step-resume breakpoint overrides anything
4324 else having to do with stepping commands until
4325 that breakpoint is reached. */
4330 if (ecs->event_thread->control.step_range_end == 0)
4333 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
4334 /* Likewise if we aren't even stepping. */
4339 /* Re-fetch current thread's frame in case the code above caused
4340 the frame cache to be re-initialized, making our FRAME variable
4341 a dangling pointer. */
4342 frame = get_current_frame ();
4343 gdbarch = get_frame_arch (frame);
4345 /* If stepping through a line, keep going if still within it.
4347 Note that step_range_end is the address of the first instruction
4348 beyond the step range, and NOT the address of the last instruction
4351 Note also that during reverse execution, we may be stepping
4352 through a function epilogue and therefore must detect when
4353 the current-frame changes in the middle of a line. */
4355 if (stop_pc >= ecs->event_thread->control.step_range_start
4356 && stop_pc < ecs->event_thread->control.step_range_end
4357 && (execution_direction != EXEC_REVERSE
4358 || frame_id_eq (get_frame_id (frame),
4359 ecs->event_thread->control.step_frame_id)))
4363 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
4364 paddress (gdbarch, ecs->event_thread->control.step_range_start),
4365 paddress (gdbarch, ecs->event_thread->control.step_range_end));
4367 /* When stepping backward, stop at beginning of line range
4368 (unless it's the function entry point, in which case
4369 keep going back to the call point). */
4370 if (stop_pc == ecs->event_thread->control.step_range_start
4371 && stop_pc != ecs->stop_func_start
4372 && execution_direction == EXEC_REVERSE)
4374 ecs->event_thread->control.stop_step = 1;
4375 print_end_stepping_range_reason ();
4376 stop_stepping (ecs);
4384 /* We stepped out of the stepping range. */
4386 /* If we are stepping at the source level and entered the runtime
4387 loader dynamic symbol resolution code...
4389 EXEC_FORWARD: we keep on single stepping until we exit the run
4390 time loader code and reach the callee's address.
4392 EXEC_REVERSE: we've already executed the callee (backward), and
4393 the runtime loader code is handled just like any other
4394 undebuggable function call. Now we need only keep stepping
4395 backward through the trampoline code, and that's handled further
4396 down, so there is nothing for us to do here. */
4398 if (execution_direction != EXEC_REVERSE
4399 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4400 && in_solib_dynsym_resolve_code (stop_pc))
4402 CORE_ADDR pc_after_resolver =
4403 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
4406 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into dynsym resolve code\n");
4408 if (pc_after_resolver)
4410 /* Set up a step-resume breakpoint at the address
4411 indicated by SKIP_SOLIB_RESOLVER. */
4412 struct symtab_and_line sr_sal;
4415 sr_sal.pc = pc_after_resolver;
4416 sr_sal.pspace = get_frame_program_space (frame);
4418 insert_step_resume_breakpoint_at_sal (gdbarch,
4419 sr_sal, null_frame_id);
4426 if (ecs->event_thread->control.step_range_end != 1
4427 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4428 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4429 && get_frame_type (frame) == SIGTRAMP_FRAME)
4432 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into signal trampoline\n");
4433 /* The inferior, while doing a "step" or "next", has ended up in
4434 a signal trampoline (either by a signal being delivered or by
4435 the signal handler returning). Just single-step until the
4436 inferior leaves the trampoline (either by calling the handler
4442 /* Check for subroutine calls. The check for the current frame
4443 equalling the step ID is not necessary - the check of the
4444 previous frame's ID is sufficient - but it is a common case and
4445 cheaper than checking the previous frame's ID.
4447 NOTE: frame_id_eq will never report two invalid frame IDs as
4448 being equal, so to get into this block, both the current and
4449 previous frame must have valid frame IDs. */
4450 /* The outer_frame_id check is a heuristic to detect stepping
4451 through startup code. If we step over an instruction which
4452 sets the stack pointer from an invalid value to a valid value,
4453 we may detect that as a subroutine call from the mythical
4454 "outermost" function. This could be fixed by marking
4455 outermost frames as !stack_p,code_p,special_p. Then the
4456 initial outermost frame, before sp was valid, would
4457 have code_addr == &_start. See the comment in frame_id_eq
4459 if (!frame_id_eq (get_stack_frame_id (frame),
4460 ecs->event_thread->control.step_stack_frame_id)
4461 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4462 ecs->event_thread->control.step_stack_frame_id)
4463 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
4465 || step_start_function != find_pc_function (stop_pc))))
4467 CORE_ADDR real_stop_pc;
4470 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
4472 if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
4473 || ((ecs->event_thread->control.step_range_end == 1)
4474 && in_prologue (gdbarch, ecs->event_thread->prev_pc,
4475 ecs->stop_func_start)))
4477 /* I presume that step_over_calls is only 0 when we're
4478 supposed to be stepping at the assembly language level
4479 ("stepi"). Just stop. */
4480 /* Also, maybe we just did a "nexti" inside a prolog, so we
4481 thought it was a subroutine call but it was not. Stop as
4483 /* And this works the same backward as frontward. MVS */
4484 ecs->event_thread->control.stop_step = 1;
4485 print_end_stepping_range_reason ();
4486 stop_stepping (ecs);
4490 /* Reverse stepping through solib trampolines. */
4492 if (execution_direction == EXEC_REVERSE
4493 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
4494 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4495 || (ecs->stop_func_start == 0
4496 && in_solib_dynsym_resolve_code (stop_pc))))
4498 /* Any solib trampoline code can be handled in reverse
4499 by simply continuing to single-step. We have already
4500 executed the solib function (backwards), and a few
4501 steps will take us back through the trampoline to the
4507 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4509 /* We're doing a "next".
4511 Normal (forward) execution: set a breakpoint at the
4512 callee's return address (the address at which the caller
4515 Reverse (backward) execution. set the step-resume
4516 breakpoint at the start of the function that we just
4517 stepped into (backwards), and continue to there. When we
4518 get there, we'll need to single-step back to the caller. */
4520 if (execution_direction == EXEC_REVERSE)
4522 struct symtab_and_line sr_sal;
4524 /* Normal function call return (static or dynamic). */
4526 sr_sal.pc = ecs->stop_func_start;
4527 sr_sal.pspace = get_frame_program_space (frame);
4528 insert_step_resume_breakpoint_at_sal (gdbarch,
4529 sr_sal, null_frame_id);
4532 insert_step_resume_breakpoint_at_caller (frame);
4538 /* If we are in a function call trampoline (a stub between the
4539 calling routine and the real function), locate the real
4540 function. That's what tells us (a) whether we want to step
4541 into it at all, and (b) what prologue we want to run to the
4542 end of, if we do step into it. */
4543 real_stop_pc = skip_language_trampoline (frame, stop_pc);
4544 if (real_stop_pc == 0)
4545 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4546 if (real_stop_pc != 0)
4547 ecs->stop_func_start = real_stop_pc;
4549 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
4551 struct symtab_and_line sr_sal;
4554 sr_sal.pc = ecs->stop_func_start;
4555 sr_sal.pspace = get_frame_program_space (frame);
4557 insert_step_resume_breakpoint_at_sal (gdbarch,
4558 sr_sal, null_frame_id);
4563 /* If we have line number information for the function we are
4564 thinking of stepping into, step into it.
4566 If there are several symtabs at that PC (e.g. with include
4567 files), just want to know whether *any* of them have line
4568 numbers. find_pc_line handles this. */
4570 struct symtab_and_line tmp_sal;
4572 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
4573 tmp_sal.pspace = get_frame_program_space (frame);
4574 if (tmp_sal.line != 0)
4576 if (execution_direction == EXEC_REVERSE)
4577 handle_step_into_function_backward (gdbarch, ecs);
4579 handle_step_into_function (gdbarch, ecs);
4584 /* If we have no line number and the step-stop-if-no-debug is
4585 set, we stop the step so that the user has a chance to switch
4586 in assembly mode. */
4587 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4588 && step_stop_if_no_debug)
4590 ecs->event_thread->control.stop_step = 1;
4591 print_end_stepping_range_reason ();
4592 stop_stepping (ecs);
4596 if (execution_direction == EXEC_REVERSE)
4598 /* Set a breakpoint at callee's start address.
4599 From there we can step once and be back in the caller. */
4600 struct symtab_and_line sr_sal;
4603 sr_sal.pc = ecs->stop_func_start;
4604 sr_sal.pspace = get_frame_program_space (frame);
4605 insert_step_resume_breakpoint_at_sal (gdbarch,
4606 sr_sal, null_frame_id);
4609 /* Set a breakpoint at callee's return address (the address
4610 at which the caller will resume). */
4611 insert_step_resume_breakpoint_at_caller (frame);
4617 /* Reverse stepping through solib trampolines. */
4619 if (execution_direction == EXEC_REVERSE
4620 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
4622 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4623 || (ecs->stop_func_start == 0
4624 && in_solib_dynsym_resolve_code (stop_pc)))
4626 /* Any solib trampoline code can be handled in reverse
4627 by simply continuing to single-step. We have already
4628 executed the solib function (backwards), and a few
4629 steps will take us back through the trampoline to the
4634 else if (in_solib_dynsym_resolve_code (stop_pc))
4636 /* Stepped backward into the solib dynsym resolver.
4637 Set a breakpoint at its start and continue, then
4638 one more step will take us out. */
4639 struct symtab_and_line sr_sal;
4642 sr_sal.pc = ecs->stop_func_start;
4643 sr_sal.pspace = get_frame_program_space (frame);
4644 insert_step_resume_breakpoint_at_sal (gdbarch,
4645 sr_sal, null_frame_id);
4651 /* If we're in the return path from a shared library trampoline,
4652 we want to proceed through the trampoline when stepping. */
4653 if (gdbarch_in_solib_return_trampoline (gdbarch,
4654 stop_pc, ecs->stop_func_name))
4656 /* Determine where this trampoline returns. */
4657 CORE_ADDR real_stop_pc;
4659 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4662 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into solib return tramp\n");
4664 /* Only proceed through if we know where it's going. */
4667 /* And put the step-breakpoint there and go until there. */
4668 struct symtab_and_line sr_sal;
4670 init_sal (&sr_sal); /* initialize to zeroes */
4671 sr_sal.pc = real_stop_pc;
4672 sr_sal.section = find_pc_overlay (sr_sal.pc);
4673 sr_sal.pspace = get_frame_program_space (frame);
4675 /* Do not specify what the fp should be when we stop since
4676 on some machines the prologue is where the new fp value
4678 insert_step_resume_breakpoint_at_sal (gdbarch,
4679 sr_sal, null_frame_id);
4681 /* Restart without fiddling with the step ranges or
4688 stop_pc_sal = find_pc_line (stop_pc, 0);
4690 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4691 the trampoline processing logic, however, there are some trampolines
4692 that have no names, so we should do trampoline handling first. */
4693 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4694 && ecs->stop_func_name == NULL
4695 && stop_pc_sal.line == 0)
4698 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into undebuggable function\n");
4700 /* The inferior just stepped into, or returned to, an
4701 undebuggable function (where there is no debugging information
4702 and no line number corresponding to the address where the
4703 inferior stopped). Since we want to skip this kind of code,
4704 we keep going until the inferior returns from this
4705 function - unless the user has asked us not to (via
4706 set step-mode) or we no longer know how to get back
4707 to the call site. */
4708 if (step_stop_if_no_debug
4709 || !frame_id_p (frame_unwind_caller_id (frame)))
4711 /* If we have no line number and the step-stop-if-no-debug
4712 is set, we stop the step so that the user has a chance to
4713 switch in assembly mode. */
4714 ecs->event_thread->control.stop_step = 1;
4715 print_end_stepping_range_reason ();
4716 stop_stepping (ecs);
4721 /* Set a breakpoint at callee's return address (the address
4722 at which the caller will resume). */
4723 insert_step_resume_breakpoint_at_caller (frame);
4729 if (ecs->event_thread->control.step_range_end == 1)
4731 /* It is stepi or nexti. We always want to stop stepping after
4734 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
4735 ecs->event_thread->control.stop_step = 1;
4736 print_end_stepping_range_reason ();
4737 stop_stepping (ecs);
4741 if (stop_pc_sal.line == 0)
4743 /* We have no line number information. That means to stop
4744 stepping (does this always happen right after one instruction,
4745 when we do "s" in a function with no line numbers,
4746 or can this happen as a result of a return or longjmp?). */
4748 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
4749 ecs->event_thread->control.stop_step = 1;
4750 print_end_stepping_range_reason ();
4751 stop_stepping (ecs);
4755 /* Look for "calls" to inlined functions, part one. If the inline
4756 frame machinery detected some skipped call sites, we have entered
4757 a new inline function. */
4759 if (frame_id_eq (get_frame_id (get_current_frame ()),
4760 ecs->event_thread->control.step_frame_id)
4761 && inline_skipped_frames (ecs->ptid))
4763 struct symtab_and_line call_sal;
4766 fprintf_unfiltered (gdb_stdlog,
4767 "infrun: stepped into inlined function\n");
4769 find_frame_sal (get_current_frame (), &call_sal);
4771 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
4773 /* For "step", we're going to stop. But if the call site
4774 for this inlined function is on the same source line as
4775 we were previously stepping, go down into the function
4776 first. Otherwise stop at the call site. */
4778 if (call_sal.line == ecs->event_thread->current_line
4779 && call_sal.symtab == ecs->event_thread->current_symtab)
4780 step_into_inline_frame (ecs->ptid);
4782 ecs->event_thread->control.stop_step = 1;
4783 print_end_stepping_range_reason ();
4784 stop_stepping (ecs);
4789 /* For "next", we should stop at the call site if it is on a
4790 different source line. Otherwise continue through the
4791 inlined function. */
4792 if (call_sal.line == ecs->event_thread->current_line
4793 && call_sal.symtab == ecs->event_thread->current_symtab)
4797 ecs->event_thread->control.stop_step = 1;
4798 print_end_stepping_range_reason ();
4799 stop_stepping (ecs);
4805 /* Look for "calls" to inlined functions, part two. If we are still
4806 in the same real function we were stepping through, but we have
4807 to go further up to find the exact frame ID, we are stepping
4808 through a more inlined call beyond its call site. */
4810 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
4811 && !frame_id_eq (get_frame_id (get_current_frame ()),
4812 ecs->event_thread->control.step_frame_id)
4813 && stepped_in_from (get_current_frame (),
4814 ecs->event_thread->control.step_frame_id))
4817 fprintf_unfiltered (gdb_stdlog,
4818 "infrun: stepping through inlined function\n");
4820 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4824 ecs->event_thread->control.stop_step = 1;
4825 print_end_stepping_range_reason ();
4826 stop_stepping (ecs);
4831 if ((stop_pc == stop_pc_sal.pc)
4832 && (ecs->event_thread->current_line != stop_pc_sal.line
4833 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
4835 /* We are at the start of a different line. So stop. Note that
4836 we don't stop if we step into the middle of a different line.
4837 That is said to make things like for (;;) statements work
4840 fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different line\n");
4841 ecs->event_thread->control.stop_step = 1;
4842 print_end_stepping_range_reason ();
4843 stop_stepping (ecs);
4847 /* We aren't done stepping.
4849 Optimize by setting the stepping range to the line.
4850 (We might not be in the original line, but if we entered a
4851 new line in mid-statement, we continue stepping. This makes
4852 things like for(;;) statements work better.) */
4854 ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
4855 ecs->event_thread->control.step_range_end = stop_pc_sal.end;
4856 set_step_info (frame, stop_pc_sal);
4859 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
4863 /* Is thread TP in the middle of single-stepping? */
4866 currently_stepping (struct thread_info *tp)
4868 return ((tp->control.step_range_end
4869 && tp->control.step_resume_breakpoint == NULL)
4870 || tp->control.trap_expected
4871 || tp->stepping_through_solib_after_catch
4872 || bpstat_should_step ());
4875 /* Returns true if any thread *but* the one passed in "data" is in the
4876 middle of stepping or of handling a "next". */
4879 currently_stepping_or_nexting_callback (struct thread_info *tp, void *data)
4884 return (tp->control.step_range_end
4885 || tp->control.trap_expected
4886 || tp->stepping_through_solib_after_catch);
4889 /* Inferior has stepped into a subroutine call with source code that
4890 we should not step over. Do step to the first line of code in
4894 handle_step_into_function (struct gdbarch *gdbarch,
4895 struct execution_control_state *ecs)
4898 struct symtab_and_line stop_func_sal, sr_sal;
4900 s = find_pc_symtab (stop_pc);
4901 if (s && s->language != language_asm)
4902 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
4903 ecs->stop_func_start);
4905 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
4906 /* Use the step_resume_break to step until the end of the prologue,
4907 even if that involves jumps (as it seems to on the vax under
4909 /* If the prologue ends in the middle of a source line, continue to
4910 the end of that source line (if it is still within the function).
4911 Otherwise, just go to end of prologue. */
4912 if (stop_func_sal.end
4913 && stop_func_sal.pc != ecs->stop_func_start
4914 && stop_func_sal.end < ecs->stop_func_end)
4915 ecs->stop_func_start = stop_func_sal.end;
4917 /* Architectures which require breakpoint adjustment might not be able
4918 to place a breakpoint at the computed address. If so, the test
4919 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
4920 ecs->stop_func_start to an address at which a breakpoint may be
4921 legitimately placed.
4923 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
4924 made, GDB will enter an infinite loop when stepping through
4925 optimized code consisting of VLIW instructions which contain
4926 subinstructions corresponding to different source lines. On
4927 FR-V, it's not permitted to place a breakpoint on any but the
4928 first subinstruction of a VLIW instruction. When a breakpoint is
4929 set, GDB will adjust the breakpoint address to the beginning of
4930 the VLIW instruction. Thus, we need to make the corresponding
4931 adjustment here when computing the stop address. */
4933 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
4935 ecs->stop_func_start
4936 = gdbarch_adjust_breakpoint_address (gdbarch,
4937 ecs->stop_func_start);
4940 if (ecs->stop_func_start == stop_pc)
4942 /* We are already there: stop now. */
4943 ecs->event_thread->control.stop_step = 1;
4944 print_end_stepping_range_reason ();
4945 stop_stepping (ecs);
4950 /* Put the step-breakpoint there and go until there. */
4951 init_sal (&sr_sal); /* initialize to zeroes */
4952 sr_sal.pc = ecs->stop_func_start;
4953 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
4954 sr_sal.pspace = get_frame_program_space (get_current_frame ());
4956 /* Do not specify what the fp should be when we stop since on
4957 some machines the prologue is where the new fp value is
4959 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
4961 /* And make sure stepping stops right away then. */
4962 ecs->event_thread->control.step_range_end
4963 = ecs->event_thread->control.step_range_start;
4968 /* Inferior has stepped backward into a subroutine call with source
4969 code that we should not step over. Do step to the beginning of the
4970 last line of code in it. */
4973 handle_step_into_function_backward (struct gdbarch *gdbarch,
4974 struct execution_control_state *ecs)
4977 struct symtab_and_line stop_func_sal;
4979 s = find_pc_symtab (stop_pc);
4980 if (s && s->language != language_asm)
4981 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
4982 ecs->stop_func_start);
4984 stop_func_sal = find_pc_line (stop_pc, 0);
4986 /* OK, we're just going to keep stepping here. */
4987 if (stop_func_sal.pc == stop_pc)
4989 /* We're there already. Just stop stepping now. */
4990 ecs->event_thread->control.stop_step = 1;
4991 print_end_stepping_range_reason ();
4992 stop_stepping (ecs);
4996 /* Else just reset the step range and keep going.
4997 No step-resume breakpoint, they don't work for
4998 epilogues, which can have multiple entry paths. */
4999 ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5000 ecs->event_thread->control.step_range_end = stop_func_sal.end;
5006 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5007 This is used to both functions and to skip over code. */
5010 insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5011 struct symtab_and_line sr_sal,
5012 struct frame_id sr_id)
5014 /* There should never be more than one step-resume or longjmp-resume
5015 breakpoint per thread, so we should never be setting a new
5016 step_resume_breakpoint when one is already active. */
5017 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5020 fprintf_unfiltered (gdb_stdlog,
5021 "infrun: inserting step-resume breakpoint at %s\n",
5022 paddress (gdbarch, sr_sal.pc));
5024 inferior_thread ()->control.step_resume_breakpoint
5025 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, bp_step_resume);
5028 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
5029 to skip a potential signal handler.
5031 This is called with the interrupted function's frame. The signal
5032 handler, when it returns, will resume the interrupted function at
5036 insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
5038 struct symtab_and_line sr_sal;
5039 struct gdbarch *gdbarch;
5041 gdb_assert (return_frame != NULL);
5042 init_sal (&sr_sal); /* initialize to zeros */
5044 gdbarch = get_frame_arch (return_frame);
5045 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
5046 sr_sal.section = find_pc_overlay (sr_sal.pc);
5047 sr_sal.pspace = get_frame_program_space (return_frame);
5049 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5050 get_stack_frame_id (return_frame));
5053 /* Similar to insert_step_resume_breakpoint_at_frame, except
5054 but a breakpoint at the previous frame's PC. This is used to
5055 skip a function after stepping into it (for "next" or if the called
5056 function has no debugging information).
5058 The current function has almost always been reached by single
5059 stepping a call or return instruction. NEXT_FRAME belongs to the
5060 current function, and the breakpoint will be set at the caller's
5063 This is a separate function rather than reusing
5064 insert_step_resume_breakpoint_at_frame in order to avoid
5065 get_prev_frame, which may stop prematurely (see the implementation
5066 of frame_unwind_caller_id for an example). */
5069 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
5071 struct symtab_and_line sr_sal;
5072 struct gdbarch *gdbarch;
5074 /* We shouldn't have gotten here if we don't know where the call site
5076 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
5078 init_sal (&sr_sal); /* initialize to zeros */
5080 gdbarch = frame_unwind_caller_arch (next_frame);
5081 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
5082 frame_unwind_caller_pc (next_frame));
5083 sr_sal.section = find_pc_overlay (sr_sal.pc);
5084 sr_sal.pspace = frame_unwind_program_space (next_frame);
5086 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5087 frame_unwind_caller_id (next_frame));
5090 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5091 new breakpoint at the target of a jmp_buf. The handling of
5092 longjmp-resume uses the same mechanisms used for handling
5093 "step-resume" breakpoints. */
5096 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
5098 /* There should never be more than one step-resume or longjmp-resume
5099 breakpoint per thread, so we should never be setting a new
5100 longjmp_resume_breakpoint when one is already active. */
5101 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5104 fprintf_unfiltered (gdb_stdlog,
5105 "infrun: inserting longjmp-resume breakpoint at %s\n",
5106 paddress (gdbarch, pc));
5108 inferior_thread ()->control.step_resume_breakpoint =
5109 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
5113 stop_stepping (struct execution_control_state *ecs)
5116 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
5118 /* Let callers know we don't want to wait for the inferior anymore. */
5119 ecs->wait_some_more = 0;
5122 /* This function handles various cases where we need to continue
5123 waiting for the inferior. */
5124 /* (Used to be the keep_going: label in the old wait_for_inferior) */
5127 keep_going (struct execution_control_state *ecs)
5129 /* Make sure normal_stop is called if we get a QUIT handled before
5131 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
5133 /* Save the pc before execution, to compare with pc after stop. */
5134 ecs->event_thread->prev_pc
5135 = regcache_read_pc (get_thread_regcache (ecs->ptid));
5137 /* If we did not do break;, it means we should keep running the
5138 inferior and not return to debugger. */
5140 if (ecs->event_thread->control.trap_expected
5141 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP)
5143 /* We took a signal (which we are supposed to pass through to
5144 the inferior, else we'd not get here) and we haven't yet
5145 gotten our trap. Simply continue. */
5147 discard_cleanups (old_cleanups);
5148 resume (currently_stepping (ecs->event_thread),
5149 ecs->event_thread->suspend.stop_signal);
5153 /* Either the trap was not expected, but we are continuing
5154 anyway (the user asked that this signal be passed to the
5157 The signal was SIGTRAP, e.g. it was our signal, but we
5158 decided we should resume from it.
5160 We're going to run this baby now!
5162 Note that insert_breakpoints won't try to re-insert
5163 already inserted breakpoints. Therefore, we don't
5164 care if breakpoints were already inserted, or not. */
5166 if (ecs->event_thread->stepping_over_breakpoint)
5168 struct regcache *thread_regcache = get_thread_regcache (ecs->ptid);
5170 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
5171 /* Since we can't do a displaced step, we have to remove
5172 the breakpoint while we step it. To keep things
5173 simple, we remove them all. */
5174 remove_breakpoints ();
5178 struct gdb_exception e;
5180 /* Stop stepping when inserting breakpoints
5182 TRY_CATCH (e, RETURN_MASK_ERROR)
5184 insert_breakpoints ();
5188 exception_print (gdb_stderr, e);
5189 stop_stepping (ecs);
5194 ecs->event_thread->control.trap_expected
5195 = ecs->event_thread->stepping_over_breakpoint;
5197 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5198 specifies that such a signal should be delivered to the
5201 Typically, this would occure when a user is debugging a
5202 target monitor on a simulator: the target monitor sets a
5203 breakpoint; the simulator encounters this break-point and
5204 halts the simulation handing control to GDB; GDB, noteing
5205 that the break-point isn't valid, returns control back to the
5206 simulator; the simulator then delivers the hardware
5207 equivalent of a SIGNAL_TRAP to the program being debugged. */
5209 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
5210 && !signal_program[ecs->event_thread->suspend.stop_signal])
5211 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
5213 discard_cleanups (old_cleanups);
5214 resume (currently_stepping (ecs->event_thread),
5215 ecs->event_thread->suspend.stop_signal);
5218 prepare_to_wait (ecs);
5221 /* This function normally comes after a resume, before
5222 handle_inferior_event exits. It takes care of any last bits of
5223 housekeeping, and sets the all-important wait_some_more flag. */
5226 prepare_to_wait (struct execution_control_state *ecs)
5229 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
5231 /* This is the old end of the while loop. Let everybody know we
5232 want to wait for the inferior some more and get called again
5234 ecs->wait_some_more = 1;
5237 /* Several print_*_reason functions to print why the inferior has stopped.
5238 We always print something when the inferior exits, or receives a signal.
5239 The rest of the cases are dealt with later on in normal_stop and
5240 print_it_typical. Ideally there should be a call to one of these
5241 print_*_reason functions functions from handle_inferior_event each time
5242 stop_stepping is called. */
5244 /* Print why the inferior has stopped.
5245 We are done with a step/next/si/ni command, print why the inferior has
5246 stopped. For now print nothing. Print a message only if not in the middle
5247 of doing a "step n" operation for n > 1. */
5250 print_end_stepping_range_reason (void)
5252 if ((!inferior_thread ()->step_multi
5253 || !inferior_thread ()->control.stop_step)
5254 && ui_out_is_mi_like_p (uiout))
5255 ui_out_field_string (uiout, "reason",
5256 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
5259 /* The inferior was terminated by a signal, print why it stopped. */
5262 print_signal_exited_reason (enum target_signal siggnal)
5264 annotate_signalled ();
5265 if (ui_out_is_mi_like_p (uiout))
5267 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
5268 ui_out_text (uiout, "\nProgram terminated with signal ");
5269 annotate_signal_name ();
5270 ui_out_field_string (uiout, "signal-name",
5271 target_signal_to_name (siggnal));
5272 annotate_signal_name_end ();
5273 ui_out_text (uiout, ", ");
5274 annotate_signal_string ();
5275 ui_out_field_string (uiout, "signal-meaning",
5276 target_signal_to_string (siggnal));
5277 annotate_signal_string_end ();
5278 ui_out_text (uiout, ".\n");
5279 ui_out_text (uiout, "The program no longer exists.\n");
5282 /* The inferior program is finished, print why it stopped. */
5285 print_exited_reason (int exitstatus)
5287 annotate_exited (exitstatus);
5290 if (ui_out_is_mi_like_p (uiout))
5291 ui_out_field_string (uiout, "reason",
5292 async_reason_lookup (EXEC_ASYNC_EXITED));
5293 ui_out_text (uiout, "\nProgram exited with code ");
5294 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
5295 ui_out_text (uiout, ".\n");
5299 if (ui_out_is_mi_like_p (uiout))
5301 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
5302 ui_out_text (uiout, "\nProgram exited normally.\n");
5304 /* Support the --return-child-result option. */
5305 return_child_result_value = exitstatus;
5308 /* Signal received, print why the inferior has stopped. The signal table
5309 tells us to print about it. */
5312 print_signal_received_reason (enum target_signal siggnal)
5316 if (siggnal == TARGET_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
5318 struct thread_info *t = inferior_thread ();
5320 ui_out_text (uiout, "\n[");
5321 ui_out_field_string (uiout, "thread-name",
5322 target_pid_to_str (t->ptid));
5323 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
5324 ui_out_text (uiout, " stopped");
5328 ui_out_text (uiout, "\nProgram received signal ");
5329 annotate_signal_name ();
5330 if (ui_out_is_mi_like_p (uiout))
5332 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
5333 ui_out_field_string (uiout, "signal-name",
5334 target_signal_to_name (siggnal));
5335 annotate_signal_name_end ();
5336 ui_out_text (uiout, ", ");
5337 annotate_signal_string ();
5338 ui_out_field_string (uiout, "signal-meaning",
5339 target_signal_to_string (siggnal));
5340 annotate_signal_string_end ();
5342 ui_out_text (uiout, ".\n");
5345 /* Reverse execution: target ran out of history info, print why the inferior
5349 print_no_history_reason (void)
5351 ui_out_text (uiout, "\nNo more reverse-execution history.\n");
5354 /* Here to return control to GDB when the inferior stops for real.
5355 Print appropriate messages, remove breakpoints, give terminal our modes.
5357 STOP_PRINT_FRAME nonzero means print the executing frame
5358 (pc, function, args, file, line number and line text).
5359 BREAKPOINTS_FAILED nonzero means stop was due to error
5360 attempting to insert breakpoints. */
5365 struct target_waitstatus last;
5367 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
5369 get_last_target_status (&last_ptid, &last);
5371 /* If an exception is thrown from this point on, make sure to
5372 propagate GDB's knowledge of the executing state to the
5373 frontend/user running state. A QUIT is an easy exception to see
5374 here, so do this before any filtered output. */
5376 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
5377 else if (last.kind != TARGET_WAITKIND_SIGNALLED
5378 && last.kind != TARGET_WAITKIND_EXITED)
5379 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
5381 /* In non-stop mode, we don't want GDB to switch threads behind the
5382 user's back, to avoid races where the user is typing a command to
5383 apply to thread x, but GDB switches to thread y before the user
5384 finishes entering the command. */
5386 /* As with the notification of thread events, we want to delay
5387 notifying the user that we've switched thread context until
5388 the inferior actually stops.
5390 There's no point in saying anything if the inferior has exited.
5391 Note that SIGNALLED here means "exited with a signal", not
5392 "received a signal". */
5394 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
5395 && target_has_execution
5396 && last.kind != TARGET_WAITKIND_SIGNALLED
5397 && last.kind != TARGET_WAITKIND_EXITED)
5399 target_terminal_ours_for_output ();
5400 printf_filtered (_("[Switching to %s]\n"),
5401 target_pid_to_str (inferior_ptid));
5402 annotate_thread_changed ();
5403 previous_inferior_ptid = inferior_ptid;
5406 if (!breakpoints_always_inserted_mode () && target_has_execution)
5408 if (remove_breakpoints ())
5410 target_terminal_ours_for_output ();
5411 printf_filtered (_("\
5412 Cannot remove breakpoints because program is no longer writable.\n\
5413 Further execution is probably impossible.\n"));
5417 /* If an auto-display called a function and that got a signal,
5418 delete that auto-display to avoid an infinite recursion. */
5420 if (stopped_by_random_signal)
5421 disable_current_display ();
5423 /* Don't print a message if in the middle of doing a "step n"
5424 operation for n > 1 */
5425 if (target_has_execution
5426 && last.kind != TARGET_WAITKIND_SIGNALLED
5427 && last.kind != TARGET_WAITKIND_EXITED
5428 && inferior_thread ()->step_multi
5429 && inferior_thread ()->control.stop_step)
5432 target_terminal_ours ();
5434 /* Set the current source location. This will also happen if we
5435 display the frame below, but the current SAL will be incorrect
5436 during a user hook-stop function. */
5437 if (has_stack_frames () && !stop_stack_dummy)
5438 set_current_sal_from_frame (get_current_frame (), 1);
5440 /* Let the user/frontend see the threads as stopped. */
5441 do_cleanups (old_chain);
5443 /* Look up the hook_stop and run it (CLI internally handles problem
5444 of stop_command's pre-hook not existing). */
5446 catch_errors (hook_stop_stub, stop_command,
5447 "Error while running hook_stop:\n", RETURN_MASK_ALL);
5449 if (!has_stack_frames ())
5452 if (last.kind == TARGET_WAITKIND_SIGNALLED
5453 || last.kind == TARGET_WAITKIND_EXITED)
5456 /* Select innermost stack frame - i.e., current frame is frame 0,
5457 and current location is based on that.
5458 Don't do this on return from a stack dummy routine,
5459 or if the program has exited. */
5461 if (!stop_stack_dummy)
5463 select_frame (get_current_frame ());
5465 /* Print current location without a level number, if
5466 we have changed functions or hit a breakpoint.
5467 Print source line if we have one.
5468 bpstat_print() contains the logic deciding in detail
5469 what to print, based on the event(s) that just occurred. */
5471 /* If --batch-silent is enabled then there's no need to print the current
5472 source location, and to try risks causing an error message about
5473 missing source files. */
5474 if (stop_print_frame && !batch_silent)
5478 int do_frame_printing = 1;
5479 struct thread_info *tp = inferior_thread ();
5481 bpstat_ret = bpstat_print (tp->control.stop_bpstat);
5485 /* If we had hit a shared library event breakpoint,
5486 bpstat_print would print out this message. If we hit
5487 an OS-level shared library event, do the same
5489 if (last.kind == TARGET_WAITKIND_LOADED)
5491 printf_filtered (_("Stopped due to shared library event\n"));
5492 source_flag = SRC_LINE; /* something bogus */
5493 do_frame_printing = 0;
5497 /* FIXME: cagney/2002-12-01: Given that a frame ID does
5498 (or should) carry around the function and does (or
5499 should) use that when doing a frame comparison. */
5500 if (tp->control.stop_step
5501 && frame_id_eq (tp->control.step_frame_id,
5502 get_frame_id (get_current_frame ()))
5503 && step_start_function == find_pc_function (stop_pc))
5504 source_flag = SRC_LINE; /* finished step, just print source line */
5506 source_flag = SRC_AND_LOC; /* print location and source line */
5508 case PRINT_SRC_AND_LOC:
5509 source_flag = SRC_AND_LOC; /* print location and source line */
5511 case PRINT_SRC_ONLY:
5512 source_flag = SRC_LINE;
5515 source_flag = SRC_LINE; /* something bogus */
5516 do_frame_printing = 0;
5519 internal_error (__FILE__, __LINE__, _("Unknown value."));
5522 /* The behavior of this routine with respect to the source
5524 SRC_LINE: Print only source line
5525 LOCATION: Print only location
5526 SRC_AND_LOC: Print location and source line */
5527 if (do_frame_printing)
5528 print_stack_frame (get_selected_frame (NULL), 0, source_flag);
5530 /* Display the auto-display expressions. */
5535 /* Save the function value return registers, if we care.
5536 We might be about to restore their previous contents. */
5537 if (inferior_thread ()->control.proceed_to_finish)
5539 /* This should not be necessary. */
5541 regcache_xfree (stop_registers);
5543 /* NB: The copy goes through to the target picking up the value of
5544 all the registers. */
5545 stop_registers = regcache_dup (get_current_regcache ());
5548 if (stop_stack_dummy == STOP_STACK_DUMMY)
5550 /* Pop the empty frame that contains the stack dummy.
5551 This also restores inferior state prior to the call
5552 (struct infcall_suspend_state). */
5553 struct frame_info *frame = get_current_frame ();
5555 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
5557 /* frame_pop() calls reinit_frame_cache as the last thing it does
5558 which means there's currently no selected frame. We don't need
5559 to re-establish a selected frame if the dummy call returns normally,
5560 that will be done by restore_infcall_control_state. However, we do have
5561 to handle the case where the dummy call is returning after being
5562 stopped (e.g. the dummy call previously hit a breakpoint). We
5563 can't know which case we have so just always re-establish a
5564 selected frame here. */
5565 select_frame (get_current_frame ());
5569 annotate_stopped ();
5571 /* Suppress the stop observer if we're in the middle of:
5573 - a step n (n > 1), as there still more steps to be done.
5575 - a "finish" command, as the observer will be called in
5576 finish_command_continuation, so it can include the inferior
5577 function's return value.
5579 - calling an inferior function, as we pretend we inferior didn't
5580 run at all. The return value of the call is handled by the
5581 expression evaluator, through call_function_by_hand. */
5583 if (!target_has_execution
5584 || last.kind == TARGET_WAITKIND_SIGNALLED
5585 || last.kind == TARGET_WAITKIND_EXITED
5586 || (!inferior_thread ()->step_multi
5587 && !(inferior_thread ()->control.stop_bpstat
5588 && inferior_thread ()->control.proceed_to_finish)
5589 && !inferior_thread ()->control.in_infcall))
5591 if (!ptid_equal (inferior_ptid, null_ptid))
5592 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
5595 observer_notify_normal_stop (NULL, stop_print_frame);
5598 if (target_has_execution)
5600 if (last.kind != TARGET_WAITKIND_SIGNALLED
5601 && last.kind != TARGET_WAITKIND_EXITED)
5602 /* Delete the breakpoint we stopped at, if it wants to be deleted.
5603 Delete any breakpoint that is to be deleted at the next stop. */
5604 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
5607 /* Try to get rid of automatically added inferiors that are no
5608 longer needed. Keeping those around slows down things linearly.
5609 Note that this never removes the current inferior. */
5614 hook_stop_stub (void *cmd)
5616 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
5621 signal_stop_state (int signo)
5623 return signal_stop[signo];
5627 signal_print_state (int signo)
5629 return signal_print[signo];
5633 signal_pass_state (int signo)
5635 return signal_program[signo];
5639 signal_stop_update (int signo, int state)
5641 int ret = signal_stop[signo];
5643 signal_stop[signo] = state;
5648 signal_print_update (int signo, int state)
5650 int ret = signal_print[signo];
5652 signal_print[signo] = state;
5657 signal_pass_update (int signo, int state)
5659 int ret = signal_program[signo];
5661 signal_program[signo] = state;
5666 sig_print_header (void)
5668 printf_filtered (_("\
5669 Signal Stop\tPrint\tPass to program\tDescription\n"));
5673 sig_print_info (enum target_signal oursig)
5675 const char *name = target_signal_to_name (oursig);
5676 int name_padding = 13 - strlen (name);
5678 if (name_padding <= 0)
5681 printf_filtered ("%s", name);
5682 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
5683 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
5684 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
5685 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
5686 printf_filtered ("%s\n", target_signal_to_string (oursig));
5689 /* Specify how various signals in the inferior should be handled. */
5692 handle_command (char *args, int from_tty)
5695 int digits, wordlen;
5696 int sigfirst, signum, siglast;
5697 enum target_signal oursig;
5700 unsigned char *sigs;
5701 struct cleanup *old_chain;
5705 error_no_arg (_("signal to handle"));
5708 /* Allocate and zero an array of flags for which signals to handle. */
5710 nsigs = (int) TARGET_SIGNAL_LAST;
5711 sigs = (unsigned char *) alloca (nsigs);
5712 memset (sigs, 0, nsigs);
5714 /* Break the command line up into args. */
5716 argv = gdb_buildargv (args);
5717 old_chain = make_cleanup_freeargv (argv);
5719 /* Walk through the args, looking for signal oursigs, signal names, and
5720 actions. Signal numbers and signal names may be interspersed with
5721 actions, with the actions being performed for all signals cumulatively
5722 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
5724 while (*argv != NULL)
5726 wordlen = strlen (*argv);
5727 for (digits = 0; isdigit ((*argv)[digits]); digits++)
5731 sigfirst = siglast = -1;
5733 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
5735 /* Apply action to all signals except those used by the
5736 debugger. Silently skip those. */
5739 siglast = nsigs - 1;
5741 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
5743 SET_SIGS (nsigs, sigs, signal_stop);
5744 SET_SIGS (nsigs, sigs, signal_print);
5746 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
5748 UNSET_SIGS (nsigs, sigs, signal_program);
5750 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
5752 SET_SIGS (nsigs, sigs, signal_print);
5754 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
5756 SET_SIGS (nsigs, sigs, signal_program);
5758 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
5760 UNSET_SIGS (nsigs, sigs, signal_stop);
5762 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
5764 SET_SIGS (nsigs, sigs, signal_program);
5766 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
5768 UNSET_SIGS (nsigs, sigs, signal_print);
5769 UNSET_SIGS (nsigs, sigs, signal_stop);
5771 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
5773 UNSET_SIGS (nsigs, sigs, signal_program);
5775 else if (digits > 0)
5777 /* It is numeric. The numeric signal refers to our own
5778 internal signal numbering from target.h, not to host/target
5779 signal number. This is a feature; users really should be
5780 using symbolic names anyway, and the common ones like
5781 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
5783 sigfirst = siglast = (int)
5784 target_signal_from_command (atoi (*argv));
5785 if ((*argv)[digits] == '-')
5788 target_signal_from_command (atoi ((*argv) + digits + 1));
5790 if (sigfirst > siglast)
5792 /* Bet he didn't figure we'd think of this case... */
5800 oursig = target_signal_from_name (*argv);
5801 if (oursig != TARGET_SIGNAL_UNKNOWN)
5803 sigfirst = siglast = (int) oursig;
5807 /* Not a number and not a recognized flag word => complain. */
5808 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
5812 /* If any signal numbers or symbol names were found, set flags for
5813 which signals to apply actions to. */
5815 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
5817 switch ((enum target_signal) signum)
5819 case TARGET_SIGNAL_TRAP:
5820 case TARGET_SIGNAL_INT:
5821 if (!allsigs && !sigs[signum])
5823 if (query (_("%s is used by the debugger.\n\
5824 Are you sure you want to change it? "), target_signal_to_name ((enum target_signal) signum)))
5830 printf_unfiltered (_("Not confirmed, unchanged.\n"));
5831 gdb_flush (gdb_stdout);
5835 case TARGET_SIGNAL_0:
5836 case TARGET_SIGNAL_DEFAULT:
5837 case TARGET_SIGNAL_UNKNOWN:
5838 /* Make sure that "all" doesn't print these. */
5849 for (signum = 0; signum < nsigs; signum++)
5852 target_notice_signals (inferior_ptid);
5856 /* Show the results. */
5857 sig_print_header ();
5858 for (; signum < nsigs; signum++)
5860 sig_print_info (signum);
5866 do_cleanups (old_chain);
5870 xdb_handle_command (char *args, int from_tty)
5873 struct cleanup *old_chain;
5876 error_no_arg (_("xdb command"));
5878 /* Break the command line up into args. */
5880 argv = gdb_buildargv (args);
5881 old_chain = make_cleanup_freeargv (argv);
5882 if (argv[1] != (char *) NULL)
5887 bufLen = strlen (argv[0]) + 20;
5888 argBuf = (char *) xmalloc (bufLen);
5892 enum target_signal oursig;
5894 oursig = target_signal_from_name (argv[0]);
5895 memset (argBuf, 0, bufLen);
5896 if (strcmp (argv[1], "Q") == 0)
5897 sprintf (argBuf, "%s %s", argv[0], "noprint");
5900 if (strcmp (argv[1], "s") == 0)
5902 if (!signal_stop[oursig])
5903 sprintf (argBuf, "%s %s", argv[0], "stop");
5905 sprintf (argBuf, "%s %s", argv[0], "nostop");
5907 else if (strcmp (argv[1], "i") == 0)
5909 if (!signal_program[oursig])
5910 sprintf (argBuf, "%s %s", argv[0], "pass");
5912 sprintf (argBuf, "%s %s", argv[0], "nopass");
5914 else if (strcmp (argv[1], "r") == 0)
5916 if (!signal_print[oursig])
5917 sprintf (argBuf, "%s %s", argv[0], "print");
5919 sprintf (argBuf, "%s %s", argv[0], "noprint");
5925 handle_command (argBuf, from_tty);
5927 printf_filtered (_("Invalid signal handling flag.\n"));
5932 do_cleanups (old_chain);
5935 /* Print current contents of the tables set by the handle command.
5936 It is possible we should just be printing signals actually used
5937 by the current target (but for things to work right when switching
5938 targets, all signals should be in the signal tables). */
5941 signals_info (char *signum_exp, int from_tty)
5943 enum target_signal oursig;
5945 sig_print_header ();
5949 /* First see if this is a symbol name. */
5950 oursig = target_signal_from_name (signum_exp);
5951 if (oursig == TARGET_SIGNAL_UNKNOWN)
5953 /* No, try numeric. */
5955 target_signal_from_command (parse_and_eval_long (signum_exp));
5957 sig_print_info (oursig);
5961 printf_filtered ("\n");
5962 /* These ugly casts brought to you by the native VAX compiler. */
5963 for (oursig = TARGET_SIGNAL_FIRST;
5964 (int) oursig < (int) TARGET_SIGNAL_LAST;
5965 oursig = (enum target_signal) ((int) oursig + 1))
5969 if (oursig != TARGET_SIGNAL_UNKNOWN
5970 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
5971 sig_print_info (oursig);
5974 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
5977 /* The $_siginfo convenience variable is a bit special. We don't know
5978 for sure the type of the value until we actually have a chance to
5979 fetch the data. The type can change depending on gdbarch, so it it
5980 also dependent on which thread you have selected.
5982 1. making $_siginfo be an internalvar that creates a new value on
5985 2. making the value of $_siginfo be an lval_computed value. */
5987 /* This function implements the lval_computed support for reading a
5991 siginfo_value_read (struct value *v)
5993 LONGEST transferred;
5996 target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO,
5998 value_contents_all_raw (v),
6000 TYPE_LENGTH (value_type (v)));
6002 if (transferred != TYPE_LENGTH (value_type (v)))
6003 error (_("Unable to read siginfo"));
6006 /* This function implements the lval_computed support for writing a
6010 siginfo_value_write (struct value *v, struct value *fromval)
6012 LONGEST transferred;
6014 transferred = target_write (¤t_target,
6015 TARGET_OBJECT_SIGNAL_INFO,
6017 value_contents_all_raw (fromval),
6019 TYPE_LENGTH (value_type (fromval)));
6021 if (transferred != TYPE_LENGTH (value_type (fromval)))
6022 error (_("Unable to write siginfo"));
6025 static struct lval_funcs siginfo_value_funcs =
6031 /* Return a new value with the correct type for the siginfo object of
6032 the current thread using architecture GDBARCH. Return a void value
6033 if there's no object available. */
6035 static struct value *
6036 siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var)
6038 if (target_has_stack
6039 && !ptid_equal (inferior_ptid, null_ptid)
6040 && gdbarch_get_siginfo_type_p (gdbarch))
6042 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6044 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
6047 return allocate_value (builtin_type (gdbarch)->builtin_void);
6051 /* infcall_suspend_state contains state about the program itself like its
6052 registers and any signal it received when it last stopped.
6053 This state must be restored regardless of how the inferior function call
6054 ends (either successfully, or after it hits a breakpoint or signal)
6055 if the program is to properly continue where it left off. */
6057 struct infcall_suspend_state
6059 struct thread_suspend_state thread_suspend;
6060 struct inferior_suspend_state inferior_suspend;
6064 struct regcache *registers;
6066 /* Format of SIGINFO_DATA or NULL if it is not present. */
6067 struct gdbarch *siginfo_gdbarch;
6069 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6070 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6071 content would be invalid. */
6072 gdb_byte *siginfo_data;
6075 struct infcall_suspend_state *
6076 save_infcall_suspend_state (void)
6078 struct infcall_suspend_state *inf_state;
6079 struct thread_info *tp = inferior_thread ();
6080 struct inferior *inf = current_inferior ();
6081 struct regcache *regcache = get_current_regcache ();
6082 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6083 gdb_byte *siginfo_data = NULL;
6085 if (gdbarch_get_siginfo_type_p (gdbarch))
6087 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6088 size_t len = TYPE_LENGTH (type);
6089 struct cleanup *back_to;
6091 siginfo_data = xmalloc (len);
6092 back_to = make_cleanup (xfree, siginfo_data);
6094 if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6095 siginfo_data, 0, len) == len)
6096 discard_cleanups (back_to);
6099 /* Errors ignored. */
6100 do_cleanups (back_to);
6101 siginfo_data = NULL;
6105 inf_state = XZALLOC (struct infcall_suspend_state);
6109 inf_state->siginfo_gdbarch = gdbarch;
6110 inf_state->siginfo_data = siginfo_data;
6113 inf_state->thread_suspend = tp->suspend;
6114 inf_state->inferior_suspend = inf->suspend;
6116 /* run_inferior_call will not use the signal due to its `proceed' call with
6117 TARGET_SIGNAL_0 anyway. */
6118 tp->suspend.stop_signal = TARGET_SIGNAL_0;
6120 inf_state->stop_pc = stop_pc;
6122 inf_state->registers = regcache_dup (regcache);
6127 /* Restore inferior session state to INF_STATE. */
6130 restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6132 struct thread_info *tp = inferior_thread ();
6133 struct inferior *inf = current_inferior ();
6134 struct regcache *regcache = get_current_regcache ();
6135 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6137 tp->suspend = inf_state->thread_suspend;
6138 inf->suspend = inf_state->inferior_suspend;
6140 stop_pc = inf_state->stop_pc;
6142 if (inf_state->siginfo_gdbarch == gdbarch)
6144 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6145 size_t len = TYPE_LENGTH (type);
6147 /* Errors ignored. */
6148 target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6149 inf_state->siginfo_data, 0, len);
6152 /* The inferior can be gone if the user types "print exit(0)"
6153 (and perhaps other times). */
6154 if (target_has_execution)
6155 /* NB: The register write goes through to the target. */
6156 regcache_cpy (regcache, inf_state->registers);
6158 discard_infcall_suspend_state (inf_state);
6162 do_restore_infcall_suspend_state_cleanup (void *state)
6164 restore_infcall_suspend_state (state);
6168 make_cleanup_restore_infcall_suspend_state
6169 (struct infcall_suspend_state *inf_state)
6171 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
6175 discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6177 regcache_xfree (inf_state->registers);
6178 xfree (inf_state->siginfo_data);
6183 get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
6185 return inf_state->registers;
6188 /* infcall_control_state contains state regarding gdb's control of the
6189 inferior itself like stepping control. It also contains session state like
6190 the user's currently selected frame. */
6192 struct infcall_control_state
6194 struct thread_control_state thread_control;
6195 struct inferior_control_state inferior_control;
6198 enum stop_stack_kind stop_stack_dummy;
6199 int stopped_by_random_signal;
6200 int stop_after_trap;
6202 /* ID if the selected frame when the inferior function call was made. */
6203 struct frame_id selected_frame_id;
6206 /* Save all of the information associated with the inferior<==>gdb
6209 struct infcall_control_state *
6210 save_infcall_control_state (void)
6212 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
6213 struct thread_info *tp = inferior_thread ();
6214 struct inferior *inf = current_inferior ();
6216 inf_status->thread_control = tp->control;
6217 inf_status->inferior_control = inf->control;
6219 tp->control.step_resume_breakpoint = NULL;
6221 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6222 chain. If caller's caller is walking the chain, they'll be happier if we
6223 hand them back the original chain when restore_infcall_control_state is
6225 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
6228 inf_status->stop_stack_dummy = stop_stack_dummy;
6229 inf_status->stopped_by_random_signal = stopped_by_random_signal;
6230 inf_status->stop_after_trap = stop_after_trap;
6232 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
6238 restore_selected_frame (void *args)
6240 struct frame_id *fid = (struct frame_id *) args;
6241 struct frame_info *frame;
6243 frame = frame_find_by_id (*fid);
6245 /* If inf_status->selected_frame_id is NULL, there was no previously
6249 warning (_("Unable to restore previously selected frame."));
6253 select_frame (frame);
6258 /* Restore inferior session state to INF_STATUS. */
6261 restore_infcall_control_state (struct infcall_control_state *inf_status)
6263 struct thread_info *tp = inferior_thread ();
6264 struct inferior *inf = current_inferior ();
6266 if (tp->control.step_resume_breakpoint)
6267 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
6269 /* Handle the bpstat_copy of the chain. */
6270 bpstat_clear (&tp->control.stop_bpstat);
6272 tp->control = inf_status->thread_control;
6273 inf->control = inf_status->inferior_control;
6276 stop_stack_dummy = inf_status->stop_stack_dummy;
6277 stopped_by_random_signal = inf_status->stopped_by_random_signal;
6278 stop_after_trap = inf_status->stop_after_trap;
6280 if (target_has_stack)
6282 /* The point of catch_errors is that if the stack is clobbered,
6283 walking the stack might encounter a garbage pointer and
6284 error() trying to dereference it. */
6286 (restore_selected_frame, &inf_status->selected_frame_id,
6287 "Unable to restore previously selected frame:\n",
6288 RETURN_MASK_ERROR) == 0)
6289 /* Error in restoring the selected frame. Select the innermost
6291 select_frame (get_current_frame ());
6298 do_restore_infcall_control_state_cleanup (void *sts)
6300 restore_infcall_control_state (sts);
6304 make_cleanup_restore_infcall_control_state
6305 (struct infcall_control_state *inf_status)
6307 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
6311 discard_infcall_control_state (struct infcall_control_state *inf_status)
6313 if (inf_status->thread_control.step_resume_breakpoint)
6314 inf_status->thread_control.step_resume_breakpoint->disposition
6315 = disp_del_at_next_stop;
6317 /* See save_infcall_control_state for info on stop_bpstat. */
6318 bpstat_clear (&inf_status->thread_control.stop_bpstat);
6324 inferior_has_forked (ptid_t pid, ptid_t *child_pid)
6326 struct target_waitstatus last;
6329 get_last_target_status (&last_ptid, &last);
6331 if (last.kind != TARGET_WAITKIND_FORKED)
6334 if (!ptid_equal (last_ptid, pid))
6337 *child_pid = last.value.related_pid;
6342 inferior_has_vforked (ptid_t pid, ptid_t *child_pid)
6344 struct target_waitstatus last;
6347 get_last_target_status (&last_ptid, &last);
6349 if (last.kind != TARGET_WAITKIND_VFORKED)
6352 if (!ptid_equal (last_ptid, pid))
6355 *child_pid = last.value.related_pid;
6360 inferior_has_execd (ptid_t pid, char **execd_pathname)
6362 struct target_waitstatus last;
6365 get_last_target_status (&last_ptid, &last);
6367 if (last.kind != TARGET_WAITKIND_EXECD)
6370 if (!ptid_equal (last_ptid, pid))
6373 *execd_pathname = xstrdup (last.value.execd_pathname);
6378 inferior_has_called_syscall (ptid_t pid, int *syscall_number)
6380 struct target_waitstatus last;
6383 get_last_target_status (&last_ptid, &last);
6385 if (last.kind != TARGET_WAITKIND_SYSCALL_ENTRY &&
6386 last.kind != TARGET_WAITKIND_SYSCALL_RETURN)
6389 if (!ptid_equal (last_ptid, pid))
6392 *syscall_number = last.value.syscall_number;
6396 /* Oft used ptids */
6398 ptid_t minus_one_ptid;
6400 /* Create a ptid given the necessary PID, LWP, and TID components. */
6403 ptid_build (int pid, long lwp, long tid)
6413 /* Create a ptid from just a pid. */
6416 pid_to_ptid (int pid)
6418 return ptid_build (pid, 0, 0);
6421 /* Fetch the pid (process id) component from a ptid. */
6424 ptid_get_pid (ptid_t ptid)
6429 /* Fetch the lwp (lightweight process) component from a ptid. */
6432 ptid_get_lwp (ptid_t ptid)
6437 /* Fetch the tid (thread id) component from a ptid. */
6440 ptid_get_tid (ptid_t ptid)
6445 /* ptid_equal() is used to test equality of two ptids. */
6448 ptid_equal (ptid_t ptid1, ptid_t ptid2)
6450 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
6451 && ptid1.tid == ptid2.tid);
6454 /* Returns true if PTID represents a process. */
6457 ptid_is_pid (ptid_t ptid)
6459 if (ptid_equal (minus_one_ptid, ptid))
6461 if (ptid_equal (null_ptid, ptid))
6464 return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0);
6468 ptid_match (ptid_t ptid, ptid_t filter)
6470 /* Since both parameters have the same type, prevent easy mistakes
6472 gdb_assert (!ptid_equal (ptid, minus_one_ptid)
6473 && !ptid_equal (ptid, null_ptid));
6475 if (ptid_equal (filter, minus_one_ptid))
6477 if (ptid_is_pid (filter)
6478 && ptid_get_pid (ptid) == ptid_get_pid (filter))
6480 else if (ptid_equal (ptid, filter))
6486 /* restore_inferior_ptid() will be used by the cleanup machinery
6487 to restore the inferior_ptid value saved in a call to
6488 save_inferior_ptid(). */
6491 restore_inferior_ptid (void *arg)
6493 ptid_t *saved_ptid_ptr = arg;
6495 inferior_ptid = *saved_ptid_ptr;
6499 /* Save the value of inferior_ptid so that it may be restored by a
6500 later call to do_cleanups(). Returns the struct cleanup pointer
6501 needed for later doing the cleanup. */
6504 save_inferior_ptid (void)
6506 ptid_t *saved_ptid_ptr;
6508 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
6509 *saved_ptid_ptr = inferior_ptid;
6510 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
6514 /* User interface for reverse debugging:
6515 Set exec-direction / show exec-direction commands
6516 (returns error unless target implements to_set_exec_direction method). */
6518 enum exec_direction_kind execution_direction = EXEC_FORWARD;
6519 static const char exec_forward[] = "forward";
6520 static const char exec_reverse[] = "reverse";
6521 static const char *exec_direction = exec_forward;
6522 static const char *exec_direction_names[] = {
6529 set_exec_direction_func (char *args, int from_tty,
6530 struct cmd_list_element *cmd)
6532 if (target_can_execute_reverse)
6534 if (!strcmp (exec_direction, exec_forward))
6535 execution_direction = EXEC_FORWARD;
6536 else if (!strcmp (exec_direction, exec_reverse))
6537 execution_direction = EXEC_REVERSE;
6541 exec_direction = exec_forward;
6542 error (_("Target does not support this operation."));
6547 show_exec_direction_func (struct ui_file *out, int from_tty,
6548 struct cmd_list_element *cmd, const char *value)
6550 switch (execution_direction) {
6552 fprintf_filtered (out, _("Forward.\n"));
6555 fprintf_filtered (out, _("Reverse.\n"));
6559 fprintf_filtered (out,
6560 _("Forward (target `%s' does not support exec-direction).\n"),
6566 /* User interface for non-stop mode. */
6571 set_non_stop (char *args, int from_tty,
6572 struct cmd_list_element *c)
6574 if (target_has_execution)
6576 non_stop_1 = non_stop;
6577 error (_("Cannot change this setting while the inferior is running."));
6580 non_stop = non_stop_1;
6584 show_non_stop (struct ui_file *file, int from_tty,
6585 struct cmd_list_element *c, const char *value)
6587 fprintf_filtered (file,
6588 _("Controlling the inferior in non-stop mode is %s.\n"),
6593 show_schedule_multiple (struct ui_file *file, int from_tty,
6594 struct cmd_list_element *c, const char *value)
6596 fprintf_filtered (file, _("\
6597 Resuming the execution of threads of all processes is %s.\n"), value);
6601 _initialize_infrun (void)
6606 add_info ("signals", signals_info, _("\
6607 What debugger does when program gets various signals.\n\
6608 Specify a signal as argument to print info on that signal only."));
6609 add_info_alias ("handle", "signals", 0);
6611 add_com ("handle", class_run, handle_command, _("\
6612 Specify how to handle a signal.\n\
6613 Args are signals and actions to apply to those signals.\n\
6614 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6615 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6616 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6617 The special arg \"all\" is recognized to mean all signals except those\n\
6618 used by the debugger, typically SIGTRAP and SIGINT.\n\
6619 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
6620 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
6621 Stop means reenter debugger if this signal happens (implies print).\n\
6622 Print means print a message if this signal happens.\n\
6623 Pass means let program see this signal; otherwise program doesn't know.\n\
6624 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6625 Pass and Stop may be combined."));
6628 add_com ("lz", class_info, signals_info, _("\
6629 What debugger does when program gets various signals.\n\
6630 Specify a signal as argument to print info on that signal only."));
6631 add_com ("z", class_run, xdb_handle_command, _("\
6632 Specify how to handle a signal.\n\
6633 Args are signals and actions to apply to those signals.\n\
6634 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6635 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6636 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6637 The special arg \"all\" is recognized to mean all signals except those\n\
6638 used by the debugger, typically SIGTRAP and SIGINT.\n\
6639 Recognized actions include \"s\" (toggles between stop and nostop),\n\
6640 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
6641 nopass), \"Q\" (noprint)\n\
6642 Stop means reenter debugger if this signal happens (implies print).\n\
6643 Print means print a message if this signal happens.\n\
6644 Pass means let program see this signal; otherwise program doesn't know.\n\
6645 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6646 Pass and Stop may be combined."));
6650 stop_command = add_cmd ("stop", class_obscure,
6651 not_just_help_class_command, _("\
6652 There is no `stop' command, but you can set a hook on `stop'.\n\
6653 This allows you to set a list of commands to be run each time execution\n\
6654 of the program stops."), &cmdlist);
6656 add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
6657 Set inferior debugging."), _("\
6658 Show inferior debugging."), _("\
6659 When non-zero, inferior specific debugging is enabled."),
6662 &setdebuglist, &showdebuglist);
6664 add_setshow_boolean_cmd ("displaced", class_maintenance, &debug_displaced, _("\
6665 Set displaced stepping debugging."), _("\
6666 Show displaced stepping debugging."), _("\
6667 When non-zero, displaced stepping specific debugging is enabled."),
6669 show_debug_displaced,
6670 &setdebuglist, &showdebuglist);
6672 add_setshow_boolean_cmd ("non-stop", no_class,
6674 Set whether gdb controls the inferior in non-stop mode."), _("\
6675 Show whether gdb controls the inferior in non-stop mode."), _("\
6676 When debugging a multi-threaded program and this setting is\n\
6677 off (the default, also called all-stop mode), when one thread stops\n\
6678 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
6679 all other threads in the program while you interact with the thread of\n\
6680 interest. When you continue or step a thread, you can allow the other\n\
6681 threads to run, or have them remain stopped, but while you inspect any\n\
6682 thread's state, all threads stop.\n\
6684 In non-stop mode, when one thread stops, other threads can continue\n\
6685 to run freely. You'll be able to step each thread independently,\n\
6686 leave it stopped or free to run as needed."),
6692 numsigs = (int) TARGET_SIGNAL_LAST;
6693 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
6694 signal_print = (unsigned char *)
6695 xmalloc (sizeof (signal_print[0]) * numsigs);
6696 signal_program = (unsigned char *)
6697 xmalloc (sizeof (signal_program[0]) * numsigs);
6698 for (i = 0; i < numsigs; i++)
6701 signal_print[i] = 1;
6702 signal_program[i] = 1;
6705 /* Signals caused by debugger's own actions
6706 should not be given to the program afterwards. */
6707 signal_program[TARGET_SIGNAL_TRAP] = 0;
6708 signal_program[TARGET_SIGNAL_INT] = 0;
6710 /* Signals that are not errors should not normally enter the debugger. */
6711 signal_stop[TARGET_SIGNAL_ALRM] = 0;
6712 signal_print[TARGET_SIGNAL_ALRM] = 0;
6713 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
6714 signal_print[TARGET_SIGNAL_VTALRM] = 0;
6715 signal_stop[TARGET_SIGNAL_PROF] = 0;
6716 signal_print[TARGET_SIGNAL_PROF] = 0;
6717 signal_stop[TARGET_SIGNAL_CHLD] = 0;
6718 signal_print[TARGET_SIGNAL_CHLD] = 0;
6719 signal_stop[TARGET_SIGNAL_IO] = 0;
6720 signal_print[TARGET_SIGNAL_IO] = 0;
6721 signal_stop[TARGET_SIGNAL_POLL] = 0;
6722 signal_print[TARGET_SIGNAL_POLL] = 0;
6723 signal_stop[TARGET_SIGNAL_URG] = 0;
6724 signal_print[TARGET_SIGNAL_URG] = 0;
6725 signal_stop[TARGET_SIGNAL_WINCH] = 0;
6726 signal_print[TARGET_SIGNAL_WINCH] = 0;
6728 /* These signals are used internally by user-level thread
6729 implementations. (See signal(5) on Solaris.) Like the above
6730 signals, a healthy program receives and handles them as part of
6731 its normal operation. */
6732 signal_stop[TARGET_SIGNAL_LWP] = 0;
6733 signal_print[TARGET_SIGNAL_LWP] = 0;
6734 signal_stop[TARGET_SIGNAL_WAITING] = 0;
6735 signal_print[TARGET_SIGNAL_WAITING] = 0;
6736 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
6737 signal_print[TARGET_SIGNAL_CANCEL] = 0;
6739 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
6740 &stop_on_solib_events, _("\
6741 Set stopping for shared library events."), _("\
6742 Show stopping for shared library events."), _("\
6743 If nonzero, gdb will give control to the user when the dynamic linker\n\
6744 notifies gdb of shared library events. The most common event of interest\n\
6745 to the user would be loading/unloading of a new library."),
6747 show_stop_on_solib_events,
6748 &setlist, &showlist);
6750 add_setshow_enum_cmd ("follow-fork-mode", class_run,
6751 follow_fork_mode_kind_names,
6752 &follow_fork_mode_string, _("\
6753 Set debugger response to a program call of fork or vfork."), _("\
6754 Show debugger response to a program call of fork or vfork."), _("\
6755 A fork or vfork creates a new process. follow-fork-mode can be:\n\
6756 parent - the original process is debugged after a fork\n\
6757 child - the new process is debugged after a fork\n\
6758 The unfollowed process will continue to run.\n\
6759 By default, the debugger will follow the parent process."),
6761 show_follow_fork_mode_string,
6762 &setlist, &showlist);
6764 add_setshow_enum_cmd ("follow-exec-mode", class_run,
6765 follow_exec_mode_names,
6766 &follow_exec_mode_string, _("\
6767 Set debugger response to a program call of exec."), _("\
6768 Show debugger response to a program call of exec."), _("\
6769 An exec call replaces the program image of a process.\n\
6771 follow-exec-mode can be:\n\
6773 new - the debugger creates a new inferior and rebinds the process\n\
6774 to this new inferior. The program the process was running before\n\
6775 the exec call can be restarted afterwards by restarting the original\n\
6778 same - the debugger keeps the process bound to the same inferior.\n\
6779 The new executable image replaces the previous executable loaded in\n\
6780 the inferior. Restarting the inferior after the exec call restarts\n\
6781 the executable the process was running after the exec call.\n\
6783 By default, the debugger will use the same inferior."),
6785 show_follow_exec_mode_string,
6786 &setlist, &showlist);
6788 add_setshow_enum_cmd ("scheduler-locking", class_run,
6789 scheduler_enums, &scheduler_mode, _("\
6790 Set mode for locking scheduler during execution."), _("\
6791 Show mode for locking scheduler during execution."), _("\
6792 off == no locking (threads may preempt at any time)\n\
6793 on == full locking (no thread except the current thread may run)\n\
6794 step == scheduler locked during every single-step operation.\n\
6795 In this mode, no other thread may run during a step command.\n\
6796 Other threads may run while stepping over a function call ('next')."),
6797 set_schedlock_func, /* traps on target vector */
6798 show_scheduler_mode,
6799 &setlist, &showlist);
6801 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
6802 Set mode for resuming threads of all processes."), _("\
6803 Show mode for resuming threads of all processes."), _("\
6804 When on, execution commands (such as 'continue' or 'next') resume all\n\
6805 threads of all processes. When off (which is the default), execution\n\
6806 commands only resume the threads of the current process. The set of\n\
6807 threads that are resumed is further refined by the scheduler-locking\n\
6808 mode (see help set scheduler-locking)."),
6810 show_schedule_multiple,
6811 &setlist, &showlist);
6813 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
6814 Set mode of the step operation."), _("\
6815 Show mode of the step operation."), _("\
6816 When set, doing a step over a function without debug line information\n\
6817 will stop at the first instruction of that function. Otherwise, the\n\
6818 function is skipped and the step command stops at a different source line."),
6820 show_step_stop_if_no_debug,
6821 &setlist, &showlist);
6823 add_setshow_enum_cmd ("displaced-stepping", class_run,
6824 can_use_displaced_stepping_enum,
6825 &can_use_displaced_stepping, _("\
6826 Set debugger's willingness to use displaced stepping."), _("\
6827 Show debugger's willingness to use displaced stepping."), _("\
6828 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
6829 supported by the target architecture. If off, gdb will not use displaced\n\
6830 stepping to step over breakpoints, even if such is supported by the target\n\
6831 architecture. If auto (which is the default), gdb will use displaced stepping\n\
6832 if the target architecture supports it and non-stop mode is active, but will not\n\
6833 use it in all-stop mode (see help set non-stop)."),
6835 show_can_use_displaced_stepping,
6836 &setlist, &showlist);
6838 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
6839 &exec_direction, _("Set direction of execution.\n\
6840 Options are 'forward' or 'reverse'."),
6841 _("Show direction of execution (forward/reverse)."),
6842 _("Tells gdb whether to execute forward or backward."),
6843 set_exec_direction_func, show_exec_direction_func,
6844 &setlist, &showlist);
6846 /* Set/show detach-on-fork: user-settable mode. */
6848 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
6849 Set whether gdb will detach the child of a fork."), _("\
6850 Show whether gdb will detach the child of a fork."), _("\
6851 Tells gdb whether to detach the child of a fork."),
6852 NULL, NULL, &setlist, &showlist);
6854 /* ptid initializations */
6855 null_ptid = ptid_build (0, 0, 0);
6856 minus_one_ptid = ptid_build (-1, 0, 0);
6857 inferior_ptid = null_ptid;
6858 target_last_wait_ptid = minus_one_ptid;
6860 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
6861 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
6862 observer_attach_thread_exit (infrun_thread_thread_exit);
6863 observer_attach_inferior_exit (infrun_inferior_exit);
6865 /* Explicitly create without lookup, since that tries to create a
6866 value with a void typed value, and when we get here, gdbarch
6867 isn't initialized yet. At this point, we're quite sure there
6868 isn't another convenience variable of the same name. */
6869 create_internalvar_type_lazy ("_siginfo", siginfo_make_value);
6871 add_setshow_boolean_cmd ("observer", no_class,
6872 &observer_mode_1, _("\
6873 Set whether gdb controls the inferior in observer mode."), _("\
6874 Show whether gdb controls the inferior in observer mode."), _("\
6875 In observer mode, GDB can get data from the inferior, but not\n\
6876 affect its execution. Registers and memory may not be changed,\n\
6877 breakpoints may not be set, and the program cannot be interrupted\n\