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 Free Software Foundation, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
29 #include "exceptions.h"
30 #include "breakpoint.h"
34 #include "cli/cli-script.h"
36 #include "gdbthread.h"
48 #include "gdb_assert.h"
49 #include "mi/mi-common.h"
50 #include "event-top.h"
52 #include "inline-frame.h"
55 /* Prototypes for local functions */
57 static void signals_info (char *, int);
59 static void handle_command (char *, int);
61 static void sig_print_info (enum target_signal);
63 static void sig_print_header (void);
65 static void resume_cleanups (void *);
67 static int hook_stop_stub (void *);
69 static int restore_selected_frame (void *);
71 static void build_infrun (void);
73 static int follow_fork (void);
75 static void set_schedlock_func (char *args, int from_tty,
76 struct cmd_list_element *c);
78 static int currently_stepping (struct thread_info *tp);
80 static int currently_stepping_or_nexting_callback (struct thread_info *tp,
83 static void xdb_handle_command (char *args, int from_tty);
85 static int prepare_to_proceed (int);
87 void _initialize_infrun (void);
89 void nullify_last_target_wait_ptid (void);
91 /* When set, stop the 'step' command if we enter a function which has
92 no line number information. The normal behavior is that we step
93 over such function. */
94 int step_stop_if_no_debug = 0;
96 show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
97 struct cmd_list_element *c, const char *value)
99 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
102 /* In asynchronous mode, but simulating synchronous execution. */
104 int sync_execution = 0;
106 /* wait_for_inferior and normal_stop use this to notify the user
107 when the inferior stopped in a different thread than it had been
110 static ptid_t previous_inferior_ptid;
112 /* Default behavior is to detach newly forked processes (legacy). */
115 int debug_displaced = 0;
117 show_debug_displaced (struct ui_file *file, int from_tty,
118 struct cmd_list_element *c, const char *value)
120 fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value);
123 static int debug_infrun = 0;
125 show_debug_infrun (struct ui_file *file, int from_tty,
126 struct cmd_list_element *c, const char *value)
128 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
131 /* If the program uses ELF-style shared libraries, then calls to
132 functions in shared libraries go through stubs, which live in a
133 table called the PLT (Procedure Linkage Table). The first time the
134 function is called, the stub sends control to the dynamic linker,
135 which looks up the function's real address, patches the stub so
136 that future calls will go directly to the function, and then passes
137 control to the function.
139 If we are stepping at the source level, we don't want to see any of
140 this --- we just want to skip over the stub and the dynamic linker.
141 The simple approach is to single-step until control leaves the
144 However, on some systems (e.g., Red Hat's 5.2 distribution) the
145 dynamic linker calls functions in the shared C library, so you
146 can't tell from the PC alone whether the dynamic linker is still
147 running. In this case, we use a step-resume breakpoint to get us
148 past the dynamic linker, as if we were using "next" to step over a
151 in_solib_dynsym_resolve_code() says whether we're in the dynamic
152 linker code or not. Normally, this means we single-step. However,
153 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
154 address where we can place a step-resume breakpoint to get past the
155 linker's symbol resolution function.
157 in_solib_dynsym_resolve_code() can generally be implemented in a
158 pretty portable way, by comparing the PC against the address ranges
159 of the dynamic linker's sections.
161 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
162 it depends on internal details of the dynamic linker. It's usually
163 not too hard to figure out where to put a breakpoint, but it
164 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
165 sanity checking. If it can't figure things out, returning zero and
166 getting the (possibly confusing) stepping behavior is better than
167 signalling an error, which will obscure the change in the
170 /* This function returns TRUE if pc is the address of an instruction
171 that lies within the dynamic linker (such as the event hook, or the
174 This function must be used only when a dynamic linker event has
175 been caught, and the inferior is being stepped out of the hook, or
176 undefined results are guaranteed. */
178 #ifndef SOLIB_IN_DYNAMIC_LINKER
179 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
183 /* Convert the #defines into values. This is temporary until wfi control
184 flow is completely sorted out. */
186 #ifndef CANNOT_STEP_HW_WATCHPOINTS
187 #define CANNOT_STEP_HW_WATCHPOINTS 0
189 #undef CANNOT_STEP_HW_WATCHPOINTS
190 #define CANNOT_STEP_HW_WATCHPOINTS 1
193 /* Tables of how to react to signals; the user sets them. */
195 static unsigned char *signal_stop;
196 static unsigned char *signal_print;
197 static unsigned char *signal_program;
199 #define SET_SIGS(nsigs,sigs,flags) \
201 int signum = (nsigs); \
202 while (signum-- > 0) \
203 if ((sigs)[signum]) \
204 (flags)[signum] = 1; \
207 #define UNSET_SIGS(nsigs,sigs,flags) \
209 int signum = (nsigs); \
210 while (signum-- > 0) \
211 if ((sigs)[signum]) \
212 (flags)[signum] = 0; \
215 /* Value to pass to target_resume() to cause all threads to resume */
217 #define RESUME_ALL minus_one_ptid
219 /* Command list pointer for the "stop" placeholder. */
221 static struct cmd_list_element *stop_command;
223 /* Function inferior was in as of last step command. */
225 static struct symbol *step_start_function;
227 /* Nonzero if we want to give control to the user when we're notified
228 of shared library events by the dynamic linker. */
229 static int stop_on_solib_events;
231 show_stop_on_solib_events (struct ui_file *file, int from_tty,
232 struct cmd_list_element *c, const char *value)
234 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
238 /* Nonzero means expecting a trace trap
239 and should stop the inferior and return silently when it happens. */
243 /* Save register contents here when executing a "finish" command or are
244 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
245 Thus this contains the return value from the called function (assuming
246 values are returned in a register). */
248 struct regcache *stop_registers;
250 /* Nonzero after stop if current stack frame should be printed. */
252 static int stop_print_frame;
254 /* This is a cached copy of the pid/waitstatus of the last event
255 returned by target_wait()/deprecated_target_wait_hook(). This
256 information is returned by get_last_target_status(). */
257 static ptid_t target_last_wait_ptid;
258 static struct target_waitstatus target_last_waitstatus;
260 static void context_switch (ptid_t ptid);
262 void init_thread_stepping_state (struct thread_info *tss);
264 void init_infwait_state (void);
266 static const char follow_fork_mode_child[] = "child";
267 static const char follow_fork_mode_parent[] = "parent";
269 static const char *follow_fork_mode_kind_names[] = {
270 follow_fork_mode_child,
271 follow_fork_mode_parent,
275 static const char *follow_fork_mode_string = follow_fork_mode_parent;
277 show_follow_fork_mode_string (struct ui_file *file, int from_tty,
278 struct cmd_list_element *c, const char *value)
280 fprintf_filtered (file, _("\
281 Debugger response to a program call of fork or vfork is \"%s\".\n"),
286 /* Tell the target to follow the fork we're stopped at. Returns true
287 if the inferior should be resumed; false, if the target for some
288 reason decided it's best not to resume. */
293 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
294 int should_resume = 1;
295 struct thread_info *tp;
297 /* Copy user stepping state to the new inferior thread. FIXME: the
298 followed fork child thread should have a copy of most of the
299 parent thread structure's run control related fields, not just these.
300 Initialized to avoid "may be used uninitialized" warnings from gcc. */
301 struct breakpoint *step_resume_breakpoint = NULL;
302 CORE_ADDR step_range_start = 0;
303 CORE_ADDR step_range_end = 0;
304 struct frame_id step_frame_id = { 0 };
309 struct target_waitstatus wait_status;
311 /* Get the last target status returned by target_wait(). */
312 get_last_target_status (&wait_ptid, &wait_status);
314 /* If not stopped at a fork event, then there's nothing else to
316 if (wait_status.kind != TARGET_WAITKIND_FORKED
317 && wait_status.kind != TARGET_WAITKIND_VFORKED)
320 /* Check if we switched over from WAIT_PTID, since the event was
322 if (!ptid_equal (wait_ptid, minus_one_ptid)
323 && !ptid_equal (inferior_ptid, wait_ptid))
325 /* We did. Switch back to WAIT_PTID thread, to tell the
326 target to follow it (in either direction). We'll
327 afterwards refuse to resume, and inform the user what
329 switch_to_thread (wait_ptid);
334 tp = inferior_thread ();
336 /* If there were any forks/vforks that were caught and are now to be
337 followed, then do so now. */
338 switch (tp->pending_follow.kind)
340 case TARGET_WAITKIND_FORKED:
341 case TARGET_WAITKIND_VFORKED:
343 ptid_t parent, child;
345 /* If the user did a next/step, etc, over a fork call,
346 preserve the stepping state in the fork child. */
347 if (follow_child && should_resume)
349 step_resume_breakpoint
350 = clone_momentary_breakpoint (tp->step_resume_breakpoint);
351 step_range_start = tp->step_range_start;
352 step_range_end = tp->step_range_end;
353 step_frame_id = tp->step_frame_id;
355 /* For now, delete the parent's sr breakpoint, otherwise,
356 parent/child sr breakpoints are considered duplicates,
357 and the child version will not be installed. Remove
358 this when the breakpoints module becomes aware of
359 inferiors and address spaces. */
360 delete_step_resume_breakpoint (tp);
361 tp->step_range_start = 0;
362 tp->step_range_end = 0;
363 tp->step_frame_id = null_frame_id;
366 parent = inferior_ptid;
367 child = tp->pending_follow.value.related_pid;
369 /* Tell the target to do whatever is necessary to follow
370 either parent or child. */
371 if (target_follow_fork (follow_child))
373 /* Target refused to follow, or there's some other reason
374 we shouldn't resume. */
379 /* This pending follow fork event is now handled, one way
380 or another. The previous selected thread may be gone
381 from the lists by now, but if it is still around, need
382 to clear the pending follow request. */
383 tp = find_thread_ptid (parent);
385 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
387 /* This makes sure we don't try to apply the "Switched
388 over from WAIT_PID" logic above. */
389 nullify_last_target_wait_ptid ();
391 /* If we followed the child, switch to it... */
394 switch_to_thread (child);
396 /* ... and preserve the stepping state, in case the
397 user was stepping over the fork call. */
400 tp = inferior_thread ();
401 tp->step_resume_breakpoint = step_resume_breakpoint;
402 tp->step_range_start = step_range_start;
403 tp->step_range_end = step_range_end;
404 tp->step_frame_id = step_frame_id;
408 /* If we get here, it was because we're trying to
409 resume from a fork catchpoint, but, the user
410 has switched threads away from the thread that
411 forked. In that case, the resume command
412 issued is most likely not applicable to the
413 child, so just warn, and refuse to resume. */
415 Not resuming: switched threads before following fork child.\n"));
418 /* Reset breakpoints in the child as appropriate. */
419 follow_inferior_reset_breakpoints ();
422 switch_to_thread (parent);
426 case TARGET_WAITKIND_SPURIOUS:
427 /* Nothing to follow. */
430 internal_error (__FILE__, __LINE__,
431 "Unexpected pending_follow.kind %d\n",
432 tp->pending_follow.kind);
436 return should_resume;
440 follow_inferior_reset_breakpoints (void)
442 struct thread_info *tp = inferior_thread ();
444 /* Was there a step_resume breakpoint? (There was if the user
445 did a "next" at the fork() call.) If so, explicitly reset its
448 step_resumes are a form of bp that are made to be per-thread.
449 Since we created the step_resume bp when the parent process
450 was being debugged, and now are switching to the child process,
451 from the breakpoint package's viewpoint, that's a switch of
452 "threads". We must update the bp's notion of which thread
453 it is for, or it'll be ignored when it triggers. */
455 if (tp->step_resume_breakpoint)
456 breakpoint_re_set_thread (tp->step_resume_breakpoint);
458 /* Reinsert all breakpoints in the child. The user may have set
459 breakpoints after catching the fork, in which case those
460 were never set in the child, but only in the parent. This makes
461 sure the inserted breakpoints match the breakpoint list. */
463 breakpoint_re_set ();
464 insert_breakpoints ();
467 /* The child has exited or execed: resume threads of the parent the
468 user wanted to be executing. */
471 proceed_after_vfork_done (struct thread_info *thread,
474 int pid = * (int *) arg;
476 if (ptid_get_pid (thread->ptid) == pid
477 && is_running (thread->ptid)
478 && !is_executing (thread->ptid)
479 && !thread->stop_requested
480 && thread->stop_signal == TARGET_SIGNAL_0)
483 fprintf_unfiltered (gdb_stdlog,
484 "infrun: resuming vfork parent thread %s\n",
485 target_pid_to_str (thread->ptid));
487 switch_to_thread (thread->ptid);
488 clear_proceed_status ();
489 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
495 /* Called whenever we notice an exec or exit event, to handle
496 detaching or resuming a vfork parent. */
499 handle_vfork_child_exec_or_exit (int exec)
501 struct inferior *inf = current_inferior ();
503 if (inf->vfork_parent)
505 int resume_parent = -1;
507 /* This exec or exit marks the end of the shared memory region
508 between the parent and the child. If the user wanted to
509 detach from the parent, now is the time. */
511 if (inf->vfork_parent->pending_detach)
513 struct thread_info *tp;
514 struct cleanup *old_chain;
515 struct program_space *pspace;
516 struct address_space *aspace;
518 /* follow-fork child, detach-on-fork on */
520 old_chain = make_cleanup_restore_current_thread ();
522 /* We're letting loose of the parent. */
523 tp = any_live_thread_of_process (inf->vfork_parent->pid);
524 switch_to_thread (tp->ptid);
526 /* We're about to detach from the parent, which implicitly
527 removes breakpoints from its address space. There's a
528 catch here: we want to reuse the spaces for the child,
529 but, parent/child are still sharing the pspace at this
530 point, although the exec in reality makes the kernel give
531 the child a fresh set of new pages. The problem here is
532 that the breakpoints module being unaware of this, would
533 likely chose the child process to write to the parent
534 address space. Swapping the child temporarily away from
535 the spaces has the desired effect. Yes, this is "sort
538 pspace = inf->pspace;
539 aspace = inf->aspace;
543 if (debug_infrun || info_verbose)
545 target_terminal_ours ();
548 fprintf_filtered (gdb_stdlog,
549 "Detaching vfork parent process %d after child exec.\n",
550 inf->vfork_parent->pid);
552 fprintf_filtered (gdb_stdlog,
553 "Detaching vfork parent process %d after child exit.\n",
554 inf->vfork_parent->pid);
557 target_detach (NULL, 0);
560 inf->pspace = pspace;
561 inf->aspace = aspace;
563 do_cleanups (old_chain);
567 /* We're staying attached to the parent, so, really give the
568 child a new address space. */
569 inf->pspace = add_program_space (maybe_new_address_space ());
570 inf->aspace = inf->pspace->aspace;
572 set_current_program_space (inf->pspace);
574 resume_parent = inf->vfork_parent->pid;
576 /* Break the bonds. */
577 inf->vfork_parent->vfork_child = NULL;
581 struct cleanup *old_chain;
582 struct program_space *pspace;
584 /* If this is a vfork child exiting, then the pspace and
585 aspaces were shared with the parent. Since we're
586 reporting the process exit, we'll be mourning all that is
587 found in the address space, and switching to null_ptid,
588 preparing to start a new inferior. But, since we don't
589 want to clobber the parent's address/program spaces, we
590 go ahead and create a new one for this exiting
593 /* Switch to null_ptid, so that clone_program_space doesn't want
594 to read the selected frame of a dead process. */
595 old_chain = save_inferior_ptid ();
596 inferior_ptid = null_ptid;
598 /* This inferior is dead, so avoid giving the breakpoints
599 module the option to write through to it (cloning a
600 program space resets breakpoints). */
603 pspace = add_program_space (maybe_new_address_space ());
604 set_current_program_space (pspace);
606 clone_program_space (pspace, inf->vfork_parent->pspace);
607 inf->pspace = pspace;
608 inf->aspace = pspace->aspace;
610 /* Put back inferior_ptid. We'll continue mourning this
612 do_cleanups (old_chain);
614 resume_parent = inf->vfork_parent->pid;
615 /* Break the bonds. */
616 inf->vfork_parent->vfork_child = NULL;
619 inf->vfork_parent = NULL;
621 gdb_assert (current_program_space == inf->pspace);
623 if (non_stop && resume_parent != -1)
625 /* If the user wanted the parent to be running, let it go
627 struct cleanup *old_chain = make_cleanup_restore_current_thread ();
630 fprintf_unfiltered (gdb_stdlog, "infrun: resuming vfork parent process %d\n",
633 iterate_over_threads (proceed_after_vfork_done, &resume_parent);
635 do_cleanups (old_chain);
640 /* Enum strings for "set|show displaced-stepping". */
642 static const char follow_exec_mode_new[] = "new";
643 static const char follow_exec_mode_same[] = "same";
644 static const char *follow_exec_mode_names[] =
646 follow_exec_mode_new,
647 follow_exec_mode_same,
651 static const char *follow_exec_mode_string = follow_exec_mode_same;
653 show_follow_exec_mode_string (struct ui_file *file, int from_tty,
654 struct cmd_list_element *c, const char *value)
656 fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value);
659 /* EXECD_PATHNAME is assumed to be non-NULL. */
662 follow_exec (ptid_t pid, char *execd_pathname)
664 struct target_ops *tgt;
665 struct thread_info *th = inferior_thread ();
666 struct inferior *inf = current_inferior ();
668 /* This is an exec event that we actually wish to pay attention to.
669 Refresh our symbol table to the newly exec'd program, remove any
672 If there are breakpoints, they aren't really inserted now,
673 since the exec() transformed our inferior into a fresh set
676 We want to preserve symbolic breakpoints on the list, since
677 we have hopes that they can be reset after the new a.out's
678 symbol table is read.
680 However, any "raw" breakpoints must be removed from the list
681 (e.g., the solib bp's), since their address is probably invalid
684 And, we DON'T want to call delete_breakpoints() here, since
685 that may write the bp's "shadow contents" (the instruction
686 value that was overwritten witha TRAP instruction). Since
687 we now have a new a.out, those shadow contents aren't valid. */
689 mark_breakpoints_out ();
691 update_breakpoints_after_exec ();
693 /* If there was one, it's gone now. We cannot truly step-to-next
694 statement through an exec(). */
695 th->step_resume_breakpoint = NULL;
696 th->step_range_start = 0;
697 th->step_range_end = 0;
699 /* The target reports the exec event to the main thread, even if
700 some other thread does the exec, and even if the main thread was
701 already stopped --- if debugging in non-stop mode, it's possible
702 the user had the main thread held stopped in the previous image
703 --- release it now. This is the same behavior as step-over-exec
704 with scheduler-locking on in all-stop mode. */
705 th->stop_requested = 0;
707 /* What is this a.out's name? */
708 printf_unfiltered (_("%s is executing new program: %s\n"),
709 target_pid_to_str (inferior_ptid),
712 /* We've followed the inferior through an exec. Therefore, the
713 inferior has essentially been killed & reborn. */
715 gdb_flush (gdb_stdout);
717 breakpoint_init_inferior (inf_execd);
719 if (gdb_sysroot && *gdb_sysroot)
721 char *name = alloca (strlen (gdb_sysroot)
722 + strlen (execd_pathname)
724 strcpy (name, gdb_sysroot);
725 strcat (name, execd_pathname);
726 execd_pathname = name;
729 /* Reset the shared library package. This ensures that we get a
730 shlib event when the child reaches "_start", at which point the
731 dld will have had a chance to initialize the child. */
732 /* Also, loading a symbol file below may trigger symbol lookups, and
733 we don't want those to be satisfied by the libraries of the
734 previous incarnation of this process. */
735 no_shared_libraries (NULL, 0);
737 if (follow_exec_mode_string == follow_exec_mode_new)
739 struct program_space *pspace;
740 struct inferior *new_inf;
742 /* The user wants to keep the old inferior and program spaces
743 around. Create a new fresh one, and switch to it. */
745 inf = add_inferior (current_inferior ()->pid);
746 pspace = add_program_space (maybe_new_address_space ());
747 inf->pspace = pspace;
748 inf->aspace = pspace->aspace;
750 exit_inferior_num_silent (current_inferior ()->num);
752 set_current_inferior (inf);
753 set_current_program_space (pspace);
756 gdb_assert (current_program_space == inf->pspace);
758 /* That a.out is now the one to use. */
759 exec_file_attach (execd_pathname, 0);
761 /* Load the main file's symbols. */
762 symbol_file_add_main (execd_pathname, 0);
764 #ifdef SOLIB_CREATE_INFERIOR_HOOK
765 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
767 solib_create_inferior_hook ();
770 jit_inferior_created_hook ();
772 /* Reinsert all breakpoints. (Those which were symbolic have
773 been reset to the proper address in the new a.out, thanks
774 to symbol_file_command...) */
775 insert_breakpoints ();
777 /* The next resume of this inferior should bring it to the shlib
778 startup breakpoints. (If the user had also set bp's on
779 "main" from the old (parent) process, then they'll auto-
780 matically get reset there in the new process.) */
783 /* Non-zero if we just simulating a single-step. This is needed
784 because we cannot remove the breakpoints in the inferior process
785 until after the `wait' in `wait_for_inferior'. */
786 static int singlestep_breakpoints_inserted_p = 0;
788 /* The thread we inserted single-step breakpoints for. */
789 static ptid_t singlestep_ptid;
791 /* PC when we started this single-step. */
792 static CORE_ADDR singlestep_pc;
794 /* If another thread hit the singlestep breakpoint, we save the original
795 thread here so that we can resume single-stepping it later. */
796 static ptid_t saved_singlestep_ptid;
797 static int stepping_past_singlestep_breakpoint;
799 /* If not equal to null_ptid, this means that after stepping over breakpoint
800 is finished, we need to switch to deferred_step_ptid, and step it.
802 The use case is when one thread has hit a breakpoint, and then the user
803 has switched to another thread and issued 'step'. We need to step over
804 breakpoint in the thread which hit the breakpoint, but then continue
805 stepping the thread user has selected. */
806 static ptid_t deferred_step_ptid;
808 /* Displaced stepping. */
810 /* In non-stop debugging mode, we must take special care to manage
811 breakpoints properly; in particular, the traditional strategy for
812 stepping a thread past a breakpoint it has hit is unsuitable.
813 'Displaced stepping' is a tactic for stepping one thread past a
814 breakpoint it has hit while ensuring that other threads running
815 concurrently will hit the breakpoint as they should.
817 The traditional way to step a thread T off a breakpoint in a
818 multi-threaded program in all-stop mode is as follows:
820 a0) Initially, all threads are stopped, and breakpoints are not
822 a1) We single-step T, leaving breakpoints uninserted.
823 a2) We insert breakpoints, and resume all threads.
825 In non-stop debugging, however, this strategy is unsuitable: we
826 don't want to have to stop all threads in the system in order to
827 continue or step T past a breakpoint. Instead, we use displaced
830 n0) Initially, T is stopped, other threads are running, and
831 breakpoints are inserted.
832 n1) We copy the instruction "under" the breakpoint to a separate
833 location, outside the main code stream, making any adjustments
834 to the instruction, register, and memory state as directed by
836 n2) We single-step T over the instruction at its new location.
837 n3) We adjust the resulting register and memory state as directed
838 by T's architecture. This includes resetting T's PC to point
839 back into the main instruction stream.
842 This approach depends on the following gdbarch methods:
844 - gdbarch_max_insn_length and gdbarch_displaced_step_location
845 indicate where to copy the instruction, and how much space must
846 be reserved there. We use these in step n1.
848 - gdbarch_displaced_step_copy_insn copies a instruction to a new
849 address, and makes any necessary adjustments to the instruction,
850 register contents, and memory. We use this in step n1.
852 - gdbarch_displaced_step_fixup adjusts registers and memory after
853 we have successfuly single-stepped the instruction, to yield the
854 same effect the instruction would have had if we had executed it
855 at its original address. We use this in step n3.
857 - gdbarch_displaced_step_free_closure provides cleanup.
859 The gdbarch_displaced_step_copy_insn and
860 gdbarch_displaced_step_fixup functions must be written so that
861 copying an instruction with gdbarch_displaced_step_copy_insn,
862 single-stepping across the copied instruction, and then applying
863 gdbarch_displaced_insn_fixup should have the same effects on the
864 thread's memory and registers as stepping the instruction in place
865 would have. Exactly which responsibilities fall to the copy and
866 which fall to the fixup is up to the author of those functions.
868 See the comments in gdbarch.sh for details.
870 Note that displaced stepping and software single-step cannot
871 currently be used in combination, although with some care I think
872 they could be made to. Software single-step works by placing
873 breakpoints on all possible subsequent instructions; if the
874 displaced instruction is a PC-relative jump, those breakpoints
875 could fall in very strange places --- on pages that aren't
876 executable, or at addresses that are not proper instruction
877 boundaries. (We do generally let other threads run while we wait
878 to hit the software single-step breakpoint, and they might
879 encounter such a corrupted instruction.) One way to work around
880 this would be to have gdbarch_displaced_step_copy_insn fully
881 simulate the effect of PC-relative instructions (and return NULL)
882 on architectures that use software single-stepping.
884 In non-stop mode, we can have independent and simultaneous step
885 requests, so more than one thread may need to simultaneously step
886 over a breakpoint. The current implementation assumes there is
887 only one scratch space per process. In this case, we have to
888 serialize access to the scratch space. If thread A wants to step
889 over a breakpoint, but we are currently waiting for some other
890 thread to complete a displaced step, we leave thread A stopped and
891 place it in the displaced_step_request_queue. Whenever a displaced
892 step finishes, we pick the next thread in the queue and start a new
893 displaced step operation on it. See displaced_step_prepare and
894 displaced_step_fixup for details. */
896 /* If this is not null_ptid, this is the thread carrying out a
897 displaced single-step. This thread's state will require fixing up
898 once it has completed its step. */
899 static ptid_t displaced_step_ptid;
901 struct displaced_step_request
904 struct displaced_step_request *next;
907 /* A queue of pending displaced stepping requests. */
908 struct displaced_step_request *displaced_step_request_queue;
910 /* The architecture the thread had when we stepped it. */
911 static struct gdbarch *displaced_step_gdbarch;
913 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
914 for post-step cleanup. */
915 static struct displaced_step_closure *displaced_step_closure;
917 /* The address of the original instruction, and the copy we made. */
918 static CORE_ADDR displaced_step_original, displaced_step_copy;
920 /* Saved contents of copy area. */
921 static gdb_byte *displaced_step_saved_copy;
923 /* Enum strings for "set|show displaced-stepping". */
925 static const char can_use_displaced_stepping_auto[] = "auto";
926 static const char can_use_displaced_stepping_on[] = "on";
927 static const char can_use_displaced_stepping_off[] = "off";
928 static const char *can_use_displaced_stepping_enum[] =
930 can_use_displaced_stepping_auto,
931 can_use_displaced_stepping_on,
932 can_use_displaced_stepping_off,
936 /* If ON, and the architecture supports it, GDB will use displaced
937 stepping to step over breakpoints. If OFF, or if the architecture
938 doesn't support it, GDB will instead use the traditional
939 hold-and-step approach. If AUTO (which is the default), GDB will
940 decide which technique to use to step over breakpoints depending on
941 which of all-stop or non-stop mode is active --- displaced stepping
942 in non-stop mode; hold-and-step in all-stop mode. */
944 static const char *can_use_displaced_stepping =
945 can_use_displaced_stepping_auto;
948 show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
949 struct cmd_list_element *c,
952 if (can_use_displaced_stepping == can_use_displaced_stepping_auto)
953 fprintf_filtered (file, _("\
954 Debugger's willingness to use displaced stepping to step over \
955 breakpoints is %s (currently %s).\n"),
956 value, non_stop ? "on" : "off");
958 fprintf_filtered (file, _("\
959 Debugger's willingness to use displaced stepping to step over \
960 breakpoints is %s.\n"), value);
963 /* Return non-zero if displaced stepping can/should be used to step
967 use_displaced_stepping (struct gdbarch *gdbarch)
969 return (((can_use_displaced_stepping == can_use_displaced_stepping_auto
971 || can_use_displaced_stepping == can_use_displaced_stepping_on)
972 && gdbarch_displaced_step_copy_insn_p (gdbarch)
976 /* Clean out any stray displaced stepping state. */
978 displaced_step_clear (void)
980 /* Indicate that there is no cleanup pending. */
981 displaced_step_ptid = null_ptid;
983 if (displaced_step_closure)
985 gdbarch_displaced_step_free_closure (displaced_step_gdbarch,
986 displaced_step_closure);
987 displaced_step_closure = NULL;
992 displaced_step_clear_cleanup (void *ignore)
994 displaced_step_clear ();
997 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
999 displaced_step_dump_bytes (struct ui_file *file,
1000 const gdb_byte *buf,
1005 for (i = 0; i < len; i++)
1006 fprintf_unfiltered (file, "%02x ", buf[i]);
1007 fputs_unfiltered ("\n", file);
1010 /* Prepare to single-step, using displaced stepping.
1012 Note that we cannot use displaced stepping when we have a signal to
1013 deliver. If we have a signal to deliver and an instruction to step
1014 over, then after the step, there will be no indication from the
1015 target whether the thread entered a signal handler or ignored the
1016 signal and stepped over the instruction successfully --- both cases
1017 result in a simple SIGTRAP. In the first case we mustn't do a
1018 fixup, and in the second case we must --- but we can't tell which.
1019 Comments in the code for 'random signals' in handle_inferior_event
1020 explain how we handle this case instead.
1022 Returns 1 if preparing was successful -- this thread is going to be
1023 stepped now; or 0 if displaced stepping this thread got queued. */
1025 displaced_step_prepare (ptid_t ptid)
1027 struct cleanup *old_cleanups, *ignore_cleanups;
1028 struct regcache *regcache = get_thread_regcache (ptid);
1029 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1030 CORE_ADDR original, copy;
1032 struct displaced_step_closure *closure;
1034 /* We should never reach this function if the architecture does not
1035 support displaced stepping. */
1036 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
1038 /* For the first cut, we're displaced stepping one thread at a
1041 if (!ptid_equal (displaced_step_ptid, null_ptid))
1043 /* Already waiting for a displaced step to finish. Defer this
1044 request and place in queue. */
1045 struct displaced_step_request *req, *new_req;
1047 if (debug_displaced)
1048 fprintf_unfiltered (gdb_stdlog,
1049 "displaced: defering step of %s\n",
1050 target_pid_to_str (ptid));
1052 new_req = xmalloc (sizeof (*new_req));
1053 new_req->ptid = ptid;
1054 new_req->next = NULL;
1056 if (displaced_step_request_queue)
1058 for (req = displaced_step_request_queue;
1062 req->next = new_req;
1065 displaced_step_request_queue = new_req;
1071 if (debug_displaced)
1072 fprintf_unfiltered (gdb_stdlog,
1073 "displaced: stepping %s now\n",
1074 target_pid_to_str (ptid));
1077 displaced_step_clear ();
1079 old_cleanups = save_inferior_ptid ();
1080 inferior_ptid = ptid;
1082 original = regcache_read_pc (regcache);
1084 copy = gdbarch_displaced_step_location (gdbarch);
1085 len = gdbarch_max_insn_length (gdbarch);
1087 /* Save the original contents of the copy area. */
1088 displaced_step_saved_copy = xmalloc (len);
1089 ignore_cleanups = make_cleanup (free_current_contents,
1090 &displaced_step_saved_copy);
1091 read_memory (copy, displaced_step_saved_copy, len);
1092 if (debug_displaced)
1094 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
1095 paddress (gdbarch, copy));
1096 displaced_step_dump_bytes (gdb_stdlog, displaced_step_saved_copy, len);
1099 closure = gdbarch_displaced_step_copy_insn (gdbarch,
1100 original, copy, regcache);
1102 /* We don't support the fully-simulated case at present. */
1103 gdb_assert (closure);
1105 /* Save the information we need to fix things up if the step
1107 displaced_step_ptid = ptid;
1108 displaced_step_gdbarch = gdbarch;
1109 displaced_step_closure = closure;
1110 displaced_step_original = original;
1111 displaced_step_copy = copy;
1113 make_cleanup (displaced_step_clear_cleanup, 0);
1115 /* Resume execution at the copy. */
1116 regcache_write_pc (regcache, copy);
1118 discard_cleanups (ignore_cleanups);
1120 do_cleanups (old_cleanups);
1122 if (debug_displaced)
1123 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
1124 paddress (gdbarch, copy));
1130 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
1132 struct cleanup *ptid_cleanup = save_inferior_ptid ();
1133 inferior_ptid = ptid;
1134 write_memory (memaddr, myaddr, len);
1135 do_cleanups (ptid_cleanup);
1139 displaced_step_fixup (ptid_t event_ptid, enum target_signal signal)
1141 struct cleanup *old_cleanups;
1143 /* Was this event for the pid we displaced? */
1144 if (ptid_equal (displaced_step_ptid, null_ptid)
1145 || ! ptid_equal (displaced_step_ptid, event_ptid))
1148 old_cleanups = make_cleanup (displaced_step_clear_cleanup, 0);
1150 /* Restore the contents of the copy area. */
1152 ULONGEST len = gdbarch_max_insn_length (displaced_step_gdbarch);
1153 write_memory_ptid (displaced_step_ptid, displaced_step_copy,
1154 displaced_step_saved_copy, len);
1155 if (debug_displaced)
1156 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s\n",
1157 paddress (displaced_step_gdbarch,
1158 displaced_step_copy));
1161 /* Did the instruction complete successfully? */
1162 if (signal == TARGET_SIGNAL_TRAP)
1164 /* Fix up the resulting state. */
1165 gdbarch_displaced_step_fixup (displaced_step_gdbarch,
1166 displaced_step_closure,
1167 displaced_step_original,
1168 displaced_step_copy,
1169 get_thread_regcache (displaced_step_ptid));
1173 /* Since the instruction didn't complete, all we can do is
1175 struct regcache *regcache = get_thread_regcache (event_ptid);
1176 CORE_ADDR pc = regcache_read_pc (regcache);
1177 pc = displaced_step_original + (pc - displaced_step_copy);
1178 regcache_write_pc (regcache, pc);
1181 do_cleanups (old_cleanups);
1183 displaced_step_ptid = null_ptid;
1185 /* Are there any pending displaced stepping requests? If so, run
1187 while (displaced_step_request_queue)
1189 struct displaced_step_request *head;
1191 struct regcache *regcache;
1192 struct gdbarch *gdbarch;
1193 CORE_ADDR actual_pc;
1194 struct address_space *aspace;
1196 head = displaced_step_request_queue;
1198 displaced_step_request_queue = head->next;
1201 context_switch (ptid);
1203 regcache = get_thread_regcache (ptid);
1204 actual_pc = regcache_read_pc (regcache);
1205 aspace = get_regcache_aspace (regcache);
1207 if (breakpoint_here_p (aspace, actual_pc))
1209 if (debug_displaced)
1210 fprintf_unfiltered (gdb_stdlog,
1211 "displaced: stepping queued %s now\n",
1212 target_pid_to_str (ptid));
1214 displaced_step_prepare (ptid);
1216 gdbarch = get_regcache_arch (regcache);
1218 if (debug_displaced)
1220 CORE_ADDR actual_pc = regcache_read_pc (regcache);
1223 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1224 paddress (gdbarch, actual_pc));
1225 read_memory (actual_pc, buf, sizeof (buf));
1226 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1229 if (gdbarch_displaced_step_hw_singlestep
1230 (gdbarch, displaced_step_closure))
1231 target_resume (ptid, 1, TARGET_SIGNAL_0);
1233 target_resume (ptid, 0, TARGET_SIGNAL_0);
1235 /* Done, we're stepping a thread. */
1241 struct thread_info *tp = inferior_thread ();
1243 /* The breakpoint we were sitting under has since been
1245 tp->trap_expected = 0;
1247 /* Go back to what we were trying to do. */
1248 step = currently_stepping (tp);
1250 if (debug_displaced)
1251 fprintf_unfiltered (gdb_stdlog, "breakpoint is gone %s: step(%d)\n",
1252 target_pid_to_str (tp->ptid), step);
1254 target_resume (ptid, step, TARGET_SIGNAL_0);
1255 tp->stop_signal = TARGET_SIGNAL_0;
1257 /* This request was discarded. See if there's any other
1258 thread waiting for its turn. */
1263 /* Update global variables holding ptids to hold NEW_PTID if they were
1264 holding OLD_PTID. */
1266 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
1268 struct displaced_step_request *it;
1270 if (ptid_equal (inferior_ptid, old_ptid))
1271 inferior_ptid = new_ptid;
1273 if (ptid_equal (singlestep_ptid, old_ptid))
1274 singlestep_ptid = new_ptid;
1276 if (ptid_equal (displaced_step_ptid, old_ptid))
1277 displaced_step_ptid = new_ptid;
1279 if (ptid_equal (deferred_step_ptid, old_ptid))
1280 deferred_step_ptid = new_ptid;
1282 for (it = displaced_step_request_queue; it; it = it->next)
1283 if (ptid_equal (it->ptid, old_ptid))
1284 it->ptid = new_ptid;
1290 /* Things to clean up if we QUIT out of resume (). */
1292 resume_cleanups (void *ignore)
1297 static const char schedlock_off[] = "off";
1298 static const char schedlock_on[] = "on";
1299 static const char schedlock_step[] = "step";
1300 static const char *scheduler_enums[] = {
1306 static const char *scheduler_mode = schedlock_off;
1308 show_scheduler_mode (struct ui_file *file, int from_tty,
1309 struct cmd_list_element *c, const char *value)
1311 fprintf_filtered (file, _("\
1312 Mode for locking scheduler during execution is \"%s\".\n"),
1317 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
1319 if (!target_can_lock_scheduler)
1321 scheduler_mode = schedlock_off;
1322 error (_("Target '%s' cannot support this command."), target_shortname);
1326 /* True if execution commands resume all threads of all processes by
1327 default; otherwise, resume only threads of the current inferior
1329 int sched_multi = 0;
1331 /* Try to setup for software single stepping over the specified location.
1332 Return 1 if target_resume() should use hardware single step.
1334 GDBARCH the current gdbarch.
1335 PC the location to step over. */
1338 maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
1342 if (gdbarch_software_single_step_p (gdbarch)
1343 && gdbarch_software_single_step (gdbarch, get_current_frame ()))
1346 /* Do not pull these breakpoints until after a `wait' in
1347 `wait_for_inferior' */
1348 singlestep_breakpoints_inserted_p = 1;
1349 singlestep_ptid = inferior_ptid;
1355 /* Resume the inferior, but allow a QUIT. This is useful if the user
1356 wants to interrupt some lengthy single-stepping operation
1357 (for child processes, the SIGINT goes to the inferior, and so
1358 we get a SIGINT random_signal, but for remote debugging and perhaps
1359 other targets, that's not true).
1361 STEP nonzero if we should step (zero to continue instead).
1362 SIG is the signal to give the inferior (zero for none). */
1364 resume (int step, enum target_signal sig)
1366 int should_resume = 1;
1367 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
1368 struct regcache *regcache = get_current_regcache ();
1369 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1370 struct thread_info *tp = inferior_thread ();
1371 CORE_ADDR pc = regcache_read_pc (regcache);
1372 struct address_space *aspace = get_regcache_aspace (regcache);
1377 fprintf_unfiltered (gdb_stdlog,
1378 "infrun: resume (step=%d, signal=%d), "
1379 "trap_expected=%d\n",
1380 step, sig, tp->trap_expected);
1382 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
1383 over an instruction that causes a page fault without triggering
1384 a hardware watchpoint. The kernel properly notices that it shouldn't
1385 stop, because the hardware watchpoint is not triggered, but it forgets
1386 the step request and continues the program normally.
1387 Work around the problem by removing hardware watchpoints if a step is
1388 requested, GDB will check for a hardware watchpoint trigger after the
1390 if (CANNOT_STEP_HW_WATCHPOINTS && step)
1391 remove_hw_watchpoints ();
1394 /* Normally, by the time we reach `resume', the breakpoints are either
1395 removed or inserted, as appropriate. The exception is if we're sitting
1396 at a permanent breakpoint; we need to step over it, but permanent
1397 breakpoints can't be removed. So we have to test for it here. */
1398 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
1400 if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
1401 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
1404 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1405 how to step past a permanent breakpoint on this architecture. Try using\n\
1406 a command like `return' or `jump' to continue execution."));
1409 /* If enabled, step over breakpoints by executing a copy of the
1410 instruction at a different address.
1412 We can't use displaced stepping when we have a signal to deliver;
1413 the comments for displaced_step_prepare explain why. The
1414 comments in the handle_inferior event for dealing with 'random
1415 signals' explain what we do instead. */
1416 if (use_displaced_stepping (gdbarch)
1417 && (tp->trap_expected
1418 || (step && gdbarch_software_single_step_p (gdbarch)))
1419 && sig == TARGET_SIGNAL_0)
1421 if (!displaced_step_prepare (inferior_ptid))
1423 /* Got placed in displaced stepping queue. Will be resumed
1424 later when all the currently queued displaced stepping
1425 requests finish. The thread is not executing at this point,
1426 and the call to set_executing will be made later. But we
1427 need to call set_running here, since from frontend point of view,
1428 the thread is running. */
1429 set_running (inferior_ptid, 1);
1430 discard_cleanups (old_cleanups);
1434 step = gdbarch_displaced_step_hw_singlestep
1435 (gdbarch, displaced_step_closure);
1438 /* Do we need to do it the hard way, w/temp breakpoints? */
1440 step = maybe_software_singlestep (gdbarch, pc);
1446 /* If STEP is set, it's a request to use hardware stepping
1447 facilities. But in that case, we should never
1448 use singlestep breakpoint. */
1449 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
1451 /* Decide the set of threads to ask the target to resume. Start
1452 by assuming everything will be resumed, than narrow the set
1453 by applying increasingly restricting conditions. */
1455 /* By default, resume all threads of all processes. */
1456 resume_ptid = RESUME_ALL;
1458 /* Maybe resume only all threads of the current process. */
1459 if (!sched_multi && target_supports_multi_process ())
1461 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
1464 /* Maybe resume a single thread after all. */
1465 if (singlestep_breakpoints_inserted_p
1466 && stepping_past_singlestep_breakpoint)
1468 /* The situation here is as follows. In thread T1 we wanted to
1469 single-step. Lacking hardware single-stepping we've
1470 set breakpoint at the PC of the next instruction -- call it
1471 P. After resuming, we've hit that breakpoint in thread T2.
1472 Now we've removed original breakpoint, inserted breakpoint
1473 at P+1, and try to step to advance T2 past breakpoint.
1474 We need to step only T2, as if T1 is allowed to freely run,
1475 it can run past P, and if other threads are allowed to run,
1476 they can hit breakpoint at P+1, and nested hits of single-step
1477 breakpoints is not something we'd want -- that's complicated
1478 to support, and has no value. */
1479 resume_ptid = inferior_ptid;
1481 else if ((step || singlestep_breakpoints_inserted_p)
1482 && tp->trap_expected)
1484 /* We're allowing a thread to run past a breakpoint it has
1485 hit, by single-stepping the thread with the breakpoint
1486 removed. In which case, we need to single-step only this
1487 thread, and keep others stopped, as they can miss this
1488 breakpoint if allowed to run.
1490 The current code actually removes all breakpoints when
1491 doing this, not just the one being stepped over, so if we
1492 let other threads run, we can actually miss any
1493 breakpoint, not just the one at PC. */
1494 resume_ptid = inferior_ptid;
1498 /* With non-stop mode on, threads are always handled
1500 resume_ptid = inferior_ptid;
1502 else if ((scheduler_mode == schedlock_on)
1503 || (scheduler_mode == schedlock_step
1504 && (step || singlestep_breakpoints_inserted_p)))
1506 /* User-settable 'scheduler' mode requires solo thread resume. */
1507 resume_ptid = inferior_ptid;
1510 if (gdbarch_cannot_step_breakpoint (gdbarch))
1512 /* Most targets can step a breakpoint instruction, thus
1513 executing it normally. But if this one cannot, just
1514 continue and we will hit it anyway. */
1515 if (step && breakpoint_inserted_here_p (aspace, pc))
1520 && use_displaced_stepping (gdbarch)
1521 && tp->trap_expected)
1523 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
1524 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
1525 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
1528 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1529 paddress (resume_gdbarch, actual_pc));
1530 read_memory (actual_pc, buf, sizeof (buf));
1531 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1534 /* Install inferior's terminal modes. */
1535 target_terminal_inferior ();
1537 /* Avoid confusing the next resume, if the next stop/resume
1538 happens to apply to another thread. */
1539 tp->stop_signal = TARGET_SIGNAL_0;
1541 target_resume (resume_ptid, step, sig);
1544 discard_cleanups (old_cleanups);
1549 /* Clear out all variables saying what to do when inferior is continued.
1550 First do this, then set the ones you want, then call `proceed'. */
1553 clear_proceed_status_thread (struct thread_info *tp)
1556 fprintf_unfiltered (gdb_stdlog,
1557 "infrun: clear_proceed_status_thread (%s)\n",
1558 target_pid_to_str (tp->ptid));
1560 tp->trap_expected = 0;
1561 tp->step_range_start = 0;
1562 tp->step_range_end = 0;
1563 tp->step_frame_id = null_frame_id;
1564 tp->step_stack_frame_id = null_frame_id;
1565 tp->step_over_calls = STEP_OVER_UNDEBUGGABLE;
1566 tp->stop_requested = 0;
1570 tp->proceed_to_finish = 0;
1572 /* Discard any remaining commands or status from previous stop. */
1573 bpstat_clear (&tp->stop_bpstat);
1577 clear_proceed_status_callback (struct thread_info *tp, void *data)
1579 if (is_exited (tp->ptid))
1582 clear_proceed_status_thread (tp);
1587 clear_proceed_status (void)
1591 /* In all-stop mode, delete the per-thread status of all
1592 threads, even if inferior_ptid is null_ptid, there may be
1593 threads on the list. E.g., we may be launching a new
1594 process, while selecting the executable. */
1595 iterate_over_threads (clear_proceed_status_callback, NULL);
1598 if (!ptid_equal (inferior_ptid, null_ptid))
1600 struct inferior *inferior;
1604 /* If in non-stop mode, only delete the per-thread status of
1605 the current thread. */
1606 clear_proceed_status_thread (inferior_thread ());
1609 inferior = current_inferior ();
1610 inferior->stop_soon = NO_STOP_QUIETLY;
1613 stop_after_trap = 0;
1615 observer_notify_about_to_proceed ();
1619 regcache_xfree (stop_registers);
1620 stop_registers = NULL;
1624 /* Check the current thread against the thread that reported the most recent
1625 event. If a step-over is required return TRUE and set the current thread
1626 to the old thread. Otherwise return FALSE.
1628 This should be suitable for any targets that support threads. */
1631 prepare_to_proceed (int step)
1634 struct target_waitstatus wait_status;
1635 int schedlock_enabled;
1637 /* With non-stop mode on, threads are always handled individually. */
1638 gdb_assert (! non_stop);
1640 /* Get the last target status returned by target_wait(). */
1641 get_last_target_status (&wait_ptid, &wait_status);
1643 /* Make sure we were stopped at a breakpoint. */
1644 if (wait_status.kind != TARGET_WAITKIND_STOPPED
1645 || wait_status.value.sig != TARGET_SIGNAL_TRAP)
1650 schedlock_enabled = (scheduler_mode == schedlock_on
1651 || (scheduler_mode == schedlock_step
1654 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
1655 if (schedlock_enabled)
1658 /* Don't switch over if we're about to resume some other process
1659 other than WAIT_PTID's, and schedule-multiple is off. */
1661 && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid))
1664 /* Switched over from WAIT_PID. */
1665 if (!ptid_equal (wait_ptid, minus_one_ptid)
1666 && !ptid_equal (inferior_ptid, wait_ptid))
1668 struct regcache *regcache = get_thread_regcache (wait_ptid);
1670 if (breakpoint_here_p (get_regcache_aspace (regcache),
1671 regcache_read_pc (regcache)))
1673 /* If stepping, remember current thread to switch back to. */
1675 deferred_step_ptid = inferior_ptid;
1677 /* Switch back to WAIT_PID thread. */
1678 switch_to_thread (wait_ptid);
1680 /* We return 1 to indicate that there is a breakpoint here,
1681 so we need to step over it before continuing to avoid
1682 hitting it straight away. */
1690 /* Basic routine for continuing the program in various fashions.
1692 ADDR is the address to resume at, or -1 for resume where stopped.
1693 SIGGNAL is the signal to give it, or 0 for none,
1694 or -1 for act according to how it stopped.
1695 STEP is nonzero if should trap after one instruction.
1696 -1 means return after that and print nothing.
1697 You should probably set various step_... variables
1698 before calling here, if you are stepping.
1700 You should call clear_proceed_status before calling proceed. */
1703 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
1705 struct regcache *regcache;
1706 struct gdbarch *gdbarch;
1707 struct thread_info *tp;
1709 struct address_space *aspace;
1712 /* If we're stopped at a fork/vfork, follow the branch set by the
1713 "set follow-fork-mode" command; otherwise, we'll just proceed
1714 resuming the current thread. */
1715 if (!follow_fork ())
1717 /* The target for some reason decided not to resume. */
1722 regcache = get_current_regcache ();
1723 gdbarch = get_regcache_arch (regcache);
1724 aspace = get_regcache_aspace (regcache);
1725 pc = regcache_read_pc (regcache);
1728 step_start_function = find_pc_function (pc);
1730 stop_after_trap = 1;
1732 if (addr == (CORE_ADDR) -1)
1734 if (pc == stop_pc && breakpoint_here_p (aspace, pc)
1735 && execution_direction != EXEC_REVERSE)
1736 /* There is a breakpoint at the address we will resume at,
1737 step one instruction before inserting breakpoints so that
1738 we do not stop right away (and report a second hit at this
1741 Note, we don't do this in reverse, because we won't
1742 actually be executing the breakpoint insn anyway.
1743 We'll be (un-)executing the previous instruction. */
1746 else if (gdbarch_single_step_through_delay_p (gdbarch)
1747 && gdbarch_single_step_through_delay (gdbarch,
1748 get_current_frame ()))
1749 /* We stepped onto an instruction that needs to be stepped
1750 again before re-inserting the breakpoint, do so. */
1755 regcache_write_pc (regcache, addr);
1759 fprintf_unfiltered (gdb_stdlog,
1760 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
1761 paddress (gdbarch, addr), siggnal, step);
1764 /* In non-stop, each thread is handled individually. The context
1765 must already be set to the right thread here. */
1769 /* In a multi-threaded task we may select another thread and
1770 then continue or step.
1772 But if the old thread was stopped at a breakpoint, it will
1773 immediately cause another breakpoint stop without any
1774 execution (i.e. it will report a breakpoint hit incorrectly).
1775 So we must step over it first.
1777 prepare_to_proceed checks the current thread against the
1778 thread that reported the most recent event. If a step-over
1779 is required it returns TRUE and sets the current thread to
1781 if (prepare_to_proceed (step))
1785 /* prepare_to_proceed may change the current thread. */
1786 tp = inferior_thread ();
1790 tp->trap_expected = 1;
1791 /* If displaced stepping is enabled, we can step over the
1792 breakpoint without hitting it, so leave all breakpoints
1793 inserted. Otherwise we need to disable all breakpoints, step
1794 one instruction, and then re-add them when that step is
1796 if (!use_displaced_stepping (gdbarch))
1797 remove_breakpoints ();
1800 /* We can insert breakpoints if we're not trying to step over one,
1801 or if we are stepping over one but we're using displaced stepping
1803 if (! tp->trap_expected || use_displaced_stepping (gdbarch))
1804 insert_breakpoints ();
1808 /* Pass the last stop signal to the thread we're resuming,
1809 irrespective of whether the current thread is the thread that
1810 got the last event or not. This was historically GDB's
1811 behaviour before keeping a stop_signal per thread. */
1813 struct thread_info *last_thread;
1815 struct target_waitstatus last_status;
1817 get_last_target_status (&last_ptid, &last_status);
1818 if (!ptid_equal (inferior_ptid, last_ptid)
1819 && !ptid_equal (last_ptid, null_ptid)
1820 && !ptid_equal (last_ptid, minus_one_ptid))
1822 last_thread = find_thread_ptid (last_ptid);
1825 tp->stop_signal = last_thread->stop_signal;
1826 last_thread->stop_signal = TARGET_SIGNAL_0;
1831 if (siggnal != TARGET_SIGNAL_DEFAULT)
1832 tp->stop_signal = siggnal;
1833 /* If this signal should not be seen by program,
1834 give it zero. Used for debugging signals. */
1835 else if (!signal_program[tp->stop_signal])
1836 tp->stop_signal = TARGET_SIGNAL_0;
1838 annotate_starting ();
1840 /* Make sure that output from GDB appears before output from the
1842 gdb_flush (gdb_stdout);
1844 /* Refresh prev_pc value just prior to resuming. This used to be
1845 done in stop_stepping, however, setting prev_pc there did not handle
1846 scenarios such as inferior function calls or returning from
1847 a function via the return command. In those cases, the prev_pc
1848 value was not set properly for subsequent commands. The prev_pc value
1849 is used to initialize the starting line number in the ecs. With an
1850 invalid value, the gdb next command ends up stopping at the position
1851 represented by the next line table entry past our start position.
1852 On platforms that generate one line table entry per line, this
1853 is not a problem. However, on the ia64, the compiler generates
1854 extraneous line table entries that do not increase the line number.
1855 When we issue the gdb next command on the ia64 after an inferior call
1856 or a return command, we often end up a few instructions forward, still
1857 within the original line we started.
1859 An attempt was made to have init_execution_control_state () refresh
1860 the prev_pc value before calculating the line number. This approach
1861 did not work because on platforms that use ptrace, the pc register
1862 cannot be read unless the inferior is stopped. At that point, we
1863 are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1864 call can fail. Setting the prev_pc value here ensures the value is
1865 updated correctly when the inferior is stopped. */
1866 tp->prev_pc = regcache_read_pc (get_current_regcache ());
1868 /* Fill in with reasonable starting values. */
1869 init_thread_stepping_state (tp);
1871 /* Reset to normal state. */
1872 init_infwait_state ();
1874 /* Resume inferior. */
1875 resume (oneproc || step || bpstat_should_step (), tp->stop_signal);
1877 /* Wait for it to stop (if not standalone)
1878 and in any case decode why it stopped, and act accordingly. */
1879 /* Do this only if we are not using the event loop, or if the target
1880 does not support asynchronous execution. */
1881 if (!target_can_async_p ())
1883 wait_for_inferior (0);
1889 /* Start remote-debugging of a machine over a serial link. */
1892 start_remote (int from_tty)
1894 struct inferior *inferior;
1895 init_wait_for_inferior ();
1897 inferior = current_inferior ();
1898 inferior->stop_soon = STOP_QUIETLY_REMOTE;
1900 /* Always go on waiting for the target, regardless of the mode. */
1901 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1902 indicate to wait_for_inferior that a target should timeout if
1903 nothing is returned (instead of just blocking). Because of this,
1904 targets expecting an immediate response need to, internally, set
1905 things up so that the target_wait() is forced to eventually
1907 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1908 differentiate to its caller what the state of the target is after
1909 the initial open has been performed. Here we're assuming that
1910 the target has stopped. It should be possible to eventually have
1911 target_open() return to the caller an indication that the target
1912 is currently running and GDB state should be set to the same as
1913 for an async run. */
1914 wait_for_inferior (0);
1916 /* Now that the inferior has stopped, do any bookkeeping like
1917 loading shared libraries. We want to do this before normal_stop,
1918 so that the displayed frame is up to date. */
1919 post_create_inferior (¤t_target, from_tty);
1924 /* Initialize static vars when a new inferior begins. */
1927 init_wait_for_inferior (void)
1929 /* These are meaningless until the first time through wait_for_inferior. */
1931 breakpoint_init_inferior (inf_starting);
1933 clear_proceed_status ();
1935 stepping_past_singlestep_breakpoint = 0;
1936 deferred_step_ptid = null_ptid;
1938 target_last_wait_ptid = minus_one_ptid;
1940 previous_inferior_ptid = null_ptid;
1941 init_infwait_state ();
1943 displaced_step_clear ();
1945 /* Discard any skipped inlined frames. */
1946 clear_inline_frame_state (minus_one_ptid);
1950 /* This enum encodes possible reasons for doing a target_wait, so that
1951 wfi can call target_wait in one place. (Ultimately the call will be
1952 moved out of the infinite loop entirely.) */
1956 infwait_normal_state,
1957 infwait_thread_hop_state,
1958 infwait_step_watch_state,
1959 infwait_nonstep_watch_state
1962 /* Why did the inferior stop? Used to print the appropriate messages
1963 to the interface from within handle_inferior_event(). */
1964 enum inferior_stop_reason
1966 /* Step, next, nexti, stepi finished. */
1968 /* Inferior terminated by signal. */
1970 /* Inferior exited. */
1972 /* Inferior received signal, and user asked to be notified. */
1974 /* Reverse execution -- target ran out of history info. */
1978 /* The PTID we'll do a target_wait on.*/
1981 /* Current inferior wait state. */
1982 enum infwait_states infwait_state;
1984 /* Data to be passed around while handling an event. This data is
1985 discarded between events. */
1986 struct execution_control_state
1989 /* The thread that got the event, if this was a thread event; NULL
1991 struct thread_info *event_thread;
1993 struct target_waitstatus ws;
1995 CORE_ADDR stop_func_start;
1996 CORE_ADDR stop_func_end;
1997 char *stop_func_name;
1998 int new_thread_event;
2002 static void init_execution_control_state (struct execution_control_state *ecs);
2004 static void handle_inferior_event (struct execution_control_state *ecs);
2006 static void handle_step_into_function (struct gdbarch *gdbarch,
2007 struct execution_control_state *ecs);
2008 static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2009 struct execution_control_state *ecs);
2010 static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame);
2011 static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
2012 static void insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
2013 struct symtab_and_line sr_sal,
2014 struct frame_id sr_id);
2015 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
2017 static void stop_stepping (struct execution_control_state *ecs);
2018 static void prepare_to_wait (struct execution_control_state *ecs);
2019 static void keep_going (struct execution_control_state *ecs);
2020 static void print_stop_reason (enum inferior_stop_reason stop_reason,
2023 /* Callback for iterate over threads. If the thread is stopped, but
2024 the user/frontend doesn't know about that yet, go through
2025 normal_stop, as if the thread had just stopped now. ARG points at
2026 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2027 ptid_is_pid(PTID) is true, applies to all threads of the process
2028 pointed at by PTID. Otherwise, apply only to the thread pointed by
2032 infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2034 ptid_t ptid = * (ptid_t *) arg;
2036 if ((ptid_equal (info->ptid, ptid)
2037 || ptid_equal (minus_one_ptid, ptid)
2038 || (ptid_is_pid (ptid)
2039 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2040 && is_running (info->ptid)
2041 && !is_executing (info->ptid))
2043 struct cleanup *old_chain;
2044 struct execution_control_state ecss;
2045 struct execution_control_state *ecs = &ecss;
2047 memset (ecs, 0, sizeof (*ecs));
2049 old_chain = make_cleanup_restore_current_thread ();
2051 switch_to_thread (info->ptid);
2053 /* Go through handle_inferior_event/normal_stop, so we always
2054 have consistent output as if the stop event had been
2056 ecs->ptid = info->ptid;
2057 ecs->event_thread = find_thread_ptid (info->ptid);
2058 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2059 ecs->ws.value.sig = TARGET_SIGNAL_0;
2061 handle_inferior_event (ecs);
2063 if (!ecs->wait_some_more)
2065 struct thread_info *tp;
2069 /* Finish off the continuations. The continations
2070 themselves are responsible for realising the thread
2071 didn't finish what it was supposed to do. */
2072 tp = inferior_thread ();
2073 do_all_intermediate_continuations_thread (tp);
2074 do_all_continuations_thread (tp);
2077 do_cleanups (old_chain);
2083 /* This function is attached as a "thread_stop_requested" observer.
2084 Cleanup local state that assumed the PTID was to be resumed, and
2085 report the stop to the frontend. */
2088 infrun_thread_stop_requested (ptid_t ptid)
2090 struct displaced_step_request *it, *next, *prev = NULL;
2092 /* PTID was requested to stop. Remove it from the displaced
2093 stepping queue, so we don't try to resume it automatically. */
2094 for (it = displaced_step_request_queue; it; it = next)
2098 if (ptid_equal (it->ptid, ptid)
2099 || ptid_equal (minus_one_ptid, ptid)
2100 || (ptid_is_pid (ptid)
2101 && ptid_get_pid (ptid) == ptid_get_pid (it->ptid)))
2103 if (displaced_step_request_queue == it)
2104 displaced_step_request_queue = it->next;
2106 prev->next = it->next;
2114 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2118 infrun_thread_thread_exit (struct thread_info *tp, int silent)
2120 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2121 nullify_last_target_wait_ptid ();
2124 /* Callback for iterate_over_threads. */
2127 delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
2129 if (is_exited (info->ptid))
2132 delete_step_resume_breakpoint (info);
2136 /* In all-stop, delete the step resume breakpoint of any thread that
2137 had one. In non-stop, delete the step resume breakpoint of the
2138 thread that just stopped. */
2141 delete_step_thread_step_resume_breakpoint (void)
2143 if (!target_has_execution
2144 || ptid_equal (inferior_ptid, null_ptid))
2145 /* If the inferior has exited, we have already deleted the step
2146 resume breakpoints out of GDB's lists. */
2151 /* If in non-stop mode, only delete the step-resume or
2152 longjmp-resume breakpoint of the thread that just stopped
2154 struct thread_info *tp = inferior_thread ();
2155 delete_step_resume_breakpoint (tp);
2158 /* In all-stop mode, delete all step-resume and longjmp-resume
2159 breakpoints of any thread that had them. */
2160 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
2163 /* A cleanup wrapper. */
2166 delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
2168 delete_step_thread_step_resume_breakpoint ();
2171 /* Pretty print the results of target_wait, for debugging purposes. */
2174 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
2175 const struct target_waitstatus *ws)
2177 char *status_string = target_waitstatus_to_string (ws);
2178 struct ui_file *tmp_stream = mem_fileopen ();
2181 /* The text is split over several lines because it was getting too long.
2182 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2183 output as a unit; we want only one timestamp printed if debug_timestamp
2186 fprintf_unfiltered (tmp_stream,
2187 "infrun: target_wait (%d", PIDGET (waiton_ptid));
2188 if (PIDGET (waiton_ptid) != -1)
2189 fprintf_unfiltered (tmp_stream,
2190 " [%s]", target_pid_to_str (waiton_ptid));
2191 fprintf_unfiltered (tmp_stream, ", status) =\n");
2192 fprintf_unfiltered (tmp_stream,
2193 "infrun: %d [%s],\n",
2194 PIDGET (result_ptid), target_pid_to_str (result_ptid));
2195 fprintf_unfiltered (tmp_stream,
2199 text = ui_file_xstrdup (tmp_stream, NULL);
2201 /* This uses %s in part to handle %'s in the text, but also to avoid
2202 a gcc error: the format attribute requires a string literal. */
2203 fprintf_unfiltered (gdb_stdlog, "%s", text);
2205 xfree (status_string);
2207 ui_file_delete (tmp_stream);
2210 /* Wait for control to return from inferior to debugger.
2212 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
2213 as if they were SIGTRAP signals. This can be useful during
2214 the startup sequence on some targets such as HP/UX, where
2215 we receive an EXEC event instead of the expected SIGTRAP.
2217 If inferior gets a signal, we may decide to start it up again
2218 instead of returning. That is why there is a loop in this function.
2219 When this function actually returns it means the inferior
2220 should be left stopped and GDB should read more commands. */
2223 wait_for_inferior (int treat_exec_as_sigtrap)
2225 struct cleanup *old_cleanups;
2226 struct execution_control_state ecss;
2227 struct execution_control_state *ecs;
2231 (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
2232 treat_exec_as_sigtrap);
2235 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
2238 memset (ecs, 0, sizeof (*ecs));
2240 /* We'll update this if & when we switch to a new thread. */
2241 previous_inferior_ptid = inferior_ptid;
2245 struct cleanup *old_chain;
2247 /* We have to invalidate the registers BEFORE calling target_wait
2248 because they can be loaded from the target while in target_wait.
2249 This makes remote debugging a bit more efficient for those
2250 targets that provide critical registers as part of their normal
2251 status mechanism. */
2253 overlay_cache_invalid = 1;
2254 registers_changed ();
2256 if (deprecated_target_wait_hook)
2257 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
2259 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
2262 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2264 if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD)
2266 xfree (ecs->ws.value.execd_pathname);
2267 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2268 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
2271 /* If an error happens while handling the event, propagate GDB's
2272 knowledge of the executing state to the frontend/user running
2274 old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2276 if (ecs->ws.kind == TARGET_WAITKIND_SYSCALL_ENTRY
2277 || ecs->ws.kind == TARGET_WAITKIND_SYSCALL_RETURN)
2278 ecs->ws.value.syscall_number = UNKNOWN_SYSCALL;
2280 /* Now figure out what to do with the result of the result. */
2281 handle_inferior_event (ecs);
2283 /* No error, don't finish the state yet. */
2284 discard_cleanups (old_chain);
2286 if (!ecs->wait_some_more)
2290 do_cleanups (old_cleanups);
2293 /* Asynchronous version of wait_for_inferior. It is called by the
2294 event loop whenever a change of state is detected on the file
2295 descriptor corresponding to the target. It can be called more than
2296 once to complete a single execution command. In such cases we need
2297 to keep the state in a global variable ECSS. If it is the last time
2298 that this function is called for a single execution command, then
2299 report to the user that the inferior has stopped, and do the
2300 necessary cleanups. */
2303 fetch_inferior_event (void *client_data)
2305 struct execution_control_state ecss;
2306 struct execution_control_state *ecs = &ecss;
2307 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
2308 struct cleanup *ts_old_chain;
2309 int was_sync = sync_execution;
2311 memset (ecs, 0, sizeof (*ecs));
2313 /* We'll update this if & when we switch to a new thread. */
2314 previous_inferior_ptid = inferior_ptid;
2317 /* In non-stop mode, the user/frontend should not notice a thread
2318 switch due to internal events. Make sure we reverse to the
2319 user selected thread and frame after handling the event and
2320 running any breakpoint commands. */
2321 make_cleanup_restore_current_thread ();
2323 /* We have to invalidate the registers BEFORE calling target_wait
2324 because they can be loaded from the target while in target_wait.
2325 This makes remote debugging a bit more efficient for those
2326 targets that provide critical registers as part of their normal
2327 status mechanism. */
2329 overlay_cache_invalid = 1;
2330 registers_changed ();
2332 if (deprecated_target_wait_hook)
2334 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2336 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2339 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2342 && ecs->ws.kind != TARGET_WAITKIND_IGNORE
2343 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2344 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2345 /* In non-stop mode, each thread is handled individually. Switch
2346 early, so the global state is set correctly for this
2348 context_switch (ecs->ptid);
2350 /* If an error happens while handling the event, propagate GDB's
2351 knowledge of the executing state to the frontend/user running
2354 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2356 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
2358 /* Now figure out what to do with the result of the result. */
2359 handle_inferior_event (ecs);
2361 if (!ecs->wait_some_more)
2363 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2365 delete_step_thread_step_resume_breakpoint ();
2367 /* We may not find an inferior if this was a process exit. */
2368 if (inf == NULL || inf->stop_soon == NO_STOP_QUIETLY)
2371 if (target_has_execution
2372 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2373 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2374 && ecs->event_thread->step_multi
2375 && ecs->event_thread->stop_step)
2376 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
2378 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2381 /* No error, don't finish the thread states yet. */
2382 discard_cleanups (ts_old_chain);
2384 /* Revert thread and frame. */
2385 do_cleanups (old_chain);
2387 /* If the inferior was in sync execution mode, and now isn't,
2388 restore the prompt. */
2389 if (was_sync && !sync_execution)
2390 display_gdb_prompt (0);
2393 /* Record the frame and location we're currently stepping through. */
2395 set_step_info (struct frame_info *frame, struct symtab_and_line sal)
2397 struct thread_info *tp = inferior_thread ();
2399 tp->step_frame_id = get_frame_id (frame);
2400 tp->step_stack_frame_id = get_stack_frame_id (frame);
2402 tp->current_symtab = sal.symtab;
2403 tp->current_line = sal.line;
2406 /* Prepare an execution control state for looping through a
2407 wait_for_inferior-type loop. */
2410 init_execution_control_state (struct execution_control_state *ecs)
2412 ecs->random_signal = 0;
2415 /* Clear context switchable stepping state. */
2418 init_thread_stepping_state (struct thread_info *tss)
2420 tss->stepping_over_breakpoint = 0;
2421 tss->step_after_step_resume_breakpoint = 0;
2422 tss->stepping_through_solib_after_catch = 0;
2423 tss->stepping_through_solib_catchpoints = NULL;
2426 /* Return the cached copy of the last pid/waitstatus returned by
2427 target_wait()/deprecated_target_wait_hook(). The data is actually
2428 cached by handle_inferior_event(), which gets called immediately
2429 after target_wait()/deprecated_target_wait_hook(). */
2432 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
2434 *ptidp = target_last_wait_ptid;
2435 *status = target_last_waitstatus;
2439 nullify_last_target_wait_ptid (void)
2441 target_last_wait_ptid = minus_one_ptid;
2444 /* Switch thread contexts. */
2447 context_switch (ptid_t ptid)
2451 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
2452 target_pid_to_str (inferior_ptid));
2453 fprintf_unfiltered (gdb_stdlog, "to %s\n",
2454 target_pid_to_str (ptid));
2457 switch_to_thread (ptid);
2461 adjust_pc_after_break (struct execution_control_state *ecs)
2463 struct regcache *regcache;
2464 struct gdbarch *gdbarch;
2465 struct address_space *aspace;
2466 CORE_ADDR breakpoint_pc;
2468 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2469 we aren't, just return.
2471 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2472 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2473 implemented by software breakpoints should be handled through the normal
2476 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2477 different signals (SIGILL or SIGEMT for instance), but it is less
2478 clear where the PC is pointing afterwards. It may not match
2479 gdbarch_decr_pc_after_break. I don't know any specific target that
2480 generates these signals at breakpoints (the code has been in GDB since at
2481 least 1992) so I can not guess how to handle them here.
2483 In earlier versions of GDB, a target with
2484 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2485 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2486 target with both of these set in GDB history, and it seems unlikely to be
2487 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2489 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
2492 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
2495 /* In reverse execution, when a breakpoint is hit, the instruction
2496 under it has already been de-executed. The reported PC always
2497 points at the breakpoint address, so adjusting it further would
2498 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2501 B1 0x08000000 : INSN1
2502 B2 0x08000001 : INSN2
2504 PC -> 0x08000003 : INSN4
2506 Say you're stopped at 0x08000003 as above. Reverse continuing
2507 from that point should hit B2 as below. Reading the PC when the
2508 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2509 been de-executed already.
2511 B1 0x08000000 : INSN1
2512 B2 PC -> 0x08000001 : INSN2
2516 We can't apply the same logic as for forward execution, because
2517 we would wrongly adjust the PC to 0x08000000, since there's a
2518 breakpoint at PC - 1. We'd then report a hit on B1, although
2519 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2521 if (execution_direction == EXEC_REVERSE)
2524 /* If this target does not decrement the PC after breakpoints, then
2525 we have nothing to do. */
2526 regcache = get_thread_regcache (ecs->ptid);
2527 gdbarch = get_regcache_arch (regcache);
2528 if (gdbarch_decr_pc_after_break (gdbarch) == 0)
2531 aspace = get_regcache_aspace (regcache);
2533 /* Find the location where (if we've hit a breakpoint) the
2534 breakpoint would be. */
2535 breakpoint_pc = regcache_read_pc (regcache)
2536 - gdbarch_decr_pc_after_break (gdbarch);
2538 /* Check whether there actually is a software breakpoint inserted at
2541 If in non-stop mode, a race condition is possible where we've
2542 removed a breakpoint, but stop events for that breakpoint were
2543 already queued and arrive later. To suppress those spurious
2544 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2545 and retire them after a number of stop events are reported. */
2546 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
2547 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
2549 struct cleanup *old_cleanups = NULL;
2551 old_cleanups = record_gdb_operation_disable_set ();
2553 /* When using hardware single-step, a SIGTRAP is reported for both
2554 a completed single-step and a software breakpoint. Need to
2555 differentiate between the two, as the latter needs adjusting
2556 but the former does not.
2558 The SIGTRAP can be due to a completed hardware single-step only if
2559 - we didn't insert software single-step breakpoints
2560 - the thread to be examined is still the current thread
2561 - this thread is currently being stepped
2563 If any of these events did not occur, we must have stopped due
2564 to hitting a software breakpoint, and have to back up to the
2567 As a special case, we could have hardware single-stepped a
2568 software breakpoint. In this case (prev_pc == breakpoint_pc),
2569 we also need to back up to the breakpoint address. */
2571 if (singlestep_breakpoints_inserted_p
2572 || !ptid_equal (ecs->ptid, inferior_ptid)
2573 || !currently_stepping (ecs->event_thread)
2574 || ecs->event_thread->prev_pc == breakpoint_pc)
2575 regcache_write_pc (regcache, breakpoint_pc);
2578 do_cleanups (old_cleanups);
2583 init_infwait_state (void)
2585 waiton_ptid = pid_to_ptid (-1);
2586 infwait_state = infwait_normal_state;
2590 error_is_running (void)
2593 Cannot execute this command while the selected thread is running."));
2597 ensure_not_running (void)
2599 if (is_running (inferior_ptid))
2600 error_is_running ();
2604 stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
2606 for (frame = get_prev_frame (frame);
2608 frame = get_prev_frame (frame))
2610 if (frame_id_eq (get_frame_id (frame), step_frame_id))
2612 if (get_frame_type (frame) != INLINE_FRAME)
2619 /* Auxiliary function that handles syscall entry/return events.
2620 It returns 1 if the inferior should keep going (and GDB
2621 should ignore the event), or 0 if the event deserves to be
2625 handle_syscall_event (struct execution_control_state *ecs)
2627 struct regcache *regcache;
2628 struct gdbarch *gdbarch;
2631 if (!ptid_equal (ecs->ptid, inferior_ptid))
2632 context_switch (ecs->ptid);
2634 regcache = get_thread_regcache (ecs->ptid);
2635 gdbarch = get_regcache_arch (regcache);
2636 syscall_number = gdbarch_get_syscall_number (gdbarch, ecs->ptid);
2637 stop_pc = regcache_read_pc (regcache);
2639 target_last_waitstatus.value.syscall_number = syscall_number;
2641 if (catch_syscall_enabled () > 0
2642 && catching_syscall_number (syscall_number) > 0)
2645 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
2648 ecs->event_thread->stop_bpstat
2649 = bpstat_stop_status (get_regcache_aspace (regcache),
2650 stop_pc, ecs->ptid);
2651 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
2653 if (!ecs->random_signal)
2655 /* Catchpoint hit. */
2656 ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2661 /* If no catchpoint triggered for this, then keep going. */
2662 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2667 /* Given an execution control state that has been freshly filled in
2668 by an event from the inferior, figure out what it means and take
2669 appropriate action. */
2672 handle_inferior_event (struct execution_control_state *ecs)
2674 struct frame_info *frame;
2675 struct gdbarch *gdbarch;
2676 int sw_single_step_trap_p = 0;
2677 int stopped_by_watchpoint;
2678 int stepped_after_stopped_by_watchpoint = 0;
2679 struct symtab_and_line stop_pc_sal;
2680 enum stop_kind stop_soon;
2682 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
2684 /* We had an event in the inferior, but we are not interested in
2685 handling it at this level. The lower layers have already
2686 done what needs to be done, if anything.
2688 One of the possible circumstances for this is when the
2689 inferior produces output for the console. The inferior has
2690 not stopped, and we are ignoring the event. Another possible
2691 circumstance is any event which the lower level knows will be
2692 reported multiple times without an intervening resume. */
2694 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
2695 prepare_to_wait (ecs);
2699 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
2700 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2702 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2704 stop_soon = inf->stop_soon;
2707 stop_soon = NO_STOP_QUIETLY;
2709 /* Cache the last pid/waitstatus. */
2710 target_last_wait_ptid = ecs->ptid;
2711 target_last_waitstatus = ecs->ws;
2713 /* Always clear state belonging to the previous time we stopped. */
2714 stop_stack_dummy = 0;
2716 /* If it's a new process, add it to the thread database */
2718 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
2719 && !ptid_equal (ecs->ptid, minus_one_ptid)
2720 && !in_thread_list (ecs->ptid));
2722 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
2723 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
2724 add_thread (ecs->ptid);
2726 ecs->event_thread = find_thread_ptid (ecs->ptid);
2728 /* Dependent on valid ECS->EVENT_THREAD. */
2729 adjust_pc_after_break (ecs);
2731 /* Dependent on the current PC value modified by adjust_pc_after_break. */
2732 reinit_frame_cache ();
2734 breakpoint_retire_moribund ();
2736 /* Mark the non-executing threads accordingly. In all-stop, all
2737 threads of all processes are stopped when we get any event
2738 reported. In non-stop mode, only the event thread stops. If
2739 we're handling a process exit in non-stop mode, there's nothing
2740 to do, as threads of the dead process are gone, and threads of
2741 any other process were left running. */
2743 set_executing (minus_one_ptid, 0);
2744 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2745 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
2746 set_executing (inferior_ptid, 0);
2748 switch (infwait_state)
2750 case infwait_thread_hop_state:
2752 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
2755 case infwait_normal_state:
2757 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
2760 case infwait_step_watch_state:
2762 fprintf_unfiltered (gdb_stdlog,
2763 "infrun: infwait_step_watch_state\n");
2765 stepped_after_stopped_by_watchpoint = 1;
2768 case infwait_nonstep_watch_state:
2770 fprintf_unfiltered (gdb_stdlog,
2771 "infrun: infwait_nonstep_watch_state\n");
2772 insert_breakpoints ();
2774 /* FIXME-maybe: is this cleaner than setting a flag? Does it
2775 handle things like signals arriving and other things happening
2776 in combination correctly? */
2777 stepped_after_stopped_by_watchpoint = 1;
2781 internal_error (__FILE__, __LINE__, _("bad switch"));
2784 infwait_state = infwait_normal_state;
2785 waiton_ptid = pid_to_ptid (-1);
2787 switch (ecs->ws.kind)
2789 case TARGET_WAITKIND_LOADED:
2791 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
2792 /* Ignore gracefully during startup of the inferior, as it might
2793 be the shell which has just loaded some objects, otherwise
2794 add the symbols for the newly loaded objects. Also ignore at
2795 the beginning of an attach or remote session; we will query
2796 the full list of libraries once the connection is
2798 if (stop_soon == NO_STOP_QUIETLY)
2800 /* Check for any newly added shared libraries if we're
2801 supposed to be adding them automatically. Switch
2802 terminal for any messages produced by
2803 breakpoint_re_set. */
2804 target_terminal_ours_for_output ();
2805 /* NOTE: cagney/2003-11-25: Make certain that the target
2806 stack's section table is kept up-to-date. Architectures,
2807 (e.g., PPC64), use the section table to perform
2808 operations such as address => section name and hence
2809 require the table to contain all sections (including
2810 those found in shared libraries). */
2812 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
2814 solib_add (NULL, 0, ¤t_target, auto_solib_add);
2816 target_terminal_inferior ();
2818 /* If requested, stop when the dynamic linker notifies
2819 gdb of events. This allows the user to get control
2820 and place breakpoints in initializer routines for
2821 dynamically loaded objects (among other things). */
2822 if (stop_on_solib_events)
2824 /* Make sure we print "Stopped due to solib-event" in
2826 stop_print_frame = 1;
2828 stop_stepping (ecs);
2832 /* NOTE drow/2007-05-11: This might be a good place to check
2833 for "catch load". */
2836 /* If we are skipping through a shell, or through shared library
2837 loading that we aren't interested in, resume the program. If
2838 we're running the program normally, also resume. But stop if
2839 we're attaching or setting up a remote connection. */
2840 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
2842 /* Loading of shared libraries might have changed breakpoint
2843 addresses. Make sure new breakpoints are inserted. */
2844 if (stop_soon == NO_STOP_QUIETLY
2845 && !breakpoints_always_inserted_mode ())
2846 insert_breakpoints ();
2847 resume (0, TARGET_SIGNAL_0);
2848 prepare_to_wait (ecs);
2854 case TARGET_WAITKIND_SPURIOUS:
2856 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
2857 resume (0, TARGET_SIGNAL_0);
2858 prepare_to_wait (ecs);
2861 case TARGET_WAITKIND_EXITED:
2863 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
2864 inferior_ptid = ecs->ptid;
2865 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
2866 set_current_program_space (current_inferior ()->pspace);
2867 handle_vfork_child_exec_or_exit (0);
2868 target_terminal_ours (); /* Must do this before mourn anyway */
2869 print_stop_reason (EXITED, ecs->ws.value.integer);
2871 /* Record the exit code in the convenience variable $_exitcode, so
2872 that the user can inspect this again later. */
2873 set_internalvar_integer (lookup_internalvar ("_exitcode"),
2874 (LONGEST) ecs->ws.value.integer);
2875 gdb_flush (gdb_stdout);
2876 target_mourn_inferior ();
2877 singlestep_breakpoints_inserted_p = 0;
2878 stop_print_frame = 0;
2879 stop_stepping (ecs);
2882 case TARGET_WAITKIND_SIGNALLED:
2884 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n");
2885 inferior_ptid = ecs->ptid;
2886 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
2887 set_current_program_space (current_inferior ()->pspace);
2888 handle_vfork_child_exec_or_exit (0);
2889 stop_print_frame = 0;
2890 target_terminal_ours (); /* Must do this before mourn anyway */
2892 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
2893 reach here unless the inferior is dead. However, for years
2894 target_kill() was called here, which hints that fatal signals aren't
2895 really fatal on some systems. If that's true, then some changes
2897 target_mourn_inferior ();
2899 print_stop_reason (SIGNAL_EXITED, ecs->ws.value.sig);
2900 singlestep_breakpoints_inserted_p = 0;
2901 stop_stepping (ecs);
2904 /* The following are the only cases in which we keep going;
2905 the above cases end in a continue or goto. */
2906 case TARGET_WAITKIND_FORKED:
2907 case TARGET_WAITKIND_VFORKED:
2909 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
2911 if (!ptid_equal (ecs->ptid, inferior_ptid))
2913 context_switch (ecs->ptid);
2914 reinit_frame_cache ();
2917 /* Immediately detach breakpoints from the child before there's
2918 any chance of letting the user delete breakpoints from the
2919 breakpoint lists. If we don't do this early, it's easy to
2920 leave left over traps in the child, vis: "break foo; catch
2921 fork; c; <fork>; del; c; <child calls foo>". We only follow
2922 the fork on the last `continue', and by that time the
2923 breakpoint at "foo" is long gone from the breakpoint table.
2924 If we vforked, then we don't need to unpatch here, since both
2925 parent and child are sharing the same memory pages; we'll
2926 need to unpatch at follow/detach time instead to be certain
2927 that new breakpoints added between catchpoint hit time and
2928 vfork follow are detached. */
2929 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
2931 int child_pid = ptid_get_pid (ecs->ws.value.related_pid);
2933 /* This won't actually modify the breakpoint list, but will
2934 physically remove the breakpoints from the child. */
2935 detach_breakpoints (child_pid);
2938 /* In case the event is caught by a catchpoint, remember that
2939 the event is to be followed at the next resume of the thread,
2940 and not immediately. */
2941 ecs->event_thread->pending_follow = ecs->ws;
2943 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
2945 ecs->event_thread->stop_bpstat
2946 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
2947 stop_pc, ecs->ptid);
2949 /* Note that we're interested in knowing the bpstat actually
2950 causes a stop, not just if it may explain the signal.
2951 Software watchpoints, for example, always appear in the
2953 ecs->random_signal = !bpstat_causes_stop (ecs->event_thread->stop_bpstat);
2955 /* If no catchpoint triggered for this, then keep going. */
2956 if (ecs->random_signal)
2961 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
2963 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2965 should_resume = follow_fork ();
2968 child = ecs->ws.value.related_pid;
2970 /* In non-stop mode, also resume the other branch. */
2971 if (non_stop && !detach_fork)
2974 switch_to_thread (parent);
2976 switch_to_thread (child);
2978 ecs->event_thread = inferior_thread ();
2979 ecs->ptid = inferior_ptid;
2984 switch_to_thread (child);
2986 switch_to_thread (parent);
2988 ecs->event_thread = inferior_thread ();
2989 ecs->ptid = inferior_ptid;
2994 stop_stepping (ecs);
2997 ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2998 goto process_event_stop_test;
3000 case TARGET_WAITKIND_VFORK_DONE:
3001 /* Done with the shared memory region. Re-insert breakpoints in
3002 the parent, and keep going. */
3005 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3007 if (!ptid_equal (ecs->ptid, inferior_ptid))
3008 context_switch (ecs->ptid);
3010 current_inferior ()->waiting_for_vfork_done = 0;
3011 current_inferior ()->pspace->breakpoints_not_allowed = 0;
3012 /* This also takes care of reinserting breakpoints in the
3013 previously locked inferior. */
3017 case TARGET_WAITKIND_EXECD:
3019 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
3021 if (!ptid_equal (ecs->ptid, inferior_ptid))
3023 context_switch (ecs->ptid);
3024 reinit_frame_cache ();
3027 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3029 /* Do whatever is necessary to the parent branch of the vfork. */
3030 handle_vfork_child_exec_or_exit (1);
3032 /* This causes the eventpoints and symbol table to be reset.
3033 Must do this now, before trying to determine whether to
3035 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
3037 ecs->event_thread->stop_bpstat
3038 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3039 stop_pc, ecs->ptid);
3040 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
3042 /* Note that this may be referenced from inside
3043 bpstat_stop_status above, through inferior_has_execd. */
3044 xfree (ecs->ws.value.execd_pathname);
3045 ecs->ws.value.execd_pathname = NULL;
3047 /* If no catchpoint triggered for this, then keep going. */
3048 if (ecs->random_signal)
3050 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
3054 ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
3055 goto process_event_stop_test;
3057 /* Be careful not to try to gather much state about a thread
3058 that's in a syscall. It's frequently a losing proposition. */
3059 case TARGET_WAITKIND_SYSCALL_ENTRY:
3061 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3062 /* Getting the current syscall number */
3063 if (handle_syscall_event (ecs) != 0)
3065 goto process_event_stop_test;
3067 /* Before examining the threads further, step this thread to
3068 get it entirely out of the syscall. (We get notice of the
3069 event when the thread is just on the verge of exiting a
3070 syscall. Stepping one instruction seems to get it back
3072 case TARGET_WAITKIND_SYSCALL_RETURN:
3074 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3075 if (handle_syscall_event (ecs) != 0)
3077 goto process_event_stop_test;
3079 case TARGET_WAITKIND_STOPPED:
3081 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
3082 ecs->event_thread->stop_signal = ecs->ws.value.sig;
3085 case TARGET_WAITKIND_NO_HISTORY:
3086 /* Reverse execution: target ran out of history info. */
3087 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3088 print_stop_reason (NO_HISTORY, 0);
3089 stop_stepping (ecs);
3093 if (ecs->new_thread_event)
3096 /* Non-stop assumes that the target handles adding new threads
3097 to the thread list. */
3098 internal_error (__FILE__, __LINE__, "\
3099 targets should add new threads to the thread list themselves in non-stop mode.");
3101 /* We may want to consider not doing a resume here in order to
3102 give the user a chance to play with the new thread. It might
3103 be good to make that a user-settable option. */
3105 /* At this point, all threads are stopped (happens automatically
3106 in either the OS or the native code). Therefore we need to
3107 continue all threads in order to make progress. */
3109 if (!ptid_equal (ecs->ptid, inferior_ptid))
3110 context_switch (ecs->ptid);
3111 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
3112 prepare_to_wait (ecs);
3116 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
3118 /* Do we need to clean up the state of a thread that has
3119 completed a displaced single-step? (Doing so usually affects
3120 the PC, so do it here, before we set stop_pc.) */
3121 displaced_step_fixup (ecs->ptid, ecs->event_thread->stop_signal);
3123 /* If we either finished a single-step or hit a breakpoint, but
3124 the user wanted this thread to be stopped, pretend we got a
3125 SIG0 (generic unsignaled stop). */
3127 if (ecs->event_thread->stop_requested
3128 && ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
3129 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
3132 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3136 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3137 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3138 struct cleanup *old_chain = save_inferior_ptid ();
3140 inferior_ptid = ecs->ptid;
3142 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
3143 paddress (gdbarch, stop_pc));
3144 if (target_stopped_by_watchpoint ())
3147 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
3149 if (target_stopped_data_address (¤t_target, &addr))
3150 fprintf_unfiltered (gdb_stdlog,
3151 "infrun: stopped data address = %s\n",
3152 paddress (gdbarch, addr));
3154 fprintf_unfiltered (gdb_stdlog,
3155 "infrun: (no data address available)\n");
3158 do_cleanups (old_chain);
3161 if (stepping_past_singlestep_breakpoint)
3163 gdb_assert (singlestep_breakpoints_inserted_p);
3164 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
3165 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
3167 stepping_past_singlestep_breakpoint = 0;
3169 /* We've either finished single-stepping past the single-step
3170 breakpoint, or stopped for some other reason. It would be nice if
3171 we could tell, but we can't reliably. */
3172 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
3175 fprintf_unfiltered (gdb_stdlog, "infrun: stepping_past_singlestep_breakpoint\n");
3176 /* Pull the single step breakpoints out of the target. */
3177 remove_single_step_breakpoints ();
3178 singlestep_breakpoints_inserted_p = 0;
3180 ecs->random_signal = 0;
3181 ecs->event_thread->trap_expected = 0;
3183 context_switch (saved_singlestep_ptid);
3184 if (deprecated_context_hook)
3185 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3187 resume (1, TARGET_SIGNAL_0);
3188 prepare_to_wait (ecs);
3193 if (!ptid_equal (deferred_step_ptid, null_ptid))
3195 /* In non-stop mode, there's never a deferred_step_ptid set. */
3196 gdb_assert (!non_stop);
3198 /* If we stopped for some other reason than single-stepping, ignore
3199 the fact that we were supposed to switch back. */
3200 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
3203 fprintf_unfiltered (gdb_stdlog,
3204 "infrun: handling deferred step\n");
3206 /* Pull the single step breakpoints out of the target. */
3207 if (singlestep_breakpoints_inserted_p)
3209 remove_single_step_breakpoints ();
3210 singlestep_breakpoints_inserted_p = 0;
3213 /* Note: We do not call context_switch at this point, as the
3214 context is already set up for stepping the original thread. */
3215 switch_to_thread (deferred_step_ptid);
3216 deferred_step_ptid = null_ptid;
3217 /* Suppress spurious "Switching to ..." message. */
3218 previous_inferior_ptid = inferior_ptid;
3220 resume (1, TARGET_SIGNAL_0);
3221 prepare_to_wait (ecs);
3225 deferred_step_ptid = null_ptid;
3228 /* See if a thread hit a thread-specific breakpoint that was meant for
3229 another thread. If so, then step that thread past the breakpoint,
3232 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
3234 int thread_hop_needed = 0;
3235 struct address_space *aspace = get_regcache_aspace (get_current_regcache ());
3237 /* Check if a regular breakpoint has been hit before checking
3238 for a potential single step breakpoint. Otherwise, GDB will
3239 not see this breakpoint hit when stepping onto breakpoints. */
3240 if (regular_breakpoint_inserted_here_p (aspace, stop_pc))
3242 ecs->random_signal = 0;
3243 if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid))
3244 thread_hop_needed = 1;
3246 else if (singlestep_breakpoints_inserted_p)
3248 /* We have not context switched yet, so this should be true
3249 no matter which thread hit the singlestep breakpoint. */
3250 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
3252 fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
3254 target_pid_to_str (ecs->ptid));
3256 ecs->random_signal = 0;
3257 /* The call to in_thread_list is necessary because PTIDs sometimes
3258 change when we go from single-threaded to multi-threaded. If
3259 the singlestep_ptid is still in the list, assume that it is
3260 really different from ecs->ptid. */
3261 if (!ptid_equal (singlestep_ptid, ecs->ptid)
3262 && in_thread_list (singlestep_ptid))
3264 /* If the PC of the thread we were trying to single-step
3265 has changed, discard this event (which we were going
3266 to ignore anyway), and pretend we saw that thread
3267 trap. This prevents us continuously moving the
3268 single-step breakpoint forward, one instruction at a
3269 time. If the PC has changed, then the thread we were
3270 trying to single-step has trapped or been signalled,
3271 but the event has not been reported to GDB yet.
3273 There might be some cases where this loses signal
3274 information, if a signal has arrived at exactly the
3275 same time that the PC changed, but this is the best
3276 we can do with the information available. Perhaps we
3277 should arrange to report all events for all threads
3278 when they stop, or to re-poll the remote looking for
3279 this particular thread (i.e. temporarily enable
3282 CORE_ADDR new_singlestep_pc
3283 = regcache_read_pc (get_thread_regcache (singlestep_ptid));
3285 if (new_singlestep_pc != singlestep_pc)
3287 enum target_signal stop_signal;
3290 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
3291 " but expected thread advanced also\n");
3293 /* The current context still belongs to
3294 singlestep_ptid. Don't swap here, since that's
3295 the context we want to use. Just fudge our
3296 state and continue. */
3297 stop_signal = ecs->event_thread->stop_signal;
3298 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
3299 ecs->ptid = singlestep_ptid;
3300 ecs->event_thread = find_thread_ptid (ecs->ptid);
3301 ecs->event_thread->stop_signal = stop_signal;
3302 stop_pc = new_singlestep_pc;
3307 fprintf_unfiltered (gdb_stdlog,
3308 "infrun: unexpected thread\n");
3310 thread_hop_needed = 1;
3311 stepping_past_singlestep_breakpoint = 1;
3312 saved_singlestep_ptid = singlestep_ptid;
3317 if (thread_hop_needed)
3319 struct regcache *thread_regcache;
3320 int remove_status = 0;
3323 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
3325 /* Switch context before touching inferior memory, the
3326 previous thread may have exited. */
3327 if (!ptid_equal (inferior_ptid, ecs->ptid))
3328 context_switch (ecs->ptid);
3330 /* Saw a breakpoint, but it was hit by the wrong thread.
3333 if (singlestep_breakpoints_inserted_p)
3335 /* Pull the single step breakpoints out of the target. */
3336 remove_single_step_breakpoints ();
3337 singlestep_breakpoints_inserted_p = 0;
3340 /* If the arch can displace step, don't remove the
3342 thread_regcache = get_thread_regcache (ecs->ptid);
3343 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
3344 remove_status = remove_breakpoints ();
3346 /* Did we fail to remove breakpoints? If so, try
3347 to set the PC past the bp. (There's at least
3348 one situation in which we can fail to remove
3349 the bp's: On HP-UX's that use ttrace, we can't
3350 change the address space of a vforking child
3351 process until the child exits (well, okay, not
3352 then either :-) or execs. */
3353 if (remove_status != 0)
3354 error (_("Cannot step over breakpoint hit in wrong thread"));
3359 /* Only need to require the next event from this
3360 thread in all-stop mode. */
3361 waiton_ptid = ecs->ptid;
3362 infwait_state = infwait_thread_hop_state;
3365 ecs->event_thread->stepping_over_breakpoint = 1;
3370 else if (singlestep_breakpoints_inserted_p)
3372 sw_single_step_trap_p = 1;
3373 ecs->random_signal = 0;
3377 ecs->random_signal = 1;
3379 /* See if something interesting happened to the non-current thread. If
3380 so, then switch to that thread. */
3381 if (!ptid_equal (ecs->ptid, inferior_ptid))
3384 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
3386 context_switch (ecs->ptid);
3388 if (deprecated_context_hook)
3389 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3392 /* At this point, get hold of the now-current thread's frame. */
3393 frame = get_current_frame ();
3394 gdbarch = get_frame_arch (frame);
3396 if (singlestep_breakpoints_inserted_p)
3398 /* Pull the single step breakpoints out of the target. */
3399 remove_single_step_breakpoints ();
3400 singlestep_breakpoints_inserted_p = 0;
3403 if (stepped_after_stopped_by_watchpoint)
3404 stopped_by_watchpoint = 0;
3406 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
3408 /* If necessary, step over this watchpoint. We'll be back to display
3410 if (stopped_by_watchpoint
3411 && (target_have_steppable_watchpoint
3412 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
3414 /* At this point, we are stopped at an instruction which has
3415 attempted to write to a piece of memory under control of
3416 a watchpoint. The instruction hasn't actually executed
3417 yet. If we were to evaluate the watchpoint expression
3418 now, we would get the old value, and therefore no change
3419 would seem to have occurred.
3421 In order to make watchpoints work `right', we really need
3422 to complete the memory write, and then evaluate the
3423 watchpoint expression. We do this by single-stepping the
3426 It may not be necessary to disable the watchpoint to stop over
3427 it. For example, the PA can (with some kernel cooperation)
3428 single step over a watchpoint without disabling the watchpoint.
3430 It is far more common to need to disable a watchpoint to step
3431 the inferior over it. If we have non-steppable watchpoints,
3432 we must disable the current watchpoint; it's simplest to
3433 disable all watchpoints and breakpoints. */
3436 if (!target_have_steppable_watchpoint)
3437 remove_breakpoints ();
3439 hw_step = maybe_software_singlestep (gdbarch, stop_pc);
3440 target_resume (ecs->ptid, hw_step, TARGET_SIGNAL_0);
3441 waiton_ptid = ecs->ptid;
3442 if (target_have_steppable_watchpoint)
3443 infwait_state = infwait_step_watch_state;
3445 infwait_state = infwait_nonstep_watch_state;
3446 prepare_to_wait (ecs);
3450 ecs->stop_func_start = 0;
3451 ecs->stop_func_end = 0;
3452 ecs->stop_func_name = 0;
3453 /* Don't care about return value; stop_func_start and stop_func_name
3454 will both be 0 if it doesn't work. */
3455 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3456 &ecs->stop_func_start, &ecs->stop_func_end);
3457 ecs->stop_func_start
3458 += gdbarch_deprecated_function_start_offset (gdbarch);
3459 ecs->event_thread->stepping_over_breakpoint = 0;
3460 bpstat_clear (&ecs->event_thread->stop_bpstat);
3461 ecs->event_thread->stop_step = 0;
3462 stop_print_frame = 1;
3463 ecs->random_signal = 0;
3464 stopped_by_random_signal = 0;
3466 /* Hide inlined functions starting here, unless we just performed stepi or
3467 nexti. After stepi and nexti, always show the innermost frame (not any
3468 inline function call sites). */
3469 if (ecs->event_thread->step_range_end != 1)
3470 skip_inline_frames (ecs->ptid);
3472 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
3473 && ecs->event_thread->trap_expected
3474 && gdbarch_single_step_through_delay_p (gdbarch)
3475 && currently_stepping (ecs->event_thread))
3477 /* We're trying to step off a breakpoint. Turns out that we're
3478 also on an instruction that needs to be stepped multiple
3479 times before it's been fully executing. E.g., architectures
3480 with a delay slot. It needs to be stepped twice, once for
3481 the instruction and once for the delay slot. */
3482 int step_through_delay
3483 = gdbarch_single_step_through_delay (gdbarch, frame);
3484 if (debug_infrun && step_through_delay)
3485 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
3486 if (ecs->event_thread->step_range_end == 0 && step_through_delay)
3488 /* The user issued a continue when stopped at a breakpoint.
3489 Set up for another trap and get out of here. */
3490 ecs->event_thread->stepping_over_breakpoint = 1;
3494 else if (step_through_delay)
3496 /* The user issued a step when stopped at a breakpoint.
3497 Maybe we should stop, maybe we should not - the delay
3498 slot *might* correspond to a line of source. In any
3499 case, don't decide that here, just set
3500 ecs->stepping_over_breakpoint, making sure we
3501 single-step again before breakpoints are re-inserted. */
3502 ecs->event_thread->stepping_over_breakpoint = 1;
3506 /* Look at the cause of the stop, and decide what to do.
3507 The alternatives are:
3508 1) stop_stepping and return; to really stop and return to the debugger,
3509 2) keep_going and return to start up again
3510 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
3511 3) set ecs->random_signal to 1, and the decision between 1 and 2
3512 will be made according to the signal handling tables. */
3514 /* First, distinguish signals caused by the debugger from signals
3515 that have to do with the program's own actions. Note that
3516 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3517 on the operating system version. Here we detect when a SIGILL or
3518 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3519 something similar for SIGSEGV, since a SIGSEGV will be generated
3520 when we're trying to execute a breakpoint instruction on a
3521 non-executable stack. This happens for call dummy breakpoints
3522 for architectures like SPARC that place call dummies on the
3525 If we're doing a displaced step past a breakpoint, then the
3526 breakpoint is always inserted at the original instruction;
3527 non-standard signals can't be explained by the breakpoint. */
3528 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
3529 || (! ecs->event_thread->trap_expected
3530 && breakpoint_inserted_here_p (get_regcache_aspace (get_current_regcache ()),
3532 && (ecs->event_thread->stop_signal == TARGET_SIGNAL_ILL
3533 || ecs->event_thread->stop_signal == TARGET_SIGNAL_SEGV
3534 || ecs->event_thread->stop_signal == TARGET_SIGNAL_EMT))
3535 || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP
3536 || stop_soon == STOP_QUIETLY_REMOTE)
3538 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
3541 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
3542 stop_print_frame = 0;
3543 stop_stepping (ecs);
3547 /* This is originated from start_remote(), start_inferior() and
3548 shared libraries hook functions. */
3549 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
3552 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
3553 stop_stepping (ecs);
3557 /* This originates from attach_command(). We need to overwrite
3558 the stop_signal here, because some kernels don't ignore a
3559 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3560 See more comments in inferior.h. On the other hand, if we
3561 get a non-SIGSTOP, report it to the user - assume the backend
3562 will handle the SIGSTOP if it should show up later.
3564 Also consider that the attach is complete when we see a
3565 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3566 target extended-remote report it instead of a SIGSTOP
3567 (e.g. gdbserver). We already rely on SIGTRAP being our
3568 signal, so this is no exception.
3570 Also consider that the attach is complete when we see a
3571 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3572 the target to stop all threads of the inferior, in case the
3573 low level attach operation doesn't stop them implicitly. If
3574 they weren't stopped implicitly, then the stub will report a
3575 TARGET_SIGNAL_0, meaning: stopped for no particular reason
3576 other than GDB's request. */
3577 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
3578 && (ecs->event_thread->stop_signal == TARGET_SIGNAL_STOP
3579 || ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
3580 || ecs->event_thread->stop_signal == TARGET_SIGNAL_0))
3582 stop_stepping (ecs);
3583 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
3587 /* See if there is a breakpoint at the current PC. */
3588 ecs->event_thread->stop_bpstat
3589 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3590 stop_pc, ecs->ptid);
3592 /* Following in case break condition called a
3594 stop_print_frame = 1;
3596 /* This is where we handle "moribund" watchpoints. Unlike
3597 software breakpoints traps, hardware watchpoint traps are
3598 always distinguishable from random traps. If no high-level
3599 watchpoint is associated with the reported stop data address
3600 anymore, then the bpstat does not explain the signal ---
3601 simply make sure to ignore it if `stopped_by_watchpoint' is
3605 && ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
3606 && !bpstat_explains_signal (ecs->event_thread->stop_bpstat)
3607 && stopped_by_watchpoint)
3608 fprintf_unfiltered (gdb_stdlog, "\
3609 infrun: no user watchpoint explains watchpoint SIGTRAP, ignoring\n");
3611 /* NOTE: cagney/2003-03-29: These two checks for a random signal
3612 at one stage in the past included checks for an inferior
3613 function call's call dummy's return breakpoint. The original
3614 comment, that went with the test, read:
3616 ``End of a stack dummy. Some systems (e.g. Sony news) give
3617 another signal besides SIGTRAP, so check here as well as
3620 If someone ever tries to get call dummys on a
3621 non-executable stack to work (where the target would stop
3622 with something like a SIGSEGV), then those tests might need
3623 to be re-instated. Given, however, that the tests were only
3624 enabled when momentary breakpoints were not being used, I
3625 suspect that it won't be the case.
3627 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
3628 be necessary for call dummies on a non-executable stack on
3631 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
3633 = !(bpstat_explains_signal (ecs->event_thread->stop_bpstat)
3634 || stopped_by_watchpoint
3635 || ecs->event_thread->trap_expected
3636 || (ecs->event_thread->step_range_end
3637 && ecs->event_thread->step_resume_breakpoint == NULL));
3640 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
3641 if (!ecs->random_signal)
3642 ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
3646 /* When we reach this point, we've pretty much decided
3647 that the reason for stopping must've been a random
3648 (unexpected) signal. */
3651 ecs->random_signal = 1;
3653 process_event_stop_test:
3655 /* Re-fetch current thread's frame in case we did a
3656 "goto process_event_stop_test" above. */
3657 frame = get_current_frame ();
3658 gdbarch = get_frame_arch (frame);
3660 /* For the program's own signals, act according to
3661 the signal handling tables. */
3663 if (ecs->random_signal)
3665 /* Signal not for debugging purposes. */
3669 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
3670 ecs->event_thread->stop_signal);
3672 stopped_by_random_signal = 1;
3674 if (signal_print[ecs->event_thread->stop_signal])
3677 target_terminal_ours_for_output ();
3678 print_stop_reason (SIGNAL_RECEIVED, ecs->event_thread->stop_signal);
3680 /* Always stop on signals if we're either just gaining control
3681 of the program, or the user explicitly requested this thread
3682 to remain stopped. */
3683 if (stop_soon != NO_STOP_QUIETLY
3684 || ecs->event_thread->stop_requested
3685 || signal_stop_state (ecs->event_thread->stop_signal))
3687 stop_stepping (ecs);
3690 /* If not going to stop, give terminal back
3691 if we took it away. */
3693 target_terminal_inferior ();
3695 /* Clear the signal if it should not be passed. */
3696 if (signal_program[ecs->event_thread->stop_signal] == 0)
3697 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
3699 if (ecs->event_thread->prev_pc == stop_pc
3700 && ecs->event_thread->trap_expected
3701 && ecs->event_thread->step_resume_breakpoint == NULL)
3703 /* We were just starting a new sequence, attempting to
3704 single-step off of a breakpoint and expecting a SIGTRAP.
3705 Instead this signal arrives. This signal will take us out
3706 of the stepping range so GDB needs to remember to, when
3707 the signal handler returns, resume stepping off that
3709 /* To simplify things, "continue" is forced to use the same
3710 code paths as single-step - set a breakpoint at the
3711 signal return address and then, once hit, step off that
3714 fprintf_unfiltered (gdb_stdlog,
3715 "infrun: signal arrived while stepping over "
3718 insert_step_resume_breakpoint_at_frame (frame);
3719 ecs->event_thread->step_after_step_resume_breakpoint = 1;
3724 if (ecs->event_thread->step_range_end != 0
3725 && ecs->event_thread->stop_signal != TARGET_SIGNAL_0
3726 && (ecs->event_thread->step_range_start <= stop_pc
3727 && stop_pc < ecs->event_thread->step_range_end)
3728 && frame_id_eq (get_stack_frame_id (frame),
3729 ecs->event_thread->step_stack_frame_id)
3730 && ecs->event_thread->step_resume_breakpoint == NULL)
3732 /* The inferior is about to take a signal that will take it
3733 out of the single step range. Set a breakpoint at the
3734 current PC (which is presumably where the signal handler
3735 will eventually return) and then allow the inferior to
3738 Note that this is only needed for a signal delivered
3739 while in the single-step range. Nested signals aren't a
3740 problem as they eventually all return. */
3742 fprintf_unfiltered (gdb_stdlog,
3743 "infrun: signal may take us out of "
3744 "single-step range\n");
3746 insert_step_resume_breakpoint_at_frame (frame);
3751 /* Note: step_resume_breakpoint may be non-NULL. This occures
3752 when either there's a nested signal, or when there's a
3753 pending signal enabled just as the signal handler returns
3754 (leaving the inferior at the step-resume-breakpoint without
3755 actually executing it). Either way continue until the
3756 breakpoint is really hit. */
3761 /* Handle cases caused by hitting a breakpoint. */
3763 CORE_ADDR jmp_buf_pc;
3764 struct bpstat_what what;
3766 what = bpstat_what (ecs->event_thread->stop_bpstat);
3768 if (what.call_dummy)
3770 stop_stack_dummy = 1;
3773 switch (what.main_action)
3775 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
3776 /* If we hit the breakpoint at longjmp while stepping, we
3777 install a momentary breakpoint at the target of the
3781 fprintf_unfiltered (gdb_stdlog,
3782 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
3784 ecs->event_thread->stepping_over_breakpoint = 1;
3786 if (!gdbarch_get_longjmp_target_p (gdbarch)
3787 || !gdbarch_get_longjmp_target (gdbarch, frame, &jmp_buf_pc))
3790 fprintf_unfiltered (gdb_stdlog, "\
3791 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
3796 /* We're going to replace the current step-resume breakpoint
3797 with a longjmp-resume breakpoint. */
3798 delete_step_resume_breakpoint (ecs->event_thread);
3800 /* Insert a breakpoint at resume address. */
3801 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
3806 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
3808 fprintf_unfiltered (gdb_stdlog,
3809 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
3811 gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
3812 delete_step_resume_breakpoint (ecs->event_thread);
3814 ecs->event_thread->stop_step = 1;
3815 print_stop_reason (END_STEPPING_RANGE, 0);
3816 stop_stepping (ecs);
3819 case BPSTAT_WHAT_SINGLE:
3821 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
3822 ecs->event_thread->stepping_over_breakpoint = 1;
3823 /* Still need to check other stuff, at least the case
3824 where we are stepping and step out of the right range. */
3827 case BPSTAT_WHAT_STOP_NOISY:
3829 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
3830 stop_print_frame = 1;
3832 /* We are about to nuke the step_resume_breakpointt via the
3833 cleanup chain, so no need to worry about it here. */
3835 stop_stepping (ecs);
3838 case BPSTAT_WHAT_STOP_SILENT:
3840 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
3841 stop_print_frame = 0;
3843 /* We are about to nuke the step_resume_breakpoin via the
3844 cleanup chain, so no need to worry about it here. */
3846 stop_stepping (ecs);
3849 case BPSTAT_WHAT_STEP_RESUME:
3851 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
3853 delete_step_resume_breakpoint (ecs->event_thread);
3854 if (ecs->event_thread->step_after_step_resume_breakpoint)
3856 /* Back when the step-resume breakpoint was inserted, we
3857 were trying to single-step off a breakpoint. Go back
3859 ecs->event_thread->step_after_step_resume_breakpoint = 0;
3860 ecs->event_thread->stepping_over_breakpoint = 1;
3864 if (stop_pc == ecs->stop_func_start
3865 && execution_direction == EXEC_REVERSE)
3867 /* We are stepping over a function call in reverse, and
3868 just hit the step-resume breakpoint at the start
3869 address of the function. Go back to single-stepping,
3870 which should take us back to the function call. */
3871 ecs->event_thread->stepping_over_breakpoint = 1;
3877 case BPSTAT_WHAT_CHECK_SHLIBS:
3880 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
3882 /* Check for any newly added shared libraries if we're
3883 supposed to be adding them automatically. Switch
3884 terminal for any messages produced by
3885 breakpoint_re_set. */
3886 target_terminal_ours_for_output ();
3887 /* NOTE: cagney/2003-11-25: Make certain that the target
3888 stack's section table is kept up-to-date. Architectures,
3889 (e.g., PPC64), use the section table to perform
3890 operations such as address => section name and hence
3891 require the table to contain all sections (including
3892 those found in shared libraries). */
3894 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
3896 solib_add (NULL, 0, ¤t_target, auto_solib_add);
3898 target_terminal_inferior ();
3900 /* If requested, stop when the dynamic linker notifies
3901 gdb of events. This allows the user to get control
3902 and place breakpoints in initializer routines for
3903 dynamically loaded objects (among other things). */
3904 if (stop_on_solib_events || stop_stack_dummy)
3906 stop_stepping (ecs);
3911 /* We want to step over this breakpoint, then keep going. */
3912 ecs->event_thread->stepping_over_breakpoint = 1;
3918 case BPSTAT_WHAT_CHECK_JIT:
3920 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_JIT\n");
3922 /* Switch terminal for any messages produced by breakpoint_re_set. */
3923 target_terminal_ours_for_output ();
3925 jit_event_handler (gdbarch);
3927 target_terminal_inferior ();
3929 /* We want to step over this breakpoint, then keep going. */
3930 ecs->event_thread->stepping_over_breakpoint = 1;
3934 case BPSTAT_WHAT_LAST:
3935 /* Not a real code, but listed here to shut up gcc -Wall. */
3937 case BPSTAT_WHAT_KEEP_CHECKING:
3942 /* We come here if we hit a breakpoint but should not
3943 stop for it. Possibly we also were stepping
3944 and should stop for that. So fall through and
3945 test for stepping. But, if not stepping,
3948 /* In all-stop mode, if we're currently stepping but have stopped in
3949 some other thread, we need to switch back to the stepped thread. */
3952 struct thread_info *tp;
3953 tp = iterate_over_threads (currently_stepping_or_nexting_callback,
3957 /* However, if the current thread is blocked on some internal
3958 breakpoint, and we simply need to step over that breakpoint
3959 to get it going again, do that first. */
3960 if ((ecs->event_thread->trap_expected
3961 && ecs->event_thread->stop_signal != TARGET_SIGNAL_TRAP)
3962 || ecs->event_thread->stepping_over_breakpoint)
3968 /* If the stepping thread exited, then don't try to switch
3969 back and resume it, which could fail in several different
3970 ways depending on the target. Instead, just keep going.
3972 We can find a stepping dead thread in the thread list in
3975 - The target supports thread exit events, and when the
3976 target tries to delete the thread from the thread list,
3977 inferior_ptid pointed at the exiting thread. In such
3978 case, calling delete_thread does not really remove the
3979 thread from the list; instead, the thread is left listed,
3980 with 'exited' state.
3982 - The target's debug interface does not support thread
3983 exit events, and so we have no idea whatsoever if the
3984 previously stepping thread is still alive. For that
3985 reason, we need to synchronously query the target
3987 if (is_exited (tp->ptid)
3988 || !target_thread_alive (tp->ptid))
3991 fprintf_unfiltered (gdb_stdlog, "\
3992 infrun: not switching back to stepped thread, it has vanished\n");
3994 delete_thread (tp->ptid);
3999 /* Otherwise, we no longer expect a trap in the current thread.
4000 Clear the trap_expected flag before switching back -- this is
4001 what keep_going would do as well, if we called it. */
4002 ecs->event_thread->trap_expected = 0;
4005 fprintf_unfiltered (gdb_stdlog,
4006 "infrun: switching back to stepped thread\n");
4008 ecs->event_thread = tp;
4009 ecs->ptid = tp->ptid;
4010 context_switch (ecs->ptid);
4016 /* Are we stepping to get the inferior out of the dynamic linker's
4017 hook (and possibly the dld itself) after catching a shlib
4019 if (ecs->event_thread->stepping_through_solib_after_catch)
4021 #if defined(SOLIB_ADD)
4022 /* Have we reached our destination? If not, keep going. */
4023 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
4026 fprintf_unfiltered (gdb_stdlog, "infrun: stepping in dynamic linker\n");
4027 ecs->event_thread->stepping_over_breakpoint = 1;
4033 fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n");
4034 /* Else, stop and report the catchpoint(s) whose triggering
4035 caused us to begin stepping. */
4036 ecs->event_thread->stepping_through_solib_after_catch = 0;
4037 bpstat_clear (&ecs->event_thread->stop_bpstat);
4038 ecs->event_thread->stop_bpstat
4039 = bpstat_copy (ecs->event_thread->stepping_through_solib_catchpoints);
4040 bpstat_clear (&ecs->event_thread->stepping_through_solib_catchpoints);
4041 stop_print_frame = 1;
4042 stop_stepping (ecs);
4046 if (ecs->event_thread->step_resume_breakpoint)
4049 fprintf_unfiltered (gdb_stdlog,
4050 "infrun: step-resume breakpoint is inserted\n");
4052 /* Having a step-resume breakpoint overrides anything
4053 else having to do with stepping commands until
4054 that breakpoint is reached. */
4059 if (ecs->event_thread->step_range_end == 0)
4062 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
4063 /* Likewise if we aren't even stepping. */
4068 /* If stepping through a line, keep going if still within it.
4070 Note that step_range_end is the address of the first instruction
4071 beyond the step range, and NOT the address of the last instruction
4074 Note also that during reverse execution, we may be stepping
4075 through a function epilogue and therefore must detect when
4076 the current-frame changes in the middle of a line. */
4078 if (stop_pc >= ecs->event_thread->step_range_start
4079 && stop_pc < ecs->event_thread->step_range_end
4080 && (execution_direction != EXEC_REVERSE
4081 || frame_id_eq (get_frame_id (frame),
4082 ecs->event_thread->step_frame_id)))
4086 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
4087 paddress (gdbarch, ecs->event_thread->step_range_start),
4088 paddress (gdbarch, ecs->event_thread->step_range_end));
4090 /* When stepping backward, stop at beginning of line range
4091 (unless it's the function entry point, in which case
4092 keep going back to the call point). */
4093 if (stop_pc == ecs->event_thread->step_range_start
4094 && stop_pc != ecs->stop_func_start
4095 && execution_direction == EXEC_REVERSE)
4097 ecs->event_thread->stop_step = 1;
4098 print_stop_reason (END_STEPPING_RANGE, 0);
4099 stop_stepping (ecs);
4107 /* We stepped out of the stepping range. */
4109 /* If we are stepping at the source level and entered the runtime
4110 loader dynamic symbol resolution code...
4112 EXEC_FORWARD: we keep on single stepping until we exit the run
4113 time loader code and reach the callee's address.
4115 EXEC_REVERSE: we've already executed the callee (backward), and
4116 the runtime loader code is handled just like any other
4117 undebuggable function call. Now we need only keep stepping
4118 backward through the trampoline code, and that's handled further
4119 down, so there is nothing for us to do here. */
4121 if (execution_direction != EXEC_REVERSE
4122 && ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
4123 && in_solib_dynsym_resolve_code (stop_pc))
4125 CORE_ADDR pc_after_resolver =
4126 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
4129 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into dynsym resolve code\n");
4131 if (pc_after_resolver)
4133 /* Set up a step-resume breakpoint at the address
4134 indicated by SKIP_SOLIB_RESOLVER. */
4135 struct symtab_and_line sr_sal;
4137 sr_sal.pc = pc_after_resolver;
4138 sr_sal.pspace = get_frame_program_space (frame);
4140 insert_step_resume_breakpoint_at_sal (gdbarch,
4141 sr_sal, null_frame_id);
4148 if (ecs->event_thread->step_range_end != 1
4149 && (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
4150 || ecs->event_thread->step_over_calls == STEP_OVER_ALL)
4151 && get_frame_type (frame) == SIGTRAMP_FRAME)
4154 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into signal trampoline\n");
4155 /* The inferior, while doing a "step" or "next", has ended up in
4156 a signal trampoline (either by a signal being delivered or by
4157 the signal handler returning). Just single-step until the
4158 inferior leaves the trampoline (either by calling the handler
4164 /* Check for subroutine calls. The check for the current frame
4165 equalling the step ID is not necessary - the check of the
4166 previous frame's ID is sufficient - but it is a common case and
4167 cheaper than checking the previous frame's ID.
4169 NOTE: frame_id_eq will never report two invalid frame IDs as
4170 being equal, so to get into this block, both the current and
4171 previous frame must have valid frame IDs. */
4172 /* The outer_frame_id check is a heuristic to detect stepping
4173 through startup code. If we step over an instruction which
4174 sets the stack pointer from an invalid value to a valid value,
4175 we may detect that as a subroutine call from the mythical
4176 "outermost" function. This could be fixed by marking
4177 outermost frames as !stack_p,code_p,special_p. Then the
4178 initial outermost frame, before sp was valid, would
4179 have code_addr == &_start. See the commend in frame_id_eq
4181 if (!frame_id_eq (get_stack_frame_id (frame),
4182 ecs->event_thread->step_stack_frame_id)
4183 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4184 ecs->event_thread->step_stack_frame_id)
4185 && (!frame_id_eq (ecs->event_thread->step_stack_frame_id,
4187 || step_start_function != find_pc_function (stop_pc))))
4189 CORE_ADDR real_stop_pc;
4192 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
4194 if ((ecs->event_thread->step_over_calls == STEP_OVER_NONE)
4195 || ((ecs->event_thread->step_range_end == 1)
4196 && in_prologue (gdbarch, ecs->event_thread->prev_pc,
4197 ecs->stop_func_start)))
4199 /* I presume that step_over_calls is only 0 when we're
4200 supposed to be stepping at the assembly language level
4201 ("stepi"). Just stop. */
4202 /* Also, maybe we just did a "nexti" inside a prolog, so we
4203 thought it was a subroutine call but it was not. Stop as
4205 /* And this works the same backward as frontward. MVS */
4206 ecs->event_thread->stop_step = 1;
4207 print_stop_reason (END_STEPPING_RANGE, 0);
4208 stop_stepping (ecs);
4212 /* Reverse stepping through solib trampolines. */
4214 if (execution_direction == EXEC_REVERSE
4215 && ecs->event_thread->step_over_calls != STEP_OVER_NONE
4216 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4217 || (ecs->stop_func_start == 0
4218 && in_solib_dynsym_resolve_code (stop_pc))))
4220 /* Any solib trampoline code can be handled in reverse
4221 by simply continuing to single-step. We have already
4222 executed the solib function (backwards), and a few
4223 steps will take us back through the trampoline to the
4229 if (ecs->event_thread->step_over_calls == STEP_OVER_ALL)
4231 /* We're doing a "next".
4233 Normal (forward) execution: set a breakpoint at the
4234 callee's return address (the address at which the caller
4237 Reverse (backward) execution. set the step-resume
4238 breakpoint at the start of the function that we just
4239 stepped into (backwards), and continue to there. When we
4240 get there, we'll need to single-step back to the caller. */
4242 if (execution_direction == EXEC_REVERSE)
4244 struct symtab_and_line sr_sal;
4246 /* Normal function call return (static or dynamic). */
4248 sr_sal.pc = ecs->stop_func_start;
4249 sr_sal.pspace = get_frame_program_space (frame);
4250 insert_step_resume_breakpoint_at_sal (gdbarch,
4251 sr_sal, null_frame_id);
4254 insert_step_resume_breakpoint_at_caller (frame);
4260 /* If we are in a function call trampoline (a stub between the
4261 calling routine and the real function), locate the real
4262 function. That's what tells us (a) whether we want to step
4263 into it at all, and (b) what prologue we want to run to the
4264 end of, if we do step into it. */
4265 real_stop_pc = skip_language_trampoline (frame, stop_pc);
4266 if (real_stop_pc == 0)
4267 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4268 if (real_stop_pc != 0)
4269 ecs->stop_func_start = real_stop_pc;
4271 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
4273 struct symtab_and_line sr_sal;
4275 sr_sal.pc = ecs->stop_func_start;
4276 sr_sal.pspace = get_frame_program_space (frame);
4278 insert_step_resume_breakpoint_at_sal (gdbarch,
4279 sr_sal, null_frame_id);
4284 /* If we have line number information for the function we are
4285 thinking of stepping into, step into it.
4287 If there are several symtabs at that PC (e.g. with include
4288 files), just want to know whether *any* of them have line
4289 numbers. find_pc_line handles this. */
4291 struct symtab_and_line tmp_sal;
4293 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
4294 tmp_sal.pspace = get_frame_program_space (frame);
4295 if (tmp_sal.line != 0)
4297 if (execution_direction == EXEC_REVERSE)
4298 handle_step_into_function_backward (gdbarch, ecs);
4300 handle_step_into_function (gdbarch, ecs);
4305 /* If we have no line number and the step-stop-if-no-debug is
4306 set, we stop the step so that the user has a chance to switch
4307 in assembly mode. */
4308 if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
4309 && step_stop_if_no_debug)
4311 ecs->event_thread->stop_step = 1;
4312 print_stop_reason (END_STEPPING_RANGE, 0);
4313 stop_stepping (ecs);
4317 if (execution_direction == EXEC_REVERSE)
4319 /* Set a breakpoint at callee's start address.
4320 From there we can step once and be back in the caller. */
4321 struct symtab_and_line sr_sal;
4323 sr_sal.pc = ecs->stop_func_start;
4324 sr_sal.pspace = get_frame_program_space (frame);
4325 insert_step_resume_breakpoint_at_sal (gdbarch,
4326 sr_sal, null_frame_id);
4329 /* Set a breakpoint at callee's return address (the address
4330 at which the caller will resume). */
4331 insert_step_resume_breakpoint_at_caller (frame);
4337 /* Reverse stepping through solib trampolines. */
4339 if (execution_direction == EXEC_REVERSE
4340 && ecs->event_thread->step_over_calls != STEP_OVER_NONE)
4342 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4343 || (ecs->stop_func_start == 0
4344 && in_solib_dynsym_resolve_code (stop_pc)))
4346 /* Any solib trampoline code can be handled in reverse
4347 by simply continuing to single-step. We have already
4348 executed the solib function (backwards), and a few
4349 steps will take us back through the trampoline to the
4354 else if (in_solib_dynsym_resolve_code (stop_pc))
4356 /* Stepped backward into the solib dynsym resolver.
4357 Set a breakpoint at its start and continue, then
4358 one more step will take us out. */
4359 struct symtab_and_line sr_sal;
4361 sr_sal.pc = ecs->stop_func_start;
4362 sr_sal.pspace = get_frame_program_space (frame);
4363 insert_step_resume_breakpoint_at_sal (gdbarch,
4364 sr_sal, null_frame_id);
4370 /* If we're in the return path from a shared library trampoline,
4371 we want to proceed through the trampoline when stepping. */
4372 if (gdbarch_in_solib_return_trampoline (gdbarch,
4373 stop_pc, ecs->stop_func_name))
4375 /* Determine where this trampoline returns. */
4376 CORE_ADDR real_stop_pc;
4377 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4380 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into solib return tramp\n");
4382 /* Only proceed through if we know where it's going. */
4385 /* And put the step-breakpoint there and go until there. */
4386 struct symtab_and_line sr_sal;
4388 init_sal (&sr_sal); /* initialize to zeroes */
4389 sr_sal.pc = real_stop_pc;
4390 sr_sal.section = find_pc_overlay (sr_sal.pc);
4391 sr_sal.pspace = get_frame_program_space (frame);
4393 /* Do not specify what the fp should be when we stop since
4394 on some machines the prologue is where the new fp value
4396 insert_step_resume_breakpoint_at_sal (gdbarch,
4397 sr_sal, null_frame_id);
4399 /* Restart without fiddling with the step ranges or
4406 stop_pc_sal = find_pc_line (stop_pc, 0);
4408 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4409 the trampoline processing logic, however, there are some trampolines
4410 that have no names, so we should do trampoline handling first. */
4411 if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
4412 && ecs->stop_func_name == NULL
4413 && stop_pc_sal.line == 0)
4416 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into undebuggable function\n");
4418 /* The inferior just stepped into, or returned to, an
4419 undebuggable function (where there is no debugging information
4420 and no line number corresponding to the address where the
4421 inferior stopped). Since we want to skip this kind of code,
4422 we keep going until the inferior returns from this
4423 function - unless the user has asked us not to (via
4424 set step-mode) or we no longer know how to get back
4425 to the call site. */
4426 if (step_stop_if_no_debug
4427 || !frame_id_p (frame_unwind_caller_id (frame)))
4429 /* If we have no line number and the step-stop-if-no-debug
4430 is set, we stop the step so that the user has a chance to
4431 switch in assembly mode. */
4432 ecs->event_thread->stop_step = 1;
4433 print_stop_reason (END_STEPPING_RANGE, 0);
4434 stop_stepping (ecs);
4439 /* Set a breakpoint at callee's return address (the address
4440 at which the caller will resume). */
4441 insert_step_resume_breakpoint_at_caller (frame);
4447 if (ecs->event_thread->step_range_end == 1)
4449 /* It is stepi or nexti. We always want to stop stepping after
4452 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
4453 ecs->event_thread->stop_step = 1;
4454 print_stop_reason (END_STEPPING_RANGE, 0);
4455 stop_stepping (ecs);
4459 if (stop_pc_sal.line == 0)
4461 /* We have no line number information. That means to stop
4462 stepping (does this always happen right after one instruction,
4463 when we do "s" in a function with no line numbers,
4464 or can this happen as a result of a return or longjmp?). */
4466 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
4467 ecs->event_thread->stop_step = 1;
4468 print_stop_reason (END_STEPPING_RANGE, 0);
4469 stop_stepping (ecs);
4473 /* Look for "calls" to inlined functions, part one. If the inline
4474 frame machinery detected some skipped call sites, we have entered
4475 a new inline function. */
4477 if (frame_id_eq (get_frame_id (get_current_frame ()),
4478 ecs->event_thread->step_frame_id)
4479 && inline_skipped_frames (ecs->ptid))
4481 struct symtab_and_line call_sal;
4484 fprintf_unfiltered (gdb_stdlog,
4485 "infrun: stepped into inlined function\n");
4487 find_frame_sal (get_current_frame (), &call_sal);
4489 if (ecs->event_thread->step_over_calls != STEP_OVER_ALL)
4491 /* For "step", we're going to stop. But if the call site
4492 for this inlined function is on the same source line as
4493 we were previously stepping, go down into the function
4494 first. Otherwise stop at the call site. */
4496 if (call_sal.line == ecs->event_thread->current_line
4497 && call_sal.symtab == ecs->event_thread->current_symtab)
4498 step_into_inline_frame (ecs->ptid);
4500 ecs->event_thread->stop_step = 1;
4501 print_stop_reason (END_STEPPING_RANGE, 0);
4502 stop_stepping (ecs);
4507 /* For "next", we should stop at the call site if it is on a
4508 different source line. Otherwise continue through the
4509 inlined function. */
4510 if (call_sal.line == ecs->event_thread->current_line
4511 && call_sal.symtab == ecs->event_thread->current_symtab)
4515 ecs->event_thread->stop_step = 1;
4516 print_stop_reason (END_STEPPING_RANGE, 0);
4517 stop_stepping (ecs);
4523 /* Look for "calls" to inlined functions, part two. If we are still
4524 in the same real function we were stepping through, but we have
4525 to go further up to find the exact frame ID, we are stepping
4526 through a more inlined call beyond its call site. */
4528 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
4529 && !frame_id_eq (get_frame_id (get_current_frame ()),
4530 ecs->event_thread->step_frame_id)
4531 && stepped_in_from (get_current_frame (),
4532 ecs->event_thread->step_frame_id))
4535 fprintf_unfiltered (gdb_stdlog,
4536 "infrun: stepping through inlined function\n");
4538 if (ecs->event_thread->step_over_calls == STEP_OVER_ALL)
4542 ecs->event_thread->stop_step = 1;
4543 print_stop_reason (END_STEPPING_RANGE, 0);
4544 stop_stepping (ecs);
4549 if ((stop_pc == stop_pc_sal.pc)
4550 && (ecs->event_thread->current_line != stop_pc_sal.line
4551 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
4553 /* We are at the start of a different line. So stop. Note that
4554 we don't stop if we step into the middle of a different line.
4555 That is said to make things like for (;;) statements work
4558 fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different line\n");
4559 ecs->event_thread->stop_step = 1;
4560 print_stop_reason (END_STEPPING_RANGE, 0);
4561 stop_stepping (ecs);
4565 /* We aren't done stepping.
4567 Optimize by setting the stepping range to the line.
4568 (We might not be in the original line, but if we entered a
4569 new line in mid-statement, we continue stepping. This makes
4570 things like for(;;) statements work better.) */
4572 ecs->event_thread->step_range_start = stop_pc_sal.pc;
4573 ecs->event_thread->step_range_end = stop_pc_sal.end;
4574 set_step_info (frame, stop_pc_sal);
4577 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
4581 /* Is thread TP in the middle of single-stepping? */
4584 currently_stepping (struct thread_info *tp)
4586 return ((tp->step_range_end && tp->step_resume_breakpoint == NULL)
4587 || tp->trap_expected
4588 || tp->stepping_through_solib_after_catch
4589 || bpstat_should_step ());
4592 /* Returns true if any thread *but* the one passed in "data" is in the
4593 middle of stepping or of handling a "next". */
4596 currently_stepping_or_nexting_callback (struct thread_info *tp, void *data)
4601 return (tp->step_range_end
4602 || tp->trap_expected
4603 || tp->stepping_through_solib_after_catch);
4606 /* Inferior has stepped into a subroutine call with source code that
4607 we should not step over. Do step to the first line of code in
4611 handle_step_into_function (struct gdbarch *gdbarch,
4612 struct execution_control_state *ecs)
4615 struct symtab_and_line stop_func_sal, sr_sal;
4617 s = find_pc_symtab (stop_pc);
4618 if (s && s->language != language_asm)
4619 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
4620 ecs->stop_func_start);
4622 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
4623 /* Use the step_resume_break to step until the end of the prologue,
4624 even if that involves jumps (as it seems to on the vax under
4626 /* If the prologue ends in the middle of a source line, continue to
4627 the end of that source line (if it is still within the function).
4628 Otherwise, just go to end of prologue. */
4629 if (stop_func_sal.end
4630 && stop_func_sal.pc != ecs->stop_func_start
4631 && stop_func_sal.end < ecs->stop_func_end)
4632 ecs->stop_func_start = stop_func_sal.end;
4634 /* Architectures which require breakpoint adjustment might not be able
4635 to place a breakpoint at the computed address. If so, the test
4636 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
4637 ecs->stop_func_start to an address at which a breakpoint may be
4638 legitimately placed.
4640 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
4641 made, GDB will enter an infinite loop when stepping through
4642 optimized code consisting of VLIW instructions which contain
4643 subinstructions corresponding to different source lines. On
4644 FR-V, it's not permitted to place a breakpoint on any but the
4645 first subinstruction of a VLIW instruction. When a breakpoint is
4646 set, GDB will adjust the breakpoint address to the beginning of
4647 the VLIW instruction. Thus, we need to make the corresponding
4648 adjustment here when computing the stop address. */
4650 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
4652 ecs->stop_func_start
4653 = gdbarch_adjust_breakpoint_address (gdbarch,
4654 ecs->stop_func_start);
4657 if (ecs->stop_func_start == stop_pc)
4659 /* We are already there: stop now. */
4660 ecs->event_thread->stop_step = 1;
4661 print_stop_reason (END_STEPPING_RANGE, 0);
4662 stop_stepping (ecs);
4667 /* Put the step-breakpoint there and go until there. */
4668 init_sal (&sr_sal); /* initialize to zeroes */
4669 sr_sal.pc = ecs->stop_func_start;
4670 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
4671 sr_sal.pspace = get_frame_program_space (get_current_frame ());
4673 /* Do not specify what the fp should be when we stop since on
4674 some machines the prologue is where the new fp value is
4676 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
4678 /* And make sure stepping stops right away then. */
4679 ecs->event_thread->step_range_end = ecs->event_thread->step_range_start;
4684 /* Inferior has stepped backward into a subroutine call with source
4685 code that we should not step over. Do step to the beginning of the
4686 last line of code in it. */
4689 handle_step_into_function_backward (struct gdbarch *gdbarch,
4690 struct execution_control_state *ecs)
4693 struct symtab_and_line stop_func_sal, sr_sal;
4695 s = find_pc_symtab (stop_pc);
4696 if (s && s->language != language_asm)
4697 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
4698 ecs->stop_func_start);
4700 stop_func_sal = find_pc_line (stop_pc, 0);
4702 /* OK, we're just going to keep stepping here. */
4703 if (stop_func_sal.pc == stop_pc)
4705 /* We're there already. Just stop stepping now. */
4706 ecs->event_thread->stop_step = 1;
4707 print_stop_reason (END_STEPPING_RANGE, 0);
4708 stop_stepping (ecs);
4712 /* Else just reset the step range and keep going.
4713 No step-resume breakpoint, they don't work for
4714 epilogues, which can have multiple entry paths. */
4715 ecs->event_thread->step_range_start = stop_func_sal.pc;
4716 ecs->event_thread->step_range_end = stop_func_sal.end;
4722 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
4723 This is used to both functions and to skip over code. */
4726 insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
4727 struct symtab_and_line sr_sal,
4728 struct frame_id sr_id)
4730 /* There should never be more than one step-resume or longjmp-resume
4731 breakpoint per thread, so we should never be setting a new
4732 step_resume_breakpoint when one is already active. */
4733 gdb_assert (inferior_thread ()->step_resume_breakpoint == NULL);
4736 fprintf_unfiltered (gdb_stdlog,
4737 "infrun: inserting step-resume breakpoint at %s\n",
4738 paddress (gdbarch, sr_sal.pc));
4740 inferior_thread ()->step_resume_breakpoint
4741 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, bp_step_resume);
4744 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
4745 to skip a potential signal handler.
4747 This is called with the interrupted function's frame. The signal
4748 handler, when it returns, will resume the interrupted function at
4752 insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
4754 struct symtab_and_line sr_sal;
4755 struct gdbarch *gdbarch;
4757 gdb_assert (return_frame != NULL);
4758 init_sal (&sr_sal); /* initialize to zeros */
4760 gdbarch = get_frame_arch (return_frame);
4761 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
4762 sr_sal.section = find_pc_overlay (sr_sal.pc);
4763 sr_sal.pspace = get_frame_program_space (return_frame);
4765 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
4766 get_stack_frame_id (return_frame));
4769 /* Similar to insert_step_resume_breakpoint_at_frame, except
4770 but a breakpoint at the previous frame's PC. This is used to
4771 skip a function after stepping into it (for "next" or if the called
4772 function has no debugging information).
4774 The current function has almost always been reached by single
4775 stepping a call or return instruction. NEXT_FRAME belongs to the
4776 current function, and the breakpoint will be set at the caller's
4779 This is a separate function rather than reusing
4780 insert_step_resume_breakpoint_at_frame in order to avoid
4781 get_prev_frame, which may stop prematurely (see the implementation
4782 of frame_unwind_caller_id for an example). */
4785 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
4787 struct symtab_and_line sr_sal;
4788 struct gdbarch *gdbarch;
4790 /* We shouldn't have gotten here if we don't know where the call site
4792 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
4794 init_sal (&sr_sal); /* initialize to zeros */
4796 gdbarch = frame_unwind_caller_arch (next_frame);
4797 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
4798 frame_unwind_caller_pc (next_frame));
4799 sr_sal.section = find_pc_overlay (sr_sal.pc);
4800 sr_sal.pspace = frame_unwind_program_space (next_frame);
4802 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
4803 frame_unwind_caller_id (next_frame));
4806 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
4807 new breakpoint at the target of a jmp_buf. The handling of
4808 longjmp-resume uses the same mechanisms used for handling
4809 "step-resume" breakpoints. */
4812 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
4814 /* There should never be more than one step-resume or longjmp-resume
4815 breakpoint per thread, so we should never be setting a new
4816 longjmp_resume_breakpoint when one is already active. */
4817 gdb_assert (inferior_thread ()->step_resume_breakpoint == NULL);
4820 fprintf_unfiltered (gdb_stdlog,
4821 "infrun: inserting longjmp-resume breakpoint at %s\n",
4822 paddress (gdbarch, pc));
4824 inferior_thread ()->step_resume_breakpoint =
4825 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
4829 stop_stepping (struct execution_control_state *ecs)
4832 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
4834 /* Let callers know we don't want to wait for the inferior anymore. */
4835 ecs->wait_some_more = 0;
4838 /* This function handles various cases where we need to continue
4839 waiting for the inferior. */
4840 /* (Used to be the keep_going: label in the old wait_for_inferior) */
4843 keep_going (struct execution_control_state *ecs)
4845 /* Make sure normal_stop is called if we get a QUIT handled before
4847 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
4849 /* Save the pc before execution, to compare with pc after stop. */
4850 ecs->event_thread->prev_pc
4851 = regcache_read_pc (get_thread_regcache (ecs->ptid));
4853 /* If we did not do break;, it means we should keep running the
4854 inferior and not return to debugger. */
4856 if (ecs->event_thread->trap_expected
4857 && ecs->event_thread->stop_signal != TARGET_SIGNAL_TRAP)
4859 /* We took a signal (which we are supposed to pass through to
4860 the inferior, else we'd not get here) and we haven't yet
4861 gotten our trap. Simply continue. */
4863 discard_cleanups (old_cleanups);
4864 resume (currently_stepping (ecs->event_thread),
4865 ecs->event_thread->stop_signal);
4869 /* Either the trap was not expected, but we are continuing
4870 anyway (the user asked that this signal be passed to the
4873 The signal was SIGTRAP, e.g. it was our signal, but we
4874 decided we should resume from it.
4876 We're going to run this baby now!
4878 Note that insert_breakpoints won't try to re-insert
4879 already inserted breakpoints. Therefore, we don't
4880 care if breakpoints were already inserted, or not. */
4882 if (ecs->event_thread->stepping_over_breakpoint)
4884 struct regcache *thread_regcache = get_thread_regcache (ecs->ptid);
4885 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
4886 /* Since we can't do a displaced step, we have to remove
4887 the breakpoint while we step it. To keep things
4888 simple, we remove them all. */
4889 remove_breakpoints ();
4893 struct gdb_exception e;
4894 /* Stop stepping when inserting breakpoints
4896 TRY_CATCH (e, RETURN_MASK_ERROR)
4898 insert_breakpoints ();
4902 exception_print (gdb_stderr, e);
4903 stop_stepping (ecs);
4908 ecs->event_thread->trap_expected = ecs->event_thread->stepping_over_breakpoint;
4910 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
4911 specifies that such a signal should be delivered to the
4914 Typically, this would occure when a user is debugging a
4915 target monitor on a simulator: the target monitor sets a
4916 breakpoint; the simulator encounters this break-point and
4917 halts the simulation handing control to GDB; GDB, noteing
4918 that the break-point isn't valid, returns control back to the
4919 simulator; the simulator then delivers the hardware
4920 equivalent of a SIGNAL_TRAP to the program being debugged. */
4922 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
4923 && !signal_program[ecs->event_thread->stop_signal])
4924 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
4926 discard_cleanups (old_cleanups);
4927 resume (currently_stepping (ecs->event_thread),
4928 ecs->event_thread->stop_signal);
4931 prepare_to_wait (ecs);
4934 /* This function normally comes after a resume, before
4935 handle_inferior_event exits. It takes care of any last bits of
4936 housekeeping, and sets the all-important wait_some_more flag. */
4939 prepare_to_wait (struct execution_control_state *ecs)
4942 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
4944 /* This is the old end of the while loop. Let everybody know we
4945 want to wait for the inferior some more and get called again
4947 ecs->wait_some_more = 1;
4950 /* Print why the inferior has stopped. We always print something when
4951 the inferior exits, or receives a signal. The rest of the cases are
4952 dealt with later on in normal_stop() and print_it_typical(). Ideally
4953 there should be a call to this function from handle_inferior_event()
4954 each time stop_stepping() is called.*/
4956 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
4958 switch (stop_reason)
4960 case END_STEPPING_RANGE:
4961 /* We are done with a step/next/si/ni command. */
4962 /* For now print nothing. */
4963 /* Print a message only if not in the middle of doing a "step n"
4964 operation for n > 1 */
4965 if (!inferior_thread ()->step_multi
4966 || !inferior_thread ()->stop_step)
4967 if (ui_out_is_mi_like_p (uiout))
4970 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
4973 /* The inferior was terminated by a signal. */
4974 annotate_signalled ();
4975 if (ui_out_is_mi_like_p (uiout))
4978 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
4979 ui_out_text (uiout, "\nProgram terminated with signal ");
4980 annotate_signal_name ();
4981 ui_out_field_string (uiout, "signal-name",
4982 target_signal_to_name (stop_info));
4983 annotate_signal_name_end ();
4984 ui_out_text (uiout, ", ");
4985 annotate_signal_string ();
4986 ui_out_field_string (uiout, "signal-meaning",
4987 target_signal_to_string (stop_info));
4988 annotate_signal_string_end ();
4989 ui_out_text (uiout, ".\n");
4990 ui_out_text (uiout, "The program no longer exists.\n");
4993 /* The inferior program is finished. */
4994 annotate_exited (stop_info);
4997 if (ui_out_is_mi_like_p (uiout))
4998 ui_out_field_string (uiout, "reason",
4999 async_reason_lookup (EXEC_ASYNC_EXITED));
5000 ui_out_text (uiout, "\nProgram exited with code ");
5001 ui_out_field_fmt (uiout, "exit-code", "0%o",
5002 (unsigned int) stop_info);
5003 ui_out_text (uiout, ".\n");
5007 if (ui_out_is_mi_like_p (uiout))
5010 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
5011 ui_out_text (uiout, "\nProgram exited normally.\n");
5013 /* Support the --return-child-result option. */
5014 return_child_result_value = stop_info;
5016 case SIGNAL_RECEIVED:
5017 /* Signal received. The signal table tells us to print about
5021 if (stop_info == TARGET_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
5023 struct thread_info *t = inferior_thread ();
5025 ui_out_text (uiout, "\n[");
5026 ui_out_field_string (uiout, "thread-name",
5027 target_pid_to_str (t->ptid));
5028 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
5029 ui_out_text (uiout, " stopped");
5033 ui_out_text (uiout, "\nProgram received signal ");
5034 annotate_signal_name ();
5035 if (ui_out_is_mi_like_p (uiout))
5037 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
5038 ui_out_field_string (uiout, "signal-name",
5039 target_signal_to_name (stop_info));
5040 annotate_signal_name_end ();
5041 ui_out_text (uiout, ", ");
5042 annotate_signal_string ();
5043 ui_out_field_string (uiout, "signal-meaning",
5044 target_signal_to_string (stop_info));
5045 annotate_signal_string_end ();
5047 ui_out_text (uiout, ".\n");
5050 /* Reverse execution: target ran out of history info. */
5051 ui_out_text (uiout, "\nNo more reverse-execution history.\n");
5054 internal_error (__FILE__, __LINE__,
5055 _("print_stop_reason: unrecognized enum value"));
5061 /* Here to return control to GDB when the inferior stops for real.
5062 Print appropriate messages, remove breakpoints, give terminal our modes.
5064 STOP_PRINT_FRAME nonzero means print the executing frame
5065 (pc, function, args, file, line number and line text).
5066 BREAKPOINTS_FAILED nonzero means stop was due to error
5067 attempting to insert breakpoints. */
5072 struct target_waitstatus last;
5074 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
5076 get_last_target_status (&last_ptid, &last);
5078 /* If an exception is thrown from this point on, make sure to
5079 propagate GDB's knowledge of the executing state to the
5080 frontend/user running state. A QUIT is an easy exception to see
5081 here, so do this before any filtered output. */
5083 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
5084 else if (last.kind != TARGET_WAITKIND_SIGNALLED
5085 && last.kind != TARGET_WAITKIND_EXITED)
5086 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
5088 /* In non-stop mode, we don't want GDB to switch threads behind the
5089 user's back, to avoid races where the user is typing a command to
5090 apply to thread x, but GDB switches to thread y before the user
5091 finishes entering the command. */
5093 /* As with the notification of thread events, we want to delay
5094 notifying the user that we've switched thread context until
5095 the inferior actually stops.
5097 There's no point in saying anything if the inferior has exited.
5098 Note that SIGNALLED here means "exited with a signal", not
5099 "received a signal". */
5101 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
5102 && target_has_execution
5103 && last.kind != TARGET_WAITKIND_SIGNALLED
5104 && last.kind != TARGET_WAITKIND_EXITED)
5106 target_terminal_ours_for_output ();
5107 printf_filtered (_("[Switching to %s]\n"),
5108 target_pid_to_str (inferior_ptid));
5109 annotate_thread_changed ();
5110 previous_inferior_ptid = inferior_ptid;
5113 if (!breakpoints_always_inserted_mode () && target_has_execution)
5115 if (remove_breakpoints ())
5117 target_terminal_ours_for_output ();
5118 printf_filtered (_("\
5119 Cannot remove breakpoints because program is no longer writable.\n\
5120 Further execution is probably impossible.\n"));
5124 /* If an auto-display called a function and that got a signal,
5125 delete that auto-display to avoid an infinite recursion. */
5127 if (stopped_by_random_signal)
5128 disable_current_display ();
5130 /* Don't print a message if in the middle of doing a "step n"
5131 operation for n > 1 */
5132 if (target_has_execution
5133 && last.kind != TARGET_WAITKIND_SIGNALLED
5134 && last.kind != TARGET_WAITKIND_EXITED
5135 && inferior_thread ()->step_multi
5136 && inferior_thread ()->stop_step)
5139 target_terminal_ours ();
5141 /* Set the current source location. This will also happen if we
5142 display the frame below, but the current SAL will be incorrect
5143 during a user hook-stop function. */
5144 if (has_stack_frames () && !stop_stack_dummy)
5145 set_current_sal_from_frame (get_current_frame (), 1);
5147 /* Let the user/frontend see the threads as stopped. */
5148 do_cleanups (old_chain);
5150 /* Look up the hook_stop and run it (CLI internally handles problem
5151 of stop_command's pre-hook not existing). */
5153 catch_errors (hook_stop_stub, stop_command,
5154 "Error while running hook_stop:\n", RETURN_MASK_ALL);
5156 if (!has_stack_frames ())
5159 if (last.kind == TARGET_WAITKIND_SIGNALLED
5160 || last.kind == TARGET_WAITKIND_EXITED)
5163 /* Select innermost stack frame - i.e., current frame is frame 0,
5164 and current location is based on that.
5165 Don't do this on return from a stack dummy routine,
5166 or if the program has exited. */
5168 if (!stop_stack_dummy)
5170 select_frame (get_current_frame ());
5172 /* Print current location without a level number, if
5173 we have changed functions or hit a breakpoint.
5174 Print source line if we have one.
5175 bpstat_print() contains the logic deciding in detail
5176 what to print, based on the event(s) that just occurred. */
5178 /* If --batch-silent is enabled then there's no need to print the current
5179 source location, and to try risks causing an error message about
5180 missing source files. */
5181 if (stop_print_frame && !batch_silent)
5185 int do_frame_printing = 1;
5186 struct thread_info *tp = inferior_thread ();
5188 bpstat_ret = bpstat_print (tp->stop_bpstat);
5192 /* If we had hit a shared library event breakpoint,
5193 bpstat_print would print out this message. If we hit
5194 an OS-level shared library event, do the same
5196 if (last.kind == TARGET_WAITKIND_LOADED)
5198 printf_filtered (_("Stopped due to shared library event\n"));
5199 source_flag = SRC_LINE; /* something bogus */
5200 do_frame_printing = 0;
5204 /* FIXME: cagney/2002-12-01: Given that a frame ID does
5205 (or should) carry around the function and does (or
5206 should) use that when doing a frame comparison. */
5208 && frame_id_eq (tp->step_frame_id,
5209 get_frame_id (get_current_frame ()))
5210 && step_start_function == find_pc_function (stop_pc))
5211 source_flag = SRC_LINE; /* finished step, just print source line */
5213 source_flag = SRC_AND_LOC; /* print location and source line */
5215 case PRINT_SRC_AND_LOC:
5216 source_flag = SRC_AND_LOC; /* print location and source line */
5218 case PRINT_SRC_ONLY:
5219 source_flag = SRC_LINE;
5222 source_flag = SRC_LINE; /* something bogus */
5223 do_frame_printing = 0;
5226 internal_error (__FILE__, __LINE__, _("Unknown value."));
5229 /* The behavior of this routine with respect to the source
5231 SRC_LINE: Print only source line
5232 LOCATION: Print only location
5233 SRC_AND_LOC: Print location and source line */
5234 if (do_frame_printing)
5235 print_stack_frame (get_selected_frame (NULL), 0, source_flag);
5237 /* Display the auto-display expressions. */
5242 /* Save the function value return registers, if we care.
5243 We might be about to restore their previous contents. */
5244 if (inferior_thread ()->proceed_to_finish)
5246 /* This should not be necessary. */
5248 regcache_xfree (stop_registers);
5250 /* NB: The copy goes through to the target picking up the value of
5251 all the registers. */
5252 stop_registers = regcache_dup (get_current_regcache ());
5255 if (stop_stack_dummy)
5257 /* Pop the empty frame that contains the stack dummy.
5258 This also restores inferior state prior to the call
5259 (struct inferior_thread_state). */
5260 struct frame_info *frame = get_current_frame ();
5261 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
5263 /* frame_pop() calls reinit_frame_cache as the last thing it does
5264 which means there's currently no selected frame. We don't need
5265 to re-establish a selected frame if the dummy call returns normally,
5266 that will be done by restore_inferior_status. However, we do have
5267 to handle the case where the dummy call is returning after being
5268 stopped (e.g. the dummy call previously hit a breakpoint). We
5269 can't know which case we have so just always re-establish a
5270 selected frame here. */
5271 select_frame (get_current_frame ());
5275 annotate_stopped ();
5277 /* Suppress the stop observer if we're in the middle of:
5279 - a step n (n > 1), as there still more steps to be done.
5281 - a "finish" command, as the observer will be called in
5282 finish_command_continuation, so it can include the inferior
5283 function's return value.
5285 - calling an inferior function, as we pretend we inferior didn't
5286 run at all. The return value of the call is handled by the
5287 expression evaluator, through call_function_by_hand. */
5289 if (!target_has_execution
5290 || last.kind == TARGET_WAITKIND_SIGNALLED
5291 || last.kind == TARGET_WAITKIND_EXITED
5292 || (!inferior_thread ()->step_multi
5293 && !(inferior_thread ()->stop_bpstat
5294 && inferior_thread ()->proceed_to_finish)
5295 && !inferior_thread ()->in_infcall))
5297 if (!ptid_equal (inferior_ptid, null_ptid))
5298 observer_notify_normal_stop (inferior_thread ()->stop_bpstat,
5301 observer_notify_normal_stop (NULL, stop_print_frame);
5304 if (target_has_execution)
5306 if (last.kind != TARGET_WAITKIND_SIGNALLED
5307 && last.kind != TARGET_WAITKIND_EXITED)
5308 /* Delete the breakpoint we stopped at, if it wants to be deleted.
5309 Delete any breakpoint that is to be deleted at the next stop. */
5310 breakpoint_auto_delete (inferior_thread ()->stop_bpstat);
5313 /* Try to get rid of automatically added inferiors that are no
5314 longer needed. Keeping those around slows down things linearly.
5315 Note that this never removes the current inferior. */
5320 hook_stop_stub (void *cmd)
5322 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
5327 signal_stop_state (int signo)
5329 return signal_stop[signo];
5333 signal_print_state (int signo)
5335 return signal_print[signo];
5339 signal_pass_state (int signo)
5341 return signal_program[signo];
5345 signal_stop_update (int signo, int state)
5347 int ret = signal_stop[signo];
5348 signal_stop[signo] = state;
5353 signal_print_update (int signo, int state)
5355 int ret = signal_print[signo];
5356 signal_print[signo] = state;
5361 signal_pass_update (int signo, int state)
5363 int ret = signal_program[signo];
5364 signal_program[signo] = state;
5369 sig_print_header (void)
5371 printf_filtered (_("\
5372 Signal Stop\tPrint\tPass to program\tDescription\n"));
5376 sig_print_info (enum target_signal oursig)
5378 const char *name = target_signal_to_name (oursig);
5379 int name_padding = 13 - strlen (name);
5381 if (name_padding <= 0)
5384 printf_filtered ("%s", name);
5385 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
5386 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
5387 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
5388 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
5389 printf_filtered ("%s\n", target_signal_to_string (oursig));
5392 /* Specify how various signals in the inferior should be handled. */
5395 handle_command (char *args, int from_tty)
5398 int digits, wordlen;
5399 int sigfirst, signum, siglast;
5400 enum target_signal oursig;
5403 unsigned char *sigs;
5404 struct cleanup *old_chain;
5408 error_no_arg (_("signal to handle"));
5411 /* Allocate and zero an array of flags for which signals to handle. */
5413 nsigs = (int) TARGET_SIGNAL_LAST;
5414 sigs = (unsigned char *) alloca (nsigs);
5415 memset (sigs, 0, nsigs);
5417 /* Break the command line up into args. */
5419 argv = gdb_buildargv (args);
5420 old_chain = make_cleanup_freeargv (argv);
5422 /* Walk through the args, looking for signal oursigs, signal names, and
5423 actions. Signal numbers and signal names may be interspersed with
5424 actions, with the actions being performed for all signals cumulatively
5425 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
5427 while (*argv != NULL)
5429 wordlen = strlen (*argv);
5430 for (digits = 0; isdigit ((*argv)[digits]); digits++)
5434 sigfirst = siglast = -1;
5436 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
5438 /* Apply action to all signals except those used by the
5439 debugger. Silently skip those. */
5442 siglast = nsigs - 1;
5444 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
5446 SET_SIGS (nsigs, sigs, signal_stop);
5447 SET_SIGS (nsigs, sigs, signal_print);
5449 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
5451 UNSET_SIGS (nsigs, sigs, signal_program);
5453 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
5455 SET_SIGS (nsigs, sigs, signal_print);
5457 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
5459 SET_SIGS (nsigs, sigs, signal_program);
5461 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
5463 UNSET_SIGS (nsigs, sigs, signal_stop);
5465 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
5467 SET_SIGS (nsigs, sigs, signal_program);
5469 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
5471 UNSET_SIGS (nsigs, sigs, signal_print);
5472 UNSET_SIGS (nsigs, sigs, signal_stop);
5474 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
5476 UNSET_SIGS (nsigs, sigs, signal_program);
5478 else if (digits > 0)
5480 /* It is numeric. The numeric signal refers to our own
5481 internal signal numbering from target.h, not to host/target
5482 signal number. This is a feature; users really should be
5483 using symbolic names anyway, and the common ones like
5484 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
5486 sigfirst = siglast = (int)
5487 target_signal_from_command (atoi (*argv));
5488 if ((*argv)[digits] == '-')
5491 target_signal_from_command (atoi ((*argv) + digits + 1));
5493 if (sigfirst > siglast)
5495 /* Bet he didn't figure we'd think of this case... */
5503 oursig = target_signal_from_name (*argv);
5504 if (oursig != TARGET_SIGNAL_UNKNOWN)
5506 sigfirst = siglast = (int) oursig;
5510 /* Not a number and not a recognized flag word => complain. */
5511 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
5515 /* If any signal numbers or symbol names were found, set flags for
5516 which signals to apply actions to. */
5518 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
5520 switch ((enum target_signal) signum)
5522 case TARGET_SIGNAL_TRAP:
5523 case TARGET_SIGNAL_INT:
5524 if (!allsigs && !sigs[signum])
5526 if (query (_("%s is used by the debugger.\n\
5527 Are you sure you want to change it? "), target_signal_to_name ((enum target_signal) signum)))
5533 printf_unfiltered (_("Not confirmed, unchanged.\n"));
5534 gdb_flush (gdb_stdout);
5538 case TARGET_SIGNAL_0:
5539 case TARGET_SIGNAL_DEFAULT:
5540 case TARGET_SIGNAL_UNKNOWN:
5541 /* Make sure that "all" doesn't print these. */
5552 for (signum = 0; signum < nsigs; signum++)
5555 target_notice_signals (inferior_ptid);
5559 /* Show the results. */
5560 sig_print_header ();
5561 for (; signum < nsigs; signum++)
5563 sig_print_info (signum);
5569 do_cleanups (old_chain);
5573 xdb_handle_command (char *args, int from_tty)
5576 struct cleanup *old_chain;
5579 error_no_arg (_("xdb command"));
5581 /* Break the command line up into args. */
5583 argv = gdb_buildargv (args);
5584 old_chain = make_cleanup_freeargv (argv);
5585 if (argv[1] != (char *) NULL)
5590 bufLen = strlen (argv[0]) + 20;
5591 argBuf = (char *) xmalloc (bufLen);
5595 enum target_signal oursig;
5597 oursig = target_signal_from_name (argv[0]);
5598 memset (argBuf, 0, bufLen);
5599 if (strcmp (argv[1], "Q") == 0)
5600 sprintf (argBuf, "%s %s", argv[0], "noprint");
5603 if (strcmp (argv[1], "s") == 0)
5605 if (!signal_stop[oursig])
5606 sprintf (argBuf, "%s %s", argv[0], "stop");
5608 sprintf (argBuf, "%s %s", argv[0], "nostop");
5610 else if (strcmp (argv[1], "i") == 0)
5612 if (!signal_program[oursig])
5613 sprintf (argBuf, "%s %s", argv[0], "pass");
5615 sprintf (argBuf, "%s %s", argv[0], "nopass");
5617 else if (strcmp (argv[1], "r") == 0)
5619 if (!signal_print[oursig])
5620 sprintf (argBuf, "%s %s", argv[0], "print");
5622 sprintf (argBuf, "%s %s", argv[0], "noprint");
5628 handle_command (argBuf, from_tty);
5630 printf_filtered (_("Invalid signal handling flag.\n"));
5635 do_cleanups (old_chain);
5638 /* Print current contents of the tables set by the handle command.
5639 It is possible we should just be printing signals actually used
5640 by the current target (but for things to work right when switching
5641 targets, all signals should be in the signal tables). */
5644 signals_info (char *signum_exp, int from_tty)
5646 enum target_signal oursig;
5647 sig_print_header ();
5651 /* First see if this is a symbol name. */
5652 oursig = target_signal_from_name (signum_exp);
5653 if (oursig == TARGET_SIGNAL_UNKNOWN)
5655 /* No, try numeric. */
5657 target_signal_from_command (parse_and_eval_long (signum_exp));
5659 sig_print_info (oursig);
5663 printf_filtered ("\n");
5664 /* These ugly casts brought to you by the native VAX compiler. */
5665 for (oursig = TARGET_SIGNAL_FIRST;
5666 (int) oursig < (int) TARGET_SIGNAL_LAST;
5667 oursig = (enum target_signal) ((int) oursig + 1))
5671 if (oursig != TARGET_SIGNAL_UNKNOWN
5672 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
5673 sig_print_info (oursig);
5676 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
5679 /* The $_siginfo convenience variable is a bit special. We don't know
5680 for sure the type of the value until we actually have a chance to
5681 fetch the data. The type can change depending on gdbarch, so it it
5682 also dependent on which thread you have selected.
5684 1. making $_siginfo be an internalvar that creates a new value on
5687 2. making the value of $_siginfo be an lval_computed value. */
5689 /* This function implements the lval_computed support for reading a
5693 siginfo_value_read (struct value *v)
5695 LONGEST transferred;
5698 target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO,
5700 value_contents_all_raw (v),
5702 TYPE_LENGTH (value_type (v)));
5704 if (transferred != TYPE_LENGTH (value_type (v)))
5705 error (_("Unable to read siginfo"));
5708 /* This function implements the lval_computed support for writing a
5712 siginfo_value_write (struct value *v, struct value *fromval)
5714 LONGEST transferred;
5716 transferred = target_write (¤t_target,
5717 TARGET_OBJECT_SIGNAL_INFO,
5719 value_contents_all_raw (fromval),
5721 TYPE_LENGTH (value_type (fromval)));
5723 if (transferred != TYPE_LENGTH (value_type (fromval)))
5724 error (_("Unable to write siginfo"));
5727 static struct lval_funcs siginfo_value_funcs =
5733 /* Return a new value with the correct type for the siginfo object of
5734 the current thread using architecture GDBARCH. Return a void value
5735 if there's no object available. */
5737 static struct value *
5738 siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var)
5740 if (target_has_stack
5741 && !ptid_equal (inferior_ptid, null_ptid)
5742 && gdbarch_get_siginfo_type_p (gdbarch))
5744 struct type *type = gdbarch_get_siginfo_type (gdbarch);
5745 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
5748 return allocate_value (builtin_type (gdbarch)->builtin_void);
5752 /* Inferior thread state.
5753 These are details related to the inferior itself, and don't include
5754 things like what frame the user had selected or what gdb was doing
5755 with the target at the time.
5756 For inferior function calls these are things we want to restore
5757 regardless of whether the function call successfully completes
5758 or the dummy frame has to be manually popped. */
5760 struct inferior_thread_state
5762 enum target_signal stop_signal;
5764 struct regcache *registers;
5767 struct inferior_thread_state *
5768 save_inferior_thread_state (void)
5770 struct inferior_thread_state *inf_state = XMALLOC (struct inferior_thread_state);
5771 struct thread_info *tp = inferior_thread ();
5773 inf_state->stop_signal = tp->stop_signal;
5774 inf_state->stop_pc = stop_pc;
5776 inf_state->registers = regcache_dup (get_current_regcache ());
5781 /* Restore inferior session state to INF_STATE. */
5784 restore_inferior_thread_state (struct inferior_thread_state *inf_state)
5786 struct thread_info *tp = inferior_thread ();
5788 tp->stop_signal = inf_state->stop_signal;
5789 stop_pc = inf_state->stop_pc;
5791 /* The inferior can be gone if the user types "print exit(0)"
5792 (and perhaps other times). */
5793 if (target_has_execution)
5794 /* NB: The register write goes through to the target. */
5795 regcache_cpy (get_current_regcache (), inf_state->registers);
5796 regcache_xfree (inf_state->registers);
5801 do_restore_inferior_thread_state_cleanup (void *state)
5803 restore_inferior_thread_state (state);
5807 make_cleanup_restore_inferior_thread_state (struct inferior_thread_state *inf_state)
5809 return make_cleanup (do_restore_inferior_thread_state_cleanup, inf_state);
5813 discard_inferior_thread_state (struct inferior_thread_state *inf_state)
5815 regcache_xfree (inf_state->registers);
5820 get_inferior_thread_state_regcache (struct inferior_thread_state *inf_state)
5822 return inf_state->registers;
5825 /* Session related state for inferior function calls.
5826 These are the additional bits of state that need to be restored
5827 when an inferior function call successfully completes. */
5829 struct inferior_status
5833 int stop_stack_dummy;
5834 int stopped_by_random_signal;
5835 int stepping_over_breakpoint;
5836 CORE_ADDR step_range_start;
5837 CORE_ADDR step_range_end;
5838 struct frame_id step_frame_id;
5839 struct frame_id step_stack_frame_id;
5840 enum step_over_calls_kind step_over_calls;
5841 CORE_ADDR step_resume_break_address;
5842 int stop_after_trap;
5845 /* ID if the selected frame when the inferior function call was made. */
5846 struct frame_id selected_frame_id;
5848 int proceed_to_finish;
5852 /* Save all of the information associated with the inferior<==>gdb
5855 struct inferior_status *
5856 save_inferior_status (void)
5858 struct inferior_status *inf_status = XMALLOC (struct inferior_status);
5859 struct thread_info *tp = inferior_thread ();
5860 struct inferior *inf = current_inferior ();
5862 inf_status->stop_step = tp->stop_step;
5863 inf_status->stop_stack_dummy = stop_stack_dummy;
5864 inf_status->stopped_by_random_signal = stopped_by_random_signal;
5865 inf_status->stepping_over_breakpoint = tp->trap_expected;
5866 inf_status->step_range_start = tp->step_range_start;
5867 inf_status->step_range_end = tp->step_range_end;
5868 inf_status->step_frame_id = tp->step_frame_id;
5869 inf_status->step_stack_frame_id = tp->step_stack_frame_id;
5870 inf_status->step_over_calls = tp->step_over_calls;
5871 inf_status->stop_after_trap = stop_after_trap;
5872 inf_status->stop_soon = inf->stop_soon;
5873 /* Save original bpstat chain here; replace it with copy of chain.
5874 If caller's caller is walking the chain, they'll be happier if we
5875 hand them back the original chain when restore_inferior_status is
5877 inf_status->stop_bpstat = tp->stop_bpstat;
5878 tp->stop_bpstat = bpstat_copy (tp->stop_bpstat);
5879 inf_status->proceed_to_finish = tp->proceed_to_finish;
5880 inf_status->in_infcall = tp->in_infcall;
5882 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
5888 restore_selected_frame (void *args)
5890 struct frame_id *fid = (struct frame_id *) args;
5891 struct frame_info *frame;
5893 frame = frame_find_by_id (*fid);
5895 /* If inf_status->selected_frame_id is NULL, there was no previously
5899 warning (_("Unable to restore previously selected frame."));
5903 select_frame (frame);
5908 /* Restore inferior session state to INF_STATUS. */
5911 restore_inferior_status (struct inferior_status *inf_status)
5913 struct thread_info *tp = inferior_thread ();
5914 struct inferior *inf = current_inferior ();
5916 tp->stop_step = inf_status->stop_step;
5917 stop_stack_dummy = inf_status->stop_stack_dummy;
5918 stopped_by_random_signal = inf_status->stopped_by_random_signal;
5919 tp->trap_expected = inf_status->stepping_over_breakpoint;
5920 tp->step_range_start = inf_status->step_range_start;
5921 tp->step_range_end = inf_status->step_range_end;
5922 tp->step_frame_id = inf_status->step_frame_id;
5923 tp->step_stack_frame_id = inf_status->step_stack_frame_id;
5924 tp->step_over_calls = inf_status->step_over_calls;
5925 stop_after_trap = inf_status->stop_after_trap;
5926 inf->stop_soon = inf_status->stop_soon;
5927 bpstat_clear (&tp->stop_bpstat);
5928 tp->stop_bpstat = inf_status->stop_bpstat;
5929 inf_status->stop_bpstat = NULL;
5930 tp->proceed_to_finish = inf_status->proceed_to_finish;
5931 tp->in_infcall = inf_status->in_infcall;
5933 if (target_has_stack)
5935 /* The point of catch_errors is that if the stack is clobbered,
5936 walking the stack might encounter a garbage pointer and
5937 error() trying to dereference it. */
5939 (restore_selected_frame, &inf_status->selected_frame_id,
5940 "Unable to restore previously selected frame:\n",
5941 RETURN_MASK_ERROR) == 0)
5942 /* Error in restoring the selected frame. Select the innermost
5944 select_frame (get_current_frame ());
5951 do_restore_inferior_status_cleanup (void *sts)
5953 restore_inferior_status (sts);
5957 make_cleanup_restore_inferior_status (struct inferior_status *inf_status)
5959 return make_cleanup (do_restore_inferior_status_cleanup, inf_status);
5963 discard_inferior_status (struct inferior_status *inf_status)
5965 /* See save_inferior_status for info on stop_bpstat. */
5966 bpstat_clear (&inf_status->stop_bpstat);
5971 inferior_has_forked (ptid_t pid, ptid_t *child_pid)
5973 struct target_waitstatus last;
5976 get_last_target_status (&last_ptid, &last);
5978 if (last.kind != TARGET_WAITKIND_FORKED)
5981 if (!ptid_equal (last_ptid, pid))
5984 *child_pid = last.value.related_pid;
5989 inferior_has_vforked (ptid_t pid, ptid_t *child_pid)
5991 struct target_waitstatus last;
5994 get_last_target_status (&last_ptid, &last);
5996 if (last.kind != TARGET_WAITKIND_VFORKED)
5999 if (!ptid_equal (last_ptid, pid))
6002 *child_pid = last.value.related_pid;
6007 inferior_has_execd (ptid_t pid, char **execd_pathname)
6009 struct target_waitstatus last;
6012 get_last_target_status (&last_ptid, &last);
6014 if (last.kind != TARGET_WAITKIND_EXECD)
6017 if (!ptid_equal (last_ptid, pid))
6020 *execd_pathname = xstrdup (last.value.execd_pathname);
6025 inferior_has_called_syscall (ptid_t pid, int *syscall_number)
6027 struct target_waitstatus last;
6030 get_last_target_status (&last_ptid, &last);
6032 if (last.kind != TARGET_WAITKIND_SYSCALL_ENTRY &&
6033 last.kind != TARGET_WAITKIND_SYSCALL_RETURN)
6036 if (!ptid_equal (last_ptid, pid))
6039 *syscall_number = last.value.syscall_number;
6043 /* Oft used ptids */
6045 ptid_t minus_one_ptid;
6047 /* Create a ptid given the necessary PID, LWP, and TID components. */
6050 ptid_build (int pid, long lwp, long tid)
6060 /* Create a ptid from just a pid. */
6063 pid_to_ptid (int pid)
6065 return ptid_build (pid, 0, 0);
6068 /* Fetch the pid (process id) component from a ptid. */
6071 ptid_get_pid (ptid_t ptid)
6076 /* Fetch the lwp (lightweight process) component from a ptid. */
6079 ptid_get_lwp (ptid_t ptid)
6084 /* Fetch the tid (thread id) component from a ptid. */
6087 ptid_get_tid (ptid_t ptid)
6092 /* ptid_equal() is used to test equality of two ptids. */
6095 ptid_equal (ptid_t ptid1, ptid_t ptid2)
6097 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
6098 && ptid1.tid == ptid2.tid);
6101 /* Returns true if PTID represents a process. */
6104 ptid_is_pid (ptid_t ptid)
6106 if (ptid_equal (minus_one_ptid, ptid))
6108 if (ptid_equal (null_ptid, ptid))
6111 return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0);
6114 /* restore_inferior_ptid() will be used by the cleanup machinery
6115 to restore the inferior_ptid value saved in a call to
6116 save_inferior_ptid(). */
6119 restore_inferior_ptid (void *arg)
6121 ptid_t *saved_ptid_ptr = arg;
6122 inferior_ptid = *saved_ptid_ptr;
6126 /* Save the value of inferior_ptid so that it may be restored by a
6127 later call to do_cleanups(). Returns the struct cleanup pointer
6128 needed for later doing the cleanup. */
6131 save_inferior_ptid (void)
6133 ptid_t *saved_ptid_ptr;
6135 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
6136 *saved_ptid_ptr = inferior_ptid;
6137 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
6141 /* User interface for reverse debugging:
6142 Set exec-direction / show exec-direction commands
6143 (returns error unless target implements to_set_exec_direction method). */
6145 enum exec_direction_kind execution_direction = EXEC_FORWARD;
6146 static const char exec_forward[] = "forward";
6147 static const char exec_reverse[] = "reverse";
6148 static const char *exec_direction = exec_forward;
6149 static const char *exec_direction_names[] = {
6156 set_exec_direction_func (char *args, int from_tty,
6157 struct cmd_list_element *cmd)
6159 if (target_can_execute_reverse)
6161 if (!strcmp (exec_direction, exec_forward))
6162 execution_direction = EXEC_FORWARD;
6163 else if (!strcmp (exec_direction, exec_reverse))
6164 execution_direction = EXEC_REVERSE;
6169 show_exec_direction_func (struct ui_file *out, int from_tty,
6170 struct cmd_list_element *cmd, const char *value)
6172 switch (execution_direction) {
6174 fprintf_filtered (out, _("Forward.\n"));
6177 fprintf_filtered (out, _("Reverse.\n"));
6181 fprintf_filtered (out,
6182 _("Forward (target `%s' does not support exec-direction).\n"),
6188 /* User interface for non-stop mode. */
6191 static int non_stop_1 = 0;
6194 set_non_stop (char *args, int from_tty,
6195 struct cmd_list_element *c)
6197 if (target_has_execution)
6199 non_stop_1 = non_stop;
6200 error (_("Cannot change this setting while the inferior is running."));
6203 non_stop = non_stop_1;
6207 show_non_stop (struct ui_file *file, int from_tty,
6208 struct cmd_list_element *c, const char *value)
6210 fprintf_filtered (file,
6211 _("Controlling the inferior in non-stop mode is %s.\n"),
6216 show_schedule_multiple (struct ui_file *file, int from_tty,
6217 struct cmd_list_element *c, const char *value)
6219 fprintf_filtered (file, _("\
6220 Resuming the execution of threads of all processes is %s.\n"), value);
6224 _initialize_infrun (void)
6228 struct cmd_list_element *c;
6230 add_info ("signals", signals_info, _("\
6231 What debugger does when program gets various signals.\n\
6232 Specify a signal as argument to print info on that signal only."));
6233 add_info_alias ("handle", "signals", 0);
6235 add_com ("handle", class_run, handle_command, _("\
6236 Specify how to handle a signal.\n\
6237 Args are signals and actions to apply to those signals.\n\
6238 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6239 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6240 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6241 The special arg \"all\" is recognized to mean all signals except those\n\
6242 used by the debugger, typically SIGTRAP and SIGINT.\n\
6243 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
6244 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
6245 Stop means reenter debugger if this signal happens (implies print).\n\
6246 Print means print a message if this signal happens.\n\
6247 Pass means let program see this signal; otherwise program doesn't know.\n\
6248 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6249 Pass and Stop may be combined."));
6252 add_com ("lz", class_info, signals_info, _("\
6253 What debugger does when program gets various signals.\n\
6254 Specify a signal as argument to print info on that signal only."));
6255 add_com ("z", class_run, xdb_handle_command, _("\
6256 Specify how to handle a signal.\n\
6257 Args are signals and actions to apply to those signals.\n\
6258 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6259 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6260 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6261 The special arg \"all\" is recognized to mean all signals except those\n\
6262 used by the debugger, typically SIGTRAP and SIGINT.\n\
6263 Recognized actions include \"s\" (toggles between stop and nostop), \n\
6264 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
6265 nopass), \"Q\" (noprint)\n\
6266 Stop means reenter debugger if this signal happens (implies print).\n\
6267 Print means print a message if this signal happens.\n\
6268 Pass means let program see this signal; otherwise program doesn't know.\n\
6269 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6270 Pass and Stop may be combined."));
6274 stop_command = add_cmd ("stop", class_obscure,
6275 not_just_help_class_command, _("\
6276 There is no `stop' command, but you can set a hook on `stop'.\n\
6277 This allows you to set a list of commands to be run each time execution\n\
6278 of the program stops."), &cmdlist);
6280 add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
6281 Set inferior debugging."), _("\
6282 Show inferior debugging."), _("\
6283 When non-zero, inferior specific debugging is enabled."),
6286 &setdebuglist, &showdebuglist);
6288 add_setshow_boolean_cmd ("displaced", class_maintenance, &debug_displaced, _("\
6289 Set displaced stepping debugging."), _("\
6290 Show displaced stepping debugging."), _("\
6291 When non-zero, displaced stepping specific debugging is enabled."),
6293 show_debug_displaced,
6294 &setdebuglist, &showdebuglist);
6296 add_setshow_boolean_cmd ("non-stop", no_class,
6298 Set whether gdb controls the inferior in non-stop mode."), _("\
6299 Show whether gdb controls the inferior in non-stop mode."), _("\
6300 When debugging a multi-threaded program and this setting is\n\
6301 off (the default, also called all-stop mode), when one thread stops\n\
6302 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
6303 all other threads in the program while you interact with the thread of\n\
6304 interest. When you continue or step a thread, you can allow the other\n\
6305 threads to run, or have them remain stopped, but while you inspect any\n\
6306 thread's state, all threads stop.\n\
6308 In non-stop mode, when one thread stops, other threads can continue\n\
6309 to run freely. You'll be able to step each thread independently,\n\
6310 leave it stopped or free to run as needed."),
6316 numsigs = (int) TARGET_SIGNAL_LAST;
6317 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
6318 signal_print = (unsigned char *)
6319 xmalloc (sizeof (signal_print[0]) * numsigs);
6320 signal_program = (unsigned char *)
6321 xmalloc (sizeof (signal_program[0]) * numsigs);
6322 for (i = 0; i < numsigs; i++)
6325 signal_print[i] = 1;
6326 signal_program[i] = 1;
6329 /* Signals caused by debugger's own actions
6330 should not be given to the program afterwards. */
6331 signal_program[TARGET_SIGNAL_TRAP] = 0;
6332 signal_program[TARGET_SIGNAL_INT] = 0;
6334 /* Signals that are not errors should not normally enter the debugger. */
6335 signal_stop[TARGET_SIGNAL_ALRM] = 0;
6336 signal_print[TARGET_SIGNAL_ALRM] = 0;
6337 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
6338 signal_print[TARGET_SIGNAL_VTALRM] = 0;
6339 signal_stop[TARGET_SIGNAL_PROF] = 0;
6340 signal_print[TARGET_SIGNAL_PROF] = 0;
6341 signal_stop[TARGET_SIGNAL_CHLD] = 0;
6342 signal_print[TARGET_SIGNAL_CHLD] = 0;
6343 signal_stop[TARGET_SIGNAL_IO] = 0;
6344 signal_print[TARGET_SIGNAL_IO] = 0;
6345 signal_stop[TARGET_SIGNAL_POLL] = 0;
6346 signal_print[TARGET_SIGNAL_POLL] = 0;
6347 signal_stop[TARGET_SIGNAL_URG] = 0;
6348 signal_print[TARGET_SIGNAL_URG] = 0;
6349 signal_stop[TARGET_SIGNAL_WINCH] = 0;
6350 signal_print[TARGET_SIGNAL_WINCH] = 0;
6352 /* These signals are used internally by user-level thread
6353 implementations. (See signal(5) on Solaris.) Like the above
6354 signals, a healthy program receives and handles them as part of
6355 its normal operation. */
6356 signal_stop[TARGET_SIGNAL_LWP] = 0;
6357 signal_print[TARGET_SIGNAL_LWP] = 0;
6358 signal_stop[TARGET_SIGNAL_WAITING] = 0;
6359 signal_print[TARGET_SIGNAL_WAITING] = 0;
6360 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
6361 signal_print[TARGET_SIGNAL_CANCEL] = 0;
6363 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
6364 &stop_on_solib_events, _("\
6365 Set stopping for shared library events."), _("\
6366 Show stopping for shared library events."), _("\
6367 If nonzero, gdb will give control to the user when the dynamic linker\n\
6368 notifies gdb of shared library events. The most common event of interest\n\
6369 to the user would be loading/unloading of a new library."),
6371 show_stop_on_solib_events,
6372 &setlist, &showlist);
6374 add_setshow_enum_cmd ("follow-fork-mode", class_run,
6375 follow_fork_mode_kind_names,
6376 &follow_fork_mode_string, _("\
6377 Set debugger response to a program call of fork or vfork."), _("\
6378 Show debugger response to a program call of fork or vfork."), _("\
6379 A fork or vfork creates a new process. follow-fork-mode can be:\n\
6380 parent - the original process is debugged after a fork\n\
6381 child - the new process is debugged after a fork\n\
6382 The unfollowed process will continue to run.\n\
6383 By default, the debugger will follow the parent process."),
6385 show_follow_fork_mode_string,
6386 &setlist, &showlist);
6388 add_setshow_enum_cmd ("follow-exec-mode", class_run,
6389 follow_exec_mode_names,
6390 &follow_exec_mode_string, _("\
6391 Set debugger response to a program call of exec."), _("\
6392 Show debugger response to a program call of exec."), _("\
6393 An exec call replaces the program image of a process.\n\
6395 follow-exec-mode can be:\n\
6397 new - the debugger creates a new inferior and rebinds the process \n\
6398 to this new inferior. The program the process was running before\n\
6399 the exec call can be restarted afterwards by restarting the original\n\
6402 same - the debugger keeps the process bound to the same inferior.\n\
6403 The new executable image replaces the previous executable loaded in\n\
6404 the inferior. Restarting the inferior after the exec call restarts\n\
6405 the executable the process was running after the exec call.\n\
6407 By default, the debugger will use the same inferior."),
6409 show_follow_exec_mode_string,
6410 &setlist, &showlist);
6412 add_setshow_enum_cmd ("scheduler-locking", class_run,
6413 scheduler_enums, &scheduler_mode, _("\
6414 Set mode for locking scheduler during execution."), _("\
6415 Show mode for locking scheduler during execution."), _("\
6416 off == no locking (threads may preempt at any time)\n\
6417 on == full locking (no thread except the current thread may run)\n\
6418 step == scheduler locked during every single-step operation.\n\
6419 In this mode, no other thread may run during a step command.\n\
6420 Other threads may run while stepping over a function call ('next')."),
6421 set_schedlock_func, /* traps on target vector */
6422 show_scheduler_mode,
6423 &setlist, &showlist);
6425 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
6426 Set mode for resuming threads of all processes."), _("\
6427 Show mode for resuming threads of all processes."), _("\
6428 When on, execution commands (such as 'continue' or 'next') resume all\n\
6429 threads of all processes. When off (which is the default), execution\n\
6430 commands only resume the threads of the current process. The set of\n\
6431 threads that are resumed is further refined by the scheduler-locking\n\
6432 mode (see help set scheduler-locking)."),
6434 show_schedule_multiple,
6435 &setlist, &showlist);
6437 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
6438 Set mode of the step operation."), _("\
6439 Show mode of the step operation."), _("\
6440 When set, doing a step over a function without debug line information\n\
6441 will stop at the first instruction of that function. Otherwise, the\n\
6442 function is skipped and the step command stops at a different source line."),
6444 show_step_stop_if_no_debug,
6445 &setlist, &showlist);
6447 add_setshow_enum_cmd ("displaced-stepping", class_run,
6448 can_use_displaced_stepping_enum,
6449 &can_use_displaced_stepping, _("\
6450 Set debugger's willingness to use displaced stepping."), _("\
6451 Show debugger's willingness to use displaced stepping."), _("\
6452 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
6453 supported by the target architecture. If off, gdb will not use displaced\n\
6454 stepping to step over breakpoints, even if such is supported by the target\n\
6455 architecture. If auto (which is the default), gdb will use displaced stepping\n\
6456 if the target architecture supports it and non-stop mode is active, but will not\n\
6457 use it in all-stop mode (see help set non-stop)."),
6459 show_can_use_displaced_stepping,
6460 &setlist, &showlist);
6462 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
6463 &exec_direction, _("Set direction of execution.\n\
6464 Options are 'forward' or 'reverse'."),
6465 _("Show direction of execution (forward/reverse)."),
6466 _("Tells gdb whether to execute forward or backward."),
6467 set_exec_direction_func, show_exec_direction_func,
6468 &setlist, &showlist);
6470 /* Set/show detach-on-fork: user-settable mode. */
6472 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
6473 Set whether gdb will detach the child of a fork."), _("\
6474 Show whether gdb will detach the child of a fork."), _("\
6475 Tells gdb whether to detach the child of a fork."),
6476 NULL, NULL, &setlist, &showlist);
6478 /* ptid initializations */
6479 null_ptid = ptid_build (0, 0, 0);
6480 minus_one_ptid = ptid_build (-1, 0, 0);
6481 inferior_ptid = null_ptid;
6482 target_last_wait_ptid = minus_one_ptid;
6483 displaced_step_ptid = null_ptid;
6485 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
6486 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
6487 observer_attach_thread_exit (infrun_thread_thread_exit);
6489 /* Explicitly create without lookup, since that tries to create a
6490 value with a void typed value, and when we get here, gdbarch
6491 isn't initialized yet. At this point, we're quite sure there
6492 isn't another convenience variable of the same name. */
6493 create_internalvar_type_lazy ("_siginfo", siginfo_make_value);