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. */
668 /* If we're handling a child exit, then inferior_ptid
669 points at the inferior's pid, not to a thread. */
670 old_chain
= save_inferior_ptid ();
671 save_current_program_space ();
672 save_current_inferior ();
675 old_chain
= save_current_space_and_thread ();
677 /* We're letting loose of the parent. */
678 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
679 switch_to_thread (tp
->ptid
);
681 /* We're about to detach from the parent, which implicitly
682 removes breakpoints from its address space. There's a
683 catch here: we want to reuse the spaces for the child,
684 but, parent/child are still sharing the pspace at this
685 point, although the exec in reality makes the kernel give
686 the child a fresh set of new pages. The problem here is
687 that the breakpoints module being unaware of this, would
688 likely chose the child process to write to the parent
689 address space. Swapping the child temporarily away from
690 the spaces has the desired effect. Yes, this is "sort
693 pspace
= inf
->pspace
;
694 aspace
= inf
->aspace
;
698 if (debug_infrun
|| info_verbose
)
700 target_terminal_ours ();
703 fprintf_filtered (gdb_stdlog
,
704 "Detaching vfork parent process "
705 "%d after child exec.\n",
706 inf
->vfork_parent
->pid
);
708 fprintf_filtered (gdb_stdlog
,
709 "Detaching vfork parent process "
710 "%d after child exit.\n",
711 inf
->vfork_parent
->pid
);
714 target_detach (NULL
, 0);
717 inf
->pspace
= pspace
;
718 inf
->aspace
= aspace
;
720 do_cleanups (old_chain
);
724 /* We're staying attached to the parent, so, really give the
725 child a new address space. */
726 inf
->pspace
= add_program_space (maybe_new_address_space ());
727 inf
->aspace
= inf
->pspace
->aspace
;
729 set_current_program_space (inf
->pspace
);
731 resume_parent
= inf
->vfork_parent
->pid
;
733 /* Break the bonds. */
734 inf
->vfork_parent
->vfork_child
= NULL
;
738 struct cleanup
*old_chain
;
739 struct program_space
*pspace
;
741 /* If this is a vfork child exiting, then the pspace and
742 aspaces were shared with the parent. Since we're
743 reporting the process exit, we'll be mourning all that is
744 found in the address space, and switching to null_ptid,
745 preparing to start a new inferior. But, since we don't
746 want to clobber the parent's address/program spaces, we
747 go ahead and create a new one for this exiting
750 /* Switch to null_ptid, so that clone_program_space doesn't want
751 to read the selected frame of a dead process. */
752 old_chain
= save_inferior_ptid ();
753 inferior_ptid
= null_ptid
;
755 /* This inferior is dead, so avoid giving the breakpoints
756 module the option to write through to it (cloning a
757 program space resets breakpoints). */
760 pspace
= add_program_space (maybe_new_address_space ());
761 set_current_program_space (pspace
);
763 inf
->symfile_flags
= SYMFILE_NO_READ
;
764 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
765 inf
->pspace
= pspace
;
766 inf
->aspace
= pspace
->aspace
;
768 /* Put back inferior_ptid. We'll continue mourning this
770 do_cleanups (old_chain
);
772 resume_parent
= inf
->vfork_parent
->pid
;
773 /* Break the bonds. */
774 inf
->vfork_parent
->vfork_child
= NULL
;
777 inf
->vfork_parent
= NULL
;
779 gdb_assert (current_program_space
== inf
->pspace
);
781 if (non_stop
&& resume_parent
!= -1)
783 /* If the user wanted the parent to be running, let it go
785 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
788 fprintf_unfiltered (gdb_stdlog
,
789 "infrun: resuming vfork parent process %d\n",
792 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
794 do_cleanups (old_chain
);
799 /* Enum strings for "set|show displaced-stepping". */
801 static const char follow_exec_mode_new
[] = "new";
802 static const char follow_exec_mode_same
[] = "same";
803 static const char *const follow_exec_mode_names
[] =
805 follow_exec_mode_new
,
806 follow_exec_mode_same
,
810 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
812 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
813 struct cmd_list_element
*c
, const char *value
)
815 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
818 /* EXECD_PATHNAME is assumed to be non-NULL. */
821 follow_exec (ptid_t pid
, char *execd_pathname
)
823 struct thread_info
*th
= inferior_thread ();
824 struct inferior
*inf
= current_inferior ();
826 /* This is an exec event that we actually wish to pay attention to.
827 Refresh our symbol table to the newly exec'd program, remove any
830 If there are breakpoints, they aren't really inserted now,
831 since the exec() transformed our inferior into a fresh set
834 We want to preserve symbolic breakpoints on the list, since
835 we have hopes that they can be reset after the new a.out's
836 symbol table is read.
838 However, any "raw" breakpoints must be removed from the list
839 (e.g., the solib bp's), since their address is probably invalid
842 And, we DON'T want to call delete_breakpoints() here, since
843 that may write the bp's "shadow contents" (the instruction
844 value that was overwritten witha TRAP instruction). Since
845 we now have a new a.out, those shadow contents aren't valid. */
847 mark_breakpoints_out ();
849 update_breakpoints_after_exec ();
851 /* If there was one, it's gone now. We cannot truly step-to-next
852 statement through an exec(). */
853 th
->control
.step_resume_breakpoint
= NULL
;
854 th
->control
.exception_resume_breakpoint
= NULL
;
855 th
->control
.step_range_start
= 0;
856 th
->control
.step_range_end
= 0;
858 /* The target reports the exec event to the main thread, even if
859 some other thread does the exec, and even if the main thread was
860 already stopped --- if debugging in non-stop mode, it's possible
861 the user had the main thread held stopped in the previous image
862 --- release it now. This is the same behavior as step-over-exec
863 with scheduler-locking on in all-stop mode. */
864 th
->stop_requested
= 0;
866 /* What is this a.out's name? */
867 printf_unfiltered (_("%s is executing new program: %s\n"),
868 target_pid_to_str (inferior_ptid
),
871 /* We've followed the inferior through an exec. Therefore, the
872 inferior has essentially been killed & reborn. */
874 gdb_flush (gdb_stdout
);
876 breakpoint_init_inferior (inf_execd
);
878 if (gdb_sysroot
&& *gdb_sysroot
)
880 char *name
= alloca (strlen (gdb_sysroot
)
881 + strlen (execd_pathname
)
884 strcpy (name
, gdb_sysroot
);
885 strcat (name
, execd_pathname
);
886 execd_pathname
= name
;
889 /* Reset the shared library package. This ensures that we get a
890 shlib event when the child reaches "_start", at which point the
891 dld will have had a chance to initialize the child. */
892 /* Also, loading a symbol file below may trigger symbol lookups, and
893 we don't want those to be satisfied by the libraries of the
894 previous incarnation of this process. */
895 no_shared_libraries (NULL
, 0);
897 if (follow_exec_mode_string
== follow_exec_mode_new
)
899 struct program_space
*pspace
;
901 /* The user wants to keep the old inferior and program spaces
902 around. Create a new fresh one, and switch to it. */
904 inf
= add_inferior (current_inferior ()->pid
);
905 pspace
= add_program_space (maybe_new_address_space ());
906 inf
->pspace
= pspace
;
907 inf
->aspace
= pspace
->aspace
;
909 exit_inferior_num_silent (current_inferior ()->num
);
911 set_current_inferior (inf
);
912 set_current_program_space (pspace
);
915 gdb_assert (current_program_space
== inf
->pspace
);
917 /* That a.out is now the one to use. */
918 exec_file_attach (execd_pathname
, 0);
920 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
921 (Position Independent Executable) main symbol file will get applied by
922 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
923 the breakpoints with the zero displacement. */
925 symbol_file_add (execd_pathname
,
927 | SYMFILE_MAINLINE
| SYMFILE_DEFER_BP_RESET
),
930 if ((inf
->symfile_flags
& SYMFILE_NO_READ
) == 0)
931 set_initial_language ();
933 #ifdef SOLIB_CREATE_INFERIOR_HOOK
934 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
936 solib_create_inferior_hook (0);
939 jit_inferior_created_hook ();
941 breakpoint_re_set ();
943 /* Reinsert all breakpoints. (Those which were symbolic have
944 been reset to the proper address in the new a.out, thanks
945 to symbol_file_command...). */
946 insert_breakpoints ();
948 /* The next resume of this inferior should bring it to the shlib
949 startup breakpoints. (If the user had also set bp's on
950 "main" from the old (parent) process, then they'll auto-
951 matically get reset there in the new process.). */
954 /* Non-zero if we just simulating a single-step. This is needed
955 because we cannot remove the breakpoints in the inferior process
956 until after the `wait' in `wait_for_inferior'. */
957 static int singlestep_breakpoints_inserted_p
= 0;
959 /* The thread we inserted single-step breakpoints for. */
960 static ptid_t singlestep_ptid
;
962 /* PC when we started this single-step. */
963 static CORE_ADDR singlestep_pc
;
965 /* If another thread hit the singlestep breakpoint, we save the original
966 thread here so that we can resume single-stepping it later. */
967 static ptid_t saved_singlestep_ptid
;
968 static int stepping_past_singlestep_breakpoint
;
970 /* If not equal to null_ptid, this means that after stepping over breakpoint
971 is finished, we need to switch to deferred_step_ptid, and step it.
973 The use case is when one thread has hit a breakpoint, and then the user
974 has switched to another thread and issued 'step'. We need to step over
975 breakpoint in the thread which hit the breakpoint, but then continue
976 stepping the thread user has selected. */
977 static ptid_t deferred_step_ptid
;
979 /* Displaced stepping. */
981 /* In non-stop debugging mode, we must take special care to manage
982 breakpoints properly; in particular, the traditional strategy for
983 stepping a thread past a breakpoint it has hit is unsuitable.
984 'Displaced stepping' is a tactic for stepping one thread past a
985 breakpoint it has hit while ensuring that other threads running
986 concurrently will hit the breakpoint as they should.
988 The traditional way to step a thread T off a breakpoint in a
989 multi-threaded program in all-stop mode is as follows:
991 a0) Initially, all threads are stopped, and breakpoints are not
993 a1) We single-step T, leaving breakpoints uninserted.
994 a2) We insert breakpoints, and resume all threads.
996 In non-stop debugging, however, this strategy is unsuitable: we
997 don't want to have to stop all threads in the system in order to
998 continue or step T past a breakpoint. Instead, we use displaced
1001 n0) Initially, T is stopped, other threads are running, and
1002 breakpoints are inserted.
1003 n1) We copy the instruction "under" the breakpoint to a separate
1004 location, outside the main code stream, making any adjustments
1005 to the instruction, register, and memory state as directed by
1007 n2) We single-step T over the instruction at its new location.
1008 n3) We adjust the resulting register and memory state as directed
1009 by T's architecture. This includes resetting T's PC to point
1010 back into the main instruction stream.
1013 This approach depends on the following gdbarch methods:
1015 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1016 indicate where to copy the instruction, and how much space must
1017 be reserved there. We use these in step n1.
1019 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1020 address, and makes any necessary adjustments to the instruction,
1021 register contents, and memory. We use this in step n1.
1023 - gdbarch_displaced_step_fixup adjusts registers and memory after
1024 we have successfuly single-stepped the instruction, to yield the
1025 same effect the instruction would have had if we had executed it
1026 at its original address. We use this in step n3.
1028 - gdbarch_displaced_step_free_closure provides cleanup.
1030 The gdbarch_displaced_step_copy_insn and
1031 gdbarch_displaced_step_fixup functions must be written so that
1032 copying an instruction with gdbarch_displaced_step_copy_insn,
1033 single-stepping across the copied instruction, and then applying
1034 gdbarch_displaced_insn_fixup should have the same effects on the
1035 thread's memory and registers as stepping the instruction in place
1036 would have. Exactly which responsibilities fall to the copy and
1037 which fall to the fixup is up to the author of those functions.
1039 See the comments in gdbarch.sh for details.
1041 Note that displaced stepping and software single-step cannot
1042 currently be used in combination, although with some care I think
1043 they could be made to. Software single-step works by placing
1044 breakpoints on all possible subsequent instructions; if the
1045 displaced instruction is a PC-relative jump, those breakpoints
1046 could fall in very strange places --- on pages that aren't
1047 executable, or at addresses that are not proper instruction
1048 boundaries. (We do generally let other threads run while we wait
1049 to hit the software single-step breakpoint, and they might
1050 encounter such a corrupted instruction.) One way to work around
1051 this would be to have gdbarch_displaced_step_copy_insn fully
1052 simulate the effect of PC-relative instructions (and return NULL)
1053 on architectures that use software single-stepping.
1055 In non-stop mode, we can have independent and simultaneous step
1056 requests, so more than one thread may need to simultaneously step
1057 over a breakpoint. The current implementation assumes there is
1058 only one scratch space per process. In this case, we have to
1059 serialize access to the scratch space. If thread A wants to step
1060 over a breakpoint, but we are currently waiting for some other
1061 thread to complete a displaced step, we leave thread A stopped and
1062 place it in the displaced_step_request_queue. Whenever a displaced
1063 step finishes, we pick the next thread in the queue and start a new
1064 displaced step operation on it. See displaced_step_prepare and
1065 displaced_step_fixup for details. */
1067 struct displaced_step_request
1070 struct displaced_step_request
*next
;
1073 /* Per-inferior displaced stepping state. */
1074 struct displaced_step_inferior_state
1076 /* Pointer to next in linked list. */
1077 struct displaced_step_inferior_state
*next
;
1079 /* The process this displaced step state refers to. */
1082 /* A queue of pending displaced stepping requests. One entry per
1083 thread that needs to do a displaced step. */
1084 struct displaced_step_request
*step_request_queue
;
1086 /* If this is not null_ptid, this is the thread carrying out a
1087 displaced single-step in process PID. This thread's state will
1088 require fixing up once it has completed its step. */
1091 /* The architecture the thread had when we stepped it. */
1092 struct gdbarch
*step_gdbarch
;
1094 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1095 for post-step cleanup. */
1096 struct displaced_step_closure
*step_closure
;
1098 /* The address of the original instruction, and the copy we
1100 CORE_ADDR step_original
, step_copy
;
1102 /* Saved contents of copy area. */
1103 gdb_byte
*step_saved_copy
;
1106 /* The list of states of processes involved in displaced stepping
1108 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1110 /* Get the displaced stepping state of process PID. */
1112 static struct displaced_step_inferior_state
*
1113 get_displaced_stepping_state (int pid
)
1115 struct displaced_step_inferior_state
*state
;
1117 for (state
= displaced_step_inferior_states
;
1119 state
= state
->next
)
1120 if (state
->pid
== pid
)
1126 /* Add a new displaced stepping state for process PID to the displaced
1127 stepping state list, or return a pointer to an already existing
1128 entry, if it already exists. Never returns NULL. */
1130 static struct displaced_step_inferior_state
*
1131 add_displaced_stepping_state (int pid
)
1133 struct displaced_step_inferior_state
*state
;
1135 for (state
= displaced_step_inferior_states
;
1137 state
= state
->next
)
1138 if (state
->pid
== pid
)
1141 state
= xcalloc (1, sizeof (*state
));
1143 state
->next
= displaced_step_inferior_states
;
1144 displaced_step_inferior_states
= state
;
1149 /* If inferior is in displaced stepping, and ADDR equals to starting address
1150 of copy area, return corresponding displaced_step_closure. Otherwise,
1153 struct displaced_step_closure
*
1154 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1156 struct displaced_step_inferior_state
*displaced
1157 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1159 /* If checking the mode of displaced instruction in copy area. */
1160 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1161 && (displaced
->step_copy
== addr
))
1162 return displaced
->step_closure
;
1167 /* Remove the displaced stepping state of process PID. */
1170 remove_displaced_stepping_state (int pid
)
1172 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1174 gdb_assert (pid
!= 0);
1176 it
= displaced_step_inferior_states
;
1177 prev_next_p
= &displaced_step_inferior_states
;
1182 *prev_next_p
= it
->next
;
1187 prev_next_p
= &it
->next
;
1193 infrun_inferior_exit (struct inferior
*inf
)
1195 remove_displaced_stepping_state (inf
->pid
);
1198 /* If ON, and the architecture supports it, GDB will use displaced
1199 stepping to step over breakpoints. If OFF, or if the architecture
1200 doesn't support it, GDB will instead use the traditional
1201 hold-and-step approach. If AUTO (which is the default), GDB will
1202 decide which technique to use to step over breakpoints depending on
1203 which of all-stop or non-stop mode is active --- displaced stepping
1204 in non-stop mode; hold-and-step in all-stop mode. */
1206 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1209 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1210 struct cmd_list_element
*c
,
1213 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1214 fprintf_filtered (file
,
1215 _("Debugger's willingness to use displaced stepping "
1216 "to step over breakpoints is %s (currently %s).\n"),
1217 value
, non_stop
? "on" : "off");
1219 fprintf_filtered (file
,
1220 _("Debugger's willingness to use displaced stepping "
1221 "to step over breakpoints is %s.\n"), value
);
1224 /* Return non-zero if displaced stepping can/should be used to step
1225 over breakpoints. */
1228 use_displaced_stepping (struct gdbarch
*gdbarch
)
1230 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1231 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1232 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1233 && !RECORD_IS_USED
);
1236 /* Clean out any stray displaced stepping state. */
1238 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1240 /* Indicate that there is no cleanup pending. */
1241 displaced
->step_ptid
= null_ptid
;
1243 if (displaced
->step_closure
)
1245 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1246 displaced
->step_closure
);
1247 displaced
->step_closure
= NULL
;
1252 displaced_step_clear_cleanup (void *arg
)
1254 struct displaced_step_inferior_state
*state
= arg
;
1256 displaced_step_clear (state
);
1259 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1261 displaced_step_dump_bytes (struct ui_file
*file
,
1262 const gdb_byte
*buf
,
1267 for (i
= 0; i
< len
; i
++)
1268 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1269 fputs_unfiltered ("\n", file
);
1272 /* Prepare to single-step, using displaced stepping.
1274 Note that we cannot use displaced stepping when we have a signal to
1275 deliver. If we have a signal to deliver and an instruction to step
1276 over, then after the step, there will be no indication from the
1277 target whether the thread entered a signal handler or ignored the
1278 signal and stepped over the instruction successfully --- both cases
1279 result in a simple SIGTRAP. In the first case we mustn't do a
1280 fixup, and in the second case we must --- but we can't tell which.
1281 Comments in the code for 'random signals' in handle_inferior_event
1282 explain how we handle this case instead.
1284 Returns 1 if preparing was successful -- this thread is going to be
1285 stepped now; or 0 if displaced stepping this thread got queued. */
1287 displaced_step_prepare (ptid_t ptid
)
1289 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1290 struct regcache
*regcache
= get_thread_regcache (ptid
);
1291 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1292 CORE_ADDR original
, copy
;
1294 struct displaced_step_closure
*closure
;
1295 struct displaced_step_inferior_state
*displaced
;
1298 /* We should never reach this function if the architecture does not
1299 support displaced stepping. */
1300 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1302 /* We have to displaced step one thread at a time, as we only have
1303 access to a single scratch space per inferior. */
1305 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1307 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1309 /* Already waiting for a displaced step to finish. Defer this
1310 request and place in queue. */
1311 struct displaced_step_request
*req
, *new_req
;
1313 if (debug_displaced
)
1314 fprintf_unfiltered (gdb_stdlog
,
1315 "displaced: defering step of %s\n",
1316 target_pid_to_str (ptid
));
1318 new_req
= xmalloc (sizeof (*new_req
));
1319 new_req
->ptid
= ptid
;
1320 new_req
->next
= NULL
;
1322 if (displaced
->step_request_queue
)
1324 for (req
= displaced
->step_request_queue
;
1328 req
->next
= new_req
;
1331 displaced
->step_request_queue
= new_req
;
1337 if (debug_displaced
)
1338 fprintf_unfiltered (gdb_stdlog
,
1339 "displaced: stepping %s now\n",
1340 target_pid_to_str (ptid
));
1343 displaced_step_clear (displaced
);
1345 old_cleanups
= save_inferior_ptid ();
1346 inferior_ptid
= ptid
;
1348 original
= regcache_read_pc (regcache
);
1350 copy
= gdbarch_displaced_step_location (gdbarch
);
1351 len
= gdbarch_max_insn_length (gdbarch
);
1353 /* Save the original contents of the copy area. */
1354 displaced
->step_saved_copy
= xmalloc (len
);
1355 ignore_cleanups
= make_cleanup (free_current_contents
,
1356 &displaced
->step_saved_copy
);
1357 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1359 throw_error (MEMORY_ERROR
,
1360 _("Error accessing memory address %s (%s) for "
1361 "displaced-stepping scratch space."),
1362 paddress (gdbarch
, copy
), safe_strerror (status
));
1363 if (debug_displaced
)
1365 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1366 paddress (gdbarch
, copy
));
1367 displaced_step_dump_bytes (gdb_stdlog
,
1368 displaced
->step_saved_copy
,
1372 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1373 original
, copy
, regcache
);
1375 /* We don't support the fully-simulated case at present. */
1376 gdb_assert (closure
);
1378 /* Save the information we need to fix things up if the step
1380 displaced
->step_ptid
= ptid
;
1381 displaced
->step_gdbarch
= gdbarch
;
1382 displaced
->step_closure
= closure
;
1383 displaced
->step_original
= original
;
1384 displaced
->step_copy
= copy
;
1386 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1388 /* Resume execution at the copy. */
1389 regcache_write_pc (regcache
, copy
);
1391 discard_cleanups (ignore_cleanups
);
1393 do_cleanups (old_cleanups
);
1395 if (debug_displaced
)
1396 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1397 paddress (gdbarch
, copy
));
1403 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1404 const gdb_byte
*myaddr
, int len
)
1406 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1408 inferior_ptid
= ptid
;
1409 write_memory (memaddr
, myaddr
, len
);
1410 do_cleanups (ptid_cleanup
);
1413 /* Restore the contents of the copy area for thread PTID. */
1416 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1419 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1421 write_memory_ptid (ptid
, displaced
->step_copy
,
1422 displaced
->step_saved_copy
, len
);
1423 if (debug_displaced
)
1424 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1425 target_pid_to_str (ptid
),
1426 paddress (displaced
->step_gdbarch
,
1427 displaced
->step_copy
));
1431 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1433 struct cleanup
*old_cleanups
;
1434 struct displaced_step_inferior_state
*displaced
1435 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1437 /* Was any thread of this process doing a displaced step? */
1438 if (displaced
== NULL
)
1441 /* Was this event for the pid we displaced? */
1442 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1443 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1446 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1448 displaced_step_restore (displaced
, displaced
->step_ptid
);
1450 /* Did the instruction complete successfully? */
1451 if (signal
== GDB_SIGNAL_TRAP
)
1453 /* Fix up the resulting state. */
1454 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1455 displaced
->step_closure
,
1456 displaced
->step_original
,
1457 displaced
->step_copy
,
1458 get_thread_regcache (displaced
->step_ptid
));
1462 /* Since the instruction didn't complete, all we can do is
1464 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1465 CORE_ADDR pc
= regcache_read_pc (regcache
);
1467 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1468 regcache_write_pc (regcache
, pc
);
1471 do_cleanups (old_cleanups
);
1473 displaced
->step_ptid
= null_ptid
;
1475 /* Are there any pending displaced stepping requests? If so, run
1476 one now. Leave the state object around, since we're likely to
1477 need it again soon. */
1478 while (displaced
->step_request_queue
)
1480 struct displaced_step_request
*head
;
1482 struct regcache
*regcache
;
1483 struct gdbarch
*gdbarch
;
1484 CORE_ADDR actual_pc
;
1485 struct address_space
*aspace
;
1487 head
= displaced
->step_request_queue
;
1489 displaced
->step_request_queue
= head
->next
;
1492 context_switch (ptid
);
1494 regcache
= get_thread_regcache (ptid
);
1495 actual_pc
= regcache_read_pc (regcache
);
1496 aspace
= get_regcache_aspace (regcache
);
1498 if (breakpoint_here_p (aspace
, actual_pc
))
1500 if (debug_displaced
)
1501 fprintf_unfiltered (gdb_stdlog
,
1502 "displaced: stepping queued %s now\n",
1503 target_pid_to_str (ptid
));
1505 displaced_step_prepare (ptid
);
1507 gdbarch
= get_regcache_arch (regcache
);
1509 if (debug_displaced
)
1511 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1514 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1515 paddress (gdbarch
, actual_pc
));
1516 read_memory (actual_pc
, buf
, sizeof (buf
));
1517 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1520 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1521 displaced
->step_closure
))
1522 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1524 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1526 /* Done, we're stepping a thread. */
1532 struct thread_info
*tp
= inferior_thread ();
1534 /* The breakpoint we were sitting under has since been
1536 tp
->control
.trap_expected
= 0;
1538 /* Go back to what we were trying to do. */
1539 step
= currently_stepping (tp
);
1541 if (debug_displaced
)
1542 fprintf_unfiltered (gdb_stdlog
,
1543 "displaced: breakpoint is gone: %s, step(%d)\n",
1544 target_pid_to_str (tp
->ptid
), step
);
1546 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1547 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1549 /* This request was discarded. See if there's any other
1550 thread waiting for its turn. */
1555 /* Update global variables holding ptids to hold NEW_PTID if they were
1556 holding OLD_PTID. */
1558 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1560 struct displaced_step_request
*it
;
1561 struct displaced_step_inferior_state
*displaced
;
1563 if (ptid_equal (inferior_ptid
, old_ptid
))
1564 inferior_ptid
= new_ptid
;
1566 if (ptid_equal (singlestep_ptid
, old_ptid
))
1567 singlestep_ptid
= new_ptid
;
1569 if (ptid_equal (deferred_step_ptid
, old_ptid
))
1570 deferred_step_ptid
= new_ptid
;
1572 for (displaced
= displaced_step_inferior_states
;
1574 displaced
= displaced
->next
)
1576 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1577 displaced
->step_ptid
= new_ptid
;
1579 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1580 if (ptid_equal (it
->ptid
, old_ptid
))
1581 it
->ptid
= new_ptid
;
1588 /* Things to clean up if we QUIT out of resume (). */
1590 resume_cleanups (void *ignore
)
1595 static const char schedlock_off
[] = "off";
1596 static const char schedlock_on
[] = "on";
1597 static const char schedlock_step
[] = "step";
1598 static const char *const scheduler_enums
[] = {
1604 static const char *scheduler_mode
= schedlock_off
;
1606 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1607 struct cmd_list_element
*c
, const char *value
)
1609 fprintf_filtered (file
,
1610 _("Mode for locking scheduler "
1611 "during execution is \"%s\".\n"),
1616 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1618 if (!target_can_lock_scheduler
)
1620 scheduler_mode
= schedlock_off
;
1621 error (_("Target '%s' cannot support this command."), target_shortname
);
1625 /* True if execution commands resume all threads of all processes by
1626 default; otherwise, resume only threads of the current inferior
1628 int sched_multi
= 0;
1630 /* Try to setup for software single stepping over the specified location.
1631 Return 1 if target_resume() should use hardware single step.
1633 GDBARCH the current gdbarch.
1634 PC the location to step over. */
1637 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1641 if (execution_direction
== EXEC_FORWARD
1642 && gdbarch_software_single_step_p (gdbarch
)
1643 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1646 /* Do not pull these breakpoints until after a `wait' in
1647 `wait_for_inferior'. */
1648 singlestep_breakpoints_inserted_p
= 1;
1649 singlestep_ptid
= inferior_ptid
;
1655 /* Return a ptid representing the set of threads that we will proceed,
1656 in the perspective of the user/frontend. We may actually resume
1657 fewer threads at first, e.g., if a thread is stopped at a
1658 breakpoint that needs stepping-off, but that should not be visible
1659 to the user/frontend, and neither should the frontend/user be
1660 allowed to proceed any of the threads that happen to be stopped for
1661 internal run control handling, if a previous command wanted them
1665 user_visible_resume_ptid (int step
)
1667 /* By default, resume all threads of all processes. */
1668 ptid_t resume_ptid
= RESUME_ALL
;
1670 /* Maybe resume only all threads of the current process. */
1671 if (!sched_multi
&& target_supports_multi_process ())
1673 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1676 /* Maybe resume a single thread after all. */
1679 /* With non-stop mode on, threads are always handled
1681 resume_ptid
= inferior_ptid
;
1683 else if ((scheduler_mode
== schedlock_on
)
1684 || (scheduler_mode
== schedlock_step
1685 && (step
|| singlestep_breakpoints_inserted_p
)))
1687 /* User-settable 'scheduler' mode requires solo thread resume. */
1688 resume_ptid
= inferior_ptid
;
1694 /* Resume the inferior, but allow a QUIT. This is useful if the user
1695 wants to interrupt some lengthy single-stepping operation
1696 (for child processes, the SIGINT goes to the inferior, and so
1697 we get a SIGINT random_signal, but for remote debugging and perhaps
1698 other targets, that's not true).
1700 STEP nonzero if we should step (zero to continue instead).
1701 SIG is the signal to give the inferior (zero for none). */
1703 resume (int step
, enum gdb_signal sig
)
1705 int should_resume
= 1;
1706 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1707 struct regcache
*regcache
= get_current_regcache ();
1708 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1709 struct thread_info
*tp
= inferior_thread ();
1710 CORE_ADDR pc
= regcache_read_pc (regcache
);
1711 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1715 if (current_inferior ()->waiting_for_vfork_done
)
1717 /* Don't try to single-step a vfork parent that is waiting for
1718 the child to get out of the shared memory region (by exec'ing
1719 or exiting). This is particularly important on software
1720 single-step archs, as the child process would trip on the
1721 software single step breakpoint inserted for the parent
1722 process. Since the parent will not actually execute any
1723 instruction until the child is out of the shared region (such
1724 are vfork's semantics), it is safe to simply continue it.
1725 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1726 the parent, and tell it to `keep_going', which automatically
1727 re-sets it stepping. */
1729 fprintf_unfiltered (gdb_stdlog
,
1730 "infrun: resume : clear step\n");
1735 fprintf_unfiltered (gdb_stdlog
,
1736 "infrun: resume (step=%d, signal=%d), "
1737 "trap_expected=%d, current thread [%s] at %s\n",
1738 step
, sig
, tp
->control
.trap_expected
,
1739 target_pid_to_str (inferior_ptid
),
1740 paddress (gdbarch
, pc
));
1742 /* Normally, by the time we reach `resume', the breakpoints are either
1743 removed or inserted, as appropriate. The exception is if we're sitting
1744 at a permanent breakpoint; we need to step over it, but permanent
1745 breakpoints can't be removed. So we have to test for it here. */
1746 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
1748 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1749 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1752 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1753 how to step past a permanent breakpoint on this architecture. Try using\n\
1754 a command like `return' or `jump' to continue execution."));
1757 /* If enabled, step over breakpoints by executing a copy of the
1758 instruction at a different address.
1760 We can't use displaced stepping when we have a signal to deliver;
1761 the comments for displaced_step_prepare explain why. The
1762 comments in the handle_inferior event for dealing with 'random
1763 signals' explain what we do instead.
1765 We can't use displaced stepping when we are waiting for vfork_done
1766 event, displaced stepping breaks the vfork child similarly as single
1767 step software breakpoint. */
1768 if (use_displaced_stepping (gdbarch
)
1769 && (tp
->control
.trap_expected
1770 || (step
&& gdbarch_software_single_step_p (gdbarch
)))
1771 && sig
== GDB_SIGNAL_0
1772 && !current_inferior ()->waiting_for_vfork_done
)
1774 struct displaced_step_inferior_state
*displaced
;
1776 if (!displaced_step_prepare (inferior_ptid
))
1778 /* Got placed in displaced stepping queue. Will be resumed
1779 later when all the currently queued displaced stepping
1780 requests finish. The thread is not executing at this point,
1781 and the call to set_executing will be made later. But we
1782 need to call set_running here, since from frontend point of view,
1783 the thread is running. */
1784 set_running (inferior_ptid
, 1);
1785 discard_cleanups (old_cleanups
);
1789 /* Update pc to reflect the new address from which we will execute
1790 instructions due to displaced stepping. */
1791 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
1793 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1794 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
1795 displaced
->step_closure
);
1798 /* Do we need to do it the hard way, w/temp breakpoints? */
1800 step
= maybe_software_singlestep (gdbarch
, pc
);
1802 /* Currently, our software single-step implementation leads to different
1803 results than hardware single-stepping in one situation: when stepping
1804 into delivering a signal which has an associated signal handler,
1805 hardware single-step will stop at the first instruction of the handler,
1806 while software single-step will simply skip execution of the handler.
1808 For now, this difference in behavior is accepted since there is no
1809 easy way to actually implement single-stepping into a signal handler
1810 without kernel support.
1812 However, there is one scenario where this difference leads to follow-on
1813 problems: if we're stepping off a breakpoint by removing all breakpoints
1814 and then single-stepping. In this case, the software single-step
1815 behavior means that even if there is a *breakpoint* in the signal
1816 handler, GDB still would not stop.
1818 Fortunately, we can at least fix this particular issue. We detect
1819 here the case where we are about to deliver a signal while software
1820 single-stepping with breakpoints removed. In this situation, we
1821 revert the decisions to remove all breakpoints and insert single-
1822 step breakpoints, and instead we install a step-resume breakpoint
1823 at the current address, deliver the signal without stepping, and
1824 once we arrive back at the step-resume breakpoint, actually step
1825 over the breakpoint we originally wanted to step over. */
1826 if (singlestep_breakpoints_inserted_p
1827 && tp
->control
.trap_expected
&& sig
!= GDB_SIGNAL_0
)
1829 /* If we have nested signals or a pending signal is delivered
1830 immediately after a handler returns, might might already have
1831 a step-resume breakpoint set on the earlier handler. We cannot
1832 set another step-resume breakpoint; just continue on until the
1833 original breakpoint is hit. */
1834 if (tp
->control
.step_resume_breakpoint
== NULL
)
1836 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1837 tp
->step_after_step_resume_breakpoint
= 1;
1840 remove_single_step_breakpoints ();
1841 singlestep_breakpoints_inserted_p
= 0;
1843 insert_breakpoints ();
1844 tp
->control
.trap_expected
= 0;
1851 /* If STEP is set, it's a request to use hardware stepping
1852 facilities. But in that case, we should never
1853 use singlestep breakpoint. */
1854 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1856 /* Decide the set of threads to ask the target to resume. Start
1857 by assuming everything will be resumed, than narrow the set
1858 by applying increasingly restricting conditions. */
1859 resume_ptid
= user_visible_resume_ptid (step
);
1861 /* Maybe resume a single thread after all. */
1862 if (singlestep_breakpoints_inserted_p
1863 && stepping_past_singlestep_breakpoint
)
1865 /* The situation here is as follows. In thread T1 we wanted to
1866 single-step. Lacking hardware single-stepping we've
1867 set breakpoint at the PC of the next instruction -- call it
1868 P. After resuming, we've hit that breakpoint in thread T2.
1869 Now we've removed original breakpoint, inserted breakpoint
1870 at P+1, and try to step to advance T2 past breakpoint.
1871 We need to step only T2, as if T1 is allowed to freely run,
1872 it can run past P, and if other threads are allowed to run,
1873 they can hit breakpoint at P+1, and nested hits of single-step
1874 breakpoints is not something we'd want -- that's complicated
1875 to support, and has no value. */
1876 resume_ptid
= inferior_ptid
;
1878 else if ((step
|| singlestep_breakpoints_inserted_p
)
1879 && tp
->control
.trap_expected
)
1881 /* We're allowing a thread to run past a breakpoint it has
1882 hit, by single-stepping the thread with the breakpoint
1883 removed. In which case, we need to single-step only this
1884 thread, and keep others stopped, as they can miss this
1885 breakpoint if allowed to run.
1887 The current code actually removes all breakpoints when
1888 doing this, not just the one being stepped over, so if we
1889 let other threads run, we can actually miss any
1890 breakpoint, not just the one at PC. */
1891 resume_ptid
= inferior_ptid
;
1894 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1896 /* Most targets can step a breakpoint instruction, thus
1897 executing it normally. But if this one cannot, just
1898 continue and we will hit it anyway. */
1899 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
1904 && use_displaced_stepping (gdbarch
)
1905 && tp
->control
.trap_expected
)
1907 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1908 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1909 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1912 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1913 paddress (resume_gdbarch
, actual_pc
));
1914 read_memory (actual_pc
, buf
, sizeof (buf
));
1915 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1918 /* Install inferior's terminal modes. */
1919 target_terminal_inferior ();
1921 /* Avoid confusing the next resume, if the next stop/resume
1922 happens to apply to another thread. */
1923 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1925 /* Advise target which signals may be handled silently. If we have
1926 removed breakpoints because we are stepping over one (which can
1927 happen only if we are not using displaced stepping), we need to
1928 receive all signals to avoid accidentally skipping a breakpoint
1929 during execution of a signal handler. */
1930 if ((step
|| singlestep_breakpoints_inserted_p
)
1931 && tp
->control
.trap_expected
1932 && !use_displaced_stepping (gdbarch
))
1933 target_pass_signals (0, NULL
);
1935 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
1937 target_resume (resume_ptid
, step
, sig
);
1940 discard_cleanups (old_cleanups
);
1945 /* Clear out all variables saying what to do when inferior is continued.
1946 First do this, then set the ones you want, then call `proceed'. */
1949 clear_proceed_status_thread (struct thread_info
*tp
)
1952 fprintf_unfiltered (gdb_stdlog
,
1953 "infrun: clear_proceed_status_thread (%s)\n",
1954 target_pid_to_str (tp
->ptid
));
1956 tp
->control
.trap_expected
= 0;
1957 tp
->control
.step_range_start
= 0;
1958 tp
->control
.step_range_end
= 0;
1959 tp
->control
.step_frame_id
= null_frame_id
;
1960 tp
->control
.step_stack_frame_id
= null_frame_id
;
1961 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1962 tp
->stop_requested
= 0;
1964 tp
->control
.stop_step
= 0;
1966 tp
->control
.proceed_to_finish
= 0;
1968 /* Discard any remaining commands or status from previous stop. */
1969 bpstat_clear (&tp
->control
.stop_bpstat
);
1973 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
1975 if (is_exited (tp
->ptid
))
1978 clear_proceed_status_thread (tp
);
1983 clear_proceed_status (void)
1987 /* In all-stop mode, delete the per-thread status of all
1988 threads, even if inferior_ptid is null_ptid, there may be
1989 threads on the list. E.g., we may be launching a new
1990 process, while selecting the executable. */
1991 iterate_over_threads (clear_proceed_status_callback
, NULL
);
1994 if (!ptid_equal (inferior_ptid
, null_ptid
))
1996 struct inferior
*inferior
;
2000 /* If in non-stop mode, only delete the per-thread status of
2001 the current thread. */
2002 clear_proceed_status_thread (inferior_thread ());
2005 inferior
= current_inferior ();
2006 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2009 stop_after_trap
= 0;
2011 observer_notify_about_to_proceed ();
2015 regcache_xfree (stop_registers
);
2016 stop_registers
= NULL
;
2020 /* Check the current thread against the thread that reported the most recent
2021 event. If a step-over is required return TRUE and set the current thread
2022 to the old thread. Otherwise return FALSE.
2024 This should be suitable for any targets that support threads. */
2027 prepare_to_proceed (int step
)
2030 struct target_waitstatus wait_status
;
2031 int schedlock_enabled
;
2033 /* With non-stop mode on, threads are always handled individually. */
2034 gdb_assert (! non_stop
);
2036 /* Get the last target status returned by target_wait(). */
2037 get_last_target_status (&wait_ptid
, &wait_status
);
2039 /* Make sure we were stopped at a breakpoint. */
2040 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
2041 || (wait_status
.value
.sig
!= GDB_SIGNAL_TRAP
2042 && wait_status
.value
.sig
!= GDB_SIGNAL_ILL
2043 && wait_status
.value
.sig
!= GDB_SIGNAL_SEGV
2044 && wait_status
.value
.sig
!= GDB_SIGNAL_EMT
))
2049 schedlock_enabled
= (scheduler_mode
== schedlock_on
2050 || (scheduler_mode
== schedlock_step
2053 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
2054 if (schedlock_enabled
)
2057 /* Don't switch over if we're about to resume some other process
2058 other than WAIT_PTID's, and schedule-multiple is off. */
2060 && ptid_get_pid (wait_ptid
) != ptid_get_pid (inferior_ptid
))
2063 /* Switched over from WAIT_PID. */
2064 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
2065 && !ptid_equal (inferior_ptid
, wait_ptid
))
2067 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
2069 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2070 regcache_read_pc (regcache
)))
2072 /* If stepping, remember current thread to switch back to. */
2074 deferred_step_ptid
= inferior_ptid
;
2076 /* Switch back to WAIT_PID thread. */
2077 switch_to_thread (wait_ptid
);
2080 fprintf_unfiltered (gdb_stdlog
,
2081 "infrun: prepare_to_proceed (step=%d), "
2082 "switched to [%s]\n",
2083 step
, target_pid_to_str (inferior_ptid
));
2085 /* We return 1 to indicate that there is a breakpoint here,
2086 so we need to step over it before continuing to avoid
2087 hitting it straight away. */
2095 /* Basic routine for continuing the program in various fashions.
2097 ADDR is the address to resume at, or -1 for resume where stopped.
2098 SIGGNAL is the signal to give it, or 0 for none,
2099 or -1 for act according to how it stopped.
2100 STEP is nonzero if should trap after one instruction.
2101 -1 means return after that and print nothing.
2102 You should probably set various step_... variables
2103 before calling here, if you are stepping.
2105 You should call clear_proceed_status before calling proceed. */
2108 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
, int step
)
2110 struct regcache
*regcache
;
2111 struct gdbarch
*gdbarch
;
2112 struct thread_info
*tp
;
2114 struct address_space
*aspace
;
2117 /* If we're stopped at a fork/vfork, follow the branch set by the
2118 "set follow-fork-mode" command; otherwise, we'll just proceed
2119 resuming the current thread. */
2120 if (!follow_fork ())
2122 /* The target for some reason decided not to resume. */
2124 if (target_can_async_p ())
2125 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2129 /* We'll update this if & when we switch to a new thread. */
2130 previous_inferior_ptid
= inferior_ptid
;
2132 regcache
= get_current_regcache ();
2133 gdbarch
= get_regcache_arch (regcache
);
2134 aspace
= get_regcache_aspace (regcache
);
2135 pc
= regcache_read_pc (regcache
);
2138 step_start_function
= find_pc_function (pc
);
2140 stop_after_trap
= 1;
2142 if (addr
== (CORE_ADDR
) -1)
2144 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
2145 && execution_direction
!= EXEC_REVERSE
)
2146 /* There is a breakpoint at the address we will resume at,
2147 step one instruction before inserting breakpoints so that
2148 we do not stop right away (and report a second hit at this
2151 Note, we don't do this in reverse, because we won't
2152 actually be executing the breakpoint insn anyway.
2153 We'll be (un-)executing the previous instruction. */
2156 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2157 && gdbarch_single_step_through_delay (gdbarch
,
2158 get_current_frame ()))
2159 /* We stepped onto an instruction that needs to be stepped
2160 again before re-inserting the breakpoint, do so. */
2165 regcache_write_pc (regcache
, addr
);
2169 fprintf_unfiltered (gdb_stdlog
,
2170 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
2171 paddress (gdbarch
, addr
), siggnal
, step
);
2174 /* In non-stop, each thread is handled individually. The context
2175 must already be set to the right thread here. */
2179 /* In a multi-threaded task we may select another thread and
2180 then continue or step.
2182 But if the old thread was stopped at a breakpoint, it will
2183 immediately cause another breakpoint stop without any
2184 execution (i.e. it will report a breakpoint hit incorrectly).
2185 So we must step over it first.
2187 prepare_to_proceed checks the current thread against the
2188 thread that reported the most recent event. If a step-over
2189 is required it returns TRUE and sets the current thread to
2191 if (prepare_to_proceed (step
))
2195 /* prepare_to_proceed may change the current thread. */
2196 tp
= inferior_thread ();
2200 tp
->control
.trap_expected
= 1;
2201 /* If displaced stepping is enabled, we can step over the
2202 breakpoint without hitting it, so leave all breakpoints
2203 inserted. Otherwise we need to disable all breakpoints, step
2204 one instruction, and then re-add them when that step is
2206 if (!use_displaced_stepping (gdbarch
))
2207 remove_breakpoints ();
2210 /* We can insert breakpoints if we're not trying to step over one,
2211 or if we are stepping over one but we're using displaced stepping
2213 if (! tp
->control
.trap_expected
|| use_displaced_stepping (gdbarch
))
2214 insert_breakpoints ();
2218 /* Pass the last stop signal to the thread we're resuming,
2219 irrespective of whether the current thread is the thread that
2220 got the last event or not. This was historically GDB's
2221 behaviour before keeping a stop_signal per thread. */
2223 struct thread_info
*last_thread
;
2225 struct target_waitstatus last_status
;
2227 get_last_target_status (&last_ptid
, &last_status
);
2228 if (!ptid_equal (inferior_ptid
, last_ptid
)
2229 && !ptid_equal (last_ptid
, null_ptid
)
2230 && !ptid_equal (last_ptid
, minus_one_ptid
))
2232 last_thread
= find_thread_ptid (last_ptid
);
2235 tp
->suspend
.stop_signal
= last_thread
->suspend
.stop_signal
;
2236 last_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2241 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2242 tp
->suspend
.stop_signal
= siggnal
;
2243 /* If this signal should not be seen by program,
2244 give it zero. Used for debugging signals. */
2245 else if (!signal_program
[tp
->suspend
.stop_signal
])
2246 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2248 annotate_starting ();
2250 /* Make sure that output from GDB appears before output from the
2252 gdb_flush (gdb_stdout
);
2254 /* Refresh prev_pc value just prior to resuming. This used to be
2255 done in stop_stepping, however, setting prev_pc there did not handle
2256 scenarios such as inferior function calls or returning from
2257 a function via the return command. In those cases, the prev_pc
2258 value was not set properly for subsequent commands. The prev_pc value
2259 is used to initialize the starting line number in the ecs. With an
2260 invalid value, the gdb next command ends up stopping at the position
2261 represented by the next line table entry past our start position.
2262 On platforms that generate one line table entry per line, this
2263 is not a problem. However, on the ia64, the compiler generates
2264 extraneous line table entries that do not increase the line number.
2265 When we issue the gdb next command on the ia64 after an inferior call
2266 or a return command, we often end up a few instructions forward, still
2267 within the original line we started.
2269 An attempt was made to refresh the prev_pc at the same time the
2270 execution_control_state is initialized (for instance, just before
2271 waiting for an inferior event). But this approach did not work
2272 because of platforms that use ptrace, where the pc register cannot
2273 be read unless the inferior is stopped. At that point, we are not
2274 guaranteed the inferior is stopped and so the regcache_read_pc() call
2275 can fail. Setting the prev_pc value here ensures the value is updated
2276 correctly when the inferior is stopped. */
2277 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2279 /* Fill in with reasonable starting values. */
2280 init_thread_stepping_state (tp
);
2282 /* Reset to normal state. */
2283 init_infwait_state ();
2285 /* Resume inferior. */
2286 resume (oneproc
|| step
|| bpstat_should_step (), tp
->suspend
.stop_signal
);
2288 /* Wait for it to stop (if not standalone)
2289 and in any case decode why it stopped, and act accordingly. */
2290 /* Do this only if we are not using the event loop, or if the target
2291 does not support asynchronous execution. */
2292 if (!target_can_async_p ())
2294 wait_for_inferior ();
2300 /* Start remote-debugging of a machine over a serial link. */
2303 start_remote (int from_tty
)
2305 struct inferior
*inferior
;
2307 inferior
= current_inferior ();
2308 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2310 /* Always go on waiting for the target, regardless of the mode. */
2311 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2312 indicate to wait_for_inferior that a target should timeout if
2313 nothing is returned (instead of just blocking). Because of this,
2314 targets expecting an immediate response need to, internally, set
2315 things up so that the target_wait() is forced to eventually
2317 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2318 differentiate to its caller what the state of the target is after
2319 the initial open has been performed. Here we're assuming that
2320 the target has stopped. It should be possible to eventually have
2321 target_open() return to the caller an indication that the target
2322 is currently running and GDB state should be set to the same as
2323 for an async run. */
2324 wait_for_inferior ();
2326 /* Now that the inferior has stopped, do any bookkeeping like
2327 loading shared libraries. We want to do this before normal_stop,
2328 so that the displayed frame is up to date. */
2329 post_create_inferior (¤t_target
, from_tty
);
2334 /* Initialize static vars when a new inferior begins. */
2337 init_wait_for_inferior (void)
2339 /* These are meaningless until the first time through wait_for_inferior. */
2341 breakpoint_init_inferior (inf_starting
);
2343 clear_proceed_status ();
2345 stepping_past_singlestep_breakpoint
= 0;
2346 deferred_step_ptid
= null_ptid
;
2348 target_last_wait_ptid
= minus_one_ptid
;
2350 previous_inferior_ptid
= inferior_ptid
;
2351 init_infwait_state ();
2353 /* Discard any skipped inlined frames. */
2354 clear_inline_frame_state (minus_one_ptid
);
2358 /* This enum encodes possible reasons for doing a target_wait, so that
2359 wfi can call target_wait in one place. (Ultimately the call will be
2360 moved out of the infinite loop entirely.) */
2364 infwait_normal_state
,
2365 infwait_thread_hop_state
,
2366 infwait_step_watch_state
,
2367 infwait_nonstep_watch_state
2370 /* The PTID we'll do a target_wait on.*/
2373 /* Current inferior wait state. */
2374 enum infwait_states infwait_state
;
2376 /* Data to be passed around while handling an event. This data is
2377 discarded between events. */
2378 struct execution_control_state
2381 /* The thread that got the event, if this was a thread event; NULL
2383 struct thread_info
*event_thread
;
2385 struct target_waitstatus ws
;
2387 int stop_func_filled_in
;
2388 CORE_ADDR stop_func_start
;
2389 CORE_ADDR stop_func_end
;
2390 const char *stop_func_name
;
2394 static void handle_inferior_event (struct execution_control_state
*ecs
);
2396 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2397 struct execution_control_state
*ecs
);
2398 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2399 struct execution_control_state
*ecs
);
2400 static void check_exception_resume (struct execution_control_state
*,
2401 struct frame_info
*);
2403 static void stop_stepping (struct execution_control_state
*ecs
);
2404 static void prepare_to_wait (struct execution_control_state
*ecs
);
2405 static void keep_going (struct execution_control_state
*ecs
);
2407 /* Callback for iterate over threads. If the thread is stopped, but
2408 the user/frontend doesn't know about that yet, go through
2409 normal_stop, as if the thread had just stopped now. ARG points at
2410 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2411 ptid_is_pid(PTID) is true, applies to all threads of the process
2412 pointed at by PTID. Otherwise, apply only to the thread pointed by
2416 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2418 ptid_t ptid
= * (ptid_t
*) arg
;
2420 if ((ptid_equal (info
->ptid
, ptid
)
2421 || ptid_equal (minus_one_ptid
, ptid
)
2422 || (ptid_is_pid (ptid
)
2423 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2424 && is_running (info
->ptid
)
2425 && !is_executing (info
->ptid
))
2427 struct cleanup
*old_chain
;
2428 struct execution_control_state ecss
;
2429 struct execution_control_state
*ecs
= &ecss
;
2431 memset (ecs
, 0, sizeof (*ecs
));
2433 old_chain
= make_cleanup_restore_current_thread ();
2435 /* Go through handle_inferior_event/normal_stop, so we always
2436 have consistent output as if the stop event had been
2438 ecs
->ptid
= info
->ptid
;
2439 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2440 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2441 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2443 handle_inferior_event (ecs
);
2445 if (!ecs
->wait_some_more
)
2447 struct thread_info
*tp
;
2451 /* Finish off the continuations. */
2452 tp
= inferior_thread ();
2453 do_all_intermediate_continuations_thread (tp
, 1);
2454 do_all_continuations_thread (tp
, 1);
2457 do_cleanups (old_chain
);
2463 /* This function is attached as a "thread_stop_requested" observer.
2464 Cleanup local state that assumed the PTID was to be resumed, and
2465 report the stop to the frontend. */
2468 infrun_thread_stop_requested (ptid_t ptid
)
2470 struct displaced_step_inferior_state
*displaced
;
2472 /* PTID was requested to stop. Remove it from the displaced
2473 stepping queue, so we don't try to resume it automatically. */
2475 for (displaced
= displaced_step_inferior_states
;
2477 displaced
= displaced
->next
)
2479 struct displaced_step_request
*it
, **prev_next_p
;
2481 it
= displaced
->step_request_queue
;
2482 prev_next_p
= &displaced
->step_request_queue
;
2485 if (ptid_match (it
->ptid
, ptid
))
2487 *prev_next_p
= it
->next
;
2493 prev_next_p
= &it
->next
;
2500 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2504 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2506 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2507 nullify_last_target_wait_ptid ();
2510 /* Callback for iterate_over_threads. */
2513 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2515 if (is_exited (info
->ptid
))
2518 delete_step_resume_breakpoint (info
);
2519 delete_exception_resume_breakpoint (info
);
2523 /* In all-stop, delete the step resume breakpoint of any thread that
2524 had one. In non-stop, delete the step resume breakpoint of the
2525 thread that just stopped. */
2528 delete_step_thread_step_resume_breakpoint (void)
2530 if (!target_has_execution
2531 || ptid_equal (inferior_ptid
, null_ptid
))
2532 /* If the inferior has exited, we have already deleted the step
2533 resume breakpoints out of GDB's lists. */
2538 /* If in non-stop mode, only delete the step-resume or
2539 longjmp-resume breakpoint of the thread that just stopped
2541 struct thread_info
*tp
= inferior_thread ();
2543 delete_step_resume_breakpoint (tp
);
2544 delete_exception_resume_breakpoint (tp
);
2547 /* In all-stop mode, delete all step-resume and longjmp-resume
2548 breakpoints of any thread that had them. */
2549 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2552 /* A cleanup wrapper. */
2555 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2557 delete_step_thread_step_resume_breakpoint ();
2560 /* Pretty print the results of target_wait, for debugging purposes. */
2563 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2564 const struct target_waitstatus
*ws
)
2566 char *status_string
= target_waitstatus_to_string (ws
);
2567 struct ui_file
*tmp_stream
= mem_fileopen ();
2570 /* The text is split over several lines because it was getting too long.
2571 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2572 output as a unit; we want only one timestamp printed if debug_timestamp
2575 fprintf_unfiltered (tmp_stream
,
2576 "infrun: target_wait (%d", PIDGET (waiton_ptid
));
2577 if (PIDGET (waiton_ptid
) != -1)
2578 fprintf_unfiltered (tmp_stream
,
2579 " [%s]", target_pid_to_str (waiton_ptid
));
2580 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2581 fprintf_unfiltered (tmp_stream
,
2582 "infrun: %d [%s],\n",
2583 PIDGET (result_ptid
), target_pid_to_str (result_ptid
));
2584 fprintf_unfiltered (tmp_stream
,
2588 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2590 /* This uses %s in part to handle %'s in the text, but also to avoid
2591 a gcc error: the format attribute requires a string literal. */
2592 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2594 xfree (status_string
);
2596 ui_file_delete (tmp_stream
);
2599 /* Prepare and stabilize the inferior for detaching it. E.g.,
2600 detaching while a thread is displaced stepping is a recipe for
2601 crashing it, as nothing would readjust the PC out of the scratch
2605 prepare_for_detach (void)
2607 struct inferior
*inf
= current_inferior ();
2608 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
2609 struct cleanup
*old_chain_1
;
2610 struct displaced_step_inferior_state
*displaced
;
2612 displaced
= get_displaced_stepping_state (inf
->pid
);
2614 /* Is any thread of this process displaced stepping? If not,
2615 there's nothing else to do. */
2616 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
2620 fprintf_unfiltered (gdb_stdlog
,
2621 "displaced-stepping in-process while detaching");
2623 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
2626 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
2628 struct cleanup
*old_chain_2
;
2629 struct execution_control_state ecss
;
2630 struct execution_control_state
*ecs
;
2633 memset (ecs
, 0, sizeof (*ecs
));
2635 overlay_cache_invalid
= 1;
2637 if (deprecated_target_wait_hook
)
2638 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
2640 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
2643 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
2645 /* If an error happens while handling the event, propagate GDB's
2646 knowledge of the executing state to the frontend/user running
2648 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
2651 /* Now figure out what to do with the result of the result. */
2652 handle_inferior_event (ecs
);
2654 /* No error, don't finish the state yet. */
2655 discard_cleanups (old_chain_2
);
2657 /* Breakpoints and watchpoints are not installed on the target
2658 at this point, and signals are passed directly to the
2659 inferior, so this must mean the process is gone. */
2660 if (!ecs
->wait_some_more
)
2662 discard_cleanups (old_chain_1
);
2663 error (_("Program exited while detaching"));
2667 discard_cleanups (old_chain_1
);
2670 /* Wait for control to return from inferior to debugger.
2672 If inferior gets a signal, we may decide to start it up again
2673 instead of returning. That is why there is a loop in this function.
2674 When this function actually returns it means the inferior
2675 should be left stopped and GDB should read more commands. */
2678 wait_for_inferior (void)
2680 struct cleanup
*old_cleanups
;
2684 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
2687 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
2691 struct execution_control_state ecss
;
2692 struct execution_control_state
*ecs
= &ecss
;
2693 struct cleanup
*old_chain
;
2695 memset (ecs
, 0, sizeof (*ecs
));
2697 overlay_cache_invalid
= 1;
2699 if (deprecated_target_wait_hook
)
2700 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2702 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2705 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2707 /* If an error happens while handling the event, propagate GDB's
2708 knowledge of the executing state to the frontend/user running
2710 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2712 /* Now figure out what to do with the result of the result. */
2713 handle_inferior_event (ecs
);
2715 /* No error, don't finish the state yet. */
2716 discard_cleanups (old_chain
);
2718 if (!ecs
->wait_some_more
)
2722 do_cleanups (old_cleanups
);
2725 /* Asynchronous version of wait_for_inferior. It is called by the
2726 event loop whenever a change of state is detected on the file
2727 descriptor corresponding to the target. It can be called more than
2728 once to complete a single execution command. In such cases we need
2729 to keep the state in a global variable ECSS. If it is the last time
2730 that this function is called for a single execution command, then
2731 report to the user that the inferior has stopped, and do the
2732 necessary cleanups. */
2735 fetch_inferior_event (void *client_data
)
2737 struct execution_control_state ecss
;
2738 struct execution_control_state
*ecs
= &ecss
;
2739 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2740 struct cleanup
*ts_old_chain
;
2741 int was_sync
= sync_execution
;
2744 memset (ecs
, 0, sizeof (*ecs
));
2746 /* We're handling a live event, so make sure we're doing live
2747 debugging. If we're looking at traceframes while the target is
2748 running, we're going to need to get back to that mode after
2749 handling the event. */
2752 make_cleanup_restore_current_traceframe ();
2753 set_current_traceframe (-1);
2757 /* In non-stop mode, the user/frontend should not notice a thread
2758 switch due to internal events. Make sure we reverse to the
2759 user selected thread and frame after handling the event and
2760 running any breakpoint commands. */
2761 make_cleanup_restore_current_thread ();
2763 overlay_cache_invalid
= 1;
2765 make_cleanup_restore_integer (&execution_direction
);
2766 execution_direction
= target_execution_direction ();
2768 if (deprecated_target_wait_hook
)
2770 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2772 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2775 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2777 /* If an error happens while handling the event, propagate GDB's
2778 knowledge of the executing state to the frontend/user running
2781 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2783 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2785 /* Get executed before make_cleanup_restore_current_thread above to apply
2786 still for the thread which has thrown the exception. */
2787 make_bpstat_clear_actions_cleanup ();
2789 /* Now figure out what to do with the result of the result. */
2790 handle_inferior_event (ecs
);
2792 if (!ecs
->wait_some_more
)
2794 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2796 delete_step_thread_step_resume_breakpoint ();
2798 /* We may not find an inferior if this was a process exit. */
2799 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
2802 if (target_has_execution
2803 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
2804 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2805 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2806 && ecs
->event_thread
->step_multi
2807 && ecs
->event_thread
->control
.stop_step
)
2808 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2811 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2816 /* No error, don't finish the thread states yet. */
2817 discard_cleanups (ts_old_chain
);
2819 /* Revert thread and frame. */
2820 do_cleanups (old_chain
);
2822 /* If the inferior was in sync execution mode, and now isn't,
2823 restore the prompt (a synchronous execution command has finished,
2824 and we're ready for input). */
2825 if (interpreter_async
&& was_sync
&& !sync_execution
)
2826 display_gdb_prompt (0);
2830 && exec_done_display_p
2831 && (ptid_equal (inferior_ptid
, null_ptid
)
2832 || !is_running (inferior_ptid
)))
2833 printf_unfiltered (_("completed.\n"));
2836 /* Record the frame and location we're currently stepping through. */
2838 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2840 struct thread_info
*tp
= inferior_thread ();
2842 tp
->control
.step_frame_id
= get_frame_id (frame
);
2843 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
2845 tp
->current_symtab
= sal
.symtab
;
2846 tp
->current_line
= sal
.line
;
2849 /* Clear context switchable stepping state. */
2852 init_thread_stepping_state (struct thread_info
*tss
)
2854 tss
->stepping_over_breakpoint
= 0;
2855 tss
->step_after_step_resume_breakpoint
= 0;
2858 /* Return the cached copy of the last pid/waitstatus returned by
2859 target_wait()/deprecated_target_wait_hook(). The data is actually
2860 cached by handle_inferior_event(), which gets called immediately
2861 after target_wait()/deprecated_target_wait_hook(). */
2864 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2866 *ptidp
= target_last_wait_ptid
;
2867 *status
= target_last_waitstatus
;
2871 nullify_last_target_wait_ptid (void)
2873 target_last_wait_ptid
= minus_one_ptid
;
2876 /* Switch thread contexts. */
2879 context_switch (ptid_t ptid
)
2881 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
2883 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
2884 target_pid_to_str (inferior_ptid
));
2885 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
2886 target_pid_to_str (ptid
));
2889 switch_to_thread (ptid
);
2893 adjust_pc_after_break (struct execution_control_state
*ecs
)
2895 struct regcache
*regcache
;
2896 struct gdbarch
*gdbarch
;
2897 struct address_space
*aspace
;
2898 CORE_ADDR breakpoint_pc
;
2900 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2901 we aren't, just return.
2903 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2904 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2905 implemented by software breakpoints should be handled through the normal
2908 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2909 different signals (SIGILL or SIGEMT for instance), but it is less
2910 clear where the PC is pointing afterwards. It may not match
2911 gdbarch_decr_pc_after_break. I don't know any specific target that
2912 generates these signals at breakpoints (the code has been in GDB since at
2913 least 1992) so I can not guess how to handle them here.
2915 In earlier versions of GDB, a target with
2916 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2917 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2918 target with both of these set in GDB history, and it seems unlikely to be
2919 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2921 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
2924 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
2927 /* In reverse execution, when a breakpoint is hit, the instruction
2928 under it has already been de-executed. The reported PC always
2929 points at the breakpoint address, so adjusting it further would
2930 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2933 B1 0x08000000 : INSN1
2934 B2 0x08000001 : INSN2
2936 PC -> 0x08000003 : INSN4
2938 Say you're stopped at 0x08000003 as above. Reverse continuing
2939 from that point should hit B2 as below. Reading the PC when the
2940 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2941 been de-executed already.
2943 B1 0x08000000 : INSN1
2944 B2 PC -> 0x08000001 : INSN2
2948 We can't apply the same logic as for forward execution, because
2949 we would wrongly adjust the PC to 0x08000000, since there's a
2950 breakpoint at PC - 1. We'd then report a hit on B1, although
2951 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2953 if (execution_direction
== EXEC_REVERSE
)
2956 /* If this target does not decrement the PC after breakpoints, then
2957 we have nothing to do. */
2958 regcache
= get_thread_regcache (ecs
->ptid
);
2959 gdbarch
= get_regcache_arch (regcache
);
2960 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
2963 aspace
= get_regcache_aspace (regcache
);
2965 /* Find the location where (if we've hit a breakpoint) the
2966 breakpoint would be. */
2967 breakpoint_pc
= regcache_read_pc (regcache
)
2968 - gdbarch_decr_pc_after_break (gdbarch
);
2970 /* Check whether there actually is a software breakpoint inserted at
2973 If in non-stop mode, a race condition is possible where we've
2974 removed a breakpoint, but stop events for that breakpoint were
2975 already queued and arrive later. To suppress those spurious
2976 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2977 and retire them after a number of stop events are reported. */
2978 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
2979 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
2981 struct cleanup
*old_cleanups
= NULL
;
2984 old_cleanups
= record_gdb_operation_disable_set ();
2986 /* When using hardware single-step, a SIGTRAP is reported for both
2987 a completed single-step and a software breakpoint. Need to
2988 differentiate between the two, as the latter needs adjusting
2989 but the former does not.
2991 The SIGTRAP can be due to a completed hardware single-step only if
2992 - we didn't insert software single-step breakpoints
2993 - the thread to be examined is still the current thread
2994 - this thread is currently being stepped
2996 If any of these events did not occur, we must have stopped due
2997 to hitting a software breakpoint, and have to back up to the
3000 As a special case, we could have hardware single-stepped a
3001 software breakpoint. In this case (prev_pc == breakpoint_pc),
3002 we also need to back up to the breakpoint address. */
3004 if (singlestep_breakpoints_inserted_p
3005 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
3006 || !currently_stepping (ecs
->event_thread
)
3007 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
3008 regcache_write_pc (regcache
, breakpoint_pc
);
3011 do_cleanups (old_cleanups
);
3016 init_infwait_state (void)
3018 waiton_ptid
= pid_to_ptid (-1);
3019 infwait_state
= infwait_normal_state
;
3023 error_is_running (void)
3025 error (_("Cannot execute this command while "
3026 "the selected thread is running."));
3030 ensure_not_running (void)
3032 if (is_running (inferior_ptid
))
3033 error_is_running ();
3037 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3039 for (frame
= get_prev_frame (frame
);
3041 frame
= get_prev_frame (frame
))
3043 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3045 if (get_frame_type (frame
) != INLINE_FRAME
)
3052 /* Auxiliary function that handles syscall entry/return events.
3053 It returns 1 if the inferior should keep going (and GDB
3054 should ignore the event), or 0 if the event deserves to be
3058 handle_syscall_event (struct execution_control_state
*ecs
)
3060 struct regcache
*regcache
;
3061 struct gdbarch
*gdbarch
;
3064 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3065 context_switch (ecs
->ptid
);
3067 regcache
= get_thread_regcache (ecs
->ptid
);
3068 gdbarch
= get_regcache_arch (regcache
);
3069 syscall_number
= ecs
->ws
.value
.syscall_number
;
3070 stop_pc
= regcache_read_pc (regcache
);
3072 if (catch_syscall_enabled () > 0
3073 && catching_syscall_number (syscall_number
) > 0)
3076 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3079 ecs
->event_thread
->control
.stop_bpstat
3080 = bpstat_stop_status (get_regcache_aspace (regcache
),
3081 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3083 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
);
3085 if (!ecs
->random_signal
)
3087 /* Catchpoint hit. */
3088 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3093 /* If no catchpoint triggered for this, then keep going. */
3094 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3099 /* Clear the supplied execution_control_state's stop_func_* fields. */
3102 clear_stop_func (struct execution_control_state
*ecs
)
3104 ecs
->stop_func_filled_in
= 0;
3105 ecs
->stop_func_start
= 0;
3106 ecs
->stop_func_end
= 0;
3107 ecs
->stop_func_name
= NULL
;
3110 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3113 fill_in_stop_func (struct gdbarch
*gdbarch
,
3114 struct execution_control_state
*ecs
)
3116 if (!ecs
->stop_func_filled_in
)
3118 /* Don't care about return value; stop_func_start and stop_func_name
3119 will both be 0 if it doesn't work. */
3120 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3121 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3122 ecs
->stop_func_start
3123 += gdbarch_deprecated_function_start_offset (gdbarch
);
3125 ecs
->stop_func_filled_in
= 1;
3129 /* Given an execution control state that has been freshly filled in
3130 by an event from the inferior, figure out what it means and take
3131 appropriate action. */
3134 handle_inferior_event (struct execution_control_state
*ecs
)
3136 struct frame_info
*frame
;
3137 struct gdbarch
*gdbarch
;
3138 int stopped_by_watchpoint
;
3139 int stepped_after_stopped_by_watchpoint
= 0;
3140 struct symtab_and_line stop_pc_sal
;
3141 enum stop_kind stop_soon
;
3143 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3145 /* We had an event in the inferior, but we are not interested in
3146 handling it at this level. The lower layers have already
3147 done what needs to be done, if anything.
3149 One of the possible circumstances for this is when the
3150 inferior produces output for the console. The inferior has
3151 not stopped, and we are ignoring the event. Another possible
3152 circumstance is any event which the lower level knows will be
3153 reported multiple times without an intervening resume. */
3155 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3156 prepare_to_wait (ecs
);
3160 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3161 && target_can_async_p () && !sync_execution
)
3163 /* There were no unwaited-for children left in the target, but,
3164 we're not synchronously waiting for events either. Just
3165 ignore. Otherwise, if we were running a synchronous
3166 execution command, we need to cancel it and give the user
3167 back the terminal. */
3169 fprintf_unfiltered (gdb_stdlog
,
3170 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3171 prepare_to_wait (ecs
);
3175 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3176 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3177 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
3179 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3182 stop_soon
= inf
->control
.stop_soon
;
3185 stop_soon
= NO_STOP_QUIETLY
;
3187 /* Cache the last pid/waitstatus. */
3188 target_last_wait_ptid
= ecs
->ptid
;
3189 target_last_waitstatus
= ecs
->ws
;
3191 /* Always clear state belonging to the previous time we stopped. */
3192 stop_stack_dummy
= STOP_NONE
;
3194 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3196 /* No unwaited-for children left. IOW, all resumed children
3199 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3201 stop_print_frame
= 0;
3202 stop_stepping (ecs
);
3206 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3207 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3209 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3210 /* If it's a new thread, add it to the thread database. */
3211 if (ecs
->event_thread
== NULL
)
3212 ecs
->event_thread
= add_thread (ecs
->ptid
);
3215 /* Dependent on valid ECS->EVENT_THREAD. */
3216 adjust_pc_after_break (ecs
);
3218 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3219 reinit_frame_cache ();
3221 breakpoint_retire_moribund ();
3223 /* First, distinguish signals caused by the debugger from signals
3224 that have to do with the program's own actions. Note that
3225 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3226 on the operating system version. Here we detect when a SIGILL or
3227 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3228 something similar for SIGSEGV, since a SIGSEGV will be generated
3229 when we're trying to execute a breakpoint instruction on a
3230 non-executable stack. This happens for call dummy breakpoints
3231 for architectures like SPARC that place call dummies on the
3233 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3234 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3235 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3236 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3238 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3240 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3241 regcache_read_pc (regcache
)))
3244 fprintf_unfiltered (gdb_stdlog
,
3245 "infrun: Treating signal as SIGTRAP\n");
3246 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3250 /* Mark the non-executing threads accordingly. In all-stop, all
3251 threads of all processes are stopped when we get any event
3252 reported. In non-stop mode, only the event thread stops. If
3253 we're handling a process exit in non-stop mode, there's nothing
3254 to do, as threads of the dead process are gone, and threads of
3255 any other process were left running. */
3257 set_executing (minus_one_ptid
, 0);
3258 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3259 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3260 set_executing (ecs
->ptid
, 0);
3262 switch (infwait_state
)
3264 case infwait_thread_hop_state
:
3266 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
3269 case infwait_normal_state
:
3271 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
3274 case infwait_step_watch_state
:
3276 fprintf_unfiltered (gdb_stdlog
,
3277 "infrun: infwait_step_watch_state\n");
3279 stepped_after_stopped_by_watchpoint
= 1;
3282 case infwait_nonstep_watch_state
:
3284 fprintf_unfiltered (gdb_stdlog
,
3285 "infrun: infwait_nonstep_watch_state\n");
3286 insert_breakpoints ();
3288 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3289 handle things like signals arriving and other things happening
3290 in combination correctly? */
3291 stepped_after_stopped_by_watchpoint
= 1;
3295 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3298 infwait_state
= infwait_normal_state
;
3299 waiton_ptid
= pid_to_ptid (-1);
3301 switch (ecs
->ws
.kind
)
3303 case TARGET_WAITKIND_LOADED
:
3305 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3306 /* Ignore gracefully during startup of the inferior, as it might
3307 be the shell which has just loaded some objects, otherwise
3308 add the symbols for the newly loaded objects. Also ignore at
3309 the beginning of an attach or remote session; we will query
3310 the full list of libraries once the connection is
3312 if (stop_soon
== NO_STOP_QUIETLY
)
3314 struct regcache
*regcache
;
3316 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3317 context_switch (ecs
->ptid
);
3318 regcache
= get_thread_regcache (ecs
->ptid
);
3320 handle_solib_event ();
3322 ecs
->event_thread
->control
.stop_bpstat
3323 = bpstat_stop_status (get_regcache_aspace (regcache
),
3324 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3326 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
);
3328 if (!ecs
->random_signal
)
3330 /* A catchpoint triggered. */
3331 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3332 goto process_event_stop_test
;
3335 /* If requested, stop when the dynamic linker notifies
3336 gdb of events. This allows the user to get control
3337 and place breakpoints in initializer routines for
3338 dynamically loaded objects (among other things). */
3339 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3340 if (stop_on_solib_events
)
3342 /* Make sure we print "Stopped due to solib-event" in
3344 stop_print_frame
= 1;
3346 stop_stepping (ecs
);
3351 /* If we are skipping through a shell, or through shared library
3352 loading that we aren't interested in, resume the program. If
3353 we're running the program normally, also resume. But stop if
3354 we're attaching or setting up a remote connection. */
3355 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3357 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3358 context_switch (ecs
->ptid
);
3360 /* Loading of shared libraries might have changed breakpoint
3361 addresses. Make sure new breakpoints are inserted. */
3362 if (stop_soon
== NO_STOP_QUIETLY
3363 && !breakpoints_always_inserted_mode ())
3364 insert_breakpoints ();
3365 resume (0, GDB_SIGNAL_0
);
3366 prepare_to_wait (ecs
);
3372 case TARGET_WAITKIND_SPURIOUS
:
3374 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3375 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3376 context_switch (ecs
->ptid
);
3377 resume (0, GDB_SIGNAL_0
);
3378 prepare_to_wait (ecs
);
3381 case TARGET_WAITKIND_EXITED
:
3382 case TARGET_WAITKIND_SIGNALLED
:
3385 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3386 fprintf_unfiltered (gdb_stdlog
,
3387 "infrun: TARGET_WAITKIND_EXITED\n");
3389 fprintf_unfiltered (gdb_stdlog
,
3390 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3393 inferior_ptid
= ecs
->ptid
;
3394 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3395 set_current_program_space (current_inferior ()->pspace
);
3396 handle_vfork_child_exec_or_exit (0);
3397 target_terminal_ours (); /* Must do this before mourn anyway. */
3399 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3401 /* Record the exit code in the convenience variable $_exitcode, so
3402 that the user can inspect this again later. */
3403 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3404 (LONGEST
) ecs
->ws
.value
.integer
);
3406 /* Also record this in the inferior itself. */
3407 current_inferior ()->has_exit_code
= 1;
3408 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3410 print_exited_reason (ecs
->ws
.value
.integer
);
3413 print_signal_exited_reason (ecs
->ws
.value
.sig
);
3415 gdb_flush (gdb_stdout
);
3416 target_mourn_inferior ();
3417 singlestep_breakpoints_inserted_p
= 0;
3418 cancel_single_step_breakpoints ();
3419 stop_print_frame
= 0;
3420 stop_stepping (ecs
);
3423 /* The following are the only cases in which we keep going;
3424 the above cases end in a continue or goto. */
3425 case TARGET_WAITKIND_FORKED
:
3426 case TARGET_WAITKIND_VFORKED
:
3429 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3430 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3432 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3435 /* Check whether the inferior is displaced stepping. */
3437 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3438 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3439 struct displaced_step_inferior_state
*displaced
3440 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3442 /* If checking displaced stepping is supported, and thread
3443 ecs->ptid is displaced stepping. */
3444 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3446 struct inferior
*parent_inf
3447 = find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3448 struct regcache
*child_regcache
;
3449 CORE_ADDR parent_pc
;
3451 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3452 indicating that the displaced stepping of syscall instruction
3453 has been done. Perform cleanup for parent process here. Note
3454 that this operation also cleans up the child process for vfork,
3455 because their pages are shared. */
3456 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3458 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3460 /* Restore scratch pad for child process. */
3461 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3464 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3465 the child's PC is also within the scratchpad. Set the child's PC
3466 to the parent's PC value, which has already been fixed up.
3467 FIXME: we use the parent's aspace here, although we're touching
3468 the child, because the child hasn't been added to the inferior
3469 list yet at this point. */
3472 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
3474 parent_inf
->aspace
);
3475 /* Read PC value of parent process. */
3476 parent_pc
= regcache_read_pc (regcache
);
3478 if (debug_displaced
)
3479 fprintf_unfiltered (gdb_stdlog
,
3480 "displaced: write child pc from %s to %s\n",
3482 regcache_read_pc (child_regcache
)),
3483 paddress (gdbarch
, parent_pc
));
3485 regcache_write_pc (child_regcache
, parent_pc
);
3489 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3490 context_switch (ecs
->ptid
);
3492 /* Immediately detach breakpoints from the child before there's
3493 any chance of letting the user delete breakpoints from the
3494 breakpoint lists. If we don't do this early, it's easy to
3495 leave left over traps in the child, vis: "break foo; catch
3496 fork; c; <fork>; del; c; <child calls foo>". We only follow
3497 the fork on the last `continue', and by that time the
3498 breakpoint at "foo" is long gone from the breakpoint table.
3499 If we vforked, then we don't need to unpatch here, since both
3500 parent and child are sharing the same memory pages; we'll
3501 need to unpatch at follow/detach time instead to be certain
3502 that new breakpoints added between catchpoint hit time and
3503 vfork follow are detached. */
3504 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
3506 /* This won't actually modify the breakpoint list, but will
3507 physically remove the breakpoints from the child. */
3508 detach_breakpoints (ecs
->ws
.value
.related_pid
);
3511 if (singlestep_breakpoints_inserted_p
)
3513 /* Pull the single step breakpoints out of the target. */
3514 remove_single_step_breakpoints ();
3515 singlestep_breakpoints_inserted_p
= 0;
3518 /* In case the event is caught by a catchpoint, remember that
3519 the event is to be followed at the next resume of the thread,
3520 and not immediately. */
3521 ecs
->event_thread
->pending_follow
= ecs
->ws
;
3523 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3525 ecs
->event_thread
->control
.stop_bpstat
3526 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3527 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3529 /* Note that we're interested in knowing the bpstat actually
3530 causes a stop, not just if it may explain the signal.
3531 Software watchpoints, for example, always appear in the
3534 = !bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
);
3536 /* If no catchpoint triggered for this, then keep going. */
3537 if (ecs
->random_signal
)
3543 = (follow_fork_mode_string
== follow_fork_mode_child
);
3545 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3547 should_resume
= follow_fork ();
3550 child
= ecs
->ws
.value
.related_pid
;
3552 /* In non-stop mode, also resume the other branch. */
3553 if (non_stop
&& !detach_fork
)
3556 switch_to_thread (parent
);
3558 switch_to_thread (child
);
3560 ecs
->event_thread
= inferior_thread ();
3561 ecs
->ptid
= inferior_ptid
;
3566 switch_to_thread (child
);
3568 switch_to_thread (parent
);
3570 ecs
->event_thread
= inferior_thread ();
3571 ecs
->ptid
= inferior_ptid
;
3576 stop_stepping (ecs
);
3579 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3580 goto process_event_stop_test
;
3582 case TARGET_WAITKIND_VFORK_DONE
:
3583 /* Done with the shared memory region. Re-insert breakpoints in
3584 the parent, and keep going. */
3587 fprintf_unfiltered (gdb_stdlog
,
3588 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3590 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3591 context_switch (ecs
->ptid
);
3593 current_inferior ()->waiting_for_vfork_done
= 0;
3594 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3595 /* This also takes care of reinserting breakpoints in the
3596 previously locked inferior. */
3600 case TARGET_WAITKIND_EXECD
:
3602 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3604 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3605 context_switch (ecs
->ptid
);
3607 singlestep_breakpoints_inserted_p
= 0;
3608 cancel_single_step_breakpoints ();
3610 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3612 /* Do whatever is necessary to the parent branch of the vfork. */
3613 handle_vfork_child_exec_or_exit (1);
3615 /* This causes the eventpoints and symbol table to be reset.
3616 Must do this now, before trying to determine whether to
3618 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3620 ecs
->event_thread
->control
.stop_bpstat
3621 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3622 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3624 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
);
3626 /* Note that this may be referenced from inside
3627 bpstat_stop_status above, through inferior_has_execd. */
3628 xfree (ecs
->ws
.value
.execd_pathname
);
3629 ecs
->ws
.value
.execd_pathname
= NULL
;
3631 /* If no catchpoint triggered for this, then keep going. */
3632 if (ecs
->random_signal
)
3634 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3638 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3639 goto process_event_stop_test
;
3641 /* Be careful not to try to gather much state about a thread
3642 that's in a syscall. It's frequently a losing proposition. */
3643 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3645 fprintf_unfiltered (gdb_stdlog
,
3646 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3647 /* Getting the current syscall number. */
3648 if (handle_syscall_event (ecs
) != 0)
3650 goto process_event_stop_test
;
3652 /* Before examining the threads further, step this thread to
3653 get it entirely out of the syscall. (We get notice of the
3654 event when the thread is just on the verge of exiting a
3655 syscall. Stepping one instruction seems to get it back
3657 case TARGET_WAITKIND_SYSCALL_RETURN
:
3659 fprintf_unfiltered (gdb_stdlog
,
3660 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3661 if (handle_syscall_event (ecs
) != 0)
3663 goto process_event_stop_test
;
3665 case TARGET_WAITKIND_STOPPED
:
3667 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
3668 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
3671 case TARGET_WAITKIND_NO_HISTORY
:
3673 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
3674 /* Reverse execution: target ran out of history info. */
3676 /* Pull the single step breakpoints out of the target. */
3677 if (singlestep_breakpoints_inserted_p
)
3679 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3680 context_switch (ecs
->ptid
);
3681 remove_single_step_breakpoints ();
3682 singlestep_breakpoints_inserted_p
= 0;
3684 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3685 print_no_history_reason ();
3686 stop_stepping (ecs
);
3690 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
3692 /* Do we need to clean up the state of a thread that has
3693 completed a displaced single-step? (Doing so usually affects
3694 the PC, so do it here, before we set stop_pc.) */
3695 displaced_step_fixup (ecs
->ptid
,
3696 ecs
->event_thread
->suspend
.stop_signal
);
3698 /* If we either finished a single-step or hit a breakpoint, but
3699 the user wanted this thread to be stopped, pretend we got a
3700 SIG0 (generic unsignaled stop). */
3702 if (ecs
->event_thread
->stop_requested
3703 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3704 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3707 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3711 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3712 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3713 struct cleanup
*old_chain
= save_inferior_ptid ();
3715 inferior_ptid
= ecs
->ptid
;
3717 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
3718 paddress (gdbarch
, stop_pc
));
3719 if (target_stopped_by_watchpoint ())
3723 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
3725 if (target_stopped_data_address (¤t_target
, &addr
))
3726 fprintf_unfiltered (gdb_stdlog
,
3727 "infrun: stopped data address = %s\n",
3728 paddress (gdbarch
, addr
));
3730 fprintf_unfiltered (gdb_stdlog
,
3731 "infrun: (no data address available)\n");
3734 do_cleanups (old_chain
);
3737 if (stepping_past_singlestep_breakpoint
)
3739 gdb_assert (singlestep_breakpoints_inserted_p
);
3740 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
3741 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
3743 stepping_past_singlestep_breakpoint
= 0;
3745 /* We've either finished single-stepping past the single-step
3746 breakpoint, or stopped for some other reason. It would be nice if
3747 we could tell, but we can't reliably. */
3748 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3751 fprintf_unfiltered (gdb_stdlog
,
3752 "infrun: stepping_past_"
3753 "singlestep_breakpoint\n");
3754 /* Pull the single step breakpoints out of the target. */
3755 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3756 context_switch (ecs
->ptid
);
3757 remove_single_step_breakpoints ();
3758 singlestep_breakpoints_inserted_p
= 0;
3760 ecs
->random_signal
= 0;
3761 ecs
->event_thread
->control
.trap_expected
= 0;
3763 context_switch (saved_singlestep_ptid
);
3764 if (deprecated_context_hook
)
3765 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3767 resume (1, GDB_SIGNAL_0
);
3768 prepare_to_wait (ecs
);
3773 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
3775 /* In non-stop mode, there's never a deferred_step_ptid set. */
3776 gdb_assert (!non_stop
);
3778 /* If we stopped for some other reason than single-stepping, ignore
3779 the fact that we were supposed to switch back. */
3780 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3783 fprintf_unfiltered (gdb_stdlog
,
3784 "infrun: handling deferred step\n");
3786 /* Pull the single step breakpoints out of the target. */
3787 if (singlestep_breakpoints_inserted_p
)
3789 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3790 context_switch (ecs
->ptid
);
3791 remove_single_step_breakpoints ();
3792 singlestep_breakpoints_inserted_p
= 0;
3795 ecs
->event_thread
->control
.trap_expected
= 0;
3797 context_switch (deferred_step_ptid
);
3798 deferred_step_ptid
= null_ptid
;
3799 /* Suppress spurious "Switching to ..." message. */
3800 previous_inferior_ptid
= inferior_ptid
;
3802 resume (1, GDB_SIGNAL_0
);
3803 prepare_to_wait (ecs
);
3807 deferred_step_ptid
= null_ptid
;
3810 /* See if a thread hit a thread-specific breakpoint that was meant for
3811 another thread. If so, then step that thread past the breakpoint,
3814 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3816 int thread_hop_needed
= 0;
3817 struct address_space
*aspace
=
3818 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
3820 /* Check if a regular breakpoint has been hit before checking
3821 for a potential single step breakpoint. Otherwise, GDB will
3822 not see this breakpoint hit when stepping onto breakpoints. */
3823 if (regular_breakpoint_inserted_here_p (aspace
, stop_pc
))
3825 ecs
->random_signal
= 0;
3826 if (!breakpoint_thread_match (aspace
, stop_pc
, ecs
->ptid
))
3827 thread_hop_needed
= 1;
3829 else if (singlestep_breakpoints_inserted_p
)
3831 /* We have not context switched yet, so this should be true
3832 no matter which thread hit the singlestep breakpoint. */
3833 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
3835 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
3837 target_pid_to_str (ecs
->ptid
));
3839 ecs
->random_signal
= 0;
3840 /* The call to in_thread_list is necessary because PTIDs sometimes
3841 change when we go from single-threaded to multi-threaded. If
3842 the singlestep_ptid is still in the list, assume that it is
3843 really different from ecs->ptid. */
3844 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
3845 && in_thread_list (singlestep_ptid
))
3847 /* If the PC of the thread we were trying to single-step
3848 has changed, discard this event (which we were going
3849 to ignore anyway), and pretend we saw that thread
3850 trap. This prevents us continuously moving the
3851 single-step breakpoint forward, one instruction at a
3852 time. If the PC has changed, then the thread we were
3853 trying to single-step has trapped or been signalled,
3854 but the event has not been reported to GDB yet.
3856 There might be some cases where this loses signal
3857 information, if a signal has arrived at exactly the
3858 same time that the PC changed, but this is the best
3859 we can do with the information available. Perhaps we
3860 should arrange to report all events for all threads
3861 when they stop, or to re-poll the remote looking for
3862 this particular thread (i.e. temporarily enable
3865 CORE_ADDR new_singlestep_pc
3866 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
3868 if (new_singlestep_pc
!= singlestep_pc
)
3870 enum gdb_signal stop_signal
;
3873 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
3874 " but expected thread advanced also\n");
3876 /* The current context still belongs to
3877 singlestep_ptid. Don't swap here, since that's
3878 the context we want to use. Just fudge our
3879 state and continue. */
3880 stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
3881 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3882 ecs
->ptid
= singlestep_ptid
;
3883 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3884 ecs
->event_thread
->suspend
.stop_signal
= stop_signal
;
3885 stop_pc
= new_singlestep_pc
;
3890 fprintf_unfiltered (gdb_stdlog
,
3891 "infrun: unexpected thread\n");
3893 thread_hop_needed
= 1;
3894 stepping_past_singlestep_breakpoint
= 1;
3895 saved_singlestep_ptid
= singlestep_ptid
;
3900 if (thread_hop_needed
)
3902 struct regcache
*thread_regcache
;
3903 int remove_status
= 0;
3906 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
3908 /* Switch context before touching inferior memory, the
3909 previous thread may have exited. */
3910 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
3911 context_switch (ecs
->ptid
);
3913 /* Saw a breakpoint, but it was hit by the wrong thread.
3916 if (singlestep_breakpoints_inserted_p
)
3918 /* Pull the single step breakpoints out of the target. */
3919 remove_single_step_breakpoints ();
3920 singlestep_breakpoints_inserted_p
= 0;
3923 /* If the arch can displace step, don't remove the
3925 thread_regcache
= get_thread_regcache (ecs
->ptid
);
3926 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
3927 remove_status
= remove_breakpoints ();
3929 /* Did we fail to remove breakpoints? If so, try
3930 to set the PC past the bp. (There's at least
3931 one situation in which we can fail to remove
3932 the bp's: On HP-UX's that use ttrace, we can't
3933 change the address space of a vforking child
3934 process until the child exits (well, okay, not
3935 then either :-) or execs. */
3936 if (remove_status
!= 0)
3937 error (_("Cannot step over breakpoint hit in wrong thread"));
3942 /* Only need to require the next event from this
3943 thread in all-stop mode. */
3944 waiton_ptid
= ecs
->ptid
;
3945 infwait_state
= infwait_thread_hop_state
;
3948 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3953 else if (singlestep_breakpoints_inserted_p
)
3955 ecs
->random_signal
= 0;
3959 ecs
->random_signal
= 1;
3961 /* See if something interesting happened to the non-current thread. If
3962 so, then switch to that thread. */
3963 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3966 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
3968 context_switch (ecs
->ptid
);
3970 if (deprecated_context_hook
)
3971 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3974 /* At this point, get hold of the now-current thread's frame. */
3975 frame
= get_current_frame ();
3976 gdbarch
= get_frame_arch (frame
);
3978 if (singlestep_breakpoints_inserted_p
)
3980 /* Pull the single step breakpoints out of the target. */
3981 remove_single_step_breakpoints ();
3982 singlestep_breakpoints_inserted_p
= 0;
3985 if (stepped_after_stopped_by_watchpoint
)
3986 stopped_by_watchpoint
= 0;
3988 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
3990 /* If necessary, step over this watchpoint. We'll be back to display
3992 if (stopped_by_watchpoint
3993 && (target_have_steppable_watchpoint
3994 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
3996 /* At this point, we are stopped at an instruction which has
3997 attempted to write to a piece of memory under control of
3998 a watchpoint. The instruction hasn't actually executed
3999 yet. If we were to evaluate the watchpoint expression
4000 now, we would get the old value, and therefore no change
4001 would seem to have occurred.
4003 In order to make watchpoints work `right', we really need
4004 to complete the memory write, and then evaluate the
4005 watchpoint expression. We do this by single-stepping the
4008 It may not be necessary to disable the watchpoint to stop over
4009 it. For example, the PA can (with some kernel cooperation)
4010 single step over a watchpoint without disabling the watchpoint.
4012 It is far more common to need to disable a watchpoint to step
4013 the inferior over it. If we have non-steppable watchpoints,
4014 we must disable the current watchpoint; it's simplest to
4015 disable all watchpoints and breakpoints. */
4018 if (!target_have_steppable_watchpoint
)
4020 remove_breakpoints ();
4021 /* See comment in resume why we need to stop bypassing signals
4022 while breakpoints have been removed. */
4023 target_pass_signals (0, NULL
);
4026 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
4027 target_resume (ecs
->ptid
, hw_step
, GDB_SIGNAL_0
);
4028 waiton_ptid
= ecs
->ptid
;
4029 if (target_have_steppable_watchpoint
)
4030 infwait_state
= infwait_step_watch_state
;
4032 infwait_state
= infwait_nonstep_watch_state
;
4033 prepare_to_wait (ecs
);
4037 clear_stop_func (ecs
);
4038 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4039 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4040 ecs
->event_thread
->control
.stop_step
= 0;
4041 stop_print_frame
= 1;
4042 ecs
->random_signal
= 0;
4043 stopped_by_random_signal
= 0;
4045 /* Hide inlined functions starting here, unless we just performed stepi or
4046 nexti. After stepi and nexti, always show the innermost frame (not any
4047 inline function call sites). */
4048 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4050 struct address_space
*aspace
=
4051 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4053 /* skip_inline_frames is expensive, so we avoid it if we can
4054 determine that the address is one where functions cannot have
4055 been inlined. This improves performance with inferiors that
4056 load a lot of shared libraries, because the solib event
4057 breakpoint is defined as the address of a function (i.e. not
4058 inline). Note that we have to check the previous PC as well
4059 as the current one to catch cases when we have just
4060 single-stepped off a breakpoint prior to reinstating it.
4061 Note that we're assuming that the code we single-step to is
4062 not inline, but that's not definitive: there's nothing
4063 preventing the event breakpoint function from containing
4064 inlined code, and the single-step ending up there. If the
4065 user had set a breakpoint on that inlined code, the missing
4066 skip_inline_frames call would break things. Fortunately
4067 that's an extremely unlikely scenario. */
4068 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4069 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4070 && ecs
->event_thread
->control
.trap_expected
4071 && pc_at_non_inline_function (aspace
,
4072 ecs
->event_thread
->prev_pc
,
4075 skip_inline_frames (ecs
->ptid
);
4077 /* Re-fetch current thread's frame in case that invalidated
4079 frame
= get_current_frame ();
4080 gdbarch
= get_frame_arch (frame
);
4084 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4085 && ecs
->event_thread
->control
.trap_expected
4086 && gdbarch_single_step_through_delay_p (gdbarch
)
4087 && currently_stepping (ecs
->event_thread
))
4089 /* We're trying to step off a breakpoint. Turns out that we're
4090 also on an instruction that needs to be stepped multiple
4091 times before it's been fully executing. E.g., architectures
4092 with a delay slot. It needs to be stepped twice, once for
4093 the instruction and once for the delay slot. */
4094 int step_through_delay
4095 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4097 if (debug_infrun
&& step_through_delay
)
4098 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4099 if (ecs
->event_thread
->control
.step_range_end
== 0
4100 && step_through_delay
)
4102 /* The user issued a continue when stopped at a breakpoint.
4103 Set up for another trap and get out of here. */
4104 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4108 else if (step_through_delay
)
4110 /* The user issued a step when stopped at a breakpoint.
4111 Maybe we should stop, maybe we should not - the delay
4112 slot *might* correspond to a line of source. In any
4113 case, don't decide that here, just set
4114 ecs->stepping_over_breakpoint, making sure we
4115 single-step again before breakpoints are re-inserted. */
4116 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4120 /* Look at the cause of the stop, and decide what to do.
4121 The alternatives are:
4122 1) stop_stepping and return; to really stop and return to the debugger,
4123 2) keep_going and return to start up again
4124 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
4125 3) set ecs->random_signal to 1, and the decision between 1 and 2
4126 will be made according to the signal handling tables. */
4128 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4129 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4130 || stop_soon
== STOP_QUIETLY_REMOTE
)
4132 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4136 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
4137 stop_print_frame
= 0;
4138 stop_stepping (ecs
);
4142 /* This is originated from start_remote(), start_inferior() and
4143 shared libraries hook functions. */
4144 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
4147 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
4148 stop_stepping (ecs
);
4152 /* This originates from attach_command(). We need to overwrite
4153 the stop_signal here, because some kernels don't ignore a
4154 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4155 See more comments in inferior.h. On the other hand, if we
4156 get a non-SIGSTOP, report it to the user - assume the backend
4157 will handle the SIGSTOP if it should show up later.
4159 Also consider that the attach is complete when we see a
4160 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4161 target extended-remote report it instead of a SIGSTOP
4162 (e.g. gdbserver). We already rely on SIGTRAP being our
4163 signal, so this is no exception.
4165 Also consider that the attach is complete when we see a
4166 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4167 the target to stop all threads of the inferior, in case the
4168 low level attach operation doesn't stop them implicitly. If
4169 they weren't stopped implicitly, then the stub will report a
4170 GDB_SIGNAL_0, meaning: stopped for no particular reason
4171 other than GDB's request. */
4172 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4173 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
4174 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4175 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
4177 stop_stepping (ecs
);
4178 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4182 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4183 handles this event. */
4184 ecs
->event_thread
->control
.stop_bpstat
4185 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4186 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4188 /* Following in case break condition called a
4190 stop_print_frame
= 1;
4192 /* This is where we handle "moribund" watchpoints. Unlike
4193 software breakpoints traps, hardware watchpoint traps are
4194 always distinguishable from random traps. If no high-level
4195 watchpoint is associated with the reported stop data address
4196 anymore, then the bpstat does not explain the signal ---
4197 simply make sure to ignore it if `stopped_by_watchpoint' is
4201 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4202 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
)
4203 && stopped_by_watchpoint
)
4204 fprintf_unfiltered (gdb_stdlog
,
4205 "infrun: no user watchpoint explains "
4206 "watchpoint SIGTRAP, ignoring\n");
4208 /* NOTE: cagney/2003-03-29: These two checks for a random signal
4209 at one stage in the past included checks for an inferior
4210 function call's call dummy's return breakpoint. The original
4211 comment, that went with the test, read:
4213 ``End of a stack dummy. Some systems (e.g. Sony news) give
4214 another signal besides SIGTRAP, so check here as well as
4217 If someone ever tries to get call dummys on a
4218 non-executable stack to work (where the target would stop
4219 with something like a SIGSEGV), then those tests might need
4220 to be re-instated. Given, however, that the tests were only
4221 enabled when momentary breakpoints were not being used, I
4222 suspect that it won't be the case.
4224 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4225 be necessary for call dummies on a non-executable stack on
4228 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4230 = !(bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
)
4231 || stopped_by_watchpoint
4232 || ecs
->event_thread
->control
.trap_expected
4233 || (ecs
->event_thread
->control
.step_range_end
4234 && (ecs
->event_thread
->control
.step_resume_breakpoint
4238 ecs
->random_signal
= !bpstat_explains_signal
4239 (ecs
->event_thread
->control
.stop_bpstat
);
4240 if (!ecs
->random_signal
)
4241 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
4245 /* When we reach this point, we've pretty much decided
4246 that the reason for stopping must've been a random
4247 (unexpected) signal. */
4250 ecs
->random_signal
= 1;
4252 process_event_stop_test
:
4254 /* Re-fetch current thread's frame in case we did a
4255 "goto process_event_stop_test" above. */
4256 frame
= get_current_frame ();
4257 gdbarch
= get_frame_arch (frame
);
4259 /* For the program's own signals, act according to
4260 the signal handling tables. */
4262 if (ecs
->random_signal
)
4264 /* Signal not for debugging purposes. */
4266 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
4269 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n",
4270 ecs
->event_thread
->suspend
.stop_signal
);
4272 stopped_by_random_signal
= 1;
4274 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4277 target_terminal_ours_for_output ();
4278 print_signal_received_reason
4279 (ecs
->event_thread
->suspend
.stop_signal
);
4281 /* Always stop on signals if we're either just gaining control
4282 of the program, or the user explicitly requested this thread
4283 to remain stopped. */
4284 if (stop_soon
!= NO_STOP_QUIETLY
4285 || ecs
->event_thread
->stop_requested
4287 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4289 stop_stepping (ecs
);
4292 /* If not going to stop, give terminal back
4293 if we took it away. */
4295 target_terminal_inferior ();
4297 /* Clear the signal if it should not be passed. */
4298 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4299 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4301 if (ecs
->event_thread
->prev_pc
== stop_pc
4302 && ecs
->event_thread
->control
.trap_expected
4303 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4305 /* We were just starting a new sequence, attempting to
4306 single-step off of a breakpoint and expecting a SIGTRAP.
4307 Instead this signal arrives. This signal will take us out
4308 of the stepping range so GDB needs to remember to, when
4309 the signal handler returns, resume stepping off that
4311 /* To simplify things, "continue" is forced to use the same
4312 code paths as single-step - set a breakpoint at the
4313 signal return address and then, once hit, step off that
4316 fprintf_unfiltered (gdb_stdlog
,
4317 "infrun: signal arrived while stepping over "
4320 insert_hp_step_resume_breakpoint_at_frame (frame
);
4321 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4322 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4323 ecs
->event_thread
->control
.trap_expected
= 0;
4328 if (ecs
->event_thread
->control
.step_range_end
!= 0
4329 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4330 && (ecs
->event_thread
->control
.step_range_start
<= stop_pc
4331 && stop_pc
< ecs
->event_thread
->control
.step_range_end
)
4332 && frame_id_eq (get_stack_frame_id (frame
),
4333 ecs
->event_thread
->control
.step_stack_frame_id
)
4334 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4336 /* The inferior is about to take a signal that will take it
4337 out of the single step range. Set a breakpoint at the
4338 current PC (which is presumably where the signal handler
4339 will eventually return) and then allow the inferior to
4342 Note that this is only needed for a signal delivered
4343 while in the single-step range. Nested signals aren't a
4344 problem as they eventually all return. */
4346 fprintf_unfiltered (gdb_stdlog
,
4347 "infrun: signal may take us out of "
4348 "single-step range\n");
4350 insert_hp_step_resume_breakpoint_at_frame (frame
);
4351 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4352 ecs
->event_thread
->control
.trap_expected
= 0;
4357 /* Note: step_resume_breakpoint may be non-NULL. This occures
4358 when either there's a nested signal, or when there's a
4359 pending signal enabled just as the signal handler returns
4360 (leaving the inferior at the step-resume-breakpoint without
4361 actually executing it). Either way continue until the
4362 breakpoint is really hit. */
4366 /* Handle cases caused by hitting a breakpoint. */
4368 CORE_ADDR jmp_buf_pc
;
4369 struct bpstat_what what
;
4371 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4373 if (what
.call_dummy
)
4375 stop_stack_dummy
= what
.call_dummy
;
4378 /* If we hit an internal event that triggers symbol changes, the
4379 current frame will be invalidated within bpstat_what (e.g.,
4380 if we hit an internal solib event). Re-fetch it. */
4381 frame
= get_current_frame ();
4382 gdbarch
= get_frame_arch (frame
);
4384 switch (what
.main_action
)
4386 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4387 /* If we hit the breakpoint at longjmp while stepping, we
4388 install a momentary breakpoint at the target of the
4392 fprintf_unfiltered (gdb_stdlog
,
4393 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4395 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4397 if (what
.is_longjmp
)
4399 struct value
*arg_value
;
4401 /* If we set the longjmp breakpoint via a SystemTap
4402 probe, then use it to extract the arguments. The
4403 destination PC is the third argument to the
4405 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4407 jmp_buf_pc
= value_as_address (arg_value
);
4408 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4409 || !gdbarch_get_longjmp_target (gdbarch
,
4410 frame
, &jmp_buf_pc
))
4413 fprintf_unfiltered (gdb_stdlog
,
4414 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4415 "(!gdbarch_get_longjmp_target)\n");
4420 /* Insert a breakpoint at resume address. */
4421 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4424 check_exception_resume (ecs
, frame
);
4428 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4430 struct frame_info
*init_frame
;
4432 /* There are several cases to consider.
4434 1. The initiating frame no longer exists. In this case
4435 we must stop, because the exception or longjmp has gone
4438 2. The initiating frame exists, and is the same as the
4439 current frame. We stop, because the exception or
4440 longjmp has been caught.
4442 3. The initiating frame exists and is different from
4443 the current frame. This means the exception or longjmp
4444 has been caught beneath the initiating frame, so keep
4447 4. longjmp breakpoint has been placed just to protect
4448 against stale dummy frames and user is not interested
4449 in stopping around longjmps. */
4452 fprintf_unfiltered (gdb_stdlog
,
4453 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4455 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4457 delete_exception_resume_breakpoint (ecs
->event_thread
);
4459 if (what
.is_longjmp
)
4461 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
->num
);
4463 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4471 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4475 struct frame_id current_id
4476 = get_frame_id (get_current_frame ());
4477 if (frame_id_eq (current_id
,
4478 ecs
->event_thread
->initiating_frame
))
4480 /* Case 2. Fall through. */
4490 /* For Cases 1 and 2, remove the step-resume breakpoint,
4492 delete_step_resume_breakpoint (ecs
->event_thread
);
4494 ecs
->event_thread
->control
.stop_step
= 1;
4495 print_end_stepping_range_reason ();
4496 stop_stepping (ecs
);
4500 case BPSTAT_WHAT_SINGLE
:
4502 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4503 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4504 /* Still need to check other stuff, at least the case where
4505 we are stepping and step out of the right range. */
4508 case BPSTAT_WHAT_STEP_RESUME
:
4510 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4512 delete_step_resume_breakpoint (ecs
->event_thread
);
4513 if (ecs
->event_thread
->control
.proceed_to_finish
4514 && execution_direction
== EXEC_REVERSE
)
4516 struct thread_info
*tp
= ecs
->event_thread
;
4518 /* We are finishing a function in reverse, and just hit
4519 the step-resume breakpoint at the start address of
4520 the function, and we're almost there -- just need to
4521 back up by one more single-step, which should take us
4522 back to the function call. */
4523 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4527 fill_in_stop_func (gdbarch
, ecs
);
4528 if (stop_pc
== ecs
->stop_func_start
4529 && execution_direction
== EXEC_REVERSE
)
4531 /* We are stepping over a function call in reverse, and
4532 just hit the step-resume breakpoint at the start
4533 address of the function. Go back to single-stepping,
4534 which should take us back to the function call. */
4535 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4541 case BPSTAT_WHAT_STOP_NOISY
:
4543 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4544 stop_print_frame
= 1;
4546 /* We are about to nuke the step_resume_breakpointt via the
4547 cleanup chain, so no need to worry about it here. */
4549 stop_stepping (ecs
);
4552 case BPSTAT_WHAT_STOP_SILENT
:
4554 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4555 stop_print_frame
= 0;
4557 /* We are about to nuke the step_resume_breakpoin via the
4558 cleanup chain, so no need to worry about it here. */
4560 stop_stepping (ecs
);
4563 case BPSTAT_WHAT_HP_STEP_RESUME
:
4565 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4567 delete_step_resume_breakpoint (ecs
->event_thread
);
4568 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4570 /* Back when the step-resume breakpoint was inserted, we
4571 were trying to single-step off a breakpoint. Go back
4573 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4574 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4580 case BPSTAT_WHAT_KEEP_CHECKING
:
4585 /* We come here if we hit a breakpoint but should not
4586 stop for it. Possibly we also were stepping
4587 and should stop for that. So fall through and
4588 test for stepping. But, if not stepping,
4591 /* In all-stop mode, if we're currently stepping but have stopped in
4592 some other thread, we need to switch back to the stepped thread. */
4595 struct thread_info
*tp
;
4597 tp
= iterate_over_threads (currently_stepping_or_nexting_callback
,
4601 /* However, if the current thread is blocked on some internal
4602 breakpoint, and we simply need to step over that breakpoint
4603 to get it going again, do that first. */
4604 if ((ecs
->event_thread
->control
.trap_expected
4605 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
4606 || ecs
->event_thread
->stepping_over_breakpoint
)
4612 /* If the stepping thread exited, then don't try to switch
4613 back and resume it, which could fail in several different
4614 ways depending on the target. Instead, just keep going.
4616 We can find a stepping dead thread in the thread list in
4619 - The target supports thread exit events, and when the
4620 target tries to delete the thread from the thread list,
4621 inferior_ptid pointed at the exiting thread. In such
4622 case, calling delete_thread does not really remove the
4623 thread from the list; instead, the thread is left listed,
4624 with 'exited' state.
4626 - The target's debug interface does not support thread
4627 exit events, and so we have no idea whatsoever if the
4628 previously stepping thread is still alive. For that
4629 reason, we need to synchronously query the target
4631 if (is_exited (tp
->ptid
)
4632 || !target_thread_alive (tp
->ptid
))
4635 fprintf_unfiltered (gdb_stdlog
,
4636 "infrun: not switching back to "
4637 "stepped thread, it has vanished\n");
4639 delete_thread (tp
->ptid
);
4644 /* Otherwise, we no longer expect a trap in the current thread.
4645 Clear the trap_expected flag before switching back -- this is
4646 what keep_going would do as well, if we called it. */
4647 ecs
->event_thread
->control
.trap_expected
= 0;
4650 fprintf_unfiltered (gdb_stdlog
,
4651 "infrun: switching back to stepped thread\n");
4653 ecs
->event_thread
= tp
;
4654 ecs
->ptid
= tp
->ptid
;
4655 context_switch (ecs
->ptid
);
4661 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
4664 fprintf_unfiltered (gdb_stdlog
,
4665 "infrun: step-resume breakpoint is inserted\n");
4667 /* Having a step-resume breakpoint overrides anything
4668 else having to do with stepping commands until
4669 that breakpoint is reached. */
4674 if (ecs
->event_thread
->control
.step_range_end
== 0)
4677 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4678 /* Likewise if we aren't even stepping. */
4683 /* Re-fetch current thread's frame in case the code above caused
4684 the frame cache to be re-initialized, making our FRAME variable
4685 a dangling pointer. */
4686 frame
= get_current_frame ();
4687 gdbarch
= get_frame_arch (frame
);
4688 fill_in_stop_func (gdbarch
, ecs
);
4690 /* If stepping through a line, keep going if still within it.
4692 Note that step_range_end is the address of the first instruction
4693 beyond the step range, and NOT the address of the last instruction
4696 Note also that during reverse execution, we may be stepping
4697 through a function epilogue and therefore must detect when
4698 the current-frame changes in the middle of a line. */
4700 if (stop_pc
>= ecs
->event_thread
->control
.step_range_start
4701 && stop_pc
< ecs
->event_thread
->control
.step_range_end
4702 && (execution_direction
!= EXEC_REVERSE
4703 || frame_id_eq (get_frame_id (frame
),
4704 ecs
->event_thread
->control
.step_frame_id
)))
4708 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4709 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
4710 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
4712 /* When stepping backward, stop at beginning of line range
4713 (unless it's the function entry point, in which case
4714 keep going back to the call point). */
4715 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
4716 && stop_pc
!= ecs
->stop_func_start
4717 && execution_direction
== EXEC_REVERSE
)
4719 ecs
->event_thread
->control
.stop_step
= 1;
4720 print_end_stepping_range_reason ();
4721 stop_stepping (ecs
);
4729 /* We stepped out of the stepping range. */
4731 /* If we are stepping at the source level and entered the runtime
4732 loader dynamic symbol resolution code...
4734 EXEC_FORWARD: we keep on single stepping until we exit the run
4735 time loader code and reach the callee's address.
4737 EXEC_REVERSE: we've already executed the callee (backward), and
4738 the runtime loader code is handled just like any other
4739 undebuggable function call. Now we need only keep stepping
4740 backward through the trampoline code, and that's handled further
4741 down, so there is nothing for us to do here. */
4743 if (execution_direction
!= EXEC_REVERSE
4744 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4745 && in_solib_dynsym_resolve_code (stop_pc
))
4747 CORE_ADDR pc_after_resolver
=
4748 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4751 fprintf_unfiltered (gdb_stdlog
,
4752 "infrun: stepped into dynsym resolve code\n");
4754 if (pc_after_resolver
)
4756 /* Set up a step-resume breakpoint at the address
4757 indicated by SKIP_SOLIB_RESOLVER. */
4758 struct symtab_and_line sr_sal
;
4761 sr_sal
.pc
= pc_after_resolver
;
4762 sr_sal
.pspace
= get_frame_program_space (frame
);
4764 insert_step_resume_breakpoint_at_sal (gdbarch
,
4765 sr_sal
, null_frame_id
);
4772 if (ecs
->event_thread
->control
.step_range_end
!= 1
4773 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4774 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4775 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4778 fprintf_unfiltered (gdb_stdlog
,
4779 "infrun: stepped into signal trampoline\n");
4780 /* The inferior, while doing a "step" or "next", has ended up in
4781 a signal trampoline (either by a signal being delivered or by
4782 the signal handler returning). Just single-step until the
4783 inferior leaves the trampoline (either by calling the handler
4789 /* If we're in the return path from a shared library trampoline,
4790 we want to proceed through the trampoline when stepping. */
4791 /* macro/2012-04-25: This needs to come before the subroutine
4792 call check below as on some targets return trampolines look
4793 like subroutine calls (MIPS16 return thunks). */
4794 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4795 stop_pc
, ecs
->stop_func_name
)
4796 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4798 /* Determine where this trampoline returns. */
4799 CORE_ADDR real_stop_pc
;
4801 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4804 fprintf_unfiltered (gdb_stdlog
,
4805 "infrun: stepped into solib return tramp\n");
4807 /* Only proceed through if we know where it's going. */
4810 /* And put the step-breakpoint there and go until there. */
4811 struct symtab_and_line sr_sal
;
4813 init_sal (&sr_sal
); /* initialize to zeroes */
4814 sr_sal
.pc
= real_stop_pc
;
4815 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4816 sr_sal
.pspace
= get_frame_program_space (frame
);
4818 /* Do not specify what the fp should be when we stop since
4819 on some machines the prologue is where the new fp value
4821 insert_step_resume_breakpoint_at_sal (gdbarch
,
4822 sr_sal
, null_frame_id
);
4824 /* Restart without fiddling with the step ranges or
4831 /* Check for subroutine calls. The check for the current frame
4832 equalling the step ID is not necessary - the check of the
4833 previous frame's ID is sufficient - but it is a common case and
4834 cheaper than checking the previous frame's ID.
4836 NOTE: frame_id_eq will never report two invalid frame IDs as
4837 being equal, so to get into this block, both the current and
4838 previous frame must have valid frame IDs. */
4839 /* The outer_frame_id check is a heuristic to detect stepping
4840 through startup code. If we step over an instruction which
4841 sets the stack pointer from an invalid value to a valid value,
4842 we may detect that as a subroutine call from the mythical
4843 "outermost" function. This could be fixed by marking
4844 outermost frames as !stack_p,code_p,special_p. Then the
4845 initial outermost frame, before sp was valid, would
4846 have code_addr == &_start. See the comment in frame_id_eq
4848 if (!frame_id_eq (get_stack_frame_id (frame
),
4849 ecs
->event_thread
->control
.step_stack_frame_id
)
4850 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4851 ecs
->event_thread
->control
.step_stack_frame_id
)
4852 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
4854 || step_start_function
!= find_pc_function (stop_pc
))))
4856 CORE_ADDR real_stop_pc
;
4859 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4861 if ((ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
4862 || ((ecs
->event_thread
->control
.step_range_end
== 1)
4863 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4864 ecs
->stop_func_start
)))
4866 /* I presume that step_over_calls is only 0 when we're
4867 supposed to be stepping at the assembly language level
4868 ("stepi"). Just stop. */
4869 /* Also, maybe we just did a "nexti" inside a prolog, so we
4870 thought it was a subroutine call but it was not. Stop as
4872 /* And this works the same backward as frontward. MVS */
4873 ecs
->event_thread
->control
.stop_step
= 1;
4874 print_end_stepping_range_reason ();
4875 stop_stepping (ecs
);
4879 /* Reverse stepping through solib trampolines. */
4881 if (execution_direction
== EXEC_REVERSE
4882 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
4883 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4884 || (ecs
->stop_func_start
== 0
4885 && in_solib_dynsym_resolve_code (stop_pc
))))
4887 /* Any solib trampoline code can be handled in reverse
4888 by simply continuing to single-step. We have already
4889 executed the solib function (backwards), and a few
4890 steps will take us back through the trampoline to the
4896 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4898 /* We're doing a "next".
4900 Normal (forward) execution: set a breakpoint at the
4901 callee's return address (the address at which the caller
4904 Reverse (backward) execution. set the step-resume
4905 breakpoint at the start of the function that we just
4906 stepped into (backwards), and continue to there. When we
4907 get there, we'll need to single-step back to the caller. */
4909 if (execution_direction
== EXEC_REVERSE
)
4911 /* If we're already at the start of the function, we've either
4912 just stepped backward into a single instruction function,
4913 or stepped back out of a signal handler to the first instruction
4914 of the function. Just keep going, which will single-step back
4916 if (ecs
->stop_func_start
!= stop_pc
)
4918 struct symtab_and_line sr_sal
;
4920 /* Normal function call return (static or dynamic). */
4922 sr_sal
.pc
= ecs
->stop_func_start
;
4923 sr_sal
.pspace
= get_frame_program_space (frame
);
4924 insert_step_resume_breakpoint_at_sal (gdbarch
,
4925 sr_sal
, null_frame_id
);
4929 insert_step_resume_breakpoint_at_caller (frame
);
4935 /* If we are in a function call trampoline (a stub between the
4936 calling routine and the real function), locate the real
4937 function. That's what tells us (a) whether we want to step
4938 into it at all, and (b) what prologue we want to run to the
4939 end of, if we do step into it. */
4940 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
4941 if (real_stop_pc
== 0)
4942 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4943 if (real_stop_pc
!= 0)
4944 ecs
->stop_func_start
= real_stop_pc
;
4946 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
4948 struct symtab_and_line sr_sal
;
4951 sr_sal
.pc
= ecs
->stop_func_start
;
4952 sr_sal
.pspace
= get_frame_program_space (frame
);
4954 insert_step_resume_breakpoint_at_sal (gdbarch
,
4955 sr_sal
, null_frame_id
);
4960 /* If we have line number information for the function we are
4961 thinking of stepping into and the function isn't on the skip
4964 If there are several symtabs at that PC (e.g. with include
4965 files), just want to know whether *any* of them have line
4966 numbers. find_pc_line handles this. */
4968 struct symtab_and_line tmp_sal
;
4970 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
4971 if (tmp_sal
.line
!= 0
4972 && !function_pc_is_marked_for_skip (ecs
->stop_func_start
))
4974 if (execution_direction
== EXEC_REVERSE
)
4975 handle_step_into_function_backward (gdbarch
, ecs
);
4977 handle_step_into_function (gdbarch
, ecs
);
4982 /* If we have no line number and the step-stop-if-no-debug is
4983 set, we stop the step so that the user has a chance to switch
4984 in assembly mode. */
4985 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4986 && step_stop_if_no_debug
)
4988 ecs
->event_thread
->control
.stop_step
= 1;
4989 print_end_stepping_range_reason ();
4990 stop_stepping (ecs
);
4994 if (execution_direction
== EXEC_REVERSE
)
4996 /* If we're already at the start of the function, we've either just
4997 stepped backward into a single instruction function without line
4998 number info, or stepped back out of a signal handler to the first
4999 instruction of the function without line number info. Just keep
5000 going, which will single-step back to the caller. */
5001 if (ecs
->stop_func_start
!= stop_pc
)
5003 /* Set a breakpoint at callee's start address.
5004 From there we can step once and be back in the caller. */
5005 struct symtab_and_line sr_sal
;
5008 sr_sal
.pc
= ecs
->stop_func_start
;
5009 sr_sal
.pspace
= get_frame_program_space (frame
);
5010 insert_step_resume_breakpoint_at_sal (gdbarch
,
5011 sr_sal
, null_frame_id
);
5015 /* Set a breakpoint at callee's return address (the address
5016 at which the caller will resume). */
5017 insert_step_resume_breakpoint_at_caller (frame
);
5023 /* Reverse stepping through solib trampolines. */
5025 if (execution_direction
== EXEC_REVERSE
5026 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5028 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5029 || (ecs
->stop_func_start
== 0
5030 && in_solib_dynsym_resolve_code (stop_pc
)))
5032 /* Any solib trampoline code can be handled in reverse
5033 by simply continuing to single-step. We have already
5034 executed the solib function (backwards), and a few
5035 steps will take us back through the trampoline to the
5040 else if (in_solib_dynsym_resolve_code (stop_pc
))
5042 /* Stepped backward into the solib dynsym resolver.
5043 Set a breakpoint at its start and continue, then
5044 one more step will take us out. */
5045 struct symtab_and_line sr_sal
;
5048 sr_sal
.pc
= ecs
->stop_func_start
;
5049 sr_sal
.pspace
= get_frame_program_space (frame
);
5050 insert_step_resume_breakpoint_at_sal (gdbarch
,
5051 sr_sal
, null_frame_id
);
5057 stop_pc_sal
= find_pc_line (stop_pc
, 0);
5059 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5060 the trampoline processing logic, however, there are some trampolines
5061 that have no names, so we should do trampoline handling first. */
5062 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5063 && ecs
->stop_func_name
== NULL
5064 && stop_pc_sal
.line
== 0)
5067 fprintf_unfiltered (gdb_stdlog
,
5068 "infrun: stepped into undebuggable function\n");
5070 /* The inferior just stepped into, or returned to, an
5071 undebuggable function (where there is no debugging information
5072 and no line number corresponding to the address where the
5073 inferior stopped). Since we want to skip this kind of code,
5074 we keep going until the inferior returns from this
5075 function - unless the user has asked us not to (via
5076 set step-mode) or we no longer know how to get back
5077 to the call site. */
5078 if (step_stop_if_no_debug
5079 || !frame_id_p (frame_unwind_caller_id (frame
)))
5081 /* If we have no line number and the step-stop-if-no-debug
5082 is set, we stop the step so that the user has a chance to
5083 switch in assembly mode. */
5084 ecs
->event_thread
->control
.stop_step
= 1;
5085 print_end_stepping_range_reason ();
5086 stop_stepping (ecs
);
5091 /* Set a breakpoint at callee's return address (the address
5092 at which the caller will resume). */
5093 insert_step_resume_breakpoint_at_caller (frame
);
5099 if (ecs
->event_thread
->control
.step_range_end
== 1)
5101 /* It is stepi or nexti. We always want to stop stepping after
5104 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5105 ecs
->event_thread
->control
.stop_step
= 1;
5106 print_end_stepping_range_reason ();
5107 stop_stepping (ecs
);
5111 if (stop_pc_sal
.line
== 0)
5113 /* We have no line number information. That means to stop
5114 stepping (does this always happen right after one instruction,
5115 when we do "s" in a function with no line numbers,
5116 or can this happen as a result of a return or longjmp?). */
5118 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5119 ecs
->event_thread
->control
.stop_step
= 1;
5120 print_end_stepping_range_reason ();
5121 stop_stepping (ecs
);
5125 /* Look for "calls" to inlined functions, part one. If the inline
5126 frame machinery detected some skipped call sites, we have entered
5127 a new inline function. */
5129 if (frame_id_eq (get_frame_id (get_current_frame ()),
5130 ecs
->event_thread
->control
.step_frame_id
)
5131 && inline_skipped_frames (ecs
->ptid
))
5133 struct symtab_and_line call_sal
;
5136 fprintf_unfiltered (gdb_stdlog
,
5137 "infrun: stepped into inlined function\n");
5139 find_frame_sal (get_current_frame (), &call_sal
);
5141 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5143 /* For "step", we're going to stop. But if the call site
5144 for this inlined function is on the same source line as
5145 we were previously stepping, go down into the function
5146 first. Otherwise stop at the call site. */
5148 if (call_sal
.line
== ecs
->event_thread
->current_line
5149 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5150 step_into_inline_frame (ecs
->ptid
);
5152 ecs
->event_thread
->control
.stop_step
= 1;
5153 print_end_stepping_range_reason ();
5154 stop_stepping (ecs
);
5159 /* For "next", we should stop at the call site if it is on a
5160 different source line. Otherwise continue through the
5161 inlined function. */
5162 if (call_sal
.line
== ecs
->event_thread
->current_line
5163 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5167 ecs
->event_thread
->control
.stop_step
= 1;
5168 print_end_stepping_range_reason ();
5169 stop_stepping (ecs
);
5175 /* Look for "calls" to inlined functions, part two. If we are still
5176 in the same real function we were stepping through, but we have
5177 to go further up to find the exact frame ID, we are stepping
5178 through a more inlined call beyond its call site. */
5180 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5181 && !frame_id_eq (get_frame_id (get_current_frame ()),
5182 ecs
->event_thread
->control
.step_frame_id
)
5183 && stepped_in_from (get_current_frame (),
5184 ecs
->event_thread
->control
.step_frame_id
))
5187 fprintf_unfiltered (gdb_stdlog
,
5188 "infrun: stepping through inlined function\n");
5190 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5194 ecs
->event_thread
->control
.stop_step
= 1;
5195 print_end_stepping_range_reason ();
5196 stop_stepping (ecs
);
5201 if ((stop_pc
== stop_pc_sal
.pc
)
5202 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5203 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5205 /* We are at the start of a different line. So stop. Note that
5206 we don't stop if we step into the middle of a different line.
5207 That is said to make things like for (;;) statements work
5210 fprintf_unfiltered (gdb_stdlog
,
5211 "infrun: stepped to a different line\n");
5212 ecs
->event_thread
->control
.stop_step
= 1;
5213 print_end_stepping_range_reason ();
5214 stop_stepping (ecs
);
5218 /* We aren't done stepping.
5220 Optimize by setting the stepping range to the line.
5221 (We might not be in the original line, but if we entered a
5222 new line in mid-statement, we continue stepping. This makes
5223 things like for(;;) statements work better.) */
5225 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5226 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5227 set_step_info (frame
, stop_pc_sal
);
5230 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5234 /* Is thread TP in the middle of single-stepping? */
5237 currently_stepping (struct thread_info
*tp
)
5239 return ((tp
->control
.step_range_end
5240 && tp
->control
.step_resume_breakpoint
== NULL
)
5241 || tp
->control
.trap_expected
5242 || bpstat_should_step ());
5245 /* Returns true if any thread *but* the one passed in "data" is in the
5246 middle of stepping or of handling a "next". */
5249 currently_stepping_or_nexting_callback (struct thread_info
*tp
, void *data
)
5254 return (tp
->control
.step_range_end
5255 || tp
->control
.trap_expected
);
5258 /* Inferior has stepped into a subroutine call with source code that
5259 we should not step over. Do step to the first line of code in
5263 handle_step_into_function (struct gdbarch
*gdbarch
,
5264 struct execution_control_state
*ecs
)
5267 struct symtab_and_line stop_func_sal
, sr_sal
;
5269 fill_in_stop_func (gdbarch
, ecs
);
5271 s
= find_pc_symtab (stop_pc
);
5272 if (s
&& s
->language
!= language_asm
)
5273 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5274 ecs
->stop_func_start
);
5276 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5277 /* Use the step_resume_break to step until the end of the prologue,
5278 even if that involves jumps (as it seems to on the vax under
5280 /* If the prologue ends in the middle of a source line, continue to
5281 the end of that source line (if it is still within the function).
5282 Otherwise, just go to end of prologue. */
5283 if (stop_func_sal
.end
5284 && stop_func_sal
.pc
!= ecs
->stop_func_start
5285 && stop_func_sal
.end
< ecs
->stop_func_end
)
5286 ecs
->stop_func_start
= stop_func_sal
.end
;
5288 /* Architectures which require breakpoint adjustment might not be able
5289 to place a breakpoint at the computed address. If so, the test
5290 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5291 ecs->stop_func_start to an address at which a breakpoint may be
5292 legitimately placed.
5294 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5295 made, GDB will enter an infinite loop when stepping through
5296 optimized code consisting of VLIW instructions which contain
5297 subinstructions corresponding to different source lines. On
5298 FR-V, it's not permitted to place a breakpoint on any but the
5299 first subinstruction of a VLIW instruction. When a breakpoint is
5300 set, GDB will adjust the breakpoint address to the beginning of
5301 the VLIW instruction. Thus, we need to make the corresponding
5302 adjustment here when computing the stop address. */
5304 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5306 ecs
->stop_func_start
5307 = gdbarch_adjust_breakpoint_address (gdbarch
,
5308 ecs
->stop_func_start
);
5311 if (ecs
->stop_func_start
== stop_pc
)
5313 /* We are already there: stop now. */
5314 ecs
->event_thread
->control
.stop_step
= 1;
5315 print_end_stepping_range_reason ();
5316 stop_stepping (ecs
);
5321 /* Put the step-breakpoint there and go until there. */
5322 init_sal (&sr_sal
); /* initialize to zeroes */
5323 sr_sal
.pc
= ecs
->stop_func_start
;
5324 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5325 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5327 /* Do not specify what the fp should be when we stop since on
5328 some machines the prologue is where the new fp value is
5330 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5332 /* And make sure stepping stops right away then. */
5333 ecs
->event_thread
->control
.step_range_end
5334 = ecs
->event_thread
->control
.step_range_start
;
5339 /* Inferior has stepped backward into a subroutine call with source
5340 code that we should not step over. Do step to the beginning of the
5341 last line of code in it. */
5344 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5345 struct execution_control_state
*ecs
)
5348 struct symtab_and_line stop_func_sal
;
5350 fill_in_stop_func (gdbarch
, ecs
);
5352 s
= find_pc_symtab (stop_pc
);
5353 if (s
&& s
->language
!= language_asm
)
5354 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5355 ecs
->stop_func_start
);
5357 stop_func_sal
= find_pc_line (stop_pc
, 0);
5359 /* OK, we're just going to keep stepping here. */
5360 if (stop_func_sal
.pc
== stop_pc
)
5362 /* We're there already. Just stop stepping now. */
5363 ecs
->event_thread
->control
.stop_step
= 1;
5364 print_end_stepping_range_reason ();
5365 stop_stepping (ecs
);
5369 /* Else just reset the step range and keep going.
5370 No step-resume breakpoint, they don't work for
5371 epilogues, which can have multiple entry paths. */
5372 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5373 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5379 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5380 This is used to both functions and to skip over code. */
5383 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5384 struct symtab_and_line sr_sal
,
5385 struct frame_id sr_id
,
5386 enum bptype sr_type
)
5388 /* There should never be more than one step-resume or longjmp-resume
5389 breakpoint per thread, so we should never be setting a new
5390 step_resume_breakpoint when one is already active. */
5391 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5392 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5395 fprintf_unfiltered (gdb_stdlog
,
5396 "infrun: inserting step-resume breakpoint at %s\n",
5397 paddress (gdbarch
, sr_sal
.pc
));
5399 inferior_thread ()->control
.step_resume_breakpoint
5400 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5404 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5405 struct symtab_and_line sr_sal
,
5406 struct frame_id sr_id
)
5408 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5413 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5414 This is used to skip a potential signal handler.
5416 This is called with the interrupted function's frame. The signal
5417 handler, when it returns, will resume the interrupted function at
5421 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5423 struct symtab_and_line sr_sal
;
5424 struct gdbarch
*gdbarch
;
5426 gdb_assert (return_frame
!= NULL
);
5427 init_sal (&sr_sal
); /* initialize to zeros */
5429 gdbarch
= get_frame_arch (return_frame
);
5430 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5431 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5432 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5434 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5435 get_stack_frame_id (return_frame
),
5439 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5440 is used to skip a function after stepping into it (for "next" or if
5441 the called function has no debugging information).
5443 The current function has almost always been reached by single
5444 stepping a call or return instruction. NEXT_FRAME belongs to the
5445 current function, and the breakpoint will be set at the caller's
5448 This is a separate function rather than reusing
5449 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5450 get_prev_frame, which may stop prematurely (see the implementation
5451 of frame_unwind_caller_id for an example). */
5454 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5456 struct symtab_and_line sr_sal
;
5457 struct gdbarch
*gdbarch
;
5459 /* We shouldn't have gotten here if we don't know where the call site
5461 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5463 init_sal (&sr_sal
); /* initialize to zeros */
5465 gdbarch
= frame_unwind_caller_arch (next_frame
);
5466 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5467 frame_unwind_caller_pc (next_frame
));
5468 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5469 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5471 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5472 frame_unwind_caller_id (next_frame
));
5475 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5476 new breakpoint at the target of a jmp_buf. The handling of
5477 longjmp-resume uses the same mechanisms used for handling
5478 "step-resume" breakpoints. */
5481 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5483 /* There should never be more than one longjmp-resume breakpoint per
5484 thread, so we should never be setting a new
5485 longjmp_resume_breakpoint when one is already active. */
5486 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
5489 fprintf_unfiltered (gdb_stdlog
,
5490 "infrun: inserting longjmp-resume breakpoint at %s\n",
5491 paddress (gdbarch
, pc
));
5493 inferior_thread ()->control
.exception_resume_breakpoint
=
5494 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
5497 /* Insert an exception resume breakpoint. TP is the thread throwing
5498 the exception. The block B is the block of the unwinder debug hook
5499 function. FRAME is the frame corresponding to the call to this
5500 function. SYM is the symbol of the function argument holding the
5501 target PC of the exception. */
5504 insert_exception_resume_breakpoint (struct thread_info
*tp
,
5506 struct frame_info
*frame
,
5509 volatile struct gdb_exception e
;
5511 /* We want to ignore errors here. */
5512 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5514 struct symbol
*vsym
;
5515 struct value
*value
;
5517 struct breakpoint
*bp
;
5519 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
5520 value
= read_var_value (vsym
, frame
);
5521 /* If the value was optimized out, revert to the old behavior. */
5522 if (! value_optimized_out (value
))
5524 handler
= value_as_address (value
);
5527 fprintf_unfiltered (gdb_stdlog
,
5528 "infrun: exception resume at %lx\n",
5529 (unsigned long) handler
);
5531 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5532 handler
, bp_exception_resume
);
5534 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5537 bp
->thread
= tp
->num
;
5538 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5543 /* A helper for check_exception_resume that sets an
5544 exception-breakpoint based on a SystemTap probe. */
5547 insert_exception_resume_from_probe (struct thread_info
*tp
,
5548 const struct probe
*probe
,
5549 struct frame_info
*frame
)
5551 struct value
*arg_value
;
5553 struct breakpoint
*bp
;
5555 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
5559 handler
= value_as_address (arg_value
);
5562 fprintf_unfiltered (gdb_stdlog
,
5563 "infrun: exception resume at %s\n",
5564 paddress (get_objfile_arch (probe
->objfile
),
5567 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5568 handler
, bp_exception_resume
);
5569 bp
->thread
= tp
->num
;
5570 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5573 /* This is called when an exception has been intercepted. Check to
5574 see whether the exception's destination is of interest, and if so,
5575 set an exception resume breakpoint there. */
5578 check_exception_resume (struct execution_control_state
*ecs
,
5579 struct frame_info
*frame
)
5581 volatile struct gdb_exception e
;
5582 const struct probe
*probe
;
5583 struct symbol
*func
;
5585 /* First see if this exception unwinding breakpoint was set via a
5586 SystemTap probe point. If so, the probe has two arguments: the
5587 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5588 set a breakpoint there. */
5589 probe
= find_probe_by_pc (get_frame_pc (frame
));
5592 insert_exception_resume_from_probe (ecs
->event_thread
, probe
, frame
);
5596 func
= get_frame_function (frame
);
5600 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5603 struct block_iterator iter
;
5607 /* The exception breakpoint is a thread-specific breakpoint on
5608 the unwinder's debug hook, declared as:
5610 void _Unwind_DebugHook (void *cfa, void *handler);
5612 The CFA argument indicates the frame to which control is
5613 about to be transferred. HANDLER is the destination PC.
5615 We ignore the CFA and set a temporary breakpoint at HANDLER.
5616 This is not extremely efficient but it avoids issues in gdb
5617 with computing the DWARF CFA, and it also works even in weird
5618 cases such as throwing an exception from inside a signal
5621 b
= SYMBOL_BLOCK_VALUE (func
);
5622 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5624 if (!SYMBOL_IS_ARGUMENT (sym
))
5631 insert_exception_resume_breakpoint (ecs
->event_thread
,
5640 stop_stepping (struct execution_control_state
*ecs
)
5643 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
5645 /* Let callers know we don't want to wait for the inferior anymore. */
5646 ecs
->wait_some_more
= 0;
5649 /* This function handles various cases where we need to continue
5650 waiting for the inferior. */
5651 /* (Used to be the keep_going: label in the old wait_for_inferior). */
5654 keep_going (struct execution_control_state
*ecs
)
5656 /* Make sure normal_stop is called if we get a QUIT handled before
5658 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
5660 /* Save the pc before execution, to compare with pc after stop. */
5661 ecs
->event_thread
->prev_pc
5662 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5664 /* If we did not do break;, it means we should keep running the
5665 inferior and not return to debugger. */
5667 if (ecs
->event_thread
->control
.trap_expected
5668 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5670 /* We took a signal (which we are supposed to pass through to
5671 the inferior, else we'd not get here) and we haven't yet
5672 gotten our trap. Simply continue. */
5674 discard_cleanups (old_cleanups
);
5675 resume (currently_stepping (ecs
->event_thread
),
5676 ecs
->event_thread
->suspend
.stop_signal
);
5680 /* Either the trap was not expected, but we are continuing
5681 anyway (the user asked that this signal be passed to the
5684 The signal was SIGTRAP, e.g. it was our signal, but we
5685 decided we should resume from it.
5687 We're going to run this baby now!
5689 Note that insert_breakpoints won't try to re-insert
5690 already inserted breakpoints. Therefore, we don't
5691 care if breakpoints were already inserted, or not. */
5693 if (ecs
->event_thread
->stepping_over_breakpoint
)
5695 struct regcache
*thread_regcache
= get_thread_regcache (ecs
->ptid
);
5697 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
5698 /* Since we can't do a displaced step, we have to remove
5699 the breakpoint while we step it. To keep things
5700 simple, we remove them all. */
5701 remove_breakpoints ();
5705 volatile struct gdb_exception e
;
5707 /* Stop stepping when inserting breakpoints
5709 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5711 insert_breakpoints ();
5715 exception_print (gdb_stderr
, e
);
5716 stop_stepping (ecs
);
5721 ecs
->event_thread
->control
.trap_expected
5722 = ecs
->event_thread
->stepping_over_breakpoint
;
5724 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5725 specifies that such a signal should be delivered to the
5728 Typically, this would occure when a user is debugging a
5729 target monitor on a simulator: the target monitor sets a
5730 breakpoint; the simulator encounters this break-point and
5731 halts the simulation handing control to GDB; GDB, noteing
5732 that the break-point isn't valid, returns control back to the
5733 simulator; the simulator then delivers the hardware
5734 equivalent of a SIGNAL_TRAP to the program being debugged. */
5736 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5737 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5738 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5740 discard_cleanups (old_cleanups
);
5741 resume (currently_stepping (ecs
->event_thread
),
5742 ecs
->event_thread
->suspend
.stop_signal
);
5745 prepare_to_wait (ecs
);
5748 /* This function normally comes after a resume, before
5749 handle_inferior_event exits. It takes care of any last bits of
5750 housekeeping, and sets the all-important wait_some_more flag. */
5753 prepare_to_wait (struct execution_control_state
*ecs
)
5756 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
5758 /* This is the old end of the while loop. Let everybody know we
5759 want to wait for the inferior some more and get called again
5761 ecs
->wait_some_more
= 1;
5764 /* Several print_*_reason functions to print why the inferior has stopped.
5765 We always print something when the inferior exits, or receives a signal.
5766 The rest of the cases are dealt with later on in normal_stop and
5767 print_it_typical. Ideally there should be a call to one of these
5768 print_*_reason functions functions from handle_inferior_event each time
5769 stop_stepping is called. */
5771 /* Print why the inferior has stopped.
5772 We are done with a step/next/si/ni command, print why the inferior has
5773 stopped. For now print nothing. Print a message only if not in the middle
5774 of doing a "step n" operation for n > 1. */
5777 print_end_stepping_range_reason (void)
5779 if ((!inferior_thread ()->step_multi
5780 || !inferior_thread ()->control
.stop_step
)
5781 && ui_out_is_mi_like_p (current_uiout
))
5782 ui_out_field_string (current_uiout
, "reason",
5783 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
5786 /* The inferior was terminated by a signal, print why it stopped. */
5789 print_signal_exited_reason (enum gdb_signal siggnal
)
5791 struct ui_out
*uiout
= current_uiout
;
5793 annotate_signalled ();
5794 if (ui_out_is_mi_like_p (uiout
))
5796 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
5797 ui_out_text (uiout
, "\nProgram terminated with signal ");
5798 annotate_signal_name ();
5799 ui_out_field_string (uiout
, "signal-name",
5800 gdb_signal_to_name (siggnal
));
5801 annotate_signal_name_end ();
5802 ui_out_text (uiout
, ", ");
5803 annotate_signal_string ();
5804 ui_out_field_string (uiout
, "signal-meaning",
5805 gdb_signal_to_string (siggnal
));
5806 annotate_signal_string_end ();
5807 ui_out_text (uiout
, ".\n");
5808 ui_out_text (uiout
, "The program no longer exists.\n");
5811 /* The inferior program is finished, print why it stopped. */
5814 print_exited_reason (int exitstatus
)
5816 struct inferior
*inf
= current_inferior ();
5817 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
5818 struct ui_out
*uiout
= current_uiout
;
5820 annotate_exited (exitstatus
);
5823 if (ui_out_is_mi_like_p (uiout
))
5824 ui_out_field_string (uiout
, "reason",
5825 async_reason_lookup (EXEC_ASYNC_EXITED
));
5826 ui_out_text (uiout
, "[Inferior ");
5827 ui_out_text (uiout
, plongest (inf
->num
));
5828 ui_out_text (uiout
, " (");
5829 ui_out_text (uiout
, pidstr
);
5830 ui_out_text (uiout
, ") exited with code ");
5831 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
5832 ui_out_text (uiout
, "]\n");
5836 if (ui_out_is_mi_like_p (uiout
))
5838 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
5839 ui_out_text (uiout
, "[Inferior ");
5840 ui_out_text (uiout
, plongest (inf
->num
));
5841 ui_out_text (uiout
, " (");
5842 ui_out_text (uiout
, pidstr
);
5843 ui_out_text (uiout
, ") exited normally]\n");
5845 /* Support the --return-child-result option. */
5846 return_child_result_value
= exitstatus
;
5849 /* Signal received, print why the inferior has stopped. The signal table
5850 tells us to print about it. */
5853 print_signal_received_reason (enum gdb_signal siggnal
)
5855 struct ui_out
*uiout
= current_uiout
;
5859 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
5861 struct thread_info
*t
= inferior_thread ();
5863 ui_out_text (uiout
, "\n[");
5864 ui_out_field_string (uiout
, "thread-name",
5865 target_pid_to_str (t
->ptid
));
5866 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
5867 ui_out_text (uiout
, " stopped");
5871 ui_out_text (uiout
, "\nProgram received signal ");
5872 annotate_signal_name ();
5873 if (ui_out_is_mi_like_p (uiout
))
5875 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
5876 ui_out_field_string (uiout
, "signal-name",
5877 gdb_signal_to_name (siggnal
));
5878 annotate_signal_name_end ();
5879 ui_out_text (uiout
, ", ");
5880 annotate_signal_string ();
5881 ui_out_field_string (uiout
, "signal-meaning",
5882 gdb_signal_to_string (siggnal
));
5883 annotate_signal_string_end ();
5885 ui_out_text (uiout
, ".\n");
5888 /* Reverse execution: target ran out of history info, print why the inferior
5892 print_no_history_reason (void)
5894 ui_out_text (current_uiout
, "\nNo more reverse-execution history.\n");
5897 /* Here to return control to GDB when the inferior stops for real.
5898 Print appropriate messages, remove breakpoints, give terminal our modes.
5900 STOP_PRINT_FRAME nonzero means print the executing frame
5901 (pc, function, args, file, line number and line text).
5902 BREAKPOINTS_FAILED nonzero means stop was due to error
5903 attempting to insert breakpoints. */
5908 struct target_waitstatus last
;
5910 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
5912 get_last_target_status (&last_ptid
, &last
);
5914 /* If an exception is thrown from this point on, make sure to
5915 propagate GDB's knowledge of the executing state to the
5916 frontend/user running state. A QUIT is an easy exception to see
5917 here, so do this before any filtered output. */
5919 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
5920 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
5921 && last
.kind
!= TARGET_WAITKIND_EXITED
5922 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
5923 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
5925 /* In non-stop mode, we don't want GDB to switch threads behind the
5926 user's back, to avoid races where the user is typing a command to
5927 apply to thread x, but GDB switches to thread y before the user
5928 finishes entering the command. */
5930 /* As with the notification of thread events, we want to delay
5931 notifying the user that we've switched thread context until
5932 the inferior actually stops.
5934 There's no point in saying anything if the inferior has exited.
5935 Note that SIGNALLED here means "exited with a signal", not
5936 "received a signal". */
5938 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
5939 && target_has_execution
5940 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5941 && last
.kind
!= TARGET_WAITKIND_EXITED
5942 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
5944 target_terminal_ours_for_output ();
5945 printf_filtered (_("[Switching to %s]\n"),
5946 target_pid_to_str (inferior_ptid
));
5947 annotate_thread_changed ();
5948 previous_inferior_ptid
= inferior_ptid
;
5951 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
5953 gdb_assert (sync_execution
|| !target_can_async_p ());
5955 target_terminal_ours_for_output ();
5956 printf_filtered (_("No unwaited-for children left.\n"));
5959 if (!breakpoints_always_inserted_mode () && target_has_execution
)
5961 if (remove_breakpoints ())
5963 target_terminal_ours_for_output ();
5964 printf_filtered (_("Cannot remove breakpoints because "
5965 "program is no longer writable.\nFurther "
5966 "execution is probably impossible.\n"));
5970 /* If an auto-display called a function and that got a signal,
5971 delete that auto-display to avoid an infinite recursion. */
5973 if (stopped_by_random_signal
)
5974 disable_current_display ();
5976 /* Don't print a message if in the middle of doing a "step n"
5977 operation for n > 1 */
5978 if (target_has_execution
5979 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5980 && last
.kind
!= TARGET_WAITKIND_EXITED
5981 && inferior_thread ()->step_multi
5982 && inferior_thread ()->control
.stop_step
)
5985 target_terminal_ours ();
5986 async_enable_stdin ();
5988 /* Set the current source location. This will also happen if we
5989 display the frame below, but the current SAL will be incorrect
5990 during a user hook-stop function. */
5991 if (has_stack_frames () && !stop_stack_dummy
)
5992 set_current_sal_from_frame (get_current_frame (), 1);
5994 /* Let the user/frontend see the threads as stopped. */
5995 do_cleanups (old_chain
);
5997 /* Look up the hook_stop and run it (CLI internally handles problem
5998 of stop_command's pre-hook not existing). */
6000 catch_errors (hook_stop_stub
, stop_command
,
6001 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6003 if (!has_stack_frames ())
6006 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6007 || last
.kind
== TARGET_WAITKIND_EXITED
)
6010 /* Select innermost stack frame - i.e., current frame is frame 0,
6011 and current location is based on that.
6012 Don't do this on return from a stack dummy routine,
6013 or if the program has exited. */
6015 if (!stop_stack_dummy
)
6017 select_frame (get_current_frame ());
6019 /* Print current location without a level number, if
6020 we have changed functions or hit a breakpoint.
6021 Print source line if we have one.
6022 bpstat_print() contains the logic deciding in detail
6023 what to print, based on the event(s) that just occurred. */
6025 /* If --batch-silent is enabled then there's no need to print the current
6026 source location, and to try risks causing an error message about
6027 missing source files. */
6028 if (stop_print_frame
&& !batch_silent
)
6032 int do_frame_printing
= 1;
6033 struct thread_info
*tp
= inferior_thread ();
6035 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, last
.kind
);
6039 /* FIXME: cagney/2002-12-01: Given that a frame ID does
6040 (or should) carry around the function and does (or
6041 should) use that when doing a frame comparison. */
6042 if (tp
->control
.stop_step
6043 && frame_id_eq (tp
->control
.step_frame_id
,
6044 get_frame_id (get_current_frame ()))
6045 && step_start_function
== find_pc_function (stop_pc
))
6046 source_flag
= SRC_LINE
; /* Finished step, just
6047 print source line. */
6049 source_flag
= SRC_AND_LOC
; /* Print location and
6052 case PRINT_SRC_AND_LOC
:
6053 source_flag
= SRC_AND_LOC
; /* Print location and
6056 case PRINT_SRC_ONLY
:
6057 source_flag
= SRC_LINE
;
6060 source_flag
= SRC_LINE
; /* something bogus */
6061 do_frame_printing
= 0;
6064 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6067 /* The behavior of this routine with respect to the source
6069 SRC_LINE: Print only source line
6070 LOCATION: Print only location
6071 SRC_AND_LOC: Print location and source line. */
6072 if (do_frame_printing
)
6073 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
6075 /* Display the auto-display expressions. */
6080 /* Save the function value return registers, if we care.
6081 We might be about to restore their previous contents. */
6082 if (inferior_thread ()->control
.proceed_to_finish
6083 && execution_direction
!= EXEC_REVERSE
)
6085 /* This should not be necessary. */
6087 regcache_xfree (stop_registers
);
6089 /* NB: The copy goes through to the target picking up the value of
6090 all the registers. */
6091 stop_registers
= regcache_dup (get_current_regcache ());
6094 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6096 /* Pop the empty frame that contains the stack dummy.
6097 This also restores inferior state prior to the call
6098 (struct infcall_suspend_state). */
6099 struct frame_info
*frame
= get_current_frame ();
6101 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6103 /* frame_pop() calls reinit_frame_cache as the last thing it
6104 does which means there's currently no selected frame. We
6105 don't need to re-establish a selected frame if the dummy call
6106 returns normally, that will be done by
6107 restore_infcall_control_state. However, we do have to handle
6108 the case where the dummy call is returning after being
6109 stopped (e.g. the dummy call previously hit a breakpoint).
6110 We can't know which case we have so just always re-establish
6111 a selected frame here. */
6112 select_frame (get_current_frame ());
6116 annotate_stopped ();
6118 /* Suppress the stop observer if we're in the middle of:
6120 - a step n (n > 1), as there still more steps to be done.
6122 - a "finish" command, as the observer will be called in
6123 finish_command_continuation, so it can include the inferior
6124 function's return value.
6126 - calling an inferior function, as we pretend we inferior didn't
6127 run at all. The return value of the call is handled by the
6128 expression evaluator, through call_function_by_hand. */
6130 if (!target_has_execution
6131 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6132 || last
.kind
== TARGET_WAITKIND_EXITED
6133 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6134 || (!(inferior_thread ()->step_multi
6135 && inferior_thread ()->control
.stop_step
)
6136 && !(inferior_thread ()->control
.stop_bpstat
6137 && inferior_thread ()->control
.proceed_to_finish
)
6138 && !inferior_thread ()->control
.in_infcall
))
6140 if (!ptid_equal (inferior_ptid
, null_ptid
))
6141 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6144 observer_notify_normal_stop (NULL
, stop_print_frame
);
6147 if (target_has_execution
)
6149 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6150 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6151 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6152 Delete any breakpoint that is to be deleted at the next stop. */
6153 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6156 /* Try to get rid of automatically added inferiors that are no
6157 longer needed. Keeping those around slows down things linearly.
6158 Note that this never removes the current inferior. */
6163 hook_stop_stub (void *cmd
)
6165 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6170 signal_stop_state (int signo
)
6172 return signal_stop
[signo
];
6176 signal_print_state (int signo
)
6178 return signal_print
[signo
];
6182 signal_pass_state (int signo
)
6184 return signal_program
[signo
];
6188 signal_cache_update (int signo
)
6192 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6193 signal_cache_update (signo
);
6198 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6199 && signal_print
[signo
] == 0
6200 && signal_program
[signo
] == 1);
6204 signal_stop_update (int signo
, int state
)
6206 int ret
= signal_stop
[signo
];
6208 signal_stop
[signo
] = state
;
6209 signal_cache_update (signo
);
6214 signal_print_update (int signo
, int state
)
6216 int ret
= signal_print
[signo
];
6218 signal_print
[signo
] = state
;
6219 signal_cache_update (signo
);
6224 signal_pass_update (int signo
, int state
)
6226 int ret
= signal_program
[signo
];
6228 signal_program
[signo
] = state
;
6229 signal_cache_update (signo
);
6234 sig_print_header (void)
6236 printf_filtered (_("Signal Stop\tPrint\tPass "
6237 "to program\tDescription\n"));
6241 sig_print_info (enum gdb_signal oursig
)
6243 const char *name
= gdb_signal_to_name (oursig
);
6244 int name_padding
= 13 - strlen (name
);
6246 if (name_padding
<= 0)
6249 printf_filtered ("%s", name
);
6250 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6251 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6252 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6253 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6254 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6257 /* Specify how various signals in the inferior should be handled. */
6260 handle_command (char *args
, int from_tty
)
6263 int digits
, wordlen
;
6264 int sigfirst
, signum
, siglast
;
6265 enum gdb_signal oursig
;
6268 unsigned char *sigs
;
6269 struct cleanup
*old_chain
;
6273 error_no_arg (_("signal to handle"));
6276 /* Allocate and zero an array of flags for which signals to handle. */
6278 nsigs
= (int) GDB_SIGNAL_LAST
;
6279 sigs
= (unsigned char *) alloca (nsigs
);
6280 memset (sigs
, 0, nsigs
);
6282 /* Break the command line up into args. */
6284 argv
= gdb_buildargv (args
);
6285 old_chain
= make_cleanup_freeargv (argv
);
6287 /* Walk through the args, looking for signal oursigs, signal names, and
6288 actions. Signal numbers and signal names may be interspersed with
6289 actions, with the actions being performed for all signals cumulatively
6290 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6292 while (*argv
!= NULL
)
6294 wordlen
= strlen (*argv
);
6295 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6299 sigfirst
= siglast
= -1;
6301 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6303 /* Apply action to all signals except those used by the
6304 debugger. Silently skip those. */
6307 siglast
= nsigs
- 1;
6309 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6311 SET_SIGS (nsigs
, sigs
, signal_stop
);
6312 SET_SIGS (nsigs
, sigs
, signal_print
);
6314 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6316 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6318 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6320 SET_SIGS (nsigs
, sigs
, signal_print
);
6322 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6324 SET_SIGS (nsigs
, sigs
, signal_program
);
6326 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6328 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6330 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6332 SET_SIGS (nsigs
, sigs
, signal_program
);
6334 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6336 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6337 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6339 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6341 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6343 else if (digits
> 0)
6345 /* It is numeric. The numeric signal refers to our own
6346 internal signal numbering from target.h, not to host/target
6347 signal number. This is a feature; users really should be
6348 using symbolic names anyway, and the common ones like
6349 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6351 sigfirst
= siglast
= (int)
6352 gdb_signal_from_command (atoi (*argv
));
6353 if ((*argv
)[digits
] == '-')
6356 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6358 if (sigfirst
> siglast
)
6360 /* Bet he didn't figure we'd think of this case... */
6368 oursig
= gdb_signal_from_name (*argv
);
6369 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6371 sigfirst
= siglast
= (int) oursig
;
6375 /* Not a number and not a recognized flag word => complain. */
6376 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6380 /* If any signal numbers or symbol names were found, set flags for
6381 which signals to apply actions to. */
6383 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6385 switch ((enum gdb_signal
) signum
)
6387 case GDB_SIGNAL_TRAP
:
6388 case GDB_SIGNAL_INT
:
6389 if (!allsigs
&& !sigs
[signum
])
6391 if (query (_("%s is used by the debugger.\n\
6392 Are you sure you want to change it? "),
6393 gdb_signal_to_name ((enum gdb_signal
) signum
)))
6399 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6400 gdb_flush (gdb_stdout
);
6405 case GDB_SIGNAL_DEFAULT
:
6406 case GDB_SIGNAL_UNKNOWN
:
6407 /* Make sure that "all" doesn't print these. */
6418 for (signum
= 0; signum
< nsigs
; signum
++)
6421 signal_cache_update (-1);
6422 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6423 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
6427 /* Show the results. */
6428 sig_print_header ();
6429 for (; signum
< nsigs
; signum
++)
6431 sig_print_info (signum
);
6437 do_cleanups (old_chain
);
6440 /* Complete the "handle" command. */
6442 static VEC (char_ptr
) *
6443 handle_completer (struct cmd_list_element
*ignore
,
6444 char *text
, char *word
)
6446 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
6447 static const char * const keywords
[] =
6461 vec_signals
= signal_completer (ignore
, text
, word
);
6462 vec_keywords
= complete_on_enum (keywords
, word
, word
);
6464 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
6465 VEC_free (char_ptr
, vec_signals
);
6466 VEC_free (char_ptr
, vec_keywords
);
6471 xdb_handle_command (char *args
, int from_tty
)
6474 struct cleanup
*old_chain
;
6477 error_no_arg (_("xdb command"));
6479 /* Break the command line up into args. */
6481 argv
= gdb_buildargv (args
);
6482 old_chain
= make_cleanup_freeargv (argv
);
6483 if (argv
[1] != (char *) NULL
)
6488 bufLen
= strlen (argv
[0]) + 20;
6489 argBuf
= (char *) xmalloc (bufLen
);
6493 enum gdb_signal oursig
;
6495 oursig
= gdb_signal_from_name (argv
[0]);
6496 memset (argBuf
, 0, bufLen
);
6497 if (strcmp (argv
[1], "Q") == 0)
6498 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6501 if (strcmp (argv
[1], "s") == 0)
6503 if (!signal_stop
[oursig
])
6504 sprintf (argBuf
, "%s %s", argv
[0], "stop");
6506 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
6508 else if (strcmp (argv
[1], "i") == 0)
6510 if (!signal_program
[oursig
])
6511 sprintf (argBuf
, "%s %s", argv
[0], "pass");
6513 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
6515 else if (strcmp (argv
[1], "r") == 0)
6517 if (!signal_print
[oursig
])
6518 sprintf (argBuf
, "%s %s", argv
[0], "print");
6520 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6526 handle_command (argBuf
, from_tty
);
6528 printf_filtered (_("Invalid signal handling flag.\n"));
6533 do_cleanups (old_chain
);
6537 gdb_signal_from_command (int num
)
6539 if (num
>= 1 && num
<= 15)
6540 return (enum gdb_signal
) num
;
6541 error (_("Only signals 1-15 are valid as numeric signals.\n\
6542 Use \"info signals\" for a list of symbolic signals."));
6545 /* Print current contents of the tables set by the handle command.
6546 It is possible we should just be printing signals actually used
6547 by the current target (but for things to work right when switching
6548 targets, all signals should be in the signal tables). */
6551 signals_info (char *signum_exp
, int from_tty
)
6553 enum gdb_signal oursig
;
6555 sig_print_header ();
6559 /* First see if this is a symbol name. */
6560 oursig
= gdb_signal_from_name (signum_exp
);
6561 if (oursig
== GDB_SIGNAL_UNKNOWN
)
6563 /* No, try numeric. */
6565 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
6567 sig_print_info (oursig
);
6571 printf_filtered ("\n");
6572 /* These ugly casts brought to you by the native VAX compiler. */
6573 for (oursig
= GDB_SIGNAL_FIRST
;
6574 (int) oursig
< (int) GDB_SIGNAL_LAST
;
6575 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
6579 if (oursig
!= GDB_SIGNAL_UNKNOWN
6580 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
6581 sig_print_info (oursig
);
6584 printf_filtered (_("\nUse the \"handle\" command "
6585 "to change these tables.\n"));
6588 /* Check if it makes sense to read $_siginfo from the current thread
6589 at this point. If not, throw an error. */
6592 validate_siginfo_access (void)
6594 /* No current inferior, no siginfo. */
6595 if (ptid_equal (inferior_ptid
, null_ptid
))
6596 error (_("No thread selected."));
6598 /* Don't try to read from a dead thread. */
6599 if (is_exited (inferior_ptid
))
6600 error (_("The current thread has terminated"));
6602 /* ... or from a spinning thread. */
6603 if (is_running (inferior_ptid
))
6604 error (_("Selected thread is running."));
6607 /* The $_siginfo convenience variable is a bit special. We don't know
6608 for sure the type of the value until we actually have a chance to
6609 fetch the data. The type can change depending on gdbarch, so it is
6610 also dependent on which thread you have selected.
6612 1. making $_siginfo be an internalvar that creates a new value on
6615 2. making the value of $_siginfo be an lval_computed value. */
6617 /* This function implements the lval_computed support for reading a
6621 siginfo_value_read (struct value
*v
)
6623 LONGEST transferred
;
6625 validate_siginfo_access ();
6628 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
6630 value_contents_all_raw (v
),
6632 TYPE_LENGTH (value_type (v
)));
6634 if (transferred
!= TYPE_LENGTH (value_type (v
)))
6635 error (_("Unable to read siginfo"));
6638 /* This function implements the lval_computed support for writing a
6642 siginfo_value_write (struct value
*v
, struct value
*fromval
)
6644 LONGEST transferred
;
6646 validate_siginfo_access ();
6648 transferred
= target_write (¤t_target
,
6649 TARGET_OBJECT_SIGNAL_INFO
,
6651 value_contents_all_raw (fromval
),
6653 TYPE_LENGTH (value_type (fromval
)));
6655 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
6656 error (_("Unable to write siginfo"));
6659 static const struct lval_funcs siginfo_value_funcs
=
6665 /* Return a new value with the correct type for the siginfo object of
6666 the current thread using architecture GDBARCH. Return a void value
6667 if there's no object available. */
6669 static struct value
*
6670 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
6673 if (target_has_stack
6674 && !ptid_equal (inferior_ptid
, null_ptid
)
6675 && gdbarch_get_siginfo_type_p (gdbarch
))
6677 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6679 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
6682 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
6686 /* infcall_suspend_state contains state about the program itself like its
6687 registers and any signal it received when it last stopped.
6688 This state must be restored regardless of how the inferior function call
6689 ends (either successfully, or after it hits a breakpoint or signal)
6690 if the program is to properly continue where it left off. */
6692 struct infcall_suspend_state
6694 struct thread_suspend_state thread_suspend
;
6695 #if 0 /* Currently unused and empty structures are not valid C. */
6696 struct inferior_suspend_state inferior_suspend
;
6701 struct regcache
*registers
;
6703 /* Format of SIGINFO_DATA or NULL if it is not present. */
6704 struct gdbarch
*siginfo_gdbarch
;
6706 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6707 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6708 content would be invalid. */
6709 gdb_byte
*siginfo_data
;
6712 struct infcall_suspend_state
*
6713 save_infcall_suspend_state (void)
6715 struct infcall_suspend_state
*inf_state
;
6716 struct thread_info
*tp
= inferior_thread ();
6717 struct inferior
*inf
= current_inferior ();
6718 struct regcache
*regcache
= get_current_regcache ();
6719 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6720 gdb_byte
*siginfo_data
= NULL
;
6722 if (gdbarch_get_siginfo_type_p (gdbarch
))
6724 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6725 size_t len
= TYPE_LENGTH (type
);
6726 struct cleanup
*back_to
;
6728 siginfo_data
= xmalloc (len
);
6729 back_to
= make_cleanup (xfree
, siginfo_data
);
6731 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6732 siginfo_data
, 0, len
) == len
)
6733 discard_cleanups (back_to
);
6736 /* Errors ignored. */
6737 do_cleanups (back_to
);
6738 siginfo_data
= NULL
;
6742 inf_state
= XZALLOC (struct infcall_suspend_state
);
6746 inf_state
->siginfo_gdbarch
= gdbarch
;
6747 inf_state
->siginfo_data
= siginfo_data
;
6750 inf_state
->thread_suspend
= tp
->suspend
;
6751 #if 0 /* Currently unused and empty structures are not valid C. */
6752 inf_state
->inferior_suspend
= inf
->suspend
;
6755 /* run_inferior_call will not use the signal due to its `proceed' call with
6756 GDB_SIGNAL_0 anyway. */
6757 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6759 inf_state
->stop_pc
= stop_pc
;
6761 inf_state
->registers
= regcache_dup (regcache
);
6766 /* Restore inferior session state to INF_STATE. */
6769 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6771 struct thread_info
*tp
= inferior_thread ();
6772 struct inferior
*inf
= current_inferior ();
6773 struct regcache
*regcache
= get_current_regcache ();
6774 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6776 tp
->suspend
= inf_state
->thread_suspend
;
6777 #if 0 /* Currently unused and empty structures are not valid C. */
6778 inf
->suspend
= inf_state
->inferior_suspend
;
6781 stop_pc
= inf_state
->stop_pc
;
6783 if (inf_state
->siginfo_gdbarch
== gdbarch
)
6785 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6787 /* Errors ignored. */
6788 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6789 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
6792 /* The inferior can be gone if the user types "print exit(0)"
6793 (and perhaps other times). */
6794 if (target_has_execution
)
6795 /* NB: The register write goes through to the target. */
6796 regcache_cpy (regcache
, inf_state
->registers
);
6798 discard_infcall_suspend_state (inf_state
);
6802 do_restore_infcall_suspend_state_cleanup (void *state
)
6804 restore_infcall_suspend_state (state
);
6808 make_cleanup_restore_infcall_suspend_state
6809 (struct infcall_suspend_state
*inf_state
)
6811 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
6815 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6817 regcache_xfree (inf_state
->registers
);
6818 xfree (inf_state
->siginfo_data
);
6823 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
6825 return inf_state
->registers
;
6828 /* infcall_control_state contains state regarding gdb's control of the
6829 inferior itself like stepping control. It also contains session state like
6830 the user's currently selected frame. */
6832 struct infcall_control_state
6834 struct thread_control_state thread_control
;
6835 struct inferior_control_state inferior_control
;
6838 enum stop_stack_kind stop_stack_dummy
;
6839 int stopped_by_random_signal
;
6840 int stop_after_trap
;
6842 /* ID if the selected frame when the inferior function call was made. */
6843 struct frame_id selected_frame_id
;
6846 /* Save all of the information associated with the inferior<==>gdb
6849 struct infcall_control_state
*
6850 save_infcall_control_state (void)
6852 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
6853 struct thread_info
*tp
= inferior_thread ();
6854 struct inferior
*inf
= current_inferior ();
6856 inf_status
->thread_control
= tp
->control
;
6857 inf_status
->inferior_control
= inf
->control
;
6859 tp
->control
.step_resume_breakpoint
= NULL
;
6860 tp
->control
.exception_resume_breakpoint
= NULL
;
6862 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6863 chain. If caller's caller is walking the chain, they'll be happier if we
6864 hand them back the original chain when restore_infcall_control_state is
6866 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
6869 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
6870 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
6871 inf_status
->stop_after_trap
= stop_after_trap
;
6873 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
6879 restore_selected_frame (void *args
)
6881 struct frame_id
*fid
= (struct frame_id
*) args
;
6882 struct frame_info
*frame
;
6884 frame
= frame_find_by_id (*fid
);
6886 /* If inf_status->selected_frame_id is NULL, there was no previously
6890 warning (_("Unable to restore previously selected frame."));
6894 select_frame (frame
);
6899 /* Restore inferior session state to INF_STATUS. */
6902 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
6904 struct thread_info
*tp
= inferior_thread ();
6905 struct inferior
*inf
= current_inferior ();
6907 if (tp
->control
.step_resume_breakpoint
)
6908 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
6910 if (tp
->control
.exception_resume_breakpoint
)
6911 tp
->control
.exception_resume_breakpoint
->disposition
6912 = disp_del_at_next_stop
;
6914 /* Handle the bpstat_copy of the chain. */
6915 bpstat_clear (&tp
->control
.stop_bpstat
);
6917 tp
->control
= inf_status
->thread_control
;
6918 inf
->control
= inf_status
->inferior_control
;
6921 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
6922 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
6923 stop_after_trap
= inf_status
->stop_after_trap
;
6925 if (target_has_stack
)
6927 /* The point of catch_errors is that if the stack is clobbered,
6928 walking the stack might encounter a garbage pointer and
6929 error() trying to dereference it. */
6931 (restore_selected_frame
, &inf_status
->selected_frame_id
,
6932 "Unable to restore previously selected frame:\n",
6933 RETURN_MASK_ERROR
) == 0)
6934 /* Error in restoring the selected frame. Select the innermost
6936 select_frame (get_current_frame ());
6943 do_restore_infcall_control_state_cleanup (void *sts
)
6945 restore_infcall_control_state (sts
);
6949 make_cleanup_restore_infcall_control_state
6950 (struct infcall_control_state
*inf_status
)
6952 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
6956 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
6958 if (inf_status
->thread_control
.step_resume_breakpoint
)
6959 inf_status
->thread_control
.step_resume_breakpoint
->disposition
6960 = disp_del_at_next_stop
;
6962 if (inf_status
->thread_control
.exception_resume_breakpoint
)
6963 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
6964 = disp_del_at_next_stop
;
6966 /* See save_infcall_control_state for info on stop_bpstat. */
6967 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
6973 ptid_match (ptid_t ptid
, ptid_t filter
)
6975 if (ptid_equal (filter
, minus_one_ptid
))
6977 if (ptid_is_pid (filter
)
6978 && ptid_get_pid (ptid
) == ptid_get_pid (filter
))
6980 else if (ptid_equal (ptid
, filter
))
6986 /* restore_inferior_ptid() will be used by the cleanup machinery
6987 to restore the inferior_ptid value saved in a call to
6988 save_inferior_ptid(). */
6991 restore_inferior_ptid (void *arg
)
6993 ptid_t
*saved_ptid_ptr
= arg
;
6995 inferior_ptid
= *saved_ptid_ptr
;
6999 /* Save the value of inferior_ptid so that it may be restored by a
7000 later call to do_cleanups(). Returns the struct cleanup pointer
7001 needed for later doing the cleanup. */
7004 save_inferior_ptid (void)
7006 ptid_t
*saved_ptid_ptr
;
7008 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7009 *saved_ptid_ptr
= inferior_ptid
;
7010 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7014 /* User interface for reverse debugging:
7015 Set exec-direction / show exec-direction commands
7016 (returns error unless target implements to_set_exec_direction method). */
7018 int execution_direction
= EXEC_FORWARD
;
7019 static const char exec_forward
[] = "forward";
7020 static const char exec_reverse
[] = "reverse";
7021 static const char *exec_direction
= exec_forward
;
7022 static const char *const exec_direction_names
[] = {
7029 set_exec_direction_func (char *args
, int from_tty
,
7030 struct cmd_list_element
*cmd
)
7032 if (target_can_execute_reverse
)
7034 if (!strcmp (exec_direction
, exec_forward
))
7035 execution_direction
= EXEC_FORWARD
;
7036 else if (!strcmp (exec_direction
, exec_reverse
))
7037 execution_direction
= EXEC_REVERSE
;
7041 exec_direction
= exec_forward
;
7042 error (_("Target does not support this operation."));
7047 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7048 struct cmd_list_element
*cmd
, const char *value
)
7050 switch (execution_direction
) {
7052 fprintf_filtered (out
, _("Forward.\n"));
7055 fprintf_filtered (out
, _("Reverse.\n"));
7058 internal_error (__FILE__
, __LINE__
,
7059 _("bogus execution_direction value: %d"),
7060 (int) execution_direction
);
7064 /* User interface for non-stop mode. */
7069 set_non_stop (char *args
, int from_tty
,
7070 struct cmd_list_element
*c
)
7072 if (target_has_execution
)
7074 non_stop_1
= non_stop
;
7075 error (_("Cannot change this setting while the inferior is running."));
7078 non_stop
= non_stop_1
;
7082 show_non_stop (struct ui_file
*file
, int from_tty
,
7083 struct cmd_list_element
*c
, const char *value
)
7085 fprintf_filtered (file
,
7086 _("Controlling the inferior in non-stop mode is %s.\n"),
7091 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7092 struct cmd_list_element
*c
, const char *value
)
7094 fprintf_filtered (file
, _("Resuming the execution of threads "
7095 "of all processes is %s.\n"), value
);
7098 /* Implementation of `siginfo' variable. */
7100 static const struct internalvar_funcs siginfo_funcs
=
7108 _initialize_infrun (void)
7112 struct cmd_list_element
*c
;
7114 add_info ("signals", signals_info
, _("\
7115 What debugger does when program gets various signals.\n\
7116 Specify a signal as argument to print info on that signal only."));
7117 add_info_alias ("handle", "signals", 0);
7119 c
= add_com ("handle", class_run
, handle_command
, _("\
7120 Specify how to handle signals.\n\
7121 Usage: handle SIGNAL [ACTIONS]\n\
7122 Args are signals and actions to apply to those signals.\n\
7123 If no actions are specified, the current settings for the specified signals\n\
7124 will be displayed instead.\n\
7126 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7127 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7128 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7129 The special arg \"all\" is recognized to mean all signals except those\n\
7130 used by the debugger, typically SIGTRAP and SIGINT.\n\
7132 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7133 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7134 Stop means reenter debugger if this signal happens (implies print).\n\
7135 Print means print a message if this signal happens.\n\
7136 Pass means let program see this signal; otherwise program doesn't know.\n\
7137 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7138 Pass and Stop may be combined.\n\
7140 Multiple signals may be specified. Signal numbers and signal names\n\
7141 may be interspersed with actions, with the actions being performed for\n\
7142 all signals cumulatively specified."));
7143 set_cmd_completer (c
, handle_completer
);
7147 add_com ("lz", class_info
, signals_info
, _("\
7148 What debugger does when program gets various signals.\n\
7149 Specify a signal as argument to print info on that signal only."));
7150 add_com ("z", class_run
, xdb_handle_command
, _("\
7151 Specify how to handle a signal.\n\
7152 Args are signals and actions to apply to those signals.\n\
7153 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7154 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7155 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7156 The special arg \"all\" is recognized to mean all signals except those\n\
7157 used by the debugger, typically SIGTRAP and SIGINT.\n\
7158 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7159 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7160 nopass), \"Q\" (noprint)\n\
7161 Stop means reenter debugger if this signal happens (implies print).\n\
7162 Print means print a message if this signal happens.\n\
7163 Pass means let program see this signal; otherwise program doesn't know.\n\
7164 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7165 Pass and Stop may be combined."));
7169 stop_command
= add_cmd ("stop", class_obscure
,
7170 not_just_help_class_command
, _("\
7171 There is no `stop' command, but you can set a hook on `stop'.\n\
7172 This allows you to set a list of commands to be run each time execution\n\
7173 of the program stops."), &cmdlist
);
7175 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7176 Set inferior debugging."), _("\
7177 Show inferior debugging."), _("\
7178 When non-zero, inferior specific debugging is enabled."),
7181 &setdebuglist
, &showdebuglist
);
7183 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7184 &debug_displaced
, _("\
7185 Set displaced stepping debugging."), _("\
7186 Show displaced stepping debugging."), _("\
7187 When non-zero, displaced stepping specific debugging is enabled."),
7189 show_debug_displaced
,
7190 &setdebuglist
, &showdebuglist
);
7192 add_setshow_boolean_cmd ("non-stop", no_class
,
7194 Set whether gdb controls the inferior in non-stop mode."), _("\
7195 Show whether gdb controls the inferior in non-stop mode."), _("\
7196 When debugging a multi-threaded program and this setting is\n\
7197 off (the default, also called all-stop mode), when one thread stops\n\
7198 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7199 all other threads in the program while you interact with the thread of\n\
7200 interest. When you continue or step a thread, you can allow the other\n\
7201 threads to run, or have them remain stopped, but while you inspect any\n\
7202 thread's state, all threads stop.\n\
7204 In non-stop mode, when one thread stops, other threads can continue\n\
7205 to run freely. You'll be able to step each thread independently,\n\
7206 leave it stopped or free to run as needed."),
7212 numsigs
= (int) GDB_SIGNAL_LAST
;
7213 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7214 signal_print
= (unsigned char *)
7215 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7216 signal_program
= (unsigned char *)
7217 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7218 signal_pass
= (unsigned char *)
7219 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7220 for (i
= 0; i
< numsigs
; i
++)
7223 signal_print
[i
] = 1;
7224 signal_program
[i
] = 1;
7227 /* Signals caused by debugger's own actions
7228 should not be given to the program afterwards. */
7229 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7230 signal_program
[GDB_SIGNAL_INT
] = 0;
7232 /* Signals that are not errors should not normally enter the debugger. */
7233 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7234 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7235 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7236 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7237 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7238 signal_print
[GDB_SIGNAL_PROF
] = 0;
7239 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7240 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7241 signal_stop
[GDB_SIGNAL_IO
] = 0;
7242 signal_print
[GDB_SIGNAL_IO
] = 0;
7243 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7244 signal_print
[GDB_SIGNAL_POLL
] = 0;
7245 signal_stop
[GDB_SIGNAL_URG
] = 0;
7246 signal_print
[GDB_SIGNAL_URG
] = 0;
7247 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7248 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7249 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7250 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7252 /* These signals are used internally by user-level thread
7253 implementations. (See signal(5) on Solaris.) Like the above
7254 signals, a healthy program receives and handles them as part of
7255 its normal operation. */
7256 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7257 signal_print
[GDB_SIGNAL_LWP
] = 0;
7258 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7259 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7260 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7261 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7263 /* Update cached state. */
7264 signal_cache_update (-1);
7266 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7267 &stop_on_solib_events
, _("\
7268 Set stopping for shared library events."), _("\
7269 Show stopping for shared library events."), _("\
7270 If nonzero, gdb will give control to the user when the dynamic linker\n\
7271 notifies gdb of shared library events. The most common event of interest\n\
7272 to the user would be loading/unloading of a new library."),
7274 show_stop_on_solib_events
,
7275 &setlist
, &showlist
);
7277 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7278 follow_fork_mode_kind_names
,
7279 &follow_fork_mode_string
, _("\
7280 Set debugger response to a program call of fork or vfork."), _("\
7281 Show debugger response to a program call of fork or vfork."), _("\
7282 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7283 parent - the original process is debugged after a fork\n\
7284 child - the new process is debugged after a fork\n\
7285 The unfollowed process will continue to run.\n\
7286 By default, the debugger will follow the parent process."),
7288 show_follow_fork_mode_string
,
7289 &setlist
, &showlist
);
7291 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7292 follow_exec_mode_names
,
7293 &follow_exec_mode_string
, _("\
7294 Set debugger response to a program call of exec."), _("\
7295 Show debugger response to a program call of exec."), _("\
7296 An exec call replaces the program image of a process.\n\
7298 follow-exec-mode can be:\n\
7300 new - the debugger creates a new inferior and rebinds the process\n\
7301 to this new inferior. The program the process was running before\n\
7302 the exec call can be restarted afterwards by restarting the original\n\
7305 same - the debugger keeps the process bound to the same inferior.\n\
7306 The new executable image replaces the previous executable loaded in\n\
7307 the inferior. Restarting the inferior after the exec call restarts\n\
7308 the executable the process was running after the exec call.\n\
7310 By default, the debugger will use the same inferior."),
7312 show_follow_exec_mode_string
,
7313 &setlist
, &showlist
);
7315 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7316 scheduler_enums
, &scheduler_mode
, _("\
7317 Set mode for locking scheduler during execution."), _("\
7318 Show mode for locking scheduler during execution."), _("\
7319 off == no locking (threads may preempt at any time)\n\
7320 on == full locking (no thread except the current thread may run)\n\
7321 step == scheduler locked during every single-step operation.\n\
7322 In this mode, no other thread may run during a step command.\n\
7323 Other threads may run while stepping over a function call ('next')."),
7324 set_schedlock_func
, /* traps on target vector */
7325 show_scheduler_mode
,
7326 &setlist
, &showlist
);
7328 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7329 Set mode for resuming threads of all processes."), _("\
7330 Show mode for resuming threads of all processes."), _("\
7331 When on, execution commands (such as 'continue' or 'next') resume all\n\
7332 threads of all processes. When off (which is the default), execution\n\
7333 commands only resume the threads of the current process. The set of\n\
7334 threads that are resumed is further refined by the scheduler-locking\n\
7335 mode (see help set scheduler-locking)."),
7337 show_schedule_multiple
,
7338 &setlist
, &showlist
);
7340 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7341 Set mode of the step operation."), _("\
7342 Show mode of the step operation."), _("\
7343 When set, doing a step over a function without debug line information\n\
7344 will stop at the first instruction of that function. Otherwise, the\n\
7345 function is skipped and the step command stops at a different source line."),
7347 show_step_stop_if_no_debug
,
7348 &setlist
, &showlist
);
7350 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7351 &can_use_displaced_stepping
, _("\
7352 Set debugger's willingness to use displaced stepping."), _("\
7353 Show debugger's willingness to use displaced stepping."), _("\
7354 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7355 supported by the target architecture. If off, gdb will not use displaced\n\
7356 stepping to step over breakpoints, even if such is supported by the target\n\
7357 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7358 if the target architecture supports it and non-stop mode is active, but will not\n\
7359 use it in all-stop mode (see help set non-stop)."),
7361 show_can_use_displaced_stepping
,
7362 &setlist
, &showlist
);
7364 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7365 &exec_direction
, _("Set direction of execution.\n\
7366 Options are 'forward' or 'reverse'."),
7367 _("Show direction of execution (forward/reverse)."),
7368 _("Tells gdb whether to execute forward or backward."),
7369 set_exec_direction_func
, show_exec_direction_func
,
7370 &setlist
, &showlist
);
7372 /* Set/show detach-on-fork: user-settable mode. */
7374 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7375 Set whether gdb will detach the child of a fork."), _("\
7376 Show whether gdb will detach the child of a fork."), _("\
7377 Tells gdb whether to detach the child of a fork."),
7378 NULL
, NULL
, &setlist
, &showlist
);
7380 /* Set/show disable address space randomization mode. */
7382 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7383 &disable_randomization
, _("\
7384 Set disabling of debuggee's virtual address space randomization."), _("\
7385 Show disabling of debuggee's virtual address space randomization."), _("\
7386 When this mode is on (which is the default), randomization of the virtual\n\
7387 address space is disabled. Standalone programs run with the randomization\n\
7388 enabled by default on some platforms."),
7389 &set_disable_randomization
,
7390 &show_disable_randomization
,
7391 &setlist
, &showlist
);
7393 /* ptid initializations */
7394 inferior_ptid
= null_ptid
;
7395 target_last_wait_ptid
= minus_one_ptid
;
7397 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7398 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7399 observer_attach_thread_exit (infrun_thread_thread_exit
);
7400 observer_attach_inferior_exit (infrun_inferior_exit
);
7402 /* Explicitly create without lookup, since that tries to create a
7403 value with a void typed value, and when we get here, gdbarch
7404 isn't initialized yet. At this point, we're quite sure there
7405 isn't another convenience variable of the same name. */
7406 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7408 add_setshow_boolean_cmd ("observer", no_class
,
7409 &observer_mode_1
, _("\
7410 Set whether gdb controls the inferior in observer mode."), _("\
7411 Show whether gdb controls the inferior in observer mode."), _("\
7412 In observer mode, GDB can get data from the inferior, but not\n\
7413 affect its execution. Registers and memory may not be changed,\n\
7414 breakpoints may not be set, and the program cannot be interrupted\n\