1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2014 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/>. */
28 #include "exceptions.h"
29 #include "breakpoint.h"
33 #include "cli/cli-script.h"
35 #include "gdbthread.h"
47 #include "dictionary.h"
49 #include "gdb_assert.h"
50 #include "mi/mi-common.h"
51 #include "event-top.h"
53 #include "record-full.h"
54 #include "inline-frame.h"
56 #include "tracepoint.h"
57 #include "continuations.h"
62 #include "completer.h"
63 #include "target-descriptions.h"
64 #include "target-dcache.h"
66 /* Prototypes for local functions */
68 static void signals_info (char *, int);
70 static void handle_command (char *, int);
72 static void sig_print_info (enum gdb_signal
);
74 static void sig_print_header (void);
76 static void resume_cleanups (void *);
78 static int hook_stop_stub (void *);
80 static int restore_selected_frame (void *);
82 static int follow_fork (void);
84 static void set_schedlock_func (char *args
, int from_tty
,
85 struct cmd_list_element
*c
);
87 static int currently_stepping (struct thread_info
*tp
);
89 static void xdb_handle_command (char *args
, int from_tty
);
91 static void print_exited_reason (int exitstatus
);
93 static void print_signal_exited_reason (enum gdb_signal siggnal
);
95 static void print_no_history_reason (void);
97 static void print_signal_received_reason (enum gdb_signal siggnal
);
99 static void print_end_stepping_range_reason (void);
101 void _initialize_infrun (void);
103 void nullify_last_target_wait_ptid (void);
105 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
107 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
109 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
111 /* When set, stop the 'step' command if we enter a function which has
112 no line number information. The normal behavior is that we step
113 over such function. */
114 int step_stop_if_no_debug
= 0;
116 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
117 struct cmd_list_element
*c
, const char *value
)
119 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
122 /* In asynchronous mode, but simulating synchronous execution. */
124 int sync_execution
= 0;
126 /* proceed and normal_stop use this to notify the user when the
127 inferior stopped in a different thread than it had been running
130 static ptid_t previous_inferior_ptid
;
132 /* If set (default for legacy reasons), when following a fork, GDB
133 will detach from one of the fork branches, child or parent.
134 Exactly which branch is detached depends on 'set follow-fork-mode'
137 static int detach_fork
= 1;
139 int debug_displaced
= 0;
141 show_debug_displaced (struct ui_file
*file
, int from_tty
,
142 struct cmd_list_element
*c
, const char *value
)
144 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
147 unsigned int debug_infrun
= 0;
149 show_debug_infrun (struct ui_file
*file
, int from_tty
,
150 struct cmd_list_element
*c
, const char *value
)
152 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
156 /* Support for disabling address space randomization. */
158 int disable_randomization
= 1;
161 show_disable_randomization (struct ui_file
*file
, int from_tty
,
162 struct cmd_list_element
*c
, const char *value
)
164 if (target_supports_disable_randomization ())
165 fprintf_filtered (file
,
166 _("Disabling randomization of debuggee's "
167 "virtual address space is %s.\n"),
170 fputs_filtered (_("Disabling randomization of debuggee's "
171 "virtual address space is unsupported on\n"
172 "this platform.\n"), file
);
176 set_disable_randomization (char *args
, int from_tty
,
177 struct cmd_list_element
*c
)
179 if (!target_supports_disable_randomization ())
180 error (_("Disabling randomization of debuggee's "
181 "virtual address space is unsupported on\n"
185 /* User interface for non-stop mode. */
188 static int non_stop_1
= 0;
191 set_non_stop (char *args
, int from_tty
,
192 struct cmd_list_element
*c
)
194 if (target_has_execution
)
196 non_stop_1
= non_stop
;
197 error (_("Cannot change this setting while the inferior is running."));
200 non_stop
= non_stop_1
;
204 show_non_stop (struct ui_file
*file
, int from_tty
,
205 struct cmd_list_element
*c
, const char *value
)
207 fprintf_filtered (file
,
208 _("Controlling the inferior in non-stop mode is %s.\n"),
212 /* "Observer mode" is somewhat like a more extreme version of
213 non-stop, in which all GDB operations that might affect the
214 target's execution have been disabled. */
216 int observer_mode
= 0;
217 static int observer_mode_1
= 0;
220 set_observer_mode (char *args
, int from_tty
,
221 struct cmd_list_element
*c
)
223 if (target_has_execution
)
225 observer_mode_1
= observer_mode
;
226 error (_("Cannot change this setting while the inferior is running."));
229 observer_mode
= observer_mode_1
;
231 may_write_registers
= !observer_mode
;
232 may_write_memory
= !observer_mode
;
233 may_insert_breakpoints
= !observer_mode
;
234 may_insert_tracepoints
= !observer_mode
;
235 /* We can insert fast tracepoints in or out of observer mode,
236 but enable them if we're going into this mode. */
238 may_insert_fast_tracepoints
= 1;
239 may_stop
= !observer_mode
;
240 update_target_permissions ();
242 /* Going *into* observer mode we must force non-stop, then
243 going out we leave it that way. */
246 target_async_permitted
= 1;
247 pagination_enabled
= 0;
248 non_stop
= non_stop_1
= 1;
252 printf_filtered (_("Observer mode is now %s.\n"),
253 (observer_mode
? "on" : "off"));
257 show_observer_mode (struct ui_file
*file
, int from_tty
,
258 struct cmd_list_element
*c
, const char *value
)
260 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
263 /* This updates the value of observer mode based on changes in
264 permissions. Note that we are deliberately ignoring the values of
265 may-write-registers and may-write-memory, since the user may have
266 reason to enable these during a session, for instance to turn on a
267 debugging-related global. */
270 update_observer_mode (void)
274 newval
= (!may_insert_breakpoints
275 && !may_insert_tracepoints
276 && may_insert_fast_tracepoints
280 /* Let the user know if things change. */
281 if (newval
!= observer_mode
)
282 printf_filtered (_("Observer mode is now %s.\n"),
283 (newval
? "on" : "off"));
285 observer_mode
= observer_mode_1
= newval
;
288 /* Tables of how to react to signals; the user sets them. */
290 static unsigned char *signal_stop
;
291 static unsigned char *signal_print
;
292 static unsigned char *signal_program
;
294 /* Table of signals that are registered with "catch signal". A
295 non-zero entry indicates that the signal is caught by some "catch
296 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
298 static unsigned char *signal_catch
;
300 /* Table of signals that the target may silently handle.
301 This is automatically determined from the flags above,
302 and simply cached here. */
303 static unsigned char *signal_pass
;
305 #define SET_SIGS(nsigs,sigs,flags) \
307 int signum = (nsigs); \
308 while (signum-- > 0) \
309 if ((sigs)[signum]) \
310 (flags)[signum] = 1; \
313 #define UNSET_SIGS(nsigs,sigs,flags) \
315 int signum = (nsigs); \
316 while (signum-- > 0) \
317 if ((sigs)[signum]) \
318 (flags)[signum] = 0; \
321 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
322 this function is to avoid exporting `signal_program'. */
325 update_signals_program_target (void)
327 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
330 /* Value to pass to target_resume() to cause all threads to resume. */
332 #define RESUME_ALL minus_one_ptid
334 /* Command list pointer for the "stop" placeholder. */
336 static struct cmd_list_element
*stop_command
;
338 /* Function inferior was in as of last step command. */
340 static struct symbol
*step_start_function
;
342 /* Nonzero if we want to give control to the user when we're notified
343 of shared library events by the dynamic linker. */
344 int stop_on_solib_events
;
346 /* Enable or disable optional shared library event breakpoints
347 as appropriate when the above flag is changed. */
350 set_stop_on_solib_events (char *args
, int from_tty
, struct cmd_list_element
*c
)
352 update_solib_breakpoints ();
356 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
357 struct cmd_list_element
*c
, const char *value
)
359 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
363 /* Nonzero means expecting a trace trap
364 and should stop the inferior and return silently when it happens. */
368 /* Save register contents here when executing a "finish" command or are
369 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
370 Thus this contains the return value from the called function (assuming
371 values are returned in a register). */
373 struct regcache
*stop_registers
;
375 /* Nonzero after stop if current stack frame should be printed. */
377 static int stop_print_frame
;
379 /* This is a cached copy of the pid/waitstatus of the last event
380 returned by target_wait()/deprecated_target_wait_hook(). This
381 information is returned by get_last_target_status(). */
382 static ptid_t target_last_wait_ptid
;
383 static struct target_waitstatus target_last_waitstatus
;
385 static void context_switch (ptid_t ptid
);
387 void init_thread_stepping_state (struct thread_info
*tss
);
389 static void init_infwait_state (void);
391 static const char follow_fork_mode_child
[] = "child";
392 static const char follow_fork_mode_parent
[] = "parent";
394 static const char *const follow_fork_mode_kind_names
[] = {
395 follow_fork_mode_child
,
396 follow_fork_mode_parent
,
400 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
402 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
403 struct cmd_list_element
*c
, const char *value
)
405 fprintf_filtered (file
,
406 _("Debugger response to a program "
407 "call of fork or vfork is \"%s\".\n"),
412 /* Tell the target to follow the fork we're stopped at. Returns true
413 if the inferior should be resumed; false, if the target for some
414 reason decided it's best not to resume. */
419 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
420 int should_resume
= 1;
421 struct thread_info
*tp
;
423 /* Copy user stepping state to the new inferior thread. FIXME: the
424 followed fork child thread should have a copy of most of the
425 parent thread structure's run control related fields, not just these.
426 Initialized to avoid "may be used uninitialized" warnings from gcc. */
427 struct breakpoint
*step_resume_breakpoint
= NULL
;
428 struct breakpoint
*exception_resume_breakpoint
= NULL
;
429 CORE_ADDR step_range_start
= 0;
430 CORE_ADDR step_range_end
= 0;
431 struct frame_id step_frame_id
= { 0 };
432 struct interp
*command_interp
= NULL
;
437 struct target_waitstatus wait_status
;
439 /* Get the last target status returned by target_wait(). */
440 get_last_target_status (&wait_ptid
, &wait_status
);
442 /* If not stopped at a fork event, then there's nothing else to
444 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
445 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
448 /* Check if we switched over from WAIT_PTID, since the event was
450 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
451 && !ptid_equal (inferior_ptid
, wait_ptid
))
453 /* We did. Switch back to WAIT_PTID thread, to tell the
454 target to follow it (in either direction). We'll
455 afterwards refuse to resume, and inform the user what
457 switch_to_thread (wait_ptid
);
462 tp
= inferior_thread ();
464 /* If there were any forks/vforks that were caught and are now to be
465 followed, then do so now. */
466 switch (tp
->pending_follow
.kind
)
468 case TARGET_WAITKIND_FORKED
:
469 case TARGET_WAITKIND_VFORKED
:
471 ptid_t parent
, child
;
473 /* If the user did a next/step, etc, over a fork call,
474 preserve the stepping state in the fork child. */
475 if (follow_child
&& should_resume
)
477 step_resume_breakpoint
= clone_momentary_breakpoint
478 (tp
->control
.step_resume_breakpoint
);
479 step_range_start
= tp
->control
.step_range_start
;
480 step_range_end
= tp
->control
.step_range_end
;
481 step_frame_id
= tp
->control
.step_frame_id
;
482 exception_resume_breakpoint
483 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
484 command_interp
= tp
->control
.command_interp
;
486 /* For now, delete the parent's sr breakpoint, otherwise,
487 parent/child sr breakpoints are considered duplicates,
488 and the child version will not be installed. Remove
489 this when the breakpoints module becomes aware of
490 inferiors and address spaces. */
491 delete_step_resume_breakpoint (tp
);
492 tp
->control
.step_range_start
= 0;
493 tp
->control
.step_range_end
= 0;
494 tp
->control
.step_frame_id
= null_frame_id
;
495 delete_exception_resume_breakpoint (tp
);
496 tp
->control
.command_interp
= NULL
;
499 parent
= inferior_ptid
;
500 child
= tp
->pending_follow
.value
.related_pid
;
502 /* Tell the target to do whatever is necessary to follow
503 either parent or child. */
504 if (target_follow_fork (follow_child
, detach_fork
))
506 /* Target refused to follow, or there's some other reason
507 we shouldn't resume. */
512 /* This pending follow fork event is now handled, one way
513 or another. The previous selected thread may be gone
514 from the lists by now, but if it is still around, need
515 to clear the pending follow request. */
516 tp
= find_thread_ptid (parent
);
518 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
520 /* This makes sure we don't try to apply the "Switched
521 over from WAIT_PID" logic above. */
522 nullify_last_target_wait_ptid ();
524 /* If we followed the child, switch to it... */
527 switch_to_thread (child
);
529 /* ... and preserve the stepping state, in case the
530 user was stepping over the fork call. */
533 tp
= inferior_thread ();
534 tp
->control
.step_resume_breakpoint
535 = step_resume_breakpoint
;
536 tp
->control
.step_range_start
= step_range_start
;
537 tp
->control
.step_range_end
= step_range_end
;
538 tp
->control
.step_frame_id
= step_frame_id
;
539 tp
->control
.exception_resume_breakpoint
540 = exception_resume_breakpoint
;
541 tp
->control
.command_interp
= command_interp
;
545 /* If we get here, it was because we're trying to
546 resume from a fork catchpoint, but, the user
547 has switched threads away from the thread that
548 forked. In that case, the resume command
549 issued is most likely not applicable to the
550 child, so just warn, and refuse to resume. */
551 warning (_("Not resuming: switched threads "
552 "before following fork child.\n"));
555 /* Reset breakpoints in the child as appropriate. */
556 follow_inferior_reset_breakpoints ();
559 switch_to_thread (parent
);
563 case TARGET_WAITKIND_SPURIOUS
:
564 /* Nothing to follow. */
567 internal_error (__FILE__
, __LINE__
,
568 "Unexpected pending_follow.kind %d\n",
569 tp
->pending_follow
.kind
);
573 return should_resume
;
577 follow_inferior_reset_breakpoints (void)
579 struct thread_info
*tp
= inferior_thread ();
581 /* Was there a step_resume breakpoint? (There was if the user
582 did a "next" at the fork() call.) If so, explicitly reset its
585 step_resumes are a form of bp that are made to be per-thread.
586 Since we created the step_resume bp when the parent process
587 was being debugged, and now are switching to the child process,
588 from the breakpoint package's viewpoint, that's a switch of
589 "threads". We must update the bp's notion of which thread
590 it is for, or it'll be ignored when it triggers. */
592 if (tp
->control
.step_resume_breakpoint
)
593 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
595 if (tp
->control
.exception_resume_breakpoint
)
596 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
598 /* Reinsert all breakpoints in the child. The user may have set
599 breakpoints after catching the fork, in which case those
600 were never set in the child, but only in the parent. This makes
601 sure the inserted breakpoints match the breakpoint list. */
603 breakpoint_re_set ();
604 insert_breakpoints ();
607 /* The child has exited or execed: resume threads of the parent the
608 user wanted to be executing. */
611 proceed_after_vfork_done (struct thread_info
*thread
,
614 int pid
= * (int *) arg
;
616 if (ptid_get_pid (thread
->ptid
) == pid
617 && is_running (thread
->ptid
)
618 && !is_executing (thread
->ptid
)
619 && !thread
->stop_requested
620 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
623 fprintf_unfiltered (gdb_stdlog
,
624 "infrun: resuming vfork parent thread %s\n",
625 target_pid_to_str (thread
->ptid
));
627 switch_to_thread (thread
->ptid
);
628 clear_proceed_status ();
629 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
635 /* Called whenever we notice an exec or exit event, to handle
636 detaching or resuming a vfork parent. */
639 handle_vfork_child_exec_or_exit (int exec
)
641 struct inferior
*inf
= current_inferior ();
643 if (inf
->vfork_parent
)
645 int resume_parent
= -1;
647 /* This exec or exit marks the end of the shared memory region
648 between the parent and the child. If the user wanted to
649 detach from the parent, now is the time. */
651 if (inf
->vfork_parent
->pending_detach
)
653 struct thread_info
*tp
;
654 struct cleanup
*old_chain
;
655 struct program_space
*pspace
;
656 struct address_space
*aspace
;
658 /* follow-fork child, detach-on-fork on. */
660 inf
->vfork_parent
->pending_detach
= 0;
664 /* If we're handling a child exit, then inferior_ptid
665 points at the inferior's pid, not to a thread. */
666 old_chain
= save_inferior_ptid ();
667 save_current_program_space ();
668 save_current_inferior ();
671 old_chain
= save_current_space_and_thread ();
673 /* We're letting loose of the parent. */
674 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
675 switch_to_thread (tp
->ptid
);
677 /* We're about to detach from the parent, which implicitly
678 removes breakpoints from its address space. There's a
679 catch here: we want to reuse the spaces for the child,
680 but, parent/child are still sharing the pspace at this
681 point, although the exec in reality makes the kernel give
682 the child a fresh set of new pages. The problem here is
683 that the breakpoints module being unaware of this, would
684 likely chose the child process to write to the parent
685 address space. Swapping the child temporarily away from
686 the spaces has the desired effect. Yes, this is "sort
689 pspace
= inf
->pspace
;
690 aspace
= inf
->aspace
;
694 if (debug_infrun
|| info_verbose
)
696 target_terminal_ours ();
699 fprintf_filtered (gdb_stdlog
,
700 "Detaching vfork parent process "
701 "%d after child exec.\n",
702 inf
->vfork_parent
->pid
);
704 fprintf_filtered (gdb_stdlog
,
705 "Detaching vfork parent process "
706 "%d after child exit.\n",
707 inf
->vfork_parent
->pid
);
710 target_detach (NULL
, 0);
713 inf
->pspace
= pspace
;
714 inf
->aspace
= aspace
;
716 do_cleanups (old_chain
);
720 /* We're staying attached to the parent, so, really give the
721 child a new address space. */
722 inf
->pspace
= add_program_space (maybe_new_address_space ());
723 inf
->aspace
= inf
->pspace
->aspace
;
725 set_current_program_space (inf
->pspace
);
727 resume_parent
= inf
->vfork_parent
->pid
;
729 /* Break the bonds. */
730 inf
->vfork_parent
->vfork_child
= NULL
;
734 struct cleanup
*old_chain
;
735 struct program_space
*pspace
;
737 /* If this is a vfork child exiting, then the pspace and
738 aspaces were shared with the parent. Since we're
739 reporting the process exit, we'll be mourning all that is
740 found in the address space, and switching to null_ptid,
741 preparing to start a new inferior. But, since we don't
742 want to clobber the parent's address/program spaces, we
743 go ahead and create a new one for this exiting
746 /* Switch to null_ptid, so that clone_program_space doesn't want
747 to read the selected frame of a dead process. */
748 old_chain
= save_inferior_ptid ();
749 inferior_ptid
= null_ptid
;
751 /* This inferior is dead, so avoid giving the breakpoints
752 module the option to write through to it (cloning a
753 program space resets breakpoints). */
756 pspace
= add_program_space (maybe_new_address_space ());
757 set_current_program_space (pspace
);
759 inf
->symfile_flags
= SYMFILE_NO_READ
;
760 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
761 inf
->pspace
= pspace
;
762 inf
->aspace
= pspace
->aspace
;
764 /* Put back inferior_ptid. We'll continue mourning this
766 do_cleanups (old_chain
);
768 resume_parent
= inf
->vfork_parent
->pid
;
769 /* Break the bonds. */
770 inf
->vfork_parent
->vfork_child
= NULL
;
773 inf
->vfork_parent
= NULL
;
775 gdb_assert (current_program_space
== inf
->pspace
);
777 if (non_stop
&& resume_parent
!= -1)
779 /* If the user wanted the parent to be running, let it go
781 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
784 fprintf_unfiltered (gdb_stdlog
,
785 "infrun: resuming vfork parent process %d\n",
788 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
790 do_cleanups (old_chain
);
795 /* Enum strings for "set|show follow-exec-mode". */
797 static const char follow_exec_mode_new
[] = "new";
798 static const char follow_exec_mode_same
[] = "same";
799 static const char *const follow_exec_mode_names
[] =
801 follow_exec_mode_new
,
802 follow_exec_mode_same
,
806 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
808 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
809 struct cmd_list_element
*c
, const char *value
)
811 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
814 /* EXECD_PATHNAME is assumed to be non-NULL. */
817 follow_exec (ptid_t pid
, char *execd_pathname
)
819 struct thread_info
*th
= inferior_thread ();
820 struct inferior
*inf
= current_inferior ();
822 /* This is an exec event that we actually wish to pay attention to.
823 Refresh our symbol table to the newly exec'd program, remove any
826 If there are breakpoints, they aren't really inserted now,
827 since the exec() transformed our inferior into a fresh set
830 We want to preserve symbolic breakpoints on the list, since
831 we have hopes that they can be reset after the new a.out's
832 symbol table is read.
834 However, any "raw" breakpoints must be removed from the list
835 (e.g., the solib bp's), since their address is probably invalid
838 And, we DON'T want to call delete_breakpoints() here, since
839 that may write the bp's "shadow contents" (the instruction
840 value that was overwritten witha TRAP instruction). Since
841 we now have a new a.out, those shadow contents aren't valid. */
843 mark_breakpoints_out ();
845 update_breakpoints_after_exec ();
847 /* If there was one, it's gone now. We cannot truly step-to-next
848 statement through an exec(). */
849 th
->control
.step_resume_breakpoint
= NULL
;
850 th
->control
.exception_resume_breakpoint
= NULL
;
851 th
->control
.step_range_start
= 0;
852 th
->control
.step_range_end
= 0;
854 /* The target reports the exec event to the main thread, even if
855 some other thread does the exec, and even if the main thread was
856 already stopped --- if debugging in non-stop mode, it's possible
857 the user had the main thread held stopped in the previous image
858 --- release it now. This is the same behavior as step-over-exec
859 with scheduler-locking on in all-stop mode. */
860 th
->stop_requested
= 0;
862 /* What is this a.out's name? */
863 printf_unfiltered (_("%s is executing new program: %s\n"),
864 target_pid_to_str (inferior_ptid
),
867 /* We've followed the inferior through an exec. Therefore, the
868 inferior has essentially been killed & reborn. */
870 gdb_flush (gdb_stdout
);
872 breakpoint_init_inferior (inf_execd
);
874 if (gdb_sysroot
&& *gdb_sysroot
)
876 char *name
= alloca (strlen (gdb_sysroot
)
877 + strlen (execd_pathname
)
880 strcpy (name
, gdb_sysroot
);
881 strcat (name
, execd_pathname
);
882 execd_pathname
= name
;
885 /* Reset the shared library package. This ensures that we get a
886 shlib event when the child reaches "_start", at which point the
887 dld will have had a chance to initialize the child. */
888 /* Also, loading a symbol file below may trigger symbol lookups, and
889 we don't want those to be satisfied by the libraries of the
890 previous incarnation of this process. */
891 no_shared_libraries (NULL
, 0);
893 if (follow_exec_mode_string
== follow_exec_mode_new
)
895 struct program_space
*pspace
;
897 /* The user wants to keep the old inferior and program spaces
898 around. Create a new fresh one, and switch to it. */
900 inf
= add_inferior (current_inferior ()->pid
);
901 pspace
= add_program_space (maybe_new_address_space ());
902 inf
->pspace
= pspace
;
903 inf
->aspace
= pspace
->aspace
;
905 exit_inferior_num_silent (current_inferior ()->num
);
907 set_current_inferior (inf
);
908 set_current_program_space (pspace
);
912 /* The old description may no longer be fit for the new image.
913 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
914 old description; we'll read a new one below. No need to do
915 this on "follow-exec-mode new", as the old inferior stays
916 around (its description is later cleared/refetched on
918 target_clear_description ();
921 gdb_assert (current_program_space
== inf
->pspace
);
923 /* That a.out is now the one to use. */
924 exec_file_attach (execd_pathname
, 0);
926 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
927 (Position Independent Executable) main symbol file will get applied by
928 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
929 the breakpoints with the zero displacement. */
931 symbol_file_add (execd_pathname
,
933 | SYMFILE_MAINLINE
| SYMFILE_DEFER_BP_RESET
),
936 if ((inf
->symfile_flags
& SYMFILE_NO_READ
) == 0)
937 set_initial_language ();
939 /* If the target can specify a description, read it. Must do this
940 after flipping to the new executable (because the target supplied
941 description must be compatible with the executable's
942 architecture, and the old executable may e.g., be 32-bit, while
943 the new one 64-bit), and before anything involving memory or
945 target_find_description ();
947 solib_create_inferior_hook (0);
949 jit_inferior_created_hook ();
951 breakpoint_re_set ();
953 /* Reinsert all breakpoints. (Those which were symbolic have
954 been reset to the proper address in the new a.out, thanks
955 to symbol_file_command...). */
956 insert_breakpoints ();
958 /* The next resume of this inferior should bring it to the shlib
959 startup breakpoints. (If the user had also set bp's on
960 "main" from the old (parent) process, then they'll auto-
961 matically get reset there in the new process.). */
964 /* Non-zero if we just simulating a single-step. This is needed
965 because we cannot remove the breakpoints in the inferior process
966 until after the `wait' in `wait_for_inferior'. */
967 static int singlestep_breakpoints_inserted_p
= 0;
969 /* The thread we inserted single-step breakpoints for. */
970 static ptid_t singlestep_ptid
;
972 /* PC when we started this single-step. */
973 static CORE_ADDR singlestep_pc
;
975 /* Info about an instruction that is being stepped over. Invalid if
978 struct step_over_info
980 /* The instruction's address space. */
981 struct address_space
*aspace
;
983 /* The instruction's address. */
987 /* The step-over info of the location that is being stepped over.
989 Note that with async/breakpoint always-inserted mode, a user might
990 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
991 being stepped over. As setting a new breakpoint inserts all
992 breakpoints, we need to make sure the breakpoint being stepped over
993 isn't inserted then. We do that by only clearing the step-over
994 info when the step-over is actually finished (or aborted).
996 Presently GDB can only step over one breakpoint at any given time.
997 Given threads that can't run code in the same address space as the
998 breakpoint's can't really miss the breakpoint, GDB could be taught
999 to step-over at most one breakpoint per address space (so this info
1000 could move to the address space object if/when GDB is extended).
1001 The set of breakpoints being stepped over will normally be much
1002 smaller than the set of all breakpoints, so a flag in the
1003 breakpoint location structure would be wasteful. A separate list
1004 also saves complexity and run-time, as otherwise we'd have to go
1005 through all breakpoint locations clearing their flag whenever we
1006 start a new sequence. Similar considerations weigh against storing
1007 this info in the thread object. Plus, not all step overs actually
1008 have breakpoint locations -- e.g., stepping past a single-step
1009 breakpoint, or stepping to complete a non-continuable
1011 static struct step_over_info step_over_info
;
1013 /* Record the address of the breakpoint/instruction we're currently
1017 set_step_over_info (struct address_space
*aspace
, CORE_ADDR address
)
1019 step_over_info
.aspace
= aspace
;
1020 step_over_info
.address
= address
;
1023 /* Called when we're not longer stepping over a breakpoint / an
1024 instruction, so all breakpoints are free to be (re)inserted. */
1027 clear_step_over_info (void)
1029 step_over_info
.aspace
= NULL
;
1030 step_over_info
.address
= 0;
1033 /* See inferior.h. */
1036 stepping_past_instruction_at (struct address_space
*aspace
,
1039 return (step_over_info
.aspace
!= NULL
1040 && breakpoint_address_match (aspace
, address
,
1041 step_over_info
.aspace
,
1042 step_over_info
.address
));
1046 /* Displaced stepping. */
1048 /* In non-stop debugging mode, we must take special care to manage
1049 breakpoints properly; in particular, the traditional strategy for
1050 stepping a thread past a breakpoint it has hit is unsuitable.
1051 'Displaced stepping' is a tactic for stepping one thread past a
1052 breakpoint it has hit while ensuring that other threads running
1053 concurrently will hit the breakpoint as they should.
1055 The traditional way to step a thread T off a breakpoint in a
1056 multi-threaded program in all-stop mode is as follows:
1058 a0) Initially, all threads are stopped, and breakpoints are not
1060 a1) We single-step T, leaving breakpoints uninserted.
1061 a2) We insert breakpoints, and resume all threads.
1063 In non-stop debugging, however, this strategy is unsuitable: we
1064 don't want to have to stop all threads in the system in order to
1065 continue or step T past a breakpoint. Instead, we use displaced
1068 n0) Initially, T is stopped, other threads are running, and
1069 breakpoints are inserted.
1070 n1) We copy the instruction "under" the breakpoint to a separate
1071 location, outside the main code stream, making any adjustments
1072 to the instruction, register, and memory state as directed by
1074 n2) We single-step T over the instruction at its new location.
1075 n3) We adjust the resulting register and memory state as directed
1076 by T's architecture. This includes resetting T's PC to point
1077 back into the main instruction stream.
1080 This approach depends on the following gdbarch methods:
1082 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1083 indicate where to copy the instruction, and how much space must
1084 be reserved there. We use these in step n1.
1086 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1087 address, and makes any necessary adjustments to the instruction,
1088 register contents, and memory. We use this in step n1.
1090 - gdbarch_displaced_step_fixup adjusts registers and memory after
1091 we have successfuly single-stepped the instruction, to yield the
1092 same effect the instruction would have had if we had executed it
1093 at its original address. We use this in step n3.
1095 - gdbarch_displaced_step_free_closure provides cleanup.
1097 The gdbarch_displaced_step_copy_insn and
1098 gdbarch_displaced_step_fixup functions must be written so that
1099 copying an instruction with gdbarch_displaced_step_copy_insn,
1100 single-stepping across the copied instruction, and then applying
1101 gdbarch_displaced_insn_fixup should have the same effects on the
1102 thread's memory and registers as stepping the instruction in place
1103 would have. Exactly which responsibilities fall to the copy and
1104 which fall to the fixup is up to the author of those functions.
1106 See the comments in gdbarch.sh for details.
1108 Note that displaced stepping and software single-step cannot
1109 currently be used in combination, although with some care I think
1110 they could be made to. Software single-step works by placing
1111 breakpoints on all possible subsequent instructions; if the
1112 displaced instruction is a PC-relative jump, those breakpoints
1113 could fall in very strange places --- on pages that aren't
1114 executable, or at addresses that are not proper instruction
1115 boundaries. (We do generally let other threads run while we wait
1116 to hit the software single-step breakpoint, and they might
1117 encounter such a corrupted instruction.) One way to work around
1118 this would be to have gdbarch_displaced_step_copy_insn fully
1119 simulate the effect of PC-relative instructions (and return NULL)
1120 on architectures that use software single-stepping.
1122 In non-stop mode, we can have independent and simultaneous step
1123 requests, so more than one thread may need to simultaneously step
1124 over a breakpoint. The current implementation assumes there is
1125 only one scratch space per process. In this case, we have to
1126 serialize access to the scratch space. If thread A wants to step
1127 over a breakpoint, but we are currently waiting for some other
1128 thread to complete a displaced step, we leave thread A stopped and
1129 place it in the displaced_step_request_queue. Whenever a displaced
1130 step finishes, we pick the next thread in the queue and start a new
1131 displaced step operation on it. See displaced_step_prepare and
1132 displaced_step_fixup for details. */
1134 struct displaced_step_request
1137 struct displaced_step_request
*next
;
1140 /* Per-inferior displaced stepping state. */
1141 struct displaced_step_inferior_state
1143 /* Pointer to next in linked list. */
1144 struct displaced_step_inferior_state
*next
;
1146 /* The process this displaced step state refers to. */
1149 /* A queue of pending displaced stepping requests. One entry per
1150 thread that needs to do a displaced step. */
1151 struct displaced_step_request
*step_request_queue
;
1153 /* If this is not null_ptid, this is the thread carrying out a
1154 displaced single-step in process PID. This thread's state will
1155 require fixing up once it has completed its step. */
1158 /* The architecture the thread had when we stepped it. */
1159 struct gdbarch
*step_gdbarch
;
1161 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1162 for post-step cleanup. */
1163 struct displaced_step_closure
*step_closure
;
1165 /* The address of the original instruction, and the copy we
1167 CORE_ADDR step_original
, step_copy
;
1169 /* Saved contents of copy area. */
1170 gdb_byte
*step_saved_copy
;
1173 /* The list of states of processes involved in displaced stepping
1175 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1177 /* Get the displaced stepping state of process PID. */
1179 static struct displaced_step_inferior_state
*
1180 get_displaced_stepping_state (int pid
)
1182 struct displaced_step_inferior_state
*state
;
1184 for (state
= displaced_step_inferior_states
;
1186 state
= state
->next
)
1187 if (state
->pid
== pid
)
1193 /* Add a new displaced stepping state for process PID to the displaced
1194 stepping state list, or return a pointer to an already existing
1195 entry, if it already exists. Never returns NULL. */
1197 static struct displaced_step_inferior_state
*
1198 add_displaced_stepping_state (int pid
)
1200 struct displaced_step_inferior_state
*state
;
1202 for (state
= displaced_step_inferior_states
;
1204 state
= state
->next
)
1205 if (state
->pid
== pid
)
1208 state
= xcalloc (1, sizeof (*state
));
1210 state
->next
= displaced_step_inferior_states
;
1211 displaced_step_inferior_states
= state
;
1216 /* If inferior is in displaced stepping, and ADDR equals to starting address
1217 of copy area, return corresponding displaced_step_closure. Otherwise,
1220 struct displaced_step_closure
*
1221 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1223 struct displaced_step_inferior_state
*displaced
1224 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1226 /* If checking the mode of displaced instruction in copy area. */
1227 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1228 && (displaced
->step_copy
== addr
))
1229 return displaced
->step_closure
;
1234 /* Remove the displaced stepping state of process PID. */
1237 remove_displaced_stepping_state (int pid
)
1239 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1241 gdb_assert (pid
!= 0);
1243 it
= displaced_step_inferior_states
;
1244 prev_next_p
= &displaced_step_inferior_states
;
1249 *prev_next_p
= it
->next
;
1254 prev_next_p
= &it
->next
;
1260 infrun_inferior_exit (struct inferior
*inf
)
1262 remove_displaced_stepping_state (inf
->pid
);
1265 /* If ON, and the architecture supports it, GDB will use displaced
1266 stepping to step over breakpoints. If OFF, or if the architecture
1267 doesn't support it, GDB will instead use the traditional
1268 hold-and-step approach. If AUTO (which is the default), GDB will
1269 decide which technique to use to step over breakpoints depending on
1270 which of all-stop or non-stop mode is active --- displaced stepping
1271 in non-stop mode; hold-and-step in all-stop mode. */
1273 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1276 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1277 struct cmd_list_element
*c
,
1280 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1281 fprintf_filtered (file
,
1282 _("Debugger's willingness to use displaced stepping "
1283 "to step over breakpoints is %s (currently %s).\n"),
1284 value
, non_stop
? "on" : "off");
1286 fprintf_filtered (file
,
1287 _("Debugger's willingness to use displaced stepping "
1288 "to step over breakpoints is %s.\n"), value
);
1291 /* Return non-zero if displaced stepping can/should be used to step
1292 over breakpoints. */
1295 use_displaced_stepping (struct gdbarch
*gdbarch
)
1297 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1298 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1299 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1300 && find_record_target () == NULL
);
1303 /* Clean out any stray displaced stepping state. */
1305 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1307 /* Indicate that there is no cleanup pending. */
1308 displaced
->step_ptid
= null_ptid
;
1310 if (displaced
->step_closure
)
1312 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1313 displaced
->step_closure
);
1314 displaced
->step_closure
= NULL
;
1319 displaced_step_clear_cleanup (void *arg
)
1321 struct displaced_step_inferior_state
*state
= arg
;
1323 displaced_step_clear (state
);
1326 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1328 displaced_step_dump_bytes (struct ui_file
*file
,
1329 const gdb_byte
*buf
,
1334 for (i
= 0; i
< len
; i
++)
1335 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1336 fputs_unfiltered ("\n", file
);
1339 /* Prepare to single-step, using displaced stepping.
1341 Note that we cannot use displaced stepping when we have a signal to
1342 deliver. If we have a signal to deliver and an instruction to step
1343 over, then after the step, there will be no indication from the
1344 target whether the thread entered a signal handler or ignored the
1345 signal and stepped over the instruction successfully --- both cases
1346 result in a simple SIGTRAP. In the first case we mustn't do a
1347 fixup, and in the second case we must --- but we can't tell which.
1348 Comments in the code for 'random signals' in handle_inferior_event
1349 explain how we handle this case instead.
1351 Returns 1 if preparing was successful -- this thread is going to be
1352 stepped now; or 0 if displaced stepping this thread got queued. */
1354 displaced_step_prepare (ptid_t ptid
)
1356 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1357 struct thread_info
*tp
= find_thread_ptid (ptid
);
1358 struct regcache
*regcache
= get_thread_regcache (ptid
);
1359 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1360 CORE_ADDR original
, copy
;
1362 struct displaced_step_closure
*closure
;
1363 struct displaced_step_inferior_state
*displaced
;
1366 /* We should never reach this function if the architecture does not
1367 support displaced stepping. */
1368 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1370 /* Disable range stepping while executing in the scratch pad. We
1371 want a single-step even if executing the displaced instruction in
1372 the scratch buffer lands within the stepping range (e.g., a
1374 tp
->control
.may_range_step
= 0;
1376 /* We have to displaced step one thread at a time, as we only have
1377 access to a single scratch space per inferior. */
1379 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1381 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1383 /* Already waiting for a displaced step to finish. Defer this
1384 request and place in queue. */
1385 struct displaced_step_request
*req
, *new_req
;
1387 if (debug_displaced
)
1388 fprintf_unfiltered (gdb_stdlog
,
1389 "displaced: defering step of %s\n",
1390 target_pid_to_str (ptid
));
1392 new_req
= xmalloc (sizeof (*new_req
));
1393 new_req
->ptid
= ptid
;
1394 new_req
->next
= NULL
;
1396 if (displaced
->step_request_queue
)
1398 for (req
= displaced
->step_request_queue
;
1402 req
->next
= new_req
;
1405 displaced
->step_request_queue
= new_req
;
1411 if (debug_displaced
)
1412 fprintf_unfiltered (gdb_stdlog
,
1413 "displaced: stepping %s now\n",
1414 target_pid_to_str (ptid
));
1417 displaced_step_clear (displaced
);
1419 old_cleanups
= save_inferior_ptid ();
1420 inferior_ptid
= ptid
;
1422 original
= regcache_read_pc (regcache
);
1424 copy
= gdbarch_displaced_step_location (gdbarch
);
1425 len
= gdbarch_max_insn_length (gdbarch
);
1427 /* Save the original contents of the copy area. */
1428 displaced
->step_saved_copy
= xmalloc (len
);
1429 ignore_cleanups
= make_cleanup (free_current_contents
,
1430 &displaced
->step_saved_copy
);
1431 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1433 throw_error (MEMORY_ERROR
,
1434 _("Error accessing memory address %s (%s) for "
1435 "displaced-stepping scratch space."),
1436 paddress (gdbarch
, copy
), safe_strerror (status
));
1437 if (debug_displaced
)
1439 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1440 paddress (gdbarch
, copy
));
1441 displaced_step_dump_bytes (gdb_stdlog
,
1442 displaced
->step_saved_copy
,
1446 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1447 original
, copy
, regcache
);
1449 /* We don't support the fully-simulated case at present. */
1450 gdb_assert (closure
);
1452 /* Save the information we need to fix things up if the step
1454 displaced
->step_ptid
= ptid
;
1455 displaced
->step_gdbarch
= gdbarch
;
1456 displaced
->step_closure
= closure
;
1457 displaced
->step_original
= original
;
1458 displaced
->step_copy
= copy
;
1460 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1462 /* Resume execution at the copy. */
1463 regcache_write_pc (regcache
, copy
);
1465 discard_cleanups (ignore_cleanups
);
1467 do_cleanups (old_cleanups
);
1469 if (debug_displaced
)
1470 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1471 paddress (gdbarch
, copy
));
1477 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1478 const gdb_byte
*myaddr
, int len
)
1480 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1482 inferior_ptid
= ptid
;
1483 write_memory (memaddr
, myaddr
, len
);
1484 do_cleanups (ptid_cleanup
);
1487 /* Restore the contents of the copy area for thread PTID. */
1490 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1493 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1495 write_memory_ptid (ptid
, displaced
->step_copy
,
1496 displaced
->step_saved_copy
, len
);
1497 if (debug_displaced
)
1498 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1499 target_pid_to_str (ptid
),
1500 paddress (displaced
->step_gdbarch
,
1501 displaced
->step_copy
));
1505 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1507 struct cleanup
*old_cleanups
;
1508 struct displaced_step_inferior_state
*displaced
1509 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1511 /* Was any thread of this process doing a displaced step? */
1512 if (displaced
== NULL
)
1515 /* Was this event for the pid we displaced? */
1516 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1517 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1520 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1522 displaced_step_restore (displaced
, displaced
->step_ptid
);
1524 /* Did the instruction complete successfully? */
1525 if (signal
== GDB_SIGNAL_TRAP
)
1527 /* Fix up the resulting state. */
1528 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1529 displaced
->step_closure
,
1530 displaced
->step_original
,
1531 displaced
->step_copy
,
1532 get_thread_regcache (displaced
->step_ptid
));
1536 /* Since the instruction didn't complete, all we can do is
1538 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1539 CORE_ADDR pc
= regcache_read_pc (regcache
);
1541 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1542 regcache_write_pc (regcache
, pc
);
1545 do_cleanups (old_cleanups
);
1547 displaced
->step_ptid
= null_ptid
;
1549 /* Are there any pending displaced stepping requests? If so, run
1550 one now. Leave the state object around, since we're likely to
1551 need it again soon. */
1552 while (displaced
->step_request_queue
)
1554 struct displaced_step_request
*head
;
1556 struct regcache
*regcache
;
1557 struct gdbarch
*gdbarch
;
1558 CORE_ADDR actual_pc
;
1559 struct address_space
*aspace
;
1561 head
= displaced
->step_request_queue
;
1563 displaced
->step_request_queue
= head
->next
;
1566 context_switch (ptid
);
1568 regcache
= get_thread_regcache (ptid
);
1569 actual_pc
= regcache_read_pc (regcache
);
1570 aspace
= get_regcache_aspace (regcache
);
1572 if (breakpoint_here_p (aspace
, actual_pc
))
1574 if (debug_displaced
)
1575 fprintf_unfiltered (gdb_stdlog
,
1576 "displaced: stepping queued %s now\n",
1577 target_pid_to_str (ptid
));
1579 displaced_step_prepare (ptid
);
1581 gdbarch
= get_regcache_arch (regcache
);
1583 if (debug_displaced
)
1585 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1588 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1589 paddress (gdbarch
, actual_pc
));
1590 read_memory (actual_pc
, buf
, sizeof (buf
));
1591 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1594 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1595 displaced
->step_closure
))
1596 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1598 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1600 /* Done, we're stepping a thread. */
1606 struct thread_info
*tp
= inferior_thread ();
1608 /* The breakpoint we were sitting under has since been
1610 tp
->control
.trap_expected
= 0;
1612 /* Go back to what we were trying to do. */
1613 step
= currently_stepping (tp
);
1615 if (debug_displaced
)
1616 fprintf_unfiltered (gdb_stdlog
,
1617 "displaced: breakpoint is gone: %s, step(%d)\n",
1618 target_pid_to_str (tp
->ptid
), step
);
1620 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1621 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1623 /* This request was discarded. See if there's any other
1624 thread waiting for its turn. */
1629 /* Update global variables holding ptids to hold NEW_PTID if they were
1630 holding OLD_PTID. */
1632 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1634 struct displaced_step_request
*it
;
1635 struct displaced_step_inferior_state
*displaced
;
1637 if (ptid_equal (inferior_ptid
, old_ptid
))
1638 inferior_ptid
= new_ptid
;
1640 if (ptid_equal (singlestep_ptid
, old_ptid
))
1641 singlestep_ptid
= new_ptid
;
1643 for (displaced
= displaced_step_inferior_states
;
1645 displaced
= displaced
->next
)
1647 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1648 displaced
->step_ptid
= new_ptid
;
1650 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1651 if (ptid_equal (it
->ptid
, old_ptid
))
1652 it
->ptid
= new_ptid
;
1659 /* Things to clean up if we QUIT out of resume (). */
1661 resume_cleanups (void *ignore
)
1666 static const char schedlock_off
[] = "off";
1667 static const char schedlock_on
[] = "on";
1668 static const char schedlock_step
[] = "step";
1669 static const char *const scheduler_enums
[] = {
1675 static const char *scheduler_mode
= schedlock_off
;
1677 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1678 struct cmd_list_element
*c
, const char *value
)
1680 fprintf_filtered (file
,
1681 _("Mode for locking scheduler "
1682 "during execution is \"%s\".\n"),
1687 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1689 if (!target_can_lock_scheduler
)
1691 scheduler_mode
= schedlock_off
;
1692 error (_("Target '%s' cannot support this command."), target_shortname
);
1696 /* True if execution commands resume all threads of all processes by
1697 default; otherwise, resume only threads of the current inferior
1699 int sched_multi
= 0;
1701 /* Try to setup for software single stepping over the specified location.
1702 Return 1 if target_resume() should use hardware single step.
1704 GDBARCH the current gdbarch.
1705 PC the location to step over. */
1708 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1712 if (execution_direction
== EXEC_FORWARD
1713 && gdbarch_software_single_step_p (gdbarch
)
1714 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1717 /* Do not pull these breakpoints until after a `wait' in
1718 `wait_for_inferior'. */
1719 singlestep_breakpoints_inserted_p
= 1;
1720 singlestep_ptid
= inferior_ptid
;
1726 /* Return a ptid representing the set of threads that we will proceed,
1727 in the perspective of the user/frontend. We may actually resume
1728 fewer threads at first, e.g., if a thread is stopped at a
1729 breakpoint that needs stepping-off, but that should not be visible
1730 to the user/frontend, and neither should the frontend/user be
1731 allowed to proceed any of the threads that happen to be stopped for
1732 internal run control handling, if a previous command wanted them
1736 user_visible_resume_ptid (int step
)
1738 /* By default, resume all threads of all processes. */
1739 ptid_t resume_ptid
= RESUME_ALL
;
1741 /* Maybe resume only all threads of the current process. */
1742 if (!sched_multi
&& target_supports_multi_process ())
1744 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1747 /* Maybe resume a single thread after all. */
1750 /* With non-stop mode on, threads are always handled
1752 resume_ptid
= inferior_ptid
;
1754 else if ((scheduler_mode
== schedlock_on
)
1755 || (scheduler_mode
== schedlock_step
1756 && (step
|| singlestep_breakpoints_inserted_p
)))
1758 /* User-settable 'scheduler' mode requires solo thread resume. */
1759 resume_ptid
= inferior_ptid
;
1765 /* Resume the inferior, but allow a QUIT. This is useful if the user
1766 wants to interrupt some lengthy single-stepping operation
1767 (for child processes, the SIGINT goes to the inferior, and so
1768 we get a SIGINT random_signal, but for remote debugging and perhaps
1769 other targets, that's not true).
1771 STEP nonzero if we should step (zero to continue instead).
1772 SIG is the signal to give the inferior (zero for none). */
1774 resume (int step
, enum gdb_signal sig
)
1776 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1777 struct regcache
*regcache
= get_current_regcache ();
1778 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1779 struct thread_info
*tp
= inferior_thread ();
1780 CORE_ADDR pc
= regcache_read_pc (regcache
);
1781 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1787 if (current_inferior ()->waiting_for_vfork_done
)
1789 /* Don't try to single-step a vfork parent that is waiting for
1790 the child to get out of the shared memory region (by exec'ing
1791 or exiting). This is particularly important on software
1792 single-step archs, as the child process would trip on the
1793 software single step breakpoint inserted for the parent
1794 process. Since the parent will not actually execute any
1795 instruction until the child is out of the shared region (such
1796 are vfork's semantics), it is safe to simply continue it.
1797 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1798 the parent, and tell it to `keep_going', which automatically
1799 re-sets it stepping. */
1801 fprintf_unfiltered (gdb_stdlog
,
1802 "infrun: resume : clear step\n");
1807 fprintf_unfiltered (gdb_stdlog
,
1808 "infrun: resume (step=%d, signal=%s), "
1809 "trap_expected=%d, current thread [%s] at %s\n",
1810 step
, gdb_signal_to_symbol_string (sig
),
1811 tp
->control
.trap_expected
,
1812 target_pid_to_str (inferior_ptid
),
1813 paddress (gdbarch
, pc
));
1815 /* Normally, by the time we reach `resume', the breakpoints are either
1816 removed or inserted, as appropriate. The exception is if we're sitting
1817 at a permanent breakpoint; we need to step over it, but permanent
1818 breakpoints can't be removed. So we have to test for it here. */
1819 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
1821 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1822 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1825 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1826 how to step past a permanent breakpoint on this architecture. Try using\n\
1827 a command like `return' or `jump' to continue execution."));
1830 /* If we have a breakpoint to step over, make sure to do a single
1831 step only. Same if we have software watchpoints. */
1832 if (tp
->control
.trap_expected
|| bpstat_should_step ())
1833 tp
->control
.may_range_step
= 0;
1835 /* If enabled, step over breakpoints by executing a copy of the
1836 instruction at a different address.
1838 We can't use displaced stepping when we have a signal to deliver;
1839 the comments for displaced_step_prepare explain why. The
1840 comments in the handle_inferior event for dealing with 'random
1841 signals' explain what we do instead.
1843 We can't use displaced stepping when we are waiting for vfork_done
1844 event, displaced stepping breaks the vfork child similarly as single
1845 step software breakpoint. */
1846 if (use_displaced_stepping (gdbarch
)
1847 && (tp
->control
.trap_expected
1848 || (hw_step
&& gdbarch_software_single_step_p (gdbarch
)))
1849 && sig
== GDB_SIGNAL_0
1850 && !current_inferior ()->waiting_for_vfork_done
)
1852 struct displaced_step_inferior_state
*displaced
;
1854 if (!displaced_step_prepare (inferior_ptid
))
1856 /* Got placed in displaced stepping queue. Will be resumed
1857 later when all the currently queued displaced stepping
1858 requests finish. The thread is not executing at this
1859 point, and the call to set_executing will be made later.
1860 But we need to call set_running here, since from the
1861 user/frontend's point of view, threads were set running.
1862 Unless we're calling an inferior function, as in that
1863 case we pretend the inferior doesn't run at all. */
1864 if (!tp
->control
.in_infcall
)
1865 set_running (user_visible_resume_ptid (step
), 1);
1866 discard_cleanups (old_cleanups
);
1870 /* Update pc to reflect the new address from which we will execute
1871 instructions due to displaced stepping. */
1872 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
1874 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1875 hw_step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
1876 displaced
->step_closure
);
1879 /* Do we need to do it the hard way, w/temp breakpoints? */
1881 step
= maybe_software_singlestep (gdbarch
, pc
);
1883 /* Currently, our software single-step implementation leads to different
1884 results than hardware single-stepping in one situation: when stepping
1885 into delivering a signal which has an associated signal handler,
1886 hardware single-step will stop at the first instruction of the handler,
1887 while software single-step will simply skip execution of the handler.
1889 For now, this difference in behavior is accepted since there is no
1890 easy way to actually implement single-stepping into a signal handler
1891 without kernel support.
1893 However, there is one scenario where this difference leads to follow-on
1894 problems: if we're stepping off a breakpoint by removing all breakpoints
1895 and then single-stepping. In this case, the software single-step
1896 behavior means that even if there is a *breakpoint* in the signal
1897 handler, GDB still would not stop.
1899 Fortunately, we can at least fix this particular issue. We detect
1900 here the case where we are about to deliver a signal while software
1901 single-stepping with breakpoints removed. In this situation, we
1902 revert the decisions to remove all breakpoints and insert single-
1903 step breakpoints, and instead we install a step-resume breakpoint
1904 at the current address, deliver the signal without stepping, and
1905 once we arrive back at the step-resume breakpoint, actually step
1906 over the breakpoint we originally wanted to step over. */
1907 if (singlestep_breakpoints_inserted_p
1908 && tp
->control
.trap_expected
&& sig
!= GDB_SIGNAL_0
)
1910 /* If we have nested signals or a pending signal is delivered
1911 immediately after a handler returns, might might already have
1912 a step-resume breakpoint set on the earlier handler. We cannot
1913 set another step-resume breakpoint; just continue on until the
1914 original breakpoint is hit. */
1915 if (tp
->control
.step_resume_breakpoint
== NULL
)
1917 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1918 tp
->step_after_step_resume_breakpoint
= 1;
1921 remove_single_step_breakpoints ();
1922 singlestep_breakpoints_inserted_p
= 0;
1924 clear_step_over_info ();
1925 tp
->control
.trap_expected
= 0;
1927 insert_breakpoints ();
1930 /* If STEP is set, it's a request to use hardware stepping
1931 facilities. But in that case, we should never
1932 use singlestep breakpoint. */
1933 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1935 /* Decide the set of threads to ask the target to resume. Start
1936 by assuming everything will be resumed, than narrow the set
1937 by applying increasingly restricting conditions. */
1938 resume_ptid
= user_visible_resume_ptid (step
);
1940 /* Even if RESUME_PTID is a wildcard, and we end up resuming less
1941 (e.g., we might need to step over a breakpoint), from the
1942 user/frontend's point of view, all threads in RESUME_PTID are now
1943 running. Unless we're calling an inferior function, as in that
1944 case pretend we inferior doesn't run at all. */
1945 if (!tp
->control
.in_infcall
)
1946 set_running (resume_ptid
, 1);
1948 /* Maybe resume a single thread after all. */
1949 if ((step
|| singlestep_breakpoints_inserted_p
)
1950 && tp
->control
.trap_expected
)
1952 /* We're allowing a thread to run past a breakpoint it has
1953 hit, by single-stepping the thread with the breakpoint
1954 removed. In which case, we need to single-step only this
1955 thread, and keep others stopped, as they can miss this
1956 breakpoint if allowed to run. */
1957 resume_ptid
= inferior_ptid
;
1960 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1962 /* Most targets can step a breakpoint instruction, thus
1963 executing it normally. But if this one cannot, just
1964 continue and we will hit it anyway. */
1965 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
1970 && use_displaced_stepping (gdbarch
)
1971 && tp
->control
.trap_expected
)
1973 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1974 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1975 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1978 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1979 paddress (resume_gdbarch
, actual_pc
));
1980 read_memory (actual_pc
, buf
, sizeof (buf
));
1981 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1984 if (tp
->control
.may_range_step
)
1986 /* If we're resuming a thread with the PC out of the step
1987 range, then we're doing some nested/finer run control
1988 operation, like stepping the thread out of the dynamic
1989 linker or the displaced stepping scratch pad. We
1990 shouldn't have allowed a range step then. */
1991 gdb_assert (pc_in_thread_step_range (pc
, tp
));
1994 /* Install inferior's terminal modes. */
1995 target_terminal_inferior ();
1997 /* Avoid confusing the next resume, if the next stop/resume
1998 happens to apply to another thread. */
1999 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2001 /* Advise target which signals may be handled silently. If we have
2002 removed breakpoints because we are stepping over one (which can
2003 happen only if we are not using displaced stepping), we need to
2004 receive all signals to avoid accidentally skipping a breakpoint
2005 during execution of a signal handler. */
2006 if ((step
|| singlestep_breakpoints_inserted_p
)
2007 && tp
->control
.trap_expected
2008 && !use_displaced_stepping (gdbarch
))
2009 target_pass_signals (0, NULL
);
2011 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
2013 target_resume (resume_ptid
, step
, sig
);
2015 discard_cleanups (old_cleanups
);
2020 /* Clear out all variables saying what to do when inferior is continued.
2021 First do this, then set the ones you want, then call `proceed'. */
2024 clear_proceed_status_thread (struct thread_info
*tp
)
2027 fprintf_unfiltered (gdb_stdlog
,
2028 "infrun: clear_proceed_status_thread (%s)\n",
2029 target_pid_to_str (tp
->ptid
));
2031 tp
->control
.trap_expected
= 0;
2032 tp
->control
.step_range_start
= 0;
2033 tp
->control
.step_range_end
= 0;
2034 tp
->control
.may_range_step
= 0;
2035 tp
->control
.step_frame_id
= null_frame_id
;
2036 tp
->control
.step_stack_frame_id
= null_frame_id
;
2037 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2038 tp
->stop_requested
= 0;
2040 tp
->control
.stop_step
= 0;
2042 tp
->control
.proceed_to_finish
= 0;
2044 tp
->control
.command_interp
= NULL
;
2046 /* Discard any remaining commands or status from previous stop. */
2047 bpstat_clear (&tp
->control
.stop_bpstat
);
2051 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
2053 if (is_exited (tp
->ptid
))
2056 clear_proceed_status_thread (tp
);
2061 clear_proceed_status (void)
2065 /* In all-stop mode, delete the per-thread status of all
2066 threads, even if inferior_ptid is null_ptid, there may be
2067 threads on the list. E.g., we may be launching a new
2068 process, while selecting the executable. */
2069 iterate_over_threads (clear_proceed_status_callback
, NULL
);
2072 if (!ptid_equal (inferior_ptid
, null_ptid
))
2074 struct inferior
*inferior
;
2078 /* If in non-stop mode, only delete the per-thread status of
2079 the current thread. */
2080 clear_proceed_status_thread (inferior_thread ());
2083 inferior
= current_inferior ();
2084 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2087 stop_after_trap
= 0;
2089 clear_step_over_info ();
2091 observer_notify_about_to_proceed ();
2095 regcache_xfree (stop_registers
);
2096 stop_registers
= NULL
;
2100 /* Returns true if TP is still stopped at a breakpoint that needs
2101 stepping-over in order to make progress. If the breakpoint is gone
2102 meanwhile, we can skip the whole step-over dance. */
2105 thread_still_needs_step_over (struct thread_info
*tp
)
2107 if (tp
->stepping_over_breakpoint
)
2109 struct regcache
*regcache
= get_thread_regcache (tp
->ptid
);
2111 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2112 regcache_read_pc (regcache
)))
2115 tp
->stepping_over_breakpoint
= 0;
2121 /* Returns true if scheduler locking applies. STEP indicates whether
2122 we're about to do a step/next-like command to a thread. */
2125 schedlock_applies (int step
)
2127 return (scheduler_mode
== schedlock_on
2128 || (scheduler_mode
== schedlock_step
2132 /* Look a thread other than EXCEPT that has previously reported a
2133 breakpoint event, and thus needs a step-over in order to make
2134 progress. Returns NULL is none is found. STEP indicates whether
2135 we're about to step the current thread, in order to decide whether
2136 "set scheduler-locking step" applies. */
2138 static struct thread_info
*
2139 find_thread_needs_step_over (int step
, struct thread_info
*except
)
2141 struct thread_info
*tp
, *current
;
2143 /* With non-stop mode on, threads are always handled individually. */
2144 gdb_assert (! non_stop
);
2146 current
= inferior_thread ();
2148 /* If scheduler locking applies, we can avoid iterating over all
2150 if (schedlock_applies (step
))
2152 if (except
!= current
2153 && thread_still_needs_step_over (current
))
2161 /* Ignore the EXCEPT thread. */
2164 /* Ignore threads of processes we're not resuming. */
2166 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
2169 if (thread_still_needs_step_over (tp
))
2176 /* Basic routine for continuing the program in various fashions.
2178 ADDR is the address to resume at, or -1 for resume where stopped.
2179 SIGGNAL is the signal to give it, or 0 for none,
2180 or -1 for act according to how it stopped.
2181 STEP is nonzero if should trap after one instruction.
2182 -1 means return after that and print nothing.
2183 You should probably set various step_... variables
2184 before calling here, if you are stepping.
2186 You should call clear_proceed_status before calling proceed. */
2189 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
, int step
)
2191 struct regcache
*regcache
;
2192 struct gdbarch
*gdbarch
;
2193 struct thread_info
*tp
;
2195 struct address_space
*aspace
;
2197 /* If we're stopped at a fork/vfork, follow the branch set by the
2198 "set follow-fork-mode" command; otherwise, we'll just proceed
2199 resuming the current thread. */
2200 if (!follow_fork ())
2202 /* The target for some reason decided not to resume. */
2204 if (target_can_async_p ())
2205 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2209 /* We'll update this if & when we switch to a new thread. */
2210 previous_inferior_ptid
= inferior_ptid
;
2212 regcache
= get_current_regcache ();
2213 gdbarch
= get_regcache_arch (regcache
);
2214 aspace
= get_regcache_aspace (regcache
);
2215 pc
= regcache_read_pc (regcache
);
2216 tp
= inferior_thread ();
2219 step_start_function
= find_pc_function (pc
);
2221 stop_after_trap
= 1;
2223 /* Fill in with reasonable starting values. */
2224 init_thread_stepping_state (tp
);
2226 if (addr
== (CORE_ADDR
) -1)
2228 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
2229 && execution_direction
!= EXEC_REVERSE
)
2230 /* There is a breakpoint at the address we will resume at,
2231 step one instruction before inserting breakpoints so that
2232 we do not stop right away (and report a second hit at this
2235 Note, we don't do this in reverse, because we won't
2236 actually be executing the breakpoint insn anyway.
2237 We'll be (un-)executing the previous instruction. */
2238 tp
->stepping_over_breakpoint
= 1;
2239 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2240 && gdbarch_single_step_through_delay (gdbarch
,
2241 get_current_frame ()))
2242 /* We stepped onto an instruction that needs to be stepped
2243 again before re-inserting the breakpoint, do so. */
2244 tp
->stepping_over_breakpoint
= 1;
2248 regcache_write_pc (regcache
, addr
);
2251 /* Record the interpreter that issued the execution command that
2252 caused this thread to resume. If the top level interpreter is
2253 MI/async, and the execution command was a CLI command
2254 (next/step/etc.), we'll want to print stop event output to the MI
2255 console channel (the stepped-to line, etc.), as if the user
2256 entered the execution command on a real GDB console. */
2257 inferior_thread ()->control
.command_interp
= command_interp ();
2260 fprintf_unfiltered (gdb_stdlog
,
2261 "infrun: proceed (addr=%s, signal=%s, step=%d)\n",
2262 paddress (gdbarch
, addr
),
2263 gdb_signal_to_symbol_string (siggnal
), step
);
2266 /* In non-stop, each thread is handled individually. The context
2267 must already be set to the right thread here. */
2271 struct thread_info
*step_over
;
2273 /* In a multi-threaded task we may select another thread and
2274 then continue or step.
2276 But if the old thread was stopped at a breakpoint, it will
2277 immediately cause another breakpoint stop without any
2278 execution (i.e. it will report a breakpoint hit incorrectly).
2279 So we must step over it first.
2281 Look for a thread other than the current (TP) that reported a
2282 breakpoint hit and hasn't been resumed yet since. */
2283 step_over
= find_thread_needs_step_over (step
, tp
);
2284 if (step_over
!= NULL
)
2287 fprintf_unfiltered (gdb_stdlog
,
2288 "infrun: need to step-over [%s] first\n",
2289 target_pid_to_str (step_over
->ptid
));
2291 /* Store the prev_pc for the stepping thread too, needed by
2292 switch_back_to_stepping thread. */
2293 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2294 switch_to_thread (step_over
->ptid
);
2299 /* If we need to step over a breakpoint, and we're not using
2300 displaced stepping to do so, insert all breakpoints (watchpoints,
2301 etc.) but the one we're stepping over, step one instruction, and
2302 then re-insert the breakpoint when that step is finished. */
2303 if (tp
->stepping_over_breakpoint
&& !use_displaced_stepping (gdbarch
))
2305 struct regcache
*regcache
= get_current_regcache ();
2307 set_step_over_info (get_regcache_aspace (regcache
),
2308 regcache_read_pc (regcache
));
2311 clear_step_over_info ();
2313 insert_breakpoints ();
2315 tp
->control
.trap_expected
= tp
->stepping_over_breakpoint
;
2319 /* Pass the last stop signal to the thread we're resuming,
2320 irrespective of whether the current thread is the thread that
2321 got the last event or not. This was historically GDB's
2322 behaviour before keeping a stop_signal per thread. */
2324 struct thread_info
*last_thread
;
2326 struct target_waitstatus last_status
;
2328 get_last_target_status (&last_ptid
, &last_status
);
2329 if (!ptid_equal (inferior_ptid
, last_ptid
)
2330 && !ptid_equal (last_ptid
, null_ptid
)
2331 && !ptid_equal (last_ptid
, minus_one_ptid
))
2333 last_thread
= find_thread_ptid (last_ptid
);
2336 tp
->suspend
.stop_signal
= last_thread
->suspend
.stop_signal
;
2337 last_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2342 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2343 tp
->suspend
.stop_signal
= siggnal
;
2344 /* If this signal should not be seen by program,
2345 give it zero. Used for debugging signals. */
2346 else if (!signal_program
[tp
->suspend
.stop_signal
])
2347 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2349 annotate_starting ();
2351 /* Make sure that output from GDB appears before output from the
2353 gdb_flush (gdb_stdout
);
2355 /* Refresh prev_pc value just prior to resuming. This used to be
2356 done in stop_stepping, however, setting prev_pc there did not handle
2357 scenarios such as inferior function calls or returning from
2358 a function via the return command. In those cases, the prev_pc
2359 value was not set properly for subsequent commands. The prev_pc value
2360 is used to initialize the starting line number in the ecs. With an
2361 invalid value, the gdb next command ends up stopping at the position
2362 represented by the next line table entry past our start position.
2363 On platforms that generate one line table entry per line, this
2364 is not a problem. However, on the ia64, the compiler generates
2365 extraneous line table entries that do not increase the line number.
2366 When we issue the gdb next command on the ia64 after an inferior call
2367 or a return command, we often end up a few instructions forward, still
2368 within the original line we started.
2370 An attempt was made to refresh the prev_pc at the same time the
2371 execution_control_state is initialized (for instance, just before
2372 waiting for an inferior event). But this approach did not work
2373 because of platforms that use ptrace, where the pc register cannot
2374 be read unless the inferior is stopped. At that point, we are not
2375 guaranteed the inferior is stopped and so the regcache_read_pc() call
2376 can fail. Setting the prev_pc value here ensures the value is updated
2377 correctly when the inferior is stopped. */
2378 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2380 /* Reset to normal state. */
2381 init_infwait_state ();
2383 /* Resume inferior. */
2384 resume (tp
->control
.trap_expected
|| step
|| bpstat_should_step (),
2385 tp
->suspend
.stop_signal
);
2387 /* Wait for it to stop (if not standalone)
2388 and in any case decode why it stopped, and act accordingly. */
2389 /* Do this only if we are not using the event loop, or if the target
2390 does not support asynchronous execution. */
2391 if (!target_can_async_p ())
2393 wait_for_inferior ();
2399 /* Start remote-debugging of a machine over a serial link. */
2402 start_remote (int from_tty
)
2404 struct inferior
*inferior
;
2406 inferior
= current_inferior ();
2407 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2409 /* Always go on waiting for the target, regardless of the mode. */
2410 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2411 indicate to wait_for_inferior that a target should timeout if
2412 nothing is returned (instead of just blocking). Because of this,
2413 targets expecting an immediate response need to, internally, set
2414 things up so that the target_wait() is forced to eventually
2416 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2417 differentiate to its caller what the state of the target is after
2418 the initial open has been performed. Here we're assuming that
2419 the target has stopped. It should be possible to eventually have
2420 target_open() return to the caller an indication that the target
2421 is currently running and GDB state should be set to the same as
2422 for an async run. */
2423 wait_for_inferior ();
2425 /* Now that the inferior has stopped, do any bookkeeping like
2426 loading shared libraries. We want to do this before normal_stop,
2427 so that the displayed frame is up to date. */
2428 post_create_inferior (¤t_target
, from_tty
);
2433 /* Initialize static vars when a new inferior begins. */
2436 init_wait_for_inferior (void)
2438 /* These are meaningless until the first time through wait_for_inferior. */
2440 breakpoint_init_inferior (inf_starting
);
2442 clear_proceed_status ();
2444 target_last_wait_ptid
= minus_one_ptid
;
2446 previous_inferior_ptid
= inferior_ptid
;
2447 init_infwait_state ();
2449 /* Discard any skipped inlined frames. */
2450 clear_inline_frame_state (minus_one_ptid
);
2452 singlestep_ptid
= null_ptid
;
2457 /* This enum encodes possible reasons for doing a target_wait, so that
2458 wfi can call target_wait in one place. (Ultimately the call will be
2459 moved out of the infinite loop entirely.) */
2463 infwait_normal_state
,
2464 infwait_step_watch_state
,
2465 infwait_nonstep_watch_state
2468 /* The PTID we'll do a target_wait on.*/
2471 /* Current inferior wait state. */
2472 static enum infwait_states infwait_state
;
2474 /* Data to be passed around while handling an event. This data is
2475 discarded between events. */
2476 struct execution_control_state
2479 /* The thread that got the event, if this was a thread event; NULL
2481 struct thread_info
*event_thread
;
2483 struct target_waitstatus ws
;
2484 int stop_func_filled_in
;
2485 CORE_ADDR stop_func_start
;
2486 CORE_ADDR stop_func_end
;
2487 const char *stop_func_name
;
2490 /* We were in infwait_step_watch_state or
2491 infwait_nonstep_watch_state state, and the thread reported an
2493 int stepped_after_stopped_by_watchpoint
;
2495 /* True if the event thread hit the single-step breakpoint of
2496 another thread. Thus the event doesn't cause a stop, the thread
2497 needs to be single-stepped past the single-step breakpoint before
2498 we can switch back to the original stepping thread. */
2499 int hit_singlestep_breakpoint
;
2502 static void handle_inferior_event (struct execution_control_state
*ecs
);
2504 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2505 struct execution_control_state
*ecs
);
2506 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2507 struct execution_control_state
*ecs
);
2508 static void handle_signal_stop (struct execution_control_state
*ecs
);
2509 static void check_exception_resume (struct execution_control_state
*,
2510 struct frame_info
*);
2512 static void stop_stepping (struct execution_control_state
*ecs
);
2513 static void prepare_to_wait (struct execution_control_state
*ecs
);
2514 static void keep_going (struct execution_control_state
*ecs
);
2515 static void process_event_stop_test (struct execution_control_state
*ecs
);
2516 static int switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
2518 /* Callback for iterate over threads. If the thread is stopped, but
2519 the user/frontend doesn't know about that yet, go through
2520 normal_stop, as if the thread had just stopped now. ARG points at
2521 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2522 ptid_is_pid(PTID) is true, applies to all threads of the process
2523 pointed at by PTID. Otherwise, apply only to the thread pointed by
2527 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2529 ptid_t ptid
= * (ptid_t
*) arg
;
2531 if ((ptid_equal (info
->ptid
, ptid
)
2532 || ptid_equal (minus_one_ptid
, ptid
)
2533 || (ptid_is_pid (ptid
)
2534 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2535 && is_running (info
->ptid
)
2536 && !is_executing (info
->ptid
))
2538 struct cleanup
*old_chain
;
2539 struct execution_control_state ecss
;
2540 struct execution_control_state
*ecs
= &ecss
;
2542 memset (ecs
, 0, sizeof (*ecs
));
2544 old_chain
= make_cleanup_restore_current_thread ();
2546 overlay_cache_invalid
= 1;
2547 /* Flush target cache before starting to handle each event.
2548 Target was running and cache could be stale. This is just a
2549 heuristic. Running threads may modify target memory, but we
2550 don't get any event. */
2551 target_dcache_invalidate ();
2553 /* Go through handle_inferior_event/normal_stop, so we always
2554 have consistent output as if the stop event had been
2556 ecs
->ptid
= info
->ptid
;
2557 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2558 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2559 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2561 handle_inferior_event (ecs
);
2563 if (!ecs
->wait_some_more
)
2565 struct thread_info
*tp
;
2569 /* Finish off the continuations. */
2570 tp
= inferior_thread ();
2571 do_all_intermediate_continuations_thread (tp
, 1);
2572 do_all_continuations_thread (tp
, 1);
2575 do_cleanups (old_chain
);
2581 /* This function is attached as a "thread_stop_requested" observer.
2582 Cleanup local state that assumed the PTID was to be resumed, and
2583 report the stop to the frontend. */
2586 infrun_thread_stop_requested (ptid_t ptid
)
2588 struct displaced_step_inferior_state
*displaced
;
2590 /* PTID was requested to stop. Remove it from the displaced
2591 stepping queue, so we don't try to resume it automatically. */
2593 for (displaced
= displaced_step_inferior_states
;
2595 displaced
= displaced
->next
)
2597 struct displaced_step_request
*it
, **prev_next_p
;
2599 it
= displaced
->step_request_queue
;
2600 prev_next_p
= &displaced
->step_request_queue
;
2603 if (ptid_match (it
->ptid
, ptid
))
2605 *prev_next_p
= it
->next
;
2611 prev_next_p
= &it
->next
;
2618 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2622 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2624 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2625 nullify_last_target_wait_ptid ();
2628 /* Callback for iterate_over_threads. */
2631 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2633 if (is_exited (info
->ptid
))
2636 delete_step_resume_breakpoint (info
);
2637 delete_exception_resume_breakpoint (info
);
2641 /* In all-stop, delete the step resume breakpoint of any thread that
2642 had one. In non-stop, delete the step resume breakpoint of the
2643 thread that just stopped. */
2646 delete_step_thread_step_resume_breakpoint (void)
2648 if (!target_has_execution
2649 || ptid_equal (inferior_ptid
, null_ptid
))
2650 /* If the inferior has exited, we have already deleted the step
2651 resume breakpoints out of GDB's lists. */
2656 /* If in non-stop mode, only delete the step-resume or
2657 longjmp-resume breakpoint of the thread that just stopped
2659 struct thread_info
*tp
= inferior_thread ();
2661 delete_step_resume_breakpoint (tp
);
2662 delete_exception_resume_breakpoint (tp
);
2665 /* In all-stop mode, delete all step-resume and longjmp-resume
2666 breakpoints of any thread that had them. */
2667 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2670 /* A cleanup wrapper. */
2673 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2675 delete_step_thread_step_resume_breakpoint ();
2678 /* Pretty print the results of target_wait, for debugging purposes. */
2681 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2682 const struct target_waitstatus
*ws
)
2684 char *status_string
= target_waitstatus_to_string (ws
);
2685 struct ui_file
*tmp_stream
= mem_fileopen ();
2688 /* The text is split over several lines because it was getting too long.
2689 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2690 output as a unit; we want only one timestamp printed if debug_timestamp
2693 fprintf_unfiltered (tmp_stream
,
2694 "infrun: target_wait (%d", ptid_get_pid (waiton_ptid
));
2695 if (ptid_get_pid (waiton_ptid
) != -1)
2696 fprintf_unfiltered (tmp_stream
,
2697 " [%s]", target_pid_to_str (waiton_ptid
));
2698 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2699 fprintf_unfiltered (tmp_stream
,
2700 "infrun: %d [%s],\n",
2701 ptid_get_pid (result_ptid
),
2702 target_pid_to_str (result_ptid
));
2703 fprintf_unfiltered (tmp_stream
,
2707 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2709 /* This uses %s in part to handle %'s in the text, but also to avoid
2710 a gcc error: the format attribute requires a string literal. */
2711 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2713 xfree (status_string
);
2715 ui_file_delete (tmp_stream
);
2718 /* Prepare and stabilize the inferior for detaching it. E.g.,
2719 detaching while a thread is displaced stepping is a recipe for
2720 crashing it, as nothing would readjust the PC out of the scratch
2724 prepare_for_detach (void)
2726 struct inferior
*inf
= current_inferior ();
2727 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
2728 struct cleanup
*old_chain_1
;
2729 struct displaced_step_inferior_state
*displaced
;
2731 displaced
= get_displaced_stepping_state (inf
->pid
);
2733 /* Is any thread of this process displaced stepping? If not,
2734 there's nothing else to do. */
2735 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
2739 fprintf_unfiltered (gdb_stdlog
,
2740 "displaced-stepping in-process while detaching");
2742 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
2745 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
2747 struct cleanup
*old_chain_2
;
2748 struct execution_control_state ecss
;
2749 struct execution_control_state
*ecs
;
2752 memset (ecs
, 0, sizeof (*ecs
));
2754 overlay_cache_invalid
= 1;
2755 /* Flush target cache before starting to handle each event.
2756 Target was running and cache could be stale. This is just a
2757 heuristic. Running threads may modify target memory, but we
2758 don't get any event. */
2759 target_dcache_invalidate ();
2761 if (deprecated_target_wait_hook
)
2762 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
2764 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
2767 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
2769 /* If an error happens while handling the event, propagate GDB's
2770 knowledge of the executing state to the frontend/user running
2772 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
2775 /* Now figure out what to do with the result of the result. */
2776 handle_inferior_event (ecs
);
2778 /* No error, don't finish the state yet. */
2779 discard_cleanups (old_chain_2
);
2781 /* Breakpoints and watchpoints are not installed on the target
2782 at this point, and signals are passed directly to the
2783 inferior, so this must mean the process is gone. */
2784 if (!ecs
->wait_some_more
)
2786 discard_cleanups (old_chain_1
);
2787 error (_("Program exited while detaching"));
2791 discard_cleanups (old_chain_1
);
2794 /* Wait for control to return from inferior to debugger.
2796 If inferior gets a signal, we may decide to start it up again
2797 instead of returning. That is why there is a loop in this function.
2798 When this function actually returns it means the inferior
2799 should be left stopped and GDB should read more commands. */
2802 wait_for_inferior (void)
2804 struct cleanup
*old_cleanups
;
2808 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
2811 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
2815 struct execution_control_state ecss
;
2816 struct execution_control_state
*ecs
= &ecss
;
2817 struct cleanup
*old_chain
;
2819 memset (ecs
, 0, sizeof (*ecs
));
2821 overlay_cache_invalid
= 1;
2823 /* Flush target cache before starting to handle each event.
2824 Target was running and cache could be stale. This is just a
2825 heuristic. Running threads may modify target memory, but we
2826 don't get any event. */
2827 target_dcache_invalidate ();
2829 if (deprecated_target_wait_hook
)
2830 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2832 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2835 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2837 /* If an error happens while handling the event, propagate GDB's
2838 knowledge of the executing state to the frontend/user running
2840 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2842 /* Now figure out what to do with the result of the result. */
2843 handle_inferior_event (ecs
);
2845 /* No error, don't finish the state yet. */
2846 discard_cleanups (old_chain
);
2848 if (!ecs
->wait_some_more
)
2852 do_cleanups (old_cleanups
);
2855 /* Asynchronous version of wait_for_inferior. It is called by the
2856 event loop whenever a change of state is detected on the file
2857 descriptor corresponding to the target. It can be called more than
2858 once to complete a single execution command. In such cases we need
2859 to keep the state in a global variable ECSS. If it is the last time
2860 that this function is called for a single execution command, then
2861 report to the user that the inferior has stopped, and do the
2862 necessary cleanups. */
2865 fetch_inferior_event (void *client_data
)
2867 struct execution_control_state ecss
;
2868 struct execution_control_state
*ecs
= &ecss
;
2869 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2870 struct cleanup
*ts_old_chain
;
2871 int was_sync
= sync_execution
;
2874 memset (ecs
, 0, sizeof (*ecs
));
2876 /* We're handling a live event, so make sure we're doing live
2877 debugging. If we're looking at traceframes while the target is
2878 running, we're going to need to get back to that mode after
2879 handling the event. */
2882 make_cleanup_restore_current_traceframe ();
2883 set_current_traceframe (-1);
2887 /* In non-stop mode, the user/frontend should not notice a thread
2888 switch due to internal events. Make sure we reverse to the
2889 user selected thread and frame after handling the event and
2890 running any breakpoint commands. */
2891 make_cleanup_restore_current_thread ();
2893 overlay_cache_invalid
= 1;
2894 /* Flush target cache before starting to handle each event. Target
2895 was running and cache could be stale. This is just a heuristic.
2896 Running threads may modify target memory, but we don't get any
2898 target_dcache_invalidate ();
2900 make_cleanup_restore_integer (&execution_direction
);
2901 execution_direction
= target_execution_direction ();
2903 if (deprecated_target_wait_hook
)
2905 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2907 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2910 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2912 /* If an error happens while handling the event, propagate GDB's
2913 knowledge of the executing state to the frontend/user running
2916 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2918 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2920 /* Get executed before make_cleanup_restore_current_thread above to apply
2921 still for the thread which has thrown the exception. */
2922 make_bpstat_clear_actions_cleanup ();
2924 /* Now figure out what to do with the result of the result. */
2925 handle_inferior_event (ecs
);
2927 if (!ecs
->wait_some_more
)
2929 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2931 delete_step_thread_step_resume_breakpoint ();
2933 /* We may not find an inferior if this was a process exit. */
2934 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
2937 if (target_has_execution
2938 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
2939 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2940 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2941 && ecs
->event_thread
->step_multi
2942 && ecs
->event_thread
->control
.stop_step
)
2943 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2946 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2951 /* No error, don't finish the thread states yet. */
2952 discard_cleanups (ts_old_chain
);
2954 /* Revert thread and frame. */
2955 do_cleanups (old_chain
);
2957 /* If the inferior was in sync execution mode, and now isn't,
2958 restore the prompt (a synchronous execution command has finished,
2959 and we're ready for input). */
2960 if (interpreter_async
&& was_sync
&& !sync_execution
)
2961 display_gdb_prompt (0);
2965 && exec_done_display_p
2966 && (ptid_equal (inferior_ptid
, null_ptid
)
2967 || !is_running (inferior_ptid
)))
2968 printf_unfiltered (_("completed.\n"));
2971 /* Record the frame and location we're currently stepping through. */
2973 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2975 struct thread_info
*tp
= inferior_thread ();
2977 tp
->control
.step_frame_id
= get_frame_id (frame
);
2978 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
2980 tp
->current_symtab
= sal
.symtab
;
2981 tp
->current_line
= sal
.line
;
2984 /* Clear context switchable stepping state. */
2987 init_thread_stepping_state (struct thread_info
*tss
)
2989 tss
->stepping_over_breakpoint
= 0;
2990 tss
->step_after_step_resume_breakpoint
= 0;
2993 /* Set the cached copy of the last ptid/waitstatus. */
2996 set_last_target_status (ptid_t ptid
, struct target_waitstatus status
)
2998 target_last_wait_ptid
= ptid
;
2999 target_last_waitstatus
= status
;
3002 /* Return the cached copy of the last pid/waitstatus returned by
3003 target_wait()/deprecated_target_wait_hook(). The data is actually
3004 cached by handle_inferior_event(), which gets called immediately
3005 after target_wait()/deprecated_target_wait_hook(). */
3008 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
3010 *ptidp
= target_last_wait_ptid
;
3011 *status
= target_last_waitstatus
;
3015 nullify_last_target_wait_ptid (void)
3017 target_last_wait_ptid
= minus_one_ptid
;
3020 /* Switch thread contexts. */
3023 context_switch (ptid_t ptid
)
3025 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
3027 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
3028 target_pid_to_str (inferior_ptid
));
3029 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
3030 target_pid_to_str (ptid
));
3033 switch_to_thread (ptid
);
3037 adjust_pc_after_break (struct execution_control_state
*ecs
)
3039 struct regcache
*regcache
;
3040 struct gdbarch
*gdbarch
;
3041 struct address_space
*aspace
;
3042 CORE_ADDR breakpoint_pc
, decr_pc
;
3044 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3045 we aren't, just return.
3047 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
3048 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3049 implemented by software breakpoints should be handled through the normal
3052 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3053 different signals (SIGILL or SIGEMT for instance), but it is less
3054 clear where the PC is pointing afterwards. It may not match
3055 gdbarch_decr_pc_after_break. I don't know any specific target that
3056 generates these signals at breakpoints (the code has been in GDB since at
3057 least 1992) so I can not guess how to handle them here.
3059 In earlier versions of GDB, a target with
3060 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
3061 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3062 target with both of these set in GDB history, and it seems unlikely to be
3063 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
3065 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
3068 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
3071 /* In reverse execution, when a breakpoint is hit, the instruction
3072 under it has already been de-executed. The reported PC always
3073 points at the breakpoint address, so adjusting it further would
3074 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3077 B1 0x08000000 : INSN1
3078 B2 0x08000001 : INSN2
3080 PC -> 0x08000003 : INSN4
3082 Say you're stopped at 0x08000003 as above. Reverse continuing
3083 from that point should hit B2 as below. Reading the PC when the
3084 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3085 been de-executed already.
3087 B1 0x08000000 : INSN1
3088 B2 PC -> 0x08000001 : INSN2
3092 We can't apply the same logic as for forward execution, because
3093 we would wrongly adjust the PC to 0x08000000, since there's a
3094 breakpoint at PC - 1. We'd then report a hit on B1, although
3095 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3097 if (execution_direction
== EXEC_REVERSE
)
3100 /* If this target does not decrement the PC after breakpoints, then
3101 we have nothing to do. */
3102 regcache
= get_thread_regcache (ecs
->ptid
);
3103 gdbarch
= get_regcache_arch (regcache
);
3105 decr_pc
= target_decr_pc_after_break (gdbarch
);
3109 aspace
= get_regcache_aspace (regcache
);
3111 /* Find the location where (if we've hit a breakpoint) the
3112 breakpoint would be. */
3113 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
3115 /* Check whether there actually is a software breakpoint inserted at
3118 If in non-stop mode, a race condition is possible where we've
3119 removed a breakpoint, but stop events for that breakpoint were
3120 already queued and arrive later. To suppress those spurious
3121 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3122 and retire them after a number of stop events are reported. */
3123 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
3124 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
3126 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
3128 if (record_full_is_used ())
3129 record_full_gdb_operation_disable_set ();
3131 /* When using hardware single-step, a SIGTRAP is reported for both
3132 a completed single-step and a software breakpoint. Need to
3133 differentiate between the two, as the latter needs adjusting
3134 but the former does not.
3136 The SIGTRAP can be due to a completed hardware single-step only if
3137 - we didn't insert software single-step breakpoints
3138 - the thread to be examined is still the current thread
3139 - this thread is currently being stepped
3141 If any of these events did not occur, we must have stopped due
3142 to hitting a software breakpoint, and have to back up to the
3145 As a special case, we could have hardware single-stepped a
3146 software breakpoint. In this case (prev_pc == breakpoint_pc),
3147 we also need to back up to the breakpoint address. */
3149 if (singlestep_breakpoints_inserted_p
3150 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
3151 || !currently_stepping (ecs
->event_thread
)
3152 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
3153 regcache_write_pc (regcache
, breakpoint_pc
);
3155 do_cleanups (old_cleanups
);
3160 init_infwait_state (void)
3162 waiton_ptid
= pid_to_ptid (-1);
3163 infwait_state
= infwait_normal_state
;
3167 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3169 for (frame
= get_prev_frame (frame
);
3171 frame
= get_prev_frame (frame
))
3173 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3175 if (get_frame_type (frame
) != INLINE_FRAME
)
3182 /* Auxiliary function that handles syscall entry/return events.
3183 It returns 1 if the inferior should keep going (and GDB
3184 should ignore the event), or 0 if the event deserves to be
3188 handle_syscall_event (struct execution_control_state
*ecs
)
3190 struct regcache
*regcache
;
3193 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3194 context_switch (ecs
->ptid
);
3196 regcache
= get_thread_regcache (ecs
->ptid
);
3197 syscall_number
= ecs
->ws
.value
.syscall_number
;
3198 stop_pc
= regcache_read_pc (regcache
);
3200 if (catch_syscall_enabled () > 0
3201 && catching_syscall_number (syscall_number
) > 0)
3204 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3207 ecs
->event_thread
->control
.stop_bpstat
3208 = bpstat_stop_status (get_regcache_aspace (regcache
),
3209 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3211 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3213 /* Catchpoint hit. */
3218 /* If no catchpoint triggered for this, then keep going. */
3223 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3226 fill_in_stop_func (struct gdbarch
*gdbarch
,
3227 struct execution_control_state
*ecs
)
3229 if (!ecs
->stop_func_filled_in
)
3231 /* Don't care about return value; stop_func_start and stop_func_name
3232 will both be 0 if it doesn't work. */
3233 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3234 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3235 ecs
->stop_func_start
3236 += gdbarch_deprecated_function_start_offset (gdbarch
);
3238 if (gdbarch_skip_entrypoint_p (gdbarch
))
3239 ecs
->stop_func_start
= gdbarch_skip_entrypoint (gdbarch
,
3240 ecs
->stop_func_start
);
3242 ecs
->stop_func_filled_in
= 1;
3247 /* Return the STOP_SOON field of the inferior pointed at by PTID. */
3249 static enum stop_kind
3250 get_inferior_stop_soon (ptid_t ptid
)
3252 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ptid
));
3254 gdb_assert (inf
!= NULL
);
3255 return inf
->control
.stop_soon
;
3258 /* Given an execution control state that has been freshly filled in by
3259 an event from the inferior, figure out what it means and take
3262 The alternatives are:
3264 1) stop_stepping and return; to really stop and return to the
3267 2) keep_going and return; to wait for the next event (set
3268 ecs->event_thread->stepping_over_breakpoint to 1 to single step
3272 handle_inferior_event (struct execution_control_state
*ecs
)
3274 enum stop_kind stop_soon
;
3276 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3278 /* We had an event in the inferior, but we are not interested in
3279 handling it at this level. The lower layers have already
3280 done what needs to be done, if anything.
3282 One of the possible circumstances for this is when the
3283 inferior produces output for the console. The inferior has
3284 not stopped, and we are ignoring the event. Another possible
3285 circumstance is any event which the lower level knows will be
3286 reported multiple times without an intervening resume. */
3288 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3289 prepare_to_wait (ecs
);
3293 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3294 && target_can_async_p () && !sync_execution
)
3296 /* There were no unwaited-for children left in the target, but,
3297 we're not synchronously waiting for events either. Just
3298 ignore. Otherwise, if we were running a synchronous
3299 execution command, we need to cancel it and give the user
3300 back the terminal. */
3302 fprintf_unfiltered (gdb_stdlog
,
3303 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3304 prepare_to_wait (ecs
);
3308 /* Cache the last pid/waitstatus. */
3309 set_last_target_status (ecs
->ptid
, ecs
->ws
);
3311 /* Always clear state belonging to the previous time we stopped. */
3312 stop_stack_dummy
= STOP_NONE
;
3314 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3316 /* No unwaited-for children left. IOW, all resumed children
3319 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3321 stop_print_frame
= 0;
3322 stop_stepping (ecs
);
3326 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3327 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3329 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3330 /* If it's a new thread, add it to the thread database. */
3331 if (ecs
->event_thread
== NULL
)
3332 ecs
->event_thread
= add_thread (ecs
->ptid
);
3334 /* Disable range stepping. If the next step request could use a
3335 range, this will be end up re-enabled then. */
3336 ecs
->event_thread
->control
.may_range_step
= 0;
3339 /* Dependent on valid ECS->EVENT_THREAD. */
3340 adjust_pc_after_break (ecs
);
3342 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3343 reinit_frame_cache ();
3345 breakpoint_retire_moribund ();
3347 /* First, distinguish signals caused by the debugger from signals
3348 that have to do with the program's own actions. Note that
3349 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3350 on the operating system version. Here we detect when a SIGILL or
3351 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3352 something similar for SIGSEGV, since a SIGSEGV will be generated
3353 when we're trying to execute a breakpoint instruction on a
3354 non-executable stack. This happens for call dummy breakpoints
3355 for architectures like SPARC that place call dummies on the
3357 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3358 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3359 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3360 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3362 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3364 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3365 regcache_read_pc (regcache
)))
3368 fprintf_unfiltered (gdb_stdlog
,
3369 "infrun: Treating signal as SIGTRAP\n");
3370 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3374 /* Mark the non-executing threads accordingly. In all-stop, all
3375 threads of all processes are stopped when we get any event
3376 reported. In non-stop mode, only the event thread stops. If
3377 we're handling a process exit in non-stop mode, there's nothing
3378 to do, as threads of the dead process are gone, and threads of
3379 any other process were left running. */
3381 set_executing (minus_one_ptid
, 0);
3382 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3383 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3384 set_executing (ecs
->ptid
, 0);
3386 switch (infwait_state
)
3388 case infwait_normal_state
:
3390 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
3393 case infwait_step_watch_state
:
3395 fprintf_unfiltered (gdb_stdlog
,
3396 "infrun: infwait_step_watch_state\n");
3398 ecs
->stepped_after_stopped_by_watchpoint
= 1;
3401 case infwait_nonstep_watch_state
:
3403 fprintf_unfiltered (gdb_stdlog
,
3404 "infrun: infwait_nonstep_watch_state\n");
3405 insert_breakpoints ();
3407 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3408 handle things like signals arriving and other things happening
3409 in combination correctly? */
3410 ecs
->stepped_after_stopped_by_watchpoint
= 1;
3414 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3417 infwait_state
= infwait_normal_state
;
3418 waiton_ptid
= pid_to_ptid (-1);
3420 switch (ecs
->ws
.kind
)
3422 case TARGET_WAITKIND_LOADED
:
3424 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3425 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3426 context_switch (ecs
->ptid
);
3427 /* Ignore gracefully during startup of the inferior, as it might
3428 be the shell which has just loaded some objects, otherwise
3429 add the symbols for the newly loaded objects. Also ignore at
3430 the beginning of an attach or remote session; we will query
3431 the full list of libraries once the connection is
3434 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
3435 if (stop_soon
== NO_STOP_QUIETLY
)
3437 struct regcache
*regcache
;
3439 regcache
= get_thread_regcache (ecs
->ptid
);
3441 handle_solib_event ();
3443 ecs
->event_thread
->control
.stop_bpstat
3444 = bpstat_stop_status (get_regcache_aspace (regcache
),
3445 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3447 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3449 /* A catchpoint triggered. */
3450 process_event_stop_test (ecs
);
3454 /* If requested, stop when the dynamic linker notifies
3455 gdb of events. This allows the user to get control
3456 and place breakpoints in initializer routines for
3457 dynamically loaded objects (among other things). */
3458 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3459 if (stop_on_solib_events
)
3461 /* Make sure we print "Stopped due to solib-event" in
3463 stop_print_frame
= 1;
3465 stop_stepping (ecs
);
3470 /* If we are skipping through a shell, or through shared library
3471 loading that we aren't interested in, resume the program. If
3472 we're running the program normally, also resume. */
3473 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3475 /* Loading of shared libraries might have changed breakpoint
3476 addresses. Make sure new breakpoints are inserted. */
3477 if (stop_soon
== NO_STOP_QUIETLY
3478 && !breakpoints_always_inserted_mode ())
3479 insert_breakpoints ();
3480 resume (0, GDB_SIGNAL_0
);
3481 prepare_to_wait (ecs
);
3485 /* But stop if we're attaching or setting up a remote
3487 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3488 || stop_soon
== STOP_QUIETLY_REMOTE
)
3491 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3492 stop_stepping (ecs
);
3496 internal_error (__FILE__
, __LINE__
,
3497 _("unhandled stop_soon: %d"), (int) stop_soon
);
3499 case TARGET_WAITKIND_SPURIOUS
:
3501 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3502 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3503 context_switch (ecs
->ptid
);
3504 resume (0, GDB_SIGNAL_0
);
3505 prepare_to_wait (ecs
);
3508 case TARGET_WAITKIND_EXITED
:
3509 case TARGET_WAITKIND_SIGNALLED
:
3512 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3513 fprintf_unfiltered (gdb_stdlog
,
3514 "infrun: TARGET_WAITKIND_EXITED\n");
3516 fprintf_unfiltered (gdb_stdlog
,
3517 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3520 inferior_ptid
= ecs
->ptid
;
3521 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3522 set_current_program_space (current_inferior ()->pspace
);
3523 handle_vfork_child_exec_or_exit (0);
3524 target_terminal_ours (); /* Must do this before mourn anyway. */
3526 /* Clearing any previous state of convenience variables. */
3527 clear_exit_convenience_vars ();
3529 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3531 /* Record the exit code in the convenience variable $_exitcode, so
3532 that the user can inspect this again later. */
3533 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3534 (LONGEST
) ecs
->ws
.value
.integer
);
3536 /* Also record this in the inferior itself. */
3537 current_inferior ()->has_exit_code
= 1;
3538 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3540 /* Support the --return-child-result option. */
3541 return_child_result_value
= ecs
->ws
.value
.integer
;
3543 print_exited_reason (ecs
->ws
.value
.integer
);
3547 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3548 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3550 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
3552 /* Set the value of the internal variable $_exitsignal,
3553 which holds the signal uncaught by the inferior. */
3554 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
3555 gdbarch_gdb_signal_to_target (gdbarch
,
3556 ecs
->ws
.value
.sig
));
3560 /* We don't have access to the target's method used for
3561 converting between signal numbers (GDB's internal
3562 representation <-> target's representation).
3563 Therefore, we cannot do a good job at displaying this
3564 information to the user. It's better to just warn
3565 her about it (if infrun debugging is enabled), and
3568 fprintf_filtered (gdb_stdlog
, _("\
3569 Cannot fill $_exitsignal with the correct signal number.\n"));
3572 print_signal_exited_reason (ecs
->ws
.value
.sig
);
3575 gdb_flush (gdb_stdout
);
3576 target_mourn_inferior ();
3577 singlestep_breakpoints_inserted_p
= 0;
3578 cancel_single_step_breakpoints ();
3579 stop_print_frame
= 0;
3580 stop_stepping (ecs
);
3583 /* The following are the only cases in which we keep going;
3584 the above cases end in a continue or goto. */
3585 case TARGET_WAITKIND_FORKED
:
3586 case TARGET_WAITKIND_VFORKED
:
3589 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3590 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3592 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3595 /* Check whether the inferior is displaced stepping. */
3597 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3598 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3599 struct displaced_step_inferior_state
*displaced
3600 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3602 /* If checking displaced stepping is supported, and thread
3603 ecs->ptid is displaced stepping. */
3604 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3606 struct inferior
*parent_inf
3607 = find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3608 struct regcache
*child_regcache
;
3609 CORE_ADDR parent_pc
;
3611 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3612 indicating that the displaced stepping of syscall instruction
3613 has been done. Perform cleanup for parent process here. Note
3614 that this operation also cleans up the child process for vfork,
3615 because their pages are shared. */
3616 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3618 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3620 /* Restore scratch pad for child process. */
3621 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3624 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3625 the child's PC is also within the scratchpad. Set the child's PC
3626 to the parent's PC value, which has already been fixed up.
3627 FIXME: we use the parent's aspace here, although we're touching
3628 the child, because the child hasn't been added to the inferior
3629 list yet at this point. */
3632 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
3634 parent_inf
->aspace
);
3635 /* Read PC value of parent process. */
3636 parent_pc
= regcache_read_pc (regcache
);
3638 if (debug_displaced
)
3639 fprintf_unfiltered (gdb_stdlog
,
3640 "displaced: write child pc from %s to %s\n",
3642 regcache_read_pc (child_regcache
)),
3643 paddress (gdbarch
, parent_pc
));
3645 regcache_write_pc (child_regcache
, parent_pc
);
3649 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3650 context_switch (ecs
->ptid
);
3652 /* Immediately detach breakpoints from the child before there's
3653 any chance of letting the user delete breakpoints from the
3654 breakpoint lists. If we don't do this early, it's easy to
3655 leave left over traps in the child, vis: "break foo; catch
3656 fork; c; <fork>; del; c; <child calls foo>". We only follow
3657 the fork on the last `continue', and by that time the
3658 breakpoint at "foo" is long gone from the breakpoint table.
3659 If we vforked, then we don't need to unpatch here, since both
3660 parent and child are sharing the same memory pages; we'll
3661 need to unpatch at follow/detach time instead to be certain
3662 that new breakpoints added between catchpoint hit time and
3663 vfork follow are detached. */
3664 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
3666 /* This won't actually modify the breakpoint list, but will
3667 physically remove the breakpoints from the child. */
3668 detach_breakpoints (ecs
->ws
.value
.related_pid
);
3671 if (singlestep_breakpoints_inserted_p
)
3673 /* Pull the single step breakpoints out of the target. */
3674 remove_single_step_breakpoints ();
3675 singlestep_breakpoints_inserted_p
= 0;
3678 /* In case the event is caught by a catchpoint, remember that
3679 the event is to be followed at the next resume of the thread,
3680 and not immediately. */
3681 ecs
->event_thread
->pending_follow
= ecs
->ws
;
3683 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3685 ecs
->event_thread
->control
.stop_bpstat
3686 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3687 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3689 /* If no catchpoint triggered for this, then keep going. Note
3690 that we're interested in knowing the bpstat actually causes a
3691 stop, not just if it may explain the signal. Software
3692 watchpoints, for example, always appear in the bpstat. */
3693 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3699 = (follow_fork_mode_string
== follow_fork_mode_child
);
3701 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3703 should_resume
= follow_fork ();
3706 child
= ecs
->ws
.value
.related_pid
;
3708 /* In non-stop mode, also resume the other branch. */
3709 if (non_stop
&& !detach_fork
)
3712 switch_to_thread (parent
);
3714 switch_to_thread (child
);
3716 ecs
->event_thread
= inferior_thread ();
3717 ecs
->ptid
= inferior_ptid
;
3722 switch_to_thread (child
);
3724 switch_to_thread (parent
);
3726 ecs
->event_thread
= inferior_thread ();
3727 ecs
->ptid
= inferior_ptid
;
3732 stop_stepping (ecs
);
3735 process_event_stop_test (ecs
);
3738 case TARGET_WAITKIND_VFORK_DONE
:
3739 /* Done with the shared memory region. Re-insert breakpoints in
3740 the parent, and keep going. */
3743 fprintf_unfiltered (gdb_stdlog
,
3744 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3746 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3747 context_switch (ecs
->ptid
);
3749 current_inferior ()->waiting_for_vfork_done
= 0;
3750 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3751 /* This also takes care of reinserting breakpoints in the
3752 previously locked inferior. */
3756 case TARGET_WAITKIND_EXECD
:
3758 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3760 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3761 context_switch (ecs
->ptid
);
3763 singlestep_breakpoints_inserted_p
= 0;
3764 cancel_single_step_breakpoints ();
3766 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3768 /* Do whatever is necessary to the parent branch of the vfork. */
3769 handle_vfork_child_exec_or_exit (1);
3771 /* This causes the eventpoints and symbol table to be reset.
3772 Must do this now, before trying to determine whether to
3774 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3776 ecs
->event_thread
->control
.stop_bpstat
3777 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3778 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3780 /* Note that this may be referenced from inside
3781 bpstat_stop_status above, through inferior_has_execd. */
3782 xfree (ecs
->ws
.value
.execd_pathname
);
3783 ecs
->ws
.value
.execd_pathname
= NULL
;
3785 /* If no catchpoint triggered for this, then keep going. */
3786 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3788 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3792 process_event_stop_test (ecs
);
3795 /* Be careful not to try to gather much state about a thread
3796 that's in a syscall. It's frequently a losing proposition. */
3797 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3799 fprintf_unfiltered (gdb_stdlog
,
3800 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3801 /* Getting the current syscall number. */
3802 if (handle_syscall_event (ecs
) == 0)
3803 process_event_stop_test (ecs
);
3806 /* Before examining the threads further, step this thread to
3807 get it entirely out of the syscall. (We get notice of the
3808 event when the thread is just on the verge of exiting a
3809 syscall. Stepping one instruction seems to get it back
3811 case TARGET_WAITKIND_SYSCALL_RETURN
:
3813 fprintf_unfiltered (gdb_stdlog
,
3814 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3815 if (handle_syscall_event (ecs
) == 0)
3816 process_event_stop_test (ecs
);
3819 case TARGET_WAITKIND_STOPPED
:
3821 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
3822 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
3823 handle_signal_stop (ecs
);
3826 case TARGET_WAITKIND_NO_HISTORY
:
3828 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
3829 /* Reverse execution: target ran out of history info. */
3831 /* Pull the single step breakpoints out of the target. */
3832 if (singlestep_breakpoints_inserted_p
)
3834 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3835 context_switch (ecs
->ptid
);
3836 remove_single_step_breakpoints ();
3837 singlestep_breakpoints_inserted_p
= 0;
3839 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3840 print_no_history_reason ();
3841 stop_stepping (ecs
);
3846 /* Come here when the program has stopped with a signal. */
3849 handle_signal_stop (struct execution_control_state
*ecs
)
3851 struct frame_info
*frame
;
3852 struct gdbarch
*gdbarch
;
3853 int stopped_by_watchpoint
;
3854 enum stop_kind stop_soon
;
3857 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
3859 /* Do we need to clean up the state of a thread that has
3860 completed a displaced single-step? (Doing so usually affects
3861 the PC, so do it here, before we set stop_pc.) */
3862 displaced_step_fixup (ecs
->ptid
,
3863 ecs
->event_thread
->suspend
.stop_signal
);
3865 /* If we either finished a single-step or hit a breakpoint, but
3866 the user wanted this thread to be stopped, pretend we got a
3867 SIG0 (generic unsignaled stop). */
3868 if (ecs
->event_thread
->stop_requested
3869 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3870 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3872 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3876 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3877 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3878 struct cleanup
*old_chain
= save_inferior_ptid ();
3880 inferior_ptid
= ecs
->ptid
;
3882 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
3883 paddress (gdbarch
, stop_pc
));
3884 if (target_stopped_by_watchpoint ())
3888 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
3890 if (target_stopped_data_address (¤t_target
, &addr
))
3891 fprintf_unfiltered (gdb_stdlog
,
3892 "infrun: stopped data address = %s\n",
3893 paddress (gdbarch
, addr
));
3895 fprintf_unfiltered (gdb_stdlog
,
3896 "infrun: (no data address available)\n");
3899 do_cleanups (old_chain
);
3902 /* This is originated from start_remote(), start_inferior() and
3903 shared libraries hook functions. */
3904 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
3905 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
3907 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3908 context_switch (ecs
->ptid
);
3910 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3911 stop_print_frame
= 1;
3912 stop_stepping (ecs
);
3916 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
3919 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3920 context_switch (ecs
->ptid
);
3922 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
3923 stop_print_frame
= 0;
3924 stop_stepping (ecs
);
3928 /* This originates from attach_command(). We need to overwrite
3929 the stop_signal here, because some kernels don't ignore a
3930 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3931 See more comments in inferior.h. On the other hand, if we
3932 get a non-SIGSTOP, report it to the user - assume the backend
3933 will handle the SIGSTOP if it should show up later.
3935 Also consider that the attach is complete when we see a
3936 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3937 target extended-remote report it instead of a SIGSTOP
3938 (e.g. gdbserver). We already rely on SIGTRAP being our
3939 signal, so this is no exception.
3941 Also consider that the attach is complete when we see a
3942 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3943 the target to stop all threads of the inferior, in case the
3944 low level attach operation doesn't stop them implicitly. If
3945 they weren't stopped implicitly, then the stub will report a
3946 GDB_SIGNAL_0, meaning: stopped for no particular reason
3947 other than GDB's request. */
3948 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3949 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
3950 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
3951 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
3953 stop_print_frame
= 1;
3954 stop_stepping (ecs
);
3955 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3959 /* See if something interesting happened to the non-current thread. If
3960 so, then switch to that thread. */
3961 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3964 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
3966 context_switch (ecs
->ptid
);
3968 if (deprecated_context_hook
)
3969 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3972 /* At this point, get hold of the now-current thread's frame. */
3973 frame
= get_current_frame ();
3974 gdbarch
= get_frame_arch (frame
);
3976 /* Pull the single step breakpoints out of the target. */
3977 if (singlestep_breakpoints_inserted_p
)
3979 /* However, before doing so, if this single-step breakpoint was
3980 actually for another thread, set this thread up for moving
3982 if (!ptid_equal (ecs
->ptid
, singlestep_ptid
)
3983 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3985 struct regcache
*regcache
;
3986 struct address_space
*aspace
;
3989 regcache
= get_thread_regcache (ecs
->ptid
);
3990 aspace
= get_regcache_aspace (regcache
);
3991 pc
= regcache_read_pc (regcache
);
3992 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3996 fprintf_unfiltered (gdb_stdlog
,
3997 "infrun: [%s] hit step over single-step"
3998 " breakpoint of [%s]\n",
3999 target_pid_to_str (ecs
->ptid
),
4000 target_pid_to_str (singlestep_ptid
));
4002 ecs
->hit_singlestep_breakpoint
= 1;
4006 remove_single_step_breakpoints ();
4007 singlestep_breakpoints_inserted_p
= 0;
4010 if (ecs
->stepped_after_stopped_by_watchpoint
)
4011 stopped_by_watchpoint
= 0;
4013 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
4015 /* If necessary, step over this watchpoint. We'll be back to display
4017 if (stopped_by_watchpoint
4018 && (target_have_steppable_watchpoint
4019 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
4021 /* At this point, we are stopped at an instruction which has
4022 attempted to write to a piece of memory under control of
4023 a watchpoint. The instruction hasn't actually executed
4024 yet. If we were to evaluate the watchpoint expression
4025 now, we would get the old value, and therefore no change
4026 would seem to have occurred.
4028 In order to make watchpoints work `right', we really need
4029 to complete the memory write, and then evaluate the
4030 watchpoint expression. We do this by single-stepping the
4033 It may not be necessary to disable the watchpoint to stop over
4034 it. For example, the PA can (with some kernel cooperation)
4035 single step over a watchpoint without disabling the watchpoint.
4037 It is far more common to need to disable a watchpoint to step
4038 the inferior over it. If we have non-steppable watchpoints,
4039 we must disable the current watchpoint; it's simplest to
4040 disable all watchpoints and breakpoints. */
4043 if (!target_have_steppable_watchpoint
)
4045 remove_breakpoints ();
4046 /* See comment in resume why we need to stop bypassing signals
4047 while breakpoints have been removed. */
4048 target_pass_signals (0, NULL
);
4051 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
4052 target_resume (ecs
->ptid
, hw_step
, GDB_SIGNAL_0
);
4053 waiton_ptid
= ecs
->ptid
;
4054 if (target_have_steppable_watchpoint
)
4055 infwait_state
= infwait_step_watch_state
;
4057 infwait_state
= infwait_nonstep_watch_state
;
4058 prepare_to_wait (ecs
);
4062 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4063 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4064 ecs
->event_thread
->control
.stop_step
= 0;
4065 stop_print_frame
= 1;
4066 stopped_by_random_signal
= 0;
4068 /* Hide inlined functions starting here, unless we just performed stepi or
4069 nexti. After stepi and nexti, always show the innermost frame (not any
4070 inline function call sites). */
4071 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4073 struct address_space
*aspace
=
4074 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4076 /* skip_inline_frames is expensive, so we avoid it if we can
4077 determine that the address is one where functions cannot have
4078 been inlined. This improves performance with inferiors that
4079 load a lot of shared libraries, because the solib event
4080 breakpoint is defined as the address of a function (i.e. not
4081 inline). Note that we have to check the previous PC as well
4082 as the current one to catch cases when we have just
4083 single-stepped off a breakpoint prior to reinstating it.
4084 Note that we're assuming that the code we single-step to is
4085 not inline, but that's not definitive: there's nothing
4086 preventing the event breakpoint function from containing
4087 inlined code, and the single-step ending up there. If the
4088 user had set a breakpoint on that inlined code, the missing
4089 skip_inline_frames call would break things. Fortunately
4090 that's an extremely unlikely scenario. */
4091 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4092 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4093 && ecs
->event_thread
->control
.trap_expected
4094 && pc_at_non_inline_function (aspace
,
4095 ecs
->event_thread
->prev_pc
,
4098 skip_inline_frames (ecs
->ptid
);
4100 /* Re-fetch current thread's frame in case that invalidated
4102 frame
= get_current_frame ();
4103 gdbarch
= get_frame_arch (frame
);
4107 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4108 && ecs
->event_thread
->control
.trap_expected
4109 && gdbarch_single_step_through_delay_p (gdbarch
)
4110 && currently_stepping (ecs
->event_thread
))
4112 /* We're trying to step off a breakpoint. Turns out that we're
4113 also on an instruction that needs to be stepped multiple
4114 times before it's been fully executing. E.g., architectures
4115 with a delay slot. It needs to be stepped twice, once for
4116 the instruction and once for the delay slot. */
4117 int step_through_delay
4118 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4120 if (debug_infrun
&& step_through_delay
)
4121 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4122 if (ecs
->event_thread
->control
.step_range_end
== 0
4123 && step_through_delay
)
4125 /* The user issued a continue when stopped at a breakpoint.
4126 Set up for another trap and get out of here. */
4127 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4131 else if (step_through_delay
)
4133 /* The user issued a step when stopped at a breakpoint.
4134 Maybe we should stop, maybe we should not - the delay
4135 slot *might* correspond to a line of source. In any
4136 case, don't decide that here, just set
4137 ecs->stepping_over_breakpoint, making sure we
4138 single-step again before breakpoints are re-inserted. */
4139 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4143 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4144 handles this event. */
4145 ecs
->event_thread
->control
.stop_bpstat
4146 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4147 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4149 /* Following in case break condition called a
4151 stop_print_frame
= 1;
4153 /* This is where we handle "moribund" watchpoints. Unlike
4154 software breakpoints traps, hardware watchpoint traps are
4155 always distinguishable from random traps. If no high-level
4156 watchpoint is associated with the reported stop data address
4157 anymore, then the bpstat does not explain the signal ---
4158 simply make sure to ignore it if `stopped_by_watchpoint' is
4162 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4163 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4165 && stopped_by_watchpoint
)
4166 fprintf_unfiltered (gdb_stdlog
,
4167 "infrun: no user watchpoint explains "
4168 "watchpoint SIGTRAP, ignoring\n");
4170 /* NOTE: cagney/2003-03-29: These checks for a random signal
4171 at one stage in the past included checks for an inferior
4172 function call's call dummy's return breakpoint. The original
4173 comment, that went with the test, read:
4175 ``End of a stack dummy. Some systems (e.g. Sony news) give
4176 another signal besides SIGTRAP, so check here as well as
4179 If someone ever tries to get call dummys on a
4180 non-executable stack to work (where the target would stop
4181 with something like a SIGSEGV), then those tests might need
4182 to be re-instated. Given, however, that the tests were only
4183 enabled when momentary breakpoints were not being used, I
4184 suspect that it won't be the case.
4186 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4187 be necessary for call dummies on a non-executable stack on
4190 /* See if the breakpoints module can explain the signal. */
4192 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4193 ecs
->event_thread
->suspend
.stop_signal
);
4195 /* If not, perhaps stepping/nexting can. */
4197 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4198 && currently_stepping (ecs
->event_thread
));
4200 /* Perhaps the thread hit a single-step breakpoint of _another_
4201 thread. Single-step breakpoints are transparent to the
4202 breakpoints module. */
4204 random_signal
= !ecs
->hit_singlestep_breakpoint
;
4206 /* No? Perhaps we got a moribund watchpoint. */
4208 random_signal
= !stopped_by_watchpoint
;
4210 /* For the program's own signals, act according to
4211 the signal handling tables. */
4215 /* Signal not for debugging purposes. */
4217 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
4218 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
4221 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal (%s)\n",
4222 gdb_signal_to_symbol_string (stop_signal
));
4224 stopped_by_random_signal
= 1;
4226 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4229 target_terminal_ours_for_output ();
4230 print_signal_received_reason
4231 (ecs
->event_thread
->suspend
.stop_signal
);
4233 /* Always stop on signals if we're either just gaining control
4234 of the program, or the user explicitly requested this thread
4235 to remain stopped. */
4236 if (stop_soon
!= NO_STOP_QUIETLY
4237 || ecs
->event_thread
->stop_requested
4239 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4241 stop_stepping (ecs
);
4244 /* If not going to stop, give terminal back
4245 if we took it away. */
4247 target_terminal_inferior ();
4249 /* Clear the signal if it should not be passed. */
4250 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4251 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4253 if (ecs
->event_thread
->prev_pc
== stop_pc
4254 && ecs
->event_thread
->control
.trap_expected
4255 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4257 /* We were just starting a new sequence, attempting to
4258 single-step off of a breakpoint and expecting a SIGTRAP.
4259 Instead this signal arrives. This signal will take us out
4260 of the stepping range so GDB needs to remember to, when
4261 the signal handler returns, resume stepping off that
4263 /* To simplify things, "continue" is forced to use the same
4264 code paths as single-step - set a breakpoint at the
4265 signal return address and then, once hit, step off that
4268 fprintf_unfiltered (gdb_stdlog
,
4269 "infrun: signal arrived while stepping over "
4272 insert_hp_step_resume_breakpoint_at_frame (frame
);
4273 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4274 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4275 ecs
->event_thread
->control
.trap_expected
= 0;
4277 /* If we were nexting/stepping some other thread, switch to
4278 it, so that we don't continue it, losing control. */
4279 if (!switch_back_to_stepped_thread (ecs
))
4284 if (ecs
->event_thread
->control
.step_range_end
!= 0
4285 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4286 && pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4287 && frame_id_eq (get_stack_frame_id (frame
),
4288 ecs
->event_thread
->control
.step_stack_frame_id
)
4289 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4291 /* The inferior is about to take a signal that will take it
4292 out of the single step range. Set a breakpoint at the
4293 current PC (which is presumably where the signal handler
4294 will eventually return) and then allow the inferior to
4297 Note that this is only needed for a signal delivered
4298 while in the single-step range. Nested signals aren't a
4299 problem as they eventually all return. */
4301 fprintf_unfiltered (gdb_stdlog
,
4302 "infrun: signal may take us out of "
4303 "single-step range\n");
4305 insert_hp_step_resume_breakpoint_at_frame (frame
);
4306 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4307 ecs
->event_thread
->control
.trap_expected
= 0;
4312 /* Note: step_resume_breakpoint may be non-NULL. This occures
4313 when either there's a nested signal, or when there's a
4314 pending signal enabled just as the signal handler returns
4315 (leaving the inferior at the step-resume-breakpoint without
4316 actually executing it). Either way continue until the
4317 breakpoint is really hit. */
4319 if (!switch_back_to_stepped_thread (ecs
))
4322 fprintf_unfiltered (gdb_stdlog
,
4323 "infrun: random signal, keep going\n");
4330 process_event_stop_test (ecs
);
4333 /* Come here when we've got some debug event / signal we can explain
4334 (IOW, not a random signal), and test whether it should cause a
4335 stop, or whether we should resume the inferior (transparently).
4336 E.g., could be a breakpoint whose condition evaluates false; we
4337 could be still stepping within the line; etc. */
4340 process_event_stop_test (struct execution_control_state
*ecs
)
4342 struct symtab_and_line stop_pc_sal
;
4343 struct frame_info
*frame
;
4344 struct gdbarch
*gdbarch
;
4345 CORE_ADDR jmp_buf_pc
;
4346 struct bpstat_what what
;
4348 /* Handle cases caused by hitting a breakpoint. */
4350 frame
= get_current_frame ();
4351 gdbarch
= get_frame_arch (frame
);
4353 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4355 if (what
.call_dummy
)
4357 stop_stack_dummy
= what
.call_dummy
;
4360 /* If we hit an internal event that triggers symbol changes, the
4361 current frame will be invalidated within bpstat_what (e.g., if we
4362 hit an internal solib event). Re-fetch it. */
4363 frame
= get_current_frame ();
4364 gdbarch
= get_frame_arch (frame
);
4366 switch (what
.main_action
)
4368 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4369 /* If we hit the breakpoint at longjmp while stepping, we
4370 install a momentary breakpoint at the target of the
4374 fprintf_unfiltered (gdb_stdlog
,
4375 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4377 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4379 if (what
.is_longjmp
)
4381 struct value
*arg_value
;
4383 /* If we set the longjmp breakpoint via a SystemTap probe,
4384 then use it to extract the arguments. The destination PC
4385 is the third argument to the probe. */
4386 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4388 jmp_buf_pc
= value_as_address (arg_value
);
4389 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4390 || !gdbarch_get_longjmp_target (gdbarch
,
4391 frame
, &jmp_buf_pc
))
4394 fprintf_unfiltered (gdb_stdlog
,
4395 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4396 "(!gdbarch_get_longjmp_target)\n");
4401 /* Insert a breakpoint at resume address. */
4402 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4405 check_exception_resume (ecs
, frame
);
4409 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4411 struct frame_info
*init_frame
;
4413 /* There are several cases to consider.
4415 1. The initiating frame no longer exists. In this case we
4416 must stop, because the exception or longjmp has gone too
4419 2. The initiating frame exists, and is the same as the
4420 current frame. We stop, because the exception or longjmp
4423 3. The initiating frame exists and is different from the
4424 current frame. This means the exception or longjmp has
4425 been caught beneath the initiating frame, so keep going.
4427 4. longjmp breakpoint has been placed just to protect
4428 against stale dummy frames and user is not interested in
4429 stopping around longjmps. */
4432 fprintf_unfiltered (gdb_stdlog
,
4433 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4435 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4437 delete_exception_resume_breakpoint (ecs
->event_thread
);
4439 if (what
.is_longjmp
)
4441 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
->num
);
4443 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4451 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4455 struct frame_id current_id
4456 = get_frame_id (get_current_frame ());
4457 if (frame_id_eq (current_id
,
4458 ecs
->event_thread
->initiating_frame
))
4460 /* Case 2. Fall through. */
4470 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4472 delete_step_resume_breakpoint (ecs
->event_thread
);
4474 ecs
->event_thread
->control
.stop_step
= 1;
4475 print_end_stepping_range_reason ();
4476 stop_stepping (ecs
);
4480 case BPSTAT_WHAT_SINGLE
:
4482 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4483 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4484 /* Still need to check other stuff, at least the case where we
4485 are stepping and step out of the right range. */
4488 case BPSTAT_WHAT_STEP_RESUME
:
4490 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4492 delete_step_resume_breakpoint (ecs
->event_thread
);
4493 if (ecs
->event_thread
->control
.proceed_to_finish
4494 && execution_direction
== EXEC_REVERSE
)
4496 struct thread_info
*tp
= ecs
->event_thread
;
4498 /* We are finishing a function in reverse, and just hit the
4499 step-resume breakpoint at the start address of the
4500 function, and we're almost there -- just need to back up
4501 by one more single-step, which should take us back to the
4503 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4507 fill_in_stop_func (gdbarch
, ecs
);
4508 if (stop_pc
== ecs
->stop_func_start
4509 && execution_direction
== EXEC_REVERSE
)
4511 /* We are stepping over a function call in reverse, and just
4512 hit the step-resume breakpoint at the start address of
4513 the function. Go back to single-stepping, which should
4514 take us back to the function call. */
4515 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4521 case BPSTAT_WHAT_STOP_NOISY
:
4523 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4524 stop_print_frame
= 1;
4526 /* Assume the thread stopped for a breapoint. We'll still check
4527 whether a/the breakpoint is there when the thread is next
4529 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4531 stop_stepping (ecs
);
4534 case BPSTAT_WHAT_STOP_SILENT
:
4536 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4537 stop_print_frame
= 0;
4539 /* Assume the thread stopped for a breapoint. We'll still check
4540 whether a/the breakpoint is there when the thread is next
4542 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4543 stop_stepping (ecs
);
4546 case BPSTAT_WHAT_HP_STEP_RESUME
:
4548 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4550 delete_step_resume_breakpoint (ecs
->event_thread
);
4551 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4553 /* Back when the step-resume breakpoint was inserted, we
4554 were trying to single-step off a breakpoint. Go back to
4556 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4557 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4563 case BPSTAT_WHAT_KEEP_CHECKING
:
4567 /* We come here if we hit a breakpoint but should not stop for it.
4568 Possibly we also were stepping and should stop for that. So fall
4569 through and test for stepping. But, if not stepping, do not
4572 /* In all-stop mode, if we're currently stepping but have stopped in
4573 some other thread, we need to switch back to the stepped thread. */
4574 if (switch_back_to_stepped_thread (ecs
))
4577 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
4580 fprintf_unfiltered (gdb_stdlog
,
4581 "infrun: step-resume breakpoint is inserted\n");
4583 /* Having a step-resume breakpoint overrides anything
4584 else having to do with stepping commands until
4585 that breakpoint is reached. */
4590 if (ecs
->event_thread
->control
.step_range_end
== 0)
4593 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4594 /* Likewise if we aren't even stepping. */
4599 /* Re-fetch current thread's frame in case the code above caused
4600 the frame cache to be re-initialized, making our FRAME variable
4601 a dangling pointer. */
4602 frame
= get_current_frame ();
4603 gdbarch
= get_frame_arch (frame
);
4604 fill_in_stop_func (gdbarch
, ecs
);
4606 /* If stepping through a line, keep going if still within it.
4608 Note that step_range_end is the address of the first instruction
4609 beyond the step range, and NOT the address of the last instruction
4612 Note also that during reverse execution, we may be stepping
4613 through a function epilogue and therefore must detect when
4614 the current-frame changes in the middle of a line. */
4616 if (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4617 && (execution_direction
!= EXEC_REVERSE
4618 || frame_id_eq (get_frame_id (frame
),
4619 ecs
->event_thread
->control
.step_frame_id
)))
4623 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4624 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
4625 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
4627 /* Tentatively re-enable range stepping; `resume' disables it if
4628 necessary (e.g., if we're stepping over a breakpoint or we
4629 have software watchpoints). */
4630 ecs
->event_thread
->control
.may_range_step
= 1;
4632 /* When stepping backward, stop at beginning of line range
4633 (unless it's the function entry point, in which case
4634 keep going back to the call point). */
4635 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
4636 && stop_pc
!= ecs
->stop_func_start
4637 && execution_direction
== EXEC_REVERSE
)
4639 ecs
->event_thread
->control
.stop_step
= 1;
4640 print_end_stepping_range_reason ();
4641 stop_stepping (ecs
);
4649 /* We stepped out of the stepping range. */
4651 /* If we are stepping at the source level and entered the runtime
4652 loader dynamic symbol resolution code...
4654 EXEC_FORWARD: we keep on single stepping until we exit the run
4655 time loader code and reach the callee's address.
4657 EXEC_REVERSE: we've already executed the callee (backward), and
4658 the runtime loader code is handled just like any other
4659 undebuggable function call. Now we need only keep stepping
4660 backward through the trampoline code, and that's handled further
4661 down, so there is nothing for us to do here. */
4663 if (execution_direction
!= EXEC_REVERSE
4664 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4665 && in_solib_dynsym_resolve_code (stop_pc
))
4667 CORE_ADDR pc_after_resolver
=
4668 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4671 fprintf_unfiltered (gdb_stdlog
,
4672 "infrun: stepped into dynsym resolve code\n");
4674 if (pc_after_resolver
)
4676 /* Set up a step-resume breakpoint at the address
4677 indicated by SKIP_SOLIB_RESOLVER. */
4678 struct symtab_and_line sr_sal
;
4681 sr_sal
.pc
= pc_after_resolver
;
4682 sr_sal
.pspace
= get_frame_program_space (frame
);
4684 insert_step_resume_breakpoint_at_sal (gdbarch
,
4685 sr_sal
, null_frame_id
);
4692 if (ecs
->event_thread
->control
.step_range_end
!= 1
4693 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4694 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4695 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4698 fprintf_unfiltered (gdb_stdlog
,
4699 "infrun: stepped into signal trampoline\n");
4700 /* The inferior, while doing a "step" or "next", has ended up in
4701 a signal trampoline (either by a signal being delivered or by
4702 the signal handler returning). Just single-step until the
4703 inferior leaves the trampoline (either by calling the handler
4709 /* If we're in the return path from a shared library trampoline,
4710 we want to proceed through the trampoline when stepping. */
4711 /* macro/2012-04-25: This needs to come before the subroutine
4712 call check below as on some targets return trampolines look
4713 like subroutine calls (MIPS16 return thunks). */
4714 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4715 stop_pc
, ecs
->stop_func_name
)
4716 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4718 /* Determine where this trampoline returns. */
4719 CORE_ADDR real_stop_pc
;
4721 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4724 fprintf_unfiltered (gdb_stdlog
,
4725 "infrun: stepped into solib return tramp\n");
4727 /* Only proceed through if we know where it's going. */
4730 /* And put the step-breakpoint there and go until there. */
4731 struct symtab_and_line sr_sal
;
4733 init_sal (&sr_sal
); /* initialize to zeroes */
4734 sr_sal
.pc
= real_stop_pc
;
4735 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4736 sr_sal
.pspace
= get_frame_program_space (frame
);
4738 /* Do not specify what the fp should be when we stop since
4739 on some machines the prologue is where the new fp value
4741 insert_step_resume_breakpoint_at_sal (gdbarch
,
4742 sr_sal
, null_frame_id
);
4744 /* Restart without fiddling with the step ranges or
4751 /* Check for subroutine calls. The check for the current frame
4752 equalling the step ID is not necessary - the check of the
4753 previous frame's ID is sufficient - but it is a common case and
4754 cheaper than checking the previous frame's ID.
4756 NOTE: frame_id_eq will never report two invalid frame IDs as
4757 being equal, so to get into this block, both the current and
4758 previous frame must have valid frame IDs. */
4759 /* The outer_frame_id check is a heuristic to detect stepping
4760 through startup code. If we step over an instruction which
4761 sets the stack pointer from an invalid value to a valid value,
4762 we may detect that as a subroutine call from the mythical
4763 "outermost" function. This could be fixed by marking
4764 outermost frames as !stack_p,code_p,special_p. Then the
4765 initial outermost frame, before sp was valid, would
4766 have code_addr == &_start. See the comment in frame_id_eq
4768 if (!frame_id_eq (get_stack_frame_id (frame
),
4769 ecs
->event_thread
->control
.step_stack_frame_id
)
4770 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4771 ecs
->event_thread
->control
.step_stack_frame_id
)
4772 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
4774 || step_start_function
!= find_pc_function (stop_pc
))))
4776 CORE_ADDR real_stop_pc
;
4779 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4781 if ((ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
4782 || ((ecs
->event_thread
->control
.step_range_end
== 1)
4783 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4784 ecs
->stop_func_start
)))
4786 /* I presume that step_over_calls is only 0 when we're
4787 supposed to be stepping at the assembly language level
4788 ("stepi"). Just stop. */
4789 /* Also, maybe we just did a "nexti" inside a prolog, so we
4790 thought it was a subroutine call but it was not. Stop as
4792 /* And this works the same backward as frontward. MVS */
4793 ecs
->event_thread
->control
.stop_step
= 1;
4794 print_end_stepping_range_reason ();
4795 stop_stepping (ecs
);
4799 /* Reverse stepping through solib trampolines. */
4801 if (execution_direction
== EXEC_REVERSE
4802 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
4803 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4804 || (ecs
->stop_func_start
== 0
4805 && in_solib_dynsym_resolve_code (stop_pc
))))
4807 /* Any solib trampoline code can be handled in reverse
4808 by simply continuing to single-step. We have already
4809 executed the solib function (backwards), and a few
4810 steps will take us back through the trampoline to the
4816 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4818 /* We're doing a "next".
4820 Normal (forward) execution: set a breakpoint at the
4821 callee's return address (the address at which the caller
4824 Reverse (backward) execution. set the step-resume
4825 breakpoint at the start of the function that we just
4826 stepped into (backwards), and continue to there. When we
4827 get there, we'll need to single-step back to the caller. */
4829 if (execution_direction
== EXEC_REVERSE
)
4831 /* If we're already at the start of the function, we've either
4832 just stepped backward into a single instruction function,
4833 or stepped back out of a signal handler to the first instruction
4834 of the function. Just keep going, which will single-step back
4836 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
4838 struct symtab_and_line sr_sal
;
4840 /* Normal function call return (static or dynamic). */
4842 sr_sal
.pc
= ecs
->stop_func_start
;
4843 sr_sal
.pspace
= get_frame_program_space (frame
);
4844 insert_step_resume_breakpoint_at_sal (gdbarch
,
4845 sr_sal
, null_frame_id
);
4849 insert_step_resume_breakpoint_at_caller (frame
);
4855 /* If we are in a function call trampoline (a stub between the
4856 calling routine and the real function), locate the real
4857 function. That's what tells us (a) whether we want to step
4858 into it at all, and (b) what prologue we want to run to the
4859 end of, if we do step into it. */
4860 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
4861 if (real_stop_pc
== 0)
4862 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4863 if (real_stop_pc
!= 0)
4864 ecs
->stop_func_start
= real_stop_pc
;
4866 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
4868 struct symtab_and_line sr_sal
;
4871 sr_sal
.pc
= ecs
->stop_func_start
;
4872 sr_sal
.pspace
= get_frame_program_space (frame
);
4874 insert_step_resume_breakpoint_at_sal (gdbarch
,
4875 sr_sal
, null_frame_id
);
4880 /* If we have line number information for the function we are
4881 thinking of stepping into and the function isn't on the skip
4884 If there are several symtabs at that PC (e.g. with include
4885 files), just want to know whether *any* of them have line
4886 numbers. find_pc_line handles this. */
4888 struct symtab_and_line tmp_sal
;
4890 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
4891 if (tmp_sal
.line
!= 0
4892 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
4895 if (execution_direction
== EXEC_REVERSE
)
4896 handle_step_into_function_backward (gdbarch
, ecs
);
4898 handle_step_into_function (gdbarch
, ecs
);
4903 /* If we have no line number and the step-stop-if-no-debug is
4904 set, we stop the step so that the user has a chance to switch
4905 in assembly mode. */
4906 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4907 && step_stop_if_no_debug
)
4909 ecs
->event_thread
->control
.stop_step
= 1;
4910 print_end_stepping_range_reason ();
4911 stop_stepping (ecs
);
4915 if (execution_direction
== EXEC_REVERSE
)
4917 /* If we're already at the start of the function, we've either just
4918 stepped backward into a single instruction function without line
4919 number info, or stepped back out of a signal handler to the first
4920 instruction of the function without line number info. Just keep
4921 going, which will single-step back to the caller. */
4922 if (ecs
->stop_func_start
!= stop_pc
)
4924 /* Set a breakpoint at callee's start address.
4925 From there we can step once and be back in the caller. */
4926 struct symtab_and_line sr_sal
;
4929 sr_sal
.pc
= ecs
->stop_func_start
;
4930 sr_sal
.pspace
= get_frame_program_space (frame
);
4931 insert_step_resume_breakpoint_at_sal (gdbarch
,
4932 sr_sal
, null_frame_id
);
4936 /* Set a breakpoint at callee's return address (the address
4937 at which the caller will resume). */
4938 insert_step_resume_breakpoint_at_caller (frame
);
4944 /* Reverse stepping through solib trampolines. */
4946 if (execution_direction
== EXEC_REVERSE
4947 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4949 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4950 || (ecs
->stop_func_start
== 0
4951 && in_solib_dynsym_resolve_code (stop_pc
)))
4953 /* Any solib trampoline code can be handled in reverse
4954 by simply continuing to single-step. We have already
4955 executed the solib function (backwards), and a few
4956 steps will take us back through the trampoline to the
4961 else if (in_solib_dynsym_resolve_code (stop_pc
))
4963 /* Stepped backward into the solib dynsym resolver.
4964 Set a breakpoint at its start and continue, then
4965 one more step will take us out. */
4966 struct symtab_and_line sr_sal
;
4969 sr_sal
.pc
= ecs
->stop_func_start
;
4970 sr_sal
.pspace
= get_frame_program_space (frame
);
4971 insert_step_resume_breakpoint_at_sal (gdbarch
,
4972 sr_sal
, null_frame_id
);
4978 stop_pc_sal
= find_pc_line (stop_pc
, 0);
4980 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4981 the trampoline processing logic, however, there are some trampolines
4982 that have no names, so we should do trampoline handling first. */
4983 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4984 && ecs
->stop_func_name
== NULL
4985 && stop_pc_sal
.line
== 0)
4988 fprintf_unfiltered (gdb_stdlog
,
4989 "infrun: stepped into undebuggable function\n");
4991 /* The inferior just stepped into, or returned to, an
4992 undebuggable function (where there is no debugging information
4993 and no line number corresponding to the address where the
4994 inferior stopped). Since we want to skip this kind of code,
4995 we keep going until the inferior returns from this
4996 function - unless the user has asked us not to (via
4997 set step-mode) or we no longer know how to get back
4998 to the call site. */
4999 if (step_stop_if_no_debug
5000 || !frame_id_p (frame_unwind_caller_id (frame
)))
5002 /* If we have no line number and the step-stop-if-no-debug
5003 is set, we stop the step so that the user has a chance to
5004 switch in assembly mode. */
5005 ecs
->event_thread
->control
.stop_step
= 1;
5006 print_end_stepping_range_reason ();
5007 stop_stepping (ecs
);
5012 /* Set a breakpoint at callee's return address (the address
5013 at which the caller will resume). */
5014 insert_step_resume_breakpoint_at_caller (frame
);
5020 if (ecs
->event_thread
->control
.step_range_end
== 1)
5022 /* It is stepi or nexti. We always want to stop stepping after
5025 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5026 ecs
->event_thread
->control
.stop_step
= 1;
5027 print_end_stepping_range_reason ();
5028 stop_stepping (ecs
);
5032 if (stop_pc_sal
.line
== 0)
5034 /* We have no line number information. That means to stop
5035 stepping (does this always happen right after one instruction,
5036 when we do "s" in a function with no line numbers,
5037 or can this happen as a result of a return or longjmp?). */
5039 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5040 ecs
->event_thread
->control
.stop_step
= 1;
5041 print_end_stepping_range_reason ();
5042 stop_stepping (ecs
);
5046 /* Look for "calls" to inlined functions, part one. If the inline
5047 frame machinery detected some skipped call sites, we have entered
5048 a new inline function. */
5050 if (frame_id_eq (get_frame_id (get_current_frame ()),
5051 ecs
->event_thread
->control
.step_frame_id
)
5052 && inline_skipped_frames (ecs
->ptid
))
5054 struct symtab_and_line call_sal
;
5057 fprintf_unfiltered (gdb_stdlog
,
5058 "infrun: stepped into inlined function\n");
5060 find_frame_sal (get_current_frame (), &call_sal
);
5062 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5064 /* For "step", we're going to stop. But if the call site
5065 for this inlined function is on the same source line as
5066 we were previously stepping, go down into the function
5067 first. Otherwise stop at the call site. */
5069 if (call_sal
.line
== ecs
->event_thread
->current_line
5070 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5071 step_into_inline_frame (ecs
->ptid
);
5073 ecs
->event_thread
->control
.stop_step
= 1;
5074 print_end_stepping_range_reason ();
5075 stop_stepping (ecs
);
5080 /* For "next", we should stop at the call site if it is on a
5081 different source line. Otherwise continue through the
5082 inlined function. */
5083 if (call_sal
.line
== ecs
->event_thread
->current_line
5084 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5088 ecs
->event_thread
->control
.stop_step
= 1;
5089 print_end_stepping_range_reason ();
5090 stop_stepping (ecs
);
5096 /* Look for "calls" to inlined functions, part two. If we are still
5097 in the same real function we were stepping through, but we have
5098 to go further up to find the exact frame ID, we are stepping
5099 through a more inlined call beyond its call site. */
5101 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5102 && !frame_id_eq (get_frame_id (get_current_frame ()),
5103 ecs
->event_thread
->control
.step_frame_id
)
5104 && stepped_in_from (get_current_frame (),
5105 ecs
->event_thread
->control
.step_frame_id
))
5108 fprintf_unfiltered (gdb_stdlog
,
5109 "infrun: stepping through inlined function\n");
5111 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5115 ecs
->event_thread
->control
.stop_step
= 1;
5116 print_end_stepping_range_reason ();
5117 stop_stepping (ecs
);
5122 if ((stop_pc
== stop_pc_sal
.pc
)
5123 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5124 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5126 /* We are at the start of a different line. So stop. Note that
5127 we don't stop if we step into the middle of a different line.
5128 That is said to make things like for (;;) statements work
5131 fprintf_unfiltered (gdb_stdlog
,
5132 "infrun: stepped to a different line\n");
5133 ecs
->event_thread
->control
.stop_step
= 1;
5134 print_end_stepping_range_reason ();
5135 stop_stepping (ecs
);
5139 /* We aren't done stepping.
5141 Optimize by setting the stepping range to the line.
5142 (We might not be in the original line, but if we entered a
5143 new line in mid-statement, we continue stepping. This makes
5144 things like for(;;) statements work better.) */
5146 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5147 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5148 ecs
->event_thread
->control
.may_range_step
= 1;
5149 set_step_info (frame
, stop_pc_sal
);
5152 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5156 /* In all-stop mode, if we're currently stepping but have stopped in
5157 some other thread, we may need to switch back to the stepped
5158 thread. Returns true we set the inferior running, false if we left
5159 it stopped (and the event needs further processing). */
5162 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
5166 struct thread_info
*tp
;
5167 struct thread_info
*stepping_thread
;
5168 struct thread_info
*step_over
;
5170 /* If any thread is blocked on some internal breakpoint, and we
5171 simply need to step over that breakpoint to get it going
5172 again, do that first. */
5174 /* However, if we see an event for the stepping thread, then we
5175 know all other threads have been moved past their breakpoints
5176 already. Let the caller check whether the step is finished,
5177 etc., before deciding to move it past a breakpoint. */
5178 if (ecs
->event_thread
->control
.step_range_end
!= 0)
5181 /* Check if the current thread is blocked on an incomplete
5182 step-over, interrupted by a random signal. */
5183 if (ecs
->event_thread
->control
.trap_expected
5184 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5188 fprintf_unfiltered (gdb_stdlog
,
5189 "infrun: need to finish step-over of [%s]\n",
5190 target_pid_to_str (ecs
->event_thread
->ptid
));
5196 /* Check if the current thread is blocked by a single-step
5197 breakpoint of another thread. */
5198 if (ecs
->hit_singlestep_breakpoint
)
5202 fprintf_unfiltered (gdb_stdlog
,
5203 "infrun: need to step [%s] over single-step "
5205 target_pid_to_str (ecs
->ptid
));
5211 /* Otherwise, we no longer expect a trap in the current thread.
5212 Clear the trap_expected flag before switching back -- this is
5213 what keep_going does as well, if we call it. */
5214 ecs
->event_thread
->control
.trap_expected
= 0;
5216 /* If scheduler locking applies even if not stepping, there's no
5217 need to walk over threads. Above we've checked whether the
5218 current thread is stepping. If some other thread not the
5219 event thread is stepping, then it must be that scheduler
5220 locking is not in effect. */
5221 if (schedlock_applies (0))
5224 /* Look for the stepping/nexting thread, and check if any other
5225 thread other than the stepping thread needs to start a
5226 step-over. Do all step-overs before actually proceeding with
5228 stepping_thread
= NULL
;
5232 /* Ignore threads of processes we're not resuming. */
5234 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
5237 /* When stepping over a breakpoint, we lock all threads
5238 except the one that needs to move past the breakpoint.
5239 If a non-event thread has this set, the "incomplete
5240 step-over" check above should have caught it earlier. */
5241 gdb_assert (!tp
->control
.trap_expected
);
5243 /* Did we find the stepping thread? */
5244 if (tp
->control
.step_range_end
)
5246 /* Yep. There should only one though. */
5247 gdb_assert (stepping_thread
== NULL
);
5249 /* The event thread is handled at the top, before we
5251 gdb_assert (tp
!= ecs
->event_thread
);
5253 /* If some thread other than the event thread is
5254 stepping, then scheduler locking can't be in effect,
5255 otherwise we wouldn't have resumed the current event
5256 thread in the first place. */
5257 gdb_assert (!schedlock_applies (1));
5259 stepping_thread
= tp
;
5261 else if (thread_still_needs_step_over (tp
))
5265 /* At the top we've returned early if the event thread
5266 is stepping. If some other thread not the event
5267 thread is stepping, then scheduler locking can't be
5268 in effect, and we can resume this thread. No need to
5269 keep looking for the stepping thread then. */
5274 if (step_over
!= NULL
)
5279 fprintf_unfiltered (gdb_stdlog
,
5280 "infrun: need to step-over [%s]\n",
5281 target_pid_to_str (tp
->ptid
));
5284 /* Only the stepping thread should have this set. */
5285 gdb_assert (tp
->control
.step_range_end
== 0);
5287 ecs
->ptid
= tp
->ptid
;
5288 ecs
->event_thread
= tp
;
5289 switch_to_thread (ecs
->ptid
);
5294 if (stepping_thread
!= NULL
)
5296 struct frame_info
*frame
;
5297 struct gdbarch
*gdbarch
;
5299 tp
= stepping_thread
;
5301 /* If the stepping thread exited, then don't try to switch
5302 back and resume it, which could fail in several different
5303 ways depending on the target. Instead, just keep going.
5305 We can find a stepping dead thread in the thread list in
5308 - The target supports thread exit events, and when the
5309 target tries to delete the thread from the thread list,
5310 inferior_ptid pointed at the exiting thread. In such
5311 case, calling delete_thread does not really remove the
5312 thread from the list; instead, the thread is left listed,
5313 with 'exited' state.
5315 - The target's debug interface does not support thread
5316 exit events, and so we have no idea whatsoever if the
5317 previously stepping thread is still alive. For that
5318 reason, we need to synchronously query the target
5320 if (is_exited (tp
->ptid
)
5321 || !target_thread_alive (tp
->ptid
))
5324 fprintf_unfiltered (gdb_stdlog
,
5325 "infrun: not switching back to "
5326 "stepped thread, it has vanished\n");
5328 delete_thread (tp
->ptid
);
5334 fprintf_unfiltered (gdb_stdlog
,
5335 "infrun: switching back to stepped thread\n");
5337 ecs
->event_thread
= tp
;
5338 ecs
->ptid
= tp
->ptid
;
5339 context_switch (ecs
->ptid
);
5341 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5342 frame
= get_current_frame ();
5343 gdbarch
= get_frame_arch (frame
);
5345 /* If the PC of the thread we were trying to single-step has
5346 changed, then that thread has trapped or been signaled,
5347 but the event has not been reported to GDB yet. Re-poll
5348 the target looking for this particular thread's event
5349 (i.e. temporarily enable schedlock) by:
5351 - setting a break at the current PC
5352 - resuming that particular thread, only (by setting
5355 This prevents us continuously moving the single-step
5356 breakpoint forward, one instruction at a time,
5359 if (gdbarch_software_single_step_p (gdbarch
)
5360 && stop_pc
!= tp
->prev_pc
)
5363 fprintf_unfiltered (gdb_stdlog
,
5364 "infrun: expected thread advanced also\n");
5366 insert_single_step_breakpoint (get_frame_arch (frame
),
5367 get_frame_address_space (frame
),
5369 singlestep_breakpoints_inserted_p
= 1;
5370 ecs
->event_thread
->control
.trap_expected
= 1;
5371 singlestep_ptid
= inferior_ptid
;
5372 singlestep_pc
= stop_pc
;
5374 resume (0, GDB_SIGNAL_0
);
5375 prepare_to_wait (ecs
);
5380 fprintf_unfiltered (gdb_stdlog
,
5381 "infrun: expected thread still "
5382 "hasn't advanced\n");
5392 /* Is thread TP in the middle of single-stepping? */
5395 currently_stepping (struct thread_info
*tp
)
5397 return ((tp
->control
.step_range_end
5398 && tp
->control
.step_resume_breakpoint
== NULL
)
5399 || tp
->control
.trap_expected
5400 || bpstat_should_step ());
5403 /* Inferior has stepped into a subroutine call with source code that
5404 we should not step over. Do step to the first line of code in
5408 handle_step_into_function (struct gdbarch
*gdbarch
,
5409 struct execution_control_state
*ecs
)
5412 struct symtab_and_line stop_func_sal
, sr_sal
;
5414 fill_in_stop_func (gdbarch
, ecs
);
5416 s
= find_pc_symtab (stop_pc
);
5417 if (s
&& s
->language
!= language_asm
)
5418 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5419 ecs
->stop_func_start
);
5421 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5422 /* Use the step_resume_break to step until the end of the prologue,
5423 even if that involves jumps (as it seems to on the vax under
5425 /* If the prologue ends in the middle of a source line, continue to
5426 the end of that source line (if it is still within the function).
5427 Otherwise, just go to end of prologue. */
5428 if (stop_func_sal
.end
5429 && stop_func_sal
.pc
!= ecs
->stop_func_start
5430 && stop_func_sal
.end
< ecs
->stop_func_end
)
5431 ecs
->stop_func_start
= stop_func_sal
.end
;
5433 /* Architectures which require breakpoint adjustment might not be able
5434 to place a breakpoint at the computed address. If so, the test
5435 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5436 ecs->stop_func_start to an address at which a breakpoint may be
5437 legitimately placed.
5439 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5440 made, GDB will enter an infinite loop when stepping through
5441 optimized code consisting of VLIW instructions which contain
5442 subinstructions corresponding to different source lines. On
5443 FR-V, it's not permitted to place a breakpoint on any but the
5444 first subinstruction of a VLIW instruction. When a breakpoint is
5445 set, GDB will adjust the breakpoint address to the beginning of
5446 the VLIW instruction. Thus, we need to make the corresponding
5447 adjustment here when computing the stop address. */
5449 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5451 ecs
->stop_func_start
5452 = gdbarch_adjust_breakpoint_address (gdbarch
,
5453 ecs
->stop_func_start
);
5456 if (ecs
->stop_func_start
== stop_pc
)
5458 /* We are already there: stop now. */
5459 ecs
->event_thread
->control
.stop_step
= 1;
5460 print_end_stepping_range_reason ();
5461 stop_stepping (ecs
);
5466 /* Put the step-breakpoint there and go until there. */
5467 init_sal (&sr_sal
); /* initialize to zeroes */
5468 sr_sal
.pc
= ecs
->stop_func_start
;
5469 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5470 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5472 /* Do not specify what the fp should be when we stop since on
5473 some machines the prologue is where the new fp value is
5475 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5477 /* And make sure stepping stops right away then. */
5478 ecs
->event_thread
->control
.step_range_end
5479 = ecs
->event_thread
->control
.step_range_start
;
5484 /* Inferior has stepped backward into a subroutine call with source
5485 code that we should not step over. Do step to the beginning of the
5486 last line of code in it. */
5489 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5490 struct execution_control_state
*ecs
)
5493 struct symtab_and_line stop_func_sal
;
5495 fill_in_stop_func (gdbarch
, ecs
);
5497 s
= find_pc_symtab (stop_pc
);
5498 if (s
&& s
->language
!= language_asm
)
5499 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5500 ecs
->stop_func_start
);
5502 stop_func_sal
= find_pc_line (stop_pc
, 0);
5504 /* OK, we're just going to keep stepping here. */
5505 if (stop_func_sal
.pc
== stop_pc
)
5507 /* We're there already. Just stop stepping now. */
5508 ecs
->event_thread
->control
.stop_step
= 1;
5509 print_end_stepping_range_reason ();
5510 stop_stepping (ecs
);
5514 /* Else just reset the step range and keep going.
5515 No step-resume breakpoint, they don't work for
5516 epilogues, which can have multiple entry paths. */
5517 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5518 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5524 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5525 This is used to both functions and to skip over code. */
5528 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5529 struct symtab_and_line sr_sal
,
5530 struct frame_id sr_id
,
5531 enum bptype sr_type
)
5533 /* There should never be more than one step-resume or longjmp-resume
5534 breakpoint per thread, so we should never be setting a new
5535 step_resume_breakpoint when one is already active. */
5536 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5537 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5540 fprintf_unfiltered (gdb_stdlog
,
5541 "infrun: inserting step-resume breakpoint at %s\n",
5542 paddress (gdbarch
, sr_sal
.pc
));
5544 inferior_thread ()->control
.step_resume_breakpoint
5545 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5549 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5550 struct symtab_and_line sr_sal
,
5551 struct frame_id sr_id
)
5553 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5558 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5559 This is used to skip a potential signal handler.
5561 This is called with the interrupted function's frame. The signal
5562 handler, when it returns, will resume the interrupted function at
5566 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5568 struct symtab_and_line sr_sal
;
5569 struct gdbarch
*gdbarch
;
5571 gdb_assert (return_frame
!= NULL
);
5572 init_sal (&sr_sal
); /* initialize to zeros */
5574 gdbarch
= get_frame_arch (return_frame
);
5575 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5576 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5577 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5579 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5580 get_stack_frame_id (return_frame
),
5584 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5585 is used to skip a function after stepping into it (for "next" or if
5586 the called function has no debugging information).
5588 The current function has almost always been reached by single
5589 stepping a call or return instruction. NEXT_FRAME belongs to the
5590 current function, and the breakpoint will be set at the caller's
5593 This is a separate function rather than reusing
5594 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5595 get_prev_frame, which may stop prematurely (see the implementation
5596 of frame_unwind_caller_id for an example). */
5599 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5601 struct symtab_and_line sr_sal
;
5602 struct gdbarch
*gdbarch
;
5604 /* We shouldn't have gotten here if we don't know where the call site
5606 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5608 init_sal (&sr_sal
); /* initialize to zeros */
5610 gdbarch
= frame_unwind_caller_arch (next_frame
);
5611 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5612 frame_unwind_caller_pc (next_frame
));
5613 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5614 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5616 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5617 frame_unwind_caller_id (next_frame
));
5620 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5621 new breakpoint at the target of a jmp_buf. The handling of
5622 longjmp-resume uses the same mechanisms used for handling
5623 "step-resume" breakpoints. */
5626 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5628 /* There should never be more than one longjmp-resume breakpoint per
5629 thread, so we should never be setting a new
5630 longjmp_resume_breakpoint when one is already active. */
5631 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
5634 fprintf_unfiltered (gdb_stdlog
,
5635 "infrun: inserting longjmp-resume breakpoint at %s\n",
5636 paddress (gdbarch
, pc
));
5638 inferior_thread ()->control
.exception_resume_breakpoint
=
5639 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
5642 /* Insert an exception resume breakpoint. TP is the thread throwing
5643 the exception. The block B is the block of the unwinder debug hook
5644 function. FRAME is the frame corresponding to the call to this
5645 function. SYM is the symbol of the function argument holding the
5646 target PC of the exception. */
5649 insert_exception_resume_breakpoint (struct thread_info
*tp
,
5651 struct frame_info
*frame
,
5654 volatile struct gdb_exception e
;
5656 /* We want to ignore errors here. */
5657 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5659 struct symbol
*vsym
;
5660 struct value
*value
;
5662 struct breakpoint
*bp
;
5664 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
5665 value
= read_var_value (vsym
, frame
);
5666 /* If the value was optimized out, revert to the old behavior. */
5667 if (! value_optimized_out (value
))
5669 handler
= value_as_address (value
);
5672 fprintf_unfiltered (gdb_stdlog
,
5673 "infrun: exception resume at %lx\n",
5674 (unsigned long) handler
);
5676 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5677 handler
, bp_exception_resume
);
5679 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5682 bp
->thread
= tp
->num
;
5683 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5688 /* A helper for check_exception_resume that sets an
5689 exception-breakpoint based on a SystemTap probe. */
5692 insert_exception_resume_from_probe (struct thread_info
*tp
,
5693 const struct bound_probe
*probe
,
5694 struct frame_info
*frame
)
5696 struct value
*arg_value
;
5698 struct breakpoint
*bp
;
5700 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
5704 handler
= value_as_address (arg_value
);
5707 fprintf_unfiltered (gdb_stdlog
,
5708 "infrun: exception resume at %s\n",
5709 paddress (get_objfile_arch (probe
->objfile
),
5712 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5713 handler
, bp_exception_resume
);
5714 bp
->thread
= tp
->num
;
5715 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5718 /* This is called when an exception has been intercepted. Check to
5719 see whether the exception's destination is of interest, and if so,
5720 set an exception resume breakpoint there. */
5723 check_exception_resume (struct execution_control_state
*ecs
,
5724 struct frame_info
*frame
)
5726 volatile struct gdb_exception e
;
5727 struct bound_probe probe
;
5728 struct symbol
*func
;
5730 /* First see if this exception unwinding breakpoint was set via a
5731 SystemTap probe point. If so, the probe has two arguments: the
5732 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5733 set a breakpoint there. */
5734 probe
= find_probe_by_pc (get_frame_pc (frame
));
5737 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
5741 func
= get_frame_function (frame
);
5745 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5748 struct block_iterator iter
;
5752 /* The exception breakpoint is a thread-specific breakpoint on
5753 the unwinder's debug hook, declared as:
5755 void _Unwind_DebugHook (void *cfa, void *handler);
5757 The CFA argument indicates the frame to which control is
5758 about to be transferred. HANDLER is the destination PC.
5760 We ignore the CFA and set a temporary breakpoint at HANDLER.
5761 This is not extremely efficient but it avoids issues in gdb
5762 with computing the DWARF CFA, and it also works even in weird
5763 cases such as throwing an exception from inside a signal
5766 b
= SYMBOL_BLOCK_VALUE (func
);
5767 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5769 if (!SYMBOL_IS_ARGUMENT (sym
))
5776 insert_exception_resume_breakpoint (ecs
->event_thread
,
5785 stop_stepping (struct execution_control_state
*ecs
)
5788 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
5790 clear_step_over_info ();
5792 /* Let callers know we don't want to wait for the inferior anymore. */
5793 ecs
->wait_some_more
= 0;
5796 /* Called when we should continue running the inferior, because the
5797 current event doesn't cause a user visible stop. This does the
5798 resuming part; waiting for the next event is done elsewhere. */
5801 keep_going (struct execution_control_state
*ecs
)
5803 /* Make sure normal_stop is called if we get a QUIT handled before
5805 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
5807 /* Save the pc before execution, to compare with pc after stop. */
5808 ecs
->event_thread
->prev_pc
5809 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5811 if (ecs
->event_thread
->control
.trap_expected
5812 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5814 /* We haven't yet gotten our trap, and either: intercepted a
5815 non-signal event (e.g., a fork); or took a signal which we
5816 are supposed to pass through to the inferior. Simply
5818 discard_cleanups (old_cleanups
);
5819 resume (currently_stepping (ecs
->event_thread
),
5820 ecs
->event_thread
->suspend
.stop_signal
);
5824 volatile struct gdb_exception e
;
5825 struct regcache
*regcache
= get_current_regcache ();
5827 /* Either the trap was not expected, but we are continuing
5828 anyway (if we got a signal, the user asked it be passed to
5831 We got our expected trap, but decided we should resume from
5834 We're going to run this baby now!
5836 Note that insert_breakpoints won't try to re-insert
5837 already inserted breakpoints. Therefore, we don't
5838 care if breakpoints were already inserted, or not. */
5840 /* If we need to step over a breakpoint, and we're not using
5841 displaced stepping to do so, insert all breakpoints
5842 (watchpoints, etc.) but the one we're stepping over, step one
5843 instruction, and then re-insert the breakpoint when that step
5845 if ((ecs
->hit_singlestep_breakpoint
5846 || thread_still_needs_step_over (ecs
->event_thread
))
5847 && !use_displaced_stepping (get_regcache_arch (regcache
)))
5849 set_step_over_info (get_regcache_aspace (regcache
),
5850 regcache_read_pc (regcache
));
5853 clear_step_over_info ();
5855 /* Stop stepping if inserting breakpoints fails. */
5856 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5858 insert_breakpoints ();
5862 exception_print (gdb_stderr
, e
);
5863 stop_stepping (ecs
);
5867 ecs
->event_thread
->control
.trap_expected
5868 = (ecs
->event_thread
->stepping_over_breakpoint
5869 || ecs
->hit_singlestep_breakpoint
);
5871 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
5872 explicitly specifies that such a signal should be delivered
5873 to the target program). Typically, that would occur when a
5874 user is debugging a target monitor on a simulator: the target
5875 monitor sets a breakpoint; the simulator encounters this
5876 breakpoint and halts the simulation handing control to GDB;
5877 GDB, noting that the stop address doesn't map to any known
5878 breakpoint, returns control back to the simulator; the
5879 simulator then delivers the hardware equivalent of a
5880 GDB_SIGNAL_TRAP to the program being debugged. */
5881 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5882 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5883 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5885 discard_cleanups (old_cleanups
);
5886 resume (currently_stepping (ecs
->event_thread
),
5887 ecs
->event_thread
->suspend
.stop_signal
);
5890 prepare_to_wait (ecs
);
5893 /* This function normally comes after a resume, before
5894 handle_inferior_event exits. It takes care of any last bits of
5895 housekeeping, and sets the all-important wait_some_more flag. */
5898 prepare_to_wait (struct execution_control_state
*ecs
)
5901 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
5903 /* This is the old end of the while loop. Let everybody know we
5904 want to wait for the inferior some more and get called again
5906 ecs
->wait_some_more
= 1;
5909 /* Several print_*_reason functions to print why the inferior has stopped.
5910 We always print something when the inferior exits, or receives a signal.
5911 The rest of the cases are dealt with later on in normal_stop and
5912 print_it_typical. Ideally there should be a call to one of these
5913 print_*_reason functions functions from handle_inferior_event each time
5914 stop_stepping is called. */
5916 /* Print why the inferior has stopped.
5917 We are done with a step/next/si/ni command, print why the inferior has
5918 stopped. For now print nothing. Print a message only if not in the middle
5919 of doing a "step n" operation for n > 1. */
5922 print_end_stepping_range_reason (void)
5924 if ((!inferior_thread ()->step_multi
5925 || !inferior_thread ()->control
.stop_step
)
5926 && ui_out_is_mi_like_p (current_uiout
))
5927 ui_out_field_string (current_uiout
, "reason",
5928 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
5931 /* The inferior was terminated by a signal, print why it stopped. */
5934 print_signal_exited_reason (enum gdb_signal siggnal
)
5936 struct ui_out
*uiout
= current_uiout
;
5938 annotate_signalled ();
5939 if (ui_out_is_mi_like_p (uiout
))
5941 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
5942 ui_out_text (uiout
, "\nProgram terminated with signal ");
5943 annotate_signal_name ();
5944 ui_out_field_string (uiout
, "signal-name",
5945 gdb_signal_to_name (siggnal
));
5946 annotate_signal_name_end ();
5947 ui_out_text (uiout
, ", ");
5948 annotate_signal_string ();
5949 ui_out_field_string (uiout
, "signal-meaning",
5950 gdb_signal_to_string (siggnal
));
5951 annotate_signal_string_end ();
5952 ui_out_text (uiout
, ".\n");
5953 ui_out_text (uiout
, "The program no longer exists.\n");
5956 /* The inferior program is finished, print why it stopped. */
5959 print_exited_reason (int exitstatus
)
5961 struct inferior
*inf
= current_inferior ();
5962 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
5963 struct ui_out
*uiout
= current_uiout
;
5965 annotate_exited (exitstatus
);
5968 if (ui_out_is_mi_like_p (uiout
))
5969 ui_out_field_string (uiout
, "reason",
5970 async_reason_lookup (EXEC_ASYNC_EXITED
));
5971 ui_out_text (uiout
, "[Inferior ");
5972 ui_out_text (uiout
, plongest (inf
->num
));
5973 ui_out_text (uiout
, " (");
5974 ui_out_text (uiout
, pidstr
);
5975 ui_out_text (uiout
, ") exited with code ");
5976 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
5977 ui_out_text (uiout
, "]\n");
5981 if (ui_out_is_mi_like_p (uiout
))
5983 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
5984 ui_out_text (uiout
, "[Inferior ");
5985 ui_out_text (uiout
, plongest (inf
->num
));
5986 ui_out_text (uiout
, " (");
5987 ui_out_text (uiout
, pidstr
);
5988 ui_out_text (uiout
, ") exited normally]\n");
5992 /* Signal received, print why the inferior has stopped. The signal table
5993 tells us to print about it. */
5996 print_signal_received_reason (enum gdb_signal siggnal
)
5998 struct ui_out
*uiout
= current_uiout
;
6002 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
6004 struct thread_info
*t
= inferior_thread ();
6006 ui_out_text (uiout
, "\n[");
6007 ui_out_field_string (uiout
, "thread-name",
6008 target_pid_to_str (t
->ptid
));
6009 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
6010 ui_out_text (uiout
, " stopped");
6014 ui_out_text (uiout
, "\nProgram received signal ");
6015 annotate_signal_name ();
6016 if (ui_out_is_mi_like_p (uiout
))
6018 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
6019 ui_out_field_string (uiout
, "signal-name",
6020 gdb_signal_to_name (siggnal
));
6021 annotate_signal_name_end ();
6022 ui_out_text (uiout
, ", ");
6023 annotate_signal_string ();
6024 ui_out_field_string (uiout
, "signal-meaning",
6025 gdb_signal_to_string (siggnal
));
6026 annotate_signal_string_end ();
6028 ui_out_text (uiout
, ".\n");
6031 /* Reverse execution: target ran out of history info, print why the inferior
6035 print_no_history_reason (void)
6037 ui_out_text (current_uiout
, "\nNo more reverse-execution history.\n");
6040 /* Print current location without a level number, if we have changed
6041 functions or hit a breakpoint. Print source line if we have one.
6042 bpstat_print contains the logic deciding in detail what to print,
6043 based on the event(s) that just occurred. */
6046 print_stop_event (struct target_waitstatus
*ws
)
6050 int do_frame_printing
= 1;
6051 struct thread_info
*tp
= inferior_thread ();
6053 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
6057 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
6058 should) carry around the function and does (or should) use
6059 that when doing a frame comparison. */
6060 if (tp
->control
.stop_step
6061 && frame_id_eq (tp
->control
.step_frame_id
,
6062 get_frame_id (get_current_frame ()))
6063 && step_start_function
== find_pc_function (stop_pc
))
6065 /* Finished step, just print source line. */
6066 source_flag
= SRC_LINE
;
6070 /* Print location and source line. */
6071 source_flag
= SRC_AND_LOC
;
6074 case PRINT_SRC_AND_LOC
:
6075 /* Print location and source line. */
6076 source_flag
= SRC_AND_LOC
;
6078 case PRINT_SRC_ONLY
:
6079 source_flag
= SRC_LINE
;
6082 /* Something bogus. */
6083 source_flag
= SRC_LINE
;
6084 do_frame_printing
= 0;
6087 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6090 /* The behavior of this routine with respect to the source
6092 SRC_LINE: Print only source line
6093 LOCATION: Print only location
6094 SRC_AND_LOC: Print location and source line. */
6095 if (do_frame_printing
)
6096 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
6098 /* Display the auto-display expressions. */
6102 /* Here to return control to GDB when the inferior stops for real.
6103 Print appropriate messages, remove breakpoints, give terminal our modes.
6105 STOP_PRINT_FRAME nonzero means print the executing frame
6106 (pc, function, args, file, line number and line text).
6107 BREAKPOINTS_FAILED nonzero means stop was due to error
6108 attempting to insert breakpoints. */
6113 struct target_waitstatus last
;
6115 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
6117 get_last_target_status (&last_ptid
, &last
);
6119 /* If an exception is thrown from this point on, make sure to
6120 propagate GDB's knowledge of the executing state to the
6121 frontend/user running state. A QUIT is an easy exception to see
6122 here, so do this before any filtered output. */
6124 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
6125 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6126 && last
.kind
!= TARGET_WAITKIND_EXITED
6127 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6128 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
6130 /* As with the notification of thread events, we want to delay
6131 notifying the user that we've switched thread context until
6132 the inferior actually stops.
6134 There's no point in saying anything if the inferior has exited.
6135 Note that SIGNALLED here means "exited with a signal", not
6136 "received a signal".
6138 Also skip saying anything in non-stop mode. In that mode, as we
6139 don't want GDB to switch threads behind the user's back, to avoid
6140 races where the user is typing a command to apply to thread x,
6141 but GDB switches to thread y before the user finishes entering
6142 the command, fetch_inferior_event installs a cleanup to restore
6143 the current thread back to the thread the user had selected right
6144 after this event is handled, so we're not really switching, only
6145 informing of a stop. */
6147 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
6148 && target_has_execution
6149 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6150 && last
.kind
!= TARGET_WAITKIND_EXITED
6151 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6153 target_terminal_ours_for_output ();
6154 printf_filtered (_("[Switching to %s]\n"),
6155 target_pid_to_str (inferior_ptid
));
6156 annotate_thread_changed ();
6157 previous_inferior_ptid
= inferior_ptid
;
6160 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
6162 gdb_assert (sync_execution
|| !target_can_async_p ());
6164 target_terminal_ours_for_output ();
6165 printf_filtered (_("No unwaited-for children left.\n"));
6168 if (!breakpoints_always_inserted_mode () && target_has_execution
)
6170 if (remove_breakpoints ())
6172 target_terminal_ours_for_output ();
6173 printf_filtered (_("Cannot remove breakpoints because "
6174 "program is no longer writable.\nFurther "
6175 "execution is probably impossible.\n"));
6179 /* If an auto-display called a function and that got a signal,
6180 delete that auto-display to avoid an infinite recursion. */
6182 if (stopped_by_random_signal
)
6183 disable_current_display ();
6185 /* Don't print a message if in the middle of doing a "step n"
6186 operation for n > 1 */
6187 if (target_has_execution
6188 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6189 && last
.kind
!= TARGET_WAITKIND_EXITED
6190 && inferior_thread ()->step_multi
6191 && inferior_thread ()->control
.stop_step
)
6194 target_terminal_ours ();
6195 async_enable_stdin ();
6197 /* Set the current source location. This will also happen if we
6198 display the frame below, but the current SAL will be incorrect
6199 during a user hook-stop function. */
6200 if (has_stack_frames () && !stop_stack_dummy
)
6201 set_current_sal_from_frame (get_current_frame ());
6203 /* Let the user/frontend see the threads as stopped, but do nothing
6204 if the thread was running an infcall. We may be e.g., evaluating
6205 a breakpoint condition. In that case, the thread had state
6206 THREAD_RUNNING before the infcall, and shall remain set to
6207 running, all without informing the user/frontend about state
6208 transition changes. If this is actually a call command, then the
6209 thread was originally already stopped, so there's no state to
6211 if (target_has_execution
&& inferior_thread ()->control
.in_infcall
)
6212 discard_cleanups (old_chain
);
6214 do_cleanups (old_chain
);
6216 /* Look up the hook_stop and run it (CLI internally handles problem
6217 of stop_command's pre-hook not existing). */
6219 catch_errors (hook_stop_stub
, stop_command
,
6220 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6222 if (!has_stack_frames ())
6225 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6226 || last
.kind
== TARGET_WAITKIND_EXITED
)
6229 /* Select innermost stack frame - i.e., current frame is frame 0,
6230 and current location is based on that.
6231 Don't do this on return from a stack dummy routine,
6232 or if the program has exited. */
6234 if (!stop_stack_dummy
)
6236 select_frame (get_current_frame ());
6238 /* If --batch-silent is enabled then there's no need to print the current
6239 source location, and to try risks causing an error message about
6240 missing source files. */
6241 if (stop_print_frame
&& !batch_silent
)
6242 print_stop_event (&last
);
6245 /* Save the function value return registers, if we care.
6246 We might be about to restore their previous contents. */
6247 if (inferior_thread ()->control
.proceed_to_finish
6248 && execution_direction
!= EXEC_REVERSE
)
6250 /* This should not be necessary. */
6252 regcache_xfree (stop_registers
);
6254 /* NB: The copy goes through to the target picking up the value of
6255 all the registers. */
6256 stop_registers
= regcache_dup (get_current_regcache ());
6259 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6261 /* Pop the empty frame that contains the stack dummy.
6262 This also restores inferior state prior to the call
6263 (struct infcall_suspend_state). */
6264 struct frame_info
*frame
= get_current_frame ();
6266 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6268 /* frame_pop() calls reinit_frame_cache as the last thing it
6269 does which means there's currently no selected frame. We
6270 don't need to re-establish a selected frame if the dummy call
6271 returns normally, that will be done by
6272 restore_infcall_control_state. However, we do have to handle
6273 the case where the dummy call is returning after being
6274 stopped (e.g. the dummy call previously hit a breakpoint).
6275 We can't know which case we have so just always re-establish
6276 a selected frame here. */
6277 select_frame (get_current_frame ());
6281 annotate_stopped ();
6283 /* Suppress the stop observer if we're in the middle of:
6285 - a step n (n > 1), as there still more steps to be done.
6287 - a "finish" command, as the observer will be called in
6288 finish_command_continuation, so it can include the inferior
6289 function's return value.
6291 - calling an inferior function, as we pretend we inferior didn't
6292 run at all. The return value of the call is handled by the
6293 expression evaluator, through call_function_by_hand. */
6295 if (!target_has_execution
6296 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6297 || last
.kind
== TARGET_WAITKIND_EXITED
6298 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6299 || (!(inferior_thread ()->step_multi
6300 && inferior_thread ()->control
.stop_step
)
6301 && !(inferior_thread ()->control
.stop_bpstat
6302 && inferior_thread ()->control
.proceed_to_finish
)
6303 && !inferior_thread ()->control
.in_infcall
))
6305 if (!ptid_equal (inferior_ptid
, null_ptid
))
6306 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6309 observer_notify_normal_stop (NULL
, stop_print_frame
);
6312 if (target_has_execution
)
6314 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6315 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6316 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6317 Delete any breakpoint that is to be deleted at the next stop. */
6318 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6321 /* Try to get rid of automatically added inferiors that are no
6322 longer needed. Keeping those around slows down things linearly.
6323 Note that this never removes the current inferior. */
6328 hook_stop_stub (void *cmd
)
6330 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6335 signal_stop_state (int signo
)
6337 return signal_stop
[signo
];
6341 signal_print_state (int signo
)
6343 return signal_print
[signo
];
6347 signal_pass_state (int signo
)
6349 return signal_program
[signo
];
6353 signal_cache_update (int signo
)
6357 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6358 signal_cache_update (signo
);
6363 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6364 && signal_print
[signo
] == 0
6365 && signal_program
[signo
] == 1
6366 && signal_catch
[signo
] == 0);
6370 signal_stop_update (int signo
, int state
)
6372 int ret
= signal_stop
[signo
];
6374 signal_stop
[signo
] = state
;
6375 signal_cache_update (signo
);
6380 signal_print_update (int signo
, int state
)
6382 int ret
= signal_print
[signo
];
6384 signal_print
[signo
] = state
;
6385 signal_cache_update (signo
);
6390 signal_pass_update (int signo
, int state
)
6392 int ret
= signal_program
[signo
];
6394 signal_program
[signo
] = state
;
6395 signal_cache_update (signo
);
6399 /* Update the global 'signal_catch' from INFO and notify the
6403 signal_catch_update (const unsigned int *info
)
6407 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
6408 signal_catch
[i
] = info
[i
] > 0;
6409 signal_cache_update (-1);
6410 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6414 sig_print_header (void)
6416 printf_filtered (_("Signal Stop\tPrint\tPass "
6417 "to program\tDescription\n"));
6421 sig_print_info (enum gdb_signal oursig
)
6423 const char *name
= gdb_signal_to_name (oursig
);
6424 int name_padding
= 13 - strlen (name
);
6426 if (name_padding
<= 0)
6429 printf_filtered ("%s", name
);
6430 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6431 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6432 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6433 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6434 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6437 /* Specify how various signals in the inferior should be handled. */
6440 handle_command (char *args
, int from_tty
)
6443 int digits
, wordlen
;
6444 int sigfirst
, signum
, siglast
;
6445 enum gdb_signal oursig
;
6448 unsigned char *sigs
;
6449 struct cleanup
*old_chain
;
6453 error_no_arg (_("signal to handle"));
6456 /* Allocate and zero an array of flags for which signals to handle. */
6458 nsigs
= (int) GDB_SIGNAL_LAST
;
6459 sigs
= (unsigned char *) alloca (nsigs
);
6460 memset (sigs
, 0, nsigs
);
6462 /* Break the command line up into args. */
6464 argv
= gdb_buildargv (args
);
6465 old_chain
= make_cleanup_freeargv (argv
);
6467 /* Walk through the args, looking for signal oursigs, signal names, and
6468 actions. Signal numbers and signal names may be interspersed with
6469 actions, with the actions being performed for all signals cumulatively
6470 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6472 while (*argv
!= NULL
)
6474 wordlen
= strlen (*argv
);
6475 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6479 sigfirst
= siglast
= -1;
6481 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6483 /* Apply action to all signals except those used by the
6484 debugger. Silently skip those. */
6487 siglast
= nsigs
- 1;
6489 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6491 SET_SIGS (nsigs
, sigs
, signal_stop
);
6492 SET_SIGS (nsigs
, sigs
, signal_print
);
6494 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6496 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6498 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6500 SET_SIGS (nsigs
, sigs
, signal_print
);
6502 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6504 SET_SIGS (nsigs
, sigs
, signal_program
);
6506 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6508 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6510 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6512 SET_SIGS (nsigs
, sigs
, signal_program
);
6514 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6516 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6517 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6519 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6521 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6523 else if (digits
> 0)
6525 /* It is numeric. The numeric signal refers to our own
6526 internal signal numbering from target.h, not to host/target
6527 signal number. This is a feature; users really should be
6528 using symbolic names anyway, and the common ones like
6529 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6531 sigfirst
= siglast
= (int)
6532 gdb_signal_from_command (atoi (*argv
));
6533 if ((*argv
)[digits
] == '-')
6536 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6538 if (sigfirst
> siglast
)
6540 /* Bet he didn't figure we'd think of this case... */
6548 oursig
= gdb_signal_from_name (*argv
);
6549 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6551 sigfirst
= siglast
= (int) oursig
;
6555 /* Not a number and not a recognized flag word => complain. */
6556 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6560 /* If any signal numbers or symbol names were found, set flags for
6561 which signals to apply actions to. */
6563 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6565 switch ((enum gdb_signal
) signum
)
6567 case GDB_SIGNAL_TRAP
:
6568 case GDB_SIGNAL_INT
:
6569 if (!allsigs
&& !sigs
[signum
])
6571 if (query (_("%s is used by the debugger.\n\
6572 Are you sure you want to change it? "),
6573 gdb_signal_to_name ((enum gdb_signal
) signum
)))
6579 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6580 gdb_flush (gdb_stdout
);
6585 case GDB_SIGNAL_DEFAULT
:
6586 case GDB_SIGNAL_UNKNOWN
:
6587 /* Make sure that "all" doesn't print these. */
6598 for (signum
= 0; signum
< nsigs
; signum
++)
6601 signal_cache_update (-1);
6602 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6603 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
6607 /* Show the results. */
6608 sig_print_header ();
6609 for (; signum
< nsigs
; signum
++)
6611 sig_print_info (signum
);
6617 do_cleanups (old_chain
);
6620 /* Complete the "handle" command. */
6622 static VEC (char_ptr
) *
6623 handle_completer (struct cmd_list_element
*ignore
,
6624 const char *text
, const char *word
)
6626 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
6627 static const char * const keywords
[] =
6641 vec_signals
= signal_completer (ignore
, text
, word
);
6642 vec_keywords
= complete_on_enum (keywords
, word
, word
);
6644 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
6645 VEC_free (char_ptr
, vec_signals
);
6646 VEC_free (char_ptr
, vec_keywords
);
6651 xdb_handle_command (char *args
, int from_tty
)
6654 struct cleanup
*old_chain
;
6657 error_no_arg (_("xdb command"));
6659 /* Break the command line up into args. */
6661 argv
= gdb_buildargv (args
);
6662 old_chain
= make_cleanup_freeargv (argv
);
6663 if (argv
[1] != (char *) NULL
)
6668 bufLen
= strlen (argv
[0]) + 20;
6669 argBuf
= (char *) xmalloc (bufLen
);
6673 enum gdb_signal oursig
;
6675 oursig
= gdb_signal_from_name (argv
[0]);
6676 memset (argBuf
, 0, bufLen
);
6677 if (strcmp (argv
[1], "Q") == 0)
6678 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6681 if (strcmp (argv
[1], "s") == 0)
6683 if (!signal_stop
[oursig
])
6684 sprintf (argBuf
, "%s %s", argv
[0], "stop");
6686 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
6688 else if (strcmp (argv
[1], "i") == 0)
6690 if (!signal_program
[oursig
])
6691 sprintf (argBuf
, "%s %s", argv
[0], "pass");
6693 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
6695 else if (strcmp (argv
[1], "r") == 0)
6697 if (!signal_print
[oursig
])
6698 sprintf (argBuf
, "%s %s", argv
[0], "print");
6700 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6706 handle_command (argBuf
, from_tty
);
6708 printf_filtered (_("Invalid signal handling flag.\n"));
6713 do_cleanups (old_chain
);
6717 gdb_signal_from_command (int num
)
6719 if (num
>= 1 && num
<= 15)
6720 return (enum gdb_signal
) num
;
6721 error (_("Only signals 1-15 are valid as numeric signals.\n\
6722 Use \"info signals\" for a list of symbolic signals."));
6725 /* Print current contents of the tables set by the handle command.
6726 It is possible we should just be printing signals actually used
6727 by the current target (but for things to work right when switching
6728 targets, all signals should be in the signal tables). */
6731 signals_info (char *signum_exp
, int from_tty
)
6733 enum gdb_signal oursig
;
6735 sig_print_header ();
6739 /* First see if this is a symbol name. */
6740 oursig
= gdb_signal_from_name (signum_exp
);
6741 if (oursig
== GDB_SIGNAL_UNKNOWN
)
6743 /* No, try numeric. */
6745 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
6747 sig_print_info (oursig
);
6751 printf_filtered ("\n");
6752 /* These ugly casts brought to you by the native VAX compiler. */
6753 for (oursig
= GDB_SIGNAL_FIRST
;
6754 (int) oursig
< (int) GDB_SIGNAL_LAST
;
6755 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
6759 if (oursig
!= GDB_SIGNAL_UNKNOWN
6760 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
6761 sig_print_info (oursig
);
6764 printf_filtered (_("\nUse the \"handle\" command "
6765 "to change these tables.\n"));
6768 /* Check if it makes sense to read $_siginfo from the current thread
6769 at this point. If not, throw an error. */
6772 validate_siginfo_access (void)
6774 /* No current inferior, no siginfo. */
6775 if (ptid_equal (inferior_ptid
, null_ptid
))
6776 error (_("No thread selected."));
6778 /* Don't try to read from a dead thread. */
6779 if (is_exited (inferior_ptid
))
6780 error (_("The current thread has terminated"));
6782 /* ... or from a spinning thread. */
6783 if (is_running (inferior_ptid
))
6784 error (_("Selected thread is running."));
6787 /* The $_siginfo convenience variable is a bit special. We don't know
6788 for sure the type of the value until we actually have a chance to
6789 fetch the data. The type can change depending on gdbarch, so it is
6790 also dependent on which thread you have selected.
6792 1. making $_siginfo be an internalvar that creates a new value on
6795 2. making the value of $_siginfo be an lval_computed value. */
6797 /* This function implements the lval_computed support for reading a
6801 siginfo_value_read (struct value
*v
)
6803 LONGEST transferred
;
6805 validate_siginfo_access ();
6808 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
6810 value_contents_all_raw (v
),
6812 TYPE_LENGTH (value_type (v
)));
6814 if (transferred
!= TYPE_LENGTH (value_type (v
)))
6815 error (_("Unable to read siginfo"));
6818 /* This function implements the lval_computed support for writing a
6822 siginfo_value_write (struct value
*v
, struct value
*fromval
)
6824 LONGEST transferred
;
6826 validate_siginfo_access ();
6828 transferred
= target_write (¤t_target
,
6829 TARGET_OBJECT_SIGNAL_INFO
,
6831 value_contents_all_raw (fromval
),
6833 TYPE_LENGTH (value_type (fromval
)));
6835 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
6836 error (_("Unable to write siginfo"));
6839 static const struct lval_funcs siginfo_value_funcs
=
6845 /* Return a new value with the correct type for the siginfo object of
6846 the current thread using architecture GDBARCH. Return a void value
6847 if there's no object available. */
6849 static struct value
*
6850 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
6853 if (target_has_stack
6854 && !ptid_equal (inferior_ptid
, null_ptid
)
6855 && gdbarch_get_siginfo_type_p (gdbarch
))
6857 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6859 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
6862 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
6866 /* infcall_suspend_state contains state about the program itself like its
6867 registers and any signal it received when it last stopped.
6868 This state must be restored regardless of how the inferior function call
6869 ends (either successfully, or after it hits a breakpoint or signal)
6870 if the program is to properly continue where it left off. */
6872 struct infcall_suspend_state
6874 struct thread_suspend_state thread_suspend
;
6875 #if 0 /* Currently unused and empty structures are not valid C. */
6876 struct inferior_suspend_state inferior_suspend
;
6881 struct regcache
*registers
;
6883 /* Format of SIGINFO_DATA or NULL if it is not present. */
6884 struct gdbarch
*siginfo_gdbarch
;
6886 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6887 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6888 content would be invalid. */
6889 gdb_byte
*siginfo_data
;
6892 struct infcall_suspend_state
*
6893 save_infcall_suspend_state (void)
6895 struct infcall_suspend_state
*inf_state
;
6896 struct thread_info
*tp
= inferior_thread ();
6898 struct inferior
*inf
= current_inferior ();
6900 struct regcache
*regcache
= get_current_regcache ();
6901 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6902 gdb_byte
*siginfo_data
= NULL
;
6904 if (gdbarch_get_siginfo_type_p (gdbarch
))
6906 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6907 size_t len
= TYPE_LENGTH (type
);
6908 struct cleanup
*back_to
;
6910 siginfo_data
= xmalloc (len
);
6911 back_to
= make_cleanup (xfree
, siginfo_data
);
6913 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6914 siginfo_data
, 0, len
) == len
)
6915 discard_cleanups (back_to
);
6918 /* Errors ignored. */
6919 do_cleanups (back_to
);
6920 siginfo_data
= NULL
;
6924 inf_state
= XCNEW (struct infcall_suspend_state
);
6928 inf_state
->siginfo_gdbarch
= gdbarch
;
6929 inf_state
->siginfo_data
= siginfo_data
;
6932 inf_state
->thread_suspend
= tp
->suspend
;
6933 #if 0 /* Currently unused and empty structures are not valid C. */
6934 inf_state
->inferior_suspend
= inf
->suspend
;
6937 /* run_inferior_call will not use the signal due to its `proceed' call with
6938 GDB_SIGNAL_0 anyway. */
6939 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6941 inf_state
->stop_pc
= stop_pc
;
6943 inf_state
->registers
= regcache_dup (regcache
);
6948 /* Restore inferior session state to INF_STATE. */
6951 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6953 struct thread_info
*tp
= inferior_thread ();
6955 struct inferior
*inf
= current_inferior ();
6957 struct regcache
*regcache
= get_current_regcache ();
6958 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6960 tp
->suspend
= inf_state
->thread_suspend
;
6961 #if 0 /* Currently unused and empty structures are not valid C. */
6962 inf
->suspend
= inf_state
->inferior_suspend
;
6965 stop_pc
= inf_state
->stop_pc
;
6967 if (inf_state
->siginfo_gdbarch
== gdbarch
)
6969 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6971 /* Errors ignored. */
6972 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6973 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
6976 /* The inferior can be gone if the user types "print exit(0)"
6977 (and perhaps other times). */
6978 if (target_has_execution
)
6979 /* NB: The register write goes through to the target. */
6980 regcache_cpy (regcache
, inf_state
->registers
);
6982 discard_infcall_suspend_state (inf_state
);
6986 do_restore_infcall_suspend_state_cleanup (void *state
)
6988 restore_infcall_suspend_state (state
);
6992 make_cleanup_restore_infcall_suspend_state
6993 (struct infcall_suspend_state
*inf_state
)
6995 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
6999 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
7001 regcache_xfree (inf_state
->registers
);
7002 xfree (inf_state
->siginfo_data
);
7007 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
7009 return inf_state
->registers
;
7012 /* infcall_control_state contains state regarding gdb's control of the
7013 inferior itself like stepping control. It also contains session state like
7014 the user's currently selected frame. */
7016 struct infcall_control_state
7018 struct thread_control_state thread_control
;
7019 struct inferior_control_state inferior_control
;
7022 enum stop_stack_kind stop_stack_dummy
;
7023 int stopped_by_random_signal
;
7024 int stop_after_trap
;
7026 /* ID if the selected frame when the inferior function call was made. */
7027 struct frame_id selected_frame_id
;
7030 /* Save all of the information associated with the inferior<==>gdb
7033 struct infcall_control_state
*
7034 save_infcall_control_state (void)
7036 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
7037 struct thread_info
*tp
= inferior_thread ();
7038 struct inferior
*inf
= current_inferior ();
7040 inf_status
->thread_control
= tp
->control
;
7041 inf_status
->inferior_control
= inf
->control
;
7043 tp
->control
.step_resume_breakpoint
= NULL
;
7044 tp
->control
.exception_resume_breakpoint
= NULL
;
7046 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
7047 chain. If caller's caller is walking the chain, they'll be happier if we
7048 hand them back the original chain when restore_infcall_control_state is
7050 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
7053 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
7054 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
7055 inf_status
->stop_after_trap
= stop_after_trap
;
7057 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
7063 restore_selected_frame (void *args
)
7065 struct frame_id
*fid
= (struct frame_id
*) args
;
7066 struct frame_info
*frame
;
7068 frame
= frame_find_by_id (*fid
);
7070 /* If inf_status->selected_frame_id is NULL, there was no previously
7074 warning (_("Unable to restore previously selected frame."));
7078 select_frame (frame
);
7083 /* Restore inferior session state to INF_STATUS. */
7086 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
7088 struct thread_info
*tp
= inferior_thread ();
7089 struct inferior
*inf
= current_inferior ();
7091 if (tp
->control
.step_resume_breakpoint
)
7092 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
7094 if (tp
->control
.exception_resume_breakpoint
)
7095 tp
->control
.exception_resume_breakpoint
->disposition
7096 = disp_del_at_next_stop
;
7098 /* Handle the bpstat_copy of the chain. */
7099 bpstat_clear (&tp
->control
.stop_bpstat
);
7101 tp
->control
= inf_status
->thread_control
;
7102 inf
->control
= inf_status
->inferior_control
;
7105 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
7106 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
7107 stop_after_trap
= inf_status
->stop_after_trap
;
7109 if (target_has_stack
)
7111 /* The point of catch_errors is that if the stack is clobbered,
7112 walking the stack might encounter a garbage pointer and
7113 error() trying to dereference it. */
7115 (restore_selected_frame
, &inf_status
->selected_frame_id
,
7116 "Unable to restore previously selected frame:\n",
7117 RETURN_MASK_ERROR
) == 0)
7118 /* Error in restoring the selected frame. Select the innermost
7120 select_frame (get_current_frame ());
7127 do_restore_infcall_control_state_cleanup (void *sts
)
7129 restore_infcall_control_state (sts
);
7133 make_cleanup_restore_infcall_control_state
7134 (struct infcall_control_state
*inf_status
)
7136 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
7140 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
7142 if (inf_status
->thread_control
.step_resume_breakpoint
)
7143 inf_status
->thread_control
.step_resume_breakpoint
->disposition
7144 = disp_del_at_next_stop
;
7146 if (inf_status
->thread_control
.exception_resume_breakpoint
)
7147 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
7148 = disp_del_at_next_stop
;
7150 /* See save_infcall_control_state for info on stop_bpstat. */
7151 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
7156 /* restore_inferior_ptid() will be used by the cleanup machinery
7157 to restore the inferior_ptid value saved in a call to
7158 save_inferior_ptid(). */
7161 restore_inferior_ptid (void *arg
)
7163 ptid_t
*saved_ptid_ptr
= arg
;
7165 inferior_ptid
= *saved_ptid_ptr
;
7169 /* Save the value of inferior_ptid so that it may be restored by a
7170 later call to do_cleanups(). Returns the struct cleanup pointer
7171 needed for later doing the cleanup. */
7174 save_inferior_ptid (void)
7176 ptid_t
*saved_ptid_ptr
;
7178 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7179 *saved_ptid_ptr
= inferior_ptid
;
7180 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7183 /* See inferior.h. */
7186 clear_exit_convenience_vars (void)
7188 clear_internalvar (lookup_internalvar ("_exitsignal"));
7189 clear_internalvar (lookup_internalvar ("_exitcode"));
7193 /* User interface for reverse debugging:
7194 Set exec-direction / show exec-direction commands
7195 (returns error unless target implements to_set_exec_direction method). */
7197 int execution_direction
= EXEC_FORWARD
;
7198 static const char exec_forward
[] = "forward";
7199 static const char exec_reverse
[] = "reverse";
7200 static const char *exec_direction
= exec_forward
;
7201 static const char *const exec_direction_names
[] = {
7208 set_exec_direction_func (char *args
, int from_tty
,
7209 struct cmd_list_element
*cmd
)
7211 if (target_can_execute_reverse
)
7213 if (!strcmp (exec_direction
, exec_forward
))
7214 execution_direction
= EXEC_FORWARD
;
7215 else if (!strcmp (exec_direction
, exec_reverse
))
7216 execution_direction
= EXEC_REVERSE
;
7220 exec_direction
= exec_forward
;
7221 error (_("Target does not support this operation."));
7226 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7227 struct cmd_list_element
*cmd
, const char *value
)
7229 switch (execution_direction
) {
7231 fprintf_filtered (out
, _("Forward.\n"));
7234 fprintf_filtered (out
, _("Reverse.\n"));
7237 internal_error (__FILE__
, __LINE__
,
7238 _("bogus execution_direction value: %d"),
7239 (int) execution_direction
);
7244 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7245 struct cmd_list_element
*c
, const char *value
)
7247 fprintf_filtered (file
, _("Resuming the execution of threads "
7248 "of all processes is %s.\n"), value
);
7251 /* Implementation of `siginfo' variable. */
7253 static const struct internalvar_funcs siginfo_funcs
=
7261 _initialize_infrun (void)
7265 struct cmd_list_element
*c
;
7267 add_info ("signals", signals_info
, _("\
7268 What debugger does when program gets various signals.\n\
7269 Specify a signal as argument to print info on that signal only."));
7270 add_info_alias ("handle", "signals", 0);
7272 c
= add_com ("handle", class_run
, handle_command
, _("\
7273 Specify how to handle signals.\n\
7274 Usage: handle SIGNAL [ACTIONS]\n\
7275 Args are signals and actions to apply to those signals.\n\
7276 If no actions are specified, the current settings for the specified signals\n\
7277 will be displayed instead.\n\
7279 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7280 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7281 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7282 The special arg \"all\" is recognized to mean all signals except those\n\
7283 used by the debugger, typically SIGTRAP and SIGINT.\n\
7285 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7286 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7287 Stop means reenter debugger if this signal happens (implies print).\n\
7288 Print means print a message if this signal happens.\n\
7289 Pass means let program see this signal; otherwise program doesn't know.\n\
7290 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7291 Pass and Stop may be combined.\n\
7293 Multiple signals may be specified. Signal numbers and signal names\n\
7294 may be interspersed with actions, with the actions being performed for\n\
7295 all signals cumulatively specified."));
7296 set_cmd_completer (c
, handle_completer
);
7300 add_com ("lz", class_info
, signals_info
, _("\
7301 What debugger does when program gets various signals.\n\
7302 Specify a signal as argument to print info on that signal only."));
7303 add_com ("z", class_run
, xdb_handle_command
, _("\
7304 Specify how to handle a signal.\n\
7305 Args are signals and actions to apply to those signals.\n\
7306 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7307 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7308 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7309 The special arg \"all\" is recognized to mean all signals except those\n\
7310 used by the debugger, typically SIGTRAP and SIGINT.\n\
7311 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7312 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7313 nopass), \"Q\" (noprint)\n\
7314 Stop means reenter debugger if this signal happens (implies print).\n\
7315 Print means print a message if this signal happens.\n\
7316 Pass means let program see this signal; otherwise program doesn't know.\n\
7317 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7318 Pass and Stop may be combined."));
7322 stop_command
= add_cmd ("stop", class_obscure
,
7323 not_just_help_class_command
, _("\
7324 There is no `stop' command, but you can set a hook on `stop'.\n\
7325 This allows you to set a list of commands to be run each time execution\n\
7326 of the program stops."), &cmdlist
);
7328 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7329 Set inferior debugging."), _("\
7330 Show inferior debugging."), _("\
7331 When non-zero, inferior specific debugging is enabled."),
7334 &setdebuglist
, &showdebuglist
);
7336 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7337 &debug_displaced
, _("\
7338 Set displaced stepping debugging."), _("\
7339 Show displaced stepping debugging."), _("\
7340 When non-zero, displaced stepping specific debugging is enabled."),
7342 show_debug_displaced
,
7343 &setdebuglist
, &showdebuglist
);
7345 add_setshow_boolean_cmd ("non-stop", no_class
,
7347 Set whether gdb controls the inferior in non-stop mode."), _("\
7348 Show whether gdb controls the inferior in non-stop mode."), _("\
7349 When debugging a multi-threaded program and this setting is\n\
7350 off (the default, also called all-stop mode), when one thread stops\n\
7351 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7352 all other threads in the program while you interact with the thread of\n\
7353 interest. When you continue or step a thread, you can allow the other\n\
7354 threads to run, or have them remain stopped, but while you inspect any\n\
7355 thread's state, all threads stop.\n\
7357 In non-stop mode, when one thread stops, other threads can continue\n\
7358 to run freely. You'll be able to step each thread independently,\n\
7359 leave it stopped or free to run as needed."),
7365 numsigs
= (int) GDB_SIGNAL_LAST
;
7366 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7367 signal_print
= (unsigned char *)
7368 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7369 signal_program
= (unsigned char *)
7370 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7371 signal_catch
= (unsigned char *)
7372 xmalloc (sizeof (signal_catch
[0]) * numsigs
);
7373 signal_pass
= (unsigned char *)
7374 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7375 for (i
= 0; i
< numsigs
; i
++)
7378 signal_print
[i
] = 1;
7379 signal_program
[i
] = 1;
7380 signal_catch
[i
] = 0;
7383 /* Signals caused by debugger's own actions
7384 should not be given to the program afterwards. */
7385 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7386 signal_program
[GDB_SIGNAL_INT
] = 0;
7388 /* Signals that are not errors should not normally enter the debugger. */
7389 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7390 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7391 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7392 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7393 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7394 signal_print
[GDB_SIGNAL_PROF
] = 0;
7395 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7396 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7397 signal_stop
[GDB_SIGNAL_IO
] = 0;
7398 signal_print
[GDB_SIGNAL_IO
] = 0;
7399 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7400 signal_print
[GDB_SIGNAL_POLL
] = 0;
7401 signal_stop
[GDB_SIGNAL_URG
] = 0;
7402 signal_print
[GDB_SIGNAL_URG
] = 0;
7403 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7404 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7405 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7406 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7408 /* These signals are used internally by user-level thread
7409 implementations. (See signal(5) on Solaris.) Like the above
7410 signals, a healthy program receives and handles them as part of
7411 its normal operation. */
7412 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7413 signal_print
[GDB_SIGNAL_LWP
] = 0;
7414 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7415 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7416 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7417 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7419 /* Update cached state. */
7420 signal_cache_update (-1);
7422 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7423 &stop_on_solib_events
, _("\
7424 Set stopping for shared library events."), _("\
7425 Show stopping for shared library events."), _("\
7426 If nonzero, gdb will give control to the user when the dynamic linker\n\
7427 notifies gdb of shared library events. The most common event of interest\n\
7428 to the user would be loading/unloading of a new library."),
7429 set_stop_on_solib_events
,
7430 show_stop_on_solib_events
,
7431 &setlist
, &showlist
);
7433 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7434 follow_fork_mode_kind_names
,
7435 &follow_fork_mode_string
, _("\
7436 Set debugger response to a program call of fork or vfork."), _("\
7437 Show debugger response to a program call of fork or vfork."), _("\
7438 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7439 parent - the original process is debugged after a fork\n\
7440 child - the new process is debugged after a fork\n\
7441 The unfollowed process will continue to run.\n\
7442 By default, the debugger will follow the parent process."),
7444 show_follow_fork_mode_string
,
7445 &setlist
, &showlist
);
7447 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7448 follow_exec_mode_names
,
7449 &follow_exec_mode_string
, _("\
7450 Set debugger response to a program call of exec."), _("\
7451 Show debugger response to a program call of exec."), _("\
7452 An exec call replaces the program image of a process.\n\
7454 follow-exec-mode can be:\n\
7456 new - the debugger creates a new inferior and rebinds the process\n\
7457 to this new inferior. The program the process was running before\n\
7458 the exec call can be restarted afterwards by restarting the original\n\
7461 same - the debugger keeps the process bound to the same inferior.\n\
7462 The new executable image replaces the previous executable loaded in\n\
7463 the inferior. Restarting the inferior after the exec call restarts\n\
7464 the executable the process was running after the exec call.\n\
7466 By default, the debugger will use the same inferior."),
7468 show_follow_exec_mode_string
,
7469 &setlist
, &showlist
);
7471 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7472 scheduler_enums
, &scheduler_mode
, _("\
7473 Set mode for locking scheduler during execution."), _("\
7474 Show mode for locking scheduler during execution."), _("\
7475 off == no locking (threads may preempt at any time)\n\
7476 on == full locking (no thread except the current thread may run)\n\
7477 step == scheduler locked during every single-step operation.\n\
7478 In this mode, no other thread may run during a step command.\n\
7479 Other threads may run while stepping over a function call ('next')."),
7480 set_schedlock_func
, /* traps on target vector */
7481 show_scheduler_mode
,
7482 &setlist
, &showlist
);
7484 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7485 Set mode for resuming threads of all processes."), _("\
7486 Show mode for resuming threads of all processes."), _("\
7487 When on, execution commands (such as 'continue' or 'next') resume all\n\
7488 threads of all processes. When off (which is the default), execution\n\
7489 commands only resume the threads of the current process. The set of\n\
7490 threads that are resumed is further refined by the scheduler-locking\n\
7491 mode (see help set scheduler-locking)."),
7493 show_schedule_multiple
,
7494 &setlist
, &showlist
);
7496 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7497 Set mode of the step operation."), _("\
7498 Show mode of the step operation."), _("\
7499 When set, doing a step over a function without debug line information\n\
7500 will stop at the first instruction of that function. Otherwise, the\n\
7501 function is skipped and the step command stops at a different source line."),
7503 show_step_stop_if_no_debug
,
7504 &setlist
, &showlist
);
7506 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7507 &can_use_displaced_stepping
, _("\
7508 Set debugger's willingness to use displaced stepping."), _("\
7509 Show debugger's willingness to use displaced stepping."), _("\
7510 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7511 supported by the target architecture. If off, gdb will not use displaced\n\
7512 stepping to step over breakpoints, even if such is supported by the target\n\
7513 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7514 if the target architecture supports it and non-stop mode is active, but will not\n\
7515 use it in all-stop mode (see help set non-stop)."),
7517 show_can_use_displaced_stepping
,
7518 &setlist
, &showlist
);
7520 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7521 &exec_direction
, _("Set direction of execution.\n\
7522 Options are 'forward' or 'reverse'."),
7523 _("Show direction of execution (forward/reverse)."),
7524 _("Tells gdb whether to execute forward or backward."),
7525 set_exec_direction_func
, show_exec_direction_func
,
7526 &setlist
, &showlist
);
7528 /* Set/show detach-on-fork: user-settable mode. */
7530 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7531 Set whether gdb will detach the child of a fork."), _("\
7532 Show whether gdb will detach the child of a fork."), _("\
7533 Tells gdb whether to detach the child of a fork."),
7534 NULL
, NULL
, &setlist
, &showlist
);
7536 /* Set/show disable address space randomization mode. */
7538 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7539 &disable_randomization
, _("\
7540 Set disabling of debuggee's virtual address space randomization."), _("\
7541 Show disabling of debuggee's virtual address space randomization."), _("\
7542 When this mode is on (which is the default), randomization of the virtual\n\
7543 address space is disabled. Standalone programs run with the randomization\n\
7544 enabled by default on some platforms."),
7545 &set_disable_randomization
,
7546 &show_disable_randomization
,
7547 &setlist
, &showlist
);
7549 /* ptid initializations */
7550 inferior_ptid
= null_ptid
;
7551 target_last_wait_ptid
= minus_one_ptid
;
7553 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7554 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7555 observer_attach_thread_exit (infrun_thread_thread_exit
);
7556 observer_attach_inferior_exit (infrun_inferior_exit
);
7558 /* Explicitly create without lookup, since that tries to create a
7559 value with a void typed value, and when we get here, gdbarch
7560 isn't initialized yet. At this point, we're quite sure there
7561 isn't another convenience variable of the same name. */
7562 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7564 add_setshow_boolean_cmd ("observer", no_class
,
7565 &observer_mode_1
, _("\
7566 Set whether gdb controls the inferior in observer mode."), _("\
7567 Show whether gdb controls the inferior in observer mode."), _("\
7568 In observer mode, GDB can get data from the inferior, but not\n\
7569 affect its execution. Registers and memory may not be changed,\n\
7570 breakpoints may not be set, and the program cannot be interrupted\n\