1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2012 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "gdb_string.h"
27 #include "exceptions.h"
28 #include "breakpoint.h"
32 #include "cli/cli-script.h"
34 #include "gdbthread.h"
46 #include "dictionary.h"
48 #include "gdb_assert.h"
49 #include "mi/mi-common.h"
50 #include "event-top.h"
52 #include "inline-frame.h"
54 #include "tracepoint.h"
55 #include "continuations.h"
60 #include "completer.h"
62 /* Prototypes for local functions */
64 static void signals_info (char *, int);
66 static void handle_command (char *, int);
68 static void sig_print_info (enum gdb_signal
);
70 static void sig_print_header (void);
72 static void resume_cleanups (void *);
74 static int hook_stop_stub (void *);
76 static int restore_selected_frame (void *);
78 static int follow_fork (void);
80 static void set_schedlock_func (char *args
, int from_tty
,
81 struct cmd_list_element
*c
);
83 static int currently_stepping (struct thread_info
*tp
);
85 static int currently_stepping_or_nexting_callback (struct thread_info
*tp
,
88 static void xdb_handle_command (char *args
, int from_tty
);
90 static int prepare_to_proceed (int);
92 static void print_exited_reason (int exitstatus
);
94 static void print_signal_exited_reason (enum gdb_signal siggnal
);
96 static void print_no_history_reason (void);
98 static void print_signal_received_reason (enum gdb_signal siggnal
);
100 static void print_end_stepping_range_reason (void);
102 void _initialize_infrun (void);
104 void nullify_last_target_wait_ptid (void);
106 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
108 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
110 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
112 /* When set, stop the 'step' command if we enter a function which has
113 no line number information. The normal behavior is that we step
114 over such function. */
115 int step_stop_if_no_debug
= 0;
117 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
118 struct cmd_list_element
*c
, const char *value
)
120 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
123 /* In asynchronous mode, but simulating synchronous execution. */
125 int sync_execution
= 0;
127 /* wait_for_inferior and normal_stop use this to notify the user
128 when the inferior stopped in a different thread than it had been
131 static ptid_t previous_inferior_ptid
;
133 /* Default behavior is to detach newly forked processes (legacy). */
136 int debug_displaced
= 0;
138 show_debug_displaced (struct ui_file
*file
, int from_tty
,
139 struct cmd_list_element
*c
, const char *value
)
141 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
144 unsigned int debug_infrun
= 0;
146 show_debug_infrun (struct ui_file
*file
, int from_tty
,
147 struct cmd_list_element
*c
, const char *value
)
149 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
153 /* Support for disabling address space randomization. */
155 int disable_randomization
= 1;
158 show_disable_randomization (struct ui_file
*file
, int from_tty
,
159 struct cmd_list_element
*c
, const char *value
)
161 if (target_supports_disable_randomization ())
162 fprintf_filtered (file
,
163 _("Disabling randomization of debuggee's "
164 "virtual address space is %s.\n"),
167 fputs_filtered (_("Disabling randomization of debuggee's "
168 "virtual address space is unsupported on\n"
169 "this platform.\n"), file
);
173 set_disable_randomization (char *args
, int from_tty
,
174 struct cmd_list_element
*c
)
176 if (!target_supports_disable_randomization ())
177 error (_("Disabling randomization of debuggee's "
178 "virtual address space is unsupported on\n"
183 /* If the program uses ELF-style shared libraries, then calls to
184 functions in shared libraries go through stubs, which live in a
185 table called the PLT (Procedure Linkage Table). The first time the
186 function is called, the stub sends control to the dynamic linker,
187 which looks up the function's real address, patches the stub so
188 that future calls will go directly to the function, and then passes
189 control to the function.
191 If we are stepping at the source level, we don't want to see any of
192 this --- we just want to skip over the stub and the dynamic linker.
193 The simple approach is to single-step until control leaves the
196 However, on some systems (e.g., Red Hat's 5.2 distribution) the
197 dynamic linker calls functions in the shared C library, so you
198 can't tell from the PC alone whether the dynamic linker is still
199 running. In this case, we use a step-resume breakpoint to get us
200 past the dynamic linker, as if we were using "next" to step over a
203 in_solib_dynsym_resolve_code() says whether we're in the dynamic
204 linker code or not. Normally, this means we single-step. However,
205 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
206 address where we can place a step-resume breakpoint to get past the
207 linker's symbol resolution function.
209 in_solib_dynsym_resolve_code() can generally be implemented in a
210 pretty portable way, by comparing the PC against the address ranges
211 of the dynamic linker's sections.
213 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
214 it depends on internal details of the dynamic linker. It's usually
215 not too hard to figure out where to put a breakpoint, but it
216 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
217 sanity checking. If it can't figure things out, returning zero and
218 getting the (possibly confusing) stepping behavior is better than
219 signalling an error, which will obscure the change in the
222 /* This function returns TRUE if pc is the address of an instruction
223 that lies within the dynamic linker (such as the event hook, or the
226 This function must be used only when a dynamic linker event has
227 been caught, and the inferior is being stepped out of the hook, or
228 undefined results are guaranteed. */
230 #ifndef SOLIB_IN_DYNAMIC_LINKER
231 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
234 /* "Observer mode" is somewhat like a more extreme version of
235 non-stop, in which all GDB operations that might affect the
236 target's execution have been disabled. */
238 static int non_stop_1
= 0;
240 int observer_mode
= 0;
241 static int observer_mode_1
= 0;
244 set_observer_mode (char *args
, int from_tty
,
245 struct cmd_list_element
*c
)
247 extern int pagination_enabled
;
249 if (target_has_execution
)
251 observer_mode_1
= observer_mode
;
252 error (_("Cannot change this setting while the inferior is running."));
255 observer_mode
= observer_mode_1
;
257 may_write_registers
= !observer_mode
;
258 may_write_memory
= !observer_mode
;
259 may_insert_breakpoints
= !observer_mode
;
260 may_insert_tracepoints
= !observer_mode
;
261 /* We can insert fast tracepoints in or out of observer mode,
262 but enable them if we're going into this mode. */
264 may_insert_fast_tracepoints
= 1;
265 may_stop
= !observer_mode
;
266 update_target_permissions ();
268 /* Going *into* observer mode we must force non-stop, then
269 going out we leave it that way. */
272 target_async_permitted
= 1;
273 pagination_enabled
= 0;
274 non_stop
= non_stop_1
= 1;
278 printf_filtered (_("Observer mode is now %s.\n"),
279 (observer_mode
? "on" : "off"));
283 show_observer_mode (struct ui_file
*file
, int from_tty
,
284 struct cmd_list_element
*c
, const char *value
)
286 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
289 /* This updates the value of observer mode based on changes in
290 permissions. Note that we are deliberately ignoring the values of
291 may-write-registers and may-write-memory, since the user may have
292 reason to enable these during a session, for instance to turn on a
293 debugging-related global. */
296 update_observer_mode (void)
300 newval
= (!may_insert_breakpoints
301 && !may_insert_tracepoints
302 && may_insert_fast_tracepoints
306 /* Let the user know if things change. */
307 if (newval
!= observer_mode
)
308 printf_filtered (_("Observer mode is now %s.\n"),
309 (newval
? "on" : "off"));
311 observer_mode
= observer_mode_1
= newval
;
314 /* Tables of how to react to signals; the user sets them. */
316 static unsigned char *signal_stop
;
317 static unsigned char *signal_print
;
318 static unsigned char *signal_program
;
320 /* Table of signals that the target may silently handle.
321 This is automatically determined from the flags above,
322 and simply cached here. */
323 static unsigned char *signal_pass
;
325 #define SET_SIGS(nsigs,sigs,flags) \
327 int signum = (nsigs); \
328 while (signum-- > 0) \
329 if ((sigs)[signum]) \
330 (flags)[signum] = 1; \
333 #define UNSET_SIGS(nsigs,sigs,flags) \
335 int signum = (nsigs); \
336 while (signum-- > 0) \
337 if ((sigs)[signum]) \
338 (flags)[signum] = 0; \
341 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
342 this function is to avoid exporting `signal_program'. */
345 update_signals_program_target (void)
347 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
350 /* Value to pass to target_resume() to cause all threads to resume. */
352 #define RESUME_ALL minus_one_ptid
354 /* Command list pointer for the "stop" placeholder. */
356 static struct cmd_list_element
*stop_command
;
358 /* Function inferior was in as of last step command. */
360 static struct symbol
*step_start_function
;
362 /* Nonzero if we want to give control to the user when we're notified
363 of shared library events by the dynamic linker. */
364 int stop_on_solib_events
;
366 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
367 struct cmd_list_element
*c
, const char *value
)
369 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
373 /* Nonzero means expecting a trace trap
374 and should stop the inferior and return silently when it happens. */
378 /* Save register contents here when executing a "finish" command or are
379 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
380 Thus this contains the return value from the called function (assuming
381 values are returned in a register). */
383 struct regcache
*stop_registers
;
385 /* Nonzero after stop if current stack frame should be printed. */
387 static int stop_print_frame
;
389 /* This is a cached copy of the pid/waitstatus of the last event
390 returned by target_wait()/deprecated_target_wait_hook(). This
391 information is returned by get_last_target_status(). */
392 static ptid_t target_last_wait_ptid
;
393 static struct target_waitstatus target_last_waitstatus
;
395 static void context_switch (ptid_t ptid
);
397 void init_thread_stepping_state (struct thread_info
*tss
);
399 void init_infwait_state (void);
401 static const char follow_fork_mode_child
[] = "child";
402 static const char follow_fork_mode_parent
[] = "parent";
404 static const char *const follow_fork_mode_kind_names
[] = {
405 follow_fork_mode_child
,
406 follow_fork_mode_parent
,
410 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
412 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
413 struct cmd_list_element
*c
, const char *value
)
415 fprintf_filtered (file
,
416 _("Debugger response to a program "
417 "call of fork or vfork is \"%s\".\n"),
422 /* Tell the target to follow the fork we're stopped at. Returns true
423 if the inferior should be resumed; false, if the target for some
424 reason decided it's best not to resume. */
429 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
430 int should_resume
= 1;
431 struct thread_info
*tp
;
433 /* Copy user stepping state to the new inferior thread. FIXME: the
434 followed fork child thread should have a copy of most of the
435 parent thread structure's run control related fields, not just these.
436 Initialized to avoid "may be used uninitialized" warnings from gcc. */
437 struct breakpoint
*step_resume_breakpoint
= NULL
;
438 struct breakpoint
*exception_resume_breakpoint
= NULL
;
439 CORE_ADDR step_range_start
= 0;
440 CORE_ADDR step_range_end
= 0;
441 struct frame_id step_frame_id
= { 0 };
446 struct target_waitstatus wait_status
;
448 /* Get the last target status returned by target_wait(). */
449 get_last_target_status (&wait_ptid
, &wait_status
);
451 /* If not stopped at a fork event, then there's nothing else to
453 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
454 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
457 /* Check if we switched over from WAIT_PTID, since the event was
459 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
460 && !ptid_equal (inferior_ptid
, wait_ptid
))
462 /* We did. Switch back to WAIT_PTID thread, to tell the
463 target to follow it (in either direction). We'll
464 afterwards refuse to resume, and inform the user what
466 switch_to_thread (wait_ptid
);
471 tp
= inferior_thread ();
473 /* If there were any forks/vforks that were caught and are now to be
474 followed, then do so now. */
475 switch (tp
->pending_follow
.kind
)
477 case TARGET_WAITKIND_FORKED
:
478 case TARGET_WAITKIND_VFORKED
:
480 ptid_t parent
, child
;
482 /* If the user did a next/step, etc, over a fork call,
483 preserve the stepping state in the fork child. */
484 if (follow_child
&& should_resume
)
486 step_resume_breakpoint
= clone_momentary_breakpoint
487 (tp
->control
.step_resume_breakpoint
);
488 step_range_start
= tp
->control
.step_range_start
;
489 step_range_end
= tp
->control
.step_range_end
;
490 step_frame_id
= tp
->control
.step_frame_id
;
491 exception_resume_breakpoint
492 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
494 /* For now, delete the parent's sr breakpoint, otherwise,
495 parent/child sr breakpoints are considered duplicates,
496 and the child version will not be installed. Remove
497 this when the breakpoints module becomes aware of
498 inferiors and address spaces. */
499 delete_step_resume_breakpoint (tp
);
500 tp
->control
.step_range_start
= 0;
501 tp
->control
.step_range_end
= 0;
502 tp
->control
.step_frame_id
= null_frame_id
;
503 delete_exception_resume_breakpoint (tp
);
506 parent
= inferior_ptid
;
507 child
= tp
->pending_follow
.value
.related_pid
;
509 /* Tell the target to do whatever is necessary to follow
510 either parent or child. */
511 if (target_follow_fork (follow_child
))
513 /* Target refused to follow, or there's some other reason
514 we shouldn't resume. */
519 /* This pending follow fork event is now handled, one way
520 or another. The previous selected thread may be gone
521 from the lists by now, but if it is still around, need
522 to clear the pending follow request. */
523 tp
= find_thread_ptid (parent
);
525 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
527 /* This makes sure we don't try to apply the "Switched
528 over from WAIT_PID" logic above. */
529 nullify_last_target_wait_ptid ();
531 /* If we followed the child, switch to it... */
534 switch_to_thread (child
);
536 /* ... and preserve the stepping state, in case the
537 user was stepping over the fork call. */
540 tp
= inferior_thread ();
541 tp
->control
.step_resume_breakpoint
542 = step_resume_breakpoint
;
543 tp
->control
.step_range_start
= step_range_start
;
544 tp
->control
.step_range_end
= step_range_end
;
545 tp
->control
.step_frame_id
= step_frame_id
;
546 tp
->control
.exception_resume_breakpoint
547 = exception_resume_breakpoint
;
551 /* If we get here, it was because we're trying to
552 resume from a fork catchpoint, but, the user
553 has switched threads away from the thread that
554 forked. In that case, the resume command
555 issued is most likely not applicable to the
556 child, so just warn, and refuse to resume. */
557 warning (_("Not resuming: switched threads "
558 "before following fork child.\n"));
561 /* Reset breakpoints in the child as appropriate. */
562 follow_inferior_reset_breakpoints ();
565 switch_to_thread (parent
);
569 case TARGET_WAITKIND_SPURIOUS
:
570 /* Nothing to follow. */
573 internal_error (__FILE__
, __LINE__
,
574 "Unexpected pending_follow.kind %d\n",
575 tp
->pending_follow
.kind
);
579 return should_resume
;
583 follow_inferior_reset_breakpoints (void)
585 struct thread_info
*tp
= inferior_thread ();
587 /* Was there a step_resume breakpoint? (There was if the user
588 did a "next" at the fork() call.) If so, explicitly reset its
591 step_resumes are a form of bp that are made to be per-thread.
592 Since we created the step_resume bp when the parent process
593 was being debugged, and now are switching to the child process,
594 from the breakpoint package's viewpoint, that's a switch of
595 "threads". We must update the bp's notion of which thread
596 it is for, or it'll be ignored when it triggers. */
598 if (tp
->control
.step_resume_breakpoint
)
599 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
601 if (tp
->control
.exception_resume_breakpoint
)
602 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
604 /* Reinsert all breakpoints in the child. The user may have set
605 breakpoints after catching the fork, in which case those
606 were never set in the child, but only in the parent. This makes
607 sure the inserted breakpoints match the breakpoint list. */
609 breakpoint_re_set ();
610 insert_breakpoints ();
613 /* The child has exited or execed: resume threads of the parent the
614 user wanted to be executing. */
617 proceed_after_vfork_done (struct thread_info
*thread
,
620 int pid
= * (int *) arg
;
622 if (ptid_get_pid (thread
->ptid
) == pid
623 && is_running (thread
->ptid
)
624 && !is_executing (thread
->ptid
)
625 && !thread
->stop_requested
626 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
629 fprintf_unfiltered (gdb_stdlog
,
630 "infrun: resuming vfork parent thread %s\n",
631 target_pid_to_str (thread
->ptid
));
633 switch_to_thread (thread
->ptid
);
634 clear_proceed_status ();
635 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
641 /* Called whenever we notice an exec or exit event, to handle
642 detaching or resuming a vfork parent. */
645 handle_vfork_child_exec_or_exit (int exec
)
647 struct inferior
*inf
= current_inferior ();
649 if (inf
->vfork_parent
)
651 int resume_parent
= -1;
653 /* This exec or exit marks the end of the shared memory region
654 between the parent and the child. If the user wanted to
655 detach from the parent, now is the time. */
657 if (inf
->vfork_parent
->pending_detach
)
659 struct thread_info
*tp
;
660 struct cleanup
*old_chain
;
661 struct program_space
*pspace
;
662 struct address_space
*aspace
;
664 /* follow-fork child, detach-on-fork on. */
666 inf
->vfork_parent
->pending_detach
= 0;
670 /* If we're handling a child exit, then inferior_ptid
671 points at the inferior's pid, not to a thread. */
672 old_chain
= save_inferior_ptid ();
673 save_current_program_space ();
674 save_current_inferior ();
677 old_chain
= save_current_space_and_thread ();
679 /* We're letting loose of the parent. */
680 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
681 switch_to_thread (tp
->ptid
);
683 /* We're about to detach from the parent, which implicitly
684 removes breakpoints from its address space. There's a
685 catch here: we want to reuse the spaces for the child,
686 but, parent/child are still sharing the pspace at this
687 point, although the exec in reality makes the kernel give
688 the child a fresh set of new pages. The problem here is
689 that the breakpoints module being unaware of this, would
690 likely chose the child process to write to the parent
691 address space. Swapping the child temporarily away from
692 the spaces has the desired effect. Yes, this is "sort
695 pspace
= inf
->pspace
;
696 aspace
= inf
->aspace
;
700 if (debug_infrun
|| info_verbose
)
702 target_terminal_ours ();
705 fprintf_filtered (gdb_stdlog
,
706 "Detaching vfork parent process "
707 "%d after child exec.\n",
708 inf
->vfork_parent
->pid
);
710 fprintf_filtered (gdb_stdlog
,
711 "Detaching vfork parent process "
712 "%d after child exit.\n",
713 inf
->vfork_parent
->pid
);
716 target_detach (NULL
, 0);
719 inf
->pspace
= pspace
;
720 inf
->aspace
= aspace
;
722 do_cleanups (old_chain
);
726 /* We're staying attached to the parent, so, really give the
727 child a new address space. */
728 inf
->pspace
= add_program_space (maybe_new_address_space ());
729 inf
->aspace
= inf
->pspace
->aspace
;
731 set_current_program_space (inf
->pspace
);
733 resume_parent
= inf
->vfork_parent
->pid
;
735 /* Break the bonds. */
736 inf
->vfork_parent
->vfork_child
= NULL
;
740 struct cleanup
*old_chain
;
741 struct program_space
*pspace
;
743 /* If this is a vfork child exiting, then the pspace and
744 aspaces were shared with the parent. Since we're
745 reporting the process exit, we'll be mourning all that is
746 found in the address space, and switching to null_ptid,
747 preparing to start a new inferior. But, since we don't
748 want to clobber the parent's address/program spaces, we
749 go ahead and create a new one for this exiting
752 /* Switch to null_ptid, so that clone_program_space doesn't want
753 to read the selected frame of a dead process. */
754 old_chain
= save_inferior_ptid ();
755 inferior_ptid
= null_ptid
;
757 /* This inferior is dead, so avoid giving the breakpoints
758 module the option to write through to it (cloning a
759 program space resets breakpoints). */
762 pspace
= add_program_space (maybe_new_address_space ());
763 set_current_program_space (pspace
);
765 inf
->symfile_flags
= SYMFILE_NO_READ
;
766 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
767 inf
->pspace
= pspace
;
768 inf
->aspace
= pspace
->aspace
;
770 /* Put back inferior_ptid. We'll continue mourning this
772 do_cleanups (old_chain
);
774 resume_parent
= inf
->vfork_parent
->pid
;
775 /* Break the bonds. */
776 inf
->vfork_parent
->vfork_child
= NULL
;
779 inf
->vfork_parent
= NULL
;
781 gdb_assert (current_program_space
== inf
->pspace
);
783 if (non_stop
&& resume_parent
!= -1)
785 /* If the user wanted the parent to be running, let it go
787 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
790 fprintf_unfiltered (gdb_stdlog
,
791 "infrun: resuming vfork parent process %d\n",
794 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
796 do_cleanups (old_chain
);
801 /* Enum strings for "set|show displaced-stepping". */
803 static const char follow_exec_mode_new
[] = "new";
804 static const char follow_exec_mode_same
[] = "same";
805 static const char *const follow_exec_mode_names
[] =
807 follow_exec_mode_new
,
808 follow_exec_mode_same
,
812 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
814 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
815 struct cmd_list_element
*c
, const char *value
)
817 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
820 /* EXECD_PATHNAME is assumed to be non-NULL. */
823 follow_exec (ptid_t pid
, char *execd_pathname
)
825 struct thread_info
*th
= inferior_thread ();
826 struct inferior
*inf
= current_inferior ();
828 /* This is an exec event that we actually wish to pay attention to.
829 Refresh our symbol table to the newly exec'd program, remove any
832 If there are breakpoints, they aren't really inserted now,
833 since the exec() transformed our inferior into a fresh set
836 We want to preserve symbolic breakpoints on the list, since
837 we have hopes that they can be reset after the new a.out's
838 symbol table is read.
840 However, any "raw" breakpoints must be removed from the list
841 (e.g., the solib bp's), since their address is probably invalid
844 And, we DON'T want to call delete_breakpoints() here, since
845 that may write the bp's "shadow contents" (the instruction
846 value that was overwritten witha TRAP instruction). Since
847 we now have a new a.out, those shadow contents aren't valid. */
849 mark_breakpoints_out ();
851 update_breakpoints_after_exec ();
853 /* If there was one, it's gone now. We cannot truly step-to-next
854 statement through an exec(). */
855 th
->control
.step_resume_breakpoint
= NULL
;
856 th
->control
.exception_resume_breakpoint
= NULL
;
857 th
->control
.step_range_start
= 0;
858 th
->control
.step_range_end
= 0;
860 /* The target reports the exec event to the main thread, even if
861 some other thread does the exec, and even if the main thread was
862 already stopped --- if debugging in non-stop mode, it's possible
863 the user had the main thread held stopped in the previous image
864 --- release it now. This is the same behavior as step-over-exec
865 with scheduler-locking on in all-stop mode. */
866 th
->stop_requested
= 0;
868 /* What is this a.out's name? */
869 printf_unfiltered (_("%s is executing new program: %s\n"),
870 target_pid_to_str (inferior_ptid
),
873 /* We've followed the inferior through an exec. Therefore, the
874 inferior has essentially been killed & reborn. */
876 gdb_flush (gdb_stdout
);
878 breakpoint_init_inferior (inf_execd
);
880 if (gdb_sysroot
&& *gdb_sysroot
)
882 char *name
= alloca (strlen (gdb_sysroot
)
883 + strlen (execd_pathname
)
886 strcpy (name
, gdb_sysroot
);
887 strcat (name
, execd_pathname
);
888 execd_pathname
= name
;
891 /* Reset the shared library package. This ensures that we get a
892 shlib event when the child reaches "_start", at which point the
893 dld will have had a chance to initialize the child. */
894 /* Also, loading a symbol file below may trigger symbol lookups, and
895 we don't want those to be satisfied by the libraries of the
896 previous incarnation of this process. */
897 no_shared_libraries (NULL
, 0);
899 if (follow_exec_mode_string
== follow_exec_mode_new
)
901 struct program_space
*pspace
;
903 /* The user wants to keep the old inferior and program spaces
904 around. Create a new fresh one, and switch to it. */
906 inf
= add_inferior (current_inferior ()->pid
);
907 pspace
= add_program_space (maybe_new_address_space ());
908 inf
->pspace
= pspace
;
909 inf
->aspace
= pspace
->aspace
;
911 exit_inferior_num_silent (current_inferior ()->num
);
913 set_current_inferior (inf
);
914 set_current_program_space (pspace
);
917 gdb_assert (current_program_space
== inf
->pspace
);
919 /* That a.out is now the one to use. */
920 exec_file_attach (execd_pathname
, 0);
922 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
923 (Position Independent Executable) main symbol file will get applied by
924 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
925 the breakpoints with the zero displacement. */
927 symbol_file_add (execd_pathname
,
929 | SYMFILE_MAINLINE
| SYMFILE_DEFER_BP_RESET
),
932 if ((inf
->symfile_flags
& SYMFILE_NO_READ
) == 0)
933 set_initial_language ();
935 #ifdef SOLIB_CREATE_INFERIOR_HOOK
936 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
938 solib_create_inferior_hook (0);
941 jit_inferior_created_hook ();
943 breakpoint_re_set ();
945 /* Reinsert all breakpoints. (Those which were symbolic have
946 been reset to the proper address in the new a.out, thanks
947 to symbol_file_command...). */
948 insert_breakpoints ();
950 /* The next resume of this inferior should bring it to the shlib
951 startup breakpoints. (If the user had also set bp's on
952 "main" from the old (parent) process, then they'll auto-
953 matically get reset there in the new process.). */
956 /* Non-zero if we just simulating a single-step. This is needed
957 because we cannot remove the breakpoints in the inferior process
958 until after the `wait' in `wait_for_inferior'. */
959 static int singlestep_breakpoints_inserted_p
= 0;
961 /* The thread we inserted single-step breakpoints for. */
962 static ptid_t singlestep_ptid
;
964 /* PC when we started this single-step. */
965 static CORE_ADDR singlestep_pc
;
967 /* If another thread hit the singlestep breakpoint, we save the original
968 thread here so that we can resume single-stepping it later. */
969 static ptid_t saved_singlestep_ptid
;
970 static int stepping_past_singlestep_breakpoint
;
972 /* If not equal to null_ptid, this means that after stepping over breakpoint
973 is finished, we need to switch to deferred_step_ptid, and step it.
975 The use case is when one thread has hit a breakpoint, and then the user
976 has switched to another thread and issued 'step'. We need to step over
977 breakpoint in the thread which hit the breakpoint, but then continue
978 stepping the thread user has selected. */
979 static ptid_t deferred_step_ptid
;
981 /* Displaced stepping. */
983 /* In non-stop debugging mode, we must take special care to manage
984 breakpoints properly; in particular, the traditional strategy for
985 stepping a thread past a breakpoint it has hit is unsuitable.
986 'Displaced stepping' is a tactic for stepping one thread past a
987 breakpoint it has hit while ensuring that other threads running
988 concurrently will hit the breakpoint as they should.
990 The traditional way to step a thread T off a breakpoint in a
991 multi-threaded program in all-stop mode is as follows:
993 a0) Initially, all threads are stopped, and breakpoints are not
995 a1) We single-step T, leaving breakpoints uninserted.
996 a2) We insert breakpoints, and resume all threads.
998 In non-stop debugging, however, this strategy is unsuitable: we
999 don't want to have to stop all threads in the system in order to
1000 continue or step T past a breakpoint. Instead, we use displaced
1003 n0) Initially, T is stopped, other threads are running, and
1004 breakpoints are inserted.
1005 n1) We copy the instruction "under" the breakpoint to a separate
1006 location, outside the main code stream, making any adjustments
1007 to the instruction, register, and memory state as directed by
1009 n2) We single-step T over the instruction at its new location.
1010 n3) We adjust the resulting register and memory state as directed
1011 by T's architecture. This includes resetting T's PC to point
1012 back into the main instruction stream.
1015 This approach depends on the following gdbarch methods:
1017 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1018 indicate where to copy the instruction, and how much space must
1019 be reserved there. We use these in step n1.
1021 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1022 address, and makes any necessary adjustments to the instruction,
1023 register contents, and memory. We use this in step n1.
1025 - gdbarch_displaced_step_fixup adjusts registers and memory after
1026 we have successfuly single-stepped the instruction, to yield the
1027 same effect the instruction would have had if we had executed it
1028 at its original address. We use this in step n3.
1030 - gdbarch_displaced_step_free_closure provides cleanup.
1032 The gdbarch_displaced_step_copy_insn and
1033 gdbarch_displaced_step_fixup functions must be written so that
1034 copying an instruction with gdbarch_displaced_step_copy_insn,
1035 single-stepping across the copied instruction, and then applying
1036 gdbarch_displaced_insn_fixup should have the same effects on the
1037 thread's memory and registers as stepping the instruction in place
1038 would have. Exactly which responsibilities fall to the copy and
1039 which fall to the fixup is up to the author of those functions.
1041 See the comments in gdbarch.sh for details.
1043 Note that displaced stepping and software single-step cannot
1044 currently be used in combination, although with some care I think
1045 they could be made to. Software single-step works by placing
1046 breakpoints on all possible subsequent instructions; if the
1047 displaced instruction is a PC-relative jump, those breakpoints
1048 could fall in very strange places --- on pages that aren't
1049 executable, or at addresses that are not proper instruction
1050 boundaries. (We do generally let other threads run while we wait
1051 to hit the software single-step breakpoint, and they might
1052 encounter such a corrupted instruction.) One way to work around
1053 this would be to have gdbarch_displaced_step_copy_insn fully
1054 simulate the effect of PC-relative instructions (and return NULL)
1055 on architectures that use software single-stepping.
1057 In non-stop mode, we can have independent and simultaneous step
1058 requests, so more than one thread may need to simultaneously step
1059 over a breakpoint. The current implementation assumes there is
1060 only one scratch space per process. In this case, we have to
1061 serialize access to the scratch space. If thread A wants to step
1062 over a breakpoint, but we are currently waiting for some other
1063 thread to complete a displaced step, we leave thread A stopped and
1064 place it in the displaced_step_request_queue. Whenever a displaced
1065 step finishes, we pick the next thread in the queue and start a new
1066 displaced step operation on it. See displaced_step_prepare and
1067 displaced_step_fixup for details. */
1069 struct displaced_step_request
1072 struct displaced_step_request
*next
;
1075 /* Per-inferior displaced stepping state. */
1076 struct displaced_step_inferior_state
1078 /* Pointer to next in linked list. */
1079 struct displaced_step_inferior_state
*next
;
1081 /* The process this displaced step state refers to. */
1084 /* A queue of pending displaced stepping requests. One entry per
1085 thread that needs to do a displaced step. */
1086 struct displaced_step_request
*step_request_queue
;
1088 /* If this is not null_ptid, this is the thread carrying out a
1089 displaced single-step in process PID. This thread's state will
1090 require fixing up once it has completed its step. */
1093 /* The architecture the thread had when we stepped it. */
1094 struct gdbarch
*step_gdbarch
;
1096 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1097 for post-step cleanup. */
1098 struct displaced_step_closure
*step_closure
;
1100 /* The address of the original instruction, and the copy we
1102 CORE_ADDR step_original
, step_copy
;
1104 /* Saved contents of copy area. */
1105 gdb_byte
*step_saved_copy
;
1108 /* The list of states of processes involved in displaced stepping
1110 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1112 /* Get the displaced stepping state of process PID. */
1114 static struct displaced_step_inferior_state
*
1115 get_displaced_stepping_state (int pid
)
1117 struct displaced_step_inferior_state
*state
;
1119 for (state
= displaced_step_inferior_states
;
1121 state
= state
->next
)
1122 if (state
->pid
== pid
)
1128 /* Add a new displaced stepping state for process PID to the displaced
1129 stepping state list, or return a pointer to an already existing
1130 entry, if it already exists. Never returns NULL. */
1132 static struct displaced_step_inferior_state
*
1133 add_displaced_stepping_state (int pid
)
1135 struct displaced_step_inferior_state
*state
;
1137 for (state
= displaced_step_inferior_states
;
1139 state
= state
->next
)
1140 if (state
->pid
== pid
)
1143 state
= xcalloc (1, sizeof (*state
));
1145 state
->next
= displaced_step_inferior_states
;
1146 displaced_step_inferior_states
= state
;
1151 /* If inferior is in displaced stepping, and ADDR equals to starting address
1152 of copy area, return corresponding displaced_step_closure. Otherwise,
1155 struct displaced_step_closure
*
1156 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1158 struct displaced_step_inferior_state
*displaced
1159 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1161 /* If checking the mode of displaced instruction in copy area. */
1162 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1163 && (displaced
->step_copy
== addr
))
1164 return displaced
->step_closure
;
1169 /* Remove the displaced stepping state of process PID. */
1172 remove_displaced_stepping_state (int pid
)
1174 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1176 gdb_assert (pid
!= 0);
1178 it
= displaced_step_inferior_states
;
1179 prev_next_p
= &displaced_step_inferior_states
;
1184 *prev_next_p
= it
->next
;
1189 prev_next_p
= &it
->next
;
1195 infrun_inferior_exit (struct inferior
*inf
)
1197 remove_displaced_stepping_state (inf
->pid
);
1200 /* If ON, and the architecture supports it, GDB will use displaced
1201 stepping to step over breakpoints. If OFF, or if the architecture
1202 doesn't support it, GDB will instead use the traditional
1203 hold-and-step approach. If AUTO (which is the default), GDB will
1204 decide which technique to use to step over breakpoints depending on
1205 which of all-stop or non-stop mode is active --- displaced stepping
1206 in non-stop mode; hold-and-step in all-stop mode. */
1208 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1211 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1212 struct cmd_list_element
*c
,
1215 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1216 fprintf_filtered (file
,
1217 _("Debugger's willingness to use displaced stepping "
1218 "to step over breakpoints is %s (currently %s).\n"),
1219 value
, non_stop
? "on" : "off");
1221 fprintf_filtered (file
,
1222 _("Debugger's willingness to use displaced stepping "
1223 "to step over breakpoints is %s.\n"), value
);
1226 /* Return non-zero if displaced stepping can/should be used to step
1227 over breakpoints. */
1230 use_displaced_stepping (struct gdbarch
*gdbarch
)
1232 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1233 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1234 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1235 && !RECORD_IS_USED
);
1238 /* Clean out any stray displaced stepping state. */
1240 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1242 /* Indicate that there is no cleanup pending. */
1243 displaced
->step_ptid
= null_ptid
;
1245 if (displaced
->step_closure
)
1247 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1248 displaced
->step_closure
);
1249 displaced
->step_closure
= NULL
;
1254 displaced_step_clear_cleanup (void *arg
)
1256 struct displaced_step_inferior_state
*state
= arg
;
1258 displaced_step_clear (state
);
1261 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1263 displaced_step_dump_bytes (struct ui_file
*file
,
1264 const gdb_byte
*buf
,
1269 for (i
= 0; i
< len
; i
++)
1270 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1271 fputs_unfiltered ("\n", file
);
1274 /* Prepare to single-step, using displaced stepping.
1276 Note that we cannot use displaced stepping when we have a signal to
1277 deliver. If we have a signal to deliver and an instruction to step
1278 over, then after the step, there will be no indication from the
1279 target whether the thread entered a signal handler or ignored the
1280 signal and stepped over the instruction successfully --- both cases
1281 result in a simple SIGTRAP. In the first case we mustn't do a
1282 fixup, and in the second case we must --- but we can't tell which.
1283 Comments in the code for 'random signals' in handle_inferior_event
1284 explain how we handle this case instead.
1286 Returns 1 if preparing was successful -- this thread is going to be
1287 stepped now; or 0 if displaced stepping this thread got queued. */
1289 displaced_step_prepare (ptid_t ptid
)
1291 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1292 struct regcache
*regcache
= get_thread_regcache (ptid
);
1293 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1294 CORE_ADDR original
, copy
;
1296 struct displaced_step_closure
*closure
;
1297 struct displaced_step_inferior_state
*displaced
;
1300 /* We should never reach this function if the architecture does not
1301 support displaced stepping. */
1302 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1304 /* We have to displaced step one thread at a time, as we only have
1305 access to a single scratch space per inferior. */
1307 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1309 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1311 /* Already waiting for a displaced step to finish. Defer this
1312 request and place in queue. */
1313 struct displaced_step_request
*req
, *new_req
;
1315 if (debug_displaced
)
1316 fprintf_unfiltered (gdb_stdlog
,
1317 "displaced: defering step of %s\n",
1318 target_pid_to_str (ptid
));
1320 new_req
= xmalloc (sizeof (*new_req
));
1321 new_req
->ptid
= ptid
;
1322 new_req
->next
= NULL
;
1324 if (displaced
->step_request_queue
)
1326 for (req
= displaced
->step_request_queue
;
1330 req
->next
= new_req
;
1333 displaced
->step_request_queue
= new_req
;
1339 if (debug_displaced
)
1340 fprintf_unfiltered (gdb_stdlog
,
1341 "displaced: stepping %s now\n",
1342 target_pid_to_str (ptid
));
1345 displaced_step_clear (displaced
);
1347 old_cleanups
= save_inferior_ptid ();
1348 inferior_ptid
= ptid
;
1350 original
= regcache_read_pc (regcache
);
1352 copy
= gdbarch_displaced_step_location (gdbarch
);
1353 len
= gdbarch_max_insn_length (gdbarch
);
1355 /* Save the original contents of the copy area. */
1356 displaced
->step_saved_copy
= xmalloc (len
);
1357 ignore_cleanups
= make_cleanup (free_current_contents
,
1358 &displaced
->step_saved_copy
);
1359 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1361 throw_error (MEMORY_ERROR
,
1362 _("Error accessing memory address %s (%s) for "
1363 "displaced-stepping scratch space."),
1364 paddress (gdbarch
, copy
), safe_strerror (status
));
1365 if (debug_displaced
)
1367 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1368 paddress (gdbarch
, copy
));
1369 displaced_step_dump_bytes (gdb_stdlog
,
1370 displaced
->step_saved_copy
,
1374 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1375 original
, copy
, regcache
);
1377 /* We don't support the fully-simulated case at present. */
1378 gdb_assert (closure
);
1380 /* Save the information we need to fix things up if the step
1382 displaced
->step_ptid
= ptid
;
1383 displaced
->step_gdbarch
= gdbarch
;
1384 displaced
->step_closure
= closure
;
1385 displaced
->step_original
= original
;
1386 displaced
->step_copy
= copy
;
1388 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1390 /* Resume execution at the copy. */
1391 regcache_write_pc (regcache
, copy
);
1393 discard_cleanups (ignore_cleanups
);
1395 do_cleanups (old_cleanups
);
1397 if (debug_displaced
)
1398 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1399 paddress (gdbarch
, copy
));
1405 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1406 const gdb_byte
*myaddr
, int len
)
1408 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1410 inferior_ptid
= ptid
;
1411 write_memory (memaddr
, myaddr
, len
);
1412 do_cleanups (ptid_cleanup
);
1415 /* Restore the contents of the copy area for thread PTID. */
1418 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1421 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1423 write_memory_ptid (ptid
, displaced
->step_copy
,
1424 displaced
->step_saved_copy
, len
);
1425 if (debug_displaced
)
1426 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1427 target_pid_to_str (ptid
),
1428 paddress (displaced
->step_gdbarch
,
1429 displaced
->step_copy
));
1433 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1435 struct cleanup
*old_cleanups
;
1436 struct displaced_step_inferior_state
*displaced
1437 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1439 /* Was any thread of this process doing a displaced step? */
1440 if (displaced
== NULL
)
1443 /* Was this event for the pid we displaced? */
1444 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1445 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1448 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1450 displaced_step_restore (displaced
, displaced
->step_ptid
);
1452 /* Did the instruction complete successfully? */
1453 if (signal
== GDB_SIGNAL_TRAP
)
1455 /* Fix up the resulting state. */
1456 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1457 displaced
->step_closure
,
1458 displaced
->step_original
,
1459 displaced
->step_copy
,
1460 get_thread_regcache (displaced
->step_ptid
));
1464 /* Since the instruction didn't complete, all we can do is
1466 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1467 CORE_ADDR pc
= regcache_read_pc (regcache
);
1469 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1470 regcache_write_pc (regcache
, pc
);
1473 do_cleanups (old_cleanups
);
1475 displaced
->step_ptid
= null_ptid
;
1477 /* Are there any pending displaced stepping requests? If so, run
1478 one now. Leave the state object around, since we're likely to
1479 need it again soon. */
1480 while (displaced
->step_request_queue
)
1482 struct displaced_step_request
*head
;
1484 struct regcache
*regcache
;
1485 struct gdbarch
*gdbarch
;
1486 CORE_ADDR actual_pc
;
1487 struct address_space
*aspace
;
1489 head
= displaced
->step_request_queue
;
1491 displaced
->step_request_queue
= head
->next
;
1494 context_switch (ptid
);
1496 regcache
= get_thread_regcache (ptid
);
1497 actual_pc
= regcache_read_pc (regcache
);
1498 aspace
= get_regcache_aspace (regcache
);
1500 if (breakpoint_here_p (aspace
, actual_pc
))
1502 if (debug_displaced
)
1503 fprintf_unfiltered (gdb_stdlog
,
1504 "displaced: stepping queued %s now\n",
1505 target_pid_to_str (ptid
));
1507 displaced_step_prepare (ptid
);
1509 gdbarch
= get_regcache_arch (regcache
);
1511 if (debug_displaced
)
1513 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1516 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1517 paddress (gdbarch
, actual_pc
));
1518 read_memory (actual_pc
, buf
, sizeof (buf
));
1519 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1522 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1523 displaced
->step_closure
))
1524 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1526 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1528 /* Done, we're stepping a thread. */
1534 struct thread_info
*tp
= inferior_thread ();
1536 /* The breakpoint we were sitting under has since been
1538 tp
->control
.trap_expected
= 0;
1540 /* Go back to what we were trying to do. */
1541 step
= currently_stepping (tp
);
1543 if (debug_displaced
)
1544 fprintf_unfiltered (gdb_stdlog
,
1545 "displaced: breakpoint is gone: %s, step(%d)\n",
1546 target_pid_to_str (tp
->ptid
), step
);
1548 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1549 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1551 /* This request was discarded. See if there's any other
1552 thread waiting for its turn. */
1557 /* Update global variables holding ptids to hold NEW_PTID if they were
1558 holding OLD_PTID. */
1560 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1562 struct displaced_step_request
*it
;
1563 struct displaced_step_inferior_state
*displaced
;
1565 if (ptid_equal (inferior_ptid
, old_ptid
))
1566 inferior_ptid
= new_ptid
;
1568 if (ptid_equal (singlestep_ptid
, old_ptid
))
1569 singlestep_ptid
= new_ptid
;
1571 if (ptid_equal (deferred_step_ptid
, old_ptid
))
1572 deferred_step_ptid
= new_ptid
;
1574 for (displaced
= displaced_step_inferior_states
;
1576 displaced
= displaced
->next
)
1578 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1579 displaced
->step_ptid
= new_ptid
;
1581 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1582 if (ptid_equal (it
->ptid
, old_ptid
))
1583 it
->ptid
= new_ptid
;
1590 /* Things to clean up if we QUIT out of resume (). */
1592 resume_cleanups (void *ignore
)
1597 static const char schedlock_off
[] = "off";
1598 static const char schedlock_on
[] = "on";
1599 static const char schedlock_step
[] = "step";
1600 static const char *const scheduler_enums
[] = {
1606 static const char *scheduler_mode
= schedlock_off
;
1608 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1609 struct cmd_list_element
*c
, const char *value
)
1611 fprintf_filtered (file
,
1612 _("Mode for locking scheduler "
1613 "during execution is \"%s\".\n"),
1618 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1620 if (!target_can_lock_scheduler
)
1622 scheduler_mode
= schedlock_off
;
1623 error (_("Target '%s' cannot support this command."), target_shortname
);
1627 /* True if execution commands resume all threads of all processes by
1628 default; otherwise, resume only threads of the current inferior
1630 int sched_multi
= 0;
1632 /* Try to setup for software single stepping over the specified location.
1633 Return 1 if target_resume() should use hardware single step.
1635 GDBARCH the current gdbarch.
1636 PC the location to step over. */
1639 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1643 if (execution_direction
== EXEC_FORWARD
1644 && gdbarch_software_single_step_p (gdbarch
)
1645 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1648 /* Do not pull these breakpoints until after a `wait' in
1649 `wait_for_inferior'. */
1650 singlestep_breakpoints_inserted_p
= 1;
1651 singlestep_ptid
= inferior_ptid
;
1657 /* Return a ptid representing the set of threads that we will proceed,
1658 in the perspective of the user/frontend. We may actually resume
1659 fewer threads at first, e.g., if a thread is stopped at a
1660 breakpoint that needs stepping-off, but that should not be visible
1661 to the user/frontend, and neither should the frontend/user be
1662 allowed to proceed any of the threads that happen to be stopped for
1663 internal run control handling, if a previous command wanted them
1667 user_visible_resume_ptid (int step
)
1669 /* By default, resume all threads of all processes. */
1670 ptid_t resume_ptid
= RESUME_ALL
;
1672 /* Maybe resume only all threads of the current process. */
1673 if (!sched_multi
&& target_supports_multi_process ())
1675 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1678 /* Maybe resume a single thread after all. */
1681 /* With non-stop mode on, threads are always handled
1683 resume_ptid
= inferior_ptid
;
1685 else if ((scheduler_mode
== schedlock_on
)
1686 || (scheduler_mode
== schedlock_step
1687 && (step
|| singlestep_breakpoints_inserted_p
)))
1689 /* User-settable 'scheduler' mode requires solo thread resume. */
1690 resume_ptid
= inferior_ptid
;
1696 /* Resume the inferior, but allow a QUIT. This is useful if the user
1697 wants to interrupt some lengthy single-stepping operation
1698 (for child processes, the SIGINT goes to the inferior, and so
1699 we get a SIGINT random_signal, but for remote debugging and perhaps
1700 other targets, that's not true).
1702 STEP nonzero if we should step (zero to continue instead).
1703 SIG is the signal to give the inferior (zero for none). */
1705 resume (int step
, enum gdb_signal sig
)
1707 int should_resume
= 1;
1708 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1709 struct regcache
*regcache
= get_current_regcache ();
1710 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1711 struct thread_info
*tp
= inferior_thread ();
1712 CORE_ADDR pc
= regcache_read_pc (regcache
);
1713 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1717 if (current_inferior ()->waiting_for_vfork_done
)
1719 /* Don't try to single-step a vfork parent that is waiting for
1720 the child to get out of the shared memory region (by exec'ing
1721 or exiting). This is particularly important on software
1722 single-step archs, as the child process would trip on the
1723 software single step breakpoint inserted for the parent
1724 process. Since the parent will not actually execute any
1725 instruction until the child is out of the shared region (such
1726 are vfork's semantics), it is safe to simply continue it.
1727 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1728 the parent, and tell it to `keep_going', which automatically
1729 re-sets it stepping. */
1731 fprintf_unfiltered (gdb_stdlog
,
1732 "infrun: resume : clear step\n");
1737 fprintf_unfiltered (gdb_stdlog
,
1738 "infrun: resume (step=%d, signal=%d), "
1739 "trap_expected=%d, current thread [%s] at %s\n",
1740 step
, sig
, tp
->control
.trap_expected
,
1741 target_pid_to_str (inferior_ptid
),
1742 paddress (gdbarch
, pc
));
1744 /* Normally, by the time we reach `resume', the breakpoints are either
1745 removed or inserted, as appropriate. The exception is if we're sitting
1746 at a permanent breakpoint; we need to step over it, but permanent
1747 breakpoints can't be removed. So we have to test for it here. */
1748 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
1750 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1751 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1754 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1755 how to step past a permanent breakpoint on this architecture. Try using\n\
1756 a command like `return' or `jump' to continue execution."));
1759 /* If enabled, step over breakpoints by executing a copy of the
1760 instruction at a different address.
1762 We can't use displaced stepping when we have a signal to deliver;
1763 the comments for displaced_step_prepare explain why. The
1764 comments in the handle_inferior event for dealing with 'random
1765 signals' explain what we do instead.
1767 We can't use displaced stepping when we are waiting for vfork_done
1768 event, displaced stepping breaks the vfork child similarly as single
1769 step software breakpoint. */
1770 if (use_displaced_stepping (gdbarch
)
1771 && (tp
->control
.trap_expected
1772 || (step
&& gdbarch_software_single_step_p (gdbarch
)))
1773 && sig
== GDB_SIGNAL_0
1774 && !current_inferior ()->waiting_for_vfork_done
)
1776 struct displaced_step_inferior_state
*displaced
;
1778 if (!displaced_step_prepare (inferior_ptid
))
1780 /* Got placed in displaced stepping queue. Will be resumed
1781 later when all the currently queued displaced stepping
1782 requests finish. The thread is not executing at this point,
1783 and the call to set_executing will be made later. But we
1784 need to call set_running here, since from frontend point of view,
1785 the thread is running. */
1786 set_running (inferior_ptid
, 1);
1787 discard_cleanups (old_cleanups
);
1791 /* Update pc to reflect the new address from which we will execute
1792 instructions due to displaced stepping. */
1793 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
1795 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1796 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
1797 displaced
->step_closure
);
1800 /* Do we need to do it the hard way, w/temp breakpoints? */
1802 step
= maybe_software_singlestep (gdbarch
, pc
);
1804 /* Currently, our software single-step implementation leads to different
1805 results than hardware single-stepping in one situation: when stepping
1806 into delivering a signal which has an associated signal handler,
1807 hardware single-step will stop at the first instruction of the handler,
1808 while software single-step will simply skip execution of the handler.
1810 For now, this difference in behavior is accepted since there is no
1811 easy way to actually implement single-stepping into a signal handler
1812 without kernel support.
1814 However, there is one scenario where this difference leads to follow-on
1815 problems: if we're stepping off a breakpoint by removing all breakpoints
1816 and then single-stepping. In this case, the software single-step
1817 behavior means that even if there is a *breakpoint* in the signal
1818 handler, GDB still would not stop.
1820 Fortunately, we can at least fix this particular issue. We detect
1821 here the case where we are about to deliver a signal while software
1822 single-stepping with breakpoints removed. In this situation, we
1823 revert the decisions to remove all breakpoints and insert single-
1824 step breakpoints, and instead we install a step-resume breakpoint
1825 at the current address, deliver the signal without stepping, and
1826 once we arrive back at the step-resume breakpoint, actually step
1827 over the breakpoint we originally wanted to step over. */
1828 if (singlestep_breakpoints_inserted_p
1829 && tp
->control
.trap_expected
&& sig
!= GDB_SIGNAL_0
)
1831 /* If we have nested signals or a pending signal is delivered
1832 immediately after a handler returns, might might already have
1833 a step-resume breakpoint set on the earlier handler. We cannot
1834 set another step-resume breakpoint; just continue on until the
1835 original breakpoint is hit. */
1836 if (tp
->control
.step_resume_breakpoint
== NULL
)
1838 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1839 tp
->step_after_step_resume_breakpoint
= 1;
1842 remove_single_step_breakpoints ();
1843 singlestep_breakpoints_inserted_p
= 0;
1845 insert_breakpoints ();
1846 tp
->control
.trap_expected
= 0;
1853 /* If STEP is set, it's a request to use hardware stepping
1854 facilities. But in that case, we should never
1855 use singlestep breakpoint. */
1856 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1858 /* Decide the set of threads to ask the target to resume. Start
1859 by assuming everything will be resumed, than narrow the set
1860 by applying increasingly restricting conditions. */
1861 resume_ptid
= user_visible_resume_ptid (step
);
1863 /* Maybe resume a single thread after all. */
1864 if (singlestep_breakpoints_inserted_p
1865 && stepping_past_singlestep_breakpoint
)
1867 /* The situation here is as follows. In thread T1 we wanted to
1868 single-step. Lacking hardware single-stepping we've
1869 set breakpoint at the PC of the next instruction -- call it
1870 P. After resuming, we've hit that breakpoint in thread T2.
1871 Now we've removed original breakpoint, inserted breakpoint
1872 at P+1, and try to step to advance T2 past breakpoint.
1873 We need to step only T2, as if T1 is allowed to freely run,
1874 it can run past P, and if other threads are allowed to run,
1875 they can hit breakpoint at P+1, and nested hits of single-step
1876 breakpoints is not something we'd want -- that's complicated
1877 to support, and has no value. */
1878 resume_ptid
= inferior_ptid
;
1880 else if ((step
|| singlestep_breakpoints_inserted_p
)
1881 && tp
->control
.trap_expected
)
1883 /* We're allowing a thread to run past a breakpoint it has
1884 hit, by single-stepping the thread with the breakpoint
1885 removed. In which case, we need to single-step only this
1886 thread, and keep others stopped, as they can miss this
1887 breakpoint if allowed to run.
1889 The current code actually removes all breakpoints when
1890 doing this, not just the one being stepped over, so if we
1891 let other threads run, we can actually miss any
1892 breakpoint, not just the one at PC. */
1893 resume_ptid
= inferior_ptid
;
1896 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1898 /* Most targets can step a breakpoint instruction, thus
1899 executing it normally. But if this one cannot, just
1900 continue and we will hit it anyway. */
1901 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
1906 && use_displaced_stepping (gdbarch
)
1907 && tp
->control
.trap_expected
)
1909 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1910 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1911 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1914 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1915 paddress (resume_gdbarch
, actual_pc
));
1916 read_memory (actual_pc
, buf
, sizeof (buf
));
1917 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1920 /* Install inferior's terminal modes. */
1921 target_terminal_inferior ();
1923 /* Avoid confusing the next resume, if the next stop/resume
1924 happens to apply to another thread. */
1925 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1927 /* Advise target which signals may be handled silently. If we have
1928 removed breakpoints because we are stepping over one (which can
1929 happen only if we are not using displaced stepping), we need to
1930 receive all signals to avoid accidentally skipping a breakpoint
1931 during execution of a signal handler. */
1932 if ((step
|| singlestep_breakpoints_inserted_p
)
1933 && tp
->control
.trap_expected
1934 && !use_displaced_stepping (gdbarch
))
1935 target_pass_signals (0, NULL
);
1937 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
1939 target_resume (resume_ptid
, step
, sig
);
1942 discard_cleanups (old_cleanups
);
1947 /* Clear out all variables saying what to do when inferior is continued.
1948 First do this, then set the ones you want, then call `proceed'. */
1951 clear_proceed_status_thread (struct thread_info
*tp
)
1954 fprintf_unfiltered (gdb_stdlog
,
1955 "infrun: clear_proceed_status_thread (%s)\n",
1956 target_pid_to_str (tp
->ptid
));
1958 tp
->control
.trap_expected
= 0;
1959 tp
->control
.step_range_start
= 0;
1960 tp
->control
.step_range_end
= 0;
1961 tp
->control
.step_frame_id
= null_frame_id
;
1962 tp
->control
.step_stack_frame_id
= null_frame_id
;
1963 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1964 tp
->stop_requested
= 0;
1966 tp
->control
.stop_step
= 0;
1968 tp
->control
.proceed_to_finish
= 0;
1970 /* Discard any remaining commands or status from previous stop. */
1971 bpstat_clear (&tp
->control
.stop_bpstat
);
1975 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
1977 if (is_exited (tp
->ptid
))
1980 clear_proceed_status_thread (tp
);
1985 clear_proceed_status (void)
1989 /* In all-stop mode, delete the per-thread status of all
1990 threads, even if inferior_ptid is null_ptid, there may be
1991 threads on the list. E.g., we may be launching a new
1992 process, while selecting the executable. */
1993 iterate_over_threads (clear_proceed_status_callback
, NULL
);
1996 if (!ptid_equal (inferior_ptid
, null_ptid
))
1998 struct inferior
*inferior
;
2002 /* If in non-stop mode, only delete the per-thread status of
2003 the current thread. */
2004 clear_proceed_status_thread (inferior_thread ());
2007 inferior
= current_inferior ();
2008 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2011 stop_after_trap
= 0;
2013 observer_notify_about_to_proceed ();
2017 regcache_xfree (stop_registers
);
2018 stop_registers
= NULL
;
2022 /* Check the current thread against the thread that reported the most recent
2023 event. If a step-over is required return TRUE and set the current thread
2024 to the old thread. Otherwise return FALSE.
2026 This should be suitable for any targets that support threads. */
2029 prepare_to_proceed (int step
)
2032 struct target_waitstatus wait_status
;
2033 int schedlock_enabled
;
2035 /* With non-stop mode on, threads are always handled individually. */
2036 gdb_assert (! non_stop
);
2038 /* Get the last target status returned by target_wait(). */
2039 get_last_target_status (&wait_ptid
, &wait_status
);
2041 /* Make sure we were stopped at a breakpoint. */
2042 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
2043 || (wait_status
.value
.sig
!= GDB_SIGNAL_TRAP
2044 && wait_status
.value
.sig
!= GDB_SIGNAL_ILL
2045 && wait_status
.value
.sig
!= GDB_SIGNAL_SEGV
2046 && wait_status
.value
.sig
!= GDB_SIGNAL_EMT
))
2051 schedlock_enabled
= (scheduler_mode
== schedlock_on
2052 || (scheduler_mode
== schedlock_step
2055 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
2056 if (schedlock_enabled
)
2059 /* Don't switch over if we're about to resume some other process
2060 other than WAIT_PTID's, and schedule-multiple is off. */
2062 && ptid_get_pid (wait_ptid
) != ptid_get_pid (inferior_ptid
))
2065 /* Switched over from WAIT_PID. */
2066 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
2067 && !ptid_equal (inferior_ptid
, wait_ptid
))
2069 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
2071 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2072 regcache_read_pc (regcache
)))
2074 /* If stepping, remember current thread to switch back to. */
2076 deferred_step_ptid
= inferior_ptid
;
2078 /* Switch back to WAIT_PID thread. */
2079 switch_to_thread (wait_ptid
);
2082 fprintf_unfiltered (gdb_stdlog
,
2083 "infrun: prepare_to_proceed (step=%d), "
2084 "switched to [%s]\n",
2085 step
, target_pid_to_str (inferior_ptid
));
2087 /* We return 1 to indicate that there is a breakpoint here,
2088 so we need to step over it before continuing to avoid
2089 hitting it straight away. */
2097 /* Basic routine for continuing the program in various fashions.
2099 ADDR is the address to resume at, or -1 for resume where stopped.
2100 SIGGNAL is the signal to give it, or 0 for none,
2101 or -1 for act according to how it stopped.
2102 STEP is nonzero if should trap after one instruction.
2103 -1 means return after that and print nothing.
2104 You should probably set various step_... variables
2105 before calling here, if you are stepping.
2107 You should call clear_proceed_status before calling proceed. */
2110 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
, int step
)
2112 struct regcache
*regcache
;
2113 struct gdbarch
*gdbarch
;
2114 struct thread_info
*tp
;
2116 struct address_space
*aspace
;
2119 /* If we're stopped at a fork/vfork, follow the branch set by the
2120 "set follow-fork-mode" command; otherwise, we'll just proceed
2121 resuming the current thread. */
2122 if (!follow_fork ())
2124 /* The target for some reason decided not to resume. */
2126 if (target_can_async_p ())
2127 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2131 /* We'll update this if & when we switch to a new thread. */
2132 previous_inferior_ptid
= inferior_ptid
;
2134 regcache
= get_current_regcache ();
2135 gdbarch
= get_regcache_arch (regcache
);
2136 aspace
= get_regcache_aspace (regcache
);
2137 pc
= regcache_read_pc (regcache
);
2140 step_start_function
= find_pc_function (pc
);
2142 stop_after_trap
= 1;
2144 if (addr
== (CORE_ADDR
) -1)
2146 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
2147 && execution_direction
!= EXEC_REVERSE
)
2148 /* There is a breakpoint at the address we will resume at,
2149 step one instruction before inserting breakpoints so that
2150 we do not stop right away (and report a second hit at this
2153 Note, we don't do this in reverse, because we won't
2154 actually be executing the breakpoint insn anyway.
2155 We'll be (un-)executing the previous instruction. */
2158 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2159 && gdbarch_single_step_through_delay (gdbarch
,
2160 get_current_frame ()))
2161 /* We stepped onto an instruction that needs to be stepped
2162 again before re-inserting the breakpoint, do so. */
2167 regcache_write_pc (regcache
, addr
);
2171 fprintf_unfiltered (gdb_stdlog
,
2172 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
2173 paddress (gdbarch
, addr
), siggnal
, step
);
2176 /* In non-stop, each thread is handled individually. The context
2177 must already be set to the right thread here. */
2181 /* In a multi-threaded task we may select another thread and
2182 then continue or step.
2184 But if the old thread was stopped at a breakpoint, it will
2185 immediately cause another breakpoint stop without any
2186 execution (i.e. it will report a breakpoint hit incorrectly).
2187 So we must step over it first.
2189 prepare_to_proceed checks the current thread against the
2190 thread that reported the most recent event. If a step-over
2191 is required it returns TRUE and sets the current thread to
2193 if (prepare_to_proceed (step
))
2197 /* prepare_to_proceed may change the current thread. */
2198 tp
= inferior_thread ();
2202 tp
->control
.trap_expected
= 1;
2203 /* If displaced stepping is enabled, we can step over the
2204 breakpoint without hitting it, so leave all breakpoints
2205 inserted. Otherwise we need to disable all breakpoints, step
2206 one instruction, and then re-add them when that step is
2208 if (!use_displaced_stepping (gdbarch
))
2209 remove_breakpoints ();
2212 /* We can insert breakpoints if we're not trying to step over one,
2213 or if we are stepping over one but we're using displaced stepping
2215 if (! tp
->control
.trap_expected
|| use_displaced_stepping (gdbarch
))
2216 insert_breakpoints ();
2220 /* Pass the last stop signal to the thread we're resuming,
2221 irrespective of whether the current thread is the thread that
2222 got the last event or not. This was historically GDB's
2223 behaviour before keeping a stop_signal per thread. */
2225 struct thread_info
*last_thread
;
2227 struct target_waitstatus last_status
;
2229 get_last_target_status (&last_ptid
, &last_status
);
2230 if (!ptid_equal (inferior_ptid
, last_ptid
)
2231 && !ptid_equal (last_ptid
, null_ptid
)
2232 && !ptid_equal (last_ptid
, minus_one_ptid
))
2234 last_thread
= find_thread_ptid (last_ptid
);
2237 tp
->suspend
.stop_signal
= last_thread
->suspend
.stop_signal
;
2238 last_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2243 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2244 tp
->suspend
.stop_signal
= siggnal
;
2245 /* If this signal should not be seen by program,
2246 give it zero. Used for debugging signals. */
2247 else if (!signal_program
[tp
->suspend
.stop_signal
])
2248 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2250 annotate_starting ();
2252 /* Make sure that output from GDB appears before output from the
2254 gdb_flush (gdb_stdout
);
2256 /* Refresh prev_pc value just prior to resuming. This used to be
2257 done in stop_stepping, however, setting prev_pc there did not handle
2258 scenarios such as inferior function calls or returning from
2259 a function via the return command. In those cases, the prev_pc
2260 value was not set properly for subsequent commands. The prev_pc value
2261 is used to initialize the starting line number in the ecs. With an
2262 invalid value, the gdb next command ends up stopping at the position
2263 represented by the next line table entry past our start position.
2264 On platforms that generate one line table entry per line, this
2265 is not a problem. However, on the ia64, the compiler generates
2266 extraneous line table entries that do not increase the line number.
2267 When we issue the gdb next command on the ia64 after an inferior call
2268 or a return command, we often end up a few instructions forward, still
2269 within the original line we started.
2271 An attempt was made to refresh the prev_pc at the same time the
2272 execution_control_state is initialized (for instance, just before
2273 waiting for an inferior event). But this approach did not work
2274 because of platforms that use ptrace, where the pc register cannot
2275 be read unless the inferior is stopped. At that point, we are not
2276 guaranteed the inferior is stopped and so the regcache_read_pc() call
2277 can fail. Setting the prev_pc value here ensures the value is updated
2278 correctly when the inferior is stopped. */
2279 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2281 /* Fill in with reasonable starting values. */
2282 init_thread_stepping_state (tp
);
2284 /* Reset to normal state. */
2285 init_infwait_state ();
2287 /* Resume inferior. */
2288 resume (oneproc
|| step
|| bpstat_should_step (), tp
->suspend
.stop_signal
);
2290 /* Wait for it to stop (if not standalone)
2291 and in any case decode why it stopped, and act accordingly. */
2292 /* Do this only if we are not using the event loop, or if the target
2293 does not support asynchronous execution. */
2294 if (!target_can_async_p ())
2296 wait_for_inferior ();
2302 /* Start remote-debugging of a machine over a serial link. */
2305 start_remote (int from_tty
)
2307 struct inferior
*inferior
;
2309 inferior
= current_inferior ();
2310 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2312 /* Always go on waiting for the target, regardless of the mode. */
2313 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2314 indicate to wait_for_inferior that a target should timeout if
2315 nothing is returned (instead of just blocking). Because of this,
2316 targets expecting an immediate response need to, internally, set
2317 things up so that the target_wait() is forced to eventually
2319 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2320 differentiate to its caller what the state of the target is after
2321 the initial open has been performed. Here we're assuming that
2322 the target has stopped. It should be possible to eventually have
2323 target_open() return to the caller an indication that the target
2324 is currently running and GDB state should be set to the same as
2325 for an async run. */
2326 wait_for_inferior ();
2328 /* Now that the inferior has stopped, do any bookkeeping like
2329 loading shared libraries. We want to do this before normal_stop,
2330 so that the displayed frame is up to date. */
2331 post_create_inferior (¤t_target
, from_tty
);
2336 /* Initialize static vars when a new inferior begins. */
2339 init_wait_for_inferior (void)
2341 /* These are meaningless until the first time through wait_for_inferior. */
2343 breakpoint_init_inferior (inf_starting
);
2345 clear_proceed_status ();
2347 stepping_past_singlestep_breakpoint
= 0;
2348 deferred_step_ptid
= null_ptid
;
2350 target_last_wait_ptid
= minus_one_ptid
;
2352 previous_inferior_ptid
= inferior_ptid
;
2353 init_infwait_state ();
2355 /* Discard any skipped inlined frames. */
2356 clear_inline_frame_state (minus_one_ptid
);
2360 /* This enum encodes possible reasons for doing a target_wait, so that
2361 wfi can call target_wait in one place. (Ultimately the call will be
2362 moved out of the infinite loop entirely.) */
2366 infwait_normal_state
,
2367 infwait_thread_hop_state
,
2368 infwait_step_watch_state
,
2369 infwait_nonstep_watch_state
2372 /* The PTID we'll do a target_wait on.*/
2375 /* Current inferior wait state. */
2376 enum infwait_states infwait_state
;
2378 /* Data to be passed around while handling an event. This data is
2379 discarded between events. */
2380 struct execution_control_state
2383 /* The thread that got the event, if this was a thread event; NULL
2385 struct thread_info
*event_thread
;
2387 struct target_waitstatus ws
;
2389 int stop_func_filled_in
;
2390 CORE_ADDR stop_func_start
;
2391 CORE_ADDR stop_func_end
;
2392 const char *stop_func_name
;
2396 static void handle_inferior_event (struct execution_control_state
*ecs
);
2398 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2399 struct execution_control_state
*ecs
);
2400 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2401 struct execution_control_state
*ecs
);
2402 static void check_exception_resume (struct execution_control_state
*,
2403 struct frame_info
*);
2405 static void stop_stepping (struct execution_control_state
*ecs
);
2406 static void prepare_to_wait (struct execution_control_state
*ecs
);
2407 static void keep_going (struct execution_control_state
*ecs
);
2409 /* Callback for iterate over threads. If the thread is stopped, but
2410 the user/frontend doesn't know about that yet, go through
2411 normal_stop, as if the thread had just stopped now. ARG points at
2412 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2413 ptid_is_pid(PTID) is true, applies to all threads of the process
2414 pointed at by PTID. Otherwise, apply only to the thread pointed by
2418 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2420 ptid_t ptid
= * (ptid_t
*) arg
;
2422 if ((ptid_equal (info
->ptid
, ptid
)
2423 || ptid_equal (minus_one_ptid
, ptid
)
2424 || (ptid_is_pid (ptid
)
2425 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2426 && is_running (info
->ptid
)
2427 && !is_executing (info
->ptid
))
2429 struct cleanup
*old_chain
;
2430 struct execution_control_state ecss
;
2431 struct execution_control_state
*ecs
= &ecss
;
2433 memset (ecs
, 0, sizeof (*ecs
));
2435 old_chain
= make_cleanup_restore_current_thread ();
2437 /* Go through handle_inferior_event/normal_stop, so we always
2438 have consistent output as if the stop event had been
2440 ecs
->ptid
= info
->ptid
;
2441 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2442 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2443 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2445 handle_inferior_event (ecs
);
2447 if (!ecs
->wait_some_more
)
2449 struct thread_info
*tp
;
2453 /* Finish off the continuations. */
2454 tp
= inferior_thread ();
2455 do_all_intermediate_continuations_thread (tp
, 1);
2456 do_all_continuations_thread (tp
, 1);
2459 do_cleanups (old_chain
);
2465 /* This function is attached as a "thread_stop_requested" observer.
2466 Cleanup local state that assumed the PTID was to be resumed, and
2467 report the stop to the frontend. */
2470 infrun_thread_stop_requested (ptid_t ptid
)
2472 struct displaced_step_inferior_state
*displaced
;
2474 /* PTID was requested to stop. Remove it from the displaced
2475 stepping queue, so we don't try to resume it automatically. */
2477 for (displaced
= displaced_step_inferior_states
;
2479 displaced
= displaced
->next
)
2481 struct displaced_step_request
*it
, **prev_next_p
;
2483 it
= displaced
->step_request_queue
;
2484 prev_next_p
= &displaced
->step_request_queue
;
2487 if (ptid_match (it
->ptid
, ptid
))
2489 *prev_next_p
= it
->next
;
2495 prev_next_p
= &it
->next
;
2502 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2506 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2508 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2509 nullify_last_target_wait_ptid ();
2512 /* Callback for iterate_over_threads. */
2515 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2517 if (is_exited (info
->ptid
))
2520 delete_step_resume_breakpoint (info
);
2521 delete_exception_resume_breakpoint (info
);
2525 /* In all-stop, delete the step resume breakpoint of any thread that
2526 had one. In non-stop, delete the step resume breakpoint of the
2527 thread that just stopped. */
2530 delete_step_thread_step_resume_breakpoint (void)
2532 if (!target_has_execution
2533 || ptid_equal (inferior_ptid
, null_ptid
))
2534 /* If the inferior has exited, we have already deleted the step
2535 resume breakpoints out of GDB's lists. */
2540 /* If in non-stop mode, only delete the step-resume or
2541 longjmp-resume breakpoint of the thread that just stopped
2543 struct thread_info
*tp
= inferior_thread ();
2545 delete_step_resume_breakpoint (tp
);
2546 delete_exception_resume_breakpoint (tp
);
2549 /* In all-stop mode, delete all step-resume and longjmp-resume
2550 breakpoints of any thread that had them. */
2551 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2554 /* A cleanup wrapper. */
2557 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2559 delete_step_thread_step_resume_breakpoint ();
2562 /* Pretty print the results of target_wait, for debugging purposes. */
2565 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2566 const struct target_waitstatus
*ws
)
2568 char *status_string
= target_waitstatus_to_string (ws
);
2569 struct ui_file
*tmp_stream
= mem_fileopen ();
2572 /* The text is split over several lines because it was getting too long.
2573 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2574 output as a unit; we want only one timestamp printed if debug_timestamp
2577 fprintf_unfiltered (tmp_stream
,
2578 "infrun: target_wait (%d", PIDGET (waiton_ptid
));
2579 if (PIDGET (waiton_ptid
) != -1)
2580 fprintf_unfiltered (tmp_stream
,
2581 " [%s]", target_pid_to_str (waiton_ptid
));
2582 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2583 fprintf_unfiltered (tmp_stream
,
2584 "infrun: %d [%s],\n",
2585 PIDGET (result_ptid
), target_pid_to_str (result_ptid
));
2586 fprintf_unfiltered (tmp_stream
,
2590 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2592 /* This uses %s in part to handle %'s in the text, but also to avoid
2593 a gcc error: the format attribute requires a string literal. */
2594 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2596 xfree (status_string
);
2598 ui_file_delete (tmp_stream
);
2601 /* Prepare and stabilize the inferior for detaching it. E.g.,
2602 detaching while a thread is displaced stepping is a recipe for
2603 crashing it, as nothing would readjust the PC out of the scratch
2607 prepare_for_detach (void)
2609 struct inferior
*inf
= current_inferior ();
2610 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
2611 struct cleanup
*old_chain_1
;
2612 struct displaced_step_inferior_state
*displaced
;
2614 displaced
= get_displaced_stepping_state (inf
->pid
);
2616 /* Is any thread of this process displaced stepping? If not,
2617 there's nothing else to do. */
2618 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
2622 fprintf_unfiltered (gdb_stdlog
,
2623 "displaced-stepping in-process while detaching");
2625 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
2628 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
2630 struct cleanup
*old_chain_2
;
2631 struct execution_control_state ecss
;
2632 struct execution_control_state
*ecs
;
2635 memset (ecs
, 0, sizeof (*ecs
));
2637 overlay_cache_invalid
= 1;
2639 if (deprecated_target_wait_hook
)
2640 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
2642 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
2645 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
2647 /* If an error happens while handling the event, propagate GDB's
2648 knowledge of the executing state to the frontend/user running
2650 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
2653 /* Now figure out what to do with the result of the result. */
2654 handle_inferior_event (ecs
);
2656 /* No error, don't finish the state yet. */
2657 discard_cleanups (old_chain_2
);
2659 /* Breakpoints and watchpoints are not installed on the target
2660 at this point, and signals are passed directly to the
2661 inferior, so this must mean the process is gone. */
2662 if (!ecs
->wait_some_more
)
2664 discard_cleanups (old_chain_1
);
2665 error (_("Program exited while detaching"));
2669 discard_cleanups (old_chain_1
);
2672 /* Wait for control to return from inferior to debugger.
2674 If inferior gets a signal, we may decide to start it up again
2675 instead of returning. That is why there is a loop in this function.
2676 When this function actually returns it means the inferior
2677 should be left stopped and GDB should read more commands. */
2680 wait_for_inferior (void)
2682 struct cleanup
*old_cleanups
;
2686 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
2689 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
2693 struct execution_control_state ecss
;
2694 struct execution_control_state
*ecs
= &ecss
;
2695 struct cleanup
*old_chain
;
2697 memset (ecs
, 0, sizeof (*ecs
));
2699 overlay_cache_invalid
= 1;
2701 if (deprecated_target_wait_hook
)
2702 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2704 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2707 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2709 /* If an error happens while handling the event, propagate GDB's
2710 knowledge of the executing state to the frontend/user running
2712 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2714 /* Now figure out what to do with the result of the result. */
2715 handle_inferior_event (ecs
);
2717 /* No error, don't finish the state yet. */
2718 discard_cleanups (old_chain
);
2720 if (!ecs
->wait_some_more
)
2724 do_cleanups (old_cleanups
);
2727 /* Asynchronous version of wait_for_inferior. It is called by the
2728 event loop whenever a change of state is detected on the file
2729 descriptor corresponding to the target. It can be called more than
2730 once to complete a single execution command. In such cases we need
2731 to keep the state in a global variable ECSS. If it is the last time
2732 that this function is called for a single execution command, then
2733 report to the user that the inferior has stopped, and do the
2734 necessary cleanups. */
2737 fetch_inferior_event (void *client_data
)
2739 struct execution_control_state ecss
;
2740 struct execution_control_state
*ecs
= &ecss
;
2741 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2742 struct cleanup
*ts_old_chain
;
2743 int was_sync
= sync_execution
;
2746 memset (ecs
, 0, sizeof (*ecs
));
2748 /* We're handling a live event, so make sure we're doing live
2749 debugging. If we're looking at traceframes while the target is
2750 running, we're going to need to get back to that mode after
2751 handling the event. */
2754 make_cleanup_restore_current_traceframe ();
2755 set_current_traceframe (-1);
2759 /* In non-stop mode, the user/frontend should not notice a thread
2760 switch due to internal events. Make sure we reverse to the
2761 user selected thread and frame after handling the event and
2762 running any breakpoint commands. */
2763 make_cleanup_restore_current_thread ();
2765 overlay_cache_invalid
= 1;
2767 make_cleanup_restore_integer (&execution_direction
);
2768 execution_direction
= target_execution_direction ();
2770 if (deprecated_target_wait_hook
)
2772 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2774 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2777 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2779 /* If an error happens while handling the event, propagate GDB's
2780 knowledge of the executing state to the frontend/user running
2783 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2785 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2787 /* Get executed before make_cleanup_restore_current_thread above to apply
2788 still for the thread which has thrown the exception. */
2789 make_bpstat_clear_actions_cleanup ();
2791 /* Now figure out what to do with the result of the result. */
2792 handle_inferior_event (ecs
);
2794 if (!ecs
->wait_some_more
)
2796 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2798 delete_step_thread_step_resume_breakpoint ();
2800 /* We may not find an inferior if this was a process exit. */
2801 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
2804 if (target_has_execution
2805 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
2806 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2807 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2808 && ecs
->event_thread
->step_multi
2809 && ecs
->event_thread
->control
.stop_step
)
2810 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2813 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2818 /* No error, don't finish the thread states yet. */
2819 discard_cleanups (ts_old_chain
);
2821 /* Revert thread and frame. */
2822 do_cleanups (old_chain
);
2824 /* If the inferior was in sync execution mode, and now isn't,
2825 restore the prompt (a synchronous execution command has finished,
2826 and we're ready for input). */
2827 if (interpreter_async
&& was_sync
&& !sync_execution
)
2828 display_gdb_prompt (0);
2832 && exec_done_display_p
2833 && (ptid_equal (inferior_ptid
, null_ptid
)
2834 || !is_running (inferior_ptid
)))
2835 printf_unfiltered (_("completed.\n"));
2838 /* Record the frame and location we're currently stepping through. */
2840 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2842 struct thread_info
*tp
= inferior_thread ();
2844 tp
->control
.step_frame_id
= get_frame_id (frame
);
2845 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
2847 tp
->current_symtab
= sal
.symtab
;
2848 tp
->current_line
= sal
.line
;
2851 /* Clear context switchable stepping state. */
2854 init_thread_stepping_state (struct thread_info
*tss
)
2856 tss
->stepping_over_breakpoint
= 0;
2857 tss
->step_after_step_resume_breakpoint
= 0;
2860 /* Return the cached copy of the last pid/waitstatus returned by
2861 target_wait()/deprecated_target_wait_hook(). The data is actually
2862 cached by handle_inferior_event(), which gets called immediately
2863 after target_wait()/deprecated_target_wait_hook(). */
2866 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2868 *ptidp
= target_last_wait_ptid
;
2869 *status
= target_last_waitstatus
;
2873 nullify_last_target_wait_ptid (void)
2875 target_last_wait_ptid
= minus_one_ptid
;
2878 /* Switch thread contexts. */
2881 context_switch (ptid_t ptid
)
2883 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
2885 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
2886 target_pid_to_str (inferior_ptid
));
2887 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
2888 target_pid_to_str (ptid
));
2891 switch_to_thread (ptid
);
2895 adjust_pc_after_break (struct execution_control_state
*ecs
)
2897 struct regcache
*regcache
;
2898 struct gdbarch
*gdbarch
;
2899 struct address_space
*aspace
;
2900 CORE_ADDR breakpoint_pc
;
2902 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2903 we aren't, just return.
2905 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2906 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2907 implemented by software breakpoints should be handled through the normal
2910 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2911 different signals (SIGILL or SIGEMT for instance), but it is less
2912 clear where the PC is pointing afterwards. It may not match
2913 gdbarch_decr_pc_after_break. I don't know any specific target that
2914 generates these signals at breakpoints (the code has been in GDB since at
2915 least 1992) so I can not guess how to handle them here.
2917 In earlier versions of GDB, a target with
2918 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2919 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2920 target with both of these set in GDB history, and it seems unlikely to be
2921 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2923 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
2926 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
2929 /* In reverse execution, when a breakpoint is hit, the instruction
2930 under it has already been de-executed. The reported PC always
2931 points at the breakpoint address, so adjusting it further would
2932 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2935 B1 0x08000000 : INSN1
2936 B2 0x08000001 : INSN2
2938 PC -> 0x08000003 : INSN4
2940 Say you're stopped at 0x08000003 as above. Reverse continuing
2941 from that point should hit B2 as below. Reading the PC when the
2942 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2943 been de-executed already.
2945 B1 0x08000000 : INSN1
2946 B2 PC -> 0x08000001 : INSN2
2950 We can't apply the same logic as for forward execution, because
2951 we would wrongly adjust the PC to 0x08000000, since there's a
2952 breakpoint at PC - 1. We'd then report a hit on B1, although
2953 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2955 if (execution_direction
== EXEC_REVERSE
)
2958 /* If this target does not decrement the PC after breakpoints, then
2959 we have nothing to do. */
2960 regcache
= get_thread_regcache (ecs
->ptid
);
2961 gdbarch
= get_regcache_arch (regcache
);
2962 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
2965 aspace
= get_regcache_aspace (regcache
);
2967 /* Find the location where (if we've hit a breakpoint) the
2968 breakpoint would be. */
2969 breakpoint_pc
= regcache_read_pc (regcache
)
2970 - gdbarch_decr_pc_after_break (gdbarch
);
2972 /* Check whether there actually is a software breakpoint inserted at
2975 If in non-stop mode, a race condition is possible where we've
2976 removed a breakpoint, but stop events for that breakpoint were
2977 already queued and arrive later. To suppress those spurious
2978 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2979 and retire them after a number of stop events are reported. */
2980 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
2981 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
2983 struct cleanup
*old_cleanups
= NULL
;
2986 old_cleanups
= record_gdb_operation_disable_set ();
2988 /* When using hardware single-step, a SIGTRAP is reported for both
2989 a completed single-step and a software breakpoint. Need to
2990 differentiate between the two, as the latter needs adjusting
2991 but the former does not.
2993 The SIGTRAP can be due to a completed hardware single-step only if
2994 - we didn't insert software single-step breakpoints
2995 - the thread to be examined is still the current thread
2996 - this thread is currently being stepped
2998 If any of these events did not occur, we must have stopped due
2999 to hitting a software breakpoint, and have to back up to the
3002 As a special case, we could have hardware single-stepped a
3003 software breakpoint. In this case (prev_pc == breakpoint_pc),
3004 we also need to back up to the breakpoint address. */
3006 if (singlestep_breakpoints_inserted_p
3007 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
3008 || !currently_stepping (ecs
->event_thread
)
3009 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
3010 regcache_write_pc (regcache
, breakpoint_pc
);
3013 do_cleanups (old_cleanups
);
3018 init_infwait_state (void)
3020 waiton_ptid
= pid_to_ptid (-1);
3021 infwait_state
= infwait_normal_state
;
3025 error_is_running (void)
3027 error (_("Cannot execute this command while "
3028 "the selected thread is running."));
3032 ensure_not_running (void)
3034 if (is_running (inferior_ptid
))
3035 error_is_running ();
3039 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3041 for (frame
= get_prev_frame (frame
);
3043 frame
= get_prev_frame (frame
))
3045 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3047 if (get_frame_type (frame
) != INLINE_FRAME
)
3054 /* Auxiliary function that handles syscall entry/return events.
3055 It returns 1 if the inferior should keep going (and GDB
3056 should ignore the event), or 0 if the event deserves to be
3060 handle_syscall_event (struct execution_control_state
*ecs
)
3062 struct regcache
*regcache
;
3063 struct gdbarch
*gdbarch
;
3066 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3067 context_switch (ecs
->ptid
);
3069 regcache
= get_thread_regcache (ecs
->ptid
);
3070 gdbarch
= get_regcache_arch (regcache
);
3071 syscall_number
= ecs
->ws
.value
.syscall_number
;
3072 stop_pc
= regcache_read_pc (regcache
);
3074 if (catch_syscall_enabled () > 0
3075 && catching_syscall_number (syscall_number
) > 0)
3078 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3081 ecs
->event_thread
->control
.stop_bpstat
3082 = bpstat_stop_status (get_regcache_aspace (regcache
),
3083 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3085 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
);
3087 if (!ecs
->random_signal
)
3089 /* Catchpoint hit. */
3090 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3095 /* If no catchpoint triggered for this, then keep going. */
3096 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3101 /* Clear the supplied execution_control_state's stop_func_* fields. */
3104 clear_stop_func (struct execution_control_state
*ecs
)
3106 ecs
->stop_func_filled_in
= 0;
3107 ecs
->stop_func_start
= 0;
3108 ecs
->stop_func_end
= 0;
3109 ecs
->stop_func_name
= NULL
;
3112 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3115 fill_in_stop_func (struct gdbarch
*gdbarch
,
3116 struct execution_control_state
*ecs
)
3118 if (!ecs
->stop_func_filled_in
)
3120 /* Don't care about return value; stop_func_start and stop_func_name
3121 will both be 0 if it doesn't work. */
3122 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3123 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3124 ecs
->stop_func_start
3125 += gdbarch_deprecated_function_start_offset (gdbarch
);
3127 ecs
->stop_func_filled_in
= 1;
3131 /* Given an execution control state that has been freshly filled in
3132 by an event from the inferior, figure out what it means and take
3133 appropriate action. */
3136 handle_inferior_event (struct execution_control_state
*ecs
)
3138 struct frame_info
*frame
;
3139 struct gdbarch
*gdbarch
;
3140 int stopped_by_watchpoint
;
3141 int stepped_after_stopped_by_watchpoint
= 0;
3142 struct symtab_and_line stop_pc_sal
;
3143 enum stop_kind stop_soon
;
3145 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3147 /* We had an event in the inferior, but we are not interested in
3148 handling it at this level. The lower layers have already
3149 done what needs to be done, if anything.
3151 One of the possible circumstances for this is when the
3152 inferior produces output for the console. The inferior has
3153 not stopped, and we are ignoring the event. Another possible
3154 circumstance is any event which the lower level knows will be
3155 reported multiple times without an intervening resume. */
3157 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3158 prepare_to_wait (ecs
);
3162 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3163 && target_can_async_p () && !sync_execution
)
3165 /* There were no unwaited-for children left in the target, but,
3166 we're not synchronously waiting for events either. Just
3167 ignore. Otherwise, if we were running a synchronous
3168 execution command, we need to cancel it and give the user
3169 back the terminal. */
3171 fprintf_unfiltered (gdb_stdlog
,
3172 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3173 prepare_to_wait (ecs
);
3177 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3178 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3179 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
3181 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3184 stop_soon
= inf
->control
.stop_soon
;
3187 stop_soon
= NO_STOP_QUIETLY
;
3189 /* Cache the last pid/waitstatus. */
3190 target_last_wait_ptid
= ecs
->ptid
;
3191 target_last_waitstatus
= ecs
->ws
;
3193 /* Always clear state belonging to the previous time we stopped. */
3194 stop_stack_dummy
= STOP_NONE
;
3196 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3198 /* No unwaited-for children left. IOW, all resumed children
3201 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3203 stop_print_frame
= 0;
3204 stop_stepping (ecs
);
3208 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3209 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3211 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3212 /* If it's a new thread, add it to the thread database. */
3213 if (ecs
->event_thread
== NULL
)
3214 ecs
->event_thread
= add_thread (ecs
->ptid
);
3217 /* Dependent on valid ECS->EVENT_THREAD. */
3218 adjust_pc_after_break (ecs
);
3220 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3221 reinit_frame_cache ();
3223 breakpoint_retire_moribund ();
3225 /* First, distinguish signals caused by the debugger from signals
3226 that have to do with the program's own actions. Note that
3227 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3228 on the operating system version. Here we detect when a SIGILL or
3229 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3230 something similar for SIGSEGV, since a SIGSEGV will be generated
3231 when we're trying to execute a breakpoint instruction on a
3232 non-executable stack. This happens for call dummy breakpoints
3233 for architectures like SPARC that place call dummies on the
3235 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3236 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3237 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3238 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3240 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3242 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3243 regcache_read_pc (regcache
)))
3246 fprintf_unfiltered (gdb_stdlog
,
3247 "infrun: Treating signal as SIGTRAP\n");
3248 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3252 /* Mark the non-executing threads accordingly. In all-stop, all
3253 threads of all processes are stopped when we get any event
3254 reported. In non-stop mode, only the event thread stops. If
3255 we're handling a process exit in non-stop mode, there's nothing
3256 to do, as threads of the dead process are gone, and threads of
3257 any other process were left running. */
3259 set_executing (minus_one_ptid
, 0);
3260 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3261 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3262 set_executing (ecs
->ptid
, 0);
3264 switch (infwait_state
)
3266 case infwait_thread_hop_state
:
3268 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
3271 case infwait_normal_state
:
3273 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
3276 case infwait_step_watch_state
:
3278 fprintf_unfiltered (gdb_stdlog
,
3279 "infrun: infwait_step_watch_state\n");
3281 stepped_after_stopped_by_watchpoint
= 1;
3284 case infwait_nonstep_watch_state
:
3286 fprintf_unfiltered (gdb_stdlog
,
3287 "infrun: infwait_nonstep_watch_state\n");
3288 insert_breakpoints ();
3290 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3291 handle things like signals arriving and other things happening
3292 in combination correctly? */
3293 stepped_after_stopped_by_watchpoint
= 1;
3297 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3300 infwait_state
= infwait_normal_state
;
3301 waiton_ptid
= pid_to_ptid (-1);
3303 switch (ecs
->ws
.kind
)
3305 case TARGET_WAITKIND_LOADED
:
3307 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3308 /* Ignore gracefully during startup of the inferior, as it might
3309 be the shell which has just loaded some objects, otherwise
3310 add the symbols for the newly loaded objects. Also ignore at
3311 the beginning of an attach or remote session; we will query
3312 the full list of libraries once the connection is
3314 if (stop_soon
== NO_STOP_QUIETLY
)
3316 struct regcache
*regcache
;
3318 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3319 context_switch (ecs
->ptid
);
3320 regcache
= get_thread_regcache (ecs
->ptid
);
3322 handle_solib_event ();
3324 ecs
->event_thread
->control
.stop_bpstat
3325 = bpstat_stop_status (get_regcache_aspace (regcache
),
3326 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3328 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
);
3330 if (!ecs
->random_signal
)
3332 /* A catchpoint triggered. */
3333 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3334 goto process_event_stop_test
;
3337 /* If requested, stop when the dynamic linker notifies
3338 gdb of events. This allows the user to get control
3339 and place breakpoints in initializer routines for
3340 dynamically loaded objects (among other things). */
3341 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3342 if (stop_on_solib_events
)
3344 /* Make sure we print "Stopped due to solib-event" in
3346 stop_print_frame
= 1;
3348 stop_stepping (ecs
);
3353 /* If we are skipping through a shell, or through shared library
3354 loading that we aren't interested in, resume the program. If
3355 we're running the program normally, also resume. But stop if
3356 we're attaching or setting up a remote connection. */
3357 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3359 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3360 context_switch (ecs
->ptid
);
3362 /* Loading of shared libraries might have changed breakpoint
3363 addresses. Make sure new breakpoints are inserted. */
3364 if (stop_soon
== NO_STOP_QUIETLY
3365 && !breakpoints_always_inserted_mode ())
3366 insert_breakpoints ();
3367 resume (0, GDB_SIGNAL_0
);
3368 prepare_to_wait (ecs
);
3374 case TARGET_WAITKIND_SPURIOUS
:
3376 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3377 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3378 context_switch (ecs
->ptid
);
3379 resume (0, GDB_SIGNAL_0
);
3380 prepare_to_wait (ecs
);
3383 case TARGET_WAITKIND_EXITED
:
3384 case TARGET_WAITKIND_SIGNALLED
:
3387 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3388 fprintf_unfiltered (gdb_stdlog
,
3389 "infrun: TARGET_WAITKIND_EXITED\n");
3391 fprintf_unfiltered (gdb_stdlog
,
3392 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3395 inferior_ptid
= ecs
->ptid
;
3396 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3397 set_current_program_space (current_inferior ()->pspace
);
3398 handle_vfork_child_exec_or_exit (0);
3399 target_terminal_ours (); /* Must do this before mourn anyway. */
3401 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3403 /* Record the exit code in the convenience variable $_exitcode, so
3404 that the user can inspect this again later. */
3405 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3406 (LONGEST
) ecs
->ws
.value
.integer
);
3408 /* Also record this in the inferior itself. */
3409 current_inferior ()->has_exit_code
= 1;
3410 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3412 print_exited_reason (ecs
->ws
.value
.integer
);
3415 print_signal_exited_reason (ecs
->ws
.value
.sig
);
3417 gdb_flush (gdb_stdout
);
3418 target_mourn_inferior ();
3419 singlestep_breakpoints_inserted_p
= 0;
3420 cancel_single_step_breakpoints ();
3421 stop_print_frame
= 0;
3422 stop_stepping (ecs
);
3425 /* The following are the only cases in which we keep going;
3426 the above cases end in a continue or goto. */
3427 case TARGET_WAITKIND_FORKED
:
3428 case TARGET_WAITKIND_VFORKED
:
3431 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3432 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3434 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3437 /* Check whether the inferior is displaced stepping. */
3439 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3440 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3441 struct displaced_step_inferior_state
*displaced
3442 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3444 /* If checking displaced stepping is supported, and thread
3445 ecs->ptid is displaced stepping. */
3446 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3448 struct inferior
*parent_inf
3449 = find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3450 struct regcache
*child_regcache
;
3451 CORE_ADDR parent_pc
;
3453 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3454 indicating that the displaced stepping of syscall instruction
3455 has been done. Perform cleanup for parent process here. Note
3456 that this operation also cleans up the child process for vfork,
3457 because their pages are shared. */
3458 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3460 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3462 /* Restore scratch pad for child process. */
3463 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3466 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3467 the child's PC is also within the scratchpad. Set the child's PC
3468 to the parent's PC value, which has already been fixed up.
3469 FIXME: we use the parent's aspace here, although we're touching
3470 the child, because the child hasn't been added to the inferior
3471 list yet at this point. */
3474 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
3476 parent_inf
->aspace
);
3477 /* Read PC value of parent process. */
3478 parent_pc
= regcache_read_pc (regcache
);
3480 if (debug_displaced
)
3481 fprintf_unfiltered (gdb_stdlog
,
3482 "displaced: write child pc from %s to %s\n",
3484 regcache_read_pc (child_regcache
)),
3485 paddress (gdbarch
, parent_pc
));
3487 regcache_write_pc (child_regcache
, parent_pc
);
3491 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3492 context_switch (ecs
->ptid
);
3494 /* Immediately detach breakpoints from the child before there's
3495 any chance of letting the user delete breakpoints from the
3496 breakpoint lists. If we don't do this early, it's easy to
3497 leave left over traps in the child, vis: "break foo; catch
3498 fork; c; <fork>; del; c; <child calls foo>". We only follow
3499 the fork on the last `continue', and by that time the
3500 breakpoint at "foo" is long gone from the breakpoint table.
3501 If we vforked, then we don't need to unpatch here, since both
3502 parent and child are sharing the same memory pages; we'll
3503 need to unpatch at follow/detach time instead to be certain
3504 that new breakpoints added between catchpoint hit time and
3505 vfork follow are detached. */
3506 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
3508 /* This won't actually modify the breakpoint list, but will
3509 physically remove the breakpoints from the child. */
3510 detach_breakpoints (ecs
->ws
.value
.related_pid
);
3513 if (singlestep_breakpoints_inserted_p
)
3515 /* Pull the single step breakpoints out of the target. */
3516 remove_single_step_breakpoints ();
3517 singlestep_breakpoints_inserted_p
= 0;
3520 /* In case the event is caught by a catchpoint, remember that
3521 the event is to be followed at the next resume of the thread,
3522 and not immediately. */
3523 ecs
->event_thread
->pending_follow
= ecs
->ws
;
3525 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3527 ecs
->event_thread
->control
.stop_bpstat
3528 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3529 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3531 /* Note that we're interested in knowing the bpstat actually
3532 causes a stop, not just if it may explain the signal.
3533 Software watchpoints, for example, always appear in the
3536 = !bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
);
3538 /* If no catchpoint triggered for this, then keep going. */
3539 if (ecs
->random_signal
)
3545 = (follow_fork_mode_string
== follow_fork_mode_child
);
3547 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3549 should_resume
= follow_fork ();
3552 child
= ecs
->ws
.value
.related_pid
;
3554 /* In non-stop mode, also resume the other branch. */
3555 if (non_stop
&& !detach_fork
)
3558 switch_to_thread (parent
);
3560 switch_to_thread (child
);
3562 ecs
->event_thread
= inferior_thread ();
3563 ecs
->ptid
= inferior_ptid
;
3568 switch_to_thread (child
);
3570 switch_to_thread (parent
);
3572 ecs
->event_thread
= inferior_thread ();
3573 ecs
->ptid
= inferior_ptid
;
3578 stop_stepping (ecs
);
3581 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3582 goto process_event_stop_test
;
3584 case TARGET_WAITKIND_VFORK_DONE
:
3585 /* Done with the shared memory region. Re-insert breakpoints in
3586 the parent, and keep going. */
3589 fprintf_unfiltered (gdb_stdlog
,
3590 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3592 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3593 context_switch (ecs
->ptid
);
3595 current_inferior ()->waiting_for_vfork_done
= 0;
3596 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3597 /* This also takes care of reinserting breakpoints in the
3598 previously locked inferior. */
3602 case TARGET_WAITKIND_EXECD
:
3604 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3606 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3607 context_switch (ecs
->ptid
);
3609 singlestep_breakpoints_inserted_p
= 0;
3610 cancel_single_step_breakpoints ();
3612 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3614 /* Do whatever is necessary to the parent branch of the vfork. */
3615 handle_vfork_child_exec_or_exit (1);
3617 /* This causes the eventpoints and symbol table to be reset.
3618 Must do this now, before trying to determine whether to
3620 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3622 ecs
->event_thread
->control
.stop_bpstat
3623 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3624 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3626 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
);
3628 /* Note that this may be referenced from inside
3629 bpstat_stop_status above, through inferior_has_execd. */
3630 xfree (ecs
->ws
.value
.execd_pathname
);
3631 ecs
->ws
.value
.execd_pathname
= NULL
;
3633 /* If no catchpoint triggered for this, then keep going. */
3634 if (ecs
->random_signal
)
3636 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3640 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3641 goto process_event_stop_test
;
3643 /* Be careful not to try to gather much state about a thread
3644 that's in a syscall. It's frequently a losing proposition. */
3645 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3647 fprintf_unfiltered (gdb_stdlog
,
3648 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3649 /* Getting the current syscall number. */
3650 if (handle_syscall_event (ecs
) != 0)
3652 goto process_event_stop_test
;
3654 /* Before examining the threads further, step this thread to
3655 get it entirely out of the syscall. (We get notice of the
3656 event when the thread is just on the verge of exiting a
3657 syscall. Stepping one instruction seems to get it back
3659 case TARGET_WAITKIND_SYSCALL_RETURN
:
3661 fprintf_unfiltered (gdb_stdlog
,
3662 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3663 if (handle_syscall_event (ecs
) != 0)
3665 goto process_event_stop_test
;
3667 case TARGET_WAITKIND_STOPPED
:
3669 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
3670 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
3673 case TARGET_WAITKIND_NO_HISTORY
:
3675 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
3676 /* Reverse execution: target ran out of history info. */
3678 /* Pull the single step breakpoints out of the target. */
3679 if (singlestep_breakpoints_inserted_p
)
3681 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3682 context_switch (ecs
->ptid
);
3683 remove_single_step_breakpoints ();
3684 singlestep_breakpoints_inserted_p
= 0;
3686 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3687 print_no_history_reason ();
3688 stop_stepping (ecs
);
3692 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
3694 /* Do we need to clean up the state of a thread that has
3695 completed a displaced single-step? (Doing so usually affects
3696 the PC, so do it here, before we set stop_pc.) */
3697 displaced_step_fixup (ecs
->ptid
,
3698 ecs
->event_thread
->suspend
.stop_signal
);
3700 /* If we either finished a single-step or hit a breakpoint, but
3701 the user wanted this thread to be stopped, pretend we got a
3702 SIG0 (generic unsignaled stop). */
3704 if (ecs
->event_thread
->stop_requested
3705 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3706 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3709 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3713 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3714 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3715 struct cleanup
*old_chain
= save_inferior_ptid ();
3717 inferior_ptid
= ecs
->ptid
;
3719 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
3720 paddress (gdbarch
, stop_pc
));
3721 if (target_stopped_by_watchpoint ())
3725 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
3727 if (target_stopped_data_address (¤t_target
, &addr
))
3728 fprintf_unfiltered (gdb_stdlog
,
3729 "infrun: stopped data address = %s\n",
3730 paddress (gdbarch
, addr
));
3732 fprintf_unfiltered (gdb_stdlog
,
3733 "infrun: (no data address available)\n");
3736 do_cleanups (old_chain
);
3739 if (stepping_past_singlestep_breakpoint
)
3741 gdb_assert (singlestep_breakpoints_inserted_p
);
3742 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
3743 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
3745 stepping_past_singlestep_breakpoint
= 0;
3747 /* We've either finished single-stepping past the single-step
3748 breakpoint, or stopped for some other reason. It would be nice if
3749 we could tell, but we can't reliably. */
3750 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3753 fprintf_unfiltered (gdb_stdlog
,
3754 "infrun: stepping_past_"
3755 "singlestep_breakpoint\n");
3756 /* Pull the single step breakpoints out of the target. */
3757 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3758 context_switch (ecs
->ptid
);
3759 remove_single_step_breakpoints ();
3760 singlestep_breakpoints_inserted_p
= 0;
3762 ecs
->random_signal
= 0;
3763 ecs
->event_thread
->control
.trap_expected
= 0;
3765 context_switch (saved_singlestep_ptid
);
3766 if (deprecated_context_hook
)
3767 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3769 resume (1, GDB_SIGNAL_0
);
3770 prepare_to_wait (ecs
);
3775 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
3777 /* In non-stop mode, there's never a deferred_step_ptid set. */
3778 gdb_assert (!non_stop
);
3780 /* If we stopped for some other reason than single-stepping, ignore
3781 the fact that we were supposed to switch back. */
3782 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3785 fprintf_unfiltered (gdb_stdlog
,
3786 "infrun: handling deferred step\n");
3788 /* Pull the single step breakpoints out of the target. */
3789 if (singlestep_breakpoints_inserted_p
)
3791 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3792 context_switch (ecs
->ptid
);
3793 remove_single_step_breakpoints ();
3794 singlestep_breakpoints_inserted_p
= 0;
3797 ecs
->event_thread
->control
.trap_expected
= 0;
3799 context_switch (deferred_step_ptid
);
3800 deferred_step_ptid
= null_ptid
;
3801 /* Suppress spurious "Switching to ..." message. */
3802 previous_inferior_ptid
= inferior_ptid
;
3804 resume (1, GDB_SIGNAL_0
);
3805 prepare_to_wait (ecs
);
3809 deferred_step_ptid
= null_ptid
;
3812 /* See if a thread hit a thread-specific breakpoint that was meant for
3813 another thread. If so, then step that thread past the breakpoint,
3816 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3818 int thread_hop_needed
= 0;
3819 struct address_space
*aspace
=
3820 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
3822 /* Check if a regular breakpoint has been hit before checking
3823 for a potential single step breakpoint. Otherwise, GDB will
3824 not see this breakpoint hit when stepping onto breakpoints. */
3825 if (regular_breakpoint_inserted_here_p (aspace
, stop_pc
))
3827 ecs
->random_signal
= 0;
3828 if (!breakpoint_thread_match (aspace
, stop_pc
, ecs
->ptid
))
3829 thread_hop_needed
= 1;
3831 else if (singlestep_breakpoints_inserted_p
)
3833 /* We have not context switched yet, so this should be true
3834 no matter which thread hit the singlestep breakpoint. */
3835 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
3837 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
3839 target_pid_to_str (ecs
->ptid
));
3841 ecs
->random_signal
= 0;
3842 /* The call to in_thread_list is necessary because PTIDs sometimes
3843 change when we go from single-threaded to multi-threaded. If
3844 the singlestep_ptid is still in the list, assume that it is
3845 really different from ecs->ptid. */
3846 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
3847 && in_thread_list (singlestep_ptid
))
3849 /* If the PC of the thread we were trying to single-step
3850 has changed, discard this event (which we were going
3851 to ignore anyway), and pretend we saw that thread
3852 trap. This prevents us continuously moving the
3853 single-step breakpoint forward, one instruction at a
3854 time. If the PC has changed, then the thread we were
3855 trying to single-step has trapped or been signalled,
3856 but the event has not been reported to GDB yet.
3858 There might be some cases where this loses signal
3859 information, if a signal has arrived at exactly the
3860 same time that the PC changed, but this is the best
3861 we can do with the information available. Perhaps we
3862 should arrange to report all events for all threads
3863 when they stop, or to re-poll the remote looking for
3864 this particular thread (i.e. temporarily enable
3867 CORE_ADDR new_singlestep_pc
3868 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
3870 if (new_singlestep_pc
!= singlestep_pc
)
3872 enum gdb_signal stop_signal
;
3875 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
3876 " but expected thread advanced also\n");
3878 /* The current context still belongs to
3879 singlestep_ptid. Don't swap here, since that's
3880 the context we want to use. Just fudge our
3881 state and continue. */
3882 stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
3883 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3884 ecs
->ptid
= singlestep_ptid
;
3885 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3886 ecs
->event_thread
->suspend
.stop_signal
= stop_signal
;
3887 stop_pc
= new_singlestep_pc
;
3892 fprintf_unfiltered (gdb_stdlog
,
3893 "infrun: unexpected thread\n");
3895 thread_hop_needed
= 1;
3896 stepping_past_singlestep_breakpoint
= 1;
3897 saved_singlestep_ptid
= singlestep_ptid
;
3902 if (thread_hop_needed
)
3904 struct regcache
*thread_regcache
;
3905 int remove_status
= 0;
3908 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
3910 /* Switch context before touching inferior memory, the
3911 previous thread may have exited. */
3912 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
3913 context_switch (ecs
->ptid
);
3915 /* Saw a breakpoint, but it was hit by the wrong thread.
3918 if (singlestep_breakpoints_inserted_p
)
3920 /* Pull the single step breakpoints out of the target. */
3921 remove_single_step_breakpoints ();
3922 singlestep_breakpoints_inserted_p
= 0;
3925 /* If the arch can displace step, don't remove the
3927 thread_regcache
= get_thread_regcache (ecs
->ptid
);
3928 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
3929 remove_status
= remove_breakpoints ();
3931 /* Did we fail to remove breakpoints? If so, try
3932 to set the PC past the bp. (There's at least
3933 one situation in which we can fail to remove
3934 the bp's: On HP-UX's that use ttrace, we can't
3935 change the address space of a vforking child
3936 process until the child exits (well, okay, not
3937 then either :-) or execs. */
3938 if (remove_status
!= 0)
3939 error (_("Cannot step over breakpoint hit in wrong thread"));
3944 /* Only need to require the next event from this
3945 thread in all-stop mode. */
3946 waiton_ptid
= ecs
->ptid
;
3947 infwait_state
= infwait_thread_hop_state
;
3950 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3955 else if (singlestep_breakpoints_inserted_p
)
3957 ecs
->random_signal
= 0;
3961 ecs
->random_signal
= 1;
3963 /* See if something interesting happened to the non-current thread. If
3964 so, then switch to that thread. */
3965 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3968 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
3970 context_switch (ecs
->ptid
);
3972 if (deprecated_context_hook
)
3973 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3976 /* At this point, get hold of the now-current thread's frame. */
3977 frame
= get_current_frame ();
3978 gdbarch
= get_frame_arch (frame
);
3980 if (singlestep_breakpoints_inserted_p
)
3982 /* Pull the single step breakpoints out of the target. */
3983 remove_single_step_breakpoints ();
3984 singlestep_breakpoints_inserted_p
= 0;
3987 if (stepped_after_stopped_by_watchpoint
)
3988 stopped_by_watchpoint
= 0;
3990 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
3992 /* If necessary, step over this watchpoint. We'll be back to display
3994 if (stopped_by_watchpoint
3995 && (target_have_steppable_watchpoint
3996 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
3998 /* At this point, we are stopped at an instruction which has
3999 attempted to write to a piece of memory under control of
4000 a watchpoint. The instruction hasn't actually executed
4001 yet. If we were to evaluate the watchpoint expression
4002 now, we would get the old value, and therefore no change
4003 would seem to have occurred.
4005 In order to make watchpoints work `right', we really need
4006 to complete the memory write, and then evaluate the
4007 watchpoint expression. We do this by single-stepping the
4010 It may not be necessary to disable the watchpoint to stop over
4011 it. For example, the PA can (with some kernel cooperation)
4012 single step over a watchpoint without disabling the watchpoint.
4014 It is far more common to need to disable a watchpoint to step
4015 the inferior over it. If we have non-steppable watchpoints,
4016 we must disable the current watchpoint; it's simplest to
4017 disable all watchpoints and breakpoints. */
4020 if (!target_have_steppable_watchpoint
)
4022 remove_breakpoints ();
4023 /* See comment in resume why we need to stop bypassing signals
4024 while breakpoints have been removed. */
4025 target_pass_signals (0, NULL
);
4028 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
4029 target_resume (ecs
->ptid
, hw_step
, GDB_SIGNAL_0
);
4030 waiton_ptid
= ecs
->ptid
;
4031 if (target_have_steppable_watchpoint
)
4032 infwait_state
= infwait_step_watch_state
;
4034 infwait_state
= infwait_nonstep_watch_state
;
4035 prepare_to_wait (ecs
);
4039 clear_stop_func (ecs
);
4040 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4041 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4042 ecs
->event_thread
->control
.stop_step
= 0;
4043 stop_print_frame
= 1;
4044 ecs
->random_signal
= 0;
4045 stopped_by_random_signal
= 0;
4047 /* Hide inlined functions starting here, unless we just performed stepi or
4048 nexti. After stepi and nexti, always show the innermost frame (not any
4049 inline function call sites). */
4050 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4052 struct address_space
*aspace
=
4053 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4055 /* skip_inline_frames is expensive, so we avoid it if we can
4056 determine that the address is one where functions cannot have
4057 been inlined. This improves performance with inferiors that
4058 load a lot of shared libraries, because the solib event
4059 breakpoint is defined as the address of a function (i.e. not
4060 inline). Note that we have to check the previous PC as well
4061 as the current one to catch cases when we have just
4062 single-stepped off a breakpoint prior to reinstating it.
4063 Note that we're assuming that the code we single-step to is
4064 not inline, but that's not definitive: there's nothing
4065 preventing the event breakpoint function from containing
4066 inlined code, and the single-step ending up there. If the
4067 user had set a breakpoint on that inlined code, the missing
4068 skip_inline_frames call would break things. Fortunately
4069 that's an extremely unlikely scenario. */
4070 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4071 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4072 && ecs
->event_thread
->control
.trap_expected
4073 && pc_at_non_inline_function (aspace
,
4074 ecs
->event_thread
->prev_pc
,
4077 skip_inline_frames (ecs
->ptid
);
4079 /* Re-fetch current thread's frame in case that invalidated
4081 frame
= get_current_frame ();
4082 gdbarch
= get_frame_arch (frame
);
4086 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4087 && ecs
->event_thread
->control
.trap_expected
4088 && gdbarch_single_step_through_delay_p (gdbarch
)
4089 && currently_stepping (ecs
->event_thread
))
4091 /* We're trying to step off a breakpoint. Turns out that we're
4092 also on an instruction that needs to be stepped multiple
4093 times before it's been fully executing. E.g., architectures
4094 with a delay slot. It needs to be stepped twice, once for
4095 the instruction and once for the delay slot. */
4096 int step_through_delay
4097 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4099 if (debug_infrun
&& step_through_delay
)
4100 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4101 if (ecs
->event_thread
->control
.step_range_end
== 0
4102 && step_through_delay
)
4104 /* The user issued a continue when stopped at a breakpoint.
4105 Set up for another trap and get out of here. */
4106 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4110 else if (step_through_delay
)
4112 /* The user issued a step when stopped at a breakpoint.
4113 Maybe we should stop, maybe we should not - the delay
4114 slot *might* correspond to a line of source. In any
4115 case, don't decide that here, just set
4116 ecs->stepping_over_breakpoint, making sure we
4117 single-step again before breakpoints are re-inserted. */
4118 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4122 /* Look at the cause of the stop, and decide what to do.
4123 The alternatives are:
4124 1) stop_stepping and return; to really stop and return to the debugger,
4125 2) keep_going and return to start up again
4126 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
4127 3) set ecs->random_signal to 1, and the decision between 1 and 2
4128 will be made according to the signal handling tables. */
4130 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4131 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4132 || stop_soon
== STOP_QUIETLY_REMOTE
)
4134 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4138 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
4139 stop_print_frame
= 0;
4140 stop_stepping (ecs
);
4144 /* This is originated from start_remote(), start_inferior() and
4145 shared libraries hook functions. */
4146 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
4149 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
4150 stop_stepping (ecs
);
4154 /* This originates from attach_command(). We need to overwrite
4155 the stop_signal here, because some kernels don't ignore a
4156 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4157 See more comments in inferior.h. On the other hand, if we
4158 get a non-SIGSTOP, report it to the user - assume the backend
4159 will handle the SIGSTOP if it should show up later.
4161 Also consider that the attach is complete when we see a
4162 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4163 target extended-remote report it instead of a SIGSTOP
4164 (e.g. gdbserver). We already rely on SIGTRAP being our
4165 signal, so this is no exception.
4167 Also consider that the attach is complete when we see a
4168 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4169 the target to stop all threads of the inferior, in case the
4170 low level attach operation doesn't stop them implicitly. If
4171 they weren't stopped implicitly, then the stub will report a
4172 GDB_SIGNAL_0, meaning: stopped for no particular reason
4173 other than GDB's request. */
4174 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4175 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
4176 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4177 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
4179 stop_stepping (ecs
);
4180 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4184 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4185 handles this event. */
4186 ecs
->event_thread
->control
.stop_bpstat
4187 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4188 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4190 /* Following in case break condition called a
4192 stop_print_frame
= 1;
4194 /* This is where we handle "moribund" watchpoints. Unlike
4195 software breakpoints traps, hardware watchpoint traps are
4196 always distinguishable from random traps. If no high-level
4197 watchpoint is associated with the reported stop data address
4198 anymore, then the bpstat does not explain the signal ---
4199 simply make sure to ignore it if `stopped_by_watchpoint' is
4203 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4204 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
)
4205 && stopped_by_watchpoint
)
4206 fprintf_unfiltered (gdb_stdlog
,
4207 "infrun: no user watchpoint explains "
4208 "watchpoint SIGTRAP, ignoring\n");
4210 /* NOTE: cagney/2003-03-29: These two checks for a random signal
4211 at one stage in the past included checks for an inferior
4212 function call's call dummy's return breakpoint. The original
4213 comment, that went with the test, read:
4215 ``End of a stack dummy. Some systems (e.g. Sony news) give
4216 another signal besides SIGTRAP, so check here as well as
4219 If someone ever tries to get call dummys on a
4220 non-executable stack to work (where the target would stop
4221 with something like a SIGSEGV), then those tests might need
4222 to be re-instated. Given, however, that the tests were only
4223 enabled when momentary breakpoints were not being used, I
4224 suspect that it won't be the case.
4226 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4227 be necessary for call dummies on a non-executable stack on
4230 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4232 = !(bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
)
4233 || stopped_by_watchpoint
4234 || ecs
->event_thread
->control
.trap_expected
4235 || (ecs
->event_thread
->control
.step_range_end
4236 && (ecs
->event_thread
->control
.step_resume_breakpoint
4240 ecs
->random_signal
= !bpstat_explains_signal
4241 (ecs
->event_thread
->control
.stop_bpstat
);
4242 if (!ecs
->random_signal
)
4243 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
4247 /* When we reach this point, we've pretty much decided
4248 that the reason for stopping must've been a random
4249 (unexpected) signal. */
4252 ecs
->random_signal
= 1;
4254 process_event_stop_test
:
4256 /* Re-fetch current thread's frame in case we did a
4257 "goto process_event_stop_test" above. */
4258 frame
= get_current_frame ();
4259 gdbarch
= get_frame_arch (frame
);
4261 /* For the program's own signals, act according to
4262 the signal handling tables. */
4264 if (ecs
->random_signal
)
4266 /* Signal not for debugging purposes. */
4268 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
4271 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n",
4272 ecs
->event_thread
->suspend
.stop_signal
);
4274 stopped_by_random_signal
= 1;
4276 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4279 target_terminal_ours_for_output ();
4280 print_signal_received_reason
4281 (ecs
->event_thread
->suspend
.stop_signal
);
4283 /* Always stop on signals if we're either just gaining control
4284 of the program, or the user explicitly requested this thread
4285 to remain stopped. */
4286 if (stop_soon
!= NO_STOP_QUIETLY
4287 || ecs
->event_thread
->stop_requested
4289 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4291 stop_stepping (ecs
);
4294 /* If not going to stop, give terminal back
4295 if we took it away. */
4297 target_terminal_inferior ();
4299 /* Clear the signal if it should not be passed. */
4300 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4301 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4303 if (ecs
->event_thread
->prev_pc
== stop_pc
4304 && ecs
->event_thread
->control
.trap_expected
4305 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4307 /* We were just starting a new sequence, attempting to
4308 single-step off of a breakpoint and expecting a SIGTRAP.
4309 Instead this signal arrives. This signal will take us out
4310 of the stepping range so GDB needs to remember to, when
4311 the signal handler returns, resume stepping off that
4313 /* To simplify things, "continue" is forced to use the same
4314 code paths as single-step - set a breakpoint at the
4315 signal return address and then, once hit, step off that
4318 fprintf_unfiltered (gdb_stdlog
,
4319 "infrun: signal arrived while stepping over "
4322 insert_hp_step_resume_breakpoint_at_frame (frame
);
4323 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4324 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4325 ecs
->event_thread
->control
.trap_expected
= 0;
4330 if (ecs
->event_thread
->control
.step_range_end
!= 0
4331 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4332 && (ecs
->event_thread
->control
.step_range_start
<= stop_pc
4333 && stop_pc
< ecs
->event_thread
->control
.step_range_end
)
4334 && frame_id_eq (get_stack_frame_id (frame
),
4335 ecs
->event_thread
->control
.step_stack_frame_id
)
4336 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4338 /* The inferior is about to take a signal that will take it
4339 out of the single step range. Set a breakpoint at the
4340 current PC (which is presumably where the signal handler
4341 will eventually return) and then allow the inferior to
4344 Note that this is only needed for a signal delivered
4345 while in the single-step range. Nested signals aren't a
4346 problem as they eventually all return. */
4348 fprintf_unfiltered (gdb_stdlog
,
4349 "infrun: signal may take us out of "
4350 "single-step range\n");
4352 insert_hp_step_resume_breakpoint_at_frame (frame
);
4353 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4354 ecs
->event_thread
->control
.trap_expected
= 0;
4359 /* Note: step_resume_breakpoint may be non-NULL. This occures
4360 when either there's a nested signal, or when there's a
4361 pending signal enabled just as the signal handler returns
4362 (leaving the inferior at the step-resume-breakpoint without
4363 actually executing it). Either way continue until the
4364 breakpoint is really hit. */
4368 /* Handle cases caused by hitting a breakpoint. */
4370 CORE_ADDR jmp_buf_pc
;
4371 struct bpstat_what what
;
4373 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4375 if (what
.call_dummy
)
4377 stop_stack_dummy
= what
.call_dummy
;
4380 /* If we hit an internal event that triggers symbol changes, the
4381 current frame will be invalidated within bpstat_what (e.g.,
4382 if we hit an internal solib event). Re-fetch it. */
4383 frame
= get_current_frame ();
4384 gdbarch
= get_frame_arch (frame
);
4386 switch (what
.main_action
)
4388 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4389 /* If we hit the breakpoint at longjmp while stepping, we
4390 install a momentary breakpoint at the target of the
4394 fprintf_unfiltered (gdb_stdlog
,
4395 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4397 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4399 if (what
.is_longjmp
)
4401 struct value
*arg_value
;
4403 /* If we set the longjmp breakpoint via a SystemTap
4404 probe, then use it to extract the arguments. The
4405 destination PC is the third argument to the
4407 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4409 jmp_buf_pc
= value_as_address (arg_value
);
4410 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4411 || !gdbarch_get_longjmp_target (gdbarch
,
4412 frame
, &jmp_buf_pc
))
4415 fprintf_unfiltered (gdb_stdlog
,
4416 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4417 "(!gdbarch_get_longjmp_target)\n");
4422 /* Insert a breakpoint at resume address. */
4423 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4426 check_exception_resume (ecs
, frame
);
4430 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4432 struct frame_info
*init_frame
;
4434 /* There are several cases to consider.
4436 1. The initiating frame no longer exists. In this case
4437 we must stop, because the exception or longjmp has gone
4440 2. The initiating frame exists, and is the same as the
4441 current frame. We stop, because the exception or
4442 longjmp has been caught.
4444 3. The initiating frame exists and is different from
4445 the current frame. This means the exception or longjmp
4446 has been caught beneath the initiating frame, so keep
4449 4. longjmp breakpoint has been placed just to protect
4450 against stale dummy frames and user is not interested
4451 in stopping around longjmps. */
4454 fprintf_unfiltered (gdb_stdlog
,
4455 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4457 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4459 delete_exception_resume_breakpoint (ecs
->event_thread
);
4461 if (what
.is_longjmp
)
4463 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
->num
);
4465 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4473 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4477 struct frame_id current_id
4478 = get_frame_id (get_current_frame ());
4479 if (frame_id_eq (current_id
,
4480 ecs
->event_thread
->initiating_frame
))
4482 /* Case 2. Fall through. */
4492 /* For Cases 1 and 2, remove the step-resume breakpoint,
4494 delete_step_resume_breakpoint (ecs
->event_thread
);
4496 ecs
->event_thread
->control
.stop_step
= 1;
4497 print_end_stepping_range_reason ();
4498 stop_stepping (ecs
);
4502 case BPSTAT_WHAT_SINGLE
:
4504 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4505 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4506 /* Still need to check other stuff, at least the case where
4507 we are stepping and step out of the right range. */
4510 case BPSTAT_WHAT_STEP_RESUME
:
4512 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4514 delete_step_resume_breakpoint (ecs
->event_thread
);
4515 if (ecs
->event_thread
->control
.proceed_to_finish
4516 && execution_direction
== EXEC_REVERSE
)
4518 struct thread_info
*tp
= ecs
->event_thread
;
4520 /* We are finishing a function in reverse, and just hit
4521 the step-resume breakpoint at the start address of
4522 the function, and we're almost there -- just need to
4523 back up by one more single-step, which should take us
4524 back to the function call. */
4525 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4529 fill_in_stop_func (gdbarch
, ecs
);
4530 if (stop_pc
== ecs
->stop_func_start
4531 && execution_direction
== EXEC_REVERSE
)
4533 /* We are stepping over a function call in reverse, and
4534 just hit the step-resume breakpoint at the start
4535 address of the function. Go back to single-stepping,
4536 which should take us back to the function call. */
4537 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4543 case BPSTAT_WHAT_STOP_NOISY
:
4545 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4546 stop_print_frame
= 1;
4548 /* We are about to nuke the step_resume_breakpointt via the
4549 cleanup chain, so no need to worry about it here. */
4551 stop_stepping (ecs
);
4554 case BPSTAT_WHAT_STOP_SILENT
:
4556 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4557 stop_print_frame
= 0;
4559 /* We are about to nuke the step_resume_breakpoin via the
4560 cleanup chain, so no need to worry about it here. */
4562 stop_stepping (ecs
);
4565 case BPSTAT_WHAT_HP_STEP_RESUME
:
4567 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4569 delete_step_resume_breakpoint (ecs
->event_thread
);
4570 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4572 /* Back when the step-resume breakpoint was inserted, we
4573 were trying to single-step off a breakpoint. Go back
4575 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4576 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4582 case BPSTAT_WHAT_KEEP_CHECKING
:
4587 /* We come here if we hit a breakpoint but should not
4588 stop for it. Possibly we also were stepping
4589 and should stop for that. So fall through and
4590 test for stepping. But, if not stepping,
4593 /* In all-stop mode, if we're currently stepping but have stopped in
4594 some other thread, we need to switch back to the stepped thread. */
4597 struct thread_info
*tp
;
4599 tp
= iterate_over_threads (currently_stepping_or_nexting_callback
,
4603 /* However, if the current thread is blocked on some internal
4604 breakpoint, and we simply need to step over that breakpoint
4605 to get it going again, do that first. */
4606 if ((ecs
->event_thread
->control
.trap_expected
4607 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
4608 || ecs
->event_thread
->stepping_over_breakpoint
)
4614 /* If the stepping thread exited, then don't try to switch
4615 back and resume it, which could fail in several different
4616 ways depending on the target. Instead, just keep going.
4618 We can find a stepping dead thread in the thread list in
4621 - The target supports thread exit events, and when the
4622 target tries to delete the thread from the thread list,
4623 inferior_ptid pointed at the exiting thread. In such
4624 case, calling delete_thread does not really remove the
4625 thread from the list; instead, the thread is left listed,
4626 with 'exited' state.
4628 - The target's debug interface does not support thread
4629 exit events, and so we have no idea whatsoever if the
4630 previously stepping thread is still alive. For that
4631 reason, we need to synchronously query the target
4633 if (is_exited (tp
->ptid
)
4634 || !target_thread_alive (tp
->ptid
))
4637 fprintf_unfiltered (gdb_stdlog
,
4638 "infrun: not switching back to "
4639 "stepped thread, it has vanished\n");
4641 delete_thread (tp
->ptid
);
4646 /* Otherwise, we no longer expect a trap in the current thread.
4647 Clear the trap_expected flag before switching back -- this is
4648 what keep_going would do as well, if we called it. */
4649 ecs
->event_thread
->control
.trap_expected
= 0;
4652 fprintf_unfiltered (gdb_stdlog
,
4653 "infrun: switching back to stepped thread\n");
4655 ecs
->event_thread
= tp
;
4656 ecs
->ptid
= tp
->ptid
;
4657 context_switch (ecs
->ptid
);
4663 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
4666 fprintf_unfiltered (gdb_stdlog
,
4667 "infrun: step-resume breakpoint is inserted\n");
4669 /* Having a step-resume breakpoint overrides anything
4670 else having to do with stepping commands until
4671 that breakpoint is reached. */
4676 if (ecs
->event_thread
->control
.step_range_end
== 0)
4679 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4680 /* Likewise if we aren't even stepping. */
4685 /* Re-fetch current thread's frame in case the code above caused
4686 the frame cache to be re-initialized, making our FRAME variable
4687 a dangling pointer. */
4688 frame
= get_current_frame ();
4689 gdbarch
= get_frame_arch (frame
);
4690 fill_in_stop_func (gdbarch
, ecs
);
4692 /* If stepping through a line, keep going if still within it.
4694 Note that step_range_end is the address of the first instruction
4695 beyond the step range, and NOT the address of the last instruction
4698 Note also that during reverse execution, we may be stepping
4699 through a function epilogue and therefore must detect when
4700 the current-frame changes in the middle of a line. */
4702 if (stop_pc
>= ecs
->event_thread
->control
.step_range_start
4703 && stop_pc
< ecs
->event_thread
->control
.step_range_end
4704 && (execution_direction
!= EXEC_REVERSE
4705 || frame_id_eq (get_frame_id (frame
),
4706 ecs
->event_thread
->control
.step_frame_id
)))
4710 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4711 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
4712 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
4714 /* When stepping backward, stop at beginning of line range
4715 (unless it's the function entry point, in which case
4716 keep going back to the call point). */
4717 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
4718 && stop_pc
!= ecs
->stop_func_start
4719 && execution_direction
== EXEC_REVERSE
)
4721 ecs
->event_thread
->control
.stop_step
= 1;
4722 print_end_stepping_range_reason ();
4723 stop_stepping (ecs
);
4731 /* We stepped out of the stepping range. */
4733 /* If we are stepping at the source level and entered the runtime
4734 loader dynamic symbol resolution code...
4736 EXEC_FORWARD: we keep on single stepping until we exit the run
4737 time loader code and reach the callee's address.
4739 EXEC_REVERSE: we've already executed the callee (backward), and
4740 the runtime loader code is handled just like any other
4741 undebuggable function call. Now we need only keep stepping
4742 backward through the trampoline code, and that's handled further
4743 down, so there is nothing for us to do here. */
4745 if (execution_direction
!= EXEC_REVERSE
4746 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4747 && in_solib_dynsym_resolve_code (stop_pc
))
4749 CORE_ADDR pc_after_resolver
=
4750 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4753 fprintf_unfiltered (gdb_stdlog
,
4754 "infrun: stepped into dynsym resolve code\n");
4756 if (pc_after_resolver
)
4758 /* Set up a step-resume breakpoint at the address
4759 indicated by SKIP_SOLIB_RESOLVER. */
4760 struct symtab_and_line sr_sal
;
4763 sr_sal
.pc
= pc_after_resolver
;
4764 sr_sal
.pspace
= get_frame_program_space (frame
);
4766 insert_step_resume_breakpoint_at_sal (gdbarch
,
4767 sr_sal
, null_frame_id
);
4774 if (ecs
->event_thread
->control
.step_range_end
!= 1
4775 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4776 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4777 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4780 fprintf_unfiltered (gdb_stdlog
,
4781 "infrun: stepped into signal trampoline\n");
4782 /* The inferior, while doing a "step" or "next", has ended up in
4783 a signal trampoline (either by a signal being delivered or by
4784 the signal handler returning). Just single-step until the
4785 inferior leaves the trampoline (either by calling the handler
4791 /* If we're in the return path from a shared library trampoline,
4792 we want to proceed through the trampoline when stepping. */
4793 /* macro/2012-04-25: This needs to come before the subroutine
4794 call check below as on some targets return trampolines look
4795 like subroutine calls (MIPS16 return thunks). */
4796 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4797 stop_pc
, ecs
->stop_func_name
)
4798 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4800 /* Determine where this trampoline returns. */
4801 CORE_ADDR real_stop_pc
;
4803 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4806 fprintf_unfiltered (gdb_stdlog
,
4807 "infrun: stepped into solib return tramp\n");
4809 /* Only proceed through if we know where it's going. */
4812 /* And put the step-breakpoint there and go until there. */
4813 struct symtab_and_line sr_sal
;
4815 init_sal (&sr_sal
); /* initialize to zeroes */
4816 sr_sal
.pc
= real_stop_pc
;
4817 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4818 sr_sal
.pspace
= get_frame_program_space (frame
);
4820 /* Do not specify what the fp should be when we stop since
4821 on some machines the prologue is where the new fp value
4823 insert_step_resume_breakpoint_at_sal (gdbarch
,
4824 sr_sal
, null_frame_id
);
4826 /* Restart without fiddling with the step ranges or
4833 /* Check for subroutine calls. The check for the current frame
4834 equalling the step ID is not necessary - the check of the
4835 previous frame's ID is sufficient - but it is a common case and
4836 cheaper than checking the previous frame's ID.
4838 NOTE: frame_id_eq will never report two invalid frame IDs as
4839 being equal, so to get into this block, both the current and
4840 previous frame must have valid frame IDs. */
4841 /* The outer_frame_id check is a heuristic to detect stepping
4842 through startup code. If we step over an instruction which
4843 sets the stack pointer from an invalid value to a valid value,
4844 we may detect that as a subroutine call from the mythical
4845 "outermost" function. This could be fixed by marking
4846 outermost frames as !stack_p,code_p,special_p. Then the
4847 initial outermost frame, before sp was valid, would
4848 have code_addr == &_start. See the comment in frame_id_eq
4850 if (!frame_id_eq (get_stack_frame_id (frame
),
4851 ecs
->event_thread
->control
.step_stack_frame_id
)
4852 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4853 ecs
->event_thread
->control
.step_stack_frame_id
)
4854 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
4856 || step_start_function
!= find_pc_function (stop_pc
))))
4858 CORE_ADDR real_stop_pc
;
4861 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4863 if ((ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
4864 || ((ecs
->event_thread
->control
.step_range_end
== 1)
4865 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4866 ecs
->stop_func_start
)))
4868 /* I presume that step_over_calls is only 0 when we're
4869 supposed to be stepping at the assembly language level
4870 ("stepi"). Just stop. */
4871 /* Also, maybe we just did a "nexti" inside a prolog, so we
4872 thought it was a subroutine call but it was not. Stop as
4874 /* And this works the same backward as frontward. MVS */
4875 ecs
->event_thread
->control
.stop_step
= 1;
4876 print_end_stepping_range_reason ();
4877 stop_stepping (ecs
);
4881 /* Reverse stepping through solib trampolines. */
4883 if (execution_direction
== EXEC_REVERSE
4884 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
4885 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4886 || (ecs
->stop_func_start
== 0
4887 && in_solib_dynsym_resolve_code (stop_pc
))))
4889 /* Any solib trampoline code can be handled in reverse
4890 by simply continuing to single-step. We have already
4891 executed the solib function (backwards), and a few
4892 steps will take us back through the trampoline to the
4898 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4900 /* We're doing a "next".
4902 Normal (forward) execution: set a breakpoint at the
4903 callee's return address (the address at which the caller
4906 Reverse (backward) execution. set the step-resume
4907 breakpoint at the start of the function that we just
4908 stepped into (backwards), and continue to there. When we
4909 get there, we'll need to single-step back to the caller. */
4911 if (execution_direction
== EXEC_REVERSE
)
4913 /* If we're already at the start of the function, we've either
4914 just stepped backward into a single instruction function,
4915 or stepped back out of a signal handler to the first instruction
4916 of the function. Just keep going, which will single-step back
4918 if (ecs
->stop_func_start
!= stop_pc
)
4920 struct symtab_and_line sr_sal
;
4922 /* Normal function call return (static or dynamic). */
4924 sr_sal
.pc
= ecs
->stop_func_start
;
4925 sr_sal
.pspace
= get_frame_program_space (frame
);
4926 insert_step_resume_breakpoint_at_sal (gdbarch
,
4927 sr_sal
, null_frame_id
);
4931 insert_step_resume_breakpoint_at_caller (frame
);
4937 /* If we are in a function call trampoline (a stub between the
4938 calling routine and the real function), locate the real
4939 function. That's what tells us (a) whether we want to step
4940 into it at all, and (b) what prologue we want to run to the
4941 end of, if we do step into it. */
4942 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
4943 if (real_stop_pc
== 0)
4944 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4945 if (real_stop_pc
!= 0)
4946 ecs
->stop_func_start
= real_stop_pc
;
4948 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
4950 struct symtab_and_line sr_sal
;
4953 sr_sal
.pc
= ecs
->stop_func_start
;
4954 sr_sal
.pspace
= get_frame_program_space (frame
);
4956 insert_step_resume_breakpoint_at_sal (gdbarch
,
4957 sr_sal
, null_frame_id
);
4962 /* If we have line number information for the function we are
4963 thinking of stepping into and the function isn't on the skip
4966 If there are several symtabs at that PC (e.g. with include
4967 files), just want to know whether *any* of them have line
4968 numbers. find_pc_line handles this. */
4970 struct symtab_and_line tmp_sal
;
4972 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
4973 if (tmp_sal
.line
!= 0
4974 && !function_pc_is_marked_for_skip (ecs
->stop_func_start
))
4976 if (execution_direction
== EXEC_REVERSE
)
4977 handle_step_into_function_backward (gdbarch
, ecs
);
4979 handle_step_into_function (gdbarch
, ecs
);
4984 /* If we have no line number and the step-stop-if-no-debug is
4985 set, we stop the step so that the user has a chance to switch
4986 in assembly mode. */
4987 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4988 && step_stop_if_no_debug
)
4990 ecs
->event_thread
->control
.stop_step
= 1;
4991 print_end_stepping_range_reason ();
4992 stop_stepping (ecs
);
4996 if (execution_direction
== EXEC_REVERSE
)
4998 /* If we're already at the start of the function, we've either just
4999 stepped backward into a single instruction function without line
5000 number info, or stepped back out of a signal handler to the first
5001 instruction of the function without line number info. Just keep
5002 going, which will single-step back to the caller. */
5003 if (ecs
->stop_func_start
!= stop_pc
)
5005 /* Set a breakpoint at callee's start address.
5006 From there we can step once and be back in the caller. */
5007 struct symtab_and_line sr_sal
;
5010 sr_sal
.pc
= ecs
->stop_func_start
;
5011 sr_sal
.pspace
= get_frame_program_space (frame
);
5012 insert_step_resume_breakpoint_at_sal (gdbarch
,
5013 sr_sal
, null_frame_id
);
5017 /* Set a breakpoint at callee's return address (the address
5018 at which the caller will resume). */
5019 insert_step_resume_breakpoint_at_caller (frame
);
5025 /* Reverse stepping through solib trampolines. */
5027 if (execution_direction
== EXEC_REVERSE
5028 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5030 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5031 || (ecs
->stop_func_start
== 0
5032 && in_solib_dynsym_resolve_code (stop_pc
)))
5034 /* Any solib trampoline code can be handled in reverse
5035 by simply continuing to single-step. We have already
5036 executed the solib function (backwards), and a few
5037 steps will take us back through the trampoline to the
5042 else if (in_solib_dynsym_resolve_code (stop_pc
))
5044 /* Stepped backward into the solib dynsym resolver.
5045 Set a breakpoint at its start and continue, then
5046 one more step will take us out. */
5047 struct symtab_and_line sr_sal
;
5050 sr_sal
.pc
= ecs
->stop_func_start
;
5051 sr_sal
.pspace
= get_frame_program_space (frame
);
5052 insert_step_resume_breakpoint_at_sal (gdbarch
,
5053 sr_sal
, null_frame_id
);
5059 stop_pc_sal
= find_pc_line (stop_pc
, 0);
5061 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5062 the trampoline processing logic, however, there are some trampolines
5063 that have no names, so we should do trampoline handling first. */
5064 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5065 && ecs
->stop_func_name
== NULL
5066 && stop_pc_sal
.line
== 0)
5069 fprintf_unfiltered (gdb_stdlog
,
5070 "infrun: stepped into undebuggable function\n");
5072 /* The inferior just stepped into, or returned to, an
5073 undebuggable function (where there is no debugging information
5074 and no line number corresponding to the address where the
5075 inferior stopped). Since we want to skip this kind of code,
5076 we keep going until the inferior returns from this
5077 function - unless the user has asked us not to (via
5078 set step-mode) or we no longer know how to get back
5079 to the call site. */
5080 if (step_stop_if_no_debug
5081 || !frame_id_p (frame_unwind_caller_id (frame
)))
5083 /* If we have no line number and the step-stop-if-no-debug
5084 is set, we stop the step so that the user has a chance to
5085 switch in assembly mode. */
5086 ecs
->event_thread
->control
.stop_step
= 1;
5087 print_end_stepping_range_reason ();
5088 stop_stepping (ecs
);
5093 /* Set a breakpoint at callee's return address (the address
5094 at which the caller will resume). */
5095 insert_step_resume_breakpoint_at_caller (frame
);
5101 if (ecs
->event_thread
->control
.step_range_end
== 1)
5103 /* It is stepi or nexti. We always want to stop stepping after
5106 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5107 ecs
->event_thread
->control
.stop_step
= 1;
5108 print_end_stepping_range_reason ();
5109 stop_stepping (ecs
);
5113 if (stop_pc_sal
.line
== 0)
5115 /* We have no line number information. That means to stop
5116 stepping (does this always happen right after one instruction,
5117 when we do "s" in a function with no line numbers,
5118 or can this happen as a result of a return or longjmp?). */
5120 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5121 ecs
->event_thread
->control
.stop_step
= 1;
5122 print_end_stepping_range_reason ();
5123 stop_stepping (ecs
);
5127 /* Look for "calls" to inlined functions, part one. If the inline
5128 frame machinery detected some skipped call sites, we have entered
5129 a new inline function. */
5131 if (frame_id_eq (get_frame_id (get_current_frame ()),
5132 ecs
->event_thread
->control
.step_frame_id
)
5133 && inline_skipped_frames (ecs
->ptid
))
5135 struct symtab_and_line call_sal
;
5138 fprintf_unfiltered (gdb_stdlog
,
5139 "infrun: stepped into inlined function\n");
5141 find_frame_sal (get_current_frame (), &call_sal
);
5143 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5145 /* For "step", we're going to stop. But if the call site
5146 for this inlined function is on the same source line as
5147 we were previously stepping, go down into the function
5148 first. Otherwise stop at the call site. */
5150 if (call_sal
.line
== ecs
->event_thread
->current_line
5151 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5152 step_into_inline_frame (ecs
->ptid
);
5154 ecs
->event_thread
->control
.stop_step
= 1;
5155 print_end_stepping_range_reason ();
5156 stop_stepping (ecs
);
5161 /* For "next", we should stop at the call site if it is on a
5162 different source line. Otherwise continue through the
5163 inlined function. */
5164 if (call_sal
.line
== ecs
->event_thread
->current_line
5165 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5169 ecs
->event_thread
->control
.stop_step
= 1;
5170 print_end_stepping_range_reason ();
5171 stop_stepping (ecs
);
5177 /* Look for "calls" to inlined functions, part two. If we are still
5178 in the same real function we were stepping through, but we have
5179 to go further up to find the exact frame ID, we are stepping
5180 through a more inlined call beyond its call site. */
5182 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5183 && !frame_id_eq (get_frame_id (get_current_frame ()),
5184 ecs
->event_thread
->control
.step_frame_id
)
5185 && stepped_in_from (get_current_frame (),
5186 ecs
->event_thread
->control
.step_frame_id
))
5189 fprintf_unfiltered (gdb_stdlog
,
5190 "infrun: stepping through inlined function\n");
5192 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5196 ecs
->event_thread
->control
.stop_step
= 1;
5197 print_end_stepping_range_reason ();
5198 stop_stepping (ecs
);
5203 if ((stop_pc
== stop_pc_sal
.pc
)
5204 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5205 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5207 /* We are at the start of a different line. So stop. Note that
5208 we don't stop if we step into the middle of a different line.
5209 That is said to make things like for (;;) statements work
5212 fprintf_unfiltered (gdb_stdlog
,
5213 "infrun: stepped to a different line\n");
5214 ecs
->event_thread
->control
.stop_step
= 1;
5215 print_end_stepping_range_reason ();
5216 stop_stepping (ecs
);
5220 /* We aren't done stepping.
5222 Optimize by setting the stepping range to the line.
5223 (We might not be in the original line, but if we entered a
5224 new line in mid-statement, we continue stepping. This makes
5225 things like for(;;) statements work better.) */
5227 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5228 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5229 set_step_info (frame
, stop_pc_sal
);
5232 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5236 /* Is thread TP in the middle of single-stepping? */
5239 currently_stepping (struct thread_info
*tp
)
5241 return ((tp
->control
.step_range_end
5242 && tp
->control
.step_resume_breakpoint
== NULL
)
5243 || tp
->control
.trap_expected
5244 || bpstat_should_step ());
5247 /* Returns true if any thread *but* the one passed in "data" is in the
5248 middle of stepping or of handling a "next". */
5251 currently_stepping_or_nexting_callback (struct thread_info
*tp
, void *data
)
5256 return (tp
->control
.step_range_end
5257 || tp
->control
.trap_expected
);
5260 /* Inferior has stepped into a subroutine call with source code that
5261 we should not step over. Do step to the first line of code in
5265 handle_step_into_function (struct gdbarch
*gdbarch
,
5266 struct execution_control_state
*ecs
)
5269 struct symtab_and_line stop_func_sal
, sr_sal
;
5271 fill_in_stop_func (gdbarch
, ecs
);
5273 s
= find_pc_symtab (stop_pc
);
5274 if (s
&& s
->language
!= language_asm
)
5275 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5276 ecs
->stop_func_start
);
5278 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5279 /* Use the step_resume_break to step until the end of the prologue,
5280 even if that involves jumps (as it seems to on the vax under
5282 /* If the prologue ends in the middle of a source line, continue to
5283 the end of that source line (if it is still within the function).
5284 Otherwise, just go to end of prologue. */
5285 if (stop_func_sal
.end
5286 && stop_func_sal
.pc
!= ecs
->stop_func_start
5287 && stop_func_sal
.end
< ecs
->stop_func_end
)
5288 ecs
->stop_func_start
= stop_func_sal
.end
;
5290 /* Architectures which require breakpoint adjustment might not be able
5291 to place a breakpoint at the computed address. If so, the test
5292 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5293 ecs->stop_func_start to an address at which a breakpoint may be
5294 legitimately placed.
5296 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5297 made, GDB will enter an infinite loop when stepping through
5298 optimized code consisting of VLIW instructions which contain
5299 subinstructions corresponding to different source lines. On
5300 FR-V, it's not permitted to place a breakpoint on any but the
5301 first subinstruction of a VLIW instruction. When a breakpoint is
5302 set, GDB will adjust the breakpoint address to the beginning of
5303 the VLIW instruction. Thus, we need to make the corresponding
5304 adjustment here when computing the stop address. */
5306 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5308 ecs
->stop_func_start
5309 = gdbarch_adjust_breakpoint_address (gdbarch
,
5310 ecs
->stop_func_start
);
5313 if (ecs
->stop_func_start
== stop_pc
)
5315 /* We are already there: stop now. */
5316 ecs
->event_thread
->control
.stop_step
= 1;
5317 print_end_stepping_range_reason ();
5318 stop_stepping (ecs
);
5323 /* Put the step-breakpoint there and go until there. */
5324 init_sal (&sr_sal
); /* initialize to zeroes */
5325 sr_sal
.pc
= ecs
->stop_func_start
;
5326 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5327 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5329 /* Do not specify what the fp should be when we stop since on
5330 some machines the prologue is where the new fp value is
5332 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5334 /* And make sure stepping stops right away then. */
5335 ecs
->event_thread
->control
.step_range_end
5336 = ecs
->event_thread
->control
.step_range_start
;
5341 /* Inferior has stepped backward into a subroutine call with source
5342 code that we should not step over. Do step to the beginning of the
5343 last line of code in it. */
5346 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5347 struct execution_control_state
*ecs
)
5350 struct symtab_and_line stop_func_sal
;
5352 fill_in_stop_func (gdbarch
, ecs
);
5354 s
= find_pc_symtab (stop_pc
);
5355 if (s
&& s
->language
!= language_asm
)
5356 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5357 ecs
->stop_func_start
);
5359 stop_func_sal
= find_pc_line (stop_pc
, 0);
5361 /* OK, we're just going to keep stepping here. */
5362 if (stop_func_sal
.pc
== stop_pc
)
5364 /* We're there already. Just stop stepping now. */
5365 ecs
->event_thread
->control
.stop_step
= 1;
5366 print_end_stepping_range_reason ();
5367 stop_stepping (ecs
);
5371 /* Else just reset the step range and keep going.
5372 No step-resume breakpoint, they don't work for
5373 epilogues, which can have multiple entry paths. */
5374 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5375 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5381 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5382 This is used to both functions and to skip over code. */
5385 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5386 struct symtab_and_line sr_sal
,
5387 struct frame_id sr_id
,
5388 enum bptype sr_type
)
5390 /* There should never be more than one step-resume or longjmp-resume
5391 breakpoint per thread, so we should never be setting a new
5392 step_resume_breakpoint when one is already active. */
5393 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5394 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5397 fprintf_unfiltered (gdb_stdlog
,
5398 "infrun: inserting step-resume breakpoint at %s\n",
5399 paddress (gdbarch
, sr_sal
.pc
));
5401 inferior_thread ()->control
.step_resume_breakpoint
5402 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5406 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5407 struct symtab_and_line sr_sal
,
5408 struct frame_id sr_id
)
5410 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5415 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5416 This is used to skip a potential signal handler.
5418 This is called with the interrupted function's frame. The signal
5419 handler, when it returns, will resume the interrupted function at
5423 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5425 struct symtab_and_line sr_sal
;
5426 struct gdbarch
*gdbarch
;
5428 gdb_assert (return_frame
!= NULL
);
5429 init_sal (&sr_sal
); /* initialize to zeros */
5431 gdbarch
= get_frame_arch (return_frame
);
5432 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5433 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5434 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5436 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5437 get_stack_frame_id (return_frame
),
5441 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5442 is used to skip a function after stepping into it (for "next" or if
5443 the called function has no debugging information).
5445 The current function has almost always been reached by single
5446 stepping a call or return instruction. NEXT_FRAME belongs to the
5447 current function, and the breakpoint will be set at the caller's
5450 This is a separate function rather than reusing
5451 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5452 get_prev_frame, which may stop prematurely (see the implementation
5453 of frame_unwind_caller_id for an example). */
5456 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5458 struct symtab_and_line sr_sal
;
5459 struct gdbarch
*gdbarch
;
5461 /* We shouldn't have gotten here if we don't know where the call site
5463 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5465 init_sal (&sr_sal
); /* initialize to zeros */
5467 gdbarch
= frame_unwind_caller_arch (next_frame
);
5468 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5469 frame_unwind_caller_pc (next_frame
));
5470 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5471 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5473 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5474 frame_unwind_caller_id (next_frame
));
5477 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5478 new breakpoint at the target of a jmp_buf. The handling of
5479 longjmp-resume uses the same mechanisms used for handling
5480 "step-resume" breakpoints. */
5483 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5485 /* There should never be more than one longjmp-resume breakpoint per
5486 thread, so we should never be setting a new
5487 longjmp_resume_breakpoint when one is already active. */
5488 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
5491 fprintf_unfiltered (gdb_stdlog
,
5492 "infrun: inserting longjmp-resume breakpoint at %s\n",
5493 paddress (gdbarch
, pc
));
5495 inferior_thread ()->control
.exception_resume_breakpoint
=
5496 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
5499 /* Insert an exception resume breakpoint. TP is the thread throwing
5500 the exception. The block B is the block of the unwinder debug hook
5501 function. FRAME is the frame corresponding to the call to this
5502 function. SYM is the symbol of the function argument holding the
5503 target PC of the exception. */
5506 insert_exception_resume_breakpoint (struct thread_info
*tp
,
5508 struct frame_info
*frame
,
5511 volatile struct gdb_exception e
;
5513 /* We want to ignore errors here. */
5514 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5516 struct symbol
*vsym
;
5517 struct value
*value
;
5519 struct breakpoint
*bp
;
5521 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
5522 value
= read_var_value (vsym
, frame
);
5523 /* If the value was optimized out, revert to the old behavior. */
5524 if (! value_optimized_out (value
))
5526 handler
= value_as_address (value
);
5529 fprintf_unfiltered (gdb_stdlog
,
5530 "infrun: exception resume at %lx\n",
5531 (unsigned long) handler
);
5533 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5534 handler
, bp_exception_resume
);
5536 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5539 bp
->thread
= tp
->num
;
5540 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5545 /* A helper for check_exception_resume that sets an
5546 exception-breakpoint based on a SystemTap probe. */
5549 insert_exception_resume_from_probe (struct thread_info
*tp
,
5550 const struct probe
*probe
,
5551 struct frame_info
*frame
)
5553 struct value
*arg_value
;
5555 struct breakpoint
*bp
;
5557 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
5561 handler
= value_as_address (arg_value
);
5564 fprintf_unfiltered (gdb_stdlog
,
5565 "infrun: exception resume at %s\n",
5566 paddress (get_objfile_arch (probe
->objfile
),
5569 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5570 handler
, bp_exception_resume
);
5571 bp
->thread
= tp
->num
;
5572 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5575 /* This is called when an exception has been intercepted. Check to
5576 see whether the exception's destination is of interest, and if so,
5577 set an exception resume breakpoint there. */
5580 check_exception_resume (struct execution_control_state
*ecs
,
5581 struct frame_info
*frame
)
5583 volatile struct gdb_exception e
;
5584 const struct probe
*probe
;
5585 struct symbol
*func
;
5587 /* First see if this exception unwinding breakpoint was set via a
5588 SystemTap probe point. If so, the probe has two arguments: the
5589 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5590 set a breakpoint there. */
5591 probe
= find_probe_by_pc (get_frame_pc (frame
));
5594 insert_exception_resume_from_probe (ecs
->event_thread
, probe
, frame
);
5598 func
= get_frame_function (frame
);
5602 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5605 struct block_iterator iter
;
5609 /* The exception breakpoint is a thread-specific breakpoint on
5610 the unwinder's debug hook, declared as:
5612 void _Unwind_DebugHook (void *cfa, void *handler);
5614 The CFA argument indicates the frame to which control is
5615 about to be transferred. HANDLER is the destination PC.
5617 We ignore the CFA and set a temporary breakpoint at HANDLER.
5618 This is not extremely efficient but it avoids issues in gdb
5619 with computing the DWARF CFA, and it also works even in weird
5620 cases such as throwing an exception from inside a signal
5623 b
= SYMBOL_BLOCK_VALUE (func
);
5624 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5626 if (!SYMBOL_IS_ARGUMENT (sym
))
5633 insert_exception_resume_breakpoint (ecs
->event_thread
,
5642 stop_stepping (struct execution_control_state
*ecs
)
5645 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
5647 /* Let callers know we don't want to wait for the inferior anymore. */
5648 ecs
->wait_some_more
= 0;
5651 /* This function handles various cases where we need to continue
5652 waiting for the inferior. */
5653 /* (Used to be the keep_going: label in the old wait_for_inferior). */
5656 keep_going (struct execution_control_state
*ecs
)
5658 /* Make sure normal_stop is called if we get a QUIT handled before
5660 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
5662 /* Save the pc before execution, to compare with pc after stop. */
5663 ecs
->event_thread
->prev_pc
5664 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5666 /* If we did not do break;, it means we should keep running the
5667 inferior and not return to debugger. */
5669 if (ecs
->event_thread
->control
.trap_expected
5670 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5672 /* We took a signal (which we are supposed to pass through to
5673 the inferior, else we'd not get here) and we haven't yet
5674 gotten our trap. Simply continue. */
5676 discard_cleanups (old_cleanups
);
5677 resume (currently_stepping (ecs
->event_thread
),
5678 ecs
->event_thread
->suspend
.stop_signal
);
5682 /* Either the trap was not expected, but we are continuing
5683 anyway (the user asked that this signal be passed to the
5686 The signal was SIGTRAP, e.g. it was our signal, but we
5687 decided we should resume from it.
5689 We're going to run this baby now!
5691 Note that insert_breakpoints won't try to re-insert
5692 already inserted breakpoints. Therefore, we don't
5693 care if breakpoints were already inserted, or not. */
5695 if (ecs
->event_thread
->stepping_over_breakpoint
)
5697 struct regcache
*thread_regcache
= get_thread_regcache (ecs
->ptid
);
5699 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
5700 /* Since we can't do a displaced step, we have to remove
5701 the breakpoint while we step it. To keep things
5702 simple, we remove them all. */
5703 remove_breakpoints ();
5707 volatile struct gdb_exception e
;
5709 /* Stop stepping when inserting breakpoints
5711 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5713 insert_breakpoints ();
5717 exception_print (gdb_stderr
, e
);
5718 stop_stepping (ecs
);
5723 ecs
->event_thread
->control
.trap_expected
5724 = ecs
->event_thread
->stepping_over_breakpoint
;
5726 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5727 specifies that such a signal should be delivered to the
5730 Typically, this would occure when a user is debugging a
5731 target monitor on a simulator: the target monitor sets a
5732 breakpoint; the simulator encounters this break-point and
5733 halts the simulation handing control to GDB; GDB, noteing
5734 that the break-point isn't valid, returns control back to the
5735 simulator; the simulator then delivers the hardware
5736 equivalent of a SIGNAL_TRAP to the program being debugged. */
5738 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5739 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5740 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5742 discard_cleanups (old_cleanups
);
5743 resume (currently_stepping (ecs
->event_thread
),
5744 ecs
->event_thread
->suspend
.stop_signal
);
5747 prepare_to_wait (ecs
);
5750 /* This function normally comes after a resume, before
5751 handle_inferior_event exits. It takes care of any last bits of
5752 housekeeping, and sets the all-important wait_some_more flag. */
5755 prepare_to_wait (struct execution_control_state
*ecs
)
5758 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
5760 /* This is the old end of the while loop. Let everybody know we
5761 want to wait for the inferior some more and get called again
5763 ecs
->wait_some_more
= 1;
5766 /* Several print_*_reason functions to print why the inferior has stopped.
5767 We always print something when the inferior exits, or receives a signal.
5768 The rest of the cases are dealt with later on in normal_stop and
5769 print_it_typical. Ideally there should be a call to one of these
5770 print_*_reason functions functions from handle_inferior_event each time
5771 stop_stepping is called. */
5773 /* Print why the inferior has stopped.
5774 We are done with a step/next/si/ni command, print why the inferior has
5775 stopped. For now print nothing. Print a message only if not in the middle
5776 of doing a "step n" operation for n > 1. */
5779 print_end_stepping_range_reason (void)
5781 if ((!inferior_thread ()->step_multi
5782 || !inferior_thread ()->control
.stop_step
)
5783 && ui_out_is_mi_like_p (current_uiout
))
5784 ui_out_field_string (current_uiout
, "reason",
5785 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
5788 /* The inferior was terminated by a signal, print why it stopped. */
5791 print_signal_exited_reason (enum gdb_signal siggnal
)
5793 struct ui_out
*uiout
= current_uiout
;
5795 annotate_signalled ();
5796 if (ui_out_is_mi_like_p (uiout
))
5798 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
5799 ui_out_text (uiout
, "\nProgram terminated with signal ");
5800 annotate_signal_name ();
5801 ui_out_field_string (uiout
, "signal-name",
5802 gdb_signal_to_name (siggnal
));
5803 annotate_signal_name_end ();
5804 ui_out_text (uiout
, ", ");
5805 annotate_signal_string ();
5806 ui_out_field_string (uiout
, "signal-meaning",
5807 gdb_signal_to_string (siggnal
));
5808 annotate_signal_string_end ();
5809 ui_out_text (uiout
, ".\n");
5810 ui_out_text (uiout
, "The program no longer exists.\n");
5813 /* The inferior program is finished, print why it stopped. */
5816 print_exited_reason (int exitstatus
)
5818 struct inferior
*inf
= current_inferior ();
5819 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
5820 struct ui_out
*uiout
= current_uiout
;
5822 annotate_exited (exitstatus
);
5825 if (ui_out_is_mi_like_p (uiout
))
5826 ui_out_field_string (uiout
, "reason",
5827 async_reason_lookup (EXEC_ASYNC_EXITED
));
5828 ui_out_text (uiout
, "[Inferior ");
5829 ui_out_text (uiout
, plongest (inf
->num
));
5830 ui_out_text (uiout
, " (");
5831 ui_out_text (uiout
, pidstr
);
5832 ui_out_text (uiout
, ") exited with code ");
5833 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
5834 ui_out_text (uiout
, "]\n");
5838 if (ui_out_is_mi_like_p (uiout
))
5840 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
5841 ui_out_text (uiout
, "[Inferior ");
5842 ui_out_text (uiout
, plongest (inf
->num
));
5843 ui_out_text (uiout
, " (");
5844 ui_out_text (uiout
, pidstr
);
5845 ui_out_text (uiout
, ") exited normally]\n");
5847 /* Support the --return-child-result option. */
5848 return_child_result_value
= exitstatus
;
5851 /* Signal received, print why the inferior has stopped. The signal table
5852 tells us to print about it. */
5855 print_signal_received_reason (enum gdb_signal siggnal
)
5857 struct ui_out
*uiout
= current_uiout
;
5861 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
5863 struct thread_info
*t
= inferior_thread ();
5865 ui_out_text (uiout
, "\n[");
5866 ui_out_field_string (uiout
, "thread-name",
5867 target_pid_to_str (t
->ptid
));
5868 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
5869 ui_out_text (uiout
, " stopped");
5873 ui_out_text (uiout
, "\nProgram received signal ");
5874 annotate_signal_name ();
5875 if (ui_out_is_mi_like_p (uiout
))
5877 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
5878 ui_out_field_string (uiout
, "signal-name",
5879 gdb_signal_to_name (siggnal
));
5880 annotate_signal_name_end ();
5881 ui_out_text (uiout
, ", ");
5882 annotate_signal_string ();
5883 ui_out_field_string (uiout
, "signal-meaning",
5884 gdb_signal_to_string (siggnal
));
5885 annotate_signal_string_end ();
5887 ui_out_text (uiout
, ".\n");
5890 /* Reverse execution: target ran out of history info, print why the inferior
5894 print_no_history_reason (void)
5896 ui_out_text (current_uiout
, "\nNo more reverse-execution history.\n");
5899 /* Here to return control to GDB when the inferior stops for real.
5900 Print appropriate messages, remove breakpoints, give terminal our modes.
5902 STOP_PRINT_FRAME nonzero means print the executing frame
5903 (pc, function, args, file, line number and line text).
5904 BREAKPOINTS_FAILED nonzero means stop was due to error
5905 attempting to insert breakpoints. */
5910 struct target_waitstatus last
;
5912 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
5914 get_last_target_status (&last_ptid
, &last
);
5916 /* If an exception is thrown from this point on, make sure to
5917 propagate GDB's knowledge of the executing state to the
5918 frontend/user running state. A QUIT is an easy exception to see
5919 here, so do this before any filtered output. */
5921 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
5922 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
5923 && last
.kind
!= TARGET_WAITKIND_EXITED
5924 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
5925 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
5927 /* In non-stop mode, we don't want GDB to switch threads behind the
5928 user's back, to avoid races where the user is typing a command to
5929 apply to thread x, but GDB switches to thread y before the user
5930 finishes entering the command. */
5932 /* As with the notification of thread events, we want to delay
5933 notifying the user that we've switched thread context until
5934 the inferior actually stops.
5936 There's no point in saying anything if the inferior has exited.
5937 Note that SIGNALLED here means "exited with a signal", not
5938 "received a signal". */
5940 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
5941 && target_has_execution
5942 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5943 && last
.kind
!= TARGET_WAITKIND_EXITED
5944 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
5946 target_terminal_ours_for_output ();
5947 printf_filtered (_("[Switching to %s]\n"),
5948 target_pid_to_str (inferior_ptid
));
5949 annotate_thread_changed ();
5950 previous_inferior_ptid
= inferior_ptid
;
5953 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
5955 gdb_assert (sync_execution
|| !target_can_async_p ());
5957 target_terminal_ours_for_output ();
5958 printf_filtered (_("No unwaited-for children left.\n"));
5961 if (!breakpoints_always_inserted_mode () && target_has_execution
)
5963 if (remove_breakpoints ())
5965 target_terminal_ours_for_output ();
5966 printf_filtered (_("Cannot remove breakpoints because "
5967 "program is no longer writable.\nFurther "
5968 "execution is probably impossible.\n"));
5972 /* If an auto-display called a function and that got a signal,
5973 delete that auto-display to avoid an infinite recursion. */
5975 if (stopped_by_random_signal
)
5976 disable_current_display ();
5978 /* Don't print a message if in the middle of doing a "step n"
5979 operation for n > 1 */
5980 if (target_has_execution
5981 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5982 && last
.kind
!= TARGET_WAITKIND_EXITED
5983 && inferior_thread ()->step_multi
5984 && inferior_thread ()->control
.stop_step
)
5987 target_terminal_ours ();
5988 async_enable_stdin ();
5990 /* Set the current source location. This will also happen if we
5991 display the frame below, but the current SAL will be incorrect
5992 during a user hook-stop function. */
5993 if (has_stack_frames () && !stop_stack_dummy
)
5994 set_current_sal_from_frame (get_current_frame (), 1);
5996 /* Let the user/frontend see the threads as stopped. */
5997 do_cleanups (old_chain
);
5999 /* Look up the hook_stop and run it (CLI internally handles problem
6000 of stop_command's pre-hook not existing). */
6002 catch_errors (hook_stop_stub
, stop_command
,
6003 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6005 if (!has_stack_frames ())
6008 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6009 || last
.kind
== TARGET_WAITKIND_EXITED
)
6012 /* Select innermost stack frame - i.e., current frame is frame 0,
6013 and current location is based on that.
6014 Don't do this on return from a stack dummy routine,
6015 or if the program has exited. */
6017 if (!stop_stack_dummy
)
6019 select_frame (get_current_frame ());
6021 /* Print current location without a level number, if
6022 we have changed functions or hit a breakpoint.
6023 Print source line if we have one.
6024 bpstat_print() contains the logic deciding in detail
6025 what to print, based on the event(s) that just occurred. */
6027 /* If --batch-silent is enabled then there's no need to print the current
6028 source location, and to try risks causing an error message about
6029 missing source files. */
6030 if (stop_print_frame
&& !batch_silent
)
6034 int do_frame_printing
= 1;
6035 struct thread_info
*tp
= inferior_thread ();
6037 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, last
.kind
);
6041 /* FIXME: cagney/2002-12-01: Given that a frame ID does
6042 (or should) carry around the function and does (or
6043 should) use that when doing a frame comparison. */
6044 if (tp
->control
.stop_step
6045 && frame_id_eq (tp
->control
.step_frame_id
,
6046 get_frame_id (get_current_frame ()))
6047 && step_start_function
== find_pc_function (stop_pc
))
6048 source_flag
= SRC_LINE
; /* Finished step, just
6049 print source line. */
6051 source_flag
= SRC_AND_LOC
; /* Print location and
6054 case PRINT_SRC_AND_LOC
:
6055 source_flag
= SRC_AND_LOC
; /* Print location and
6058 case PRINT_SRC_ONLY
:
6059 source_flag
= SRC_LINE
;
6062 source_flag
= SRC_LINE
; /* something bogus */
6063 do_frame_printing
= 0;
6066 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6069 /* The behavior of this routine with respect to the source
6071 SRC_LINE: Print only source line
6072 LOCATION: Print only location
6073 SRC_AND_LOC: Print location and source line. */
6074 if (do_frame_printing
)
6075 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
6077 /* Display the auto-display expressions. */
6082 /* Save the function value return registers, if we care.
6083 We might be about to restore their previous contents. */
6084 if (inferior_thread ()->control
.proceed_to_finish
6085 && execution_direction
!= EXEC_REVERSE
)
6087 /* This should not be necessary. */
6089 regcache_xfree (stop_registers
);
6091 /* NB: The copy goes through to the target picking up the value of
6092 all the registers. */
6093 stop_registers
= regcache_dup (get_current_regcache ());
6096 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6098 /* Pop the empty frame that contains the stack dummy.
6099 This also restores inferior state prior to the call
6100 (struct infcall_suspend_state). */
6101 struct frame_info
*frame
= get_current_frame ();
6103 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6105 /* frame_pop() calls reinit_frame_cache as the last thing it
6106 does which means there's currently no selected frame. We
6107 don't need to re-establish a selected frame if the dummy call
6108 returns normally, that will be done by
6109 restore_infcall_control_state. However, we do have to handle
6110 the case where the dummy call is returning after being
6111 stopped (e.g. the dummy call previously hit a breakpoint).
6112 We can't know which case we have so just always re-establish
6113 a selected frame here. */
6114 select_frame (get_current_frame ());
6118 annotate_stopped ();
6120 /* Suppress the stop observer if we're in the middle of:
6122 - a step n (n > 1), as there still more steps to be done.
6124 - a "finish" command, as the observer will be called in
6125 finish_command_continuation, so it can include the inferior
6126 function's return value.
6128 - calling an inferior function, as we pretend we inferior didn't
6129 run at all. The return value of the call is handled by the
6130 expression evaluator, through call_function_by_hand. */
6132 if (!target_has_execution
6133 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6134 || last
.kind
== TARGET_WAITKIND_EXITED
6135 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6136 || (!(inferior_thread ()->step_multi
6137 && inferior_thread ()->control
.stop_step
)
6138 && !(inferior_thread ()->control
.stop_bpstat
6139 && inferior_thread ()->control
.proceed_to_finish
)
6140 && !inferior_thread ()->control
.in_infcall
))
6142 if (!ptid_equal (inferior_ptid
, null_ptid
))
6143 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6146 observer_notify_normal_stop (NULL
, stop_print_frame
);
6149 if (target_has_execution
)
6151 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6152 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6153 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6154 Delete any breakpoint that is to be deleted at the next stop. */
6155 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6158 /* Try to get rid of automatically added inferiors that are no
6159 longer needed. Keeping those around slows down things linearly.
6160 Note that this never removes the current inferior. */
6165 hook_stop_stub (void *cmd
)
6167 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6172 signal_stop_state (int signo
)
6174 return signal_stop
[signo
];
6178 signal_print_state (int signo
)
6180 return signal_print
[signo
];
6184 signal_pass_state (int signo
)
6186 return signal_program
[signo
];
6190 signal_cache_update (int signo
)
6194 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6195 signal_cache_update (signo
);
6200 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6201 && signal_print
[signo
] == 0
6202 && signal_program
[signo
] == 1);
6206 signal_stop_update (int signo
, int state
)
6208 int ret
= signal_stop
[signo
];
6210 signal_stop
[signo
] = state
;
6211 signal_cache_update (signo
);
6216 signal_print_update (int signo
, int state
)
6218 int ret
= signal_print
[signo
];
6220 signal_print
[signo
] = state
;
6221 signal_cache_update (signo
);
6226 signal_pass_update (int signo
, int state
)
6228 int ret
= signal_program
[signo
];
6230 signal_program
[signo
] = state
;
6231 signal_cache_update (signo
);
6236 sig_print_header (void)
6238 printf_filtered (_("Signal Stop\tPrint\tPass "
6239 "to program\tDescription\n"));
6243 sig_print_info (enum gdb_signal oursig
)
6245 const char *name
= gdb_signal_to_name (oursig
);
6246 int name_padding
= 13 - strlen (name
);
6248 if (name_padding
<= 0)
6251 printf_filtered ("%s", name
);
6252 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6253 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6254 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6255 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6256 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6259 /* Specify how various signals in the inferior should be handled. */
6262 handle_command (char *args
, int from_tty
)
6265 int digits
, wordlen
;
6266 int sigfirst
, signum
, siglast
;
6267 enum gdb_signal oursig
;
6270 unsigned char *sigs
;
6271 struct cleanup
*old_chain
;
6275 error_no_arg (_("signal to handle"));
6278 /* Allocate and zero an array of flags for which signals to handle. */
6280 nsigs
= (int) GDB_SIGNAL_LAST
;
6281 sigs
= (unsigned char *) alloca (nsigs
);
6282 memset (sigs
, 0, nsigs
);
6284 /* Break the command line up into args. */
6286 argv
= gdb_buildargv (args
);
6287 old_chain
= make_cleanup_freeargv (argv
);
6289 /* Walk through the args, looking for signal oursigs, signal names, and
6290 actions. Signal numbers and signal names may be interspersed with
6291 actions, with the actions being performed for all signals cumulatively
6292 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6294 while (*argv
!= NULL
)
6296 wordlen
= strlen (*argv
);
6297 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6301 sigfirst
= siglast
= -1;
6303 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6305 /* Apply action to all signals except those used by the
6306 debugger. Silently skip those. */
6309 siglast
= nsigs
- 1;
6311 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6313 SET_SIGS (nsigs
, sigs
, signal_stop
);
6314 SET_SIGS (nsigs
, sigs
, signal_print
);
6316 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6318 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6320 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6322 SET_SIGS (nsigs
, sigs
, signal_print
);
6324 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6326 SET_SIGS (nsigs
, sigs
, signal_program
);
6328 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6330 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6332 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6334 SET_SIGS (nsigs
, sigs
, signal_program
);
6336 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6338 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6339 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6341 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6343 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6345 else if (digits
> 0)
6347 /* It is numeric. The numeric signal refers to our own
6348 internal signal numbering from target.h, not to host/target
6349 signal number. This is a feature; users really should be
6350 using symbolic names anyway, and the common ones like
6351 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6353 sigfirst
= siglast
= (int)
6354 gdb_signal_from_command (atoi (*argv
));
6355 if ((*argv
)[digits
] == '-')
6358 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6360 if (sigfirst
> siglast
)
6362 /* Bet he didn't figure we'd think of this case... */
6370 oursig
= gdb_signal_from_name (*argv
);
6371 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6373 sigfirst
= siglast
= (int) oursig
;
6377 /* Not a number and not a recognized flag word => complain. */
6378 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6382 /* If any signal numbers or symbol names were found, set flags for
6383 which signals to apply actions to. */
6385 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6387 switch ((enum gdb_signal
) signum
)
6389 case GDB_SIGNAL_TRAP
:
6390 case GDB_SIGNAL_INT
:
6391 if (!allsigs
&& !sigs
[signum
])
6393 if (query (_("%s is used by the debugger.\n\
6394 Are you sure you want to change it? "),
6395 gdb_signal_to_name ((enum gdb_signal
) signum
)))
6401 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6402 gdb_flush (gdb_stdout
);
6407 case GDB_SIGNAL_DEFAULT
:
6408 case GDB_SIGNAL_UNKNOWN
:
6409 /* Make sure that "all" doesn't print these. */
6420 for (signum
= 0; signum
< nsigs
; signum
++)
6423 signal_cache_update (-1);
6424 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6425 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
6429 /* Show the results. */
6430 sig_print_header ();
6431 for (; signum
< nsigs
; signum
++)
6433 sig_print_info (signum
);
6439 do_cleanups (old_chain
);
6442 /* Complete the "handle" command. */
6444 static VEC (char_ptr
) *
6445 handle_completer (struct cmd_list_element
*ignore
,
6446 char *text
, char *word
)
6448 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
6449 static const char * const keywords
[] =
6463 vec_signals
= signal_completer (ignore
, text
, word
);
6464 vec_keywords
= complete_on_enum (keywords
, word
, word
);
6466 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
6467 VEC_free (char_ptr
, vec_signals
);
6468 VEC_free (char_ptr
, vec_keywords
);
6473 xdb_handle_command (char *args
, int from_tty
)
6476 struct cleanup
*old_chain
;
6479 error_no_arg (_("xdb command"));
6481 /* Break the command line up into args. */
6483 argv
= gdb_buildargv (args
);
6484 old_chain
= make_cleanup_freeargv (argv
);
6485 if (argv
[1] != (char *) NULL
)
6490 bufLen
= strlen (argv
[0]) + 20;
6491 argBuf
= (char *) xmalloc (bufLen
);
6495 enum gdb_signal oursig
;
6497 oursig
= gdb_signal_from_name (argv
[0]);
6498 memset (argBuf
, 0, bufLen
);
6499 if (strcmp (argv
[1], "Q") == 0)
6500 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6503 if (strcmp (argv
[1], "s") == 0)
6505 if (!signal_stop
[oursig
])
6506 sprintf (argBuf
, "%s %s", argv
[0], "stop");
6508 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
6510 else if (strcmp (argv
[1], "i") == 0)
6512 if (!signal_program
[oursig
])
6513 sprintf (argBuf
, "%s %s", argv
[0], "pass");
6515 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
6517 else if (strcmp (argv
[1], "r") == 0)
6519 if (!signal_print
[oursig
])
6520 sprintf (argBuf
, "%s %s", argv
[0], "print");
6522 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6528 handle_command (argBuf
, from_tty
);
6530 printf_filtered (_("Invalid signal handling flag.\n"));
6535 do_cleanups (old_chain
);
6539 gdb_signal_from_command (int num
)
6541 if (num
>= 1 && num
<= 15)
6542 return (enum gdb_signal
) num
;
6543 error (_("Only signals 1-15 are valid as numeric signals.\n\
6544 Use \"info signals\" for a list of symbolic signals."));
6547 /* Print current contents of the tables set by the handle command.
6548 It is possible we should just be printing signals actually used
6549 by the current target (but for things to work right when switching
6550 targets, all signals should be in the signal tables). */
6553 signals_info (char *signum_exp
, int from_tty
)
6555 enum gdb_signal oursig
;
6557 sig_print_header ();
6561 /* First see if this is a symbol name. */
6562 oursig
= gdb_signal_from_name (signum_exp
);
6563 if (oursig
== GDB_SIGNAL_UNKNOWN
)
6565 /* No, try numeric. */
6567 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
6569 sig_print_info (oursig
);
6573 printf_filtered ("\n");
6574 /* These ugly casts brought to you by the native VAX compiler. */
6575 for (oursig
= GDB_SIGNAL_FIRST
;
6576 (int) oursig
< (int) GDB_SIGNAL_LAST
;
6577 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
6581 if (oursig
!= GDB_SIGNAL_UNKNOWN
6582 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
6583 sig_print_info (oursig
);
6586 printf_filtered (_("\nUse the \"handle\" command "
6587 "to change these tables.\n"));
6590 /* Check if it makes sense to read $_siginfo from the current thread
6591 at this point. If not, throw an error. */
6594 validate_siginfo_access (void)
6596 /* No current inferior, no siginfo. */
6597 if (ptid_equal (inferior_ptid
, null_ptid
))
6598 error (_("No thread selected."));
6600 /* Don't try to read from a dead thread. */
6601 if (is_exited (inferior_ptid
))
6602 error (_("The current thread has terminated"));
6604 /* ... or from a spinning thread. */
6605 if (is_running (inferior_ptid
))
6606 error (_("Selected thread is running."));
6609 /* The $_siginfo convenience variable is a bit special. We don't know
6610 for sure the type of the value until we actually have a chance to
6611 fetch the data. The type can change depending on gdbarch, so it is
6612 also dependent on which thread you have selected.
6614 1. making $_siginfo be an internalvar that creates a new value on
6617 2. making the value of $_siginfo be an lval_computed value. */
6619 /* This function implements the lval_computed support for reading a
6623 siginfo_value_read (struct value
*v
)
6625 LONGEST transferred
;
6627 validate_siginfo_access ();
6630 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
6632 value_contents_all_raw (v
),
6634 TYPE_LENGTH (value_type (v
)));
6636 if (transferred
!= TYPE_LENGTH (value_type (v
)))
6637 error (_("Unable to read siginfo"));
6640 /* This function implements the lval_computed support for writing a
6644 siginfo_value_write (struct value
*v
, struct value
*fromval
)
6646 LONGEST transferred
;
6648 validate_siginfo_access ();
6650 transferred
= target_write (¤t_target
,
6651 TARGET_OBJECT_SIGNAL_INFO
,
6653 value_contents_all_raw (fromval
),
6655 TYPE_LENGTH (value_type (fromval
)));
6657 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
6658 error (_("Unable to write siginfo"));
6661 static const struct lval_funcs siginfo_value_funcs
=
6667 /* Return a new value with the correct type for the siginfo object of
6668 the current thread using architecture GDBARCH. Return a void value
6669 if there's no object available. */
6671 static struct value
*
6672 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
6675 if (target_has_stack
6676 && !ptid_equal (inferior_ptid
, null_ptid
)
6677 && gdbarch_get_siginfo_type_p (gdbarch
))
6679 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6681 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
6684 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
6688 /* infcall_suspend_state contains state about the program itself like its
6689 registers and any signal it received when it last stopped.
6690 This state must be restored regardless of how the inferior function call
6691 ends (either successfully, or after it hits a breakpoint or signal)
6692 if the program is to properly continue where it left off. */
6694 struct infcall_suspend_state
6696 struct thread_suspend_state thread_suspend
;
6697 #if 0 /* Currently unused and empty structures are not valid C. */
6698 struct inferior_suspend_state inferior_suspend
;
6703 struct regcache
*registers
;
6705 /* Format of SIGINFO_DATA or NULL if it is not present. */
6706 struct gdbarch
*siginfo_gdbarch
;
6708 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6709 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6710 content would be invalid. */
6711 gdb_byte
*siginfo_data
;
6714 struct infcall_suspend_state
*
6715 save_infcall_suspend_state (void)
6717 struct infcall_suspend_state
*inf_state
;
6718 struct thread_info
*tp
= inferior_thread ();
6719 struct inferior
*inf
= current_inferior ();
6720 struct regcache
*regcache
= get_current_regcache ();
6721 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6722 gdb_byte
*siginfo_data
= NULL
;
6724 if (gdbarch_get_siginfo_type_p (gdbarch
))
6726 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6727 size_t len
= TYPE_LENGTH (type
);
6728 struct cleanup
*back_to
;
6730 siginfo_data
= xmalloc (len
);
6731 back_to
= make_cleanup (xfree
, siginfo_data
);
6733 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6734 siginfo_data
, 0, len
) == len
)
6735 discard_cleanups (back_to
);
6738 /* Errors ignored. */
6739 do_cleanups (back_to
);
6740 siginfo_data
= NULL
;
6744 inf_state
= XZALLOC (struct infcall_suspend_state
);
6748 inf_state
->siginfo_gdbarch
= gdbarch
;
6749 inf_state
->siginfo_data
= siginfo_data
;
6752 inf_state
->thread_suspend
= tp
->suspend
;
6753 #if 0 /* Currently unused and empty structures are not valid C. */
6754 inf_state
->inferior_suspend
= inf
->suspend
;
6757 /* run_inferior_call will not use the signal due to its `proceed' call with
6758 GDB_SIGNAL_0 anyway. */
6759 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6761 inf_state
->stop_pc
= stop_pc
;
6763 inf_state
->registers
= regcache_dup (regcache
);
6768 /* Restore inferior session state to INF_STATE. */
6771 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6773 struct thread_info
*tp
= inferior_thread ();
6774 struct inferior
*inf
= current_inferior ();
6775 struct regcache
*regcache
= get_current_regcache ();
6776 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6778 tp
->suspend
= inf_state
->thread_suspend
;
6779 #if 0 /* Currently unused and empty structures are not valid C. */
6780 inf
->suspend
= inf_state
->inferior_suspend
;
6783 stop_pc
= inf_state
->stop_pc
;
6785 if (inf_state
->siginfo_gdbarch
== gdbarch
)
6787 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6789 /* Errors ignored. */
6790 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6791 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
6794 /* The inferior can be gone if the user types "print exit(0)"
6795 (and perhaps other times). */
6796 if (target_has_execution
)
6797 /* NB: The register write goes through to the target. */
6798 regcache_cpy (regcache
, inf_state
->registers
);
6800 discard_infcall_suspend_state (inf_state
);
6804 do_restore_infcall_suspend_state_cleanup (void *state
)
6806 restore_infcall_suspend_state (state
);
6810 make_cleanup_restore_infcall_suspend_state
6811 (struct infcall_suspend_state
*inf_state
)
6813 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
6817 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6819 regcache_xfree (inf_state
->registers
);
6820 xfree (inf_state
->siginfo_data
);
6825 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
6827 return inf_state
->registers
;
6830 /* infcall_control_state contains state regarding gdb's control of the
6831 inferior itself like stepping control. It also contains session state like
6832 the user's currently selected frame. */
6834 struct infcall_control_state
6836 struct thread_control_state thread_control
;
6837 struct inferior_control_state inferior_control
;
6840 enum stop_stack_kind stop_stack_dummy
;
6841 int stopped_by_random_signal
;
6842 int stop_after_trap
;
6844 /* ID if the selected frame when the inferior function call was made. */
6845 struct frame_id selected_frame_id
;
6848 /* Save all of the information associated with the inferior<==>gdb
6851 struct infcall_control_state
*
6852 save_infcall_control_state (void)
6854 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
6855 struct thread_info
*tp
= inferior_thread ();
6856 struct inferior
*inf
= current_inferior ();
6858 inf_status
->thread_control
= tp
->control
;
6859 inf_status
->inferior_control
= inf
->control
;
6861 tp
->control
.step_resume_breakpoint
= NULL
;
6862 tp
->control
.exception_resume_breakpoint
= NULL
;
6864 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6865 chain. If caller's caller is walking the chain, they'll be happier if we
6866 hand them back the original chain when restore_infcall_control_state is
6868 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
6871 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
6872 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
6873 inf_status
->stop_after_trap
= stop_after_trap
;
6875 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
6881 restore_selected_frame (void *args
)
6883 struct frame_id
*fid
= (struct frame_id
*) args
;
6884 struct frame_info
*frame
;
6886 frame
= frame_find_by_id (*fid
);
6888 /* If inf_status->selected_frame_id is NULL, there was no previously
6892 warning (_("Unable to restore previously selected frame."));
6896 select_frame (frame
);
6901 /* Restore inferior session state to INF_STATUS. */
6904 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
6906 struct thread_info
*tp
= inferior_thread ();
6907 struct inferior
*inf
= current_inferior ();
6909 if (tp
->control
.step_resume_breakpoint
)
6910 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
6912 if (tp
->control
.exception_resume_breakpoint
)
6913 tp
->control
.exception_resume_breakpoint
->disposition
6914 = disp_del_at_next_stop
;
6916 /* Handle the bpstat_copy of the chain. */
6917 bpstat_clear (&tp
->control
.stop_bpstat
);
6919 tp
->control
= inf_status
->thread_control
;
6920 inf
->control
= inf_status
->inferior_control
;
6923 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
6924 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
6925 stop_after_trap
= inf_status
->stop_after_trap
;
6927 if (target_has_stack
)
6929 /* The point of catch_errors is that if the stack is clobbered,
6930 walking the stack might encounter a garbage pointer and
6931 error() trying to dereference it. */
6933 (restore_selected_frame
, &inf_status
->selected_frame_id
,
6934 "Unable to restore previously selected frame:\n",
6935 RETURN_MASK_ERROR
) == 0)
6936 /* Error in restoring the selected frame. Select the innermost
6938 select_frame (get_current_frame ());
6945 do_restore_infcall_control_state_cleanup (void *sts
)
6947 restore_infcall_control_state (sts
);
6951 make_cleanup_restore_infcall_control_state
6952 (struct infcall_control_state
*inf_status
)
6954 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
6958 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
6960 if (inf_status
->thread_control
.step_resume_breakpoint
)
6961 inf_status
->thread_control
.step_resume_breakpoint
->disposition
6962 = disp_del_at_next_stop
;
6964 if (inf_status
->thread_control
.exception_resume_breakpoint
)
6965 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
6966 = disp_del_at_next_stop
;
6968 /* See save_infcall_control_state for info on stop_bpstat. */
6969 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
6975 ptid_match (ptid_t ptid
, ptid_t filter
)
6977 if (ptid_equal (filter
, minus_one_ptid
))
6979 if (ptid_is_pid (filter
)
6980 && ptid_get_pid (ptid
) == ptid_get_pid (filter
))
6982 else if (ptid_equal (ptid
, filter
))
6988 /* restore_inferior_ptid() will be used by the cleanup machinery
6989 to restore the inferior_ptid value saved in a call to
6990 save_inferior_ptid(). */
6993 restore_inferior_ptid (void *arg
)
6995 ptid_t
*saved_ptid_ptr
= arg
;
6997 inferior_ptid
= *saved_ptid_ptr
;
7001 /* Save the value of inferior_ptid so that it may be restored by a
7002 later call to do_cleanups(). Returns the struct cleanup pointer
7003 needed for later doing the cleanup. */
7006 save_inferior_ptid (void)
7008 ptid_t
*saved_ptid_ptr
;
7010 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7011 *saved_ptid_ptr
= inferior_ptid
;
7012 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7016 /* User interface for reverse debugging:
7017 Set exec-direction / show exec-direction commands
7018 (returns error unless target implements to_set_exec_direction method). */
7020 int execution_direction
= EXEC_FORWARD
;
7021 static const char exec_forward
[] = "forward";
7022 static const char exec_reverse
[] = "reverse";
7023 static const char *exec_direction
= exec_forward
;
7024 static const char *const exec_direction_names
[] = {
7031 set_exec_direction_func (char *args
, int from_tty
,
7032 struct cmd_list_element
*cmd
)
7034 if (target_can_execute_reverse
)
7036 if (!strcmp (exec_direction
, exec_forward
))
7037 execution_direction
= EXEC_FORWARD
;
7038 else if (!strcmp (exec_direction
, exec_reverse
))
7039 execution_direction
= EXEC_REVERSE
;
7043 exec_direction
= exec_forward
;
7044 error (_("Target does not support this operation."));
7049 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7050 struct cmd_list_element
*cmd
, const char *value
)
7052 switch (execution_direction
) {
7054 fprintf_filtered (out
, _("Forward.\n"));
7057 fprintf_filtered (out
, _("Reverse.\n"));
7060 internal_error (__FILE__
, __LINE__
,
7061 _("bogus execution_direction value: %d"),
7062 (int) execution_direction
);
7066 /* User interface for non-stop mode. */
7071 set_non_stop (char *args
, int from_tty
,
7072 struct cmd_list_element
*c
)
7074 if (target_has_execution
)
7076 non_stop_1
= non_stop
;
7077 error (_("Cannot change this setting while the inferior is running."));
7080 non_stop
= non_stop_1
;
7084 show_non_stop (struct ui_file
*file
, int from_tty
,
7085 struct cmd_list_element
*c
, const char *value
)
7087 fprintf_filtered (file
,
7088 _("Controlling the inferior in non-stop mode is %s.\n"),
7093 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7094 struct cmd_list_element
*c
, const char *value
)
7096 fprintf_filtered (file
, _("Resuming the execution of threads "
7097 "of all processes is %s.\n"), value
);
7100 /* Implementation of `siginfo' variable. */
7102 static const struct internalvar_funcs siginfo_funcs
=
7110 _initialize_infrun (void)
7114 struct cmd_list_element
*c
;
7116 add_info ("signals", signals_info
, _("\
7117 What debugger does when program gets various signals.\n\
7118 Specify a signal as argument to print info on that signal only."));
7119 add_info_alias ("handle", "signals", 0);
7121 c
= add_com ("handle", class_run
, handle_command
, _("\
7122 Specify how to handle signals.\n\
7123 Usage: handle SIGNAL [ACTIONS]\n\
7124 Args are signals and actions to apply to those signals.\n\
7125 If no actions are specified, the current settings for the specified signals\n\
7126 will be displayed instead.\n\
7128 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7129 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7130 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7131 The special arg \"all\" is recognized to mean all signals except those\n\
7132 used by the debugger, typically SIGTRAP and SIGINT.\n\
7134 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7135 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7136 Stop means reenter debugger if this signal happens (implies print).\n\
7137 Print means print a message if this signal happens.\n\
7138 Pass means let program see this signal; otherwise program doesn't know.\n\
7139 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7140 Pass and Stop may be combined.\n\
7142 Multiple signals may be specified. Signal numbers and signal names\n\
7143 may be interspersed with actions, with the actions being performed for\n\
7144 all signals cumulatively specified."));
7145 set_cmd_completer (c
, handle_completer
);
7149 add_com ("lz", class_info
, signals_info
, _("\
7150 What debugger does when program gets various signals.\n\
7151 Specify a signal as argument to print info on that signal only."));
7152 add_com ("z", class_run
, xdb_handle_command
, _("\
7153 Specify how to handle a signal.\n\
7154 Args are signals and actions to apply to those signals.\n\
7155 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7156 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7157 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7158 The special arg \"all\" is recognized to mean all signals except those\n\
7159 used by the debugger, typically SIGTRAP and SIGINT.\n\
7160 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7161 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7162 nopass), \"Q\" (noprint)\n\
7163 Stop means reenter debugger if this signal happens (implies print).\n\
7164 Print means print a message if this signal happens.\n\
7165 Pass means let program see this signal; otherwise program doesn't know.\n\
7166 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7167 Pass and Stop may be combined."));
7171 stop_command
= add_cmd ("stop", class_obscure
,
7172 not_just_help_class_command
, _("\
7173 There is no `stop' command, but you can set a hook on `stop'.\n\
7174 This allows you to set a list of commands to be run each time execution\n\
7175 of the program stops."), &cmdlist
);
7177 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7178 Set inferior debugging."), _("\
7179 Show inferior debugging."), _("\
7180 When non-zero, inferior specific debugging is enabled."),
7183 &setdebuglist
, &showdebuglist
);
7185 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7186 &debug_displaced
, _("\
7187 Set displaced stepping debugging."), _("\
7188 Show displaced stepping debugging."), _("\
7189 When non-zero, displaced stepping specific debugging is enabled."),
7191 show_debug_displaced
,
7192 &setdebuglist
, &showdebuglist
);
7194 add_setshow_boolean_cmd ("non-stop", no_class
,
7196 Set whether gdb controls the inferior in non-stop mode."), _("\
7197 Show whether gdb controls the inferior in non-stop mode."), _("\
7198 When debugging a multi-threaded program and this setting is\n\
7199 off (the default, also called all-stop mode), when one thread stops\n\
7200 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7201 all other threads in the program while you interact with the thread of\n\
7202 interest. When you continue or step a thread, you can allow the other\n\
7203 threads to run, or have them remain stopped, but while you inspect any\n\
7204 thread's state, all threads stop.\n\
7206 In non-stop mode, when one thread stops, other threads can continue\n\
7207 to run freely. You'll be able to step each thread independently,\n\
7208 leave it stopped or free to run as needed."),
7214 numsigs
= (int) GDB_SIGNAL_LAST
;
7215 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7216 signal_print
= (unsigned char *)
7217 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7218 signal_program
= (unsigned char *)
7219 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7220 signal_pass
= (unsigned char *)
7221 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7222 for (i
= 0; i
< numsigs
; i
++)
7225 signal_print
[i
] = 1;
7226 signal_program
[i
] = 1;
7229 /* Signals caused by debugger's own actions
7230 should not be given to the program afterwards. */
7231 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7232 signal_program
[GDB_SIGNAL_INT
] = 0;
7234 /* Signals that are not errors should not normally enter the debugger. */
7235 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7236 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7237 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7238 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7239 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7240 signal_print
[GDB_SIGNAL_PROF
] = 0;
7241 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7242 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7243 signal_stop
[GDB_SIGNAL_IO
] = 0;
7244 signal_print
[GDB_SIGNAL_IO
] = 0;
7245 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7246 signal_print
[GDB_SIGNAL_POLL
] = 0;
7247 signal_stop
[GDB_SIGNAL_URG
] = 0;
7248 signal_print
[GDB_SIGNAL_URG
] = 0;
7249 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7250 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7251 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7252 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7254 /* These signals are used internally by user-level thread
7255 implementations. (See signal(5) on Solaris.) Like the above
7256 signals, a healthy program receives and handles them as part of
7257 its normal operation. */
7258 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7259 signal_print
[GDB_SIGNAL_LWP
] = 0;
7260 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7261 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7262 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7263 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7265 /* Update cached state. */
7266 signal_cache_update (-1);
7268 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7269 &stop_on_solib_events
, _("\
7270 Set stopping for shared library events."), _("\
7271 Show stopping for shared library events."), _("\
7272 If nonzero, gdb will give control to the user when the dynamic linker\n\
7273 notifies gdb of shared library events. The most common event of interest\n\
7274 to the user would be loading/unloading of a new library."),
7276 show_stop_on_solib_events
,
7277 &setlist
, &showlist
);
7279 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7280 follow_fork_mode_kind_names
,
7281 &follow_fork_mode_string
, _("\
7282 Set debugger response to a program call of fork or vfork."), _("\
7283 Show debugger response to a program call of fork or vfork."), _("\
7284 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7285 parent - the original process is debugged after a fork\n\
7286 child - the new process is debugged after a fork\n\
7287 The unfollowed process will continue to run.\n\
7288 By default, the debugger will follow the parent process."),
7290 show_follow_fork_mode_string
,
7291 &setlist
, &showlist
);
7293 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7294 follow_exec_mode_names
,
7295 &follow_exec_mode_string
, _("\
7296 Set debugger response to a program call of exec."), _("\
7297 Show debugger response to a program call of exec."), _("\
7298 An exec call replaces the program image of a process.\n\
7300 follow-exec-mode can be:\n\
7302 new - the debugger creates a new inferior and rebinds the process\n\
7303 to this new inferior. The program the process was running before\n\
7304 the exec call can be restarted afterwards by restarting the original\n\
7307 same - the debugger keeps the process bound to the same inferior.\n\
7308 The new executable image replaces the previous executable loaded in\n\
7309 the inferior. Restarting the inferior after the exec call restarts\n\
7310 the executable the process was running after the exec call.\n\
7312 By default, the debugger will use the same inferior."),
7314 show_follow_exec_mode_string
,
7315 &setlist
, &showlist
);
7317 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7318 scheduler_enums
, &scheduler_mode
, _("\
7319 Set mode for locking scheduler during execution."), _("\
7320 Show mode for locking scheduler during execution."), _("\
7321 off == no locking (threads may preempt at any time)\n\
7322 on == full locking (no thread except the current thread may run)\n\
7323 step == scheduler locked during every single-step operation.\n\
7324 In this mode, no other thread may run during a step command.\n\
7325 Other threads may run while stepping over a function call ('next')."),
7326 set_schedlock_func
, /* traps on target vector */
7327 show_scheduler_mode
,
7328 &setlist
, &showlist
);
7330 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7331 Set mode for resuming threads of all processes."), _("\
7332 Show mode for resuming threads of all processes."), _("\
7333 When on, execution commands (such as 'continue' or 'next') resume all\n\
7334 threads of all processes. When off (which is the default), execution\n\
7335 commands only resume the threads of the current process. The set of\n\
7336 threads that are resumed is further refined by the scheduler-locking\n\
7337 mode (see help set scheduler-locking)."),
7339 show_schedule_multiple
,
7340 &setlist
, &showlist
);
7342 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7343 Set mode of the step operation."), _("\
7344 Show mode of the step operation."), _("\
7345 When set, doing a step over a function without debug line information\n\
7346 will stop at the first instruction of that function. Otherwise, the\n\
7347 function is skipped and the step command stops at a different source line."),
7349 show_step_stop_if_no_debug
,
7350 &setlist
, &showlist
);
7352 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7353 &can_use_displaced_stepping
, _("\
7354 Set debugger's willingness to use displaced stepping."), _("\
7355 Show debugger's willingness to use displaced stepping."), _("\
7356 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7357 supported by the target architecture. If off, gdb will not use displaced\n\
7358 stepping to step over breakpoints, even if such is supported by the target\n\
7359 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7360 if the target architecture supports it and non-stop mode is active, but will not\n\
7361 use it in all-stop mode (see help set non-stop)."),
7363 show_can_use_displaced_stepping
,
7364 &setlist
, &showlist
);
7366 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7367 &exec_direction
, _("Set direction of execution.\n\
7368 Options are 'forward' or 'reverse'."),
7369 _("Show direction of execution (forward/reverse)."),
7370 _("Tells gdb whether to execute forward or backward."),
7371 set_exec_direction_func
, show_exec_direction_func
,
7372 &setlist
, &showlist
);
7374 /* Set/show detach-on-fork: user-settable mode. */
7376 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7377 Set whether gdb will detach the child of a fork."), _("\
7378 Show whether gdb will detach the child of a fork."), _("\
7379 Tells gdb whether to detach the child of a fork."),
7380 NULL
, NULL
, &setlist
, &showlist
);
7382 /* Set/show disable address space randomization mode. */
7384 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7385 &disable_randomization
, _("\
7386 Set disabling of debuggee's virtual address space randomization."), _("\
7387 Show disabling of debuggee's virtual address space randomization."), _("\
7388 When this mode is on (which is the default), randomization of the virtual\n\
7389 address space is disabled. Standalone programs run with the randomization\n\
7390 enabled by default on some platforms."),
7391 &set_disable_randomization
,
7392 &show_disable_randomization
,
7393 &setlist
, &showlist
);
7395 /* ptid initializations */
7396 inferior_ptid
= null_ptid
;
7397 target_last_wait_ptid
= minus_one_ptid
;
7399 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7400 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7401 observer_attach_thread_exit (infrun_thread_thread_exit
);
7402 observer_attach_inferior_exit (infrun_inferior_exit
);
7404 /* Explicitly create without lookup, since that tries to create a
7405 value with a void typed value, and when we get here, gdbarch
7406 isn't initialized yet. At this point, we're quite sure there
7407 isn't another convenience variable of the same name. */
7408 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7410 add_setshow_boolean_cmd ("observer", no_class
,
7411 &observer_mode_1
, _("\
7412 Set whether gdb controls the inferior in observer mode."), _("\
7413 Show whether gdb controls the inferior in observer mode."), _("\
7414 In observer mode, GDB can get data from the inferior, but not\n\
7415 affect its execution. Registers and memory may not be changed,\n\
7416 breakpoints may not be set, and the program cannot be interrupted\n\