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 /* If inferior is in displaced stepping, and ADDR equals to starting address
1082 of copy area, return corresponding displaced_step_closure. Otherwise,
1085 struct displaced_step_closure*
1086 get_displaced_step_closure_by_addr (CORE_ADDR addr)
1088 struct displaced_step_inferior_state *displaced
1089 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1091 /* If checking the mode of displaced instruction in copy area. */
1092 if (displaced && !ptid_equal (displaced->step_ptid, null_ptid)
1093 && (displaced->step_copy == addr))
1094 return displaced->step_closure;
1099 /* Remove the displaced stepping state of process PID. */
1102 remove_displaced_stepping_state (int pid)
1104 struct displaced_step_inferior_state *it, **prev_next_p;
1106 gdb_assert (kernel_debugger || (pid != 0));
1108 it = displaced_step_inferior_states;
1109 prev_next_p = &displaced_step_inferior_states;
1114 *prev_next_p = it->next;
1119 prev_next_p = &it->next;
1125 infrun_inferior_exit (struct inferior *inf)
1127 remove_displaced_stepping_state (inf->pid);
1130 /* Enum strings for "set|show displaced-stepping". */
1132 static const char can_use_displaced_stepping_auto[] = "auto";
1133 static const char can_use_displaced_stepping_on[] = "on";
1134 static const char can_use_displaced_stepping_off[] = "off";
1135 static const char *can_use_displaced_stepping_enum[] =
1137 can_use_displaced_stepping_auto,
1138 can_use_displaced_stepping_on,
1139 can_use_displaced_stepping_off,
1143 /* If ON, and the architecture supports it, GDB will use displaced
1144 stepping to step over breakpoints. If OFF, or if the architecture
1145 doesn't support it, GDB will instead use the traditional
1146 hold-and-step approach. If AUTO (which is the default), GDB will
1147 decide which technique to use to step over breakpoints depending on
1148 which of all-stop or non-stop mode is active --- displaced stepping
1149 in non-stop mode; hold-and-step in all-stop mode. */
1151 static const char *can_use_displaced_stepping =
1152 can_use_displaced_stepping_auto;
1155 show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
1156 struct cmd_list_element *c,
1159 if (can_use_displaced_stepping == can_use_displaced_stepping_auto)
1160 fprintf_filtered (file,
1161 _("Debugger's willingness to use displaced stepping "
1162 "to step over breakpoints is %s (currently %s).\n"),
1163 value, non_stop ? "on" : "off");
1165 fprintf_filtered (file,
1166 _("Debugger's willingness to use displaced stepping "
1167 "to step over breakpoints is %s.\n"), value);
1170 /* Return non-zero if displaced stepping can/should be used to step
1171 over breakpoints. */
1174 use_displaced_stepping (struct gdbarch *gdbarch)
1176 return (((can_use_displaced_stepping == can_use_displaced_stepping_auto
1178 || can_use_displaced_stepping == can_use_displaced_stepping_on)
1179 && gdbarch_displaced_step_copy_insn_p (gdbarch)
1180 && !RECORD_IS_USED);
1183 /* Clean out any stray displaced stepping state. */
1185 displaced_step_clear (struct displaced_step_inferior_state *displaced)
1187 /* Indicate that there is no cleanup pending. */
1188 displaced->step_ptid = null_ptid;
1190 if (displaced->step_closure)
1192 gdbarch_displaced_step_free_closure (displaced->step_gdbarch,
1193 displaced->step_closure);
1194 displaced->step_closure = NULL;
1199 displaced_step_clear_cleanup (void *arg)
1201 struct displaced_step_inferior_state *state = arg;
1203 displaced_step_clear (state);
1206 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1208 displaced_step_dump_bytes (struct ui_file *file,
1209 const gdb_byte *buf,
1214 for (i = 0; i < len; i++)
1215 fprintf_unfiltered (file, "%02x ", buf[i]);
1216 fputs_unfiltered ("\n", file);
1219 /* Prepare to single-step, using displaced stepping.
1221 Note that we cannot use displaced stepping when we have a signal to
1222 deliver. If we have a signal to deliver and an instruction to step
1223 over, then after the step, there will be no indication from the
1224 target whether the thread entered a signal handler or ignored the
1225 signal and stepped over the instruction successfully --- both cases
1226 result in a simple SIGTRAP. In the first case we mustn't do a
1227 fixup, and in the second case we must --- but we can't tell which.
1228 Comments in the code for 'random signals' in handle_inferior_event
1229 explain how we handle this case instead.
1231 Returns 1 if preparing was successful -- this thread is going to be
1232 stepped now; or 0 if displaced stepping this thread got queued. */
1234 displaced_step_prepare (ptid_t ptid)
1236 struct cleanup *old_cleanups, *ignore_cleanups;
1237 struct regcache *regcache = get_thread_regcache (ptid);
1238 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1239 CORE_ADDR original, copy;
1241 struct displaced_step_closure *closure;
1242 struct displaced_step_inferior_state *displaced;
1244 /* We should never reach this function if the architecture does not
1245 support displaced stepping. */
1246 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
1248 /* We have to displaced step one thread at a time, as we only have
1249 access to a single scratch space per inferior. */
1251 displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
1253 if (!ptid_equal (displaced->step_ptid, null_ptid))
1255 /* Already waiting for a displaced step to finish. Defer this
1256 request and place in queue. */
1257 struct displaced_step_request *req, *new_req;
1259 if (debug_displaced)
1260 fprintf_unfiltered (gdb_stdlog,
1261 "displaced: defering step of %s\n",
1262 target_pid_to_str (ptid));
1264 new_req = xmalloc (sizeof (*new_req));
1265 new_req->ptid = ptid;
1266 new_req->next = NULL;
1268 if (displaced->step_request_queue)
1270 for (req = displaced->step_request_queue;
1274 req->next = new_req;
1277 displaced->step_request_queue = new_req;
1283 if (debug_displaced)
1284 fprintf_unfiltered (gdb_stdlog,
1285 "displaced: stepping %s now\n",
1286 target_pid_to_str (ptid));
1289 displaced_step_clear (displaced);
1291 old_cleanups = save_inferior_ptid ();
1292 inferior_ptid = ptid;
1294 original = regcache_read_pc (regcache);
1296 copy = gdbarch_displaced_step_location (gdbarch);
1297 len = gdbarch_max_insn_length (gdbarch);
1299 /* Save the original contents of the copy area. */
1300 displaced->step_saved_copy = xmalloc (len);
1301 ignore_cleanups = make_cleanup (free_current_contents,
1302 &displaced->step_saved_copy);
1303 read_memory (copy, displaced->step_saved_copy, len);
1304 if (debug_displaced)
1306 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
1307 paddress (gdbarch, copy));
1308 displaced_step_dump_bytes (gdb_stdlog,
1309 displaced->step_saved_copy,
1313 closure = gdbarch_displaced_step_copy_insn (gdbarch,
1314 original, copy, regcache);
1316 /* We don't support the fully-simulated case at present. */
1317 gdb_assert (closure);
1319 /* Save the information we need to fix things up if the step
1321 displaced->step_ptid = ptid;
1322 displaced->step_gdbarch = gdbarch;
1323 displaced->step_closure = closure;
1324 displaced->step_original = original;
1325 displaced->step_copy = copy;
1327 make_cleanup (displaced_step_clear_cleanup, displaced);
1329 /* Resume execution at the copy. */
1330 regcache_write_pc (regcache, copy);
1332 discard_cleanups (ignore_cleanups);
1334 do_cleanups (old_cleanups);
1336 if (debug_displaced)
1337 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
1338 paddress (gdbarch, copy));
1344 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr,
1345 const gdb_byte *myaddr, int len)
1347 struct cleanup *ptid_cleanup = save_inferior_ptid ();
1349 inferior_ptid = ptid;
1350 write_memory (memaddr, myaddr, len);
1351 do_cleanups (ptid_cleanup);
1355 displaced_step_fixup (ptid_t event_ptid, enum target_signal signal)
1357 struct cleanup *old_cleanups;
1358 struct displaced_step_inferior_state *displaced
1359 = get_displaced_stepping_state (ptid_get_pid (event_ptid));
1361 /* Was any thread of this process doing a displaced step? */
1362 if (displaced == NULL)
1365 /* Was this event for the pid we displaced? */
1366 if (ptid_equal (displaced->step_ptid, null_ptid)
1367 || ! ptid_equal (displaced->step_ptid, event_ptid))
1370 old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
1372 /* Restore the contents of the copy area. */
1374 ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
1376 write_memory_ptid (displaced->step_ptid, displaced->step_copy,
1377 displaced->step_saved_copy, len);
1378 if (debug_displaced)
1379 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s\n",
1380 paddress (displaced->step_gdbarch,
1381 displaced->step_copy));
1384 /* Did the instruction complete successfully? */
1385 if (signal == TARGET_SIGNAL_TRAP)
1387 /* Fix up the resulting state. */
1388 gdbarch_displaced_step_fixup (displaced->step_gdbarch,
1389 displaced->step_closure,
1390 displaced->step_original,
1391 displaced->step_copy,
1392 get_thread_regcache (displaced->step_ptid));
1396 /* Since the instruction didn't complete, all we can do is
1398 struct regcache *regcache = get_thread_regcache (event_ptid);
1399 CORE_ADDR pc = regcache_read_pc (regcache);
1401 pc = displaced->step_original + (pc - displaced->step_copy);
1402 regcache_write_pc (regcache, pc);
1405 do_cleanups (old_cleanups);
1407 displaced->step_ptid = null_ptid;
1409 /* Are there any pending displaced stepping requests? If so, run
1410 one now. Leave the state object around, since we're likely to
1411 need it again soon. */
1412 while (displaced->step_request_queue)
1414 struct displaced_step_request *head;
1416 struct regcache *regcache;
1417 struct gdbarch *gdbarch;
1418 CORE_ADDR actual_pc;
1419 struct address_space *aspace;
1421 head = displaced->step_request_queue;
1423 displaced->step_request_queue = head->next;
1426 context_switch (ptid);
1428 regcache = get_thread_regcache (ptid);
1429 actual_pc = regcache_read_pc (regcache);
1430 aspace = get_regcache_aspace (regcache);
1432 if (breakpoint_here_p (aspace, actual_pc))
1434 if (debug_displaced)
1435 fprintf_unfiltered (gdb_stdlog,
1436 "displaced: stepping queued %s now\n",
1437 target_pid_to_str (ptid));
1439 displaced_step_prepare (ptid);
1441 gdbarch = get_regcache_arch (regcache);
1443 if (debug_displaced)
1445 CORE_ADDR actual_pc = regcache_read_pc (regcache);
1448 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1449 paddress (gdbarch, actual_pc));
1450 read_memory (actual_pc, buf, sizeof (buf));
1451 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1454 if (gdbarch_displaced_step_hw_singlestep (gdbarch,
1455 displaced->step_closure))
1456 target_resume (ptid, 1, TARGET_SIGNAL_0);
1458 target_resume (ptid, 0, TARGET_SIGNAL_0);
1460 /* Done, we're stepping a thread. */
1466 struct thread_info *tp = inferior_thread ();
1468 /* The breakpoint we were sitting under has since been
1470 tp->control.trap_expected = 0;
1472 /* Go back to what we were trying to do. */
1473 step = currently_stepping (tp);
1475 if (debug_displaced)
1476 fprintf_unfiltered (gdb_stdlog,
1477 "breakpoint is gone %s: step(%d)\n",
1478 target_pid_to_str (tp->ptid), step);
1480 target_resume (ptid, step, TARGET_SIGNAL_0);
1481 tp->suspend.stop_signal = TARGET_SIGNAL_0;
1483 /* This request was discarded. See if there's any other
1484 thread waiting for its turn. */
1489 /* Update global variables holding ptids to hold NEW_PTID if they were
1490 holding OLD_PTID. */
1492 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
1494 struct displaced_step_request *it;
1495 struct displaced_step_inferior_state *displaced;
1497 if (ptid_equal (inferior_ptid, old_ptid))
1498 inferior_ptid = new_ptid;
1500 if (ptid_equal (singlestep_ptid, old_ptid))
1501 singlestep_ptid = new_ptid;
1503 if (ptid_equal (deferred_step_ptid, old_ptid))
1504 deferred_step_ptid = new_ptid;
1506 for (displaced = displaced_step_inferior_states;
1508 displaced = displaced->next)
1510 if (ptid_equal (displaced->step_ptid, old_ptid))
1511 displaced->step_ptid = new_ptid;
1513 for (it = displaced->step_request_queue; it; it = it->next)
1514 if (ptid_equal (it->ptid, old_ptid))
1515 it->ptid = new_ptid;
1522 /* Things to clean up if we QUIT out of resume (). */
1524 resume_cleanups (void *ignore)
1529 static const char schedlock_off[] = "off";
1530 static const char schedlock_on[] = "on";
1531 static const char schedlock_step[] = "step";
1532 static const char *scheduler_enums[] = {
1538 static const char *scheduler_mode = schedlock_off;
1540 show_scheduler_mode (struct ui_file *file, int from_tty,
1541 struct cmd_list_element *c, const char *value)
1543 fprintf_filtered (file,
1544 _("Mode for locking scheduler "
1545 "during execution is \"%s\".\n"),
1550 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
1552 if (!target_can_lock_scheduler)
1554 scheduler_mode = schedlock_off;
1555 error (_("Target '%s' cannot support this command."), target_shortname);
1559 /* True if execution commands resume all threads of all processes by
1560 default; otherwise, resume only threads of the current inferior
1562 int sched_multi = 0;
1564 /* Try to setup for software single stepping over the specified location.
1565 Return 1 if target_resume() should use hardware single step.
1567 GDBARCH the current gdbarch.
1568 PC the location to step over. */
1571 maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
1575 if (execution_direction == EXEC_FORWARD
1576 && gdbarch_software_single_step_p (gdbarch)
1577 && gdbarch_software_single_step (gdbarch, get_current_frame ()))
1580 /* Do not pull these breakpoints until after a `wait' in
1581 `wait_for_inferior'. */
1582 singlestep_breakpoints_inserted_p = 1;
1583 singlestep_ptid = inferior_ptid;
1589 /* Resume the inferior, but allow a QUIT. This is useful if the user
1590 wants to interrupt some lengthy single-stepping operation
1591 (for child processes, the SIGINT goes to the inferior, and so
1592 we get a SIGINT random_signal, but for remote debugging and perhaps
1593 other targets, that's not true).
1595 STEP nonzero if we should step (zero to continue instead).
1596 SIG is the signal to give the inferior (zero for none). */
1598 resume (int step, enum target_signal sig)
1600 int should_resume = 1;
1601 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
1602 struct regcache *regcache = get_current_regcache ();
1603 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1604 struct thread_info *tp = inferior_thread ();
1605 CORE_ADDR pc = regcache_read_pc (regcache);
1606 struct address_space *aspace = get_regcache_aspace (regcache);
1610 if (current_inferior ()->waiting_for_vfork_done)
1612 /* Don't try to single-step a vfork parent that is waiting for
1613 the child to get out of the shared memory region (by exec'ing
1614 or exiting). This is particularly important on software
1615 single-step archs, as the child process would trip on the
1616 software single step breakpoint inserted for the parent
1617 process. Since the parent will not actually execute any
1618 instruction until the child is out of the shared region (such
1619 are vfork's semantics), it is safe to simply continue it.
1620 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1621 the parent, and tell it to `keep_going', which automatically
1622 re-sets it stepping. */
1624 fprintf_unfiltered (gdb_stdlog,
1625 "infrun: resume : clear step\n");
1630 fprintf_unfiltered (gdb_stdlog,
1631 "infrun: resume (step=%d, signal=%d), "
1632 "trap_expected=%d\n",
1633 step, sig, tp->control.trap_expected);
1635 /* Normally, by the time we reach `resume', the breakpoints are either
1636 removed or inserted, as appropriate. The exception is if we're sitting
1637 at a permanent breakpoint; we need to step over it, but permanent
1638 breakpoints can't be removed. So we have to test for it here. */
1639 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
1641 if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
1642 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
1645 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1646 how to step past a permanent breakpoint on this architecture. Try using\n\
1647 a command like `return' or `jump' to continue execution."));
1650 /* If enabled, step over breakpoints by executing a copy of the
1651 instruction at a different address.
1653 We can't use displaced stepping when we have a signal to deliver;
1654 the comments for displaced_step_prepare explain why. The
1655 comments in the handle_inferior event for dealing with 'random
1656 signals' explain what we do instead.
1658 We can't use displaced stepping when we are waiting for vfork_done
1659 event, displaced stepping breaks the vfork child similarly as single
1660 step software breakpoint. */
1661 if (use_displaced_stepping (gdbarch)
1662 && (tp->control.trap_expected
1663 || (step && gdbarch_software_single_step_p (gdbarch)))
1664 && sig == TARGET_SIGNAL_0
1665 && !current_inferior ()->waiting_for_vfork_done)
1667 struct displaced_step_inferior_state *displaced;
1669 if (!displaced_step_prepare (inferior_ptid))
1671 /* Got placed in displaced stepping queue. Will be resumed
1672 later when all the currently queued displaced stepping
1673 requests finish. The thread is not executing at this point,
1674 and the call to set_executing will be made later. But we
1675 need to call set_running here, since from frontend point of view,
1676 the thread is running. */
1677 set_running (inferior_ptid, 1);
1678 discard_cleanups (old_cleanups);
1682 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1683 step = gdbarch_displaced_step_hw_singlestep (gdbarch,
1684 displaced->step_closure);
1687 /* Do we need to do it the hard way, w/temp breakpoints? */
1689 step = maybe_software_singlestep (gdbarch, pc);
1695 /* If STEP is set, it's a request to use hardware stepping
1696 facilities. But in that case, we should never
1697 use singlestep breakpoint. */
1698 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
1700 /* Decide the set of threads to ask the target to resume. Start
1701 by assuming everything will be resumed, than narrow the set
1702 by applying increasingly restricting conditions. */
1704 /* By default, resume all threads of all processes. */
1705 resume_ptid = RESUME_ALL;
1707 /* Maybe resume only all threads of the current process. */
1708 if (!sched_multi && target_supports_multi_process ())
1710 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
1713 /* Maybe resume a single thread after all. */
1714 if (singlestep_breakpoints_inserted_p
1715 && stepping_past_singlestep_breakpoint)
1717 /* The situation here is as follows. In thread T1 we wanted to
1718 single-step. Lacking hardware single-stepping we've
1719 set breakpoint at the PC of the next instruction -- call it
1720 P. After resuming, we've hit that breakpoint in thread T2.
1721 Now we've removed original breakpoint, inserted breakpoint
1722 at P+1, and try to step to advance T2 past breakpoint.
1723 We need to step only T2, as if T1 is allowed to freely run,
1724 it can run past P, and if other threads are allowed to run,
1725 they can hit breakpoint at P+1, and nested hits of single-step
1726 breakpoints is not something we'd want -- that's complicated
1727 to support, and has no value. */
1728 resume_ptid = inferior_ptid;
1730 else if ((step || singlestep_breakpoints_inserted_p)
1731 && tp->control.trap_expected)
1733 /* We're allowing a thread to run past a breakpoint it has
1734 hit, by single-stepping the thread with the breakpoint
1735 removed. In which case, we need to single-step only this
1736 thread, and keep others stopped, as they can miss this
1737 breakpoint if allowed to run.
1739 The current code actually removes all breakpoints when
1740 doing this, not just the one being stepped over, so if we
1741 let other threads run, we can actually miss any
1742 breakpoint, not just the one at PC. */
1743 resume_ptid = inferior_ptid;
1747 /* With non-stop mode on, threads are always handled
1749 resume_ptid = inferior_ptid;
1751 else if ((scheduler_mode == schedlock_on)
1752 || (scheduler_mode == schedlock_step
1753 && (step || singlestep_breakpoints_inserted_p)))
1755 /* User-settable 'scheduler' mode requires solo thread resume. */
1756 resume_ptid = inferior_ptid;
1759 if (gdbarch_cannot_step_breakpoint (gdbarch))
1761 /* Most targets can step a breakpoint instruction, thus
1762 executing it normally. But if this one cannot, just
1763 continue and we will hit it anyway. */
1764 if (step && breakpoint_inserted_here_p (aspace, pc))
1769 && use_displaced_stepping (gdbarch)
1770 && tp->control.trap_expected)
1772 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
1773 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
1774 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
1777 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1778 paddress (resume_gdbarch, actual_pc));
1779 read_memory (actual_pc, buf, sizeof (buf));
1780 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1783 /* Install inferior's terminal modes. */
1784 target_terminal_inferior ();
1786 /* Avoid confusing the next resume, if the next stop/resume
1787 happens to apply to another thread. */
1788 tp->suspend.stop_signal = TARGET_SIGNAL_0;
1790 target_resume (resume_ptid, step, sig);
1793 discard_cleanups (old_cleanups);
1798 /* Clear out all variables saying what to do when inferior is continued.
1799 First do this, then set the ones you want, then call `proceed'. */
1802 clear_proceed_status_thread (struct thread_info *tp)
1805 fprintf_unfiltered (gdb_stdlog,
1806 "infrun: clear_proceed_status_thread (%s)\n",
1807 target_pid_to_str (tp->ptid));
1809 tp->control.trap_expected = 0;
1810 tp->control.step_range_start = 0;
1811 tp->control.step_range_end = 0;
1812 tp->control.step_frame_id = null_frame_id;
1813 tp->control.step_stack_frame_id = null_frame_id;
1814 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
1815 tp->stop_requested = 0;
1817 tp->control.stop_step = 0;
1819 tp->control.proceed_to_finish = 0;
1821 /* Discard any remaining commands or status from previous stop. */
1822 bpstat_clear (&tp->control.stop_bpstat);
1826 clear_proceed_status_callback (struct thread_info *tp, void *data)
1828 if (is_exited (tp->ptid))
1831 clear_proceed_status_thread (tp);
1836 clear_proceed_status (void)
1840 /* In all-stop mode, delete the per-thread status of all
1841 threads, even if inferior_ptid is null_ptid, there may be
1842 threads on the list. E.g., we may be launching a new
1843 process, while selecting the executable. */
1844 iterate_over_threads (clear_proceed_status_callback, NULL);
1847 if (!ptid_equal (inferior_ptid, null_ptid))
1849 struct inferior *inferior;
1853 /* If in non-stop mode, only delete the per-thread status of
1854 the current thread. */
1855 clear_proceed_status_thread (inferior_thread ());
1858 inferior = current_inferior ();
1859 inferior->control.stop_soon = NO_STOP_QUIETLY;
1862 stop_after_trap = 0;
1864 observer_notify_about_to_proceed ();
1868 regcache_xfree (stop_registers);
1869 stop_registers = NULL;
1873 /* Check the current thread against the thread that reported the most recent
1874 event. If a step-over is required return TRUE and set the current thread
1875 to the old thread. Otherwise return FALSE.
1877 This should be suitable for any targets that support threads. */
1880 prepare_to_proceed (int step)
1883 struct target_waitstatus wait_status;
1884 int schedlock_enabled;
1886 /* With non-stop mode on, threads are always handled individually. */
1887 gdb_assert (! non_stop);
1889 /* Get the last target status returned by target_wait(). */
1890 get_last_target_status (&wait_ptid, &wait_status);
1892 /* Make sure we were stopped at a breakpoint. */
1893 if (wait_status.kind != TARGET_WAITKIND_STOPPED
1894 || (wait_status.value.sig != TARGET_SIGNAL_TRAP
1895 && wait_status.value.sig != TARGET_SIGNAL_ILL
1896 && wait_status.value.sig != TARGET_SIGNAL_SEGV
1897 && wait_status.value.sig != TARGET_SIGNAL_EMT))
1902 schedlock_enabled = (scheduler_mode == schedlock_on
1903 || (scheduler_mode == schedlock_step
1906 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
1907 if (schedlock_enabled)
1910 /* Don't switch over if we're about to resume some other process
1911 other than WAIT_PTID's, and schedule-multiple is off. */
1913 && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid))
1916 /* Switched over from WAIT_PID. */
1917 if (!ptid_equal (wait_ptid, minus_one_ptid)
1918 && !ptid_equal (inferior_ptid, wait_ptid))
1920 struct regcache *regcache = get_thread_regcache (wait_ptid);
1922 if (breakpoint_here_p (get_regcache_aspace (regcache),
1923 regcache_read_pc (regcache)))
1925 /* If stepping, remember current thread to switch back to. */
1927 deferred_step_ptid = inferior_ptid;
1929 /* Switch back to WAIT_PID thread. */
1930 switch_to_thread (wait_ptid);
1932 /* We return 1 to indicate that there is a breakpoint here,
1933 so we need to step over it before continuing to avoid
1934 hitting it straight away. */
1942 /* Basic routine for continuing the program in various fashions.
1944 ADDR is the address to resume at, or -1 for resume where stopped.
1945 SIGGNAL is the signal to give it, or 0 for none,
1946 or -1 for act according to how it stopped.
1947 STEP is nonzero if should trap after one instruction.
1948 -1 means return after that and print nothing.
1949 You should probably set various step_... variables
1950 before calling here, if you are stepping.
1952 You should call clear_proceed_status before calling proceed. */
1955 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
1957 struct regcache *regcache;
1958 struct gdbarch *gdbarch;
1959 struct thread_info *tp;
1961 struct address_space *aspace;
1964 /* If we're stopped at a fork/vfork, follow the branch set by the
1965 "set follow-fork-mode" command; otherwise, we'll just proceed
1966 resuming the current thread. */
1967 if (!follow_fork ())
1969 /* The target for some reason decided not to resume. */
1974 regcache = get_current_regcache ();
1975 gdbarch = get_regcache_arch (regcache);
1976 aspace = get_regcache_aspace (regcache);
1977 pc = regcache_read_pc (regcache);
1980 step_start_function = find_pc_function (pc);
1982 stop_after_trap = 1;
1984 if (addr == (CORE_ADDR) -1)
1986 if (pc == stop_pc && breakpoint_here_p (aspace, pc)
1987 && execution_direction != EXEC_REVERSE)
1988 /* There is a breakpoint at the address we will resume at,
1989 step one instruction before inserting breakpoints so that
1990 we do not stop right away (and report a second hit at this
1993 Note, we don't do this in reverse, because we won't
1994 actually be executing the breakpoint insn anyway.
1995 We'll be (un-)executing the previous instruction. */
1998 else if (gdbarch_single_step_through_delay_p (gdbarch)
1999 && gdbarch_single_step_through_delay (gdbarch,
2000 get_current_frame ()))
2001 /* We stepped onto an instruction that needs to be stepped
2002 again before re-inserting the breakpoint, do so. */
2007 regcache_write_pc (regcache, addr);
2011 fprintf_unfiltered (gdb_stdlog,
2012 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
2013 paddress (gdbarch, addr), siggnal, step);
2016 /* In non-stop, each thread is handled individually. The context
2017 must already be set to the right thread here. */
2021 /* In a multi-threaded task we may select another thread and
2022 then continue or step.
2024 But if the old thread was stopped at a breakpoint, it will
2025 immediately cause another breakpoint stop without any
2026 execution (i.e. it will report a breakpoint hit incorrectly).
2027 So we must step over it first.
2029 prepare_to_proceed checks the current thread against the
2030 thread that reported the most recent event. If a step-over
2031 is required it returns TRUE and sets the current thread to
2033 if (prepare_to_proceed (step))
2037 /* prepare_to_proceed may change the current thread. */
2038 tp = inferior_thread ();
2042 tp->control.trap_expected = 1;
2043 /* If displaced stepping is enabled, we can step over the
2044 breakpoint without hitting it, so leave all breakpoints
2045 inserted. Otherwise we need to disable all breakpoints, step
2046 one instruction, and then re-add them when that step is
2048 if (!use_displaced_stepping (gdbarch))
2049 remove_breakpoints ();
2052 /* We can insert breakpoints if we're not trying to step over one,
2053 or if we are stepping over one but we're using displaced stepping
2055 if (! tp->control.trap_expected || use_displaced_stepping (gdbarch))
2056 insert_breakpoints ();
2060 /* Pass the last stop signal to the thread we're resuming,
2061 irrespective of whether the current thread is the thread that
2062 got the last event or not. This was historically GDB's
2063 behaviour before keeping a stop_signal per thread. */
2065 struct thread_info *last_thread;
2067 struct target_waitstatus last_status;
2069 get_last_target_status (&last_ptid, &last_status);
2070 if (!ptid_equal (inferior_ptid, last_ptid)
2071 && !ptid_equal (last_ptid, null_ptid)
2072 && !ptid_equal (last_ptid, minus_one_ptid))
2074 last_thread = find_thread_ptid (last_ptid);
2077 tp->suspend.stop_signal = last_thread->suspend.stop_signal;
2078 last_thread->suspend.stop_signal = TARGET_SIGNAL_0;
2083 if (siggnal != TARGET_SIGNAL_DEFAULT)
2084 tp->suspend.stop_signal = siggnal;
2085 /* If this signal should not be seen by program,
2086 give it zero. Used for debugging signals. */
2087 else if (!signal_program[tp->suspend.stop_signal])
2088 tp->suspend.stop_signal = TARGET_SIGNAL_0;
2090 annotate_starting ();
2092 /* Make sure that output from GDB appears before output from the
2094 gdb_flush (gdb_stdout);
2096 /* Refresh prev_pc value just prior to resuming. This used to be
2097 done in stop_stepping, however, setting prev_pc there did not handle
2098 scenarios such as inferior function calls or returning from
2099 a function via the return command. In those cases, the prev_pc
2100 value was not set properly for subsequent commands. The prev_pc value
2101 is used to initialize the starting line number in the ecs. With an
2102 invalid value, the gdb next command ends up stopping at the position
2103 represented by the next line table entry past our start position.
2104 On platforms that generate one line table entry per line, this
2105 is not a problem. However, on the ia64, the compiler generates
2106 extraneous line table entries that do not increase the line number.
2107 When we issue the gdb next command on the ia64 after an inferior call
2108 or a return command, we often end up a few instructions forward, still
2109 within the original line we started.
2111 An attempt was made to refresh the prev_pc at the same time the
2112 execution_control_state is initialized (for instance, just before
2113 waiting for an inferior event). But this approach did not work
2114 because of platforms that use ptrace, where the pc register cannot
2115 be read unless the inferior is stopped. At that point, we are not
2116 guaranteed the inferior is stopped and so the regcache_read_pc() call
2117 can fail. Setting the prev_pc value here ensures the value is updated
2118 correctly when the inferior is stopped. */
2119 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2121 /* Fill in with reasonable starting values. */
2122 init_thread_stepping_state (tp);
2124 /* Reset to normal state. */
2125 init_infwait_state ();
2127 /* Resume inferior. */
2128 resume (oneproc || step || bpstat_should_step (), tp->suspend.stop_signal);
2130 /* Wait for it to stop (if not standalone)
2131 and in any case decode why it stopped, and act accordingly. */
2132 /* Do this only if we are not using the event loop, or if the target
2133 does not support asynchronous execution. */
2134 if (!target_can_async_p ())
2136 wait_for_inferior (0);
2142 /* Start remote-debugging of a machine over a serial link. */
2145 start_remote (int from_tty)
2147 struct inferior *inferior;
2149 init_wait_for_inferior ();
2150 inferior = current_inferior ();
2151 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2153 /* Always go on waiting for the target, regardless of the mode. */
2154 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2155 indicate to wait_for_inferior that a target should timeout if
2156 nothing is returned (instead of just blocking). Because of this,
2157 targets expecting an immediate response need to, internally, set
2158 things up so that the target_wait() is forced to eventually
2160 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2161 differentiate to its caller what the state of the target is after
2162 the initial open has been performed. Here we're assuming that
2163 the target has stopped. It should be possible to eventually have
2164 target_open() return to the caller an indication that the target
2165 is currently running and GDB state should be set to the same as
2166 for an async run. */
2167 wait_for_inferior (0);
2169 /* Now that the inferior has stopped, do any bookkeeping like
2170 loading shared libraries. We want to do this before normal_stop,
2171 so that the displayed frame is up to date. */
2172 post_create_inferior (¤t_target, from_tty);
2177 /* Initialize static vars when a new inferior begins. */
2180 init_wait_for_inferior (void)
2182 /* These are meaningless until the first time through wait_for_inferior. */
2184 breakpoint_init_inferior (inf_starting);
2186 clear_proceed_status ();
2188 stepping_past_singlestep_breakpoint = 0;
2189 deferred_step_ptid = null_ptid;
2191 target_last_wait_ptid = minus_one_ptid;
2193 previous_inferior_ptid = null_ptid;
2194 init_infwait_state ();
2196 /* Discard any skipped inlined frames. */
2197 clear_inline_frame_state (minus_one_ptid);
2201 /* This enum encodes possible reasons for doing a target_wait, so that
2202 wfi can call target_wait in one place. (Ultimately the call will be
2203 moved out of the infinite loop entirely.) */
2207 infwait_normal_state,
2208 infwait_thread_hop_state,
2209 infwait_step_watch_state,
2210 infwait_nonstep_watch_state
2213 /* The PTID we'll do a target_wait on.*/
2216 /* Current inferior wait state. */
2217 enum infwait_states infwait_state;
2219 /* Data to be passed around while handling an event. This data is
2220 discarded between events. */
2221 struct execution_control_state
2224 /* The thread that got the event, if this was a thread event; NULL
2226 struct thread_info *event_thread;
2228 struct target_waitstatus ws;
2230 CORE_ADDR stop_func_start;
2231 CORE_ADDR stop_func_end;
2232 char *stop_func_name;
2233 int new_thread_event;
2237 static void handle_inferior_event (struct execution_control_state *ecs);
2239 static void handle_step_into_function (struct gdbarch *gdbarch,
2240 struct execution_control_state *ecs);
2241 static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2242 struct execution_control_state *ecs);
2243 static void insert_step_resume_breakpoint_at_frame (struct frame_info *);
2244 static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
2245 static void insert_step_resume_breakpoint_at_sal (struct gdbarch *,
2246 struct symtab_and_line ,
2248 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
2249 static void check_exception_resume (struct execution_control_state *,
2250 struct frame_info *, struct symbol *);
2252 static void stop_stepping (struct execution_control_state *ecs);
2253 static void prepare_to_wait (struct execution_control_state *ecs);
2254 static void keep_going (struct execution_control_state *ecs);
2256 /* Callback for iterate over threads. If the thread is stopped, but
2257 the user/frontend doesn't know about that yet, go through
2258 normal_stop, as if the thread had just stopped now. ARG points at
2259 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2260 ptid_is_pid(PTID) is true, applies to all threads of the process
2261 pointed at by PTID. Otherwise, apply only to the thread pointed by
2265 infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2267 ptid_t ptid = * (ptid_t *) arg;
2269 if ((ptid_equal (info->ptid, ptid)
2270 || ptid_equal (minus_one_ptid, ptid)
2271 || (ptid_is_pid (ptid)
2272 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2273 && is_running (info->ptid)
2274 && !is_executing (info->ptid))
2276 struct cleanup *old_chain;
2277 struct execution_control_state ecss;
2278 struct execution_control_state *ecs = &ecss;
2280 memset (ecs, 0, sizeof (*ecs));
2282 old_chain = make_cleanup_restore_current_thread ();
2284 switch_to_thread (info->ptid);
2286 /* Go through handle_inferior_event/normal_stop, so we always
2287 have consistent output as if the stop event had been
2289 ecs->ptid = info->ptid;
2290 ecs->event_thread = find_thread_ptid (info->ptid);
2291 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2292 ecs->ws.value.sig = TARGET_SIGNAL_0;
2294 handle_inferior_event (ecs);
2296 if (!ecs->wait_some_more)
2298 struct thread_info *tp;
2302 /* Finish off the continuations. The continations
2303 themselves are responsible for realising the thread
2304 didn't finish what it was supposed to do. */
2305 tp = inferior_thread ();
2306 do_all_intermediate_continuations_thread (tp);
2307 do_all_continuations_thread (tp);
2310 do_cleanups (old_chain);
2316 /* This function is attached as a "thread_stop_requested" observer.
2317 Cleanup local state that assumed the PTID was to be resumed, and
2318 report the stop to the frontend. */
2321 infrun_thread_stop_requested (ptid_t ptid)
2323 struct displaced_step_inferior_state *displaced;
2325 /* PTID was requested to stop. Remove it from the displaced
2326 stepping queue, so we don't try to resume it automatically. */
2328 for (displaced = displaced_step_inferior_states;
2330 displaced = displaced->next)
2332 struct displaced_step_request *it, **prev_next_p;
2334 it = displaced->step_request_queue;
2335 prev_next_p = &displaced->step_request_queue;
2338 if (ptid_match (it->ptid, ptid))
2340 *prev_next_p = it->next;
2346 prev_next_p = &it->next;
2353 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2357 infrun_thread_thread_exit (struct thread_info *tp, int silent)
2359 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2360 nullify_last_target_wait_ptid ();
2363 /* Callback for iterate_over_threads. */
2366 delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
2368 if (is_exited (info->ptid))
2371 delete_step_resume_breakpoint (info);
2372 delete_exception_resume_breakpoint (info);
2376 /* In all-stop, delete the step resume breakpoint of any thread that
2377 had one. In non-stop, delete the step resume breakpoint of the
2378 thread that just stopped. */
2381 delete_step_thread_step_resume_breakpoint (void)
2383 if (!target_has_execution
2384 || ptid_equal (inferior_ptid, null_ptid))
2385 /* If the inferior has exited, we have already deleted the step
2386 resume breakpoints out of GDB's lists. */
2391 /* If in non-stop mode, only delete the step-resume or
2392 longjmp-resume breakpoint of the thread that just stopped
2394 struct thread_info *tp = inferior_thread ();
2396 delete_step_resume_breakpoint (tp);
2397 delete_exception_resume_breakpoint (tp);
2400 /* In all-stop mode, delete all step-resume and longjmp-resume
2401 breakpoints of any thread that had them. */
2402 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
2405 /* A cleanup wrapper. */
2408 delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
2410 delete_step_thread_step_resume_breakpoint ();
2413 /* Pretty print the results of target_wait, for debugging purposes. */
2416 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
2417 const struct target_waitstatus *ws)
2419 char *status_string = target_waitstatus_to_string (ws);
2420 struct ui_file *tmp_stream = mem_fileopen ();
2423 /* The text is split over several lines because it was getting too long.
2424 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2425 output as a unit; we want only one timestamp printed if debug_timestamp
2428 fprintf_unfiltered (tmp_stream,
2429 "infrun: target_wait (%d", PIDGET (waiton_ptid));
2430 if (PIDGET (waiton_ptid) != -1)
2431 fprintf_unfiltered (tmp_stream,
2432 " [%s]", target_pid_to_str (waiton_ptid));
2433 fprintf_unfiltered (tmp_stream, ", status) =\n");
2434 fprintf_unfiltered (tmp_stream,
2435 "infrun: %d [%s],\n",
2436 PIDGET (result_ptid), target_pid_to_str (result_ptid));
2437 fprintf_unfiltered (tmp_stream,
2441 text = ui_file_xstrdup (tmp_stream, NULL);
2443 /* This uses %s in part to handle %'s in the text, but also to avoid
2444 a gcc error: the format attribute requires a string literal. */
2445 fprintf_unfiltered (gdb_stdlog, "%s", text);
2447 xfree (status_string);
2449 ui_file_delete (tmp_stream);
2452 /* Prepare and stabilize the inferior for detaching it. E.g.,
2453 detaching while a thread is displaced stepping is a recipe for
2454 crashing it, as nothing would readjust the PC out of the scratch
2458 prepare_for_detach (void)
2460 struct inferior *inf = current_inferior ();
2461 ptid_t pid_ptid = pid_to_ptid (inf->pid);
2462 struct cleanup *old_chain_1;
2463 struct displaced_step_inferior_state *displaced;
2465 displaced = get_displaced_stepping_state (inf->pid);
2467 /* Is any thread of this process displaced stepping? If not,
2468 there's nothing else to do. */
2469 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
2473 fprintf_unfiltered (gdb_stdlog,
2474 "displaced-stepping in-process while detaching");
2476 old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
2479 while (!ptid_equal (displaced->step_ptid, null_ptid))
2481 struct cleanup *old_chain_2;
2482 struct execution_control_state ecss;
2483 struct execution_control_state *ecs;
2486 memset (ecs, 0, sizeof (*ecs));
2488 overlay_cache_invalid = 1;
2490 /* We have to invalidate the registers BEFORE calling
2491 target_wait because they can be loaded from the target while
2492 in target_wait. This makes remote debugging a bit more
2493 efficient for those targets that provide critical registers
2494 as part of their normal status mechanism. */
2496 registers_changed ();
2498 if (deprecated_target_wait_hook)
2499 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
2501 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
2504 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
2506 /* If an error happens while handling the event, propagate GDB's
2507 knowledge of the executing state to the frontend/user running
2509 old_chain_2 = make_cleanup (finish_thread_state_cleanup,
2512 /* In non-stop mode, each thread is handled individually.
2513 Switch early, so the global state is set correctly for this
2516 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2517 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2518 context_switch (ecs->ptid);
2520 /* Now figure out what to do with the result of the result. */
2521 handle_inferior_event (ecs);
2523 /* No error, don't finish the state yet. */
2524 discard_cleanups (old_chain_2);
2526 /* Breakpoints and watchpoints are not installed on the target
2527 at this point, and signals are passed directly to the
2528 inferior, so this must mean the process is gone. */
2529 if (!ecs->wait_some_more)
2531 discard_cleanups (old_chain_1);
2532 error (_("Program exited while detaching"));
2536 discard_cleanups (old_chain_1);
2539 /* Wait for control to return from inferior to debugger.
2541 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
2542 as if they were SIGTRAP signals. This can be useful during
2543 the startup sequence on some targets such as HP/UX, where
2544 we receive an EXEC event instead of the expected SIGTRAP.
2546 If inferior gets a signal, we may decide to start it up again
2547 instead of returning. That is why there is a loop in this function.
2548 When this function actually returns it means the inferior
2549 should be left stopped and GDB should read more commands. */
2552 wait_for_inferior (int treat_exec_as_sigtrap)
2554 struct cleanup *old_cleanups;
2555 struct execution_control_state ecss;
2556 struct execution_control_state *ecs;
2560 (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
2561 treat_exec_as_sigtrap);
2564 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
2567 memset (ecs, 0, sizeof (*ecs));
2569 /* We'll update this if & when we switch to a new thread. */
2570 previous_inferior_ptid = inferior_ptid;
2574 struct cleanup *old_chain;
2576 /* We have to invalidate the registers BEFORE calling target_wait
2577 because they can be loaded from the target while in target_wait.
2578 This makes remote debugging a bit more efficient for those
2579 targets that provide critical registers as part of their normal
2580 status mechanism. */
2582 overlay_cache_invalid = 1;
2583 registers_changed ();
2585 if (deprecated_target_wait_hook)
2586 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
2588 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
2591 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2593 if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD)
2595 xfree (ecs->ws.value.execd_pathname);
2596 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2597 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
2600 /* If an error happens while handling the event, propagate GDB's
2601 knowledge of the executing state to the frontend/user running
2603 old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2605 if (ecs->ws.kind == TARGET_WAITKIND_SYSCALL_ENTRY
2606 || ecs->ws.kind == TARGET_WAITKIND_SYSCALL_RETURN)
2607 ecs->ws.value.syscall_number = UNKNOWN_SYSCALL;
2609 /* Now figure out what to do with the result of the result. */
2610 handle_inferior_event (ecs);
2612 /* No error, don't finish the state yet. */
2613 discard_cleanups (old_chain);
2615 if (!ecs->wait_some_more)
2619 do_cleanups (old_cleanups);
2622 /* Asynchronous version of wait_for_inferior. It is called by the
2623 event loop whenever a change of state is detected on the file
2624 descriptor corresponding to the target. It can be called more than
2625 once to complete a single execution command. In such cases we need
2626 to keep the state in a global variable ECSS. If it is the last time
2627 that this function is called for a single execution command, then
2628 report to the user that the inferior has stopped, and do the
2629 necessary cleanups. */
2632 fetch_inferior_event (void *client_data)
2634 struct execution_control_state ecss;
2635 struct execution_control_state *ecs = &ecss;
2636 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
2637 struct cleanup *ts_old_chain;
2638 int was_sync = sync_execution;
2640 memset (ecs, 0, sizeof (*ecs));
2642 /* We'll update this if & when we switch to a new thread. */
2643 previous_inferior_ptid = inferior_ptid;
2645 /* We're handling a live event, so make sure we're doing live
2646 debugging. If we're looking at traceframes while the target is
2647 running, we're going to need to get back to that mode after
2648 handling the event. */
2651 make_cleanup_restore_current_traceframe ();
2652 set_current_traceframe (-1);
2656 /* In non-stop mode, the user/frontend should not notice a thread
2657 switch due to internal events. Make sure we reverse to the
2658 user selected thread and frame after handling the event and
2659 running any breakpoint commands. */
2660 make_cleanup_restore_current_thread ();
2662 /* We have to invalidate the registers BEFORE calling target_wait
2663 because they can be loaded from the target while in target_wait.
2664 This makes remote debugging a bit more efficient for those
2665 targets that provide critical registers as part of their normal
2666 status mechanism. */
2668 overlay_cache_invalid = 1;
2669 registers_changed ();
2671 if (deprecated_target_wait_hook)
2673 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2675 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2678 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2681 && ecs->ws.kind != TARGET_WAITKIND_IGNORE
2682 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2683 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2684 /* In non-stop mode, each thread is handled individually. Switch
2685 early, so the global state is set correctly for this
2687 context_switch (ecs->ptid);
2689 /* If an error happens while handling the event, propagate GDB's
2690 knowledge of the executing state to the frontend/user running
2693 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2695 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
2697 /* Now figure out what to do with the result of the result. */
2698 handle_inferior_event (ecs);
2700 if (!ecs->wait_some_more)
2702 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2704 delete_step_thread_step_resume_breakpoint ();
2706 /* We may not find an inferior if this was a process exit. */
2707 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
2710 if (target_has_execution
2711 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2712 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2713 && ecs->event_thread->step_multi
2714 && ecs->event_thread->control.stop_step)
2715 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
2717 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2720 /* No error, don't finish the thread states yet. */
2721 discard_cleanups (ts_old_chain);
2723 /* Revert thread and frame. */
2724 do_cleanups (old_chain);
2726 /* If the inferior was in sync execution mode, and now isn't,
2727 restore the prompt. */
2728 if (was_sync && !sync_execution)
2729 display_gdb_prompt (0);
2732 /* Record the frame and location we're currently stepping through. */
2734 set_step_info (struct frame_info *frame, struct symtab_and_line sal)
2736 struct thread_info *tp = inferior_thread ();
2738 tp->control.step_frame_id = get_frame_id (frame);
2739 tp->control.step_stack_frame_id = get_stack_frame_id (frame);
2741 tp->current_symtab = sal.symtab;
2742 tp->current_line = sal.line;
2745 /* Clear context switchable stepping state. */
2748 init_thread_stepping_state (struct thread_info *tss)
2750 tss->stepping_over_breakpoint = 0;
2751 tss->step_after_step_resume_breakpoint = 0;
2752 tss->stepping_through_solib_after_catch = 0;
2753 tss->stepping_through_solib_catchpoints = NULL;
2756 /* Return the cached copy of the last pid/waitstatus returned by
2757 target_wait()/deprecated_target_wait_hook(). The data is actually
2758 cached by handle_inferior_event(), which gets called immediately
2759 after target_wait()/deprecated_target_wait_hook(). */
2762 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
2764 *ptidp = target_last_wait_ptid;
2765 *status = target_last_waitstatus;
2769 nullify_last_target_wait_ptid (void)
2771 target_last_wait_ptid = minus_one_ptid;
2774 /* Switch thread contexts. */
2777 context_switch (ptid_t ptid)
2781 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
2782 target_pid_to_str (inferior_ptid));
2783 fprintf_unfiltered (gdb_stdlog, "to %s\n",
2784 target_pid_to_str (ptid));
2787 switch_to_thread (ptid);
2791 adjust_pc_after_break (struct execution_control_state *ecs)
2793 struct regcache *regcache;
2794 struct gdbarch *gdbarch;
2795 struct address_space *aspace;
2796 CORE_ADDR breakpoint_pc;
2798 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2799 we aren't, just return.
2801 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2802 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2803 implemented by software breakpoints should be handled through the normal
2806 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2807 different signals (SIGILL or SIGEMT for instance), but it is less
2808 clear where the PC is pointing afterwards. It may not match
2809 gdbarch_decr_pc_after_break. I don't know any specific target that
2810 generates these signals at breakpoints (the code has been in GDB since at
2811 least 1992) so I can not guess how to handle them here.
2813 In earlier versions of GDB, a target with
2814 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2815 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2816 target with both of these set in GDB history, and it seems unlikely to be
2817 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2819 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
2822 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
2825 /* In reverse execution, when a breakpoint is hit, the instruction
2826 under it has already been de-executed. The reported PC always
2827 points at the breakpoint address, so adjusting it further would
2828 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2831 B1 0x08000000 : INSN1
2832 B2 0x08000001 : INSN2
2834 PC -> 0x08000003 : INSN4
2836 Say you're stopped at 0x08000003 as above. Reverse continuing
2837 from that point should hit B2 as below. Reading the PC when the
2838 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2839 been de-executed already.
2841 B1 0x08000000 : INSN1
2842 B2 PC -> 0x08000001 : INSN2
2846 We can't apply the same logic as for forward execution, because
2847 we would wrongly adjust the PC to 0x08000000, since there's a
2848 breakpoint at PC - 1. We'd then report a hit on B1, although
2849 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2851 if (execution_direction == EXEC_REVERSE)
2854 /* If this target does not decrement the PC after breakpoints, then
2855 we have nothing to do. */
2856 regcache = get_thread_regcache (ecs->ptid);
2857 gdbarch = get_regcache_arch (regcache);
2858 if (gdbarch_decr_pc_after_break (gdbarch) == 0)
2861 aspace = get_regcache_aspace (regcache);
2863 /* Find the location where (if we've hit a breakpoint) the
2864 breakpoint would be. */
2865 breakpoint_pc = regcache_read_pc (regcache)
2866 - gdbarch_decr_pc_after_break (gdbarch);
2868 /* Check whether there actually is a software breakpoint inserted at
2871 If in non-stop mode, a race condition is possible where we've
2872 removed a breakpoint, but stop events for that breakpoint were
2873 already queued and arrive later. To suppress those spurious
2874 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2875 and retire them after a number of stop events are reported. */
2876 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
2877 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
2879 struct cleanup *old_cleanups = NULL;
2882 old_cleanups = record_gdb_operation_disable_set ();
2884 /* When using hardware single-step, a SIGTRAP is reported for both
2885 a completed single-step and a software breakpoint. Need to
2886 differentiate between the two, as the latter needs adjusting
2887 but the former does not.
2889 The SIGTRAP can be due to a completed hardware single-step only if
2890 - we didn't insert software single-step breakpoints
2891 - the thread to be examined is still the current thread
2892 - this thread is currently being stepped
2894 If any of these events did not occur, we must have stopped due
2895 to hitting a software breakpoint, and have to back up to the
2898 As a special case, we could have hardware single-stepped a
2899 software breakpoint. In this case (prev_pc == breakpoint_pc),
2900 we also need to back up to the breakpoint address. */
2902 if (singlestep_breakpoints_inserted_p
2903 || !ptid_equal (ecs->ptid, inferior_ptid)
2904 || !currently_stepping (ecs->event_thread)
2905 || ecs->event_thread->prev_pc == breakpoint_pc)
2906 regcache_write_pc (regcache, breakpoint_pc);
2909 do_cleanups (old_cleanups);
2914 init_infwait_state (void)
2916 waiton_ptid = pid_to_ptid (-1);
2917 infwait_state = infwait_normal_state;
2921 error_is_running (void)
2923 error (_("Cannot execute this command while "
2924 "the selected thread is running."));
2928 ensure_not_running (void)
2930 if (is_running (inferior_ptid))
2931 error_is_running ();
2935 stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
2937 for (frame = get_prev_frame (frame);
2939 frame = get_prev_frame (frame))
2941 if (frame_id_eq (get_frame_id (frame), step_frame_id))
2943 if (get_frame_type (frame) != INLINE_FRAME)
2950 /* Auxiliary function that handles syscall entry/return events.
2951 It returns 1 if the inferior should keep going (and GDB
2952 should ignore the event), or 0 if the event deserves to be
2956 handle_syscall_event (struct execution_control_state *ecs)
2958 struct regcache *regcache;
2959 struct gdbarch *gdbarch;
2962 if (!ptid_equal (ecs->ptid, inferior_ptid))
2963 context_switch (ecs->ptid);
2965 regcache = get_thread_regcache (ecs->ptid);
2966 gdbarch = get_regcache_arch (regcache);
2967 syscall_number = gdbarch_get_syscall_number (gdbarch, ecs->ptid);
2968 stop_pc = regcache_read_pc (regcache);
2970 target_last_waitstatus.value.syscall_number = syscall_number;
2972 if (catch_syscall_enabled () > 0
2973 && catching_syscall_number (syscall_number) > 0)
2976 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
2979 ecs->event_thread->control.stop_bpstat
2980 = bpstat_stop_status (get_regcache_aspace (regcache),
2981 stop_pc, ecs->ptid);
2983 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
2985 if (!ecs->random_signal)
2987 /* Catchpoint hit. */
2988 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
2993 /* If no catchpoint triggered for this, then keep going. */
2994 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
2999 /* Given an execution control state that has been freshly filled in
3000 by an event from the inferior, figure out what it means and take
3001 appropriate action. */
3004 handle_inferior_event (struct execution_control_state *ecs)
3006 struct frame_info *frame;
3007 struct gdbarch *gdbarch;
3008 int sw_single_step_trap_p = 0;
3009 int stopped_by_watchpoint;
3010 int stepped_after_stopped_by_watchpoint = 0;
3011 struct symtab_and_line stop_pc_sal;
3012 enum stop_kind stop_soon;
3014 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
3016 /* We had an event in the inferior, but we are not interested in
3017 handling it at this level. The lower layers have already
3018 done what needs to be done, if anything.
3020 One of the possible circumstances for this is when the
3021 inferior produces output for the console. The inferior has
3022 not stopped, and we are ignoring the event. Another possible
3023 circumstance is any event which the lower level knows will be
3024 reported multiple times without an intervening resume. */
3026 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
3027 prepare_to_wait (ecs);
3031 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3032 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
3034 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
3037 stop_soon = inf->control.stop_soon;
3040 stop_soon = NO_STOP_QUIETLY;
3042 /* Cache the last pid/waitstatus. */
3043 target_last_wait_ptid = ecs->ptid;
3044 target_last_waitstatus = ecs->ws;
3046 /* Always clear state belonging to the previous time we stopped. */
3047 stop_stack_dummy = STOP_NONE;
3049 /* If it's a new process, add it to the thread database. */
3051 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
3052 && !ptid_equal (ecs->ptid, minus_one_ptid)
3053 && !in_thread_list (ecs->ptid));
3055 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3056 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
3057 add_thread (ecs->ptid);
3059 ecs->event_thread = find_thread_ptid (ecs->ptid);
3061 /* Dependent on valid ECS->EVENT_THREAD. */
3062 adjust_pc_after_break (ecs);
3064 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3065 reinit_frame_cache ();
3067 breakpoint_retire_moribund ();
3069 /* First, distinguish signals caused by the debugger from signals
3070 that have to do with the program's own actions. Note that
3071 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3072 on the operating system version. Here we detect when a SIGILL or
3073 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3074 something similar for SIGSEGV, since a SIGSEGV will be generated
3075 when we're trying to execute a breakpoint instruction on a
3076 non-executable stack. This happens for call dummy breakpoints
3077 for architectures like SPARC that place call dummies on the
3079 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
3080 && (ecs->ws.value.sig == TARGET_SIGNAL_ILL
3081 || ecs->ws.value.sig == TARGET_SIGNAL_SEGV
3082 || ecs->ws.value.sig == TARGET_SIGNAL_EMT))
3084 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3086 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3087 regcache_read_pc (regcache)))
3090 fprintf_unfiltered (gdb_stdlog,
3091 "infrun: Treating signal as SIGTRAP\n");
3092 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
3096 /* Mark the non-executing threads accordingly. In all-stop, all
3097 threads of all processes are stopped when we get any event
3098 reported. In non-stop mode, only the event thread stops. If
3099 we're handling a process exit in non-stop mode, there's nothing
3100 to do, as threads of the dead process are gone, and threads of
3101 any other process were left running. */
3103 set_executing (minus_one_ptid, 0);
3104 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3105 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
3106 set_executing (inferior_ptid, 0);
3108 switch (infwait_state)
3110 case infwait_thread_hop_state:
3112 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
3115 case infwait_normal_state:
3117 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
3120 case infwait_step_watch_state:
3122 fprintf_unfiltered (gdb_stdlog,
3123 "infrun: infwait_step_watch_state\n");
3125 stepped_after_stopped_by_watchpoint = 1;
3128 case infwait_nonstep_watch_state:
3130 fprintf_unfiltered (gdb_stdlog,
3131 "infrun: infwait_nonstep_watch_state\n");
3132 insert_breakpoints ();
3134 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3135 handle things like signals arriving and other things happening
3136 in combination correctly? */
3137 stepped_after_stopped_by_watchpoint = 1;
3141 internal_error (__FILE__, __LINE__, _("bad switch"));
3144 infwait_state = infwait_normal_state;
3145 waiton_ptid = pid_to_ptid (-1);
3147 switch (ecs->ws.kind)
3149 case TARGET_WAITKIND_LOADED:
3151 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
3152 /* Ignore gracefully during startup of the inferior, as it might
3153 be the shell which has just loaded some objects, otherwise
3154 add the symbols for the newly loaded objects. Also ignore at
3155 the beginning of an attach or remote session; we will query
3156 the full list of libraries once the connection is
3158 if (stop_soon == NO_STOP_QUIETLY)
3160 /* Check for any newly added shared libraries if we're
3161 supposed to be adding them automatically. Switch
3162 terminal for any messages produced by
3163 breakpoint_re_set. */
3164 target_terminal_ours_for_output ();
3165 /* NOTE: cagney/2003-11-25: Make certain that the target
3166 stack's section table is kept up-to-date. Architectures,
3167 (e.g., PPC64), use the section table to perform
3168 operations such as address => section name and hence
3169 require the table to contain all sections (including
3170 those found in shared libraries). */
3172 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
3174 solib_add (NULL, 0, ¤t_target, auto_solib_add);
3176 target_terminal_inferior ();
3178 /* If requested, stop when the dynamic linker notifies
3179 gdb of events. This allows the user to get control
3180 and place breakpoints in initializer routines for
3181 dynamically loaded objects (among other things). */
3182 if (stop_on_solib_events)
3184 /* Make sure we print "Stopped due to solib-event" in
3186 stop_print_frame = 1;
3188 stop_stepping (ecs);
3192 /* NOTE drow/2007-05-11: This might be a good place to check
3193 for "catch load". */
3196 /* If we are skipping through a shell, or through shared library
3197 loading that we aren't interested in, resume the program. If
3198 we're running the program normally, also resume. But stop if
3199 we're attaching or setting up a remote connection. */
3200 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
3202 /* Loading of shared libraries might have changed breakpoint
3203 addresses. Make sure new breakpoints are inserted. */
3204 if (stop_soon == NO_STOP_QUIETLY
3205 && !breakpoints_always_inserted_mode ())
3206 insert_breakpoints ();
3207 resume (0, TARGET_SIGNAL_0);
3208 prepare_to_wait (ecs);
3214 case TARGET_WAITKIND_SPURIOUS:
3216 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3217 resume (0, TARGET_SIGNAL_0);
3218 prepare_to_wait (ecs);
3221 case TARGET_WAITKIND_EXITED:
3223 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
3224 inferior_ptid = ecs->ptid;
3225 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3226 set_current_program_space (current_inferior ()->pspace);
3227 handle_vfork_child_exec_or_exit (0);
3228 target_terminal_ours (); /* Must do this before mourn anyway. */
3229 print_exited_reason (ecs->ws.value.integer);
3231 /* Record the exit code in the convenience variable $_exitcode, so
3232 that the user can inspect this again later. */
3233 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3234 (LONGEST) ecs->ws.value.integer);
3236 /* Also record this in the inferior itself. */
3237 current_inferior ()->has_exit_code = 1;
3238 current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer;
3240 gdb_flush (gdb_stdout);
3241 target_mourn_inferior ();
3242 singlestep_breakpoints_inserted_p = 0;
3243 cancel_single_step_breakpoints ();
3244 stop_print_frame = 0;
3245 stop_stepping (ecs);
3248 case TARGET_WAITKIND_SIGNALLED:
3250 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n");
3251 inferior_ptid = ecs->ptid;
3252 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3253 set_current_program_space (current_inferior ()->pspace);
3254 handle_vfork_child_exec_or_exit (0);
3255 stop_print_frame = 0;
3256 target_terminal_ours (); /* Must do this before mourn anyway. */
3258 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
3259 reach here unless the inferior is dead. However, for years
3260 target_kill() was called here, which hints that fatal signals aren't
3261 really fatal on some systems. If that's true, then some changes
3263 target_mourn_inferior ();
3265 print_signal_exited_reason (ecs->ws.value.sig);
3266 singlestep_breakpoints_inserted_p = 0;
3267 cancel_single_step_breakpoints ();
3268 stop_stepping (ecs);
3271 /* The following are the only cases in which we keep going;
3272 the above cases end in a continue or goto. */
3273 case TARGET_WAITKIND_FORKED:
3274 case TARGET_WAITKIND_VFORKED:
3276 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3278 if (!ptid_equal (ecs->ptid, inferior_ptid))
3280 context_switch (ecs->ptid);
3281 reinit_frame_cache ();
3284 /* Immediately detach breakpoints from the child before there's
3285 any chance of letting the user delete breakpoints from the
3286 breakpoint lists. If we don't do this early, it's easy to
3287 leave left over traps in the child, vis: "break foo; catch
3288 fork; c; <fork>; del; c; <child calls foo>". We only follow
3289 the fork on the last `continue', and by that time the
3290 breakpoint at "foo" is long gone from the breakpoint table.
3291 If we vforked, then we don't need to unpatch here, since both
3292 parent and child are sharing the same memory pages; we'll
3293 need to unpatch at follow/detach time instead to be certain
3294 that new breakpoints added between catchpoint hit time and
3295 vfork follow are detached. */
3296 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
3298 int child_pid = ptid_get_pid (ecs->ws.value.related_pid);
3300 /* This won't actually modify the breakpoint list, but will
3301 physically remove the breakpoints from the child. */
3302 detach_breakpoints (child_pid);
3305 if (singlestep_breakpoints_inserted_p)
3307 /* Pull the single step breakpoints out of the target. */
3308 remove_single_step_breakpoints ();
3309 singlestep_breakpoints_inserted_p = 0;
3312 /* In case the event is caught by a catchpoint, remember that
3313 the event is to be followed at the next resume of the thread,
3314 and not immediately. */
3315 ecs->event_thread->pending_follow = ecs->ws;
3317 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3319 ecs->event_thread->control.stop_bpstat
3320 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3321 stop_pc, ecs->ptid);
3323 /* Note that we're interested in knowing the bpstat actually
3324 causes a stop, not just if it may explain the signal.
3325 Software watchpoints, for example, always appear in the
3328 = !bpstat_causes_stop (ecs->event_thread->control.stop_bpstat);
3330 /* If no catchpoint triggered for this, then keep going. */
3331 if (ecs->random_signal)
3337 = (follow_fork_mode_string == follow_fork_mode_child);
3339 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3341 should_resume = follow_fork ();
3344 child = ecs->ws.value.related_pid;
3346 /* In non-stop mode, also resume the other branch. */
3347 if (non_stop && !detach_fork)
3350 switch_to_thread (parent);
3352 switch_to_thread (child);
3354 ecs->event_thread = inferior_thread ();
3355 ecs->ptid = inferior_ptid;
3360 switch_to_thread (child);
3362 switch_to_thread (parent);
3364 ecs->event_thread = inferior_thread ();
3365 ecs->ptid = inferior_ptid;
3370 stop_stepping (ecs);
3373 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3374 goto process_event_stop_test;
3376 case TARGET_WAITKIND_VFORK_DONE:
3377 /* Done with the shared memory region. Re-insert breakpoints in
3378 the parent, and keep going. */
3381 fprintf_unfiltered (gdb_stdlog,
3382 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3384 if (!ptid_equal (ecs->ptid, inferior_ptid))
3385 context_switch (ecs->ptid);
3387 current_inferior ()->waiting_for_vfork_done = 0;
3388 current_inferior ()->pspace->breakpoints_not_allowed = 0;
3389 /* This also takes care of reinserting breakpoints in the
3390 previously locked inferior. */
3394 case TARGET_WAITKIND_EXECD:
3396 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
3398 if (!ptid_equal (ecs->ptid, inferior_ptid))
3400 context_switch (ecs->ptid);
3401 reinit_frame_cache ();
3404 singlestep_breakpoints_inserted_p = 0;
3405 cancel_single_step_breakpoints ();
3407 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3409 /* Do whatever is necessary to the parent branch of the vfork. */
3410 handle_vfork_child_exec_or_exit (1);
3412 /* This causes the eventpoints and symbol table to be reset.
3413 Must do this now, before trying to determine whether to
3415 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
3417 ecs->event_thread->control.stop_bpstat
3418 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3419 stop_pc, ecs->ptid);
3421 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
3423 /* Note that this may be referenced from inside
3424 bpstat_stop_status above, through inferior_has_execd. */
3425 xfree (ecs->ws.value.execd_pathname);
3426 ecs->ws.value.execd_pathname = NULL;
3428 /* If no catchpoint triggered for this, then keep going. */
3429 if (ecs->random_signal)
3431 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3435 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3436 goto process_event_stop_test;
3438 /* Be careful not to try to gather much state about a thread
3439 that's in a syscall. It's frequently a losing proposition. */
3440 case TARGET_WAITKIND_SYSCALL_ENTRY:
3442 fprintf_unfiltered (gdb_stdlog,
3443 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3444 /* Getting the current syscall number. */
3445 if (handle_syscall_event (ecs) != 0)
3447 goto process_event_stop_test;
3449 /* Before examining the threads further, step this thread to
3450 get it entirely out of the syscall. (We get notice of the
3451 event when the thread is just on the verge of exiting a
3452 syscall. Stepping one instruction seems to get it back
3454 case TARGET_WAITKIND_SYSCALL_RETURN:
3456 fprintf_unfiltered (gdb_stdlog,
3457 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3458 if (handle_syscall_event (ecs) != 0)
3460 goto process_event_stop_test;
3462 case TARGET_WAITKIND_STOPPED:
3464 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
3465 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
3468 case TARGET_WAITKIND_NO_HISTORY:
3469 /* Reverse execution: target ran out of history info. */
3470 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3471 print_no_history_reason ();
3472 stop_stepping (ecs);
3476 if (ecs->new_thread_event)
3479 /* Non-stop assumes that the target handles adding new threads
3480 to the thread list. */
3481 internal_error (__FILE__, __LINE__,
3482 "targets should add new threads to the thread "
3483 "list themselves in non-stop mode.");
3485 /* We may want to consider not doing a resume here in order to
3486 give the user a chance to play with the new thread. It might
3487 be good to make that a user-settable option. */
3489 /* At this point, all threads are stopped (happens automatically
3490 in either the OS or the native code). Therefore we need to
3491 continue all threads in order to make progress. */
3493 if (!ptid_equal (ecs->ptid, inferior_ptid))
3494 context_switch (ecs->ptid);
3495 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
3496 prepare_to_wait (ecs);
3500 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
3502 /* Do we need to clean up the state of a thread that has
3503 completed a displaced single-step? (Doing so usually affects
3504 the PC, so do it here, before we set stop_pc.) */
3505 displaced_step_fixup (ecs->ptid,
3506 ecs->event_thread->suspend.stop_signal);
3508 /* If we either finished a single-step or hit a breakpoint, but
3509 the user wanted this thread to be stopped, pretend we got a
3510 SIG0 (generic unsignaled stop). */
3512 if (ecs->event_thread->stop_requested
3513 && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3514 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3517 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3521 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3522 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3523 struct cleanup *old_chain = save_inferior_ptid ();
3525 inferior_ptid = ecs->ptid;
3527 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
3528 paddress (gdbarch, stop_pc));
3529 if (target_stopped_by_watchpoint ())
3533 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
3535 if (target_stopped_data_address (¤t_target, &addr))
3536 fprintf_unfiltered (gdb_stdlog,
3537 "infrun: stopped data address = %s\n",
3538 paddress (gdbarch, addr));
3540 fprintf_unfiltered (gdb_stdlog,
3541 "infrun: (no data address available)\n");
3544 do_cleanups (old_chain);
3547 if (stepping_past_singlestep_breakpoint)
3549 gdb_assert (singlestep_breakpoints_inserted_p);
3550 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
3551 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
3553 stepping_past_singlestep_breakpoint = 0;
3555 /* We've either finished single-stepping past the single-step
3556 breakpoint, or stopped for some other reason. It would be nice if
3557 we could tell, but we can't reliably. */
3558 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3561 fprintf_unfiltered (gdb_stdlog,
3562 "infrun: stepping_past_"
3563 "singlestep_breakpoint\n");
3564 /* Pull the single step breakpoints out of the target. */
3565 remove_single_step_breakpoints ();
3566 singlestep_breakpoints_inserted_p = 0;
3568 ecs->random_signal = 0;
3569 ecs->event_thread->control.trap_expected = 0;
3571 context_switch (saved_singlestep_ptid);
3572 if (deprecated_context_hook)
3573 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3575 resume (1, TARGET_SIGNAL_0);
3576 prepare_to_wait (ecs);
3581 if (!ptid_equal (deferred_step_ptid, null_ptid))
3583 /* In non-stop mode, there's never a deferred_step_ptid set. */
3584 gdb_assert (!non_stop);
3586 /* If we stopped for some other reason than single-stepping, ignore
3587 the fact that we were supposed to switch back. */
3588 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3591 fprintf_unfiltered (gdb_stdlog,
3592 "infrun: handling deferred step\n");
3594 /* Pull the single step breakpoints out of the target. */
3595 if (singlestep_breakpoints_inserted_p)
3597 remove_single_step_breakpoints ();
3598 singlestep_breakpoints_inserted_p = 0;
3601 /* Note: We do not call context_switch at this point, as the
3602 context is already set up for stepping the original thread. */
3603 switch_to_thread (deferred_step_ptid);
3604 deferred_step_ptid = null_ptid;
3605 /* Suppress spurious "Switching to ..." message. */
3606 previous_inferior_ptid = inferior_ptid;
3608 resume (1, TARGET_SIGNAL_0);
3609 prepare_to_wait (ecs);
3613 deferred_step_ptid = null_ptid;
3616 /* See if a thread hit a thread-specific breakpoint that was meant for
3617 another thread. If so, then step that thread past the breakpoint,
3620 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3622 int thread_hop_needed = 0;
3623 struct address_space *aspace =
3624 get_regcache_aspace (get_thread_regcache (ecs->ptid));
3626 /* Check if a regular breakpoint has been hit before checking
3627 for a potential single step breakpoint. Otherwise, GDB will
3628 not see this breakpoint hit when stepping onto breakpoints. */
3629 if (regular_breakpoint_inserted_here_p (aspace, stop_pc))
3631 ecs->random_signal = 0;
3632 if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid))
3633 thread_hop_needed = 1;
3635 else if (singlestep_breakpoints_inserted_p)
3637 /* We have not context switched yet, so this should be true
3638 no matter which thread hit the singlestep breakpoint. */
3639 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
3641 fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
3643 target_pid_to_str (ecs->ptid));
3645 ecs->random_signal = 0;
3646 /* The call to in_thread_list is necessary because PTIDs sometimes
3647 change when we go from single-threaded to multi-threaded. If
3648 the singlestep_ptid is still in the list, assume that it is
3649 really different from ecs->ptid. */
3650 if (!ptid_equal (singlestep_ptid, ecs->ptid)
3651 && in_thread_list (singlestep_ptid))
3653 /* If the PC of the thread we were trying to single-step
3654 has changed, discard this event (which we were going
3655 to ignore anyway), and pretend we saw that thread
3656 trap. This prevents us continuously moving the
3657 single-step breakpoint forward, one instruction at a
3658 time. If the PC has changed, then the thread we were
3659 trying to single-step has trapped or been signalled,
3660 but the event has not been reported to GDB yet.
3662 There might be some cases where this loses signal
3663 information, if a signal has arrived at exactly the
3664 same time that the PC changed, but this is the best
3665 we can do with the information available. Perhaps we
3666 should arrange to report all events for all threads
3667 when they stop, or to re-poll the remote looking for
3668 this particular thread (i.e. temporarily enable
3671 CORE_ADDR new_singlestep_pc
3672 = regcache_read_pc (get_thread_regcache (singlestep_ptid));
3674 if (new_singlestep_pc != singlestep_pc)
3676 enum target_signal stop_signal;
3679 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
3680 " but expected thread advanced also\n");
3682 /* The current context still belongs to
3683 singlestep_ptid. Don't swap here, since that's
3684 the context we want to use. Just fudge our
3685 state and continue. */
3686 stop_signal = ecs->event_thread->suspend.stop_signal;
3687 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3688 ecs->ptid = singlestep_ptid;
3689 ecs->event_thread = find_thread_ptid (ecs->ptid);
3690 ecs->event_thread->suspend.stop_signal = stop_signal;
3691 stop_pc = new_singlestep_pc;
3696 fprintf_unfiltered (gdb_stdlog,
3697 "infrun: unexpected thread\n");
3699 thread_hop_needed = 1;
3700 stepping_past_singlestep_breakpoint = 1;
3701 saved_singlestep_ptid = singlestep_ptid;
3706 if (thread_hop_needed)
3708 struct regcache *thread_regcache;
3709 int remove_status = 0;
3712 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
3714 /* Switch context before touching inferior memory, the
3715 previous thread may have exited. */
3716 if (!ptid_equal (inferior_ptid, ecs->ptid))
3717 context_switch (ecs->ptid);
3719 /* Saw a breakpoint, but it was hit by the wrong thread.
3722 if (singlestep_breakpoints_inserted_p)
3724 /* Pull the single step breakpoints out of the target. */
3725 remove_single_step_breakpoints ();
3726 singlestep_breakpoints_inserted_p = 0;
3729 /* If the arch can displace step, don't remove the
3731 thread_regcache = get_thread_regcache (ecs->ptid);
3732 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
3733 remove_status = remove_breakpoints ();
3735 /* Did we fail to remove breakpoints? If so, try
3736 to set the PC past the bp. (There's at least
3737 one situation in which we can fail to remove
3738 the bp's: On HP-UX's that use ttrace, we can't
3739 change the address space of a vforking child
3740 process until the child exits (well, okay, not
3741 then either :-) or execs. */
3742 if (remove_status != 0)
3743 error (_("Cannot step over breakpoint hit in wrong thread"));
3748 /* Only need to require the next event from this
3749 thread in all-stop mode. */
3750 waiton_ptid = ecs->ptid;
3751 infwait_state = infwait_thread_hop_state;
3754 ecs->event_thread->stepping_over_breakpoint = 1;
3759 else if (singlestep_breakpoints_inserted_p)
3761 sw_single_step_trap_p = 1;
3762 ecs->random_signal = 0;
3766 ecs->random_signal = 1;
3768 /* See if something interesting happened to the non-current thread. If
3769 so, then switch to that thread. */
3770 if (!ptid_equal (ecs->ptid, inferior_ptid))
3773 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
3775 context_switch (ecs->ptid);
3777 if (deprecated_context_hook)
3778 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3781 /* At this point, get hold of the now-current thread's frame. */
3782 frame = get_current_frame ();
3783 gdbarch = get_frame_arch (frame);
3785 if (singlestep_breakpoints_inserted_p)
3787 /* Pull the single step breakpoints out of the target. */
3788 remove_single_step_breakpoints ();
3789 singlestep_breakpoints_inserted_p = 0;
3792 if (stepped_after_stopped_by_watchpoint)
3793 stopped_by_watchpoint = 0;
3795 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
3797 /* If necessary, step over this watchpoint. We'll be back to display
3799 if (stopped_by_watchpoint
3800 && (target_have_steppable_watchpoint
3801 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
3803 /* At this point, we are stopped at an instruction which has
3804 attempted to write to a piece of memory under control of
3805 a watchpoint. The instruction hasn't actually executed
3806 yet. If we were to evaluate the watchpoint expression
3807 now, we would get the old value, and therefore no change
3808 would seem to have occurred.
3810 In order to make watchpoints work `right', we really need
3811 to complete the memory write, and then evaluate the
3812 watchpoint expression. We do this by single-stepping the
3815 It may not be necessary to disable the watchpoint to stop over
3816 it. For example, the PA can (with some kernel cooperation)
3817 single step over a watchpoint without disabling the watchpoint.
3819 It is far more common to need to disable a watchpoint to step
3820 the inferior over it. If we have non-steppable watchpoints,
3821 we must disable the current watchpoint; it's simplest to
3822 disable all watchpoints and breakpoints. */
3825 if (!target_have_steppable_watchpoint)
3826 remove_breakpoints ();
3828 hw_step = maybe_software_singlestep (gdbarch, stop_pc);
3829 target_resume (ecs->ptid, hw_step, TARGET_SIGNAL_0);
3830 waiton_ptid = ecs->ptid;
3831 if (target_have_steppable_watchpoint)
3832 infwait_state = infwait_step_watch_state;
3834 infwait_state = infwait_nonstep_watch_state;
3835 prepare_to_wait (ecs);
3839 ecs->stop_func_start = 0;
3840 ecs->stop_func_end = 0;
3841 ecs->stop_func_name = 0;
3842 /* Don't care about return value; stop_func_start and stop_func_name
3843 will both be 0 if it doesn't work. */
3844 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3845 &ecs->stop_func_start, &ecs->stop_func_end);
3846 ecs->stop_func_start
3847 += gdbarch_deprecated_function_start_offset (gdbarch);
3848 ecs->event_thread->stepping_over_breakpoint = 0;
3849 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
3850 ecs->event_thread->control.stop_step = 0;
3851 stop_print_frame = 1;
3852 ecs->random_signal = 0;
3853 stopped_by_random_signal = 0;
3855 /* Hide inlined functions starting here, unless we just performed stepi or
3856 nexti. After stepi and nexti, always show the innermost frame (not any
3857 inline function call sites). */
3858 if (ecs->event_thread->control.step_range_end != 1)
3859 skip_inline_frames (ecs->ptid);
3861 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3862 && ecs->event_thread->control.trap_expected
3863 && gdbarch_single_step_through_delay_p (gdbarch)
3864 && currently_stepping (ecs->event_thread))
3866 /* We're trying to step off a breakpoint. Turns out that we're
3867 also on an instruction that needs to be stepped multiple
3868 times before it's been fully executing. E.g., architectures
3869 with a delay slot. It needs to be stepped twice, once for
3870 the instruction and once for the delay slot. */
3871 int step_through_delay
3872 = gdbarch_single_step_through_delay (gdbarch, frame);
3874 if (debug_infrun && step_through_delay)
3875 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
3876 if (ecs->event_thread->control.step_range_end == 0
3877 && step_through_delay)
3879 /* The user issued a continue when stopped at a breakpoint.
3880 Set up for another trap and get out of here. */
3881 ecs->event_thread->stepping_over_breakpoint = 1;
3885 else if (step_through_delay)
3887 /* The user issued a step when stopped at a breakpoint.
3888 Maybe we should stop, maybe we should not - the delay
3889 slot *might* correspond to a line of source. In any
3890 case, don't decide that here, just set
3891 ecs->stepping_over_breakpoint, making sure we
3892 single-step again before breakpoints are re-inserted. */
3893 ecs->event_thread->stepping_over_breakpoint = 1;
3897 /* Look at the cause of the stop, and decide what to do.
3898 The alternatives are:
3899 1) stop_stepping and return; to really stop and return to the debugger,
3900 2) keep_going and return to start up again
3901 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
3902 3) set ecs->random_signal to 1, and the decision between 1 and 2
3903 will be made according to the signal handling tables. */
3905 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3906 || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP
3907 || stop_soon == STOP_QUIETLY_REMOTE)
3909 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3913 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
3914 stop_print_frame = 0;
3915 stop_stepping (ecs);
3919 /* This is originated from start_remote(), start_inferior() and
3920 shared libraries hook functions. */
3921 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
3924 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
3925 stop_stepping (ecs);
3929 /* This originates from attach_command(). We need to overwrite
3930 the stop_signal here, because some kernels don't ignore a
3931 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3932 See more comments in inferior.h. On the other hand, if we
3933 get a non-SIGSTOP, report it to the user - assume the backend
3934 will handle the SIGSTOP if it should show up later.
3936 Also consider that the attach is complete when we see a
3937 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3938 target extended-remote report it instead of a SIGSTOP
3939 (e.g. gdbserver). We already rely on SIGTRAP being our
3940 signal, so this is no exception.
3942 Also consider that the attach is complete when we see a
3943 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3944 the target to stop all threads of the inferior, in case the
3945 low level attach operation doesn't stop them implicitly. If
3946 they weren't stopped implicitly, then the stub will report a
3947 TARGET_SIGNAL_0, meaning: stopped for no particular reason
3948 other than GDB's request. */
3949 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
3950 && (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_STOP
3951 || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3952 || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_0))
3954 stop_stepping (ecs);
3955 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3959 /* See if there is a breakpoint at the current PC. */
3960 ecs->event_thread->control.stop_bpstat
3961 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3962 stop_pc, ecs->ptid);
3964 /* Following in case break condition called a
3966 stop_print_frame = 1;
3968 /* This is where we handle "moribund" watchpoints. Unlike
3969 software breakpoints traps, hardware watchpoint traps are
3970 always distinguishable from random traps. If no high-level
3971 watchpoint is associated with the reported stop data address
3972 anymore, then the bpstat does not explain the signal ---
3973 simply make sure to ignore it if `stopped_by_watchpoint' is
3977 && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3978 && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat)
3979 && stopped_by_watchpoint)
3980 fprintf_unfiltered (gdb_stdlog,
3981 "infrun: no user watchpoint explains "
3982 "watchpoint SIGTRAP, ignoring\n");
3984 /* NOTE: cagney/2003-03-29: These two checks for a random signal
3985 at one stage in the past included checks for an inferior
3986 function call's call dummy's return breakpoint. The original
3987 comment, that went with the test, read:
3989 ``End of a stack dummy. Some systems (e.g. Sony news) give
3990 another signal besides SIGTRAP, so check here as well as
3993 If someone ever tries to get call dummys on a
3994 non-executable stack to work (where the target would stop
3995 with something like a SIGSEGV), then those tests might need
3996 to be re-instated. Given, however, that the tests were only
3997 enabled when momentary breakpoints were not being used, I
3998 suspect that it won't be the case.
4000 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4001 be necessary for call dummies on a non-executable stack on
4004 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
4006 = !(bpstat_explains_signal (ecs->event_thread->control.stop_bpstat)
4007 || stopped_by_watchpoint
4008 || ecs->event_thread->control.trap_expected
4009 || (ecs->event_thread->control.step_range_end
4010 && (ecs->event_thread->control.step_resume_breakpoint
4014 ecs->random_signal = !bpstat_explains_signal
4015 (ecs->event_thread->control.stop_bpstat);
4016 if (!ecs->random_signal)
4017 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
4021 /* When we reach this point, we've pretty much decided
4022 that the reason for stopping must've been a random
4023 (unexpected) signal. */
4026 ecs->random_signal = 1;
4028 process_event_stop_test:
4030 /* Re-fetch current thread's frame in case we did a
4031 "goto process_event_stop_test" above. */
4032 frame = get_current_frame ();
4033 gdbarch = get_frame_arch (frame);
4035 /* For the program's own signals, act according to
4036 the signal handling tables. */
4038 if (ecs->random_signal)
4040 /* Signal not for debugging purposes. */
4042 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
4045 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
4046 ecs->event_thread->suspend.stop_signal);
4048 stopped_by_random_signal = 1;
4050 if (signal_print[ecs->event_thread->suspend.stop_signal])
4053 target_terminal_ours_for_output ();
4054 print_signal_received_reason
4055 (ecs->event_thread->suspend.stop_signal);
4057 /* Always stop on signals if we're either just gaining control
4058 of the program, or the user explicitly requested this thread
4059 to remain stopped. */
4060 if (stop_soon != NO_STOP_QUIETLY
4061 || ecs->event_thread->stop_requested
4063 && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
4065 stop_stepping (ecs);
4068 /* If not going to stop, give terminal back
4069 if we took it away. */
4071 target_terminal_inferior ();
4073 /* Clear the signal if it should not be passed. */
4074 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
4075 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
4077 if (ecs->event_thread->prev_pc == stop_pc
4078 && ecs->event_thread->control.trap_expected
4079 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4081 /* We were just starting a new sequence, attempting to
4082 single-step off of a breakpoint and expecting a SIGTRAP.
4083 Instead this signal arrives. This signal will take us out
4084 of the stepping range so GDB needs to remember to, when
4085 the signal handler returns, resume stepping off that
4087 /* To simplify things, "continue" is forced to use the same
4088 code paths as single-step - set a breakpoint at the
4089 signal return address and then, once hit, step off that
4092 fprintf_unfiltered (gdb_stdlog,
4093 "infrun: signal arrived while stepping over "
4096 insert_step_resume_breakpoint_at_frame (frame);
4097 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4102 if (ecs->event_thread->control.step_range_end != 0
4103 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_0
4104 && (ecs->event_thread->control.step_range_start <= stop_pc
4105 && stop_pc < ecs->event_thread->control.step_range_end)
4106 && frame_id_eq (get_stack_frame_id (frame),
4107 ecs->event_thread->control.step_stack_frame_id)
4108 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4110 /* The inferior is about to take a signal that will take it
4111 out of the single step range. Set a breakpoint at the
4112 current PC (which is presumably where the signal handler
4113 will eventually return) and then allow the inferior to
4116 Note that this is only needed for a signal delivered
4117 while in the single-step range. Nested signals aren't a
4118 problem as they eventually all return. */
4120 fprintf_unfiltered (gdb_stdlog,
4121 "infrun: signal may take us out of "
4122 "single-step range\n");
4124 insert_step_resume_breakpoint_at_frame (frame);
4129 /* Note: step_resume_breakpoint may be non-NULL. This occures
4130 when either there's a nested signal, or when there's a
4131 pending signal enabled just as the signal handler returns
4132 (leaving the inferior at the step-resume-breakpoint without
4133 actually executing it). Either way continue until the
4134 breakpoint is really hit. */
4139 /* Handle cases caused by hitting a breakpoint. */
4141 CORE_ADDR jmp_buf_pc;
4142 struct bpstat_what what;
4144 what = bpstat_what (ecs->event_thread->control.stop_bpstat);
4146 if (what.call_dummy)
4148 stop_stack_dummy = what.call_dummy;
4151 /* If we hit an internal event that triggers symbol changes, the
4152 current frame will be invalidated within bpstat_what (e.g., if
4153 we hit an internal solib event). Re-fetch it. */
4154 frame = get_current_frame ();
4155 gdbarch = get_frame_arch (frame);
4157 switch (what.main_action)
4159 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
4160 /* If we hit the breakpoint at longjmp while stepping, we
4161 install a momentary breakpoint at the target of the
4165 fprintf_unfiltered (gdb_stdlog,
4166 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4168 ecs->event_thread->stepping_over_breakpoint = 1;
4170 if (what.is_longjmp)
4172 if (!gdbarch_get_longjmp_target_p (gdbarch)
4173 || !gdbarch_get_longjmp_target (gdbarch,
4174 frame, &jmp_buf_pc))
4177 fprintf_unfiltered (gdb_stdlog,
4178 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4179 "(!gdbarch_get_longjmp_target)\n");
4184 /* We're going to replace the current step-resume breakpoint
4185 with a longjmp-resume breakpoint. */
4186 delete_step_resume_breakpoint (ecs->event_thread);
4188 /* Insert a breakpoint at resume address. */
4189 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4193 struct symbol *func = get_frame_function (frame);
4196 check_exception_resume (ecs, frame, func);
4201 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4203 fprintf_unfiltered (gdb_stdlog,
4204 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4206 if (what.is_longjmp)
4208 gdb_assert (ecs->event_thread->control.step_resume_breakpoint
4210 delete_step_resume_breakpoint (ecs->event_thread);
4214 /* There are several cases to consider.
4216 1. The initiating frame no longer exists. In this case
4217 we must stop, because the exception has gone too far.
4219 2. The initiating frame exists, and is the same as the
4220 current frame. We stop, because the exception has been
4223 3. The initiating frame exists and is different from
4224 the current frame. This means the exception has been
4225 caught beneath the initiating frame, so keep going. */
4226 struct frame_info *init_frame
4227 = frame_find_by_id (ecs->event_thread->initiating_frame);
4229 gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
4231 delete_exception_resume_breakpoint (ecs->event_thread);
4235 struct frame_id current_id
4236 = get_frame_id (get_current_frame ());
4237 if (frame_id_eq (current_id,
4238 ecs->event_thread->initiating_frame))
4240 /* Case 2. Fall through. */
4250 /* For Cases 1 and 2, remove the step-resume breakpoint,
4252 delete_step_resume_breakpoint (ecs->event_thread);
4255 ecs->event_thread->control.stop_step = 1;
4256 print_end_stepping_range_reason ();
4257 stop_stepping (ecs);
4260 case BPSTAT_WHAT_SINGLE:
4262 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
4263 ecs->event_thread->stepping_over_breakpoint = 1;
4264 /* Still need to check other stuff, at least the case
4265 where we are stepping and step out of the right range. */
4268 case BPSTAT_WHAT_STOP_NOISY:
4270 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4271 stop_print_frame = 1;
4273 /* We are about to nuke the step_resume_breakpointt via the
4274 cleanup chain, so no need to worry about it here. */
4276 stop_stepping (ecs);
4279 case BPSTAT_WHAT_STOP_SILENT:
4281 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4282 stop_print_frame = 0;
4284 /* We are about to nuke the step_resume_breakpoin via the
4285 cleanup chain, so no need to worry about it here. */
4287 stop_stepping (ecs);
4290 case BPSTAT_WHAT_STEP_RESUME:
4292 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4294 delete_step_resume_breakpoint (ecs->event_thread);
4295 if (ecs->event_thread->step_after_step_resume_breakpoint)
4297 /* Back when the step-resume breakpoint was inserted, we
4298 were trying to single-step off a breakpoint. Go back
4300 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4301 ecs->event_thread->stepping_over_breakpoint = 1;
4305 if (stop_pc == ecs->stop_func_start
4306 && execution_direction == EXEC_REVERSE)
4308 /* We are stepping over a function call in reverse, and
4309 just hit the step-resume breakpoint at the start
4310 address of the function. Go back to single-stepping,
4311 which should take us back to the function call. */
4312 ecs->event_thread->stepping_over_breakpoint = 1;
4318 case BPSTAT_WHAT_KEEP_CHECKING:
4323 /* We come here if we hit a breakpoint but should not
4324 stop for it. Possibly we also were stepping
4325 and should stop for that. So fall through and
4326 test for stepping. But, if not stepping,
4329 /* In all-stop mode, if we're currently stepping but have stopped in
4330 some other thread, we need to switch back to the stepped thread. */
4333 struct thread_info *tp;
4335 tp = iterate_over_threads (currently_stepping_or_nexting_callback,
4339 /* However, if the current thread is blocked on some internal
4340 breakpoint, and we simply need to step over that breakpoint
4341 to get it going again, do that first. */
4342 if ((ecs->event_thread->control.trap_expected
4343 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP)
4344 || ecs->event_thread->stepping_over_breakpoint)
4350 /* If the stepping thread exited, then don't try to switch
4351 back and resume it, which could fail in several different
4352 ways depending on the target. Instead, just keep going.
4354 We can find a stepping dead thread in the thread list in
4357 - The target supports thread exit events, and when the
4358 target tries to delete the thread from the thread list,
4359 inferior_ptid pointed at the exiting thread. In such
4360 case, calling delete_thread does not really remove the
4361 thread from the list; instead, the thread is left listed,
4362 with 'exited' state.
4364 - The target's debug interface does not support thread
4365 exit events, and so we have no idea whatsoever if the
4366 previously stepping thread is still alive. For that
4367 reason, we need to synchronously query the target
4369 if (is_exited (tp->ptid)
4370 || !target_thread_alive (tp->ptid))
4373 fprintf_unfiltered (gdb_stdlog,
4374 "infrun: not switching back to "
4375 "stepped thread, it has vanished\n");
4377 delete_thread (tp->ptid);
4382 /* Otherwise, we no longer expect a trap in the current thread.
4383 Clear the trap_expected flag before switching back -- this is
4384 what keep_going would do as well, if we called it. */
4385 ecs->event_thread->control.trap_expected = 0;
4388 fprintf_unfiltered (gdb_stdlog,
4389 "infrun: switching back to stepped thread\n");
4391 ecs->event_thread = tp;
4392 ecs->ptid = tp->ptid;
4393 context_switch (ecs->ptid);
4399 /* Are we stepping to get the inferior out of the dynamic linker's
4400 hook (and possibly the dld itself) after catching a shlib
4402 if (ecs->event_thread->stepping_through_solib_after_catch)
4404 #if defined(SOLIB_ADD)
4405 /* Have we reached our destination? If not, keep going. */
4406 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
4409 fprintf_unfiltered (gdb_stdlog,
4410 "infrun: stepping in dynamic linker\n");
4411 ecs->event_thread->stepping_over_breakpoint = 1;
4417 fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n");
4418 /* Else, stop and report the catchpoint(s) whose triggering
4419 caused us to begin stepping. */
4420 ecs->event_thread->stepping_through_solib_after_catch = 0;
4421 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
4422 ecs->event_thread->control.stop_bpstat
4423 = bpstat_copy (ecs->event_thread->stepping_through_solib_catchpoints);
4424 bpstat_clear (&ecs->event_thread->stepping_through_solib_catchpoints);
4425 stop_print_frame = 1;
4426 stop_stepping (ecs);
4430 if (ecs->event_thread->control.step_resume_breakpoint)
4433 fprintf_unfiltered (gdb_stdlog,
4434 "infrun: step-resume breakpoint is inserted\n");
4436 /* Having a step-resume breakpoint overrides anything
4437 else having to do with stepping commands until
4438 that breakpoint is reached. */
4443 if (ecs->event_thread->control.step_range_end == 0)
4446 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
4447 /* Likewise if we aren't even stepping. */
4452 /* Re-fetch current thread's frame in case the code above caused
4453 the frame cache to be re-initialized, making our FRAME variable
4454 a dangling pointer. */
4455 frame = get_current_frame ();
4456 gdbarch = get_frame_arch (frame);
4458 /* If stepping through a line, keep going if still within it.
4460 Note that step_range_end is the address of the first instruction
4461 beyond the step range, and NOT the address of the last instruction
4464 Note also that during reverse execution, we may be stepping
4465 through a function epilogue and therefore must detect when
4466 the current-frame changes in the middle of a line. */
4468 if (stop_pc >= ecs->event_thread->control.step_range_start
4469 && stop_pc < ecs->event_thread->control.step_range_end
4470 && (execution_direction != EXEC_REVERSE
4471 || frame_id_eq (get_frame_id (frame),
4472 ecs->event_thread->control.step_frame_id)))
4476 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
4477 paddress (gdbarch, ecs->event_thread->control.step_range_start),
4478 paddress (gdbarch, ecs->event_thread->control.step_range_end));
4480 /* When stepping backward, stop at beginning of line range
4481 (unless it's the function entry point, in which case
4482 keep going back to the call point). */
4483 if (stop_pc == ecs->event_thread->control.step_range_start
4484 && stop_pc != ecs->stop_func_start
4485 && execution_direction == EXEC_REVERSE)
4487 ecs->event_thread->control.stop_step = 1;
4488 print_end_stepping_range_reason ();
4489 stop_stepping (ecs);
4497 /* We stepped out of the stepping range. */
4499 /* If we are stepping at the source level and entered the runtime
4500 loader dynamic symbol resolution code...
4502 EXEC_FORWARD: we keep on single stepping until we exit the run
4503 time loader code and reach the callee's address.
4505 EXEC_REVERSE: we've already executed the callee (backward), and
4506 the runtime loader code is handled just like any other
4507 undebuggable function call. Now we need only keep stepping
4508 backward through the trampoline code, and that's handled further
4509 down, so there is nothing for us to do here. */
4511 if (execution_direction != EXEC_REVERSE
4512 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4513 && in_solib_dynsym_resolve_code (stop_pc))
4515 CORE_ADDR pc_after_resolver =
4516 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
4519 fprintf_unfiltered (gdb_stdlog,
4520 "infrun: stepped into dynsym resolve code\n");
4522 if (pc_after_resolver)
4524 /* Set up a step-resume breakpoint at the address
4525 indicated by SKIP_SOLIB_RESOLVER. */
4526 struct symtab_and_line sr_sal;
4529 sr_sal.pc = pc_after_resolver;
4530 sr_sal.pspace = get_frame_program_space (frame);
4532 insert_step_resume_breakpoint_at_sal (gdbarch,
4533 sr_sal, null_frame_id);
4540 if (ecs->event_thread->control.step_range_end != 1
4541 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4542 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4543 && get_frame_type (frame) == SIGTRAMP_FRAME)
4546 fprintf_unfiltered (gdb_stdlog,
4547 "infrun: stepped into signal trampoline\n");
4548 /* The inferior, while doing a "step" or "next", has ended up in
4549 a signal trampoline (either by a signal being delivered or by
4550 the signal handler returning). Just single-step until the
4551 inferior leaves the trampoline (either by calling the handler
4557 /* Check for subroutine calls. The check for the current frame
4558 equalling the step ID is not necessary - the check of the
4559 previous frame's ID is sufficient - but it is a common case and
4560 cheaper than checking the previous frame's ID.
4562 NOTE: frame_id_eq will never report two invalid frame IDs as
4563 being equal, so to get into this block, both the current and
4564 previous frame must have valid frame IDs. */
4565 /* The outer_frame_id check is a heuristic to detect stepping
4566 through startup code. If we step over an instruction which
4567 sets the stack pointer from an invalid value to a valid value,
4568 we may detect that as a subroutine call from the mythical
4569 "outermost" function. This could be fixed by marking
4570 outermost frames as !stack_p,code_p,special_p. Then the
4571 initial outermost frame, before sp was valid, would
4572 have code_addr == &_start. See the comment in frame_id_eq
4574 if (!frame_id_eq (get_stack_frame_id (frame),
4575 ecs->event_thread->control.step_stack_frame_id)
4576 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4577 ecs->event_thread->control.step_stack_frame_id)
4578 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
4580 || step_start_function != find_pc_function (stop_pc))))
4582 CORE_ADDR real_stop_pc;
4585 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
4587 if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
4588 || ((ecs->event_thread->control.step_range_end == 1)
4589 && in_prologue (gdbarch, ecs->event_thread->prev_pc,
4590 ecs->stop_func_start)))
4592 /* I presume that step_over_calls is only 0 when we're
4593 supposed to be stepping at the assembly language level
4594 ("stepi"). Just stop. */
4595 /* Also, maybe we just did a "nexti" inside a prolog, so we
4596 thought it was a subroutine call but it was not. Stop as
4598 /* And this works the same backward as frontward. MVS */
4599 ecs->event_thread->control.stop_step = 1;
4600 print_end_stepping_range_reason ();
4601 stop_stepping (ecs);
4605 /* Reverse stepping through solib trampolines. */
4607 if (execution_direction == EXEC_REVERSE
4608 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
4609 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4610 || (ecs->stop_func_start == 0
4611 && in_solib_dynsym_resolve_code (stop_pc))))
4613 /* Any solib trampoline code can be handled in reverse
4614 by simply continuing to single-step. We have already
4615 executed the solib function (backwards), and a few
4616 steps will take us back through the trampoline to the
4622 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4624 /* We're doing a "next".
4626 Normal (forward) execution: set a breakpoint at the
4627 callee's return address (the address at which the caller
4630 Reverse (backward) execution. set the step-resume
4631 breakpoint at the start of the function that we just
4632 stepped into (backwards), and continue to there. When we
4633 get there, we'll need to single-step back to the caller. */
4635 if (execution_direction == EXEC_REVERSE)
4637 struct symtab_and_line sr_sal;
4639 /* Normal function call return (static or dynamic). */
4641 sr_sal.pc = ecs->stop_func_start;
4642 sr_sal.pspace = get_frame_program_space (frame);
4643 insert_step_resume_breakpoint_at_sal (gdbarch,
4644 sr_sal, null_frame_id);
4647 insert_step_resume_breakpoint_at_caller (frame);
4653 /* If we are in a function call trampoline (a stub between the
4654 calling routine and the real function), locate the real
4655 function. That's what tells us (a) whether we want to step
4656 into it at all, and (b) what prologue we want to run to the
4657 end of, if we do step into it. */
4658 real_stop_pc = skip_language_trampoline (frame, stop_pc);
4659 if (real_stop_pc == 0)
4660 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4661 if (real_stop_pc != 0)
4662 ecs->stop_func_start = real_stop_pc;
4664 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
4666 struct symtab_and_line sr_sal;
4669 sr_sal.pc = ecs->stop_func_start;
4670 sr_sal.pspace = get_frame_program_space (frame);
4672 insert_step_resume_breakpoint_at_sal (gdbarch,
4673 sr_sal, null_frame_id);
4678 /* If we have line number information for the function we are
4679 thinking of stepping into, step into it.
4681 If there are several symtabs at that PC (e.g. with include
4682 files), just want to know whether *any* of them have line
4683 numbers. find_pc_line handles this. */
4685 struct symtab_and_line tmp_sal;
4687 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
4688 if (tmp_sal.line != 0)
4690 if (execution_direction == EXEC_REVERSE)
4691 handle_step_into_function_backward (gdbarch, ecs);
4693 handle_step_into_function (gdbarch, ecs);
4698 /* If we have no line number and the step-stop-if-no-debug is
4699 set, we stop the step so that the user has a chance to switch
4700 in assembly mode. */
4701 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4702 && step_stop_if_no_debug)
4704 ecs->event_thread->control.stop_step = 1;
4705 print_end_stepping_range_reason ();
4706 stop_stepping (ecs);
4710 if (execution_direction == EXEC_REVERSE)
4712 /* Set a breakpoint at callee's start address.
4713 From there we can step once and be back in the caller. */
4714 struct symtab_and_line sr_sal;
4717 sr_sal.pc = ecs->stop_func_start;
4718 sr_sal.pspace = get_frame_program_space (frame);
4719 insert_step_resume_breakpoint_at_sal (gdbarch,
4720 sr_sal, null_frame_id);
4723 /* Set a breakpoint at callee's return address (the address
4724 at which the caller will resume). */
4725 insert_step_resume_breakpoint_at_caller (frame);
4731 /* Reverse stepping through solib trampolines. */
4733 if (execution_direction == EXEC_REVERSE
4734 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
4736 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4737 || (ecs->stop_func_start == 0
4738 && in_solib_dynsym_resolve_code (stop_pc)))
4740 /* Any solib trampoline code can be handled in reverse
4741 by simply continuing to single-step. We have already
4742 executed the solib function (backwards), and a few
4743 steps will take us back through the trampoline to the
4748 else if (in_solib_dynsym_resolve_code (stop_pc))
4750 /* Stepped backward into the solib dynsym resolver.
4751 Set a breakpoint at its start and continue, then
4752 one more step will take us out. */
4753 struct symtab_and_line sr_sal;
4756 sr_sal.pc = ecs->stop_func_start;
4757 sr_sal.pspace = get_frame_program_space (frame);
4758 insert_step_resume_breakpoint_at_sal (gdbarch,
4759 sr_sal, null_frame_id);
4765 /* If we're in the return path from a shared library trampoline,
4766 we want to proceed through the trampoline when stepping. */
4767 if (gdbarch_in_solib_return_trampoline (gdbarch,
4768 stop_pc, ecs->stop_func_name))
4770 /* Determine where this trampoline returns. */
4771 CORE_ADDR real_stop_pc;
4773 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4776 fprintf_unfiltered (gdb_stdlog,
4777 "infrun: stepped into solib return tramp\n");
4779 /* Only proceed through if we know where it's going. */
4782 /* And put the step-breakpoint there and go until there. */
4783 struct symtab_and_line sr_sal;
4785 init_sal (&sr_sal); /* initialize to zeroes */
4786 sr_sal.pc = real_stop_pc;
4787 sr_sal.section = find_pc_overlay (sr_sal.pc);
4788 sr_sal.pspace = get_frame_program_space (frame);
4790 /* Do not specify what the fp should be when we stop since
4791 on some machines the prologue is where the new fp value
4793 insert_step_resume_breakpoint_at_sal (gdbarch,
4794 sr_sal, null_frame_id);
4796 /* Restart without fiddling with the step ranges or
4803 stop_pc_sal = find_pc_line (stop_pc, 0);
4805 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4806 the trampoline processing logic, however, there are some trampolines
4807 that have no names, so we should do trampoline handling first. */
4808 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4809 && ecs->stop_func_name == NULL
4810 && stop_pc_sal.line == 0)
4813 fprintf_unfiltered (gdb_stdlog,
4814 "infrun: stepped into undebuggable function\n");
4816 /* The inferior just stepped into, or returned to, an
4817 undebuggable function (where there is no debugging information
4818 and no line number corresponding to the address where the
4819 inferior stopped). Since we want to skip this kind of code,
4820 we keep going until the inferior returns from this
4821 function - unless the user has asked us not to (via
4822 set step-mode) or we no longer know how to get back
4823 to the call site. */
4824 if (step_stop_if_no_debug
4825 || !frame_id_p (frame_unwind_caller_id (frame)))
4827 /* If we have no line number and the step-stop-if-no-debug
4828 is set, we stop the step so that the user has a chance to
4829 switch in assembly mode. */
4830 ecs->event_thread->control.stop_step = 1;
4831 print_end_stepping_range_reason ();
4832 stop_stepping (ecs);
4837 /* Set a breakpoint at callee's return address (the address
4838 at which the caller will resume). */
4839 insert_step_resume_breakpoint_at_caller (frame);
4845 if (ecs->event_thread->control.step_range_end == 1)
4847 /* It is stepi or nexti. We always want to stop stepping after
4850 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
4851 ecs->event_thread->control.stop_step = 1;
4852 print_end_stepping_range_reason ();
4853 stop_stepping (ecs);
4857 if (stop_pc_sal.line == 0)
4859 /* We have no line number information. That means to stop
4860 stepping (does this always happen right after one instruction,
4861 when we do "s" in a function with no line numbers,
4862 or can this happen as a result of a return or longjmp?). */
4864 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
4865 ecs->event_thread->control.stop_step = 1;
4866 print_end_stepping_range_reason ();
4867 stop_stepping (ecs);
4871 /* Look for "calls" to inlined functions, part one. If the inline
4872 frame machinery detected some skipped call sites, we have entered
4873 a new inline function. */
4875 if (frame_id_eq (get_frame_id (get_current_frame ()),
4876 ecs->event_thread->control.step_frame_id)
4877 && inline_skipped_frames (ecs->ptid))
4879 struct symtab_and_line call_sal;
4882 fprintf_unfiltered (gdb_stdlog,
4883 "infrun: stepped into inlined function\n");
4885 find_frame_sal (get_current_frame (), &call_sal);
4887 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
4889 /* For "step", we're going to stop. But if the call site
4890 for this inlined function is on the same source line as
4891 we were previously stepping, go down into the function
4892 first. Otherwise stop at the call site. */
4894 if (call_sal.line == ecs->event_thread->current_line
4895 && call_sal.symtab == ecs->event_thread->current_symtab)
4896 step_into_inline_frame (ecs->ptid);
4898 ecs->event_thread->control.stop_step = 1;
4899 print_end_stepping_range_reason ();
4900 stop_stepping (ecs);
4905 /* For "next", we should stop at the call site if it is on a
4906 different source line. Otherwise continue through the
4907 inlined function. */
4908 if (call_sal.line == ecs->event_thread->current_line
4909 && call_sal.symtab == ecs->event_thread->current_symtab)
4913 ecs->event_thread->control.stop_step = 1;
4914 print_end_stepping_range_reason ();
4915 stop_stepping (ecs);
4921 /* Look for "calls" to inlined functions, part two. If we are still
4922 in the same real function we were stepping through, but we have
4923 to go further up to find the exact frame ID, we are stepping
4924 through a more inlined call beyond its call site. */
4926 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
4927 && !frame_id_eq (get_frame_id (get_current_frame ()),
4928 ecs->event_thread->control.step_frame_id)
4929 && stepped_in_from (get_current_frame (),
4930 ecs->event_thread->control.step_frame_id))
4933 fprintf_unfiltered (gdb_stdlog,
4934 "infrun: stepping through inlined function\n");
4936 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4940 ecs->event_thread->control.stop_step = 1;
4941 print_end_stepping_range_reason ();
4942 stop_stepping (ecs);
4947 if ((stop_pc == stop_pc_sal.pc)
4948 && (ecs->event_thread->current_line != stop_pc_sal.line
4949 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
4951 /* We are at the start of a different line. So stop. Note that
4952 we don't stop if we step into the middle of a different line.
4953 That is said to make things like for (;;) statements work
4956 fprintf_unfiltered (gdb_stdlog,
4957 "infrun: stepped to a different line\n");
4958 ecs->event_thread->control.stop_step = 1;
4959 print_end_stepping_range_reason ();
4960 stop_stepping (ecs);
4964 /* We aren't done stepping.
4966 Optimize by setting the stepping range to the line.
4967 (We might not be in the original line, but if we entered a
4968 new line in mid-statement, we continue stepping. This makes
4969 things like for(;;) statements work better.) */
4971 ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
4972 ecs->event_thread->control.step_range_end = stop_pc_sal.end;
4973 set_step_info (frame, stop_pc_sal);
4976 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
4980 /* Is thread TP in the middle of single-stepping? */
4983 currently_stepping (struct thread_info *tp)
4985 return ((tp->control.step_range_end
4986 && tp->control.step_resume_breakpoint == NULL)
4987 || tp->control.trap_expected
4988 || tp->stepping_through_solib_after_catch
4989 || bpstat_should_step ());
4992 /* Returns true if any thread *but* the one passed in "data" is in the
4993 middle of stepping or of handling a "next". */
4996 currently_stepping_or_nexting_callback (struct thread_info *tp, void *data)
5001 return (tp->control.step_range_end
5002 || tp->control.trap_expected
5003 || tp->stepping_through_solib_after_catch);
5006 /* Inferior has stepped into a subroutine call with source code that
5007 we should not step over. Do step to the first line of code in
5011 handle_step_into_function (struct gdbarch *gdbarch,
5012 struct execution_control_state *ecs)
5015 struct symtab_and_line stop_func_sal, sr_sal;
5017 s = find_pc_symtab (stop_pc);
5018 if (s && s->language != language_asm)
5019 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5020 ecs->stop_func_start);
5022 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
5023 /* Use the step_resume_break to step until the end of the prologue,
5024 even if that involves jumps (as it seems to on the vax under
5026 /* If the prologue ends in the middle of a source line, continue to
5027 the end of that source line (if it is still within the function).
5028 Otherwise, just go to end of prologue. */
5029 if (stop_func_sal.end
5030 && stop_func_sal.pc != ecs->stop_func_start
5031 && stop_func_sal.end < ecs->stop_func_end)
5032 ecs->stop_func_start = stop_func_sal.end;
5034 /* Architectures which require breakpoint adjustment might not be able
5035 to place a breakpoint at the computed address. If so, the test
5036 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5037 ecs->stop_func_start to an address at which a breakpoint may be
5038 legitimately placed.
5040 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5041 made, GDB will enter an infinite loop when stepping through
5042 optimized code consisting of VLIW instructions which contain
5043 subinstructions corresponding to different source lines. On
5044 FR-V, it's not permitted to place a breakpoint on any but the
5045 first subinstruction of a VLIW instruction. When a breakpoint is
5046 set, GDB will adjust the breakpoint address to the beginning of
5047 the VLIW instruction. Thus, we need to make the corresponding
5048 adjustment here when computing the stop address. */
5050 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
5052 ecs->stop_func_start
5053 = gdbarch_adjust_breakpoint_address (gdbarch,
5054 ecs->stop_func_start);
5057 if (ecs->stop_func_start == stop_pc)
5059 /* We are already there: stop now. */
5060 ecs->event_thread->control.stop_step = 1;
5061 print_end_stepping_range_reason ();
5062 stop_stepping (ecs);
5067 /* Put the step-breakpoint there and go until there. */
5068 init_sal (&sr_sal); /* initialize to zeroes */
5069 sr_sal.pc = ecs->stop_func_start;
5070 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
5071 sr_sal.pspace = get_frame_program_space (get_current_frame ());
5073 /* Do not specify what the fp should be when we stop since on
5074 some machines the prologue is where the new fp value is
5076 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
5078 /* And make sure stepping stops right away then. */
5079 ecs->event_thread->control.step_range_end
5080 = ecs->event_thread->control.step_range_start;
5085 /* Inferior has stepped backward into a subroutine call with source
5086 code that we should not step over. Do step to the beginning of the
5087 last line of code in it. */
5090 handle_step_into_function_backward (struct gdbarch *gdbarch,
5091 struct execution_control_state *ecs)
5094 struct symtab_and_line stop_func_sal;
5096 s = find_pc_symtab (stop_pc);
5097 if (s && s->language != language_asm)
5098 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5099 ecs->stop_func_start);
5101 stop_func_sal = find_pc_line (stop_pc, 0);
5103 /* OK, we're just going to keep stepping here. */
5104 if (stop_func_sal.pc == stop_pc)
5106 /* We're there already. Just stop stepping now. */
5107 ecs->event_thread->control.stop_step = 1;
5108 print_end_stepping_range_reason ();
5109 stop_stepping (ecs);
5113 /* Else just reset the step range and keep going.
5114 No step-resume breakpoint, they don't work for
5115 epilogues, which can have multiple entry paths. */
5116 ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5117 ecs->event_thread->control.step_range_end = stop_func_sal.end;
5123 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5124 This is used to both functions and to skip over code. */
5127 insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5128 struct symtab_and_line sr_sal,
5129 struct frame_id sr_id)
5131 /* There should never be more than one step-resume or longjmp-resume
5132 breakpoint per thread, so we should never be setting a new
5133 step_resume_breakpoint when one is already active. */
5134 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5137 fprintf_unfiltered (gdb_stdlog,
5138 "infrun: inserting step-resume breakpoint at %s\n",
5139 paddress (gdbarch, sr_sal.pc));
5141 inferior_thread ()->control.step_resume_breakpoint
5142 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, bp_step_resume);
5145 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
5146 to skip a potential signal handler.
5148 This is called with the interrupted function's frame. The signal
5149 handler, when it returns, will resume the interrupted function at
5153 insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
5155 struct symtab_and_line sr_sal;
5156 struct gdbarch *gdbarch;
5158 gdb_assert (return_frame != NULL);
5159 init_sal (&sr_sal); /* initialize to zeros */
5161 gdbarch = get_frame_arch (return_frame);
5162 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
5163 sr_sal.section = find_pc_overlay (sr_sal.pc);
5164 sr_sal.pspace = get_frame_program_space (return_frame);
5166 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5167 get_stack_frame_id (return_frame));
5170 /* Similar to insert_step_resume_breakpoint_at_frame, except
5171 but a breakpoint at the previous frame's PC. This is used to
5172 skip a function after stepping into it (for "next" or if the called
5173 function has no debugging information).
5175 The current function has almost always been reached by single
5176 stepping a call or return instruction. NEXT_FRAME belongs to the
5177 current function, and the breakpoint will be set at the caller's
5180 This is a separate function rather than reusing
5181 insert_step_resume_breakpoint_at_frame in order to avoid
5182 get_prev_frame, which may stop prematurely (see the implementation
5183 of frame_unwind_caller_id for an example). */
5186 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
5188 struct symtab_and_line sr_sal;
5189 struct gdbarch *gdbarch;
5191 /* We shouldn't have gotten here if we don't know where the call site
5193 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
5195 init_sal (&sr_sal); /* initialize to zeros */
5197 gdbarch = frame_unwind_caller_arch (next_frame);
5198 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
5199 frame_unwind_caller_pc (next_frame));
5200 sr_sal.section = find_pc_overlay (sr_sal.pc);
5201 sr_sal.pspace = frame_unwind_program_space (next_frame);
5203 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5204 frame_unwind_caller_id (next_frame));
5207 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5208 new breakpoint at the target of a jmp_buf. The handling of
5209 longjmp-resume uses the same mechanisms used for handling
5210 "step-resume" breakpoints. */
5213 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
5215 /* There should never be more than one step-resume or longjmp-resume
5216 breakpoint per thread, so we should never be setting a new
5217 longjmp_resume_breakpoint when one is already active. */
5218 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5221 fprintf_unfiltered (gdb_stdlog,
5222 "infrun: inserting longjmp-resume breakpoint at %s\n",
5223 paddress (gdbarch, pc));
5225 inferior_thread ()->control.step_resume_breakpoint =
5226 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
5229 /* Insert an exception resume breakpoint. TP is the thread throwing
5230 the exception. The block B is the block of the unwinder debug hook
5231 function. FRAME is the frame corresponding to the call to this
5232 function. SYM is the symbol of the function argument holding the
5233 target PC of the exception. */
5236 insert_exception_resume_breakpoint (struct thread_info *tp,
5238 struct frame_info *frame,
5241 struct gdb_exception e;
5243 /* We want to ignore errors here. */
5244 TRY_CATCH (e, RETURN_MASK_ERROR)
5246 struct symbol *vsym;
5247 struct value *value;
5249 struct breakpoint *bp;
5251 vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
5252 value = read_var_value (vsym, frame);
5253 /* If the value was optimized out, revert to the old behavior. */
5254 if (! value_optimized_out (value))
5256 handler = value_as_address (value);
5259 fprintf_unfiltered (gdb_stdlog,
5260 "infrun: exception resume at %lx\n",
5261 (unsigned long) handler);
5263 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5264 handler, bp_exception_resume);
5265 bp->thread = tp->num;
5266 inferior_thread ()->control.exception_resume_breakpoint = bp;
5271 /* This is called when an exception has been intercepted. Check to
5272 see whether the exception's destination is of interest, and if so,
5273 set an exception resume breakpoint there. */
5276 check_exception_resume (struct execution_control_state *ecs,
5277 struct frame_info *frame, struct symbol *func)
5279 struct gdb_exception e;
5281 TRY_CATCH (e, RETURN_MASK_ERROR)
5284 struct dict_iterator iter;
5288 /* The exception breakpoint is a thread-specific breakpoint on
5289 the unwinder's debug hook, declared as:
5291 void _Unwind_DebugHook (void *cfa, void *handler);
5293 The CFA argument indicates the frame to which control is
5294 about to be transferred. HANDLER is the destination PC.
5296 We ignore the CFA and set a temporary breakpoint at HANDLER.
5297 This is not extremely efficient but it avoids issues in gdb
5298 with computing the DWARF CFA, and it also works even in weird
5299 cases such as throwing an exception from inside a signal
5302 b = SYMBOL_BLOCK_VALUE (func);
5303 ALL_BLOCK_SYMBOLS (b, iter, sym)
5305 if (!SYMBOL_IS_ARGUMENT (sym))
5312 insert_exception_resume_breakpoint (ecs->event_thread,
5321 stop_stepping (struct execution_control_state *ecs)
5324 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
5326 /* Let callers know we don't want to wait for the inferior anymore. */
5327 ecs->wait_some_more = 0;
5330 /* This function handles various cases where we need to continue
5331 waiting for the inferior. */
5332 /* (Used to be the keep_going: label in the old wait_for_inferior). */
5335 keep_going (struct execution_control_state *ecs)
5337 /* Make sure normal_stop is called if we get a QUIT handled before
5339 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
5341 /* Save the pc before execution, to compare with pc after stop. */
5342 ecs->event_thread->prev_pc
5343 = regcache_read_pc (get_thread_regcache (ecs->ptid));
5345 /* If we did not do break;, it means we should keep running the
5346 inferior and not return to debugger. */
5348 if (ecs->event_thread->control.trap_expected
5349 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP)
5351 /* We took a signal (which we are supposed to pass through to
5352 the inferior, else we'd not get here) and we haven't yet
5353 gotten our trap. Simply continue. */
5355 discard_cleanups (old_cleanups);
5356 resume (currently_stepping (ecs->event_thread),
5357 ecs->event_thread->suspend.stop_signal);
5361 /* Either the trap was not expected, but we are continuing
5362 anyway (the user asked that this signal be passed to the
5365 The signal was SIGTRAP, e.g. it was our signal, but we
5366 decided we should resume from it.
5368 We're going to run this baby now!
5370 Note that insert_breakpoints won't try to re-insert
5371 already inserted breakpoints. Therefore, we don't
5372 care if breakpoints were already inserted, or not. */
5374 if (ecs->event_thread->stepping_over_breakpoint)
5376 struct regcache *thread_regcache = get_thread_regcache (ecs->ptid);
5378 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
5379 /* Since we can't do a displaced step, we have to remove
5380 the breakpoint while we step it. To keep things
5381 simple, we remove them all. */
5382 remove_breakpoints ();
5386 struct gdb_exception e;
5388 /* Stop stepping when inserting breakpoints
5390 TRY_CATCH (e, RETURN_MASK_ERROR)
5392 insert_breakpoints ();
5396 exception_print (gdb_stderr, e);
5397 stop_stepping (ecs);
5402 ecs->event_thread->control.trap_expected
5403 = ecs->event_thread->stepping_over_breakpoint;
5405 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5406 specifies that such a signal should be delivered to the
5409 Typically, this would occure when a user is debugging a
5410 target monitor on a simulator: the target monitor sets a
5411 breakpoint; the simulator encounters this break-point and
5412 halts the simulation handing control to GDB; GDB, noteing
5413 that the break-point isn't valid, returns control back to the
5414 simulator; the simulator then delivers the hardware
5415 equivalent of a SIGNAL_TRAP to the program being debugged. */
5417 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
5418 && !signal_program[ecs->event_thread->suspend.stop_signal])
5419 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
5421 discard_cleanups (old_cleanups);
5422 resume (currently_stepping (ecs->event_thread),
5423 ecs->event_thread->suspend.stop_signal);
5426 prepare_to_wait (ecs);
5429 /* This function normally comes after a resume, before
5430 handle_inferior_event exits. It takes care of any last bits of
5431 housekeeping, and sets the all-important wait_some_more flag. */
5434 prepare_to_wait (struct execution_control_state *ecs)
5437 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
5439 /* This is the old end of the while loop. Let everybody know we
5440 want to wait for the inferior some more and get called again
5442 ecs->wait_some_more = 1;
5445 /* Several print_*_reason functions to print why the inferior has stopped.
5446 We always print something when the inferior exits, or receives a signal.
5447 The rest of the cases are dealt with later on in normal_stop and
5448 print_it_typical. Ideally there should be a call to one of these
5449 print_*_reason functions functions from handle_inferior_event each time
5450 stop_stepping is called. */
5452 /* Print why the inferior has stopped.
5453 We are done with a step/next/si/ni command, print why the inferior has
5454 stopped. For now print nothing. Print a message only if not in the middle
5455 of doing a "step n" operation for n > 1. */
5458 print_end_stepping_range_reason (void)
5460 if ((!inferior_thread ()->step_multi
5461 || !inferior_thread ()->control.stop_step)
5462 && ui_out_is_mi_like_p (uiout))
5463 ui_out_field_string (uiout, "reason",
5464 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
5467 /* The inferior was terminated by a signal, print why it stopped. */
5470 print_signal_exited_reason (enum target_signal siggnal)
5472 annotate_signalled ();
5473 if (ui_out_is_mi_like_p (uiout))
5475 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
5476 ui_out_text (uiout, "\nProgram terminated with signal ");
5477 annotate_signal_name ();
5478 ui_out_field_string (uiout, "signal-name",
5479 target_signal_to_name (siggnal));
5480 annotate_signal_name_end ();
5481 ui_out_text (uiout, ", ");
5482 annotate_signal_string ();
5483 ui_out_field_string (uiout, "signal-meaning",
5484 target_signal_to_string (siggnal));
5485 annotate_signal_string_end ();
5486 ui_out_text (uiout, ".\n");
5487 ui_out_text (uiout, "The program no longer exists.\n");
5490 /* The inferior program is finished, print why it stopped. */
5493 print_exited_reason (int exitstatus)
5495 struct inferior *inf = current_inferior ();
5496 const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid));
5498 annotate_exited (exitstatus);
5501 if (ui_out_is_mi_like_p (uiout))
5502 ui_out_field_string (uiout, "reason",
5503 async_reason_lookup (EXEC_ASYNC_EXITED));
5504 ui_out_text (uiout, "[Inferior ");
5505 ui_out_text (uiout, plongest (inf->num));
5506 ui_out_text (uiout, " (");
5507 ui_out_text (uiout, pidstr);
5508 ui_out_text (uiout, ") exited with code ");
5509 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
5510 ui_out_text (uiout, "]\n");
5514 if (ui_out_is_mi_like_p (uiout))
5516 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
5517 ui_out_text (uiout, "[Inferior ");
5518 ui_out_text (uiout, plongest (inf->num));
5519 ui_out_text (uiout, " (");
5520 ui_out_text (uiout, pidstr);
5521 ui_out_text (uiout, ") exited normally]\n");
5523 /* Support the --return-child-result option. */
5524 return_child_result_value = exitstatus;
5527 /* Signal received, print why the inferior has stopped. The signal table
5528 tells us to print about it. */
5531 print_signal_received_reason (enum target_signal siggnal)
5535 if (siggnal == TARGET_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
5537 struct thread_info *t = inferior_thread ();
5539 ui_out_text (uiout, "\n[");
5540 ui_out_field_string (uiout, "thread-name",
5541 target_pid_to_str (t->ptid));
5542 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
5543 ui_out_text (uiout, " stopped");
5547 ui_out_text (uiout, "\nProgram received signal ");
5548 annotate_signal_name ();
5549 if (ui_out_is_mi_like_p (uiout))
5551 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
5552 ui_out_field_string (uiout, "signal-name",
5553 target_signal_to_name (siggnal));
5554 annotate_signal_name_end ();
5555 ui_out_text (uiout, ", ");
5556 annotate_signal_string ();
5557 ui_out_field_string (uiout, "signal-meaning",
5558 target_signal_to_string (siggnal));
5559 annotate_signal_string_end ();
5561 ui_out_text (uiout, ".\n");
5564 /* Reverse execution: target ran out of history info, print why the inferior
5568 print_no_history_reason (void)
5570 ui_out_text (uiout, "\nNo more reverse-execution history.\n");
5573 /* Here to return control to GDB when the inferior stops for real.
5574 Print appropriate messages, remove breakpoints, give terminal our modes.
5576 STOP_PRINT_FRAME nonzero means print the executing frame
5577 (pc, function, args, file, line number and line text).
5578 BREAKPOINTS_FAILED nonzero means stop was due to error
5579 attempting to insert breakpoints. */
5584 struct target_waitstatus last;
5586 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
5588 get_last_target_status (&last_ptid, &last);
5590 /* If an exception is thrown from this point on, make sure to
5591 propagate GDB's knowledge of the executing state to the
5592 frontend/user running state. A QUIT is an easy exception to see
5593 here, so do this before any filtered output. */
5595 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
5596 else if (last.kind != TARGET_WAITKIND_SIGNALLED
5597 && last.kind != TARGET_WAITKIND_EXITED)
5598 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
5600 /* In non-stop mode, we don't want GDB to switch threads behind the
5601 user's back, to avoid races where the user is typing a command to
5602 apply to thread x, but GDB switches to thread y before the user
5603 finishes entering the command. */
5605 /* As with the notification of thread events, we want to delay
5606 notifying the user that we've switched thread context until
5607 the inferior actually stops.
5609 There's no point in saying anything if the inferior has exited.
5610 Note that SIGNALLED here means "exited with a signal", not
5611 "received a signal". */
5613 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
5614 && target_has_execution
5615 && last.kind != TARGET_WAITKIND_SIGNALLED
5616 && last.kind != TARGET_WAITKIND_EXITED)
5618 target_terminal_ours_for_output ();
5619 printf_filtered (_("[Switching to %s]\n"),
5620 target_pid_to_str (inferior_ptid));
5621 annotate_thread_changed ();
5622 previous_inferior_ptid = inferior_ptid;
5625 if (!breakpoints_always_inserted_mode () && target_has_execution)
5627 if (remove_breakpoints ())
5629 target_terminal_ours_for_output ();
5630 printf_filtered (_("Cannot remove breakpoints because "
5631 "program is no longer writable.\nFurther "
5632 "execution is probably impossible.\n"));
5636 /* If an auto-display called a function and that got a signal,
5637 delete that auto-display to avoid an infinite recursion. */
5639 if (stopped_by_random_signal)
5640 disable_current_display ();
5642 /* Don't print a message if in the middle of doing a "step n"
5643 operation for n > 1 */
5644 if (target_has_execution
5645 && last.kind != TARGET_WAITKIND_SIGNALLED
5646 && last.kind != TARGET_WAITKIND_EXITED
5647 && inferior_thread ()->step_multi
5648 && inferior_thread ()->control.stop_step)
5651 target_terminal_ours ();
5653 /* Set the current source location. This will also happen if we
5654 display the frame below, but the current SAL will be incorrect
5655 during a user hook-stop function. */
5656 if (has_stack_frames () && !stop_stack_dummy)
5657 set_current_sal_from_frame (get_current_frame (), 1);
5659 /* Let the user/frontend see the threads as stopped. */
5660 do_cleanups (old_chain);
5662 /* Look up the hook_stop and run it (CLI internally handles problem
5663 of stop_command's pre-hook not existing). */
5665 catch_errors (hook_stop_stub, stop_command,
5666 "Error while running hook_stop:\n", RETURN_MASK_ALL);
5668 if (!has_stack_frames ())
5671 if (last.kind == TARGET_WAITKIND_SIGNALLED
5672 || last.kind == TARGET_WAITKIND_EXITED)
5675 /* Select innermost stack frame - i.e., current frame is frame 0,
5676 and current location is based on that.
5677 Don't do this on return from a stack dummy routine,
5678 or if the program has exited. */
5680 if (!stop_stack_dummy)
5682 select_frame (get_current_frame ());
5684 /* Print current location without a level number, if
5685 we have changed functions or hit a breakpoint.
5686 Print source line if we have one.
5687 bpstat_print() contains the logic deciding in detail
5688 what to print, based on the event(s) that just occurred. */
5690 /* If --batch-silent is enabled then there's no need to print the current
5691 source location, and to try risks causing an error message about
5692 missing source files. */
5693 if (stop_print_frame && !batch_silent)
5697 int do_frame_printing = 1;
5698 struct thread_info *tp = inferior_thread ();
5700 bpstat_ret = bpstat_print (tp->control.stop_bpstat);
5704 /* If we had hit a shared library event breakpoint,
5705 bpstat_print would print out this message. If we hit
5706 an OS-level shared library event, do the same
5708 if (last.kind == TARGET_WAITKIND_LOADED)
5710 printf_filtered (_("Stopped due to shared library event\n"));
5711 source_flag = SRC_LINE; /* something bogus */
5712 do_frame_printing = 0;
5716 /* FIXME: cagney/2002-12-01: Given that a frame ID does
5717 (or should) carry around the function and does (or
5718 should) use that when doing a frame comparison. */
5719 if (tp->control.stop_step
5720 && frame_id_eq (tp->control.step_frame_id,
5721 get_frame_id (get_current_frame ()))
5722 && step_start_function == find_pc_function (stop_pc))
5723 source_flag = SRC_LINE; /* Finished step, just
5724 print source line. */
5726 source_flag = SRC_AND_LOC; /* Print location and
5729 case PRINT_SRC_AND_LOC:
5730 source_flag = SRC_AND_LOC; /* Print location and
5733 case PRINT_SRC_ONLY:
5734 source_flag = SRC_LINE;
5737 source_flag = SRC_LINE; /* something bogus */
5738 do_frame_printing = 0;
5741 internal_error (__FILE__, __LINE__, _("Unknown value."));
5744 /* The behavior of this routine with respect to the source
5746 SRC_LINE: Print only source line
5747 LOCATION: Print only location
5748 SRC_AND_LOC: Print location and source line. */
5749 if (do_frame_printing)
5750 print_stack_frame (get_selected_frame (NULL), 0, source_flag);
5752 /* Display the auto-display expressions. */
5757 /* Save the function value return registers, if we care.
5758 We might be about to restore their previous contents. */
5759 if (inferior_thread ()->control.proceed_to_finish)
5761 /* This should not be necessary. */
5763 regcache_xfree (stop_registers);
5765 /* NB: The copy goes through to the target picking up the value of
5766 all the registers. */
5767 stop_registers = regcache_dup (get_current_regcache ());
5770 if (stop_stack_dummy == STOP_STACK_DUMMY)
5772 /* Pop the empty frame that contains the stack dummy.
5773 This also restores inferior state prior to the call
5774 (struct infcall_suspend_state). */
5775 struct frame_info *frame = get_current_frame ();
5777 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
5779 /* frame_pop() calls reinit_frame_cache as the last thing it
5780 does which means there's currently no selected frame. We
5781 don't need to re-establish a selected frame if the dummy call
5782 returns normally, that will be done by
5783 restore_infcall_control_state. However, we do have to handle
5784 the case where the dummy call is returning after being
5785 stopped (e.g. the dummy call previously hit a breakpoint).
5786 We can't know which case we have so just always re-establish
5787 a selected frame here. */
5788 select_frame (get_current_frame ());
5792 annotate_stopped ();
5794 /* Suppress the stop observer if we're in the middle of:
5796 - a step n (n > 1), as there still more steps to be done.
5798 - a "finish" command, as the observer will be called in
5799 finish_command_continuation, so it can include the inferior
5800 function's return value.
5802 - calling an inferior function, as we pretend we inferior didn't
5803 run at all. The return value of the call is handled by the
5804 expression evaluator, through call_function_by_hand. */
5806 if (!target_has_execution
5807 || last.kind == TARGET_WAITKIND_SIGNALLED
5808 || last.kind == TARGET_WAITKIND_EXITED
5809 || (!inferior_thread ()->step_multi
5810 && !(inferior_thread ()->control.stop_bpstat
5811 && inferior_thread ()->control.proceed_to_finish)
5812 && !inferior_thread ()->control.in_infcall))
5814 if (!ptid_equal (inferior_ptid, null_ptid))
5815 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
5818 observer_notify_normal_stop (NULL, stop_print_frame);
5821 if (target_has_execution)
5823 if (last.kind != TARGET_WAITKIND_SIGNALLED
5824 && last.kind != TARGET_WAITKIND_EXITED)
5825 /* Delete the breakpoint we stopped at, if it wants to be deleted.
5826 Delete any breakpoint that is to be deleted at the next stop. */
5827 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
5830 /* Try to get rid of automatically added inferiors that are no
5831 longer needed. Keeping those around slows down things linearly.
5832 Note that this never removes the current inferior. */
5837 hook_stop_stub (void *cmd)
5839 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
5844 signal_stop_state (int signo)
5846 return signal_stop[signo];
5850 signal_print_state (int signo)
5852 return signal_print[signo];
5856 signal_pass_state (int signo)
5858 return signal_program[signo];
5862 signal_stop_update (int signo, int state)
5864 int ret = signal_stop[signo];
5866 signal_stop[signo] = state;
5871 signal_print_update (int signo, int state)
5873 int ret = signal_print[signo];
5875 signal_print[signo] = state;
5880 signal_pass_update (int signo, int state)
5882 int ret = signal_program[signo];
5884 signal_program[signo] = state;
5889 sig_print_header (void)
5891 printf_filtered (_("Signal Stop\tPrint\tPass "
5892 "to program\tDescription\n"));
5896 sig_print_info (enum target_signal oursig)
5898 const char *name = target_signal_to_name (oursig);
5899 int name_padding = 13 - strlen (name);
5901 if (name_padding <= 0)
5904 printf_filtered ("%s", name);
5905 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
5906 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
5907 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
5908 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
5909 printf_filtered ("%s\n", target_signal_to_string (oursig));
5912 /* Specify how various signals in the inferior should be handled. */
5915 handle_command (char *args, int from_tty)
5918 int digits, wordlen;
5919 int sigfirst, signum, siglast;
5920 enum target_signal oursig;
5923 unsigned char *sigs;
5924 struct cleanup *old_chain;
5928 error_no_arg (_("signal to handle"));
5931 /* Allocate and zero an array of flags for which signals to handle. */
5933 nsigs = (int) TARGET_SIGNAL_LAST;
5934 sigs = (unsigned char *) alloca (nsigs);
5935 memset (sigs, 0, nsigs);
5937 /* Break the command line up into args. */
5939 argv = gdb_buildargv (args);
5940 old_chain = make_cleanup_freeargv (argv);
5942 /* Walk through the args, looking for signal oursigs, signal names, and
5943 actions. Signal numbers and signal names may be interspersed with
5944 actions, with the actions being performed for all signals cumulatively
5945 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
5947 while (*argv != NULL)
5949 wordlen = strlen (*argv);
5950 for (digits = 0; isdigit ((*argv)[digits]); digits++)
5954 sigfirst = siglast = -1;
5956 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
5958 /* Apply action to all signals except those used by the
5959 debugger. Silently skip those. */
5962 siglast = nsigs - 1;
5964 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
5966 SET_SIGS (nsigs, sigs, signal_stop);
5967 SET_SIGS (nsigs, sigs, signal_print);
5969 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
5971 UNSET_SIGS (nsigs, sigs, signal_program);
5973 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
5975 SET_SIGS (nsigs, sigs, signal_print);
5977 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
5979 SET_SIGS (nsigs, sigs, signal_program);
5981 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
5983 UNSET_SIGS (nsigs, sigs, signal_stop);
5985 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
5987 SET_SIGS (nsigs, sigs, signal_program);
5989 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
5991 UNSET_SIGS (nsigs, sigs, signal_print);
5992 UNSET_SIGS (nsigs, sigs, signal_stop);
5994 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
5996 UNSET_SIGS (nsigs, sigs, signal_program);
5998 else if (digits > 0)
6000 /* It is numeric. The numeric signal refers to our own
6001 internal signal numbering from target.h, not to host/target
6002 signal number. This is a feature; users really should be
6003 using symbolic names anyway, and the common ones like
6004 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6006 sigfirst = siglast = (int)
6007 target_signal_from_command (atoi (*argv));
6008 if ((*argv)[digits] == '-')
6011 target_signal_from_command (atoi ((*argv) + digits + 1));
6013 if (sigfirst > siglast)
6015 /* Bet he didn't figure we'd think of this case... */
6023 oursig = target_signal_from_name (*argv);
6024 if (oursig != TARGET_SIGNAL_UNKNOWN)
6026 sigfirst = siglast = (int) oursig;
6030 /* Not a number and not a recognized flag word => complain. */
6031 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
6035 /* If any signal numbers or symbol names were found, set flags for
6036 which signals to apply actions to. */
6038 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
6040 switch ((enum target_signal) signum)
6042 case TARGET_SIGNAL_TRAP:
6043 case TARGET_SIGNAL_INT:
6044 if (!allsigs && !sigs[signum])
6046 if (query (_("%s is used by the debugger.\n\
6047 Are you sure you want to change it? "),
6048 target_signal_to_name ((enum target_signal) signum)))
6054 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6055 gdb_flush (gdb_stdout);
6059 case TARGET_SIGNAL_0:
6060 case TARGET_SIGNAL_DEFAULT:
6061 case TARGET_SIGNAL_UNKNOWN:
6062 /* Make sure that "all" doesn't print these. */
6073 for (signum = 0; signum < nsigs; signum++)
6076 target_notice_signals (inferior_ptid);
6080 /* Show the results. */
6081 sig_print_header ();
6082 for (; signum < nsigs; signum++)
6084 sig_print_info (signum);
6090 do_cleanups (old_chain);
6094 xdb_handle_command (char *args, int from_tty)
6097 struct cleanup *old_chain;
6100 error_no_arg (_("xdb command"));
6102 /* Break the command line up into args. */
6104 argv = gdb_buildargv (args);
6105 old_chain = make_cleanup_freeargv (argv);
6106 if (argv[1] != (char *) NULL)
6111 bufLen = strlen (argv[0]) + 20;
6112 argBuf = (char *) xmalloc (bufLen);
6116 enum target_signal oursig;
6118 oursig = target_signal_from_name (argv[0]);
6119 memset (argBuf, 0, bufLen);
6120 if (strcmp (argv[1], "Q") == 0)
6121 sprintf (argBuf, "%s %s", argv[0], "noprint");
6124 if (strcmp (argv[1], "s") == 0)
6126 if (!signal_stop[oursig])
6127 sprintf (argBuf, "%s %s", argv[0], "stop");
6129 sprintf (argBuf, "%s %s", argv[0], "nostop");
6131 else if (strcmp (argv[1], "i") == 0)
6133 if (!signal_program[oursig])
6134 sprintf (argBuf, "%s %s", argv[0], "pass");
6136 sprintf (argBuf, "%s %s", argv[0], "nopass");
6138 else if (strcmp (argv[1], "r") == 0)
6140 if (!signal_print[oursig])
6141 sprintf (argBuf, "%s %s", argv[0], "print");
6143 sprintf (argBuf, "%s %s", argv[0], "noprint");
6149 handle_command (argBuf, from_tty);
6151 printf_filtered (_("Invalid signal handling flag.\n"));
6156 do_cleanups (old_chain);
6159 /* Print current contents of the tables set by the handle command.
6160 It is possible we should just be printing signals actually used
6161 by the current target (but for things to work right when switching
6162 targets, all signals should be in the signal tables). */
6165 signals_info (char *signum_exp, int from_tty)
6167 enum target_signal oursig;
6169 sig_print_header ();
6173 /* First see if this is a symbol name. */
6174 oursig = target_signal_from_name (signum_exp);
6175 if (oursig == TARGET_SIGNAL_UNKNOWN)
6177 /* No, try numeric. */
6179 target_signal_from_command (parse_and_eval_long (signum_exp));
6181 sig_print_info (oursig);
6185 printf_filtered ("\n");
6186 /* These ugly casts brought to you by the native VAX compiler. */
6187 for (oursig = TARGET_SIGNAL_FIRST;
6188 (int) oursig < (int) TARGET_SIGNAL_LAST;
6189 oursig = (enum target_signal) ((int) oursig + 1))
6193 if (oursig != TARGET_SIGNAL_UNKNOWN
6194 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
6195 sig_print_info (oursig);
6198 printf_filtered (_("\nUse the \"handle\" command "
6199 "to change these tables.\n"));
6202 /* The $_siginfo convenience variable is a bit special. We don't know
6203 for sure the type of the value until we actually have a chance to
6204 fetch the data. The type can change depending on gdbarch, so it it
6205 also dependent on which thread you have selected.
6207 1. making $_siginfo be an internalvar that creates a new value on
6210 2. making the value of $_siginfo be an lval_computed value. */
6212 /* This function implements the lval_computed support for reading a
6216 siginfo_value_read (struct value *v)
6218 LONGEST transferred;
6221 target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO,
6223 value_contents_all_raw (v),
6225 TYPE_LENGTH (value_type (v)));
6227 if (transferred != TYPE_LENGTH (value_type (v)))
6228 error (_("Unable to read siginfo"));
6231 /* This function implements the lval_computed support for writing a
6235 siginfo_value_write (struct value *v, struct value *fromval)
6237 LONGEST transferred;
6239 transferred = target_write (¤t_target,
6240 TARGET_OBJECT_SIGNAL_INFO,
6242 value_contents_all_raw (fromval),
6244 TYPE_LENGTH (value_type (fromval)));
6246 if (transferred != TYPE_LENGTH (value_type (fromval)))
6247 error (_("Unable to write siginfo"));
6250 static struct lval_funcs siginfo_value_funcs =
6256 /* Return a new value with the correct type for the siginfo object of
6257 the current thread using architecture GDBARCH. Return a void value
6258 if there's no object available. */
6260 static struct value *
6261 siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var)
6263 if (target_has_stack
6264 && !ptid_equal (inferior_ptid, null_ptid)
6265 && gdbarch_get_siginfo_type_p (gdbarch))
6267 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6269 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
6272 return allocate_value (builtin_type (gdbarch)->builtin_void);
6276 /* infcall_suspend_state contains state about the program itself like its
6277 registers and any signal it received when it last stopped.
6278 This state must be restored regardless of how the inferior function call
6279 ends (either successfully, or after it hits a breakpoint or signal)
6280 if the program is to properly continue where it left off. */
6282 struct infcall_suspend_state
6284 struct thread_suspend_state thread_suspend;
6285 struct inferior_suspend_state inferior_suspend;
6289 struct regcache *registers;
6291 /* Format of SIGINFO_DATA or NULL if it is not present. */
6292 struct gdbarch *siginfo_gdbarch;
6294 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6295 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6296 content would be invalid. */
6297 gdb_byte *siginfo_data;
6300 struct infcall_suspend_state *
6301 save_infcall_suspend_state (void)
6303 struct infcall_suspend_state *inf_state;
6304 struct thread_info *tp = inferior_thread ();
6305 struct inferior *inf = current_inferior ();
6306 struct regcache *regcache = get_current_regcache ();
6307 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6308 gdb_byte *siginfo_data = NULL;
6310 if (gdbarch_get_siginfo_type_p (gdbarch))
6312 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6313 size_t len = TYPE_LENGTH (type);
6314 struct cleanup *back_to;
6316 siginfo_data = xmalloc (len);
6317 back_to = make_cleanup (xfree, siginfo_data);
6319 if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6320 siginfo_data, 0, len) == len)
6321 discard_cleanups (back_to);
6324 /* Errors ignored. */
6325 do_cleanups (back_to);
6326 siginfo_data = NULL;
6330 inf_state = XZALLOC (struct infcall_suspend_state);
6334 inf_state->siginfo_gdbarch = gdbarch;
6335 inf_state->siginfo_data = siginfo_data;
6338 inf_state->thread_suspend = tp->suspend;
6339 inf_state->inferior_suspend = inf->suspend;
6341 /* run_inferior_call will not use the signal due to its `proceed' call with
6342 TARGET_SIGNAL_0 anyway. */
6343 tp->suspend.stop_signal = TARGET_SIGNAL_0;
6345 inf_state->stop_pc = stop_pc;
6347 inf_state->registers = regcache_dup (regcache);
6352 /* Restore inferior session state to INF_STATE. */
6355 restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6357 struct thread_info *tp = inferior_thread ();
6358 struct inferior *inf = current_inferior ();
6359 struct regcache *regcache = get_current_regcache ();
6360 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6362 tp->suspend = inf_state->thread_suspend;
6363 inf->suspend = inf_state->inferior_suspend;
6365 stop_pc = inf_state->stop_pc;
6367 if (inf_state->siginfo_gdbarch == gdbarch)
6369 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6370 size_t len = TYPE_LENGTH (type);
6372 /* Errors ignored. */
6373 target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6374 inf_state->siginfo_data, 0, len);
6377 /* The inferior can be gone if the user types "print exit(0)"
6378 (and perhaps other times). */
6379 if (target_has_execution)
6380 /* NB: The register write goes through to the target. */
6381 regcache_cpy (regcache, inf_state->registers);
6383 discard_infcall_suspend_state (inf_state);
6387 do_restore_infcall_suspend_state_cleanup (void *state)
6389 restore_infcall_suspend_state (state);
6393 make_cleanup_restore_infcall_suspend_state
6394 (struct infcall_suspend_state *inf_state)
6396 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
6400 discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6402 regcache_xfree (inf_state->registers);
6403 xfree (inf_state->siginfo_data);
6408 get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
6410 return inf_state->registers;
6413 /* infcall_control_state contains state regarding gdb's control of the
6414 inferior itself like stepping control. It also contains session state like
6415 the user's currently selected frame. */
6417 struct infcall_control_state
6419 struct thread_control_state thread_control;
6420 struct inferior_control_state inferior_control;
6423 enum stop_stack_kind stop_stack_dummy;
6424 int stopped_by_random_signal;
6425 int stop_after_trap;
6427 /* ID if the selected frame when the inferior function call was made. */
6428 struct frame_id selected_frame_id;
6431 /* Save all of the information associated with the inferior<==>gdb
6434 struct infcall_control_state *
6435 save_infcall_control_state (void)
6437 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
6438 struct thread_info *tp = inferior_thread ();
6439 struct inferior *inf = current_inferior ();
6441 inf_status->thread_control = tp->control;
6442 inf_status->inferior_control = inf->control;
6444 tp->control.step_resume_breakpoint = NULL;
6445 tp->control.exception_resume_breakpoint = NULL;
6447 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6448 chain. If caller's caller is walking the chain, they'll be happier if we
6449 hand them back the original chain when restore_infcall_control_state is
6451 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
6454 inf_status->stop_stack_dummy = stop_stack_dummy;
6455 inf_status->stopped_by_random_signal = stopped_by_random_signal;
6456 inf_status->stop_after_trap = stop_after_trap;
6458 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
6464 restore_selected_frame (void *args)
6466 struct frame_id *fid = (struct frame_id *) args;
6467 struct frame_info *frame;
6469 frame = frame_find_by_id (*fid);
6471 /* If inf_status->selected_frame_id is NULL, there was no previously
6475 warning (_("Unable to restore previously selected frame."));
6479 select_frame (frame);
6484 /* Restore inferior session state to INF_STATUS. */
6487 restore_infcall_control_state (struct infcall_control_state *inf_status)
6489 struct thread_info *tp = inferior_thread ();
6490 struct inferior *inf = current_inferior ();
6492 if (tp->control.step_resume_breakpoint)
6493 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
6495 if (tp->control.exception_resume_breakpoint)
6496 tp->control.exception_resume_breakpoint->disposition
6497 = disp_del_at_next_stop;
6499 /* Handle the bpstat_copy of the chain. */
6500 bpstat_clear (&tp->control.stop_bpstat);
6502 tp->control = inf_status->thread_control;
6503 inf->control = inf_status->inferior_control;
6506 stop_stack_dummy = inf_status->stop_stack_dummy;
6507 stopped_by_random_signal = inf_status->stopped_by_random_signal;
6508 stop_after_trap = inf_status->stop_after_trap;
6510 if (target_has_stack)
6512 /* The point of catch_errors is that if the stack is clobbered,
6513 walking the stack might encounter a garbage pointer and
6514 error() trying to dereference it. */
6516 (restore_selected_frame, &inf_status->selected_frame_id,
6517 "Unable to restore previously selected frame:\n",
6518 RETURN_MASK_ERROR) == 0)
6519 /* Error in restoring the selected frame. Select the innermost
6521 select_frame (get_current_frame ());
6528 do_restore_infcall_control_state_cleanup (void *sts)
6530 restore_infcall_control_state (sts);
6534 make_cleanup_restore_infcall_control_state
6535 (struct infcall_control_state *inf_status)
6537 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
6541 discard_infcall_control_state (struct infcall_control_state *inf_status)
6543 if (inf_status->thread_control.step_resume_breakpoint)
6544 inf_status->thread_control.step_resume_breakpoint->disposition
6545 = disp_del_at_next_stop;
6547 if (inf_status->thread_control.exception_resume_breakpoint)
6548 inf_status->thread_control.exception_resume_breakpoint->disposition
6549 = disp_del_at_next_stop;
6551 /* See save_infcall_control_state for info on stop_bpstat. */
6552 bpstat_clear (&inf_status->thread_control.stop_bpstat);
6558 inferior_has_forked (ptid_t pid, ptid_t *child_pid)
6560 struct target_waitstatus last;
6563 get_last_target_status (&last_ptid, &last);
6565 if (last.kind != TARGET_WAITKIND_FORKED)
6568 if (!ptid_equal (last_ptid, pid))
6571 *child_pid = last.value.related_pid;
6576 inferior_has_vforked (ptid_t pid, ptid_t *child_pid)
6578 struct target_waitstatus last;
6581 get_last_target_status (&last_ptid, &last);
6583 if (last.kind != TARGET_WAITKIND_VFORKED)
6586 if (!ptid_equal (last_ptid, pid))
6589 *child_pid = last.value.related_pid;
6594 inferior_has_execd (ptid_t pid, char **execd_pathname)
6596 struct target_waitstatus last;
6599 get_last_target_status (&last_ptid, &last);
6601 if (last.kind != TARGET_WAITKIND_EXECD)
6604 if (!ptid_equal (last_ptid, pid))
6607 *execd_pathname = xstrdup (last.value.execd_pathname);
6612 inferior_has_called_syscall (ptid_t pid, int *syscall_number)
6614 struct target_waitstatus last;
6617 get_last_target_status (&last_ptid, &last);
6619 if (last.kind != TARGET_WAITKIND_SYSCALL_ENTRY &&
6620 last.kind != TARGET_WAITKIND_SYSCALL_RETURN)
6623 if (!ptid_equal (last_ptid, pid))
6626 *syscall_number = last.value.syscall_number;
6630 /* Oft used ptids */
6632 ptid_t minus_one_ptid;
6634 /* Create a ptid given the necessary PID, LWP, and TID components. */
6637 ptid_build (int pid, long lwp, long tid)
6647 /* Create a ptid from just a pid. */
6650 pid_to_ptid (int pid)
6652 return ptid_build (pid, 0, 0);
6655 /* Fetch the pid (process id) component from a ptid. */
6658 ptid_get_pid (ptid_t ptid)
6663 /* Fetch the lwp (lightweight process) component from a ptid. */
6666 ptid_get_lwp (ptid_t ptid)
6671 /* Fetch the tid (thread id) component from a ptid. */
6674 ptid_get_tid (ptid_t ptid)
6679 /* ptid_equal() is used to test equality of two ptids. */
6682 ptid_equal (ptid_t ptid1, ptid_t ptid2)
6684 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
6685 && ptid1.tid == ptid2.tid);
6688 /* Returns true if PTID represents a process. */
6691 ptid_is_pid (ptid_t ptid)
6693 if (ptid_equal (minus_one_ptid, ptid))
6695 if (ptid_equal (null_ptid, ptid))
6698 return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0);
6702 ptid_match (ptid_t ptid, ptid_t filter)
6704 if (ptid_equal (filter, minus_one_ptid))
6706 if (ptid_is_pid (filter)
6707 && ptid_get_pid (ptid) == ptid_get_pid (filter))
6709 else if (ptid_equal (ptid, filter))
6715 /* restore_inferior_ptid() will be used by the cleanup machinery
6716 to restore the inferior_ptid value saved in a call to
6717 save_inferior_ptid(). */
6720 restore_inferior_ptid (void *arg)
6722 ptid_t *saved_ptid_ptr = arg;
6724 inferior_ptid = *saved_ptid_ptr;
6728 /* Save the value of inferior_ptid so that it may be restored by a
6729 later call to do_cleanups(). Returns the struct cleanup pointer
6730 needed for later doing the cleanup. */
6733 save_inferior_ptid (void)
6735 ptid_t *saved_ptid_ptr;
6737 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
6738 *saved_ptid_ptr = inferior_ptid;
6739 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
6743 /* User interface for reverse debugging:
6744 Set exec-direction / show exec-direction commands
6745 (returns error unless target implements to_set_exec_direction method). */
6747 enum exec_direction_kind execution_direction = EXEC_FORWARD;
6748 static const char exec_forward[] = "forward";
6749 static const char exec_reverse[] = "reverse";
6750 static const char *exec_direction = exec_forward;
6751 static const char *exec_direction_names[] = {
6758 set_exec_direction_func (char *args, int from_tty,
6759 struct cmd_list_element *cmd)
6761 if (target_can_execute_reverse)
6763 if (!strcmp (exec_direction, exec_forward))
6764 execution_direction = EXEC_FORWARD;
6765 else if (!strcmp (exec_direction, exec_reverse))
6766 execution_direction = EXEC_REVERSE;
6770 exec_direction = exec_forward;
6771 error (_("Target does not support this operation."));
6776 show_exec_direction_func (struct ui_file *out, int from_tty,
6777 struct cmd_list_element *cmd, const char *value)
6779 switch (execution_direction) {
6781 fprintf_filtered (out, _("Forward.\n"));
6784 fprintf_filtered (out, _("Reverse.\n"));
6788 fprintf_filtered (out, _("Forward (target `%s' does not "
6789 "support exec-direction).\n"),
6795 /* User interface for non-stop mode. */
6800 set_non_stop (char *args, int from_tty,
6801 struct cmd_list_element *c)
6803 if (target_has_execution)
6805 non_stop_1 = non_stop;
6806 error (_("Cannot change this setting while the inferior is running."));
6809 non_stop = non_stop_1;
6813 show_non_stop (struct ui_file *file, int from_tty,
6814 struct cmd_list_element *c, const char *value)
6816 fprintf_filtered (file,
6817 _("Controlling the inferior in non-stop mode is %s.\n"),
6822 show_schedule_multiple (struct ui_file *file, int from_tty,
6823 struct cmd_list_element *c, const char *value)
6825 fprintf_filtered (file, _("Resuming the execution of threads "
6826 "of all processes is %s.\n"), value);
6830 _initialize_infrun (void)
6835 add_info ("signals", signals_info, _("\
6836 What debugger does when program gets various signals.\n\
6837 Specify a signal as argument to print info on that signal only."));
6838 add_info_alias ("handle", "signals", 0);
6840 add_com ("handle", class_run, handle_command, _("\
6841 Specify how to handle a signal.\n\
6842 Args are signals and actions to apply to those signals.\n\
6843 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6844 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6845 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6846 The special arg \"all\" is recognized to mean all signals except those\n\
6847 used by the debugger, typically SIGTRAP and SIGINT.\n\
6848 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
6849 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
6850 Stop means reenter debugger if this signal happens (implies print).\n\
6851 Print means print a message if this signal happens.\n\
6852 Pass means let program see this signal; otherwise program doesn't know.\n\
6853 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6854 Pass and Stop may be combined."));
6857 add_com ("lz", class_info, signals_info, _("\
6858 What debugger does when program gets various signals.\n\
6859 Specify a signal as argument to print info on that signal only."));
6860 add_com ("z", class_run, xdb_handle_command, _("\
6861 Specify how to handle a signal.\n\
6862 Args are signals and actions to apply to those signals.\n\
6863 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6864 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6865 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6866 The special arg \"all\" is recognized to mean all signals except those\n\
6867 used by the debugger, typically SIGTRAP and SIGINT.\n\
6868 Recognized actions include \"s\" (toggles between stop and nostop),\n\
6869 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
6870 nopass), \"Q\" (noprint)\n\
6871 Stop means reenter debugger if this signal happens (implies print).\n\
6872 Print means print a message if this signal happens.\n\
6873 Pass means let program see this signal; otherwise program doesn't know.\n\
6874 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6875 Pass and Stop may be combined."));
6879 stop_command = add_cmd ("stop", class_obscure,
6880 not_just_help_class_command, _("\
6881 There is no `stop' command, but you can set a hook on `stop'.\n\
6882 This allows you to set a list of commands to be run each time execution\n\
6883 of the program stops."), &cmdlist);
6885 add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
6886 Set inferior debugging."), _("\
6887 Show inferior debugging."), _("\
6888 When non-zero, inferior specific debugging is enabled."),
6891 &setdebuglist, &showdebuglist);
6893 add_setshow_boolean_cmd ("displaced", class_maintenance,
6894 &debug_displaced, _("\
6895 Set displaced stepping debugging."), _("\
6896 Show displaced stepping debugging."), _("\
6897 When non-zero, displaced stepping specific debugging is enabled."),
6899 show_debug_displaced,
6900 &setdebuglist, &showdebuglist);
6902 add_setshow_boolean_cmd ("non-stop", no_class,
6904 Set whether gdb controls the inferior in non-stop mode."), _("\
6905 Show whether gdb controls the inferior in non-stop mode."), _("\
6906 When debugging a multi-threaded program and this setting is\n\
6907 off (the default, also called all-stop mode), when one thread stops\n\
6908 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
6909 all other threads in the program while you interact with the thread of\n\
6910 interest. When you continue or step a thread, you can allow the other\n\
6911 threads to run, or have them remain stopped, but while you inspect any\n\
6912 thread's state, all threads stop.\n\
6914 In non-stop mode, when one thread stops, other threads can continue\n\
6915 to run freely. You'll be able to step each thread independently,\n\
6916 leave it stopped or free to run as needed."),
6922 numsigs = (int) TARGET_SIGNAL_LAST;
6923 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
6924 signal_print = (unsigned char *)
6925 xmalloc (sizeof (signal_print[0]) * numsigs);
6926 signal_program = (unsigned char *)
6927 xmalloc (sizeof (signal_program[0]) * numsigs);
6928 for (i = 0; i < numsigs; i++)
6931 signal_print[i] = 1;
6932 signal_program[i] = 1;
6935 /* Signals caused by debugger's own actions
6936 should not be given to the program afterwards. */
6937 signal_program[TARGET_SIGNAL_TRAP] = 0;
6938 signal_program[TARGET_SIGNAL_INT] = 0;
6940 /* Signals that are not errors should not normally enter the debugger. */
6941 signal_stop[TARGET_SIGNAL_ALRM] = 0;
6942 signal_print[TARGET_SIGNAL_ALRM] = 0;
6943 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
6944 signal_print[TARGET_SIGNAL_VTALRM] = 0;
6945 signal_stop[TARGET_SIGNAL_PROF] = 0;
6946 signal_print[TARGET_SIGNAL_PROF] = 0;
6947 signal_stop[TARGET_SIGNAL_CHLD] = 0;
6948 signal_print[TARGET_SIGNAL_CHLD] = 0;
6949 signal_stop[TARGET_SIGNAL_IO] = 0;
6950 signal_print[TARGET_SIGNAL_IO] = 0;
6951 signal_stop[TARGET_SIGNAL_POLL] = 0;
6952 signal_print[TARGET_SIGNAL_POLL] = 0;
6953 signal_stop[TARGET_SIGNAL_URG] = 0;
6954 signal_print[TARGET_SIGNAL_URG] = 0;
6955 signal_stop[TARGET_SIGNAL_WINCH] = 0;
6956 signal_print[TARGET_SIGNAL_WINCH] = 0;
6957 signal_stop[TARGET_SIGNAL_PRIO] = 0;
6958 signal_print[TARGET_SIGNAL_PRIO] = 0;
6960 /* These signals are used internally by user-level thread
6961 implementations. (See signal(5) on Solaris.) Like the above
6962 signals, a healthy program receives and handles them as part of
6963 its normal operation. */
6964 signal_stop[TARGET_SIGNAL_LWP] = 0;
6965 signal_print[TARGET_SIGNAL_LWP] = 0;
6966 signal_stop[TARGET_SIGNAL_WAITING] = 0;
6967 signal_print[TARGET_SIGNAL_WAITING] = 0;
6968 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
6969 signal_print[TARGET_SIGNAL_CANCEL] = 0;
6971 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
6972 &stop_on_solib_events, _("\
6973 Set stopping for shared library events."), _("\
6974 Show stopping for shared library events."), _("\
6975 If nonzero, gdb will give control to the user when the dynamic linker\n\
6976 notifies gdb of shared library events. The most common event of interest\n\
6977 to the user would be loading/unloading of a new library."),
6979 show_stop_on_solib_events,
6980 &setlist, &showlist);
6982 add_setshow_enum_cmd ("follow-fork-mode", class_run,
6983 follow_fork_mode_kind_names,
6984 &follow_fork_mode_string, _("\
6985 Set debugger response to a program call of fork or vfork."), _("\
6986 Show debugger response to a program call of fork or vfork."), _("\
6987 A fork or vfork creates a new process. follow-fork-mode can be:\n\
6988 parent - the original process is debugged after a fork\n\
6989 child - the new process is debugged after a fork\n\
6990 The unfollowed process will continue to run.\n\
6991 By default, the debugger will follow the parent process."),
6993 show_follow_fork_mode_string,
6994 &setlist, &showlist);
6996 add_setshow_enum_cmd ("follow-exec-mode", class_run,
6997 follow_exec_mode_names,
6998 &follow_exec_mode_string, _("\
6999 Set debugger response to a program call of exec."), _("\
7000 Show debugger response to a program call of exec."), _("\
7001 An exec call replaces the program image of a process.\n\
7003 follow-exec-mode can be:\n\
7005 new - the debugger creates a new inferior and rebinds the process\n\
7006 to this new inferior. The program the process was running before\n\
7007 the exec call can be restarted afterwards by restarting the original\n\
7010 same - the debugger keeps the process bound to the same inferior.\n\
7011 The new executable image replaces the previous executable loaded in\n\
7012 the inferior. Restarting the inferior after the exec call restarts\n\
7013 the executable the process was running after the exec call.\n\
7015 By default, the debugger will use the same inferior."),
7017 show_follow_exec_mode_string,
7018 &setlist, &showlist);
7020 add_setshow_enum_cmd ("scheduler-locking", class_run,
7021 scheduler_enums, &scheduler_mode, _("\
7022 Set mode for locking scheduler during execution."), _("\
7023 Show mode for locking scheduler during execution."), _("\
7024 off == no locking (threads may preempt at any time)\n\
7025 on == full locking (no thread except the current thread may run)\n\
7026 step == scheduler locked during every single-step operation.\n\
7027 In this mode, no other thread may run during a step command.\n\
7028 Other threads may run while stepping over a function call ('next')."),
7029 set_schedlock_func, /* traps on target vector */
7030 show_scheduler_mode,
7031 &setlist, &showlist);
7033 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
7034 Set mode for resuming threads of all processes."), _("\
7035 Show mode for resuming threads of all processes."), _("\
7036 When on, execution commands (such as 'continue' or 'next') resume all\n\
7037 threads of all processes. When off (which is the default), execution\n\
7038 commands only resume the threads of the current process. The set of\n\
7039 threads that are resumed is further refined by the scheduler-locking\n\
7040 mode (see help set scheduler-locking)."),
7042 show_schedule_multiple,
7043 &setlist, &showlist);
7045 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
7046 Set mode of the step operation."), _("\
7047 Show mode of the step operation."), _("\
7048 When set, doing a step over a function without debug line information\n\
7049 will stop at the first instruction of that function. Otherwise, the\n\
7050 function is skipped and the step command stops at a different source line."),
7052 show_step_stop_if_no_debug,
7053 &setlist, &showlist);
7055 add_setshow_enum_cmd ("displaced-stepping", class_run,
7056 can_use_displaced_stepping_enum,
7057 &can_use_displaced_stepping, _("\
7058 Set debugger's willingness to use displaced stepping."), _("\
7059 Show debugger's willingness to use displaced stepping."), _("\
7060 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7061 supported by the target architecture. If off, gdb will not use displaced\n\
7062 stepping to step over breakpoints, even if such is supported by the target\n\
7063 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7064 if the target architecture supports it and non-stop mode is active, but will not\n\
7065 use it in all-stop mode (see help set non-stop)."),
7067 show_can_use_displaced_stepping,
7068 &setlist, &showlist);
7070 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
7071 &exec_direction, _("Set direction of execution.\n\
7072 Options are 'forward' or 'reverse'."),
7073 _("Show direction of execution (forward/reverse)."),
7074 _("Tells gdb whether to execute forward or backward."),
7075 set_exec_direction_func, show_exec_direction_func,
7076 &setlist, &showlist);
7078 /* Set/show detach-on-fork: user-settable mode. */
7080 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
7081 Set whether gdb will detach the child of a fork."), _("\
7082 Show whether gdb will detach the child of a fork."), _("\
7083 Tells gdb whether to detach the child of a fork."),
7084 NULL, NULL, &setlist, &showlist);
7086 /* ptid initializations */
7087 null_ptid = ptid_build (0, 0, 0);
7088 minus_one_ptid = ptid_build (-1, 0, 0);
7089 inferior_ptid = null_ptid;
7090 target_last_wait_ptid = minus_one_ptid;
7092 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
7093 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
7094 observer_attach_thread_exit (infrun_thread_thread_exit);
7095 observer_attach_inferior_exit (infrun_inferior_exit);
7097 /* Explicitly create without lookup, since that tries to create a
7098 value with a void typed value, and when we get here, gdbarch
7099 isn't initialized yet. At this point, we're quite sure there
7100 isn't another convenience variable of the same name. */
7101 create_internalvar_type_lazy ("_siginfo", siginfo_make_value);
7103 add_setshow_boolean_cmd ("observer", no_class,
7104 &observer_mode_1, _("\
7105 Set whether gdb controls the inferior in observer mode."), _("\
7106 Show whether gdb controls the inferior in observer mode."), _("\
7107 In observer mode, GDB can get data from the inferior, but not\n\
7108 affect its execution. Registers and memory may not be changed,\n\
7109 breakpoints may not be set, and the program cannot be interrupted\n\