1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
5 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
6 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
29 #include "exceptions.h"
30 #include "breakpoint.h"
34 #include "cli/cli-script.h"
36 #include "gdbthread.h"
48 #include "dictionary.h"
50 #include "gdb_assert.h"
51 #include "mi/mi-common.h"
52 #include "event-top.h"
54 #include "inline-frame.h"
56 #include "tracepoint.h"
58 /* Prototypes for local functions */
60 static void signals_info (char *, int);
62 static void handle_command (char *, int);
64 static void sig_print_info (enum target_signal);
66 static void sig_print_header (void);
68 static void resume_cleanups (void *);
70 static int hook_stop_stub (void *);
72 static int restore_selected_frame (void *);
74 static int follow_fork (void);
76 static void set_schedlock_func (char *args, int from_tty,
77 struct cmd_list_element *c);
79 static int currently_stepping (struct thread_info *tp);
81 static int currently_stepping_or_nexting_callback (struct thread_info *tp,
84 static void xdb_handle_command (char *args, int from_tty);
86 static int prepare_to_proceed (int);
88 static void print_exited_reason (int exitstatus);
90 static void print_signal_exited_reason (enum target_signal siggnal);
92 static void print_no_history_reason (void);
94 static void print_signal_received_reason (enum target_signal siggnal);
96 static void print_end_stepping_range_reason (void);
98 void _initialize_infrun (void);
100 void nullify_last_target_wait_ptid (void);
102 /* When set, stop the 'step' command if we enter a function which has
103 no line number information. The normal behavior is that we step
104 over such function. */
105 int step_stop_if_no_debug = 0;
107 show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
108 struct cmd_list_element *c, const char *value)
110 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
113 /* In asynchronous mode, but simulating synchronous execution. */
115 int sync_execution = 0;
117 /* wait_for_inferior and normal_stop use this to notify the user
118 when the inferior stopped in a different thread than it had been
121 static ptid_t previous_inferior_ptid;
123 /* Default behavior is to detach newly forked processes (legacy). */
126 int debug_displaced = 0;
128 show_debug_displaced (struct ui_file *file, int from_tty,
129 struct cmd_list_element *c, const char *value)
131 fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value);
134 int debug_infrun = 0;
136 show_debug_infrun (struct ui_file *file, int from_tty,
137 struct cmd_list_element *c, const char *value)
139 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
142 /* If the program uses ELF-style shared libraries, then calls to
143 functions in shared libraries go through stubs, which live in a
144 table called the PLT (Procedure Linkage Table). The first time the
145 function is called, the stub sends control to the dynamic linker,
146 which looks up the function's real address, patches the stub so
147 that future calls will go directly to the function, and then passes
148 control to the function.
150 If we are stepping at the source level, we don't want to see any of
151 this --- we just want to skip over the stub and the dynamic linker.
152 The simple approach is to single-step until control leaves the
155 However, on some systems (e.g., Red Hat's 5.2 distribution) the
156 dynamic linker calls functions in the shared C library, so you
157 can't tell from the PC alone whether the dynamic linker is still
158 running. In this case, we use a step-resume breakpoint to get us
159 past the dynamic linker, as if we were using "next" to step over a
162 in_solib_dynsym_resolve_code() says whether we're in the dynamic
163 linker code or not. Normally, this means we single-step. However,
164 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
165 address where we can place a step-resume breakpoint to get past the
166 linker's symbol resolution function.
168 in_solib_dynsym_resolve_code() can generally be implemented in a
169 pretty portable way, by comparing the PC against the address ranges
170 of the dynamic linker's sections.
172 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
173 it depends on internal details of the dynamic linker. It's usually
174 not too hard to figure out where to put a breakpoint, but it
175 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
176 sanity checking. If it can't figure things out, returning zero and
177 getting the (possibly confusing) stepping behavior is better than
178 signalling an error, which will obscure the change in the
181 /* This function returns TRUE if pc is the address of an instruction
182 that lies within the dynamic linker (such as the event hook, or the
185 This function must be used only when a dynamic linker event has
186 been caught, and the inferior is being stepped out of the hook, or
187 undefined results are guaranteed. */
189 #ifndef SOLIB_IN_DYNAMIC_LINKER
190 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
193 /* "Observer mode" is somewhat like a more extreme version of
194 non-stop, in which all GDB operations that might affect the
195 target's execution have been disabled. */
197 static int non_stop_1 = 0;
199 int observer_mode = 0;
200 static int observer_mode_1 = 0;
203 set_observer_mode (char *args, int from_tty,
204 struct cmd_list_element *c)
206 extern int pagination_enabled;
208 if (target_has_execution)
210 observer_mode_1 = observer_mode;
211 error (_("Cannot change this setting while the inferior is running."));
214 observer_mode = observer_mode_1;
216 may_write_registers = !observer_mode;
217 may_write_memory = !observer_mode;
218 may_insert_breakpoints = !observer_mode;
219 may_insert_tracepoints = !observer_mode;
220 /* We can insert fast tracepoints in or out of observer mode,
221 but enable them if we're going into this mode. */
223 may_insert_fast_tracepoints = 1;
224 may_stop = !observer_mode;
225 update_target_permissions ();
227 /* Going *into* observer mode we must force non-stop, then
228 going out we leave it that way. */
231 target_async_permitted = 1;
232 pagination_enabled = 0;
233 non_stop = non_stop_1 = 1;
237 printf_filtered (_("Observer mode is now %s.\n"),
238 (observer_mode ? "on" : "off"));
242 show_observer_mode (struct ui_file *file, int from_tty,
243 struct cmd_list_element *c, const char *value)
245 fprintf_filtered (file, _("Observer mode is %s.\n"), value);
248 /* This updates the value of observer mode based on changes in
249 permissions. Note that we are deliberately ignoring the values of
250 may-write-registers and may-write-memory, since the user may have
251 reason to enable these during a session, for instance to turn on a
252 debugging-related global. */
255 update_observer_mode (void)
259 newval = (!may_insert_breakpoints
260 && !may_insert_tracepoints
261 && may_insert_fast_tracepoints
265 /* Let the user know if things change. */
266 if (newval != observer_mode)
267 printf_filtered (_("Observer mode is now %s.\n"),
268 (newval ? "on" : "off"));
270 observer_mode = observer_mode_1 = newval;
273 /* Tables of how to react to signals; the user sets them. */
275 static unsigned char *signal_stop;
276 static unsigned char *signal_print;
277 static unsigned char *signal_program;
279 #define SET_SIGS(nsigs,sigs,flags) \
281 int signum = (nsigs); \
282 while (signum-- > 0) \
283 if ((sigs)[signum]) \
284 (flags)[signum] = 1; \
287 #define UNSET_SIGS(nsigs,sigs,flags) \
289 int signum = (nsigs); \
290 while (signum-- > 0) \
291 if ((sigs)[signum]) \
292 (flags)[signum] = 0; \
295 /* Value to pass to target_resume() to cause all threads to resume */
297 #define RESUME_ALL minus_one_ptid
299 /* Command list pointer for the "stop" placeholder. */
301 static struct cmd_list_element *stop_command;
303 /* Function inferior was in as of last step command. */
305 static struct symbol *step_start_function;
307 /* Nonzero if we want to give control to the user when we're notified
308 of shared library events by the dynamic linker. */
309 int stop_on_solib_events;
311 show_stop_on_solib_events (struct ui_file *file, int from_tty,
312 struct cmd_list_element *c, const char *value)
314 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
318 /* Nonzero means expecting a trace trap
319 and should stop the inferior and return silently when it happens. */
323 /* Save register contents here when executing a "finish" command or are
324 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
325 Thus this contains the return value from the called function (assuming
326 values are returned in a register). */
328 struct regcache *stop_registers;
330 /* Nonzero after stop if current stack frame should be printed. */
332 static int stop_print_frame;
334 /* This is a cached copy of the pid/waitstatus of the last event
335 returned by target_wait()/deprecated_target_wait_hook(). This
336 information is returned by get_last_target_status(). */
337 static ptid_t target_last_wait_ptid;
338 static struct target_waitstatus target_last_waitstatus;
340 static void context_switch (ptid_t ptid);
342 void init_thread_stepping_state (struct thread_info *tss);
344 void init_infwait_state (void);
346 static const char follow_fork_mode_child[] = "child";
347 static const char follow_fork_mode_parent[] = "parent";
349 static const char *follow_fork_mode_kind_names[] = {
350 follow_fork_mode_child,
351 follow_fork_mode_parent,
355 static const char *follow_fork_mode_string = follow_fork_mode_parent;
357 show_follow_fork_mode_string (struct ui_file *file, int from_tty,
358 struct cmd_list_element *c, const char *value)
360 fprintf_filtered (file,
361 _("Debugger response to a program "
362 "call of fork or vfork is \"%s\".\n"),
367 /* Tell the target to follow the fork we're stopped at. Returns true
368 if the inferior should be resumed; false, if the target for some
369 reason decided it's best not to resume. */
374 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
375 int should_resume = 1;
376 struct thread_info *tp;
378 /* Copy user stepping state to the new inferior thread. FIXME: the
379 followed fork child thread should have a copy of most of the
380 parent thread structure's run control related fields, not just these.
381 Initialized to avoid "may be used uninitialized" warnings from gcc. */
382 struct breakpoint *step_resume_breakpoint = NULL;
383 struct breakpoint *exception_resume_breakpoint = NULL;
384 CORE_ADDR step_range_start = 0;
385 CORE_ADDR step_range_end = 0;
386 struct frame_id step_frame_id = { 0 };
391 struct target_waitstatus wait_status;
393 /* Get the last target status returned by target_wait(). */
394 get_last_target_status (&wait_ptid, &wait_status);
396 /* If not stopped at a fork event, then there's nothing else to
398 if (wait_status.kind != TARGET_WAITKIND_FORKED
399 && wait_status.kind != TARGET_WAITKIND_VFORKED)
402 /* Check if we switched over from WAIT_PTID, since the event was
404 if (!ptid_equal (wait_ptid, minus_one_ptid)
405 && !ptid_equal (inferior_ptid, wait_ptid))
407 /* We did. Switch back to WAIT_PTID thread, to tell the
408 target to follow it (in either direction). We'll
409 afterwards refuse to resume, and inform the user what
411 switch_to_thread (wait_ptid);
416 tp = inferior_thread ();
418 /* If there were any forks/vforks that were caught and are now to be
419 followed, then do so now. */
420 switch (tp->pending_follow.kind)
422 case TARGET_WAITKIND_FORKED:
423 case TARGET_WAITKIND_VFORKED:
425 ptid_t parent, child;
427 /* If the user did a next/step, etc, over a fork call,
428 preserve the stepping state in the fork child. */
429 if (follow_child && should_resume)
431 step_resume_breakpoint = clone_momentary_breakpoint
432 (tp->control.step_resume_breakpoint);
433 step_range_start = tp->control.step_range_start;
434 step_range_end = tp->control.step_range_end;
435 step_frame_id = tp->control.step_frame_id;
436 exception_resume_breakpoint
437 = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint);
439 /* For now, delete the parent's sr breakpoint, otherwise,
440 parent/child sr breakpoints are considered duplicates,
441 and the child version will not be installed. Remove
442 this when the breakpoints module becomes aware of
443 inferiors and address spaces. */
444 delete_step_resume_breakpoint (tp);
445 tp->control.step_range_start = 0;
446 tp->control.step_range_end = 0;
447 tp->control.step_frame_id = null_frame_id;
448 delete_exception_resume_breakpoint (tp);
451 parent = inferior_ptid;
452 child = tp->pending_follow.value.related_pid;
454 /* Tell the target to do whatever is necessary to follow
455 either parent or child. */
456 if (target_follow_fork (follow_child))
458 /* Target refused to follow, or there's some other reason
459 we shouldn't resume. */
464 /* This pending follow fork event is now handled, one way
465 or another. The previous selected thread may be gone
466 from the lists by now, but if it is still around, need
467 to clear the pending follow request. */
468 tp = find_thread_ptid (parent);
470 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
472 /* This makes sure we don't try to apply the "Switched
473 over from WAIT_PID" logic above. */
474 nullify_last_target_wait_ptid ();
476 /* If we followed the child, switch to it... */
479 switch_to_thread (child);
481 /* ... and preserve the stepping state, in case the
482 user was stepping over the fork call. */
485 tp = inferior_thread ();
486 tp->control.step_resume_breakpoint
487 = step_resume_breakpoint;
488 tp->control.step_range_start = step_range_start;
489 tp->control.step_range_end = step_range_end;
490 tp->control.step_frame_id = step_frame_id;
491 tp->control.exception_resume_breakpoint
492 = exception_resume_breakpoint;
496 /* If we get here, it was because we're trying to
497 resume from a fork catchpoint, but, the user
498 has switched threads away from the thread that
499 forked. In that case, the resume command
500 issued is most likely not applicable to the
501 child, so just warn, and refuse to resume. */
502 warning (_("Not resuming: switched threads "
503 "before following fork child.\n"));
506 /* Reset breakpoints in the child as appropriate. */
507 follow_inferior_reset_breakpoints ();
510 switch_to_thread (parent);
514 case TARGET_WAITKIND_SPURIOUS:
515 /* Nothing to follow. */
518 internal_error (__FILE__, __LINE__,
519 "Unexpected pending_follow.kind %d\n",
520 tp->pending_follow.kind);
524 return should_resume;
528 follow_inferior_reset_breakpoints (void)
530 struct thread_info *tp = inferior_thread ();
532 /* Was there a step_resume breakpoint? (There was if the user
533 did a "next" at the fork() call.) If so, explicitly reset its
536 step_resumes are a form of bp that are made to be per-thread.
537 Since we created the step_resume bp when the parent process
538 was being debugged, and now are switching to the child process,
539 from the breakpoint package's viewpoint, that's a switch of
540 "threads". We must update the bp's notion of which thread
541 it is for, or it'll be ignored when it triggers. */
543 if (tp->control.step_resume_breakpoint)
544 breakpoint_re_set_thread (tp->control.step_resume_breakpoint);
546 if (tp->control.exception_resume_breakpoint)
547 breakpoint_re_set_thread (tp->control.exception_resume_breakpoint);
549 /* Reinsert all breakpoints in the child. The user may have set
550 breakpoints after catching the fork, in which case those
551 were never set in the child, but only in the parent. This makes
552 sure the inserted breakpoints match the breakpoint list. */
554 breakpoint_re_set ();
555 insert_breakpoints ();
558 /* The child has exited or execed: resume threads of the parent the
559 user wanted to be executing. */
562 proceed_after_vfork_done (struct thread_info *thread,
565 int pid = * (int *) arg;
567 if (ptid_get_pid (thread->ptid) == pid
568 && is_running (thread->ptid)
569 && !is_executing (thread->ptid)
570 && !thread->stop_requested
571 && thread->suspend.stop_signal == TARGET_SIGNAL_0)
574 fprintf_unfiltered (gdb_stdlog,
575 "infrun: resuming vfork parent thread %s\n",
576 target_pid_to_str (thread->ptid));
578 switch_to_thread (thread->ptid);
579 clear_proceed_status ();
580 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
586 /* Called whenever we notice an exec or exit event, to handle
587 detaching or resuming a vfork parent. */
590 handle_vfork_child_exec_or_exit (int exec)
592 struct inferior *inf = current_inferior ();
594 if (inf->vfork_parent)
596 int resume_parent = -1;
598 /* This exec or exit marks the end of the shared memory region
599 between the parent and the child. If the user wanted to
600 detach from the parent, now is the time. */
602 if (inf->vfork_parent->pending_detach)
604 struct thread_info *tp;
605 struct cleanup *old_chain;
606 struct program_space *pspace;
607 struct address_space *aspace;
609 /* follow-fork child, detach-on-fork on */
611 old_chain = make_cleanup_restore_current_thread ();
613 /* We're letting loose of the parent. */
614 tp = any_live_thread_of_process (inf->vfork_parent->pid);
615 switch_to_thread (tp->ptid);
617 /* We're about to detach from the parent, which implicitly
618 removes breakpoints from its address space. There's a
619 catch here: we want to reuse the spaces for the child,
620 but, parent/child are still sharing the pspace at this
621 point, although the exec in reality makes the kernel give
622 the child a fresh set of new pages. The problem here is
623 that the breakpoints module being unaware of this, would
624 likely chose the child process to write to the parent
625 address space. Swapping the child temporarily away from
626 the spaces has the desired effect. Yes, this is "sort
629 pspace = inf->pspace;
630 aspace = inf->aspace;
634 if (debug_infrun || info_verbose)
636 target_terminal_ours ();
639 fprintf_filtered (gdb_stdlog,
640 "Detaching vfork parent process "
641 "%d after child exec.\n",
642 inf->vfork_parent->pid);
644 fprintf_filtered (gdb_stdlog,
645 "Detaching vfork parent process "
646 "%d after child exit.\n",
647 inf->vfork_parent->pid);
650 target_detach (NULL, 0);
653 inf->pspace = pspace;
654 inf->aspace = aspace;
656 do_cleanups (old_chain);
660 /* We're staying attached to the parent, so, really give the
661 child a new address space. */
662 inf->pspace = add_program_space (maybe_new_address_space ());
663 inf->aspace = inf->pspace->aspace;
665 set_current_program_space (inf->pspace);
667 resume_parent = inf->vfork_parent->pid;
669 /* Break the bonds. */
670 inf->vfork_parent->vfork_child = NULL;
674 struct cleanup *old_chain;
675 struct program_space *pspace;
677 /* If this is a vfork child exiting, then the pspace and
678 aspaces were shared with the parent. Since we're
679 reporting the process exit, we'll be mourning all that is
680 found in the address space, and switching to null_ptid,
681 preparing to start a new inferior. But, since we don't
682 want to clobber the parent's address/program spaces, we
683 go ahead and create a new one for this exiting
686 /* Switch to null_ptid, so that clone_program_space doesn't want
687 to read the selected frame of a dead process. */
688 old_chain = save_inferior_ptid ();
689 inferior_ptid = null_ptid;
691 /* This inferior is dead, so avoid giving the breakpoints
692 module the option to write through to it (cloning a
693 program space resets breakpoints). */
696 pspace = add_program_space (maybe_new_address_space ());
697 set_current_program_space (pspace);
699 clone_program_space (pspace, inf->vfork_parent->pspace);
700 inf->pspace = pspace;
701 inf->aspace = pspace->aspace;
703 /* Put back inferior_ptid. We'll continue mourning this
705 do_cleanups (old_chain);
707 resume_parent = inf->vfork_parent->pid;
708 /* Break the bonds. */
709 inf->vfork_parent->vfork_child = NULL;
712 inf->vfork_parent = NULL;
714 gdb_assert (current_program_space == inf->pspace);
716 if (non_stop && resume_parent != -1)
718 /* If the user wanted the parent to be running, let it go
720 struct cleanup *old_chain = make_cleanup_restore_current_thread ();
723 fprintf_unfiltered (gdb_stdlog,
724 "infrun: resuming vfork parent process %d\n",
727 iterate_over_threads (proceed_after_vfork_done, &resume_parent);
729 do_cleanups (old_chain);
734 /* Enum strings for "set|show displaced-stepping". */
736 static const char follow_exec_mode_new[] = "new";
737 static const char follow_exec_mode_same[] = "same";
738 static const char *follow_exec_mode_names[] =
740 follow_exec_mode_new,
741 follow_exec_mode_same,
745 static const char *follow_exec_mode_string = follow_exec_mode_same;
747 show_follow_exec_mode_string (struct ui_file *file, int from_tty,
748 struct cmd_list_element *c, const char *value)
750 fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value);
753 /* EXECD_PATHNAME is assumed to be non-NULL. */
756 follow_exec (ptid_t pid, char *execd_pathname)
758 struct thread_info *th = inferior_thread ();
759 struct inferior *inf = current_inferior ();
761 /* This is an exec event that we actually wish to pay attention to.
762 Refresh our symbol table to the newly exec'd program, remove any
765 If there are breakpoints, they aren't really inserted now,
766 since the exec() transformed our inferior into a fresh set
769 We want to preserve symbolic breakpoints on the list, since
770 we have hopes that they can be reset after the new a.out's
771 symbol table is read.
773 However, any "raw" breakpoints must be removed from the list
774 (e.g., the solib bp's), since their address is probably invalid
777 And, we DON'T want to call delete_breakpoints() here, since
778 that may write the bp's "shadow contents" (the instruction
779 value that was overwritten witha TRAP instruction). Since
780 we now have a new a.out, those shadow contents aren't valid. */
782 mark_breakpoints_out ();
784 update_breakpoints_after_exec ();
786 /* If there was one, it's gone now. We cannot truly step-to-next
787 statement through an exec(). */
788 th->control.step_resume_breakpoint = NULL;
789 th->control.exception_resume_breakpoint = NULL;
790 th->control.step_range_start = 0;
791 th->control.step_range_end = 0;
793 /* The target reports the exec event to the main thread, even if
794 some other thread does the exec, and even if the main thread was
795 already stopped --- if debugging in non-stop mode, it's possible
796 the user had the main thread held stopped in the previous image
797 --- release it now. This is the same behavior as step-over-exec
798 with scheduler-locking on in all-stop mode. */
799 th->stop_requested = 0;
801 /* What is this a.out's name? */
802 printf_unfiltered (_("%s is executing new program: %s\n"),
803 target_pid_to_str (inferior_ptid),
806 /* We've followed the inferior through an exec. Therefore, the
807 inferior has essentially been killed & reborn. */
809 gdb_flush (gdb_stdout);
811 breakpoint_init_inferior (inf_execd);
813 if (gdb_sysroot && *gdb_sysroot)
815 char *name = alloca (strlen (gdb_sysroot)
816 + strlen (execd_pathname)
819 strcpy (name, gdb_sysroot);
820 strcat (name, execd_pathname);
821 execd_pathname = name;
824 /* Reset the shared library package. This ensures that we get a
825 shlib event when the child reaches "_start", at which point the
826 dld will have had a chance to initialize the child. */
827 /* Also, loading a symbol file below may trigger symbol lookups, and
828 we don't want those to be satisfied by the libraries of the
829 previous incarnation of this process. */
830 no_shared_libraries (NULL, 0);
832 if (follow_exec_mode_string == follow_exec_mode_new)
834 struct program_space *pspace;
836 /* The user wants to keep the old inferior and program spaces
837 around. Create a new fresh one, and switch to it. */
839 inf = add_inferior (current_inferior ()->pid);
840 pspace = add_program_space (maybe_new_address_space ());
841 inf->pspace = pspace;
842 inf->aspace = pspace->aspace;
844 exit_inferior_num_silent (current_inferior ()->num);
846 set_current_inferior (inf);
847 set_current_program_space (pspace);
850 gdb_assert (current_program_space == inf->pspace);
852 /* That a.out is now the one to use. */
853 exec_file_attach (execd_pathname, 0);
855 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
856 (Position Independent Executable) main symbol file will get applied by
857 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
858 the breakpoints with the zero displacement. */
860 symbol_file_add (execd_pathname, SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET,
863 set_initial_language ();
865 #ifdef SOLIB_CREATE_INFERIOR_HOOK
866 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
868 solib_create_inferior_hook (0);
871 jit_inferior_created_hook ();
873 breakpoint_re_set ();
875 /* Reinsert all breakpoints. (Those which were symbolic have
876 been reset to the proper address in the new a.out, thanks
877 to symbol_file_command...) */
878 insert_breakpoints ();
880 /* The next resume of this inferior should bring it to the shlib
881 startup breakpoints. (If the user had also set bp's on
882 "main" from the old (parent) process, then they'll auto-
883 matically get reset there in the new process.) */
886 /* Non-zero if we just simulating a single-step. This is needed
887 because we cannot remove the breakpoints in the inferior process
888 until after the `wait' in `wait_for_inferior'. */
889 static int singlestep_breakpoints_inserted_p = 0;
891 /* The thread we inserted single-step breakpoints for. */
892 static ptid_t singlestep_ptid;
894 /* PC when we started this single-step. */
895 static CORE_ADDR singlestep_pc;
897 /* If another thread hit the singlestep breakpoint, we save the original
898 thread here so that we can resume single-stepping it later. */
899 static ptid_t saved_singlestep_ptid;
900 static int stepping_past_singlestep_breakpoint;
902 /* If not equal to null_ptid, this means that after stepping over breakpoint
903 is finished, we need to switch to deferred_step_ptid, and step it.
905 The use case is when one thread has hit a breakpoint, and then the user
906 has switched to another thread and issued 'step'. We need to step over
907 breakpoint in the thread which hit the breakpoint, but then continue
908 stepping the thread user has selected. */
909 static ptid_t deferred_step_ptid;
911 /* Displaced stepping. */
913 /* In non-stop debugging mode, we must take special care to manage
914 breakpoints properly; in particular, the traditional strategy for
915 stepping a thread past a breakpoint it has hit is unsuitable.
916 'Displaced stepping' is a tactic for stepping one thread past a
917 breakpoint it has hit while ensuring that other threads running
918 concurrently will hit the breakpoint as they should.
920 The traditional way to step a thread T off a breakpoint in a
921 multi-threaded program in all-stop mode is as follows:
923 a0) Initially, all threads are stopped, and breakpoints are not
925 a1) We single-step T, leaving breakpoints uninserted.
926 a2) We insert breakpoints, and resume all threads.
928 In non-stop debugging, however, this strategy is unsuitable: we
929 don't want to have to stop all threads in the system in order to
930 continue or step T past a breakpoint. Instead, we use displaced
933 n0) Initially, T is stopped, other threads are running, and
934 breakpoints are inserted.
935 n1) We copy the instruction "under" the breakpoint to a separate
936 location, outside the main code stream, making any adjustments
937 to the instruction, register, and memory state as directed by
939 n2) We single-step T over the instruction at its new location.
940 n3) We adjust the resulting register and memory state as directed
941 by T's architecture. This includes resetting T's PC to point
942 back into the main instruction stream.
945 This approach depends on the following gdbarch methods:
947 - gdbarch_max_insn_length and gdbarch_displaced_step_location
948 indicate where to copy the instruction, and how much space must
949 be reserved there. We use these in step n1.
951 - gdbarch_displaced_step_copy_insn copies a instruction to a new
952 address, and makes any necessary adjustments to the instruction,
953 register contents, and memory. We use this in step n1.
955 - gdbarch_displaced_step_fixup adjusts registers and memory after
956 we have successfuly single-stepped the instruction, to yield the
957 same effect the instruction would have had if we had executed it
958 at its original address. We use this in step n3.
960 - gdbarch_displaced_step_free_closure provides cleanup.
962 The gdbarch_displaced_step_copy_insn and
963 gdbarch_displaced_step_fixup functions must be written so that
964 copying an instruction with gdbarch_displaced_step_copy_insn,
965 single-stepping across the copied instruction, and then applying
966 gdbarch_displaced_insn_fixup should have the same effects on the
967 thread's memory and registers as stepping the instruction in place
968 would have. Exactly which responsibilities fall to the copy and
969 which fall to the fixup is up to the author of those functions.
971 See the comments in gdbarch.sh for details.
973 Note that displaced stepping and software single-step cannot
974 currently be used in combination, although with some care I think
975 they could be made to. Software single-step works by placing
976 breakpoints on all possible subsequent instructions; if the
977 displaced instruction is a PC-relative jump, those breakpoints
978 could fall in very strange places --- on pages that aren't
979 executable, or at addresses that are not proper instruction
980 boundaries. (We do generally let other threads run while we wait
981 to hit the software single-step breakpoint, and they might
982 encounter such a corrupted instruction.) One way to work around
983 this would be to have gdbarch_displaced_step_copy_insn fully
984 simulate the effect of PC-relative instructions (and return NULL)
985 on architectures that use software single-stepping.
987 In non-stop mode, we can have independent and simultaneous step
988 requests, so more than one thread may need to simultaneously step
989 over a breakpoint. The current implementation assumes there is
990 only one scratch space per process. In this case, we have to
991 serialize access to the scratch space. If thread A wants to step
992 over a breakpoint, but we are currently waiting for some other
993 thread to complete a displaced step, we leave thread A stopped and
994 place it in the displaced_step_request_queue. Whenever a displaced
995 step finishes, we pick the next thread in the queue and start a new
996 displaced step operation on it. See displaced_step_prepare and
997 displaced_step_fixup for details. */
999 struct displaced_step_request
1002 struct displaced_step_request *next;
1005 /* Per-inferior displaced stepping state. */
1006 struct displaced_step_inferior_state
1008 /* Pointer to next in linked list. */
1009 struct displaced_step_inferior_state *next;
1011 /* The process this displaced step state refers to. */
1014 /* A queue of pending displaced stepping requests. One entry per
1015 thread that needs to do a displaced step. */
1016 struct displaced_step_request *step_request_queue;
1018 /* If this is not null_ptid, this is the thread carrying out a
1019 displaced single-step in process PID. This thread's state will
1020 require fixing up once it has completed its step. */
1023 /* The architecture the thread had when we stepped it. */
1024 struct gdbarch *step_gdbarch;
1026 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1027 for post-step cleanup. */
1028 struct displaced_step_closure *step_closure;
1030 /* The address of the original instruction, and the copy we
1032 CORE_ADDR step_original, step_copy;
1034 /* Saved contents of copy area. */
1035 gdb_byte *step_saved_copy;
1038 /* The list of states of processes involved in displaced stepping
1040 static struct displaced_step_inferior_state *displaced_step_inferior_states;
1042 /* Get the displaced stepping state of process PID. */
1044 static struct displaced_step_inferior_state *
1045 get_displaced_stepping_state (int pid)
1047 struct displaced_step_inferior_state *state;
1049 for (state = displaced_step_inferior_states;
1051 state = state->next)
1052 if (state->pid == pid)
1058 /* Add a new displaced stepping state for process PID to the displaced
1059 stepping state list, or return a pointer to an already existing
1060 entry, if it already exists. Never returns NULL. */
1062 static struct displaced_step_inferior_state *
1063 add_displaced_stepping_state (int pid)
1065 struct displaced_step_inferior_state *state;
1067 for (state = displaced_step_inferior_states;
1069 state = state->next)
1070 if (state->pid == pid)
1073 state = xcalloc (1, sizeof (*state));
1075 state->next = displaced_step_inferior_states;
1076 displaced_step_inferior_states = state;
1081 /* Remove the displaced stepping state of process PID. */
1084 remove_displaced_stepping_state (int pid)
1086 struct displaced_step_inferior_state *it, **prev_next_p;
1088 gdb_assert (pid != 0);
1090 it = displaced_step_inferior_states;
1091 prev_next_p = &displaced_step_inferior_states;
1096 *prev_next_p = it->next;
1101 prev_next_p = &it->next;
1107 infrun_inferior_exit (struct inferior *inf)
1109 remove_displaced_stepping_state (inf->pid);
1112 /* Enum strings for "set|show displaced-stepping". */
1114 static const char can_use_displaced_stepping_auto[] = "auto";
1115 static const char can_use_displaced_stepping_on[] = "on";
1116 static const char can_use_displaced_stepping_off[] = "off";
1117 static const char *can_use_displaced_stepping_enum[] =
1119 can_use_displaced_stepping_auto,
1120 can_use_displaced_stepping_on,
1121 can_use_displaced_stepping_off,
1125 /* If ON, and the architecture supports it, GDB will use displaced
1126 stepping to step over breakpoints. If OFF, or if the architecture
1127 doesn't support it, GDB will instead use the traditional
1128 hold-and-step approach. If AUTO (which is the default), GDB will
1129 decide which technique to use to step over breakpoints depending on
1130 which of all-stop or non-stop mode is active --- displaced stepping
1131 in non-stop mode; hold-and-step in all-stop mode. */
1133 static const char *can_use_displaced_stepping =
1134 can_use_displaced_stepping_auto;
1137 show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
1138 struct cmd_list_element *c,
1141 if (can_use_displaced_stepping == can_use_displaced_stepping_auto)
1142 fprintf_filtered (file,
1143 _("Debugger's willingness to use displaced stepping "
1144 "to step over breakpoints is %s (currently %s).\n"),
1145 value, non_stop ? "on" : "off");
1147 fprintf_filtered (file,
1148 _("Debugger's willingness to use displaced stepping "
1149 "to step over breakpoints is %s.\n"), value);
1152 /* Return non-zero if displaced stepping can/should be used to step
1153 over breakpoints. */
1156 use_displaced_stepping (struct gdbarch *gdbarch)
1158 return (((can_use_displaced_stepping == can_use_displaced_stepping_auto
1160 || can_use_displaced_stepping == can_use_displaced_stepping_on)
1161 && gdbarch_displaced_step_copy_insn_p (gdbarch)
1162 && !RECORD_IS_USED);
1165 /* Clean out any stray displaced stepping state. */
1167 displaced_step_clear (struct displaced_step_inferior_state *displaced)
1169 /* Indicate that there is no cleanup pending. */
1170 displaced->step_ptid = null_ptid;
1172 if (displaced->step_closure)
1174 gdbarch_displaced_step_free_closure (displaced->step_gdbarch,
1175 displaced->step_closure);
1176 displaced->step_closure = NULL;
1181 displaced_step_clear_cleanup (void *arg)
1183 struct displaced_step_inferior_state *state = arg;
1185 displaced_step_clear (state);
1188 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1190 displaced_step_dump_bytes (struct ui_file *file,
1191 const gdb_byte *buf,
1196 for (i = 0; i < len; i++)
1197 fprintf_unfiltered (file, "%02x ", buf[i]);
1198 fputs_unfiltered ("\n", file);
1201 /* Prepare to single-step, using displaced stepping.
1203 Note that we cannot use displaced stepping when we have a signal to
1204 deliver. If we have a signal to deliver and an instruction to step
1205 over, then after the step, there will be no indication from the
1206 target whether the thread entered a signal handler or ignored the
1207 signal and stepped over the instruction successfully --- both cases
1208 result in a simple SIGTRAP. In the first case we mustn't do a
1209 fixup, and in the second case we must --- but we can't tell which.
1210 Comments in the code for 'random signals' in handle_inferior_event
1211 explain how we handle this case instead.
1213 Returns 1 if preparing was successful -- this thread is going to be
1214 stepped now; or 0 if displaced stepping this thread got queued. */
1216 displaced_step_prepare (ptid_t ptid)
1218 struct cleanup *old_cleanups, *ignore_cleanups;
1219 struct regcache *regcache = get_thread_regcache (ptid);
1220 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1221 CORE_ADDR original, copy;
1223 struct displaced_step_closure *closure;
1224 struct displaced_step_inferior_state *displaced;
1226 /* We should never reach this function if the architecture does not
1227 support displaced stepping. */
1228 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
1230 /* We have to displaced step one thread at a time, as we only have
1231 access to a single scratch space per inferior. */
1233 displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
1235 if (!ptid_equal (displaced->step_ptid, null_ptid))
1237 /* Already waiting for a displaced step to finish. Defer this
1238 request and place in queue. */
1239 struct displaced_step_request *req, *new_req;
1241 if (debug_displaced)
1242 fprintf_unfiltered (gdb_stdlog,
1243 "displaced: defering step of %s\n",
1244 target_pid_to_str (ptid));
1246 new_req = xmalloc (sizeof (*new_req));
1247 new_req->ptid = ptid;
1248 new_req->next = NULL;
1250 if (displaced->step_request_queue)
1252 for (req = displaced->step_request_queue;
1256 req->next = new_req;
1259 displaced->step_request_queue = new_req;
1265 if (debug_displaced)
1266 fprintf_unfiltered (gdb_stdlog,
1267 "displaced: stepping %s now\n",
1268 target_pid_to_str (ptid));
1271 displaced_step_clear (displaced);
1273 old_cleanups = save_inferior_ptid ();
1274 inferior_ptid = ptid;
1276 original = regcache_read_pc (regcache);
1278 copy = gdbarch_displaced_step_location (gdbarch);
1279 len = gdbarch_max_insn_length (gdbarch);
1281 /* Save the original contents of the copy area. */
1282 displaced->step_saved_copy = xmalloc (len);
1283 ignore_cleanups = make_cleanup (free_current_contents,
1284 &displaced->step_saved_copy);
1285 read_memory (copy, displaced->step_saved_copy, len);
1286 if (debug_displaced)
1288 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
1289 paddress (gdbarch, copy));
1290 displaced_step_dump_bytes (gdb_stdlog,
1291 displaced->step_saved_copy,
1295 closure = gdbarch_displaced_step_copy_insn (gdbarch,
1296 original, copy, regcache);
1298 /* We don't support the fully-simulated case at present. */
1299 gdb_assert (closure);
1301 /* Save the information we need to fix things up if the step
1303 displaced->step_ptid = ptid;
1304 displaced->step_gdbarch = gdbarch;
1305 displaced->step_closure = closure;
1306 displaced->step_original = original;
1307 displaced->step_copy = copy;
1309 make_cleanup (displaced_step_clear_cleanup, displaced);
1311 /* Resume execution at the copy. */
1312 regcache_write_pc (regcache, copy);
1314 discard_cleanups (ignore_cleanups);
1316 do_cleanups (old_cleanups);
1318 if (debug_displaced)
1319 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
1320 paddress (gdbarch, copy));
1326 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr,
1327 const gdb_byte *myaddr, int len)
1329 struct cleanup *ptid_cleanup = save_inferior_ptid ();
1331 inferior_ptid = ptid;
1332 write_memory (memaddr, myaddr, len);
1333 do_cleanups (ptid_cleanup);
1337 displaced_step_fixup (ptid_t event_ptid, enum target_signal signal)
1339 struct cleanup *old_cleanups;
1340 struct displaced_step_inferior_state *displaced
1341 = get_displaced_stepping_state (ptid_get_pid (event_ptid));
1343 /* Was any thread of this process doing a displaced step? */
1344 if (displaced == NULL)
1347 /* Was this event for the pid we displaced? */
1348 if (ptid_equal (displaced->step_ptid, null_ptid)
1349 || ! ptid_equal (displaced->step_ptid, event_ptid))
1352 old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
1354 /* Restore the contents of the copy area. */
1356 ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
1358 write_memory_ptid (displaced->step_ptid, displaced->step_copy,
1359 displaced->step_saved_copy, len);
1360 if (debug_displaced)
1361 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s\n",
1362 paddress (displaced->step_gdbarch,
1363 displaced->step_copy));
1366 /* Did the instruction complete successfully? */
1367 if (signal == TARGET_SIGNAL_TRAP)
1369 /* Fix up the resulting state. */
1370 gdbarch_displaced_step_fixup (displaced->step_gdbarch,
1371 displaced->step_closure,
1372 displaced->step_original,
1373 displaced->step_copy,
1374 get_thread_regcache (displaced->step_ptid));
1378 /* Since the instruction didn't complete, all we can do is
1380 struct regcache *regcache = get_thread_regcache (event_ptid);
1381 CORE_ADDR pc = regcache_read_pc (regcache);
1383 pc = displaced->step_original + (pc - displaced->step_copy);
1384 regcache_write_pc (regcache, pc);
1387 do_cleanups (old_cleanups);
1389 displaced->step_ptid = null_ptid;
1391 /* Are there any pending displaced stepping requests? If so, run
1392 one now. Leave the state object around, since we're likely to
1393 need it again soon. */
1394 while (displaced->step_request_queue)
1396 struct displaced_step_request *head;
1398 struct regcache *regcache;
1399 struct gdbarch *gdbarch;
1400 CORE_ADDR actual_pc;
1401 struct address_space *aspace;
1403 head = displaced->step_request_queue;
1405 displaced->step_request_queue = head->next;
1408 context_switch (ptid);
1410 regcache = get_thread_regcache (ptid);
1411 actual_pc = regcache_read_pc (regcache);
1412 aspace = get_regcache_aspace (regcache);
1414 if (breakpoint_here_p (aspace, actual_pc))
1416 if (debug_displaced)
1417 fprintf_unfiltered (gdb_stdlog,
1418 "displaced: stepping queued %s now\n",
1419 target_pid_to_str (ptid));
1421 displaced_step_prepare (ptid);
1423 gdbarch = get_regcache_arch (regcache);
1425 if (debug_displaced)
1427 CORE_ADDR actual_pc = regcache_read_pc (regcache);
1430 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1431 paddress (gdbarch, actual_pc));
1432 read_memory (actual_pc, buf, sizeof (buf));
1433 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1436 if (gdbarch_displaced_step_hw_singlestep (gdbarch,
1437 displaced->step_closure))
1438 target_resume (ptid, 1, TARGET_SIGNAL_0);
1440 target_resume (ptid, 0, TARGET_SIGNAL_0);
1442 /* Done, we're stepping a thread. */
1448 struct thread_info *tp = inferior_thread ();
1450 /* The breakpoint we were sitting under has since been
1452 tp->control.trap_expected = 0;
1454 /* Go back to what we were trying to do. */
1455 step = currently_stepping (tp);
1457 if (debug_displaced)
1458 fprintf_unfiltered (gdb_stdlog,
1459 "breakpoint is gone %s: step(%d)\n",
1460 target_pid_to_str (tp->ptid), step);
1462 target_resume (ptid, step, TARGET_SIGNAL_0);
1463 tp->suspend.stop_signal = TARGET_SIGNAL_0;
1465 /* This request was discarded. See if there's any other
1466 thread waiting for its turn. */
1471 /* Update global variables holding ptids to hold NEW_PTID if they were
1472 holding OLD_PTID. */
1474 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
1476 struct displaced_step_request *it;
1477 struct displaced_step_inferior_state *displaced;
1479 if (ptid_equal (inferior_ptid, old_ptid))
1480 inferior_ptid = new_ptid;
1482 if (ptid_equal (singlestep_ptid, old_ptid))
1483 singlestep_ptid = new_ptid;
1485 if (ptid_equal (deferred_step_ptid, old_ptid))
1486 deferred_step_ptid = new_ptid;
1488 for (displaced = displaced_step_inferior_states;
1490 displaced = displaced->next)
1492 if (ptid_equal (displaced->step_ptid, old_ptid))
1493 displaced->step_ptid = new_ptid;
1495 for (it = displaced->step_request_queue; it; it = it->next)
1496 if (ptid_equal (it->ptid, old_ptid))
1497 it->ptid = new_ptid;
1504 /* Things to clean up if we QUIT out of resume (). */
1506 resume_cleanups (void *ignore)
1511 static const char schedlock_off[] = "off";
1512 static const char schedlock_on[] = "on";
1513 static const char schedlock_step[] = "step";
1514 static const char *scheduler_enums[] = {
1520 static const char *scheduler_mode = schedlock_off;
1522 show_scheduler_mode (struct ui_file *file, int from_tty,
1523 struct cmd_list_element *c, const char *value)
1525 fprintf_filtered (file,
1526 _("Mode for locking scheduler "
1527 "during execution is \"%s\".\n"),
1532 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
1534 if (!target_can_lock_scheduler)
1536 scheduler_mode = schedlock_off;
1537 error (_("Target '%s' cannot support this command."), target_shortname);
1541 /* True if execution commands resume all threads of all processes by
1542 default; otherwise, resume only threads of the current inferior
1544 int sched_multi = 0;
1546 /* Try to setup for software single stepping over the specified location.
1547 Return 1 if target_resume() should use hardware single step.
1549 GDBARCH the current gdbarch.
1550 PC the location to step over. */
1553 maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
1557 if (execution_direction == EXEC_FORWARD
1558 && gdbarch_software_single_step_p (gdbarch)
1559 && gdbarch_software_single_step (gdbarch, get_current_frame ()))
1562 /* Do not pull these breakpoints until after a `wait' in
1563 `wait_for_inferior' */
1564 singlestep_breakpoints_inserted_p = 1;
1565 singlestep_ptid = inferior_ptid;
1571 /* Resume the inferior, but allow a QUIT. This is useful if the user
1572 wants to interrupt some lengthy single-stepping operation
1573 (for child processes, the SIGINT goes to the inferior, and so
1574 we get a SIGINT random_signal, but for remote debugging and perhaps
1575 other targets, that's not true).
1577 STEP nonzero if we should step (zero to continue instead).
1578 SIG is the signal to give the inferior (zero for none). */
1580 resume (int step, enum target_signal sig)
1582 int should_resume = 1;
1583 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
1584 struct regcache *regcache = get_current_regcache ();
1585 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1586 struct thread_info *tp = inferior_thread ();
1587 CORE_ADDR pc = regcache_read_pc (regcache);
1588 struct address_space *aspace = get_regcache_aspace (regcache);
1592 if (current_inferior ()->waiting_for_vfork_done)
1594 /* Don't try to single-step a vfork parent that is waiting for
1595 the child to get out of the shared memory region (by exec'ing
1596 or exiting). This is particularly important on software
1597 single-step archs, as the child process would trip on the
1598 software single step breakpoint inserted for the parent
1599 process. Since the parent will not actually execute any
1600 instruction until the child is out of the shared region (such
1601 are vfork's semantics), it is safe to simply continue it.
1602 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1603 the parent, and tell it to `keep_going', which automatically
1604 re-sets it stepping. */
1606 fprintf_unfiltered (gdb_stdlog,
1607 "infrun: resume : clear step\n");
1612 fprintf_unfiltered (gdb_stdlog,
1613 "infrun: resume (step=%d, signal=%d), "
1614 "trap_expected=%d\n",
1615 step, sig, tp->control.trap_expected);
1617 /* Normally, by the time we reach `resume', the breakpoints are either
1618 removed or inserted, as appropriate. The exception is if we're sitting
1619 at a permanent breakpoint; we need to step over it, but permanent
1620 breakpoints can't be removed. So we have to test for it here. */
1621 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
1623 if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
1624 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
1626 error (_("The program is stopped at a permanent "
1627 "breakpoint, but GDB does not know\n"
1628 "how to step past a permanent breakpoint "
1629 "on this architecture. Try using\na command "
1630 "like `return' or `jump' to continue execution."));
1633 /* If enabled, step over breakpoints by executing a copy of the
1634 instruction at a different address.
1636 We can't use displaced stepping when we have a signal to deliver;
1637 the comments for displaced_step_prepare explain why. The
1638 comments in the handle_inferior event for dealing with 'random
1639 signals' explain what we do instead.
1641 We can't use displaced stepping when we are waiting for vfork_done
1642 event, displaced stepping breaks the vfork child similarly as single
1643 step software breakpoint. */
1644 if (use_displaced_stepping (gdbarch)
1645 && (tp->control.trap_expected
1646 || (step && gdbarch_software_single_step_p (gdbarch)))
1647 && sig == TARGET_SIGNAL_0
1648 && !current_inferior ()->waiting_for_vfork_done)
1650 struct displaced_step_inferior_state *displaced;
1652 if (!displaced_step_prepare (inferior_ptid))
1654 /* Got placed in displaced stepping queue. Will be resumed
1655 later when all the currently queued displaced stepping
1656 requests finish. The thread is not executing at this point,
1657 and the call to set_executing will be made later. But we
1658 need to call set_running here, since from frontend point of view,
1659 the thread is running. */
1660 set_running (inferior_ptid, 1);
1661 discard_cleanups (old_cleanups);
1665 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1666 step = gdbarch_displaced_step_hw_singlestep (gdbarch,
1667 displaced->step_closure);
1670 /* Do we need to do it the hard way, w/temp breakpoints? */
1672 step = maybe_software_singlestep (gdbarch, pc);
1678 /* If STEP is set, it's a request to use hardware stepping
1679 facilities. But in that case, we should never
1680 use singlestep breakpoint. */
1681 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
1683 /* Decide the set of threads to ask the target to resume. Start
1684 by assuming everything will be resumed, than narrow the set
1685 by applying increasingly restricting conditions. */
1687 /* By default, resume all threads of all processes. */
1688 resume_ptid = RESUME_ALL;
1690 /* Maybe resume only all threads of the current process. */
1691 if (!sched_multi && target_supports_multi_process ())
1693 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
1696 /* Maybe resume a single thread after all. */
1697 if (singlestep_breakpoints_inserted_p
1698 && stepping_past_singlestep_breakpoint)
1700 /* The situation here is as follows. In thread T1 we wanted to
1701 single-step. Lacking hardware single-stepping we've
1702 set breakpoint at the PC of the next instruction -- call it
1703 P. After resuming, we've hit that breakpoint in thread T2.
1704 Now we've removed original breakpoint, inserted breakpoint
1705 at P+1, and try to step to advance T2 past breakpoint.
1706 We need to step only T2, as if T1 is allowed to freely run,
1707 it can run past P, and if other threads are allowed to run,
1708 they can hit breakpoint at P+1, and nested hits of single-step
1709 breakpoints is not something we'd want -- that's complicated
1710 to support, and has no value. */
1711 resume_ptid = inferior_ptid;
1713 else if ((step || singlestep_breakpoints_inserted_p)
1714 && tp->control.trap_expected)
1716 /* We're allowing a thread to run past a breakpoint it has
1717 hit, by single-stepping the thread with the breakpoint
1718 removed. In which case, we need to single-step only this
1719 thread, and keep others stopped, as they can miss this
1720 breakpoint if allowed to run.
1722 The current code actually removes all breakpoints when
1723 doing this, not just the one being stepped over, so if we
1724 let other threads run, we can actually miss any
1725 breakpoint, not just the one at PC. */
1726 resume_ptid = inferior_ptid;
1730 /* With non-stop mode on, threads are always handled
1732 resume_ptid = inferior_ptid;
1734 else if ((scheduler_mode == schedlock_on)
1735 || (scheduler_mode == schedlock_step
1736 && (step || singlestep_breakpoints_inserted_p)))
1738 /* User-settable 'scheduler' mode requires solo thread resume. */
1739 resume_ptid = inferior_ptid;
1742 if (gdbarch_cannot_step_breakpoint (gdbarch))
1744 /* Most targets can step a breakpoint instruction, thus
1745 executing it normally. But if this one cannot, just
1746 continue and we will hit it anyway. */
1747 if (step && breakpoint_inserted_here_p (aspace, pc))
1752 && use_displaced_stepping (gdbarch)
1753 && tp->control.trap_expected)
1755 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
1756 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
1757 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
1760 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1761 paddress (resume_gdbarch, actual_pc));
1762 read_memory (actual_pc, buf, sizeof (buf));
1763 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1766 /* Install inferior's terminal modes. */
1767 target_terminal_inferior ();
1769 /* Avoid confusing the next resume, if the next stop/resume
1770 happens to apply to another thread. */
1771 tp->suspend.stop_signal = TARGET_SIGNAL_0;
1773 target_resume (resume_ptid, step, sig);
1776 discard_cleanups (old_cleanups);
1781 /* Clear out all variables saying what to do when inferior is continued.
1782 First do this, then set the ones you want, then call `proceed'. */
1785 clear_proceed_status_thread (struct thread_info *tp)
1788 fprintf_unfiltered (gdb_stdlog,
1789 "infrun: clear_proceed_status_thread (%s)\n",
1790 target_pid_to_str (tp->ptid));
1792 tp->control.trap_expected = 0;
1793 tp->control.step_range_start = 0;
1794 tp->control.step_range_end = 0;
1795 tp->control.step_frame_id = null_frame_id;
1796 tp->control.step_stack_frame_id = null_frame_id;
1797 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
1798 tp->stop_requested = 0;
1800 tp->control.stop_step = 0;
1802 tp->control.proceed_to_finish = 0;
1804 /* Discard any remaining commands or status from previous stop. */
1805 bpstat_clear (&tp->control.stop_bpstat);
1809 clear_proceed_status_callback (struct thread_info *tp, void *data)
1811 if (is_exited (tp->ptid))
1814 clear_proceed_status_thread (tp);
1819 clear_proceed_status (void)
1823 /* In all-stop mode, delete the per-thread status of all
1824 threads, even if inferior_ptid is null_ptid, there may be
1825 threads on the list. E.g., we may be launching a new
1826 process, while selecting the executable. */
1827 iterate_over_threads (clear_proceed_status_callback, NULL);
1830 if (!ptid_equal (inferior_ptid, null_ptid))
1832 struct inferior *inferior;
1836 /* If in non-stop mode, only delete the per-thread status of
1837 the current thread. */
1838 clear_proceed_status_thread (inferior_thread ());
1841 inferior = current_inferior ();
1842 inferior->control.stop_soon = NO_STOP_QUIETLY;
1845 stop_after_trap = 0;
1847 observer_notify_about_to_proceed ();
1851 regcache_xfree (stop_registers);
1852 stop_registers = NULL;
1856 /* Check the current thread against the thread that reported the most recent
1857 event. If a step-over is required return TRUE and set the current thread
1858 to the old thread. Otherwise return FALSE.
1860 This should be suitable for any targets that support threads. */
1863 prepare_to_proceed (int step)
1866 struct target_waitstatus wait_status;
1867 int schedlock_enabled;
1869 /* With non-stop mode on, threads are always handled individually. */
1870 gdb_assert (! non_stop);
1872 /* Get the last target status returned by target_wait(). */
1873 get_last_target_status (&wait_ptid, &wait_status);
1875 /* Make sure we were stopped at a breakpoint. */
1876 if (wait_status.kind != TARGET_WAITKIND_STOPPED
1877 || (wait_status.value.sig != TARGET_SIGNAL_TRAP
1878 && wait_status.value.sig != TARGET_SIGNAL_ILL
1879 && wait_status.value.sig != TARGET_SIGNAL_SEGV
1880 && wait_status.value.sig != TARGET_SIGNAL_EMT))
1885 schedlock_enabled = (scheduler_mode == schedlock_on
1886 || (scheduler_mode == schedlock_step
1889 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
1890 if (schedlock_enabled)
1893 /* Don't switch over if we're about to resume some other process
1894 other than WAIT_PTID's, and schedule-multiple is off. */
1896 && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid))
1899 /* Switched over from WAIT_PID. */
1900 if (!ptid_equal (wait_ptid, minus_one_ptid)
1901 && !ptid_equal (inferior_ptid, wait_ptid))
1903 struct regcache *regcache = get_thread_regcache (wait_ptid);
1905 if (breakpoint_here_p (get_regcache_aspace (regcache),
1906 regcache_read_pc (regcache)))
1908 /* If stepping, remember current thread to switch back to. */
1910 deferred_step_ptid = inferior_ptid;
1912 /* Switch back to WAIT_PID thread. */
1913 switch_to_thread (wait_ptid);
1915 /* We return 1 to indicate that there is a breakpoint here,
1916 so we need to step over it before continuing to avoid
1917 hitting it straight away. */
1925 /* Basic routine for continuing the program in various fashions.
1927 ADDR is the address to resume at, or -1 for resume where stopped.
1928 SIGGNAL is the signal to give it, or 0 for none,
1929 or -1 for act according to how it stopped.
1930 STEP is nonzero if should trap after one instruction.
1931 -1 means return after that and print nothing.
1932 You should probably set various step_... variables
1933 before calling here, if you are stepping.
1935 You should call clear_proceed_status before calling proceed. */
1938 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
1940 struct regcache *regcache;
1941 struct gdbarch *gdbarch;
1942 struct thread_info *tp;
1944 struct address_space *aspace;
1947 /* If we're stopped at a fork/vfork, follow the branch set by the
1948 "set follow-fork-mode" command; otherwise, we'll just proceed
1949 resuming the current thread. */
1950 if (!follow_fork ())
1952 /* The target for some reason decided not to resume. */
1957 regcache = get_current_regcache ();
1958 gdbarch = get_regcache_arch (regcache);
1959 aspace = get_regcache_aspace (regcache);
1960 pc = regcache_read_pc (regcache);
1963 step_start_function = find_pc_function (pc);
1965 stop_after_trap = 1;
1967 if (addr == (CORE_ADDR) -1)
1969 if (pc == stop_pc && breakpoint_here_p (aspace, pc)
1970 && execution_direction != EXEC_REVERSE)
1971 /* There is a breakpoint at the address we will resume at,
1972 step one instruction before inserting breakpoints so that
1973 we do not stop right away (and report a second hit at this
1976 Note, we don't do this in reverse, because we won't
1977 actually be executing the breakpoint insn anyway.
1978 We'll be (un-)executing the previous instruction. */
1981 else if (gdbarch_single_step_through_delay_p (gdbarch)
1982 && gdbarch_single_step_through_delay (gdbarch,
1983 get_current_frame ()))
1984 /* We stepped onto an instruction that needs to be stepped
1985 again before re-inserting the breakpoint, do so. */
1990 regcache_write_pc (regcache, addr);
1994 fprintf_unfiltered (gdb_stdlog,
1995 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
1996 paddress (gdbarch, addr), siggnal, step);
1998 /* We're handling a live event, so make sure we're doing live
1999 debugging. If we're looking at traceframes while the target is
2000 running, we're going to need to get back to that mode after
2001 handling the event. */
2004 make_cleanup_restore_current_traceframe ();
2005 set_traceframe_number (-1);
2009 /* In non-stop, each thread is handled individually. The context
2010 must already be set to the right thread here. */
2014 /* In a multi-threaded task we may select another thread and
2015 then continue or step.
2017 But if the old thread was stopped at a breakpoint, it will
2018 immediately cause another breakpoint stop without any
2019 execution (i.e. it will report a breakpoint hit incorrectly).
2020 So we must step over it first.
2022 prepare_to_proceed checks the current thread against the
2023 thread that reported the most recent event. If a step-over
2024 is required it returns TRUE and sets the current thread to
2026 if (prepare_to_proceed (step))
2030 /* prepare_to_proceed may change the current thread. */
2031 tp = inferior_thread ();
2035 tp->control.trap_expected = 1;
2036 /* If displaced stepping is enabled, we can step over the
2037 breakpoint without hitting it, so leave all breakpoints
2038 inserted. Otherwise we need to disable all breakpoints, step
2039 one instruction, and then re-add them when that step is
2041 if (!use_displaced_stepping (gdbarch))
2042 remove_breakpoints ();
2045 /* We can insert breakpoints if we're not trying to step over one,
2046 or if we are stepping over one but we're using displaced stepping
2048 if (! tp->control.trap_expected || use_displaced_stepping (gdbarch))
2049 insert_breakpoints ();
2053 /* Pass the last stop signal to the thread we're resuming,
2054 irrespective of whether the current thread is the thread that
2055 got the last event or not. This was historically GDB's
2056 behaviour before keeping a stop_signal per thread. */
2058 struct thread_info *last_thread;
2060 struct target_waitstatus last_status;
2062 get_last_target_status (&last_ptid, &last_status);
2063 if (!ptid_equal (inferior_ptid, last_ptid)
2064 && !ptid_equal (last_ptid, null_ptid)
2065 && !ptid_equal (last_ptid, minus_one_ptid))
2067 last_thread = find_thread_ptid (last_ptid);
2070 tp->suspend.stop_signal = last_thread->suspend.stop_signal;
2071 last_thread->suspend.stop_signal = TARGET_SIGNAL_0;
2076 if (siggnal != TARGET_SIGNAL_DEFAULT)
2077 tp->suspend.stop_signal = siggnal;
2078 /* If this signal should not be seen by program,
2079 give it zero. Used for debugging signals. */
2080 else if (!signal_program[tp->suspend.stop_signal])
2081 tp->suspend.stop_signal = TARGET_SIGNAL_0;
2083 annotate_starting ();
2085 /* Make sure that output from GDB appears before output from the
2087 gdb_flush (gdb_stdout);
2089 /* Refresh prev_pc value just prior to resuming. This used to be
2090 done in stop_stepping, however, setting prev_pc there did not handle
2091 scenarios such as inferior function calls or returning from
2092 a function via the return command. In those cases, the prev_pc
2093 value was not set properly for subsequent commands. The prev_pc value
2094 is used to initialize the starting line number in the ecs. With an
2095 invalid value, the gdb next command ends up stopping at the position
2096 represented by the next line table entry past our start position.
2097 On platforms that generate one line table entry per line, this
2098 is not a problem. However, on the ia64, the compiler generates
2099 extraneous line table entries that do not increase the line number.
2100 When we issue the gdb next command on the ia64 after an inferior call
2101 or a return command, we often end up a few instructions forward, still
2102 within the original line we started.
2104 An attempt was made to refresh the prev_pc at the same time the
2105 execution_control_state is initialized (for instance, just before
2106 waiting for an inferior event). But this approach did not work
2107 because of platforms that use ptrace, where the pc register cannot
2108 be read unless the inferior is stopped. At that point, we are not
2109 guaranteed the inferior is stopped and so the regcache_read_pc() call
2110 can fail. Setting the prev_pc value here ensures the value is updated
2111 correctly when the inferior is stopped. */
2112 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2114 /* Fill in with reasonable starting values. */
2115 init_thread_stepping_state (tp);
2117 /* Reset to normal state. */
2118 init_infwait_state ();
2120 /* Resume inferior. */
2121 resume (oneproc || step || bpstat_should_step (), tp->suspend.stop_signal);
2123 /* Wait for it to stop (if not standalone)
2124 and in any case decode why it stopped, and act accordingly. */
2125 /* Do this only if we are not using the event loop, or if the target
2126 does not support asynchronous execution. */
2127 if (!target_can_async_p ())
2129 wait_for_inferior (0);
2135 /* Start remote-debugging of a machine over a serial link. */
2138 start_remote (int from_tty)
2140 struct inferior *inferior;
2142 init_wait_for_inferior ();
2143 inferior = current_inferior ();
2144 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2146 /* Always go on waiting for the target, regardless of the mode. */
2147 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2148 indicate to wait_for_inferior that a target should timeout if
2149 nothing is returned (instead of just blocking). Because of this,
2150 targets expecting an immediate response need to, internally, set
2151 things up so that the target_wait() is forced to eventually
2153 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2154 differentiate to its caller what the state of the target is after
2155 the initial open has been performed. Here we're assuming that
2156 the target has stopped. It should be possible to eventually have
2157 target_open() return to the caller an indication that the target
2158 is currently running and GDB state should be set to the same as
2159 for an async run. */
2160 wait_for_inferior (0);
2162 /* Now that the inferior has stopped, do any bookkeeping like
2163 loading shared libraries. We want to do this before normal_stop,
2164 so that the displayed frame is up to date. */
2165 post_create_inferior (¤t_target, from_tty);
2170 /* Initialize static vars when a new inferior begins. */
2173 init_wait_for_inferior (void)
2175 /* These are meaningless until the first time through wait_for_inferior. */
2177 breakpoint_init_inferior (inf_starting);
2179 clear_proceed_status ();
2181 stepping_past_singlestep_breakpoint = 0;
2182 deferred_step_ptid = null_ptid;
2184 target_last_wait_ptid = minus_one_ptid;
2186 previous_inferior_ptid = null_ptid;
2187 init_infwait_state ();
2189 /* Discard any skipped inlined frames. */
2190 clear_inline_frame_state (minus_one_ptid);
2194 /* This enum encodes possible reasons for doing a target_wait, so that
2195 wfi can call target_wait in one place. (Ultimately the call will be
2196 moved out of the infinite loop entirely.) */
2200 infwait_normal_state,
2201 infwait_thread_hop_state,
2202 infwait_step_watch_state,
2203 infwait_nonstep_watch_state
2206 /* The PTID we'll do a target_wait on.*/
2209 /* Current inferior wait state. */
2210 enum infwait_states infwait_state;
2212 /* Data to be passed around while handling an event. This data is
2213 discarded between events. */
2214 struct execution_control_state
2217 /* The thread that got the event, if this was a thread event; NULL
2219 struct thread_info *event_thread;
2221 struct target_waitstatus ws;
2223 CORE_ADDR stop_func_start;
2224 CORE_ADDR stop_func_end;
2225 char *stop_func_name;
2226 int new_thread_event;
2230 static void handle_inferior_event (struct execution_control_state *ecs);
2232 static void handle_step_into_function (struct gdbarch *gdbarch,
2233 struct execution_control_state *ecs);
2234 static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2235 struct execution_control_state *ecs);
2236 static void insert_step_resume_breakpoint_at_frame (struct frame_info *);
2237 static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
2238 static void insert_step_resume_breakpoint_at_sal (struct gdbarch *,
2239 struct symtab_and_line ,
2241 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
2242 static void check_exception_resume (struct execution_control_state *,
2243 struct frame_info *, struct symbol *);
2245 static void stop_stepping (struct execution_control_state *ecs);
2246 static void prepare_to_wait (struct execution_control_state *ecs);
2247 static void keep_going (struct execution_control_state *ecs);
2249 /* Callback for iterate over threads. If the thread is stopped, but
2250 the user/frontend doesn't know about that yet, go through
2251 normal_stop, as if the thread had just stopped now. ARG points at
2252 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2253 ptid_is_pid(PTID) is true, applies to all threads of the process
2254 pointed at by PTID. Otherwise, apply only to the thread pointed by
2258 infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2260 ptid_t ptid = * (ptid_t *) arg;
2262 if ((ptid_equal (info->ptid, ptid)
2263 || ptid_equal (minus_one_ptid, ptid)
2264 || (ptid_is_pid (ptid)
2265 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2266 && is_running (info->ptid)
2267 && !is_executing (info->ptid))
2269 struct cleanup *old_chain;
2270 struct execution_control_state ecss;
2271 struct execution_control_state *ecs = &ecss;
2273 memset (ecs, 0, sizeof (*ecs));
2275 old_chain = make_cleanup_restore_current_thread ();
2277 switch_to_thread (info->ptid);
2279 /* Go through handle_inferior_event/normal_stop, so we always
2280 have consistent output as if the stop event had been
2282 ecs->ptid = info->ptid;
2283 ecs->event_thread = find_thread_ptid (info->ptid);
2284 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2285 ecs->ws.value.sig = TARGET_SIGNAL_0;
2287 handle_inferior_event (ecs);
2289 if (!ecs->wait_some_more)
2291 struct thread_info *tp;
2295 /* Finish off the continuations. The continations
2296 themselves are responsible for realising the thread
2297 didn't finish what it was supposed to do. */
2298 tp = inferior_thread ();
2299 do_all_intermediate_continuations_thread (tp);
2300 do_all_continuations_thread (tp);
2303 do_cleanups (old_chain);
2309 /* This function is attached as a "thread_stop_requested" observer.
2310 Cleanup local state that assumed the PTID was to be resumed, and
2311 report the stop to the frontend. */
2314 infrun_thread_stop_requested (ptid_t ptid)
2316 struct displaced_step_inferior_state *displaced;
2318 /* PTID was requested to stop. Remove it from the displaced
2319 stepping queue, so we don't try to resume it automatically. */
2321 for (displaced = displaced_step_inferior_states;
2323 displaced = displaced->next)
2325 struct displaced_step_request *it, **prev_next_p;
2327 it = displaced->step_request_queue;
2328 prev_next_p = &displaced->step_request_queue;
2331 if (ptid_match (it->ptid, ptid))
2333 *prev_next_p = it->next;
2339 prev_next_p = &it->next;
2346 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2350 infrun_thread_thread_exit (struct thread_info *tp, int silent)
2352 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2353 nullify_last_target_wait_ptid ();
2356 /* Callback for iterate_over_threads. */
2359 delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
2361 if (is_exited (info->ptid))
2364 delete_step_resume_breakpoint (info);
2365 delete_exception_resume_breakpoint (info);
2369 /* In all-stop, delete the step resume breakpoint of any thread that
2370 had one. In non-stop, delete the step resume breakpoint of the
2371 thread that just stopped. */
2374 delete_step_thread_step_resume_breakpoint (void)
2376 if (!target_has_execution
2377 || ptid_equal (inferior_ptid, null_ptid))
2378 /* If the inferior has exited, we have already deleted the step
2379 resume breakpoints out of GDB's lists. */
2384 /* If in non-stop mode, only delete the step-resume or
2385 longjmp-resume breakpoint of the thread that just stopped
2387 struct thread_info *tp = inferior_thread ();
2389 delete_step_resume_breakpoint (tp);
2390 delete_exception_resume_breakpoint (tp);
2393 /* In all-stop mode, delete all step-resume and longjmp-resume
2394 breakpoints of any thread that had them. */
2395 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
2398 /* A cleanup wrapper. */
2401 delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
2403 delete_step_thread_step_resume_breakpoint ();
2406 /* Pretty print the results of target_wait, for debugging purposes. */
2409 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
2410 const struct target_waitstatus *ws)
2412 char *status_string = target_waitstatus_to_string (ws);
2413 struct ui_file *tmp_stream = mem_fileopen ();
2416 /* The text is split over several lines because it was getting too long.
2417 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2418 output as a unit; we want only one timestamp printed if debug_timestamp
2421 fprintf_unfiltered (tmp_stream,
2422 "infrun: target_wait (%d", PIDGET (waiton_ptid));
2423 if (PIDGET (waiton_ptid) != -1)
2424 fprintf_unfiltered (tmp_stream,
2425 " [%s]", target_pid_to_str (waiton_ptid));
2426 fprintf_unfiltered (tmp_stream, ", status) =\n");
2427 fprintf_unfiltered (tmp_stream,
2428 "infrun: %d [%s],\n",
2429 PIDGET (result_ptid), target_pid_to_str (result_ptid));
2430 fprintf_unfiltered (tmp_stream,
2434 text = ui_file_xstrdup (tmp_stream, NULL);
2436 /* This uses %s in part to handle %'s in the text, but also to avoid
2437 a gcc error: the format attribute requires a string literal. */
2438 fprintf_unfiltered (gdb_stdlog, "%s", text);
2440 xfree (status_string);
2442 ui_file_delete (tmp_stream);
2445 /* Prepare and stabilize the inferior for detaching it. E.g.,
2446 detaching while a thread is displaced stepping is a recipe for
2447 crashing it, as nothing would readjust the PC out of the scratch
2451 prepare_for_detach (void)
2453 struct inferior *inf = current_inferior ();
2454 ptid_t pid_ptid = pid_to_ptid (inf->pid);
2455 struct cleanup *old_chain_1;
2456 struct displaced_step_inferior_state *displaced;
2458 displaced = get_displaced_stepping_state (inf->pid);
2460 /* Is any thread of this process displaced stepping? If not,
2461 there's nothing else to do. */
2462 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
2466 fprintf_unfiltered (gdb_stdlog,
2467 "displaced-stepping in-process while detaching");
2469 old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
2472 while (!ptid_equal (displaced->step_ptid, null_ptid))
2474 struct cleanup *old_chain_2;
2475 struct execution_control_state ecss;
2476 struct execution_control_state *ecs;
2479 memset (ecs, 0, sizeof (*ecs));
2481 overlay_cache_invalid = 1;
2483 /* We have to invalidate the registers BEFORE calling
2484 target_wait because they can be loaded from the target while
2485 in target_wait. This makes remote debugging a bit more
2486 efficient for those targets that provide critical registers
2487 as part of their normal status mechanism. */
2489 registers_changed ();
2491 if (deprecated_target_wait_hook)
2492 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
2494 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
2497 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
2499 /* If an error happens while handling the event, propagate GDB's
2500 knowledge of the executing state to the frontend/user running
2502 old_chain_2 = make_cleanup (finish_thread_state_cleanup,
2505 /* In non-stop mode, each thread is handled individually.
2506 Switch early, so the global state is set correctly for this
2509 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2510 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2511 context_switch (ecs->ptid);
2513 /* Now figure out what to do with the result of the result. */
2514 handle_inferior_event (ecs);
2516 /* No error, don't finish the state yet. */
2517 discard_cleanups (old_chain_2);
2519 /* Breakpoints and watchpoints are not installed on the target
2520 at this point, and signals are passed directly to the
2521 inferior, so this must mean the process is gone. */
2522 if (!ecs->wait_some_more)
2524 discard_cleanups (old_chain_1);
2525 error (_("Program exited while detaching"));
2529 discard_cleanups (old_chain_1);
2532 /* Wait for control to return from inferior to debugger.
2534 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
2535 as if they were SIGTRAP signals. This can be useful during
2536 the startup sequence on some targets such as HP/UX, where
2537 we receive an EXEC event instead of the expected SIGTRAP.
2539 If inferior gets a signal, we may decide to start it up again
2540 instead of returning. That is why there is a loop in this function.
2541 When this function actually returns it means the inferior
2542 should be left stopped and GDB should read more commands. */
2545 wait_for_inferior (int treat_exec_as_sigtrap)
2547 struct cleanup *old_cleanups;
2548 struct execution_control_state ecss;
2549 struct execution_control_state *ecs;
2553 (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
2554 treat_exec_as_sigtrap);
2557 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
2560 memset (ecs, 0, sizeof (*ecs));
2562 /* We'll update this if & when we switch to a new thread. */
2563 previous_inferior_ptid = inferior_ptid;
2567 struct cleanup *old_chain;
2569 /* We have to invalidate the registers BEFORE calling target_wait
2570 because they can be loaded from the target while in target_wait.
2571 This makes remote debugging a bit more efficient for those
2572 targets that provide critical registers as part of their normal
2573 status mechanism. */
2575 overlay_cache_invalid = 1;
2576 registers_changed ();
2578 if (deprecated_target_wait_hook)
2579 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
2581 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
2584 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2586 if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD)
2588 xfree (ecs->ws.value.execd_pathname);
2589 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2590 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
2593 /* If an error happens while handling the event, propagate GDB's
2594 knowledge of the executing state to the frontend/user running
2596 old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2598 if (ecs->ws.kind == TARGET_WAITKIND_SYSCALL_ENTRY
2599 || ecs->ws.kind == TARGET_WAITKIND_SYSCALL_RETURN)
2600 ecs->ws.value.syscall_number = UNKNOWN_SYSCALL;
2602 /* Now figure out what to do with the result of the result. */
2603 handle_inferior_event (ecs);
2605 /* No error, don't finish the state yet. */
2606 discard_cleanups (old_chain);
2608 if (!ecs->wait_some_more)
2612 do_cleanups (old_cleanups);
2615 /* Asynchronous version of wait_for_inferior. It is called by the
2616 event loop whenever a change of state is detected on the file
2617 descriptor corresponding to the target. It can be called more than
2618 once to complete a single execution command. In such cases we need
2619 to keep the state in a global variable ECSS. If it is the last time
2620 that this function is called for a single execution command, then
2621 report to the user that the inferior has stopped, and do the
2622 necessary cleanups. */
2625 fetch_inferior_event (void *client_data)
2627 struct execution_control_state ecss;
2628 struct execution_control_state *ecs = &ecss;
2629 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
2630 struct cleanup *ts_old_chain;
2631 int was_sync = sync_execution;
2633 memset (ecs, 0, sizeof (*ecs));
2635 /* We'll update this if & when we switch to a new thread. */
2636 previous_inferior_ptid = inferior_ptid;
2639 /* In non-stop mode, the user/frontend should not notice a thread
2640 switch due to internal events. Make sure we reverse to the
2641 user selected thread and frame after handling the event and
2642 running any breakpoint commands. */
2643 make_cleanup_restore_current_thread ();
2645 /* We have to invalidate the registers BEFORE calling target_wait
2646 because they can be loaded from the target while in target_wait.
2647 This makes remote debugging a bit more efficient for those
2648 targets that provide critical registers as part of their normal
2649 status mechanism. */
2651 overlay_cache_invalid = 1;
2652 registers_changed ();
2654 if (deprecated_target_wait_hook)
2656 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2658 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2661 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2664 && ecs->ws.kind != TARGET_WAITKIND_IGNORE
2665 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2666 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2667 /* In non-stop mode, each thread is handled individually. Switch
2668 early, so the global state is set correctly for this
2670 context_switch (ecs->ptid);
2672 /* If an error happens while handling the event, propagate GDB's
2673 knowledge of the executing state to the frontend/user running
2676 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2678 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
2680 /* Now figure out what to do with the result of the result. */
2681 handle_inferior_event (ecs);
2683 if (!ecs->wait_some_more)
2685 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2687 delete_step_thread_step_resume_breakpoint ();
2689 /* We may not find an inferior if this was a process exit. */
2690 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
2693 if (target_has_execution
2694 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2695 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2696 && ecs->event_thread->step_multi
2697 && ecs->event_thread->control.stop_step)
2698 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
2700 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2703 /* No error, don't finish the thread states yet. */
2704 discard_cleanups (ts_old_chain);
2706 /* Revert thread and frame. */
2707 do_cleanups (old_chain);
2709 /* If the inferior was in sync execution mode, and now isn't,
2710 restore the prompt. */
2711 if (was_sync && !sync_execution)
2712 display_gdb_prompt (0);
2715 /* Record the frame and location we're currently stepping through. */
2717 set_step_info (struct frame_info *frame, struct symtab_and_line sal)
2719 struct thread_info *tp = inferior_thread ();
2721 tp->control.step_frame_id = get_frame_id (frame);
2722 tp->control.step_stack_frame_id = get_stack_frame_id (frame);
2724 tp->current_symtab = sal.symtab;
2725 tp->current_line = sal.line;
2728 /* Clear context switchable stepping state. */
2731 init_thread_stepping_state (struct thread_info *tss)
2733 tss->stepping_over_breakpoint = 0;
2734 tss->step_after_step_resume_breakpoint = 0;
2735 tss->stepping_through_solib_after_catch = 0;
2736 tss->stepping_through_solib_catchpoints = NULL;
2739 /* Return the cached copy of the last pid/waitstatus returned by
2740 target_wait()/deprecated_target_wait_hook(). The data is actually
2741 cached by handle_inferior_event(), which gets called immediately
2742 after target_wait()/deprecated_target_wait_hook(). */
2745 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
2747 *ptidp = target_last_wait_ptid;
2748 *status = target_last_waitstatus;
2752 nullify_last_target_wait_ptid (void)
2754 target_last_wait_ptid = minus_one_ptid;
2757 /* Switch thread contexts. */
2760 context_switch (ptid_t ptid)
2764 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
2765 target_pid_to_str (inferior_ptid));
2766 fprintf_unfiltered (gdb_stdlog, "to %s\n",
2767 target_pid_to_str (ptid));
2770 switch_to_thread (ptid);
2774 adjust_pc_after_break (struct execution_control_state *ecs)
2776 struct regcache *regcache;
2777 struct gdbarch *gdbarch;
2778 struct address_space *aspace;
2779 CORE_ADDR breakpoint_pc;
2781 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2782 we aren't, just return.
2784 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2785 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2786 implemented by software breakpoints should be handled through the normal
2789 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2790 different signals (SIGILL or SIGEMT for instance), but it is less
2791 clear where the PC is pointing afterwards. It may not match
2792 gdbarch_decr_pc_after_break. I don't know any specific target that
2793 generates these signals at breakpoints (the code has been in GDB since at
2794 least 1992) so I can not guess how to handle them here.
2796 In earlier versions of GDB, a target with
2797 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2798 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2799 target with both of these set in GDB history, and it seems unlikely to be
2800 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2802 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
2805 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
2808 /* In reverse execution, when a breakpoint is hit, the instruction
2809 under it has already been de-executed. The reported PC always
2810 points at the breakpoint address, so adjusting it further would
2811 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2814 B1 0x08000000 : INSN1
2815 B2 0x08000001 : INSN2
2817 PC -> 0x08000003 : INSN4
2819 Say you're stopped at 0x08000003 as above. Reverse continuing
2820 from that point should hit B2 as below. Reading the PC when the
2821 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2822 been de-executed already.
2824 B1 0x08000000 : INSN1
2825 B2 PC -> 0x08000001 : INSN2
2829 We can't apply the same logic as for forward execution, because
2830 we would wrongly adjust the PC to 0x08000000, since there's a
2831 breakpoint at PC - 1. We'd then report a hit on B1, although
2832 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2834 if (execution_direction == EXEC_REVERSE)
2837 /* If this target does not decrement the PC after breakpoints, then
2838 we have nothing to do. */
2839 regcache = get_thread_regcache (ecs->ptid);
2840 gdbarch = get_regcache_arch (regcache);
2841 if (gdbarch_decr_pc_after_break (gdbarch) == 0)
2844 aspace = get_regcache_aspace (regcache);
2846 /* Find the location where (if we've hit a breakpoint) the
2847 breakpoint would be. */
2848 breakpoint_pc = regcache_read_pc (regcache)
2849 - gdbarch_decr_pc_after_break (gdbarch);
2851 /* Check whether there actually is a software breakpoint inserted at
2854 If in non-stop mode, a race condition is possible where we've
2855 removed a breakpoint, but stop events for that breakpoint were
2856 already queued and arrive later. To suppress those spurious
2857 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2858 and retire them after a number of stop events are reported. */
2859 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
2860 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
2862 struct cleanup *old_cleanups = NULL;
2865 old_cleanups = record_gdb_operation_disable_set ();
2867 /* When using hardware single-step, a SIGTRAP is reported for both
2868 a completed single-step and a software breakpoint. Need to
2869 differentiate between the two, as the latter needs adjusting
2870 but the former does not.
2872 The SIGTRAP can be due to a completed hardware single-step only if
2873 - we didn't insert software single-step breakpoints
2874 - the thread to be examined is still the current thread
2875 - this thread is currently being stepped
2877 If any of these events did not occur, we must have stopped due
2878 to hitting a software breakpoint, and have to back up to the
2881 As a special case, we could have hardware single-stepped a
2882 software breakpoint. In this case (prev_pc == breakpoint_pc),
2883 we also need to back up to the breakpoint address. */
2885 if (singlestep_breakpoints_inserted_p
2886 || !ptid_equal (ecs->ptid, inferior_ptid)
2887 || !currently_stepping (ecs->event_thread)
2888 || ecs->event_thread->prev_pc == breakpoint_pc)
2889 regcache_write_pc (regcache, breakpoint_pc);
2892 do_cleanups (old_cleanups);
2897 init_infwait_state (void)
2899 waiton_ptid = pid_to_ptid (-1);
2900 infwait_state = infwait_normal_state;
2904 error_is_running (void)
2906 error (_("Cannot execute this command while "
2907 "the selected thread is running."));
2911 ensure_not_running (void)
2913 if (is_running (inferior_ptid))
2914 error_is_running ();
2918 stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
2920 for (frame = get_prev_frame (frame);
2922 frame = get_prev_frame (frame))
2924 if (frame_id_eq (get_frame_id (frame), step_frame_id))
2926 if (get_frame_type (frame) != INLINE_FRAME)
2933 /* Auxiliary function that handles syscall entry/return events.
2934 It returns 1 if the inferior should keep going (and GDB
2935 should ignore the event), or 0 if the event deserves to be
2939 handle_syscall_event (struct execution_control_state *ecs)
2941 struct regcache *regcache;
2942 struct gdbarch *gdbarch;
2945 if (!ptid_equal (ecs->ptid, inferior_ptid))
2946 context_switch (ecs->ptid);
2948 regcache = get_thread_regcache (ecs->ptid);
2949 gdbarch = get_regcache_arch (regcache);
2950 syscall_number = gdbarch_get_syscall_number (gdbarch, ecs->ptid);
2951 stop_pc = regcache_read_pc (regcache);
2953 target_last_waitstatus.value.syscall_number = syscall_number;
2955 if (catch_syscall_enabled () > 0
2956 && catching_syscall_number (syscall_number) > 0)
2959 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
2962 ecs->event_thread->control.stop_bpstat
2963 = bpstat_stop_status (get_regcache_aspace (regcache),
2964 stop_pc, ecs->ptid);
2966 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
2968 if (!ecs->random_signal)
2970 /* Catchpoint hit. */
2971 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
2976 /* If no catchpoint triggered for this, then keep going. */
2977 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
2982 /* Given an execution control state that has been freshly filled in
2983 by an event from the inferior, figure out what it means and take
2984 appropriate action. */
2987 handle_inferior_event (struct execution_control_state *ecs)
2989 struct frame_info *frame;
2990 struct gdbarch *gdbarch;
2991 int sw_single_step_trap_p = 0;
2992 int stopped_by_watchpoint;
2993 int stepped_after_stopped_by_watchpoint = 0;
2994 struct symtab_and_line stop_pc_sal;
2995 enum stop_kind stop_soon;
2997 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
2999 /* We had an event in the inferior, but we are not interested in
3000 handling it at this level. The lower layers have already
3001 done what needs to be done, if anything.
3003 One of the possible circumstances for this is when the
3004 inferior produces output for the console. The inferior has
3005 not stopped, and we are ignoring the event. Another possible
3006 circumstance is any event which the lower level knows will be
3007 reported multiple times without an intervening resume. */
3009 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
3010 prepare_to_wait (ecs);
3014 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3015 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
3017 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
3020 stop_soon = inf->control.stop_soon;
3023 stop_soon = NO_STOP_QUIETLY;
3025 /* Cache the last pid/waitstatus. */
3026 target_last_wait_ptid = ecs->ptid;
3027 target_last_waitstatus = ecs->ws;
3029 /* Always clear state belonging to the previous time we stopped. */
3030 stop_stack_dummy = STOP_NONE;
3032 /* If it's a new process, add it to the thread database */
3034 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
3035 && !ptid_equal (ecs->ptid, minus_one_ptid)
3036 && !in_thread_list (ecs->ptid));
3038 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3039 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
3040 add_thread (ecs->ptid);
3042 ecs->event_thread = find_thread_ptid (ecs->ptid);
3044 /* Dependent on valid ECS->EVENT_THREAD. */
3045 adjust_pc_after_break (ecs);
3047 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3048 reinit_frame_cache ();
3050 breakpoint_retire_moribund ();
3052 /* First, distinguish signals caused by the debugger from signals
3053 that have to do with the program's own actions. Note that
3054 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3055 on the operating system version. Here we detect when a SIGILL or
3056 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3057 something similar for SIGSEGV, since a SIGSEGV will be generated
3058 when we're trying to execute a breakpoint instruction on a
3059 non-executable stack. This happens for call dummy breakpoints
3060 for architectures like SPARC that place call dummies on the
3062 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
3063 && (ecs->ws.value.sig == TARGET_SIGNAL_ILL
3064 || ecs->ws.value.sig == TARGET_SIGNAL_SEGV
3065 || ecs->ws.value.sig == TARGET_SIGNAL_EMT))
3067 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3069 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3070 regcache_read_pc (regcache)))
3073 fprintf_unfiltered (gdb_stdlog,
3074 "infrun: Treating signal as SIGTRAP\n");
3075 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
3079 /* Mark the non-executing threads accordingly. In all-stop, all
3080 threads of all processes are stopped when we get any event
3081 reported. In non-stop mode, only the event thread stops. If
3082 we're handling a process exit in non-stop mode, there's nothing
3083 to do, as threads of the dead process are gone, and threads of
3084 any other process were left running. */
3086 set_executing (minus_one_ptid, 0);
3087 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3088 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
3089 set_executing (inferior_ptid, 0);
3091 switch (infwait_state)
3093 case infwait_thread_hop_state:
3095 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
3098 case infwait_normal_state:
3100 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
3103 case infwait_step_watch_state:
3105 fprintf_unfiltered (gdb_stdlog,
3106 "infrun: infwait_step_watch_state\n");
3108 stepped_after_stopped_by_watchpoint = 1;
3111 case infwait_nonstep_watch_state:
3113 fprintf_unfiltered (gdb_stdlog,
3114 "infrun: infwait_nonstep_watch_state\n");
3115 insert_breakpoints ();
3117 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3118 handle things like signals arriving and other things happening
3119 in combination correctly? */
3120 stepped_after_stopped_by_watchpoint = 1;
3124 internal_error (__FILE__, __LINE__, _("bad switch"));
3127 infwait_state = infwait_normal_state;
3128 waiton_ptid = pid_to_ptid (-1);
3130 switch (ecs->ws.kind)
3132 case TARGET_WAITKIND_LOADED:
3134 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
3135 /* Ignore gracefully during startup of the inferior, as it might
3136 be the shell which has just loaded some objects, otherwise
3137 add the symbols for the newly loaded objects. Also ignore at
3138 the beginning of an attach or remote session; we will query
3139 the full list of libraries once the connection is
3141 if (stop_soon == NO_STOP_QUIETLY)
3143 /* Check for any newly added shared libraries if we're
3144 supposed to be adding them automatically. Switch
3145 terminal for any messages produced by
3146 breakpoint_re_set. */
3147 target_terminal_ours_for_output ();
3148 /* NOTE: cagney/2003-11-25: Make certain that the target
3149 stack's section table is kept up-to-date. Architectures,
3150 (e.g., PPC64), use the section table to perform
3151 operations such as address => section name and hence
3152 require the table to contain all sections (including
3153 those found in shared libraries). */
3155 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
3157 solib_add (NULL, 0, ¤t_target, auto_solib_add);
3159 target_terminal_inferior ();
3161 /* If requested, stop when the dynamic linker notifies
3162 gdb of events. This allows the user to get control
3163 and place breakpoints in initializer routines for
3164 dynamically loaded objects (among other things). */
3165 if (stop_on_solib_events)
3167 /* Make sure we print "Stopped due to solib-event" in
3169 stop_print_frame = 1;
3171 stop_stepping (ecs);
3175 /* NOTE drow/2007-05-11: This might be a good place to check
3176 for "catch load". */
3179 /* If we are skipping through a shell, or through shared library
3180 loading that we aren't interested in, resume the program. If
3181 we're running the program normally, also resume. But stop if
3182 we're attaching or setting up a remote connection. */
3183 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
3185 /* Loading of shared libraries might have changed breakpoint
3186 addresses. Make sure new breakpoints are inserted. */
3187 if (stop_soon == NO_STOP_QUIETLY
3188 && !breakpoints_always_inserted_mode ())
3189 insert_breakpoints ();
3190 resume (0, TARGET_SIGNAL_0);
3191 prepare_to_wait (ecs);
3197 case TARGET_WAITKIND_SPURIOUS:
3199 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3200 resume (0, TARGET_SIGNAL_0);
3201 prepare_to_wait (ecs);
3204 case TARGET_WAITKIND_EXITED:
3206 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
3207 inferior_ptid = ecs->ptid;
3208 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3209 set_current_program_space (current_inferior ()->pspace);
3210 handle_vfork_child_exec_or_exit (0);
3211 target_terminal_ours (); /* Must do this before mourn anyway */
3212 print_exited_reason (ecs->ws.value.integer);
3214 /* Record the exit code in the convenience variable $_exitcode, so
3215 that the user can inspect this again later. */
3216 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3217 (LONGEST) ecs->ws.value.integer);
3218 gdb_flush (gdb_stdout);
3219 target_mourn_inferior ();
3220 singlestep_breakpoints_inserted_p = 0;
3221 cancel_single_step_breakpoints ();
3222 stop_print_frame = 0;
3223 stop_stepping (ecs);
3226 case TARGET_WAITKIND_SIGNALLED:
3228 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n");
3229 inferior_ptid = ecs->ptid;
3230 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3231 set_current_program_space (current_inferior ()->pspace);
3232 handle_vfork_child_exec_or_exit (0);
3233 stop_print_frame = 0;
3234 target_terminal_ours (); /* Must do this before mourn anyway */
3236 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
3237 reach here unless the inferior is dead. However, for years
3238 target_kill() was called here, which hints that fatal signals aren't
3239 really fatal on some systems. If that's true, then some changes
3241 target_mourn_inferior ();
3243 print_signal_exited_reason (ecs->ws.value.sig);
3244 singlestep_breakpoints_inserted_p = 0;
3245 cancel_single_step_breakpoints ();
3246 stop_stepping (ecs);
3249 /* The following are the only cases in which we keep going;
3250 the above cases end in a continue or goto. */
3251 case TARGET_WAITKIND_FORKED:
3252 case TARGET_WAITKIND_VFORKED:
3254 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3256 if (!ptid_equal (ecs->ptid, inferior_ptid))
3258 context_switch (ecs->ptid);
3259 reinit_frame_cache ();
3262 /* Immediately detach breakpoints from the child before there's
3263 any chance of letting the user delete breakpoints from the
3264 breakpoint lists. If we don't do this early, it's easy to
3265 leave left over traps in the child, vis: "break foo; catch
3266 fork; c; <fork>; del; c; <child calls foo>". We only follow
3267 the fork on the last `continue', and by that time the
3268 breakpoint at "foo" is long gone from the breakpoint table.
3269 If we vforked, then we don't need to unpatch here, since both
3270 parent and child are sharing the same memory pages; we'll
3271 need to unpatch at follow/detach time instead to be certain
3272 that new breakpoints added between catchpoint hit time and
3273 vfork follow are detached. */
3274 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
3276 int child_pid = ptid_get_pid (ecs->ws.value.related_pid);
3278 /* This won't actually modify the breakpoint list, but will
3279 physically remove the breakpoints from the child. */
3280 detach_breakpoints (child_pid);
3283 if (singlestep_breakpoints_inserted_p)
3285 /* Pull the single step breakpoints out of the target. */
3286 remove_single_step_breakpoints ();
3287 singlestep_breakpoints_inserted_p = 0;
3290 /* In case the event is caught by a catchpoint, remember that
3291 the event is to be followed at the next resume of the thread,
3292 and not immediately. */
3293 ecs->event_thread->pending_follow = ecs->ws;
3295 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3297 ecs->event_thread->control.stop_bpstat
3298 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3299 stop_pc, ecs->ptid);
3301 /* Note that we're interested in knowing the bpstat actually
3302 causes a stop, not just if it may explain the signal.
3303 Software watchpoints, for example, always appear in the
3306 = !bpstat_causes_stop (ecs->event_thread->control.stop_bpstat);
3308 /* If no catchpoint triggered for this, then keep going. */
3309 if (ecs->random_signal)
3315 = (follow_fork_mode_string == follow_fork_mode_child);
3317 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3319 should_resume = follow_fork ();
3322 child = ecs->ws.value.related_pid;
3324 /* In non-stop mode, also resume the other branch. */
3325 if (non_stop && !detach_fork)
3328 switch_to_thread (parent);
3330 switch_to_thread (child);
3332 ecs->event_thread = inferior_thread ();
3333 ecs->ptid = inferior_ptid;
3338 switch_to_thread (child);
3340 switch_to_thread (parent);
3342 ecs->event_thread = inferior_thread ();
3343 ecs->ptid = inferior_ptid;
3348 stop_stepping (ecs);
3351 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3352 goto process_event_stop_test;
3354 case TARGET_WAITKIND_VFORK_DONE:
3355 /* Done with the shared memory region. Re-insert breakpoints in
3356 the parent, and keep going. */
3359 fprintf_unfiltered (gdb_stdlog,
3360 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3362 if (!ptid_equal (ecs->ptid, inferior_ptid))
3363 context_switch (ecs->ptid);
3365 current_inferior ()->waiting_for_vfork_done = 0;
3366 current_inferior ()->pspace->breakpoints_not_allowed = 0;
3367 /* This also takes care of reinserting breakpoints in the
3368 previously locked inferior. */
3372 case TARGET_WAITKIND_EXECD:
3374 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
3376 if (!ptid_equal (ecs->ptid, inferior_ptid))
3378 context_switch (ecs->ptid);
3379 reinit_frame_cache ();
3382 singlestep_breakpoints_inserted_p = 0;
3383 cancel_single_step_breakpoints ();
3385 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3387 /* Do whatever is necessary to the parent branch of the vfork. */
3388 handle_vfork_child_exec_or_exit (1);
3390 /* This causes the eventpoints and symbol table to be reset.
3391 Must do this now, before trying to determine whether to
3393 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
3395 ecs->event_thread->control.stop_bpstat
3396 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3397 stop_pc, ecs->ptid);
3399 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
3401 /* Note that this may be referenced from inside
3402 bpstat_stop_status above, through inferior_has_execd. */
3403 xfree (ecs->ws.value.execd_pathname);
3404 ecs->ws.value.execd_pathname = NULL;
3406 /* If no catchpoint triggered for this, then keep going. */
3407 if (ecs->random_signal)
3409 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3413 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3414 goto process_event_stop_test;
3416 /* Be careful not to try to gather much state about a thread
3417 that's in a syscall. It's frequently a losing proposition. */
3418 case TARGET_WAITKIND_SYSCALL_ENTRY:
3420 fprintf_unfiltered (gdb_stdlog,
3421 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3422 /* Getting the current syscall number */
3423 if (handle_syscall_event (ecs) != 0)
3425 goto process_event_stop_test;
3427 /* Before examining the threads further, step this thread to
3428 get it entirely out of the syscall. (We get notice of the
3429 event when the thread is just on the verge of exiting a
3430 syscall. Stepping one instruction seems to get it back
3432 case TARGET_WAITKIND_SYSCALL_RETURN:
3434 fprintf_unfiltered (gdb_stdlog,
3435 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3436 if (handle_syscall_event (ecs) != 0)
3438 goto process_event_stop_test;
3440 case TARGET_WAITKIND_STOPPED:
3442 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
3443 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
3446 case TARGET_WAITKIND_NO_HISTORY:
3447 /* Reverse execution: target ran out of history info. */
3448 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3449 print_no_history_reason ();
3450 stop_stepping (ecs);
3454 if (ecs->new_thread_event)
3457 /* Non-stop assumes that the target handles adding new threads
3458 to the thread list. */
3459 internal_error (__FILE__, __LINE__,
3460 "targets should add new threads to the thread "
3461 "list themselves in non-stop mode.");
3463 /* We may want to consider not doing a resume here in order to
3464 give the user a chance to play with the new thread. It might
3465 be good to make that a user-settable option. */
3467 /* At this point, all threads are stopped (happens automatically
3468 in either the OS or the native code). Therefore we need to
3469 continue all threads in order to make progress. */
3471 if (!ptid_equal (ecs->ptid, inferior_ptid))
3472 context_switch (ecs->ptid);
3473 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
3474 prepare_to_wait (ecs);
3478 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
3480 /* Do we need to clean up the state of a thread that has
3481 completed a displaced single-step? (Doing so usually affects
3482 the PC, so do it here, before we set stop_pc.) */
3483 displaced_step_fixup (ecs->ptid,
3484 ecs->event_thread->suspend.stop_signal);
3486 /* If we either finished a single-step or hit a breakpoint, but
3487 the user wanted this thread to be stopped, pretend we got a
3488 SIG0 (generic unsignaled stop). */
3490 if (ecs->event_thread->stop_requested
3491 && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3492 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3495 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3499 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3500 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3501 struct cleanup *old_chain = save_inferior_ptid ();
3503 inferior_ptid = ecs->ptid;
3505 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
3506 paddress (gdbarch, stop_pc));
3507 if (target_stopped_by_watchpoint ())
3511 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
3513 if (target_stopped_data_address (¤t_target, &addr))
3514 fprintf_unfiltered (gdb_stdlog,
3515 "infrun: stopped data address = %s\n",
3516 paddress (gdbarch, addr));
3518 fprintf_unfiltered (gdb_stdlog,
3519 "infrun: (no data address available)\n");
3522 do_cleanups (old_chain);
3525 if (stepping_past_singlestep_breakpoint)
3527 gdb_assert (singlestep_breakpoints_inserted_p);
3528 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
3529 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
3531 stepping_past_singlestep_breakpoint = 0;
3533 /* We've either finished single-stepping past the single-step
3534 breakpoint, or stopped for some other reason. It would be nice if
3535 we could tell, but we can't reliably. */
3536 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3539 fprintf_unfiltered (gdb_stdlog,
3540 "infrun: stepping_past_"
3541 "singlestep_breakpoint\n");
3542 /* Pull the single step breakpoints out of the target. */
3543 remove_single_step_breakpoints ();
3544 singlestep_breakpoints_inserted_p = 0;
3546 ecs->random_signal = 0;
3547 ecs->event_thread->control.trap_expected = 0;
3549 context_switch (saved_singlestep_ptid);
3550 if (deprecated_context_hook)
3551 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3553 resume (1, TARGET_SIGNAL_0);
3554 prepare_to_wait (ecs);
3559 if (!ptid_equal (deferred_step_ptid, null_ptid))
3561 /* In non-stop mode, there's never a deferred_step_ptid set. */
3562 gdb_assert (!non_stop);
3564 /* If we stopped for some other reason than single-stepping, ignore
3565 the fact that we were supposed to switch back. */
3566 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3569 fprintf_unfiltered (gdb_stdlog,
3570 "infrun: handling deferred step\n");
3572 /* Pull the single step breakpoints out of the target. */
3573 if (singlestep_breakpoints_inserted_p)
3575 remove_single_step_breakpoints ();
3576 singlestep_breakpoints_inserted_p = 0;
3579 /* Note: We do not call context_switch at this point, as the
3580 context is already set up for stepping the original thread. */
3581 switch_to_thread (deferred_step_ptid);
3582 deferred_step_ptid = null_ptid;
3583 /* Suppress spurious "Switching to ..." message. */
3584 previous_inferior_ptid = inferior_ptid;
3586 resume (1, TARGET_SIGNAL_0);
3587 prepare_to_wait (ecs);
3591 deferred_step_ptid = null_ptid;
3594 /* See if a thread hit a thread-specific breakpoint that was meant for
3595 another thread. If so, then step that thread past the breakpoint,
3598 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3600 int thread_hop_needed = 0;
3601 struct address_space *aspace =
3602 get_regcache_aspace (get_thread_regcache (ecs->ptid));
3604 /* Check if a regular breakpoint has been hit before checking
3605 for a potential single step breakpoint. Otherwise, GDB will
3606 not see this breakpoint hit when stepping onto breakpoints. */
3607 if (regular_breakpoint_inserted_here_p (aspace, stop_pc))
3609 ecs->random_signal = 0;
3610 if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid))
3611 thread_hop_needed = 1;
3613 else if (singlestep_breakpoints_inserted_p)
3615 /* We have not context switched yet, so this should be true
3616 no matter which thread hit the singlestep breakpoint. */
3617 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
3619 fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
3621 target_pid_to_str (ecs->ptid));
3623 ecs->random_signal = 0;
3624 /* The call to in_thread_list is necessary because PTIDs sometimes
3625 change when we go from single-threaded to multi-threaded. If
3626 the singlestep_ptid is still in the list, assume that it is
3627 really different from ecs->ptid. */
3628 if (!ptid_equal (singlestep_ptid, ecs->ptid)
3629 && in_thread_list (singlestep_ptid))
3631 /* If the PC of the thread we were trying to single-step
3632 has changed, discard this event (which we were going
3633 to ignore anyway), and pretend we saw that thread
3634 trap. This prevents us continuously moving the
3635 single-step breakpoint forward, one instruction at a
3636 time. If the PC has changed, then the thread we were
3637 trying to single-step has trapped or been signalled,
3638 but the event has not been reported to GDB yet.
3640 There might be some cases where this loses signal
3641 information, if a signal has arrived at exactly the
3642 same time that the PC changed, but this is the best
3643 we can do with the information available. Perhaps we
3644 should arrange to report all events for all threads
3645 when they stop, or to re-poll the remote looking for
3646 this particular thread (i.e. temporarily enable
3649 CORE_ADDR new_singlestep_pc
3650 = regcache_read_pc (get_thread_regcache (singlestep_ptid));
3652 if (new_singlestep_pc != singlestep_pc)
3654 enum target_signal stop_signal;
3657 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
3658 " but expected thread advanced also\n");
3660 /* The current context still belongs to
3661 singlestep_ptid. Don't swap here, since that's
3662 the context we want to use. Just fudge our
3663 state and continue. */
3664 stop_signal = ecs->event_thread->suspend.stop_signal;
3665 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3666 ecs->ptid = singlestep_ptid;
3667 ecs->event_thread = find_thread_ptid (ecs->ptid);
3668 ecs->event_thread->suspend.stop_signal = stop_signal;
3669 stop_pc = new_singlestep_pc;
3674 fprintf_unfiltered (gdb_stdlog,
3675 "infrun: unexpected thread\n");
3677 thread_hop_needed = 1;
3678 stepping_past_singlestep_breakpoint = 1;
3679 saved_singlestep_ptid = singlestep_ptid;
3684 if (thread_hop_needed)
3686 struct regcache *thread_regcache;
3687 int remove_status = 0;
3690 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
3692 /* Switch context before touching inferior memory, the
3693 previous thread may have exited. */
3694 if (!ptid_equal (inferior_ptid, ecs->ptid))
3695 context_switch (ecs->ptid);
3697 /* Saw a breakpoint, but it was hit by the wrong thread.
3700 if (singlestep_breakpoints_inserted_p)
3702 /* Pull the single step breakpoints out of the target. */
3703 remove_single_step_breakpoints ();
3704 singlestep_breakpoints_inserted_p = 0;
3707 /* If the arch can displace step, don't remove the
3709 thread_regcache = get_thread_regcache (ecs->ptid);
3710 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
3711 remove_status = remove_breakpoints ();
3713 /* Did we fail to remove breakpoints? If so, try
3714 to set the PC past the bp. (There's at least
3715 one situation in which we can fail to remove
3716 the bp's: On HP-UX's that use ttrace, we can't
3717 change the address space of a vforking child
3718 process until the child exits (well, okay, not
3719 then either :-) or execs. */
3720 if (remove_status != 0)
3721 error (_("Cannot step over breakpoint hit in wrong thread"));
3726 /* Only need to require the next event from this
3727 thread in all-stop mode. */
3728 waiton_ptid = ecs->ptid;
3729 infwait_state = infwait_thread_hop_state;
3732 ecs->event_thread->stepping_over_breakpoint = 1;
3737 else if (singlestep_breakpoints_inserted_p)
3739 sw_single_step_trap_p = 1;
3740 ecs->random_signal = 0;
3744 ecs->random_signal = 1;
3746 /* See if something interesting happened to the non-current thread. If
3747 so, then switch to that thread. */
3748 if (!ptid_equal (ecs->ptid, inferior_ptid))
3751 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
3753 context_switch (ecs->ptid);
3755 if (deprecated_context_hook)
3756 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3759 /* At this point, get hold of the now-current thread's frame. */
3760 frame = get_current_frame ();
3761 gdbarch = get_frame_arch (frame);
3763 if (singlestep_breakpoints_inserted_p)
3765 /* Pull the single step breakpoints out of the target. */
3766 remove_single_step_breakpoints ();
3767 singlestep_breakpoints_inserted_p = 0;
3770 if (stepped_after_stopped_by_watchpoint)
3771 stopped_by_watchpoint = 0;
3773 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
3775 /* If necessary, step over this watchpoint. We'll be back to display
3777 if (stopped_by_watchpoint
3778 && (target_have_steppable_watchpoint
3779 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
3781 /* At this point, we are stopped at an instruction which has
3782 attempted to write to a piece of memory under control of
3783 a watchpoint. The instruction hasn't actually executed
3784 yet. If we were to evaluate the watchpoint expression
3785 now, we would get the old value, and therefore no change
3786 would seem to have occurred.
3788 In order to make watchpoints work `right', we really need
3789 to complete the memory write, and then evaluate the
3790 watchpoint expression. We do this by single-stepping the
3793 It may not be necessary to disable the watchpoint to stop over
3794 it. For example, the PA can (with some kernel cooperation)
3795 single step over a watchpoint without disabling the watchpoint.
3797 It is far more common to need to disable a watchpoint to step
3798 the inferior over it. If we have non-steppable watchpoints,
3799 we must disable the current watchpoint; it's simplest to
3800 disable all watchpoints and breakpoints. */
3803 if (!target_have_steppable_watchpoint)
3804 remove_breakpoints ();
3806 hw_step = maybe_software_singlestep (gdbarch, stop_pc);
3807 target_resume (ecs->ptid, hw_step, TARGET_SIGNAL_0);
3808 waiton_ptid = ecs->ptid;
3809 if (target_have_steppable_watchpoint)
3810 infwait_state = infwait_step_watch_state;
3812 infwait_state = infwait_nonstep_watch_state;
3813 prepare_to_wait (ecs);
3817 ecs->stop_func_start = 0;
3818 ecs->stop_func_end = 0;
3819 ecs->stop_func_name = 0;
3820 /* Don't care about return value; stop_func_start and stop_func_name
3821 will both be 0 if it doesn't work. */
3822 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3823 &ecs->stop_func_start, &ecs->stop_func_end);
3824 ecs->stop_func_start
3825 += gdbarch_deprecated_function_start_offset (gdbarch);
3826 ecs->event_thread->stepping_over_breakpoint = 0;
3827 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
3828 ecs->event_thread->control.stop_step = 0;
3829 stop_print_frame = 1;
3830 ecs->random_signal = 0;
3831 stopped_by_random_signal = 0;
3833 /* Hide inlined functions starting here, unless we just performed stepi or
3834 nexti. After stepi and nexti, always show the innermost frame (not any
3835 inline function call sites). */
3836 if (ecs->event_thread->control.step_range_end != 1)
3837 skip_inline_frames (ecs->ptid);
3839 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3840 && ecs->event_thread->control.trap_expected
3841 && gdbarch_single_step_through_delay_p (gdbarch)
3842 && currently_stepping (ecs->event_thread))
3844 /* We're trying to step off a breakpoint. Turns out that we're
3845 also on an instruction that needs to be stepped multiple
3846 times before it's been fully executing. E.g., architectures
3847 with a delay slot. It needs to be stepped twice, once for
3848 the instruction and once for the delay slot. */
3849 int step_through_delay
3850 = gdbarch_single_step_through_delay (gdbarch, frame);
3852 if (debug_infrun && step_through_delay)
3853 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
3854 if (ecs->event_thread->control.step_range_end == 0
3855 && step_through_delay)
3857 /* The user issued a continue when stopped at a breakpoint.
3858 Set up for another trap and get out of here. */
3859 ecs->event_thread->stepping_over_breakpoint = 1;
3863 else if (step_through_delay)
3865 /* The user issued a step when stopped at a breakpoint.
3866 Maybe we should stop, maybe we should not - the delay
3867 slot *might* correspond to a line of source. In any
3868 case, don't decide that here, just set
3869 ecs->stepping_over_breakpoint, making sure we
3870 single-step again before breakpoints are re-inserted. */
3871 ecs->event_thread->stepping_over_breakpoint = 1;
3875 /* Look at the cause of the stop, and decide what to do.
3876 The alternatives are:
3877 1) stop_stepping and return; to really stop and return to the debugger,
3878 2) keep_going and return to start up again
3879 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
3880 3) set ecs->random_signal to 1, and the decision between 1 and 2
3881 will be made according to the signal handling tables. */
3883 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3884 || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP
3885 || stop_soon == STOP_QUIETLY_REMOTE)
3887 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3891 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
3892 stop_print_frame = 0;
3893 stop_stepping (ecs);
3897 /* This is originated from start_remote(), start_inferior() and
3898 shared libraries hook functions. */
3899 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
3902 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
3903 stop_stepping (ecs);
3907 /* This originates from attach_command(). We need to overwrite
3908 the stop_signal here, because some kernels don't ignore a
3909 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3910 See more comments in inferior.h. On the other hand, if we
3911 get a non-SIGSTOP, report it to the user - assume the backend
3912 will handle the SIGSTOP if it should show up later.
3914 Also consider that the attach is complete when we see a
3915 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3916 target extended-remote report it instead of a SIGSTOP
3917 (e.g. gdbserver). We already rely on SIGTRAP being our
3918 signal, so this is no exception.
3920 Also consider that the attach is complete when we see a
3921 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3922 the target to stop all threads of the inferior, in case the
3923 low level attach operation doesn't stop them implicitly. If
3924 they weren't stopped implicitly, then the stub will report a
3925 TARGET_SIGNAL_0, meaning: stopped for no particular reason
3926 other than GDB's request. */
3927 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
3928 && (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_STOP
3929 || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3930 || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_0))
3932 stop_stepping (ecs);
3933 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3937 /* See if there is a breakpoint at the current PC. */
3938 ecs->event_thread->control.stop_bpstat
3939 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3940 stop_pc, ecs->ptid);
3942 /* Following in case break condition called a
3944 stop_print_frame = 1;
3946 /* This is where we handle "moribund" watchpoints. Unlike
3947 software breakpoints traps, hardware watchpoint traps are
3948 always distinguishable from random traps. If no high-level
3949 watchpoint is associated with the reported stop data address
3950 anymore, then the bpstat does not explain the signal ---
3951 simply make sure to ignore it if `stopped_by_watchpoint' is
3955 && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3956 && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat)
3957 && stopped_by_watchpoint)
3958 fprintf_unfiltered (gdb_stdlog,
3959 "infrun: no user watchpoint explains "
3960 "watchpoint SIGTRAP, ignoring\n");
3962 /* NOTE: cagney/2003-03-29: These two checks for a random signal
3963 at one stage in the past included checks for an inferior
3964 function call's call dummy's return breakpoint. The original
3965 comment, that went with the test, read:
3967 ``End of a stack dummy. Some systems (e.g. Sony news) give
3968 another signal besides SIGTRAP, so check here as well as
3971 If someone ever tries to get call dummys on a
3972 non-executable stack to work (where the target would stop
3973 with something like a SIGSEGV), then those tests might need
3974 to be re-instated. Given, however, that the tests were only
3975 enabled when momentary breakpoints were not being used, I
3976 suspect that it won't be the case.
3978 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
3979 be necessary for call dummies on a non-executable stack on
3982 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3984 = !(bpstat_explains_signal (ecs->event_thread->control.stop_bpstat)
3985 || stopped_by_watchpoint
3986 || ecs->event_thread->control.trap_expected
3987 || (ecs->event_thread->control.step_range_end
3988 && (ecs->event_thread->control.step_resume_breakpoint
3992 ecs->random_signal = !bpstat_explains_signal
3993 (ecs->event_thread->control.stop_bpstat);
3994 if (!ecs->random_signal)
3995 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3999 /* When we reach this point, we've pretty much decided
4000 that the reason for stopping must've been a random
4001 (unexpected) signal. */
4004 ecs->random_signal = 1;
4006 process_event_stop_test:
4008 /* Re-fetch current thread's frame in case we did a
4009 "goto process_event_stop_test" above. */
4010 frame = get_current_frame ();
4011 gdbarch = get_frame_arch (frame);
4013 /* For the program's own signals, act according to
4014 the signal handling tables. */
4016 if (ecs->random_signal)
4018 /* Signal not for debugging purposes. */
4020 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
4023 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
4024 ecs->event_thread->suspend.stop_signal);
4026 stopped_by_random_signal = 1;
4028 if (signal_print[ecs->event_thread->suspend.stop_signal])
4031 target_terminal_ours_for_output ();
4032 print_signal_received_reason
4033 (ecs->event_thread->suspend.stop_signal);
4035 /* Always stop on signals if we're either just gaining control
4036 of the program, or the user explicitly requested this thread
4037 to remain stopped. */
4038 if (stop_soon != NO_STOP_QUIETLY
4039 || ecs->event_thread->stop_requested
4041 && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
4043 stop_stepping (ecs);
4046 /* If not going to stop, give terminal back
4047 if we took it away. */
4049 target_terminal_inferior ();
4051 /* Clear the signal if it should not be passed. */
4052 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
4053 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
4055 if (ecs->event_thread->prev_pc == stop_pc
4056 && ecs->event_thread->control.trap_expected
4057 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4059 /* We were just starting a new sequence, attempting to
4060 single-step off of a breakpoint and expecting a SIGTRAP.
4061 Instead this signal arrives. This signal will take us out
4062 of the stepping range so GDB needs to remember to, when
4063 the signal handler returns, resume stepping off that
4065 /* To simplify things, "continue" is forced to use the same
4066 code paths as single-step - set a breakpoint at the
4067 signal return address and then, once hit, step off that
4070 fprintf_unfiltered (gdb_stdlog,
4071 "infrun: signal arrived while stepping over "
4074 insert_step_resume_breakpoint_at_frame (frame);
4075 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4080 if (ecs->event_thread->control.step_range_end != 0
4081 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_0
4082 && (ecs->event_thread->control.step_range_start <= stop_pc
4083 && stop_pc < ecs->event_thread->control.step_range_end)
4084 && frame_id_eq (get_stack_frame_id (frame),
4085 ecs->event_thread->control.step_stack_frame_id)
4086 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4088 /* The inferior is about to take a signal that will take it
4089 out of the single step range. Set a breakpoint at the
4090 current PC (which is presumably where the signal handler
4091 will eventually return) and then allow the inferior to
4094 Note that this is only needed for a signal delivered
4095 while in the single-step range. Nested signals aren't a
4096 problem as they eventually all return. */
4098 fprintf_unfiltered (gdb_stdlog,
4099 "infrun: signal may take us out of "
4100 "single-step range\n");
4102 insert_step_resume_breakpoint_at_frame (frame);
4107 /* Note: step_resume_breakpoint may be non-NULL. This occures
4108 when either there's a nested signal, or when there's a
4109 pending signal enabled just as the signal handler returns
4110 (leaving the inferior at the step-resume-breakpoint without
4111 actually executing it). Either way continue until the
4112 breakpoint is really hit. */
4117 /* Handle cases caused by hitting a breakpoint. */
4119 CORE_ADDR jmp_buf_pc;
4120 struct bpstat_what what;
4122 what = bpstat_what (ecs->event_thread->control.stop_bpstat);
4124 if (what.call_dummy)
4126 stop_stack_dummy = what.call_dummy;
4129 /* If we hit an internal event that triggers symbol changes, the
4130 current frame will be invalidated within bpstat_what (e.g., if
4131 we hit an internal solib event). Re-fetch it. */
4132 frame = get_current_frame ();
4133 gdbarch = get_frame_arch (frame);
4135 switch (what.main_action)
4137 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
4138 /* If we hit the breakpoint at longjmp while stepping, we
4139 install a momentary breakpoint at the target of the
4143 fprintf_unfiltered (gdb_stdlog,
4144 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4146 ecs->event_thread->stepping_over_breakpoint = 1;
4148 if (what.is_longjmp)
4150 if (!gdbarch_get_longjmp_target_p (gdbarch)
4151 || !gdbarch_get_longjmp_target (gdbarch,
4152 frame, &jmp_buf_pc))
4155 fprintf_unfiltered (gdb_stdlog,
4156 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4157 "(!gdbarch_get_longjmp_target)\n");
4162 /* We're going to replace the current step-resume breakpoint
4163 with a longjmp-resume breakpoint. */
4164 delete_step_resume_breakpoint (ecs->event_thread);
4166 /* Insert a breakpoint at resume address. */
4167 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4171 struct symbol *func = get_frame_function (frame);
4174 check_exception_resume (ecs, frame, func);
4179 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4181 fprintf_unfiltered (gdb_stdlog,
4182 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4184 if (what.is_longjmp)
4186 gdb_assert (ecs->event_thread->control.step_resume_breakpoint
4188 delete_step_resume_breakpoint (ecs->event_thread);
4192 /* There are several cases to consider.
4194 1. The initiating frame no longer exists. In this case
4195 we must stop, because the exception has gone too far.
4197 2. The initiating frame exists, and is the same as the
4198 current frame. We stop, because the exception has been
4201 3. The initiating frame exists and is different from
4202 the current frame. This means the exception has been
4203 caught beneath the initiating frame, so keep going. */
4204 struct frame_info *init_frame
4205 = frame_find_by_id (ecs->event_thread->initiating_frame);
4207 gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
4209 delete_exception_resume_breakpoint (ecs->event_thread);
4213 struct frame_id current_id
4214 = get_frame_id (get_current_frame ());
4215 if (frame_id_eq (current_id,
4216 ecs->event_thread->initiating_frame))
4218 /* Case 2. Fall through. */
4228 /* For Cases 1 and 2, remove the step-resume breakpoint,
4230 delete_step_resume_breakpoint (ecs->event_thread);
4233 ecs->event_thread->control.stop_step = 1;
4234 print_end_stepping_range_reason ();
4235 stop_stepping (ecs);
4238 case BPSTAT_WHAT_SINGLE:
4240 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
4241 ecs->event_thread->stepping_over_breakpoint = 1;
4242 /* Still need to check other stuff, at least the case
4243 where we are stepping and step out of the right range. */
4246 case BPSTAT_WHAT_STOP_NOISY:
4248 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4249 stop_print_frame = 1;
4251 /* We are about to nuke the step_resume_breakpointt via the
4252 cleanup chain, so no need to worry about it here. */
4254 stop_stepping (ecs);
4257 case BPSTAT_WHAT_STOP_SILENT:
4259 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4260 stop_print_frame = 0;
4262 /* We are about to nuke the step_resume_breakpoin via the
4263 cleanup chain, so no need to worry about it here. */
4265 stop_stepping (ecs);
4268 case BPSTAT_WHAT_STEP_RESUME:
4270 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4272 delete_step_resume_breakpoint (ecs->event_thread);
4273 if (ecs->event_thread->step_after_step_resume_breakpoint)
4275 /* Back when the step-resume breakpoint was inserted, we
4276 were trying to single-step off a breakpoint. Go back
4278 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4279 ecs->event_thread->stepping_over_breakpoint = 1;
4283 if (stop_pc == ecs->stop_func_start
4284 && execution_direction == EXEC_REVERSE)
4286 /* We are stepping over a function call in reverse, and
4287 just hit the step-resume breakpoint at the start
4288 address of the function. Go back to single-stepping,
4289 which should take us back to the function call. */
4290 ecs->event_thread->stepping_over_breakpoint = 1;
4296 case BPSTAT_WHAT_KEEP_CHECKING:
4301 /* We come here if we hit a breakpoint but should not
4302 stop for it. Possibly we also were stepping
4303 and should stop for that. So fall through and
4304 test for stepping. But, if not stepping,
4307 /* In all-stop mode, if we're currently stepping but have stopped in
4308 some other thread, we need to switch back to the stepped thread. */
4311 struct thread_info *tp;
4313 tp = iterate_over_threads (currently_stepping_or_nexting_callback,
4317 /* However, if the current thread is blocked on some internal
4318 breakpoint, and we simply need to step over that breakpoint
4319 to get it going again, do that first. */
4320 if ((ecs->event_thread->control.trap_expected
4321 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP)
4322 || ecs->event_thread->stepping_over_breakpoint)
4328 /* If the stepping thread exited, then don't try to switch
4329 back and resume it, which could fail in several different
4330 ways depending on the target. Instead, just keep going.
4332 We can find a stepping dead thread in the thread list in
4335 - The target supports thread exit events, and when the
4336 target tries to delete the thread from the thread list,
4337 inferior_ptid pointed at the exiting thread. In such
4338 case, calling delete_thread does not really remove the
4339 thread from the list; instead, the thread is left listed,
4340 with 'exited' state.
4342 - The target's debug interface does not support thread
4343 exit events, and so we have no idea whatsoever if the
4344 previously stepping thread is still alive. For that
4345 reason, we need to synchronously query the target
4347 if (is_exited (tp->ptid)
4348 || !target_thread_alive (tp->ptid))
4351 fprintf_unfiltered (gdb_stdlog,
4352 "infrun: not switching back to "
4353 "stepped thread, it has vanished\n");
4355 delete_thread (tp->ptid);
4360 /* Otherwise, we no longer expect a trap in the current thread.
4361 Clear the trap_expected flag before switching back -- this is
4362 what keep_going would do as well, if we called it. */
4363 ecs->event_thread->control.trap_expected = 0;
4366 fprintf_unfiltered (gdb_stdlog,
4367 "infrun: switching back to stepped thread\n");
4369 ecs->event_thread = tp;
4370 ecs->ptid = tp->ptid;
4371 context_switch (ecs->ptid);
4377 /* Are we stepping to get the inferior out of the dynamic linker's
4378 hook (and possibly the dld itself) after catching a shlib
4380 if (ecs->event_thread->stepping_through_solib_after_catch)
4382 #if defined(SOLIB_ADD)
4383 /* Have we reached our destination? If not, keep going. */
4384 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
4387 fprintf_unfiltered (gdb_stdlog,
4388 "infrun: stepping in dynamic linker\n");
4389 ecs->event_thread->stepping_over_breakpoint = 1;
4395 fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n");
4396 /* Else, stop and report the catchpoint(s) whose triggering
4397 caused us to begin stepping. */
4398 ecs->event_thread->stepping_through_solib_after_catch = 0;
4399 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
4400 ecs->event_thread->control.stop_bpstat
4401 = bpstat_copy (ecs->event_thread->stepping_through_solib_catchpoints);
4402 bpstat_clear (&ecs->event_thread->stepping_through_solib_catchpoints);
4403 stop_print_frame = 1;
4404 stop_stepping (ecs);
4408 if (ecs->event_thread->control.step_resume_breakpoint)
4411 fprintf_unfiltered (gdb_stdlog,
4412 "infrun: step-resume breakpoint is inserted\n");
4414 /* Having a step-resume breakpoint overrides anything
4415 else having to do with stepping commands until
4416 that breakpoint is reached. */
4421 if (ecs->event_thread->control.step_range_end == 0)
4424 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
4425 /* Likewise if we aren't even stepping. */
4430 /* Re-fetch current thread's frame in case the code above caused
4431 the frame cache to be re-initialized, making our FRAME variable
4432 a dangling pointer. */
4433 frame = get_current_frame ();
4434 gdbarch = get_frame_arch (frame);
4436 /* If stepping through a line, keep going if still within it.
4438 Note that step_range_end is the address of the first instruction
4439 beyond the step range, and NOT the address of the last instruction
4442 Note also that during reverse execution, we may be stepping
4443 through a function epilogue and therefore must detect when
4444 the current-frame changes in the middle of a line. */
4446 if (stop_pc >= ecs->event_thread->control.step_range_start
4447 && stop_pc < ecs->event_thread->control.step_range_end
4448 && (execution_direction != EXEC_REVERSE
4449 || frame_id_eq (get_frame_id (frame),
4450 ecs->event_thread->control.step_frame_id)))
4454 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
4455 paddress (gdbarch, ecs->event_thread->control.step_range_start),
4456 paddress (gdbarch, ecs->event_thread->control.step_range_end));
4458 /* When stepping backward, stop at beginning of line range
4459 (unless it's the function entry point, in which case
4460 keep going back to the call point). */
4461 if (stop_pc == ecs->event_thread->control.step_range_start
4462 && stop_pc != ecs->stop_func_start
4463 && execution_direction == EXEC_REVERSE)
4465 ecs->event_thread->control.stop_step = 1;
4466 print_end_stepping_range_reason ();
4467 stop_stepping (ecs);
4475 /* We stepped out of the stepping range. */
4477 /* If we are stepping at the source level and entered the runtime
4478 loader dynamic symbol resolution code...
4480 EXEC_FORWARD: we keep on single stepping until we exit the run
4481 time loader code and reach the callee's address.
4483 EXEC_REVERSE: we've already executed the callee (backward), and
4484 the runtime loader code is handled just like any other
4485 undebuggable function call. Now we need only keep stepping
4486 backward through the trampoline code, and that's handled further
4487 down, so there is nothing for us to do here. */
4489 if (execution_direction != EXEC_REVERSE
4490 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4491 && in_solib_dynsym_resolve_code (stop_pc))
4493 CORE_ADDR pc_after_resolver =
4494 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
4497 fprintf_unfiltered (gdb_stdlog,
4498 "infrun: stepped into dynsym resolve code\n");
4500 if (pc_after_resolver)
4502 /* Set up a step-resume breakpoint at the address
4503 indicated by SKIP_SOLIB_RESOLVER. */
4504 struct symtab_and_line sr_sal;
4507 sr_sal.pc = pc_after_resolver;
4508 sr_sal.pspace = get_frame_program_space (frame);
4510 insert_step_resume_breakpoint_at_sal (gdbarch,
4511 sr_sal, null_frame_id);
4518 if (ecs->event_thread->control.step_range_end != 1
4519 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4520 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4521 && get_frame_type (frame) == SIGTRAMP_FRAME)
4524 fprintf_unfiltered (gdb_stdlog,
4525 "infrun: stepped into signal trampoline\n");
4526 /* The inferior, while doing a "step" or "next", has ended up in
4527 a signal trampoline (either by a signal being delivered or by
4528 the signal handler returning). Just single-step until the
4529 inferior leaves the trampoline (either by calling the handler
4535 /* Check for subroutine calls. The check for the current frame
4536 equalling the step ID is not necessary - the check of the
4537 previous frame's ID is sufficient - but it is a common case and
4538 cheaper than checking the previous frame's ID.
4540 NOTE: frame_id_eq will never report two invalid frame IDs as
4541 being equal, so to get into this block, both the current and
4542 previous frame must have valid frame IDs. */
4543 /* The outer_frame_id check is a heuristic to detect stepping
4544 through startup code. If we step over an instruction which
4545 sets the stack pointer from an invalid value to a valid value,
4546 we may detect that as a subroutine call from the mythical
4547 "outermost" function. This could be fixed by marking
4548 outermost frames as !stack_p,code_p,special_p. Then the
4549 initial outermost frame, before sp was valid, would
4550 have code_addr == &_start. See the comment in frame_id_eq
4552 if (!frame_id_eq (get_stack_frame_id (frame),
4553 ecs->event_thread->control.step_stack_frame_id)
4554 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4555 ecs->event_thread->control.step_stack_frame_id)
4556 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
4558 || step_start_function != find_pc_function (stop_pc))))
4560 CORE_ADDR real_stop_pc;
4563 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
4565 if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
4566 || ((ecs->event_thread->control.step_range_end == 1)
4567 && in_prologue (gdbarch, ecs->event_thread->prev_pc,
4568 ecs->stop_func_start)))
4570 /* I presume that step_over_calls is only 0 when we're
4571 supposed to be stepping at the assembly language level
4572 ("stepi"). Just stop. */
4573 /* Also, maybe we just did a "nexti" inside a prolog, so we
4574 thought it was a subroutine call but it was not. Stop as
4576 /* And this works the same backward as frontward. MVS */
4577 ecs->event_thread->control.stop_step = 1;
4578 print_end_stepping_range_reason ();
4579 stop_stepping (ecs);
4583 /* Reverse stepping through solib trampolines. */
4585 if (execution_direction == EXEC_REVERSE
4586 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
4587 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4588 || (ecs->stop_func_start == 0
4589 && in_solib_dynsym_resolve_code (stop_pc))))
4591 /* Any solib trampoline code can be handled in reverse
4592 by simply continuing to single-step. We have already
4593 executed the solib function (backwards), and a few
4594 steps will take us back through the trampoline to the
4600 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4602 /* We're doing a "next".
4604 Normal (forward) execution: set a breakpoint at the
4605 callee's return address (the address at which the caller
4608 Reverse (backward) execution. set the step-resume
4609 breakpoint at the start of the function that we just
4610 stepped into (backwards), and continue to there. When we
4611 get there, we'll need to single-step back to the caller. */
4613 if (execution_direction == EXEC_REVERSE)
4615 struct symtab_and_line sr_sal;
4617 /* Normal function call return (static or dynamic). */
4619 sr_sal.pc = ecs->stop_func_start;
4620 sr_sal.pspace = get_frame_program_space (frame);
4621 insert_step_resume_breakpoint_at_sal (gdbarch,
4622 sr_sal, null_frame_id);
4625 insert_step_resume_breakpoint_at_caller (frame);
4631 /* If we are in a function call trampoline (a stub between the
4632 calling routine and the real function), locate the real
4633 function. That's what tells us (a) whether we want to step
4634 into it at all, and (b) what prologue we want to run to the
4635 end of, if we do step into it. */
4636 real_stop_pc = skip_language_trampoline (frame, stop_pc);
4637 if (real_stop_pc == 0)
4638 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4639 if (real_stop_pc != 0)
4640 ecs->stop_func_start = real_stop_pc;
4642 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
4644 struct symtab_and_line sr_sal;
4647 sr_sal.pc = ecs->stop_func_start;
4648 sr_sal.pspace = get_frame_program_space (frame);
4650 insert_step_resume_breakpoint_at_sal (gdbarch,
4651 sr_sal, null_frame_id);
4656 /* If we have line number information for the function we are
4657 thinking of stepping into, step into it.
4659 If there are several symtabs at that PC (e.g. with include
4660 files), just want to know whether *any* of them have line
4661 numbers. find_pc_line handles this. */
4663 struct symtab_and_line tmp_sal;
4665 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
4666 tmp_sal.pspace = get_frame_program_space (frame);
4667 if (tmp_sal.line != 0)
4669 if (execution_direction == EXEC_REVERSE)
4670 handle_step_into_function_backward (gdbarch, ecs);
4672 handle_step_into_function (gdbarch, ecs);
4677 /* If we have no line number and the step-stop-if-no-debug is
4678 set, we stop the step so that the user has a chance to switch
4679 in assembly mode. */
4680 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4681 && step_stop_if_no_debug)
4683 ecs->event_thread->control.stop_step = 1;
4684 print_end_stepping_range_reason ();
4685 stop_stepping (ecs);
4689 if (execution_direction == EXEC_REVERSE)
4691 /* Set a breakpoint at callee's start address.
4692 From there we can step once and be back in the caller. */
4693 struct symtab_and_line sr_sal;
4696 sr_sal.pc = ecs->stop_func_start;
4697 sr_sal.pspace = get_frame_program_space (frame);
4698 insert_step_resume_breakpoint_at_sal (gdbarch,
4699 sr_sal, null_frame_id);
4702 /* Set a breakpoint at callee's return address (the address
4703 at which the caller will resume). */
4704 insert_step_resume_breakpoint_at_caller (frame);
4710 /* Reverse stepping through solib trampolines. */
4712 if (execution_direction == EXEC_REVERSE
4713 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
4715 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4716 || (ecs->stop_func_start == 0
4717 && in_solib_dynsym_resolve_code (stop_pc)))
4719 /* Any solib trampoline code can be handled in reverse
4720 by simply continuing to single-step. We have already
4721 executed the solib function (backwards), and a few
4722 steps will take us back through the trampoline to the
4727 else if (in_solib_dynsym_resolve_code (stop_pc))
4729 /* Stepped backward into the solib dynsym resolver.
4730 Set a breakpoint at its start and continue, then
4731 one more step will take us out. */
4732 struct symtab_and_line sr_sal;
4735 sr_sal.pc = ecs->stop_func_start;
4736 sr_sal.pspace = get_frame_program_space (frame);
4737 insert_step_resume_breakpoint_at_sal (gdbarch,
4738 sr_sal, null_frame_id);
4744 /* If we're in the return path from a shared library trampoline,
4745 we want to proceed through the trampoline when stepping. */
4746 if (gdbarch_in_solib_return_trampoline (gdbarch,
4747 stop_pc, ecs->stop_func_name))
4749 /* Determine where this trampoline returns. */
4750 CORE_ADDR real_stop_pc;
4752 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4755 fprintf_unfiltered (gdb_stdlog,
4756 "infrun: stepped into solib return tramp\n");
4758 /* Only proceed through if we know where it's going. */
4761 /* And put the step-breakpoint there and go until there. */
4762 struct symtab_and_line sr_sal;
4764 init_sal (&sr_sal); /* initialize to zeroes */
4765 sr_sal.pc = real_stop_pc;
4766 sr_sal.section = find_pc_overlay (sr_sal.pc);
4767 sr_sal.pspace = get_frame_program_space (frame);
4769 /* Do not specify what the fp should be when we stop since
4770 on some machines the prologue is where the new fp value
4772 insert_step_resume_breakpoint_at_sal (gdbarch,
4773 sr_sal, null_frame_id);
4775 /* Restart without fiddling with the step ranges or
4782 stop_pc_sal = find_pc_line (stop_pc, 0);
4784 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4785 the trampoline processing logic, however, there are some trampolines
4786 that have no names, so we should do trampoline handling first. */
4787 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4788 && ecs->stop_func_name == NULL
4789 && stop_pc_sal.line == 0)
4792 fprintf_unfiltered (gdb_stdlog,
4793 "infrun: stepped into undebuggable function\n");
4795 /* The inferior just stepped into, or returned to, an
4796 undebuggable function (where there is no debugging information
4797 and no line number corresponding to the address where the
4798 inferior stopped). Since we want to skip this kind of code,
4799 we keep going until the inferior returns from this
4800 function - unless the user has asked us not to (via
4801 set step-mode) or we no longer know how to get back
4802 to the call site. */
4803 if (step_stop_if_no_debug
4804 || !frame_id_p (frame_unwind_caller_id (frame)))
4806 /* If we have no line number and the step-stop-if-no-debug
4807 is set, we stop the step so that the user has a chance to
4808 switch in assembly mode. */
4809 ecs->event_thread->control.stop_step = 1;
4810 print_end_stepping_range_reason ();
4811 stop_stepping (ecs);
4816 /* Set a breakpoint at callee's return address (the address
4817 at which the caller will resume). */
4818 insert_step_resume_breakpoint_at_caller (frame);
4824 if (ecs->event_thread->control.step_range_end == 1)
4826 /* It is stepi or nexti. We always want to stop stepping after
4829 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
4830 ecs->event_thread->control.stop_step = 1;
4831 print_end_stepping_range_reason ();
4832 stop_stepping (ecs);
4836 if (stop_pc_sal.line == 0)
4838 /* We have no line number information. That means to stop
4839 stepping (does this always happen right after one instruction,
4840 when we do "s" in a function with no line numbers,
4841 or can this happen as a result of a return or longjmp?). */
4843 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
4844 ecs->event_thread->control.stop_step = 1;
4845 print_end_stepping_range_reason ();
4846 stop_stepping (ecs);
4850 /* Look for "calls" to inlined functions, part one. If the inline
4851 frame machinery detected some skipped call sites, we have entered
4852 a new inline function. */
4854 if (frame_id_eq (get_frame_id (get_current_frame ()),
4855 ecs->event_thread->control.step_frame_id)
4856 && inline_skipped_frames (ecs->ptid))
4858 struct symtab_and_line call_sal;
4861 fprintf_unfiltered (gdb_stdlog,
4862 "infrun: stepped into inlined function\n");
4864 find_frame_sal (get_current_frame (), &call_sal);
4866 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
4868 /* For "step", we're going to stop. But if the call site
4869 for this inlined function is on the same source line as
4870 we were previously stepping, go down into the function
4871 first. Otherwise stop at the call site. */
4873 if (call_sal.line == ecs->event_thread->current_line
4874 && call_sal.symtab == ecs->event_thread->current_symtab)
4875 step_into_inline_frame (ecs->ptid);
4877 ecs->event_thread->control.stop_step = 1;
4878 print_end_stepping_range_reason ();
4879 stop_stepping (ecs);
4884 /* For "next", we should stop at the call site if it is on a
4885 different source line. Otherwise continue through the
4886 inlined function. */
4887 if (call_sal.line == ecs->event_thread->current_line
4888 && call_sal.symtab == ecs->event_thread->current_symtab)
4892 ecs->event_thread->control.stop_step = 1;
4893 print_end_stepping_range_reason ();
4894 stop_stepping (ecs);
4900 /* Look for "calls" to inlined functions, part two. If we are still
4901 in the same real function we were stepping through, but we have
4902 to go further up to find the exact frame ID, we are stepping
4903 through a more inlined call beyond its call site. */
4905 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
4906 && !frame_id_eq (get_frame_id (get_current_frame ()),
4907 ecs->event_thread->control.step_frame_id)
4908 && stepped_in_from (get_current_frame (),
4909 ecs->event_thread->control.step_frame_id))
4912 fprintf_unfiltered (gdb_stdlog,
4913 "infrun: stepping through inlined function\n");
4915 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4919 ecs->event_thread->control.stop_step = 1;
4920 print_end_stepping_range_reason ();
4921 stop_stepping (ecs);
4926 if ((stop_pc == stop_pc_sal.pc)
4927 && (ecs->event_thread->current_line != stop_pc_sal.line
4928 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
4930 /* We are at the start of a different line. So stop. Note that
4931 we don't stop if we step into the middle of a different line.
4932 That is said to make things like for (;;) statements work
4935 fprintf_unfiltered (gdb_stdlog,
4936 "infrun: stepped to a different line\n");
4937 ecs->event_thread->control.stop_step = 1;
4938 print_end_stepping_range_reason ();
4939 stop_stepping (ecs);
4943 /* We aren't done stepping.
4945 Optimize by setting the stepping range to the line.
4946 (We might not be in the original line, but if we entered a
4947 new line in mid-statement, we continue stepping. This makes
4948 things like for(;;) statements work better.) */
4950 ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
4951 ecs->event_thread->control.step_range_end = stop_pc_sal.end;
4952 set_step_info (frame, stop_pc_sal);
4955 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
4959 /* Is thread TP in the middle of single-stepping? */
4962 currently_stepping (struct thread_info *tp)
4964 return ((tp->control.step_range_end
4965 && tp->control.step_resume_breakpoint == NULL)
4966 || tp->control.trap_expected
4967 || tp->stepping_through_solib_after_catch
4968 || bpstat_should_step ());
4971 /* Returns true if any thread *but* the one passed in "data" is in the
4972 middle of stepping or of handling a "next". */
4975 currently_stepping_or_nexting_callback (struct thread_info *tp, void *data)
4980 return (tp->control.step_range_end
4981 || tp->control.trap_expected
4982 || tp->stepping_through_solib_after_catch);
4985 /* Inferior has stepped into a subroutine call with source code that
4986 we should not step over. Do step to the first line of code in
4990 handle_step_into_function (struct gdbarch *gdbarch,
4991 struct execution_control_state *ecs)
4994 struct symtab_and_line stop_func_sal, sr_sal;
4996 s = find_pc_symtab (stop_pc);
4997 if (s && s->language != language_asm)
4998 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
4999 ecs->stop_func_start);
5001 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
5002 /* Use the step_resume_break to step until the end of the prologue,
5003 even if that involves jumps (as it seems to on the vax under
5005 /* If the prologue ends in the middle of a source line, continue to
5006 the end of that source line (if it is still within the function).
5007 Otherwise, just go to end of prologue. */
5008 if (stop_func_sal.end
5009 && stop_func_sal.pc != ecs->stop_func_start
5010 && stop_func_sal.end < ecs->stop_func_end)
5011 ecs->stop_func_start = stop_func_sal.end;
5013 /* Architectures which require breakpoint adjustment might not be able
5014 to place a breakpoint at the computed address. If so, the test
5015 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5016 ecs->stop_func_start to an address at which a breakpoint may be
5017 legitimately placed.
5019 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5020 made, GDB will enter an infinite loop when stepping through
5021 optimized code consisting of VLIW instructions which contain
5022 subinstructions corresponding to different source lines. On
5023 FR-V, it's not permitted to place a breakpoint on any but the
5024 first subinstruction of a VLIW instruction. When a breakpoint is
5025 set, GDB will adjust the breakpoint address to the beginning of
5026 the VLIW instruction. Thus, we need to make the corresponding
5027 adjustment here when computing the stop address. */
5029 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
5031 ecs->stop_func_start
5032 = gdbarch_adjust_breakpoint_address (gdbarch,
5033 ecs->stop_func_start);
5036 if (ecs->stop_func_start == stop_pc)
5038 /* We are already there: stop now. */
5039 ecs->event_thread->control.stop_step = 1;
5040 print_end_stepping_range_reason ();
5041 stop_stepping (ecs);
5046 /* Put the step-breakpoint there and go until there. */
5047 init_sal (&sr_sal); /* initialize to zeroes */
5048 sr_sal.pc = ecs->stop_func_start;
5049 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
5050 sr_sal.pspace = get_frame_program_space (get_current_frame ());
5052 /* Do not specify what the fp should be when we stop since on
5053 some machines the prologue is where the new fp value is
5055 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
5057 /* And make sure stepping stops right away then. */
5058 ecs->event_thread->control.step_range_end
5059 = ecs->event_thread->control.step_range_start;
5064 /* Inferior has stepped backward into a subroutine call with source
5065 code that we should not step over. Do step to the beginning of the
5066 last line of code in it. */
5069 handle_step_into_function_backward (struct gdbarch *gdbarch,
5070 struct execution_control_state *ecs)
5073 struct symtab_and_line stop_func_sal;
5075 s = find_pc_symtab (stop_pc);
5076 if (s && s->language != language_asm)
5077 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5078 ecs->stop_func_start);
5080 stop_func_sal = find_pc_line (stop_pc, 0);
5082 /* OK, we're just going to keep stepping here. */
5083 if (stop_func_sal.pc == stop_pc)
5085 /* We're there already. Just stop stepping now. */
5086 ecs->event_thread->control.stop_step = 1;
5087 print_end_stepping_range_reason ();
5088 stop_stepping (ecs);
5092 /* Else just reset the step range and keep going.
5093 No step-resume breakpoint, they don't work for
5094 epilogues, which can have multiple entry paths. */
5095 ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5096 ecs->event_thread->control.step_range_end = stop_func_sal.end;
5102 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5103 This is used to both functions and to skip over code. */
5106 insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5107 struct symtab_and_line sr_sal,
5108 struct frame_id sr_id)
5110 /* There should never be more than one step-resume or longjmp-resume
5111 breakpoint per thread, so we should never be setting a new
5112 step_resume_breakpoint when one is already active. */
5113 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5116 fprintf_unfiltered (gdb_stdlog,
5117 "infrun: inserting step-resume breakpoint at %s\n",
5118 paddress (gdbarch, sr_sal.pc));
5120 inferior_thread ()->control.step_resume_breakpoint
5121 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, bp_step_resume);
5124 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
5125 to skip a potential signal handler.
5127 This is called with the interrupted function's frame. The signal
5128 handler, when it returns, will resume the interrupted function at
5132 insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
5134 struct symtab_and_line sr_sal;
5135 struct gdbarch *gdbarch;
5137 gdb_assert (return_frame != NULL);
5138 init_sal (&sr_sal); /* initialize to zeros */
5140 gdbarch = get_frame_arch (return_frame);
5141 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
5142 sr_sal.section = find_pc_overlay (sr_sal.pc);
5143 sr_sal.pspace = get_frame_program_space (return_frame);
5145 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5146 get_stack_frame_id (return_frame));
5149 /* Similar to insert_step_resume_breakpoint_at_frame, except
5150 but a breakpoint at the previous frame's PC. This is used to
5151 skip a function after stepping into it (for "next" or if the called
5152 function has no debugging information).
5154 The current function has almost always been reached by single
5155 stepping a call or return instruction. NEXT_FRAME belongs to the
5156 current function, and the breakpoint will be set at the caller's
5159 This is a separate function rather than reusing
5160 insert_step_resume_breakpoint_at_frame in order to avoid
5161 get_prev_frame, which may stop prematurely (see the implementation
5162 of frame_unwind_caller_id for an example). */
5165 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
5167 struct symtab_and_line sr_sal;
5168 struct gdbarch *gdbarch;
5170 /* We shouldn't have gotten here if we don't know where the call site
5172 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
5174 init_sal (&sr_sal); /* initialize to zeros */
5176 gdbarch = frame_unwind_caller_arch (next_frame);
5177 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
5178 frame_unwind_caller_pc (next_frame));
5179 sr_sal.section = find_pc_overlay (sr_sal.pc);
5180 sr_sal.pspace = frame_unwind_program_space (next_frame);
5182 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5183 frame_unwind_caller_id (next_frame));
5186 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5187 new breakpoint at the target of a jmp_buf. The handling of
5188 longjmp-resume uses the same mechanisms used for handling
5189 "step-resume" breakpoints. */
5192 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
5194 /* There should never be more than one step-resume or longjmp-resume
5195 breakpoint per thread, so we should never be setting a new
5196 longjmp_resume_breakpoint when one is already active. */
5197 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5200 fprintf_unfiltered (gdb_stdlog,
5201 "infrun: inserting longjmp-resume breakpoint at %s\n",
5202 paddress (gdbarch, pc));
5204 inferior_thread ()->control.step_resume_breakpoint =
5205 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
5208 /* Insert an exception resume breakpoint. TP is the thread throwing
5209 the exception. The block B is the block of the unwinder debug hook
5210 function. FRAME is the frame corresponding to the call to this
5211 function. SYM is the symbol of the function argument holding the
5212 target PC of the exception. */
5215 insert_exception_resume_breakpoint (struct thread_info *tp,
5217 struct frame_info *frame,
5220 struct gdb_exception e;
5222 /* We want to ignore errors here. */
5223 TRY_CATCH (e, RETURN_MASK_ERROR)
5225 struct symbol *vsym;
5226 struct value *value;
5228 struct breakpoint *bp;
5230 vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
5231 value = read_var_value (vsym, frame);
5232 /* If the value was optimized out, revert to the old behavior. */
5233 if (! value_optimized_out (value))
5235 handler = value_as_address (value);
5238 fprintf_unfiltered (gdb_stdlog,
5239 "infrun: exception resume at %lx\n",
5240 (unsigned long) handler);
5242 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5243 handler, bp_exception_resume);
5244 bp->thread = tp->num;
5245 inferior_thread ()->control.exception_resume_breakpoint = bp;
5250 /* This is called when an exception has been intercepted. Check to
5251 see whether the exception's destination is of interest, and if so,
5252 set an exception resume breakpoint there. */
5255 check_exception_resume (struct execution_control_state *ecs,
5256 struct frame_info *frame, struct symbol *func)
5258 struct gdb_exception e;
5260 TRY_CATCH (e, RETURN_MASK_ERROR)
5263 struct dict_iterator iter;
5267 /* The exception breakpoint is a thread-specific breakpoint on
5268 the unwinder's debug hook, declared as:
5270 void _Unwind_DebugHook (void *cfa, void *handler);
5272 The CFA argument indicates the frame to which control is
5273 about to be transferred. HANDLER is the destination PC.
5275 We ignore the CFA and set a temporary breakpoint at HANDLER.
5276 This is not extremely efficient but it avoids issues in gdb
5277 with computing the DWARF CFA, and it also works even in weird
5278 cases such as throwing an exception from inside a signal
5281 b = SYMBOL_BLOCK_VALUE (func);
5282 ALL_BLOCK_SYMBOLS (b, iter, sym)
5284 if (!SYMBOL_IS_ARGUMENT (sym))
5291 insert_exception_resume_breakpoint (ecs->event_thread,
5300 stop_stepping (struct execution_control_state *ecs)
5303 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
5305 /* Let callers know we don't want to wait for the inferior anymore. */
5306 ecs->wait_some_more = 0;
5309 /* This function handles various cases where we need to continue
5310 waiting for the inferior. */
5311 /* (Used to be the keep_going: label in the old wait_for_inferior) */
5314 keep_going (struct execution_control_state *ecs)
5316 /* Make sure normal_stop is called if we get a QUIT handled before
5318 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
5320 /* Save the pc before execution, to compare with pc after stop. */
5321 ecs->event_thread->prev_pc
5322 = regcache_read_pc (get_thread_regcache (ecs->ptid));
5324 /* If we did not do break;, it means we should keep running the
5325 inferior and not return to debugger. */
5327 if (ecs->event_thread->control.trap_expected
5328 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP)
5330 /* We took a signal (which we are supposed to pass through to
5331 the inferior, else we'd not get here) and we haven't yet
5332 gotten our trap. Simply continue. */
5334 discard_cleanups (old_cleanups);
5335 resume (currently_stepping (ecs->event_thread),
5336 ecs->event_thread->suspend.stop_signal);
5340 /* Either the trap was not expected, but we are continuing
5341 anyway (the user asked that this signal be passed to the
5344 The signal was SIGTRAP, e.g. it was our signal, but we
5345 decided we should resume from it.
5347 We're going to run this baby now!
5349 Note that insert_breakpoints won't try to re-insert
5350 already inserted breakpoints. Therefore, we don't
5351 care if breakpoints were already inserted, or not. */
5353 if (ecs->event_thread->stepping_over_breakpoint)
5355 struct regcache *thread_regcache = get_thread_regcache (ecs->ptid);
5357 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
5358 /* Since we can't do a displaced step, we have to remove
5359 the breakpoint while we step it. To keep things
5360 simple, we remove them all. */
5361 remove_breakpoints ();
5365 struct gdb_exception e;
5367 /* Stop stepping when inserting breakpoints
5369 TRY_CATCH (e, RETURN_MASK_ERROR)
5371 insert_breakpoints ();
5375 exception_print (gdb_stderr, e);
5376 stop_stepping (ecs);
5381 ecs->event_thread->control.trap_expected
5382 = ecs->event_thread->stepping_over_breakpoint;
5384 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5385 specifies that such a signal should be delivered to the
5388 Typically, this would occure when a user is debugging a
5389 target monitor on a simulator: the target monitor sets a
5390 breakpoint; the simulator encounters this break-point and
5391 halts the simulation handing control to GDB; GDB, noteing
5392 that the break-point isn't valid, returns control back to the
5393 simulator; the simulator then delivers the hardware
5394 equivalent of a SIGNAL_TRAP to the program being debugged. */
5396 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
5397 && !signal_program[ecs->event_thread->suspend.stop_signal])
5398 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
5400 discard_cleanups (old_cleanups);
5401 resume (currently_stepping (ecs->event_thread),
5402 ecs->event_thread->suspend.stop_signal);
5405 prepare_to_wait (ecs);
5408 /* This function normally comes after a resume, before
5409 handle_inferior_event exits. It takes care of any last bits of
5410 housekeeping, and sets the all-important wait_some_more flag. */
5413 prepare_to_wait (struct execution_control_state *ecs)
5416 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
5418 /* This is the old end of the while loop. Let everybody know we
5419 want to wait for the inferior some more and get called again
5421 ecs->wait_some_more = 1;
5424 /* Several print_*_reason functions to print why the inferior has stopped.
5425 We always print something when the inferior exits, or receives a signal.
5426 The rest of the cases are dealt with later on in normal_stop and
5427 print_it_typical. Ideally there should be a call to one of these
5428 print_*_reason functions functions from handle_inferior_event each time
5429 stop_stepping is called. */
5431 /* Print why the inferior has stopped.
5432 We are done with a step/next/si/ni command, print why the inferior has
5433 stopped. For now print nothing. Print a message only if not in the middle
5434 of doing a "step n" operation for n > 1. */
5437 print_end_stepping_range_reason (void)
5439 if ((!inferior_thread ()->step_multi
5440 || !inferior_thread ()->control.stop_step)
5441 && ui_out_is_mi_like_p (uiout))
5442 ui_out_field_string (uiout, "reason",
5443 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
5446 /* The inferior was terminated by a signal, print why it stopped. */
5449 print_signal_exited_reason (enum target_signal siggnal)
5451 annotate_signalled ();
5452 if (ui_out_is_mi_like_p (uiout))
5454 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
5455 ui_out_text (uiout, "\nProgram terminated with signal ");
5456 annotate_signal_name ();
5457 ui_out_field_string (uiout, "signal-name",
5458 target_signal_to_name (siggnal));
5459 annotate_signal_name_end ();
5460 ui_out_text (uiout, ", ");
5461 annotate_signal_string ();
5462 ui_out_field_string (uiout, "signal-meaning",
5463 target_signal_to_string (siggnal));
5464 annotate_signal_string_end ();
5465 ui_out_text (uiout, ".\n");
5466 ui_out_text (uiout, "The program no longer exists.\n");
5469 /* The inferior program is finished, print why it stopped. */
5472 print_exited_reason (int exitstatus)
5474 annotate_exited (exitstatus);
5477 if (ui_out_is_mi_like_p (uiout))
5478 ui_out_field_string (uiout, "reason",
5479 async_reason_lookup (EXEC_ASYNC_EXITED));
5480 ui_out_text (uiout, "\nProgram exited with code ");
5481 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
5482 ui_out_text (uiout, ".\n");
5486 if (ui_out_is_mi_like_p (uiout))
5488 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
5489 ui_out_text (uiout, "\nProgram exited normally.\n");
5491 /* Support the --return-child-result option. */
5492 return_child_result_value = exitstatus;
5495 /* Signal received, print why the inferior has stopped. The signal table
5496 tells us to print about it. */
5499 print_signal_received_reason (enum target_signal siggnal)
5503 if (siggnal == TARGET_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
5505 struct thread_info *t = inferior_thread ();
5507 ui_out_text (uiout, "\n[");
5508 ui_out_field_string (uiout, "thread-name",
5509 target_pid_to_str (t->ptid));
5510 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
5511 ui_out_text (uiout, " stopped");
5515 ui_out_text (uiout, "\nProgram received signal ");
5516 annotate_signal_name ();
5517 if (ui_out_is_mi_like_p (uiout))
5519 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
5520 ui_out_field_string (uiout, "signal-name",
5521 target_signal_to_name (siggnal));
5522 annotate_signal_name_end ();
5523 ui_out_text (uiout, ", ");
5524 annotate_signal_string ();
5525 ui_out_field_string (uiout, "signal-meaning",
5526 target_signal_to_string (siggnal));
5527 annotate_signal_string_end ();
5529 ui_out_text (uiout, ".\n");
5532 /* Reverse execution: target ran out of history info, print why the inferior
5536 print_no_history_reason (void)
5538 ui_out_text (uiout, "\nNo more reverse-execution history.\n");
5541 /* Here to return control to GDB when the inferior stops for real.
5542 Print appropriate messages, remove breakpoints, give terminal our modes.
5544 STOP_PRINT_FRAME nonzero means print the executing frame
5545 (pc, function, args, file, line number and line text).
5546 BREAKPOINTS_FAILED nonzero means stop was due to error
5547 attempting to insert breakpoints. */
5552 struct target_waitstatus last;
5554 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
5556 get_last_target_status (&last_ptid, &last);
5558 /* If an exception is thrown from this point on, make sure to
5559 propagate GDB's knowledge of the executing state to the
5560 frontend/user running state. A QUIT is an easy exception to see
5561 here, so do this before any filtered output. */
5563 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
5564 else if (last.kind != TARGET_WAITKIND_SIGNALLED
5565 && last.kind != TARGET_WAITKIND_EXITED)
5566 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
5568 /* In non-stop mode, we don't want GDB to switch threads behind the
5569 user's back, to avoid races where the user is typing a command to
5570 apply to thread x, but GDB switches to thread y before the user
5571 finishes entering the command. */
5573 /* As with the notification of thread events, we want to delay
5574 notifying the user that we've switched thread context until
5575 the inferior actually stops.
5577 There's no point in saying anything if the inferior has exited.
5578 Note that SIGNALLED here means "exited with a signal", not
5579 "received a signal". */
5581 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
5582 && target_has_execution
5583 && last.kind != TARGET_WAITKIND_SIGNALLED
5584 && last.kind != TARGET_WAITKIND_EXITED)
5586 target_terminal_ours_for_output ();
5587 printf_filtered (_("[Switching to %s]\n"),
5588 target_pid_to_str (inferior_ptid));
5589 annotate_thread_changed ();
5590 previous_inferior_ptid = inferior_ptid;
5593 if (!breakpoints_always_inserted_mode () && target_has_execution)
5595 if (remove_breakpoints ())
5597 target_terminal_ours_for_output ();
5598 printf_filtered (_("Cannot remove breakpoints because "
5599 "program is no longer writable.\nFurther "
5600 "execution is probably impossible.\n"));
5604 /* If an auto-display called a function and that got a signal,
5605 delete that auto-display to avoid an infinite recursion. */
5607 if (stopped_by_random_signal)
5608 disable_current_display ();
5610 /* Don't print a message if in the middle of doing a "step n"
5611 operation for n > 1 */
5612 if (target_has_execution
5613 && last.kind != TARGET_WAITKIND_SIGNALLED
5614 && last.kind != TARGET_WAITKIND_EXITED
5615 && inferior_thread ()->step_multi
5616 && inferior_thread ()->control.stop_step)
5619 target_terminal_ours ();
5621 /* Set the current source location. This will also happen if we
5622 display the frame below, but the current SAL will be incorrect
5623 during a user hook-stop function. */
5624 if (has_stack_frames () && !stop_stack_dummy)
5625 set_current_sal_from_frame (get_current_frame (), 1);
5627 /* Let the user/frontend see the threads as stopped. */
5628 do_cleanups (old_chain);
5630 /* Look up the hook_stop and run it (CLI internally handles problem
5631 of stop_command's pre-hook not existing). */
5633 catch_errors (hook_stop_stub, stop_command,
5634 "Error while running hook_stop:\n", RETURN_MASK_ALL);
5636 if (!has_stack_frames ())
5639 if (last.kind == TARGET_WAITKIND_SIGNALLED
5640 || last.kind == TARGET_WAITKIND_EXITED)
5643 /* Select innermost stack frame - i.e., current frame is frame 0,
5644 and current location is based on that.
5645 Don't do this on return from a stack dummy routine,
5646 or if the program has exited. */
5648 if (!stop_stack_dummy)
5650 select_frame (get_current_frame ());
5652 /* Print current location without a level number, if
5653 we have changed functions or hit a breakpoint.
5654 Print source line if we have one.
5655 bpstat_print() contains the logic deciding in detail
5656 what to print, based on the event(s) that just occurred. */
5658 /* If --batch-silent is enabled then there's no need to print the current
5659 source location, and to try risks causing an error message about
5660 missing source files. */
5661 if (stop_print_frame && !batch_silent)
5665 int do_frame_printing = 1;
5666 struct thread_info *tp = inferior_thread ();
5668 bpstat_ret = bpstat_print (tp->control.stop_bpstat);
5672 /* If we had hit a shared library event breakpoint,
5673 bpstat_print would print out this message. If we hit
5674 an OS-level shared library event, do the same
5676 if (last.kind == TARGET_WAITKIND_LOADED)
5678 printf_filtered (_("Stopped due to shared library event\n"));
5679 source_flag = SRC_LINE; /* something bogus */
5680 do_frame_printing = 0;
5684 /* FIXME: cagney/2002-12-01: Given that a frame ID does
5685 (or should) carry around the function and does (or
5686 should) use that when doing a frame comparison. */
5687 if (tp->control.stop_step
5688 && frame_id_eq (tp->control.step_frame_id,
5689 get_frame_id (get_current_frame ()))
5690 && step_start_function == find_pc_function (stop_pc))
5691 source_flag = SRC_LINE; /* finished step, just
5692 print source line */
5694 source_flag = SRC_AND_LOC; /* print location and
5697 case PRINT_SRC_AND_LOC:
5698 source_flag = SRC_AND_LOC; /* print location and
5701 case PRINT_SRC_ONLY:
5702 source_flag = SRC_LINE;
5705 source_flag = SRC_LINE; /* something bogus */
5706 do_frame_printing = 0;
5709 internal_error (__FILE__, __LINE__, _("Unknown value."));
5712 /* The behavior of this routine with respect to the source
5714 SRC_LINE: Print only source line
5715 LOCATION: Print only location
5716 SRC_AND_LOC: Print location and source line */
5717 if (do_frame_printing)
5718 print_stack_frame (get_selected_frame (NULL), 0, source_flag);
5720 /* Display the auto-display expressions. */
5725 /* Save the function value return registers, if we care.
5726 We might be about to restore their previous contents. */
5727 if (inferior_thread ()->control.proceed_to_finish)
5729 /* This should not be necessary. */
5731 regcache_xfree (stop_registers);
5733 /* NB: The copy goes through to the target picking up the value of
5734 all the registers. */
5735 stop_registers = regcache_dup (get_current_regcache ());
5738 if (stop_stack_dummy == STOP_STACK_DUMMY)
5740 /* Pop the empty frame that contains the stack dummy.
5741 This also restores inferior state prior to the call
5742 (struct infcall_suspend_state). */
5743 struct frame_info *frame = get_current_frame ();
5745 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
5747 /* frame_pop() calls reinit_frame_cache as the last thing it
5748 does which means there's currently no selected frame. We
5749 don't need to re-establish a selected frame if the dummy call
5750 returns normally, that will be done by
5751 restore_infcall_control_state. However, we do have to handle
5752 the case where the dummy call is returning after being
5753 stopped (e.g. the dummy call previously hit a breakpoint).
5754 We can't know which case we have so just always re-establish
5755 a selected frame here. */
5756 select_frame (get_current_frame ());
5760 annotate_stopped ();
5762 /* Suppress the stop observer if we're in the middle of:
5764 - a step n (n > 1), as there still more steps to be done.
5766 - a "finish" command, as the observer will be called in
5767 finish_command_continuation, so it can include the inferior
5768 function's return value.
5770 - calling an inferior function, as we pretend we inferior didn't
5771 run at all. The return value of the call is handled by the
5772 expression evaluator, through call_function_by_hand. */
5774 if (!target_has_execution
5775 || last.kind == TARGET_WAITKIND_SIGNALLED
5776 || last.kind == TARGET_WAITKIND_EXITED
5777 || (!inferior_thread ()->step_multi
5778 && !(inferior_thread ()->control.stop_bpstat
5779 && inferior_thread ()->control.proceed_to_finish)
5780 && !inferior_thread ()->control.in_infcall))
5782 if (!ptid_equal (inferior_ptid, null_ptid))
5783 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
5786 observer_notify_normal_stop (NULL, stop_print_frame);
5789 if (target_has_execution)
5791 if (last.kind != TARGET_WAITKIND_SIGNALLED
5792 && last.kind != TARGET_WAITKIND_EXITED)
5793 /* Delete the breakpoint we stopped at, if it wants to be deleted.
5794 Delete any breakpoint that is to be deleted at the next stop. */
5795 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
5798 /* Try to get rid of automatically added inferiors that are no
5799 longer needed. Keeping those around slows down things linearly.
5800 Note that this never removes the current inferior. */
5805 hook_stop_stub (void *cmd)
5807 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
5812 signal_stop_state (int signo)
5814 return signal_stop[signo];
5818 signal_print_state (int signo)
5820 return signal_print[signo];
5824 signal_pass_state (int signo)
5826 return signal_program[signo];
5830 signal_stop_update (int signo, int state)
5832 int ret = signal_stop[signo];
5834 signal_stop[signo] = state;
5839 signal_print_update (int signo, int state)
5841 int ret = signal_print[signo];
5843 signal_print[signo] = state;
5848 signal_pass_update (int signo, int state)
5850 int ret = signal_program[signo];
5852 signal_program[signo] = state;
5857 sig_print_header (void)
5859 printf_filtered (_("Signal Stop\tPrint\tPass "
5860 "to program\tDescription\n"));
5864 sig_print_info (enum target_signal oursig)
5866 const char *name = target_signal_to_name (oursig);
5867 int name_padding = 13 - strlen (name);
5869 if (name_padding <= 0)
5872 printf_filtered ("%s", name);
5873 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
5874 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
5875 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
5876 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
5877 printf_filtered ("%s\n", target_signal_to_string (oursig));
5880 /* Specify how various signals in the inferior should be handled. */
5883 handle_command (char *args, int from_tty)
5886 int digits, wordlen;
5887 int sigfirst, signum, siglast;
5888 enum target_signal oursig;
5891 unsigned char *sigs;
5892 struct cleanup *old_chain;
5896 error_no_arg (_("signal to handle"));
5899 /* Allocate and zero an array of flags for which signals to handle. */
5901 nsigs = (int) TARGET_SIGNAL_LAST;
5902 sigs = (unsigned char *) alloca (nsigs);
5903 memset (sigs, 0, nsigs);
5905 /* Break the command line up into args. */
5907 argv = gdb_buildargv (args);
5908 old_chain = make_cleanup_freeargv (argv);
5910 /* Walk through the args, looking for signal oursigs, signal names, and
5911 actions. Signal numbers and signal names may be interspersed with
5912 actions, with the actions being performed for all signals cumulatively
5913 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
5915 while (*argv != NULL)
5917 wordlen = strlen (*argv);
5918 for (digits = 0; isdigit ((*argv)[digits]); digits++)
5922 sigfirst = siglast = -1;
5924 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
5926 /* Apply action to all signals except those used by the
5927 debugger. Silently skip those. */
5930 siglast = nsigs - 1;
5932 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
5934 SET_SIGS (nsigs, sigs, signal_stop);
5935 SET_SIGS (nsigs, sigs, signal_print);
5937 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
5939 UNSET_SIGS (nsigs, sigs, signal_program);
5941 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
5943 SET_SIGS (nsigs, sigs, signal_print);
5945 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
5947 SET_SIGS (nsigs, sigs, signal_program);
5949 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
5951 UNSET_SIGS (nsigs, sigs, signal_stop);
5953 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
5955 SET_SIGS (nsigs, sigs, signal_program);
5957 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
5959 UNSET_SIGS (nsigs, sigs, signal_print);
5960 UNSET_SIGS (nsigs, sigs, signal_stop);
5962 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
5964 UNSET_SIGS (nsigs, sigs, signal_program);
5966 else if (digits > 0)
5968 /* It is numeric. The numeric signal refers to our own
5969 internal signal numbering from target.h, not to host/target
5970 signal number. This is a feature; users really should be
5971 using symbolic names anyway, and the common ones like
5972 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
5974 sigfirst = siglast = (int)
5975 target_signal_from_command (atoi (*argv));
5976 if ((*argv)[digits] == '-')
5979 target_signal_from_command (atoi ((*argv) + digits + 1));
5981 if (sigfirst > siglast)
5983 /* Bet he didn't figure we'd think of this case... */
5991 oursig = target_signal_from_name (*argv);
5992 if (oursig != TARGET_SIGNAL_UNKNOWN)
5994 sigfirst = siglast = (int) oursig;
5998 /* Not a number and not a recognized flag word => complain. */
5999 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
6003 /* If any signal numbers or symbol names were found, set flags for
6004 which signals to apply actions to. */
6006 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
6008 switch ((enum target_signal) signum)
6010 case TARGET_SIGNAL_TRAP:
6011 case TARGET_SIGNAL_INT:
6012 if (!allsigs && !sigs[signum])
6014 if (query (_("%s is used by the debugger.\n\
6015 Are you sure you want to change it? "),
6016 target_signal_to_name ((enum target_signal) signum)))
6022 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6023 gdb_flush (gdb_stdout);
6027 case TARGET_SIGNAL_0:
6028 case TARGET_SIGNAL_DEFAULT:
6029 case TARGET_SIGNAL_UNKNOWN:
6030 /* Make sure that "all" doesn't print these. */
6041 for (signum = 0; signum < nsigs; signum++)
6044 target_notice_signals (inferior_ptid);
6048 /* Show the results. */
6049 sig_print_header ();
6050 for (; signum < nsigs; signum++)
6052 sig_print_info (signum);
6058 do_cleanups (old_chain);
6062 xdb_handle_command (char *args, int from_tty)
6065 struct cleanup *old_chain;
6068 error_no_arg (_("xdb command"));
6070 /* Break the command line up into args. */
6072 argv = gdb_buildargv (args);
6073 old_chain = make_cleanup_freeargv (argv);
6074 if (argv[1] != (char *) NULL)
6079 bufLen = strlen (argv[0]) + 20;
6080 argBuf = (char *) xmalloc (bufLen);
6084 enum target_signal oursig;
6086 oursig = target_signal_from_name (argv[0]);
6087 memset (argBuf, 0, bufLen);
6088 if (strcmp (argv[1], "Q") == 0)
6089 sprintf (argBuf, "%s %s", argv[0], "noprint");
6092 if (strcmp (argv[1], "s") == 0)
6094 if (!signal_stop[oursig])
6095 sprintf (argBuf, "%s %s", argv[0], "stop");
6097 sprintf (argBuf, "%s %s", argv[0], "nostop");
6099 else if (strcmp (argv[1], "i") == 0)
6101 if (!signal_program[oursig])
6102 sprintf (argBuf, "%s %s", argv[0], "pass");
6104 sprintf (argBuf, "%s %s", argv[0], "nopass");
6106 else if (strcmp (argv[1], "r") == 0)
6108 if (!signal_print[oursig])
6109 sprintf (argBuf, "%s %s", argv[0], "print");
6111 sprintf (argBuf, "%s %s", argv[0], "noprint");
6117 handle_command (argBuf, from_tty);
6119 printf_filtered (_("Invalid signal handling flag.\n"));
6124 do_cleanups (old_chain);
6127 /* Print current contents of the tables set by the handle command.
6128 It is possible we should just be printing signals actually used
6129 by the current target (but for things to work right when switching
6130 targets, all signals should be in the signal tables). */
6133 signals_info (char *signum_exp, int from_tty)
6135 enum target_signal oursig;
6137 sig_print_header ();
6141 /* First see if this is a symbol name. */
6142 oursig = target_signal_from_name (signum_exp);
6143 if (oursig == TARGET_SIGNAL_UNKNOWN)
6145 /* No, try numeric. */
6147 target_signal_from_command (parse_and_eval_long (signum_exp));
6149 sig_print_info (oursig);
6153 printf_filtered ("\n");
6154 /* These ugly casts brought to you by the native VAX compiler. */
6155 for (oursig = TARGET_SIGNAL_FIRST;
6156 (int) oursig < (int) TARGET_SIGNAL_LAST;
6157 oursig = (enum target_signal) ((int) oursig + 1))
6161 if (oursig != TARGET_SIGNAL_UNKNOWN
6162 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
6163 sig_print_info (oursig);
6166 printf_filtered (_("\nUse the \"handle\" command "
6167 "to change these tables.\n"));
6170 /* The $_siginfo convenience variable is a bit special. We don't know
6171 for sure the type of the value until we actually have a chance to
6172 fetch the data. The type can change depending on gdbarch, so it it
6173 also dependent on which thread you have selected.
6175 1. making $_siginfo be an internalvar that creates a new value on
6178 2. making the value of $_siginfo be an lval_computed value. */
6180 /* This function implements the lval_computed support for reading a
6184 siginfo_value_read (struct value *v)
6186 LONGEST transferred;
6189 target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO,
6191 value_contents_all_raw (v),
6193 TYPE_LENGTH (value_type (v)));
6195 if (transferred != TYPE_LENGTH (value_type (v)))
6196 error (_("Unable to read siginfo"));
6199 /* This function implements the lval_computed support for writing a
6203 siginfo_value_write (struct value *v, struct value *fromval)
6205 LONGEST transferred;
6207 transferred = target_write (¤t_target,
6208 TARGET_OBJECT_SIGNAL_INFO,
6210 value_contents_all_raw (fromval),
6212 TYPE_LENGTH (value_type (fromval)));
6214 if (transferred != TYPE_LENGTH (value_type (fromval)))
6215 error (_("Unable to write siginfo"));
6218 static struct lval_funcs siginfo_value_funcs =
6224 /* Return a new value with the correct type for the siginfo object of
6225 the current thread using architecture GDBARCH. Return a void value
6226 if there's no object available. */
6228 static struct value *
6229 siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var)
6231 if (target_has_stack
6232 && !ptid_equal (inferior_ptid, null_ptid)
6233 && gdbarch_get_siginfo_type_p (gdbarch))
6235 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6237 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
6240 return allocate_value (builtin_type (gdbarch)->builtin_void);
6244 /* infcall_suspend_state contains state about the program itself like its
6245 registers and any signal it received when it last stopped.
6246 This state must be restored regardless of how the inferior function call
6247 ends (either successfully, or after it hits a breakpoint or signal)
6248 if the program is to properly continue where it left off. */
6250 struct infcall_suspend_state
6252 struct thread_suspend_state thread_suspend;
6253 struct inferior_suspend_state inferior_suspend;
6257 struct regcache *registers;
6259 /* Format of SIGINFO_DATA or NULL if it is not present. */
6260 struct gdbarch *siginfo_gdbarch;
6262 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6263 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6264 content would be invalid. */
6265 gdb_byte *siginfo_data;
6268 struct infcall_suspend_state *
6269 save_infcall_suspend_state (void)
6271 struct infcall_suspend_state *inf_state;
6272 struct thread_info *tp = inferior_thread ();
6273 struct inferior *inf = current_inferior ();
6274 struct regcache *regcache = get_current_regcache ();
6275 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6276 gdb_byte *siginfo_data = NULL;
6278 if (gdbarch_get_siginfo_type_p (gdbarch))
6280 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6281 size_t len = TYPE_LENGTH (type);
6282 struct cleanup *back_to;
6284 siginfo_data = xmalloc (len);
6285 back_to = make_cleanup (xfree, siginfo_data);
6287 if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6288 siginfo_data, 0, len) == len)
6289 discard_cleanups (back_to);
6292 /* Errors ignored. */
6293 do_cleanups (back_to);
6294 siginfo_data = NULL;
6298 inf_state = XZALLOC (struct infcall_suspend_state);
6302 inf_state->siginfo_gdbarch = gdbarch;
6303 inf_state->siginfo_data = siginfo_data;
6306 inf_state->thread_suspend = tp->suspend;
6307 inf_state->inferior_suspend = inf->suspend;
6309 /* run_inferior_call will not use the signal due to its `proceed' call with
6310 TARGET_SIGNAL_0 anyway. */
6311 tp->suspend.stop_signal = TARGET_SIGNAL_0;
6313 inf_state->stop_pc = stop_pc;
6315 inf_state->registers = regcache_dup (regcache);
6320 /* Restore inferior session state to INF_STATE. */
6323 restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6325 struct thread_info *tp = inferior_thread ();
6326 struct inferior *inf = current_inferior ();
6327 struct regcache *regcache = get_current_regcache ();
6328 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6330 tp->suspend = inf_state->thread_suspend;
6331 inf->suspend = inf_state->inferior_suspend;
6333 stop_pc = inf_state->stop_pc;
6335 if (inf_state->siginfo_gdbarch == gdbarch)
6337 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6338 size_t len = TYPE_LENGTH (type);
6340 /* Errors ignored. */
6341 target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6342 inf_state->siginfo_data, 0, len);
6345 /* The inferior can be gone if the user types "print exit(0)"
6346 (and perhaps other times). */
6347 if (target_has_execution)
6348 /* NB: The register write goes through to the target. */
6349 regcache_cpy (regcache, inf_state->registers);
6351 discard_infcall_suspend_state (inf_state);
6355 do_restore_infcall_suspend_state_cleanup (void *state)
6357 restore_infcall_suspend_state (state);
6361 make_cleanup_restore_infcall_suspend_state
6362 (struct infcall_suspend_state *inf_state)
6364 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
6368 discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6370 regcache_xfree (inf_state->registers);
6371 xfree (inf_state->siginfo_data);
6376 get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
6378 return inf_state->registers;
6381 /* infcall_control_state contains state regarding gdb's control of the
6382 inferior itself like stepping control. It also contains session state like
6383 the user's currently selected frame. */
6385 struct infcall_control_state
6387 struct thread_control_state thread_control;
6388 struct inferior_control_state inferior_control;
6391 enum stop_stack_kind stop_stack_dummy;
6392 int stopped_by_random_signal;
6393 int stop_after_trap;
6395 /* ID if the selected frame when the inferior function call was made. */
6396 struct frame_id selected_frame_id;
6399 /* Save all of the information associated with the inferior<==>gdb
6402 struct infcall_control_state *
6403 save_infcall_control_state (void)
6405 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
6406 struct thread_info *tp = inferior_thread ();
6407 struct inferior *inf = current_inferior ();
6409 inf_status->thread_control = tp->control;
6410 inf_status->inferior_control = inf->control;
6412 tp->control.step_resume_breakpoint = NULL;
6413 tp->control.exception_resume_breakpoint = NULL;
6415 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6416 chain. If caller's caller is walking the chain, they'll be happier if we
6417 hand them back the original chain when restore_infcall_control_state is
6419 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
6422 inf_status->stop_stack_dummy = stop_stack_dummy;
6423 inf_status->stopped_by_random_signal = stopped_by_random_signal;
6424 inf_status->stop_after_trap = stop_after_trap;
6426 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
6432 restore_selected_frame (void *args)
6434 struct frame_id *fid = (struct frame_id *) args;
6435 struct frame_info *frame;
6437 frame = frame_find_by_id (*fid);
6439 /* If inf_status->selected_frame_id is NULL, there was no previously
6443 warning (_("Unable to restore previously selected frame."));
6447 select_frame (frame);
6452 /* Restore inferior session state to INF_STATUS. */
6455 restore_infcall_control_state (struct infcall_control_state *inf_status)
6457 struct thread_info *tp = inferior_thread ();
6458 struct inferior *inf = current_inferior ();
6460 if (tp->control.step_resume_breakpoint)
6461 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
6463 if (tp->control.exception_resume_breakpoint)
6464 tp->control.exception_resume_breakpoint->disposition
6465 = disp_del_at_next_stop;
6467 /* Handle the bpstat_copy of the chain. */
6468 bpstat_clear (&tp->control.stop_bpstat);
6470 tp->control = inf_status->thread_control;
6471 inf->control = inf_status->inferior_control;
6474 stop_stack_dummy = inf_status->stop_stack_dummy;
6475 stopped_by_random_signal = inf_status->stopped_by_random_signal;
6476 stop_after_trap = inf_status->stop_after_trap;
6478 if (target_has_stack)
6480 /* The point of catch_errors is that if the stack is clobbered,
6481 walking the stack might encounter a garbage pointer and
6482 error() trying to dereference it. */
6484 (restore_selected_frame, &inf_status->selected_frame_id,
6485 "Unable to restore previously selected frame:\n",
6486 RETURN_MASK_ERROR) == 0)
6487 /* Error in restoring the selected frame. Select the innermost
6489 select_frame (get_current_frame ());
6496 do_restore_infcall_control_state_cleanup (void *sts)
6498 restore_infcall_control_state (sts);
6502 make_cleanup_restore_infcall_control_state
6503 (struct infcall_control_state *inf_status)
6505 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
6509 discard_infcall_control_state (struct infcall_control_state *inf_status)
6511 if (inf_status->thread_control.step_resume_breakpoint)
6512 inf_status->thread_control.step_resume_breakpoint->disposition
6513 = disp_del_at_next_stop;
6515 if (inf_status->thread_control.exception_resume_breakpoint)
6516 inf_status->thread_control.exception_resume_breakpoint->disposition
6517 = disp_del_at_next_stop;
6519 /* See save_infcall_control_state for info on stop_bpstat. */
6520 bpstat_clear (&inf_status->thread_control.stop_bpstat);
6526 inferior_has_forked (ptid_t pid, ptid_t *child_pid)
6528 struct target_waitstatus last;
6531 get_last_target_status (&last_ptid, &last);
6533 if (last.kind != TARGET_WAITKIND_FORKED)
6536 if (!ptid_equal (last_ptid, pid))
6539 *child_pid = last.value.related_pid;
6544 inferior_has_vforked (ptid_t pid, ptid_t *child_pid)
6546 struct target_waitstatus last;
6549 get_last_target_status (&last_ptid, &last);
6551 if (last.kind != TARGET_WAITKIND_VFORKED)
6554 if (!ptid_equal (last_ptid, pid))
6557 *child_pid = last.value.related_pid;
6562 inferior_has_execd (ptid_t pid, char **execd_pathname)
6564 struct target_waitstatus last;
6567 get_last_target_status (&last_ptid, &last);
6569 if (last.kind != TARGET_WAITKIND_EXECD)
6572 if (!ptid_equal (last_ptid, pid))
6575 *execd_pathname = xstrdup (last.value.execd_pathname);
6580 inferior_has_called_syscall (ptid_t pid, int *syscall_number)
6582 struct target_waitstatus last;
6585 get_last_target_status (&last_ptid, &last);
6587 if (last.kind != TARGET_WAITKIND_SYSCALL_ENTRY &&
6588 last.kind != TARGET_WAITKIND_SYSCALL_RETURN)
6591 if (!ptid_equal (last_ptid, pid))
6594 *syscall_number = last.value.syscall_number;
6598 /* Oft used ptids */
6600 ptid_t minus_one_ptid;
6602 /* Create a ptid given the necessary PID, LWP, and TID components. */
6605 ptid_build (int pid, long lwp, long tid)
6615 /* Create a ptid from just a pid. */
6618 pid_to_ptid (int pid)
6620 return ptid_build (pid, 0, 0);
6623 /* Fetch the pid (process id) component from a ptid. */
6626 ptid_get_pid (ptid_t ptid)
6631 /* Fetch the lwp (lightweight process) component from a ptid. */
6634 ptid_get_lwp (ptid_t ptid)
6639 /* Fetch the tid (thread id) component from a ptid. */
6642 ptid_get_tid (ptid_t ptid)
6647 /* ptid_equal() is used to test equality of two ptids. */
6650 ptid_equal (ptid_t ptid1, ptid_t ptid2)
6652 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
6653 && ptid1.tid == ptid2.tid);
6656 /* Returns true if PTID represents a process. */
6659 ptid_is_pid (ptid_t ptid)
6661 if (ptid_equal (minus_one_ptid, ptid))
6663 if (ptid_equal (null_ptid, ptid))
6666 return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0);
6670 ptid_match (ptid_t ptid, ptid_t filter)
6672 /* Since both parameters have the same type, prevent easy mistakes
6674 gdb_assert (!ptid_equal (ptid, minus_one_ptid)
6675 && !ptid_equal (ptid, null_ptid));
6677 if (ptid_equal (filter, minus_one_ptid))
6679 if (ptid_is_pid (filter)
6680 && ptid_get_pid (ptid) == ptid_get_pid (filter))
6682 else if (ptid_equal (ptid, filter))
6688 /* restore_inferior_ptid() will be used by the cleanup machinery
6689 to restore the inferior_ptid value saved in a call to
6690 save_inferior_ptid(). */
6693 restore_inferior_ptid (void *arg)
6695 ptid_t *saved_ptid_ptr = arg;
6697 inferior_ptid = *saved_ptid_ptr;
6701 /* Save the value of inferior_ptid so that it may be restored by a
6702 later call to do_cleanups(). Returns the struct cleanup pointer
6703 needed for later doing the cleanup. */
6706 save_inferior_ptid (void)
6708 ptid_t *saved_ptid_ptr;
6710 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
6711 *saved_ptid_ptr = inferior_ptid;
6712 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
6716 /* User interface for reverse debugging:
6717 Set exec-direction / show exec-direction commands
6718 (returns error unless target implements to_set_exec_direction method). */
6720 enum exec_direction_kind execution_direction = EXEC_FORWARD;
6721 static const char exec_forward[] = "forward";
6722 static const char exec_reverse[] = "reverse";
6723 static const char *exec_direction = exec_forward;
6724 static const char *exec_direction_names[] = {
6731 set_exec_direction_func (char *args, int from_tty,
6732 struct cmd_list_element *cmd)
6734 if (target_can_execute_reverse)
6736 if (!strcmp (exec_direction, exec_forward))
6737 execution_direction = EXEC_FORWARD;
6738 else if (!strcmp (exec_direction, exec_reverse))
6739 execution_direction = EXEC_REVERSE;
6743 exec_direction = exec_forward;
6744 error (_("Target does not support this operation."));
6749 show_exec_direction_func (struct ui_file *out, int from_tty,
6750 struct cmd_list_element *cmd, const char *value)
6752 switch (execution_direction) {
6754 fprintf_filtered (out, _("Forward.\n"));
6757 fprintf_filtered (out, _("Reverse.\n"));
6761 fprintf_filtered (out, _("Forward (target `%s' does not "
6762 "support exec-direction).\n"),
6768 /* User interface for non-stop mode. */
6773 set_non_stop (char *args, int from_tty,
6774 struct cmd_list_element *c)
6776 if (target_has_execution)
6778 non_stop_1 = non_stop;
6779 error (_("Cannot change this setting while the inferior is running."));
6782 non_stop = non_stop_1;
6786 show_non_stop (struct ui_file *file, int from_tty,
6787 struct cmd_list_element *c, const char *value)
6789 fprintf_filtered (file,
6790 _("Controlling the inferior in non-stop mode is %s.\n"),
6795 show_schedule_multiple (struct ui_file *file, int from_tty,
6796 struct cmd_list_element *c, const char *value)
6798 fprintf_filtered (file, _("Resuming the execution of threads "
6799 "of all processes is %s.\n"), value);
6803 _initialize_infrun (void)
6808 add_info ("signals", signals_info, _("\
6809 What debugger does when program gets various signals.\n\
6810 Specify a signal as argument to print info on that signal only."));
6811 add_info_alias ("handle", "signals", 0);
6813 add_com ("handle", class_run, handle_command, _("\
6814 Specify how to handle a signal.\n\
6815 Args are signals and actions to apply to those signals.\n\
6816 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6817 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6818 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6819 The special arg \"all\" is recognized to mean all signals except those\n\
6820 used by the debugger, typically SIGTRAP and SIGINT.\n\
6821 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
6822 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
6823 Stop means reenter debugger if this signal happens (implies print).\n\
6824 Print means print a message if this signal happens.\n\
6825 Pass means let program see this signal; otherwise program doesn't know.\n\
6826 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6827 Pass and Stop may be combined."));
6830 add_com ("lz", class_info, signals_info, _("\
6831 What debugger does when program gets various signals.\n\
6832 Specify a signal as argument to print info on that signal only."));
6833 add_com ("z", class_run, xdb_handle_command, _("\
6834 Specify how to handle a signal.\n\
6835 Args are signals and actions to apply to those signals.\n\
6836 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6837 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6838 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6839 The special arg \"all\" is recognized to mean all signals except those\n\
6840 used by the debugger, typically SIGTRAP and SIGINT.\n\
6841 Recognized actions include \"s\" (toggles between stop and nostop),\n\
6842 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
6843 nopass), \"Q\" (noprint)\n\
6844 Stop means reenter debugger if this signal happens (implies print).\n\
6845 Print means print a message if this signal happens.\n\
6846 Pass means let program see this signal; otherwise program doesn't know.\n\
6847 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6848 Pass and Stop may be combined."));
6852 stop_command = add_cmd ("stop", class_obscure,
6853 not_just_help_class_command, _("\
6854 There is no `stop' command, but you can set a hook on `stop'.\n\
6855 This allows you to set a list of commands to be run each time execution\n\
6856 of the program stops."), &cmdlist);
6858 add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
6859 Set inferior debugging."), _("\
6860 Show inferior debugging."), _("\
6861 When non-zero, inferior specific debugging is enabled."),
6864 &setdebuglist, &showdebuglist);
6866 add_setshow_boolean_cmd ("displaced", class_maintenance,
6867 &debug_displaced, _("\
6868 Set displaced stepping debugging."), _("\
6869 Show displaced stepping debugging."), _("\
6870 When non-zero, displaced stepping specific debugging is enabled."),
6872 show_debug_displaced,
6873 &setdebuglist, &showdebuglist);
6875 add_setshow_boolean_cmd ("non-stop", no_class,
6877 Set whether gdb controls the inferior in non-stop mode."), _("\
6878 Show whether gdb controls the inferior in non-stop mode."), _("\
6879 When debugging a multi-threaded program and this setting is\n\
6880 off (the default, also called all-stop mode), when one thread stops\n\
6881 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
6882 all other threads in the program while you interact with the thread of\n\
6883 interest. When you continue or step a thread, you can allow the other\n\
6884 threads to run, or have them remain stopped, but while you inspect any\n\
6885 thread's state, all threads stop.\n\
6887 In non-stop mode, when one thread stops, other threads can continue\n\
6888 to run freely. You'll be able to step each thread independently,\n\
6889 leave it stopped or free to run as needed."),
6895 numsigs = (int) TARGET_SIGNAL_LAST;
6896 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
6897 signal_print = (unsigned char *)
6898 xmalloc (sizeof (signal_print[0]) * numsigs);
6899 signal_program = (unsigned char *)
6900 xmalloc (sizeof (signal_program[0]) * numsigs);
6901 for (i = 0; i < numsigs; i++)
6904 signal_print[i] = 1;
6905 signal_program[i] = 1;
6908 /* Signals caused by debugger's own actions
6909 should not be given to the program afterwards. */
6910 signal_program[TARGET_SIGNAL_TRAP] = 0;
6911 signal_program[TARGET_SIGNAL_INT] = 0;
6913 /* Signals that are not errors should not normally enter the debugger. */
6914 signal_stop[TARGET_SIGNAL_ALRM] = 0;
6915 signal_print[TARGET_SIGNAL_ALRM] = 0;
6916 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
6917 signal_print[TARGET_SIGNAL_VTALRM] = 0;
6918 signal_stop[TARGET_SIGNAL_PROF] = 0;
6919 signal_print[TARGET_SIGNAL_PROF] = 0;
6920 signal_stop[TARGET_SIGNAL_CHLD] = 0;
6921 signal_print[TARGET_SIGNAL_CHLD] = 0;
6922 signal_stop[TARGET_SIGNAL_IO] = 0;
6923 signal_print[TARGET_SIGNAL_IO] = 0;
6924 signal_stop[TARGET_SIGNAL_POLL] = 0;
6925 signal_print[TARGET_SIGNAL_POLL] = 0;
6926 signal_stop[TARGET_SIGNAL_URG] = 0;
6927 signal_print[TARGET_SIGNAL_URG] = 0;
6928 signal_stop[TARGET_SIGNAL_WINCH] = 0;
6929 signal_print[TARGET_SIGNAL_WINCH] = 0;
6930 signal_stop[TARGET_SIGNAL_PRIO] = 0;
6931 signal_print[TARGET_SIGNAL_PRIO] = 0;
6933 /* These signals are used internally by user-level thread
6934 implementations. (See signal(5) on Solaris.) Like the above
6935 signals, a healthy program receives and handles them as part of
6936 its normal operation. */
6937 signal_stop[TARGET_SIGNAL_LWP] = 0;
6938 signal_print[TARGET_SIGNAL_LWP] = 0;
6939 signal_stop[TARGET_SIGNAL_WAITING] = 0;
6940 signal_print[TARGET_SIGNAL_WAITING] = 0;
6941 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
6942 signal_print[TARGET_SIGNAL_CANCEL] = 0;
6944 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
6945 &stop_on_solib_events, _("\
6946 Set stopping for shared library events."), _("\
6947 Show stopping for shared library events."), _("\
6948 If nonzero, gdb will give control to the user when the dynamic linker\n\
6949 notifies gdb of shared library events. The most common event of interest\n\
6950 to the user would be loading/unloading of a new library."),
6952 show_stop_on_solib_events,
6953 &setlist, &showlist);
6955 add_setshow_enum_cmd ("follow-fork-mode", class_run,
6956 follow_fork_mode_kind_names,
6957 &follow_fork_mode_string, _("\
6958 Set debugger response to a program call of fork or vfork."), _("\
6959 Show debugger response to a program call of fork or vfork."), _("\
6960 A fork or vfork creates a new process. follow-fork-mode can be:\n\
6961 parent - the original process is debugged after a fork\n\
6962 child - the new process is debugged after a fork\n\
6963 The unfollowed process will continue to run.\n\
6964 By default, the debugger will follow the parent process."),
6966 show_follow_fork_mode_string,
6967 &setlist, &showlist);
6969 add_setshow_enum_cmd ("follow-exec-mode", class_run,
6970 follow_exec_mode_names,
6971 &follow_exec_mode_string, _("\
6972 Set debugger response to a program call of exec."), _("\
6973 Show debugger response to a program call of exec."), _("\
6974 An exec call replaces the program image of a process.\n\
6976 follow-exec-mode can be:\n\
6978 new - the debugger creates a new inferior and rebinds the process\n\
6979 to this new inferior. The program the process was running before\n\
6980 the exec call can be restarted afterwards by restarting the original\n\
6983 same - the debugger keeps the process bound to the same inferior.\n\
6984 The new executable image replaces the previous executable loaded in\n\
6985 the inferior. Restarting the inferior after the exec call restarts\n\
6986 the executable the process was running after the exec call.\n\
6988 By default, the debugger will use the same inferior."),
6990 show_follow_exec_mode_string,
6991 &setlist, &showlist);
6993 add_setshow_enum_cmd ("scheduler-locking", class_run,
6994 scheduler_enums, &scheduler_mode, _("\
6995 Set mode for locking scheduler during execution."), _("\
6996 Show mode for locking scheduler during execution."), _("\
6997 off == no locking (threads may preempt at any time)\n\
6998 on == full locking (no thread except the current thread may run)\n\
6999 step == scheduler locked during every single-step operation.\n\
7000 In this mode, no other thread may run during a step command.\n\
7001 Other threads may run while stepping over a function call ('next')."),
7002 set_schedlock_func, /* traps on target vector */
7003 show_scheduler_mode,
7004 &setlist, &showlist);
7006 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
7007 Set mode for resuming threads of all processes."), _("\
7008 Show mode for resuming threads of all processes."), _("\
7009 When on, execution commands (such as 'continue' or 'next') resume all\n\
7010 threads of all processes. When off (which is the default), execution\n\
7011 commands only resume the threads of the current process. The set of\n\
7012 threads that are resumed is further refined by the scheduler-locking\n\
7013 mode (see help set scheduler-locking)."),
7015 show_schedule_multiple,
7016 &setlist, &showlist);
7018 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
7019 Set mode of the step operation."), _("\
7020 Show mode of the step operation."), _("\
7021 When set, doing a step over a function without debug line information\n\
7022 will stop at the first instruction of that function. Otherwise, the\n\
7023 function is skipped and the step command stops at a different source line."),
7025 show_step_stop_if_no_debug,
7026 &setlist, &showlist);
7028 add_setshow_enum_cmd ("displaced-stepping", class_run,
7029 can_use_displaced_stepping_enum,
7030 &can_use_displaced_stepping, _("\
7031 Set debugger's willingness to use displaced stepping."), _("\
7032 Show debugger's willingness to use displaced stepping."), _("\
7033 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7034 supported by the target architecture. If off, gdb will not use displaced\n\
7035 stepping to step over breakpoints, even if such is supported by the target\n\
7036 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7037 if the target architecture supports it and non-stop mode is active, but will not\n\
7038 use it in all-stop mode (see help set non-stop)."),
7040 show_can_use_displaced_stepping,
7041 &setlist, &showlist);
7043 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
7044 &exec_direction, _("Set direction of execution.\n\
7045 Options are 'forward' or 'reverse'."),
7046 _("Show direction of execution (forward/reverse)."),
7047 _("Tells gdb whether to execute forward or backward."),
7048 set_exec_direction_func, show_exec_direction_func,
7049 &setlist, &showlist);
7051 /* Set/show detach-on-fork: user-settable mode. */
7053 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
7054 Set whether gdb will detach the child of a fork."), _("\
7055 Show whether gdb will detach the child of a fork."), _("\
7056 Tells gdb whether to detach the child of a fork."),
7057 NULL, NULL, &setlist, &showlist);
7059 /* ptid initializations */
7060 null_ptid = ptid_build (0, 0, 0);
7061 minus_one_ptid = ptid_build (-1, 0, 0);
7062 inferior_ptid = null_ptid;
7063 target_last_wait_ptid = minus_one_ptid;
7065 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
7066 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
7067 observer_attach_thread_exit (infrun_thread_thread_exit);
7068 observer_attach_inferior_exit (infrun_inferior_exit);
7070 /* Explicitly create without lookup, since that tries to create a
7071 value with a void typed value, and when we get here, gdbarch
7072 isn't initialized yet. At this point, we're quite sure there
7073 isn't another convenience variable of the same name. */
7074 create_internalvar_type_lazy ("_siginfo", siginfo_make_value);
7076 add_setshow_boolean_cmd ("observer", no_class,
7077 &observer_mode_1, _("\
7078 Set whether gdb controls the inferior in observer mode."), _("\
7079 Show whether gdb controls the inferior in observer mode."), _("\
7080 In observer mode, GDB can get data from the inferior, but not\n\
7081 affect its execution. Registers and memory may not be changed,\n\
7082 breakpoints may not be set, and the program cannot be interrupted\n\